Data types using C#

Interface Attributes

The following are interface attributes grouped as:

  • Required attributes
  • Optional attributes
  • Expert attributes

Required Attributes

These are required attributes:

  • ImmutableTypeId Attribute
  • KeyPropertyName Attribute
  • DataScope Attribute
 

Please consider using the LabelPropertyName attribute, too, to provide user-friendly labels for data items, for example, in function parameters of the DataReference<T> type. Otherwise, GUID-like labels will be used.

ImmutableTypeId Attribute

This attribute specifies a unique ID for the type. The ID should be unique for the running C1 CMS solution. The value of the argument should be a string representation of a GUID. This unique ID is used by C1 CMS to identify the type. This means that it is possible to rename the type and the type would still work. Though, when coding your own type and using the type name in code (your own or code that might use yours), the same compile rules apply as those with normal C# interfaces. Example:

[ImmutableTypeId("{D261B424-3629-4e00-9D24-BDA763DE8DD8}")]

KeyPropertyName Attribute

Use this attribute to specify one or more key property names. A key property is the property that will be used as a key for data type. No more than one instance of your data type may have the same key value (or keys values) in a given scope. The value of the argument should be a string with the name of one of the properties of your interface. Example:

[KeyPropertyName("Id")]

DataScope Attribute

This attribute specifies which data scopes items of the data types should exist in. Currently two scopes are supported: DataScopeIdentifier.Public and DataScopeIdentifier.Administrated. If your type should not support publishing workflows, then add this attribute once with the value DataScopeIdentifier.PublicName. If your type should support publishing workflows, you should add this attribute twice with the argument values: DataScopeIdentifier.PublicName and DataScopeIdentifier.AdministratedName. See the Creating a publishable data type section for more information on types that support publishing workflows.

Examples:

[DataScope(DataScopeIdentifier.PublicName)]

and

[DataScope(DataScopeIdentifier.AdministratedName)]

Optional Attributes

These are optional attributes:

 
  • Title Attribute
  • AutoUpdateble Attribute
  • LabelPropertyName Attribute
  • RelevantToUserType Attribute
  • Caching Attribute
  • PublishProcessControllerType Attribute

Title Attribute

Use this attribute to assign a more user-friendly name for your type. The value of the argument should be a string. This will be used by C1 CMS when the type’s name needs to be displayed in the UI. Example:

[Title("Employee")]

AutoUpdateble Attribute

This attribute will make C1 CMS auto add and update your type. The type will be added to the default data provider when data is added for the first time. If reading data is done before the type has been added, zero items are returned. If you change your type, adding a new property, then C1 CMS will update the underlying data store automatically. If you omit this attribute, you have to manually add it to the data layer and future changes to the type also have to be made manually. It is recommended that your type has this attribute. See the Manually adding or removing a data type to or from C1 CMS chapter for manually adding and removing a data type. Example:

[AutoUpdateble]

LabelPropertyName Attribute

Use this attribute to specify which property value should be used as label for items of the data type. The label is used when listing items in trees or other kinds of lists.

If the property used as a label is nullable (optional) or is a string and the value of the property is null, then the title will be of the form: “(undefined [PROPERTY_NAME])”, where PROPERTY_NAME is the name of the property specified with this attribute.

If the property is a reference property (See ForeignKey attribute) then the label of the referenced data will be displayed. The value of the argument should be a string with exactly the same name and casing as one of the properties of your interface. Example:

[LabelPropertyName("Name")]

Although this attribute is optional, we recommend using it to provide user-friendly labels for data items, for example, in function parameters of the DataReference<T> type.

RelevantToUserType Attribute

If you add this attribute to your type then your type will be selectable in the UI. Examples: Data references, adding a Visual function for your type and being a part of the functions calls in XSLT functions. At the moment the only supported argument value for this attribute is: UserType.Developer. Example:

[RelevantToUserType(UserType.Developer)]

Caching Attribute

By specifying this attribute on your type, instances of your type will be cached by C1 CMS, thus making data access to your type faster. Caching is done in memory, so avoid caching a type where large data sets are expected. Example:

[Caching(CachingType.Full)]

PublishProcessControllerType Attribute

When your type supports publishing workflows this attribute should be specified. The value of the argument should be a type that implements the IPublishProcessController interface. For a default behavior you can use the type GenericPublishProcessController as an argument value for this attribute. See the Creating a publishable data type chapter for more information on types that supports publishing workflows. Example:

[PublishProcessControllerType(typeof(GenericPublishProcessController))]

Expert Attributes

These are expert attributes:

  • PublishControlledAuxiliary Attribute
  • BuildNewHandler Attribute

PublishControlledAuxiliary Attribute

Use this attribute to get some custom code to run after the IPublishProcessController has done its work. The argument value of this attribute should be a type that implements the interface IPublishControlledAuxiliary. See the Creating a publishable data type chapter for more information on types that supports publish workflows. Example:

public class MyPublishControlledAuxiliary : IPublishControlledAuxiliary
{
    // IPublishControlledAuxiliary Members
}
[PublishControlledAuxiliary(typeof(MyPublishControlledAuxiliary))]
public interface IMyData : IData
{
    // Properties
}
 

BuildNewHandler Attribute

When the DataConnection.New<T>() is made, an object of a type that implements T is created. If you want to control which type is used to create a new object, then you should add this attribute to your type. The value of the argument should be a type value to a type that implements the interface IBuildNewHandler. Example:

public class MyBuildNewHandler : IBuildNewHandler
{
    // IBuildNewHandler Members
}
[BuildNewHandler(typeof(MyBuildNewHandler))]
public interface IMyData : IData
{
    // Properties
}