public static class EnumExtension
{
public static string GetEnumDescription(this Enum enumerator)
{
FieldInfo info = enumerator.GetType().GetField(enumerator.ToString());
DescriptionAttribute attribute = info.GetCustomAttribute<DescriptionAttribute>();
return attribute == null ? enumerator.ToString() : attribute.Description;
}
}
Extension to help get the enumerator description using the attribute "DescriptionAttribute".
Example: YourEnum.Value.GetEnumDescription();
Example: YourEnum.Value.GetEnumDescription();
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.