Created
January 21, 2014 22:26
-
-
Save alanjuden/8549750 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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