Skip to content
Lars-Erik Aabech edited this page Oct 20, 2013 · 10 revisions

Unless you installed via the package repository, add a file called CodeGen.config to your configuration folder. Otherwise it's already there, but you might want to include it in your project.

The full configuration looks like this:

###CodeGenerator element

OverwriteReadOnly

For everyone lucky enough to have a SCS locking the files.

GeneratorFactory and ParserFactory

The ones in the sample config above are the defaults. They can be omitted.

You can create your own factories, generating whichever composition of generators (and preferably matching parsers) you want. See this page for a sample, and check out the unit-tests and source to see how you can "roll your own".

DocumentTypes and MediaTypes elements

ModelPath

If you have ReSharper, you may set the model folders as Namespace Provider=False. Otherwise, make a folder that has the namespace structure you want.

If GenerateXml is set to true, the code generation will attemt to create content type XML for ALL classes found in the specified folder.

Tip: don't put your base class in there

BaseClass

A class in the same namespace as the generated/code-first classes with at least the following structure:

public class DocumentTypeBase
{
    protected IPublishedContent Content; // Can be field or property, must be named Content

    protected DocumentTypeBase(IPublishedContent content) // Must implement ctor with one IPublishedContent arg
    {
        Content = content;
    }
}

The class itself can be named whatever.

It should however not be in the synced folders, keep it one step up, for instance under Models.

*Tip: You can make your own property bodies relatively easy, thereby controlling how your base class should look. Take a look at the source. :) *

Namespace

Preferably the correct namespace for your model folder. :)

GenerateClasses

Whether to generate class for document types when saved. (Works with uSync attach=true or uSync write=true)

GenerateXml

Whether to generate XML for document types when Umbraco starts. (Works with uSync read=true)

TypeMappings

Pretty self explanatory if you should use this tool at all. ;) For some reason the CSharpCodeDomProvider adds @ to intristic type aliases. (string, int etc.) Use the class names of the types to avoid it. DataTypeId = the editor ID.

Now for some [usage]... (todo)

Clone this wiki locally