Skip to content

Instantly share code, notes, and snippets.

@adhamankar
Created November 2, 2016 09:19
Show Gist options
  • Save adhamankar/891f979b89c79d138dc914eb56eb9f52 to your computer and use it in GitHub Desktop.
Save adhamankar/891f979b89c79d138dc914eb56eb9f52 to your computer and use it in GitHub Desktop.
public static class Extensions
{
public static string GetEnumDescription(this Enum value)
{
if (value == null) return string.Empty;
FieldInfo fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
return (attributes != null && attributes.Length > 0) ? attributes[0].Description : value.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment