Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
The MetaEnum class represents enumerations which can be single or multi-select. When a new meta enum is created, a meta type with the McDataType property and McDataType.Enum value is registered. If an enumerator has been created, you can create a new field with the enumerator meta type. The entity object property returns the selected item ID (Int32) or an array of selected item IDs (Int32[]).
When creating and deleting meta enums, remember that a meta model can only be modified in Design mode. Refer to the MetaClassManager Class section for more information.
Since the enumerator is an original meta type, you can get all enumerators from the MetaClassManager.RegisteredTypes property.
Example: Find all enumerators
foreach(MetaFieldType type in DataContext.Current.MetaModel.RegisteredTypes)
{
if (type.McDataType == McDataType.Enum)
{
// The enumerator is found
}
}
Call the Create method of the MetaEnum class, passing type name, friendly name and multy value flag to create a new enumerator.
Example: Create a new enumerator
MetaFieldType newEnum = MetaEnum.Create(enumName, enumFriendlyName, bMultiValue);
The following methods from the MetaEnum class are useful when managing enumerators:
If an enumerator has been created, you can create a new field with the enumerator meta type.
Example: Creation of enum meta field
public MetaField CreateEnumField(string name, string friendlyName, string enumName, bool isNullable, string defaultValue, bool enumEditable)
{
if (name == null)
throw new ArgumentNullException("name");
if (friendlyName == null)
throw new ArgumentNullException("friendlyName");
AttributeCollection attr = new AttributeCollection();
attr.Add(McDataTypeAttribute.EnumEditable, enumEditable);
MetaField retVal = this.MetaClass.CreateMetaField(name, friendlyName, enumName, isNullable, defaultValue, attr);
return retVal;
}
Call the Remove method of the MetaEnum class, passing meta type to delete an enumerator.
Last updated: Oct 21, 2014