using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace AllBase { public class EnumHelper { public static List GetEnumMember(Type type) { List list = new List(); foreach (var d in Enum.GetValues(type)) { string desc = (d.GetType().GetField(d.ToString()).GetCustomAttribute(typeof(EnumDescriptionAttribute)) as EnumDescriptionAttribute).Description; list.Add(new EnumMember(d.ToString(), (int)d, desc)); } return list; } } public class EnumMember { public string Name; public int Value; public string Description; public EnumMember(string name, int value, string description) { this.Name = name; this.Value = value; this.Description = description; } public override string ToString() { return this.Description; } } /// /// 枚举注释的自定义属性类 /// public class EnumDescriptionAttribute : Attribute { private string m_strDescription; public EnumDescriptionAttribute(string strPrinterName) { m_strDescription = strPrinterName; } public string Description { get { return m_strDescription; } } } }