Created
November 8, 2018 17:44
-
-
Save oguzhankircali/6b49035d620b2ebb1f7921103b092831 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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