Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.ComponentModel;
- using System.Reflection;
- public static class EnumExtensions
- {
- public static string GetDescription(this Enum enumeration)
- {
- Type enumType = enumeration.GetType();
- object value = (object)enumeration;
- System.Reflection.MemberInfo[] memberInfo = enumType.GetMember(Enum.GetName(enumType, value));
- System.ComponentModel.DescriptionAttribute attribute = (System.ComponentModel.DescriptionAttribute)memberInfo[0].GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false).First();
- string description = attribute.Description;
- return description;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment