Created
June 27, 2017 23:23
-
-
Save rdakar/f8105b3ba9155b16ed74b23b9d0c4f53 to your computer and use it in GitHub Desktop.
EnumExtender.GetDescription
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 enumerationValue) | |
{ | |
Type type = enumerationValue.GetType(); | |
MemberInfo member = type.GetMembers().Where(w => w.Name == Enum.GetName(type, enumerationValue)).FirstOrDefault(); | |
var attribute = member?.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() as DescriptionAttribute; | |
return attribute?.Description != null ? attribute.Description : enumerationValue.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment