using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace wispro.sp.entity { public class EnumnDescription { public string Description { get; set; } public T Value { get; set; } } public class EnumHelper { /// /// 将枚举转换成描述字典集合 /// /// 枚举类型 /// public static List> getEnumDescriptionDic() { List> resultList = new List>(); Type type = typeof(T); var strList = Enum.GetNames(typeof(T)).ToList(); foreach (string key in strList) { var obj = (T)Enum.Parse(type, key); FieldInfo field = obj.GetType().GetField(obj.ToString()); DescriptionAttribute att = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute), false) as DescriptionAttribute; if (att == null) { resultList.Add(new EnumnDescription() { Description = key, Value = obj }); } else { resultList.Add(new EnumnDescription() { Description = att.Description, Value = obj }); } } return resultList; } } }