using System; using System.Collections.Generic; using System.ComponentModel; namespace Common.Utils { public class EnumUtil { public static IList<EnumEntity> EnumToList<T>() { IList<EnumEntity> list = new List<EnumEntity>(); foreach (var item in Enum.GetValues(typeof(T))) { EnumEntity enumEntity = new EnumEntity(); Object[] objArr = item.GetType().GetField(item.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true); if (objArr != null && objArr.Length > 0) { DescriptionAttribute descAttr = objArr[0] as DescriptionAttribute; enumEntity.Desction = descAttr.Description; } enumEntity.EnumValue = Convert.ToInt32(item); enumEntity.EnumName = item.ToString(); list.Add(enumEntity); } return list; } } public class EnumEntity { /// <summary> /// 枚举的描述 /// </summary> public string Desction { set; get; } /// <summary> /// 枚举名称 /// </summary> public string EnumName { set; get; } /// <summary> /// 枚举对象的值 /// </summary> public int EnumValue { set; get; } } }