Skip to content

Instantly share code, notes, and snippets.

@lfgrando
Last active July 20, 2018 18:16
Show Gist options
  • Save lfgrando/8794680896c864101b58f2047a4cbc9e to your computer and use it in GitHub Desktop.
Save lfgrando/8794680896c864101b58f2047a4cbc9e to your computer and use it in GitHub Desktop.
public static string ToDescription<T>(this T source)
{
FieldInfo fi = source.GetType().GetField(source.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
//
return attributes.Length > 0 ? attributes[0].Description : source.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment