Skip to content

Instantly share code, notes, and snippets.

@rdakar
Created June 27, 2017 23:23
Show Gist options
  • Save rdakar/f8105b3ba9155b16ed74b23b9d0c4f53 to your computer and use it in GitHub Desktop.
Save rdakar/f8105b3ba9155b16ed74b23b9d0c4f53 to your computer and use it in GitHub Desktop.
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