using System; using System.Collections.Generic; using System.ComponentModel; namespace zifar.SgmhWeb.CommonMethod { public class EnumberHelper { public static List<EnumberEntity> EnumToList<T>() { List<EnumberEntity> list = new List<EnumberEntity>(); foreach (var e in Enum.GetValues(typeof(T))) { EnumberEntity m = new EnumberEntity(); object[] objArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true); if(objArr!=null && objArr.Length>0) { DescriptionAttribute da = objArr[0] as DescriptionAttribute; m.Desction = da.Description; } m.EnumValue = Convert.ToInt32(e); m.EnumName = e.ToString(); list.Add(m); } return list; } } public class EnumberEntity { /// <summary> /// 枚舉的描述 /// </summary> public string Desction { set; get; } /// <summary> /// 枚舉名稱 /// </summary> public string EnumName { set; get; } /// <summary> /// 枚舉對象的值 /// </summary> public int EnumValue { set; get; } } }
public enum QxItem { [Description("查看")] Show=0, [Description("新增")] Add=1, [Description("編輯")] Edit=2, [Description("刪除")] Del=3, [Description("審批")] Sp=4, [Description("導出")] Export=5, [Description("同步")] Sync=6, [Description("打印")] Print=7 }