The post presents a tool that automatically generates DD4T .net strongly typed models from Tridion Schemas.
In the previous posts Strong Typed Models and Umbrella Models, I presented a flavour of strongly type models to be used with DD4T .NET. The tedious part with these models, is that one needs to write them manually one by one, while carefully checking the type of each field in the Schema, the single vs multi-value property, the Allowed Schemas, etc.
This is an ideal candidate for automation and code generation and that's exactly what this Model Generator is doing:
The application .config file must define the following settings:
The entire Model Generator solution, including sources, dlls and executable are available on this blog's GitHub page, project Model Generator.
In the previous posts Strong Typed Models and Umbrella Models, I presented a flavour of strongly type models to be used with DD4T .NET. The tedious part with these models, is that one needs to write them manually one by one, while carefully checking the type of each field in the Schema, the single vs multi-value property, the Allowed Schemas, etc.
This is an ideal candidate for automation and code generation and that's exactly what this Model Generator is doing:
- Connect to a Tridion CM instance using Core Service and download all Schemas of type Component, Multimedia and Embedded
- Build an internal model for each Schema, each field in it, retaining all return types, field name, allowed Schemas, multi- and single-value
- Generate individual C# classes for each Schema model, generating the using statements, class, properties for each Schema field, constructor
The Model Generator is in fact a simple Console application, making use of Core Service client and creating .cs files in a predefined location.
The application .config file must define the following settings:
<add key="TridionCmeUrl" value="http://my.tridion.com"/> - defines the Tridion CME URL to connect to using Core Service
<add key="Username" value="mihai.cadariu"/> - the username to use when connecting
<add key="Password" value="password"/> - the password to use when connecting
<add key="StartTcmUri" value="tcm:0-13-1"/> - the Publication or Folder to search Schemas under
<add key="Namespace" value="Mitza.DD4T.Model"/> - the namespace to use when generating models
<add key="Folder" value="C:\Mitza.DD4T.Model"/> - the folder on local file system where .cs files are generated
Comments
So far I'm only writing strings to a file. Quick and it gets the job done.