enum to render display names in cms editor


I have an enum property in the block model.

public enum TextFieldSize { Small, Standard, Large }

[EditorDescriptor(EditorDescriptorType = typeof(EnumSelector))]
Name = "Field size",
Description = "Determines width of field displayed",
GroupName = SystemTabNames.Content,
Order = 50)]
public virtual TextFieldSize FieldSize { get; set; }

public override void SetDefaultValues(ContentType contentType)
FieldSize = TextFieldSize.Standard;

In the CMS editor, it displays the dropdown with the list of enums (Small, Standard, Large).

But I want to have display name for each. That is, instead of 'Small' I want to display as 'Small - Single Line'.

Small - Small - Single Line
Standard - Standard - Single Line
Large - Large - Multi line

I have change the enum property to
public enum TextFieldSize { [Display(Name = "Small - Single line")]Small, [Display(Name = "Standard - Single line")]Standard, [Display(Name = "Large - Multi line")]Large }

but it's does show any display names.

Aug 22, 2016 18:19
[EditorDescriptor(EditorDescriptorType = typeof(EnumEditorDescriptor<SomeEnum>))]


public class EnumEditorDescriptor<TEnum> : EditorDescriptor where TEnum : struct, IComparable, IConvertible, IFormattable
    public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
        SelectionFactoryType = typeof(EnumSelectionFactory<TEnum>);
        ClientEditingClass = "epi-cms/contentediting/editors/SelectionEditor";
        base.ModifyMetadata(metadata, attributes);

public class EnumSelectionFactory<TEnum> : ISelectionFactory
    public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
        var values = Enum.GetValues(typeof(TEnum))
                .Select(x=> new SelectItem { Text = "HERE-EXTRACT-TEXT-FROM-LOCALIZATION-SERVICE", Value = x});

        return values;
Sep 08, 2016 11:05

Maybe I'm misunderstanding this but shouldn't it be possible to put this in a language XML resource file in //languages/language node:

            <small>Small - Single line</small>
            <standard>Standard - Single line</standard>
            <large>Large - Single line</large>
Sep 08, 2016 12:26

Yes, that should also work. We were just using localization service n ot based on Xml language files.. therefore needed programmatic access

Sep 08, 2016 12:49
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.