Skip to content

ModelsGenerationConfiguration

Stephan edited this page Jun 23, 2014 · 1 revision

Models generation can be configured by dropping some CSharp files into the directory containing models (note: not available with Live models). These files can contain your own partial implementations of models, and some attributes that will configure how models are generated.

Ignore Content Type

Indicates that a content type with a give alias should be ignored and not generated. The attribute is an assembly attribute.

[assembly:IgnoreContentType("alias")]

This will cause the content type class to not be generated.

Note: must document what happens when it is a parent content type, or when it is part of a composition.

Ignore Property Type

Indicates that a property type with a give alias should be ignored and not generated. The attribute must decorate the corresponding content type class.

[IgnorePropertyType("alias")]
public partial class MyContentType
{ }

This will cause the property to not be generated.

Implement Content Type

Indicates that a class implements a content type with a given alias. The attribute must decorate the corresponding content type class. Use when alias and class name do not match.

[ImplementContentType("myDifferentAlias")]
public partial class MyContentType : PublishedContentModel
{ }

This will cause the content type class to not be generated, since you already implement it.

Implement Property Type

Indicates that a property implements a property type with a given alias. The attribute must decorate the corresponding property type property. Use when alias and property name do not match.

public partial class MyContentType
{ 
  [ImplementPropertyType("myDifferentAlias")]
  public int MyProperty { get { return this.GetPropertyValue<int>("myDifferentAlias"); } }
}

This will cause the property to not be generated, since you already implement it.

Rename content type

Indicates a different class name for a content type. The attribute is an assembly attribute. Use when alias and class name do not match.

[assembly:RenameContentType("alias", "ClassName")]

This will cause the content type class to be generated, with the class name "ClassName" instead of "Alias".

Rename property type

Indicates a different property name for a property type. The attribute must decorate the corresponding content type class. Use when alias and property name do not match.

[RenamePropertyType("myDifferentAlias", "PropertyName")]
public partial class MyContentType
{ }

This will cause the property to be generated, with the name "PropertyName" instead of "MyDifferentAlias".

Models Base Class

Indicates the base class for all models. By default the base class is PublishedContentModel but the attribute lets you override it. The attribute is an assembly attribute.

[assembly:ModelsBaseClass(typeof (MyOwnBaseClass))]

Models namespace

Indicates the namespace for all models. Overrides every other namespace that might have been configured. The attribute is an assembly attribute.

[assembly:ModelsNamespace("MyProject.ContentModels")]

Models using

Indicates extra "using" statements to be inserted in model files. The models generator already inserts some common "using" statements, plus tries to be clever, but it is not always enough. The attribute is an assembly attribute.

[assembly:ModelsUsing("MyOtherProject.Some.Other.Thing")]