Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
EnumExtender.GetDescription
public static string GetDescription(this Enum enumerationValue)
{
Type type = enumerationValue.GetType();
MemberInfo member = type.GetMembers().Where(w => w.Name == Enum.GetName(type, enumerationValue)).FirstOrDefault();
var attribute = member?.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() as DescriptionAttribute;
return attribute?.Description != null ? attribute.Description : enumerationValue.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.