Skip to content

Instantly share code, notes, and snippets.

@oguzhankircali
Created November 8, 2018 17:44
Show Gist options
  • Select an option

  • Save oguzhankircali/6b49035d620b2ebb1f7921103b092831 to your computer and use it in GitHub Desktop.

Select an option

Save oguzhankircali/6b49035d620b2ebb1f7921103b092831 to your computer and use it in GitHub Desktop.
public static string GetDescription(this Enum value)
{
string description = string.Empty;
if (value != null)
{
description = value.ToString();
FieldInfo fieldInfo = value.GetType().GetField(description);
DescriptionAttribute[] attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attributes.Length > 0)
{
description = attributes[0].Description;
}
}
return description;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment