1
2
3
4
5
6
7
8
9
10
11
12
public static string GetDescription<T>(this T source)
{
FieldInfo fi = source.GetType().GetField(source.ToString());

DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(
typeof(DescriptionAttribute), false);

if (attributes != null && attributes.Length > 0)
return attributes[0].Description;
else
return source.ToString();
}
1
2
3
// In Enums.NET you'd use:

string description = ((MyEnum)value).AsString(EnumFormat.Description);