using System; using System.Collections.Generic; using System.Linq; using System.Text; using ICSSoft.Frame.Data.Entity; namespace ICSSoft.Frame.Common { public static class EnumExtfunction { public static string GetDescription(this Enum em) where Attr : AttrDescription { Type enumType = em.GetType(); var name = Enum.GetName(enumType, em); if (name == null) return string.Empty; object[] objs = enumType.GetField(name).GetCustomAttributes(typeof(Attr), false); if (objs == null || objs.Length == 0) return string.Empty; Attr attr = objs[0] as Attr; return attr.Description; } public static string GetDescription(this Enum em) { Type enumType = em.GetType(); var name = Enum.GetName(enumType, em); if (name == null) return string.Empty; object[] objs = enumType.GetField(name).GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false); if (objs == null || objs.Length == 0) return string.Empty; System.ComponentModel.DescriptionAttribute attr = objs[0] as System.ComponentModel.DescriptionAttribute; return attr.Description; } } }