Skip to content

Files

Latest commit

49a8106 · May 15, 2023

History

History
59 lines (36 loc) · 2.39 KB
·

data-source--enum.md

File metadata and controls

59 lines (36 loc) · 2.39 KB
·

Contentment for Umbraco logo

Contentment for Umbraco

Data Sources

.NET Enumeration

Select an enumeration from a .NET assembly as the data source.

How to configure the editor?

Select the desired enumeration, by selecting the containing .NET assembly, and then the enumeration type. You can opt to sort the values alphabetically in the data source too.

Configuration Editor for .NET Enumeration

What is the value's object-type?

The value returned from the List editor is the configured enumeration type.

Depending on the List editor used, this may be wrapped in a List<T>.

Controlling Enum display

You can use the DataListItemAttribute to decorate your enum values with additional information for use with Contentment. With this attribute, you can specify properties such as name, description, icon, etc., for individual enum items.

For example:

using Umbraco.Community.Contentment.DataEditors;

public enum MyEnum
{
    [DataListItem(Description = "This is the first value", Group = "Group A", Icon = "icon-first")]
    First,

    [DataListItem(Description = "This is the second value", Group = "Group B", Icon = "icon-second")]
    Second,

    [DataListItem(Description = "This is the third value", Group = "Group A", Icon = "icon-third")]
    Third
}

The DataListItemAttribute contains the following properties:

Property Description Type
Description Provides a description for the Enum value string
Disabled Specifies whether the Enum value should be disabled bool
Group Assigns the Enum value to a specific group string
Icon Specifies an icon for the Enum value string
Ignore Indicates whether the Enum value should be ignored bool
Name Provides a custom name for the Enum value (default: field name) string
Value Specifies a custom value for the Enum value (default: field value) string