Skip to content

Instantly share code, notes, and snippets.

@alanjuden
Created January 21, 2014 22:26
Show Gist options
  • Save alanjuden/8549750 to your computer and use it in GitHub Desktop.
Save alanjuden/8549750 to your computer and use it in GitHub Desktop.
using System;
using System.Reflection;
using System.ComponentModel;
namespace YourNamespace
{
public static class Missing
{
public static string GetDescription(this Enum value)
{
FieldInfo info = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attribs = (DescriptionAttribute[])info.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attribs.Length > 0)
{
return attribs[0].Description;
}
else
{
return value.ToString();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment