/// <summary> /// 返回枚举值的描述 /// </summary> /// <param name="value">枚举值</param> /// <returns>指定枚举值描述</returns> public static string getEnumDescription(this Enum value) { FieldInfo fi = value.GetType().GetField(value.ToString()); if (fi == null) { return value.ToString(); } object[] attributes = fi.GetCustomAttributes(typeof(EnumDescriptionAttribute), false); if (attributes == null || attributes.Length == 0) { return value.ToString(); } else { string[] arr = ((EnumDescriptionAttribute)attributes[0]).Description.Split(new string[] { "," }, StringSplitOptions.None); return AppCommon.convertLanguage(arr); } } /// <summary> /// 根据枚举类型返回类型中的所有值、文本及描述 /// </summary> /// <param name="type"></param> /// <returns>返回三列数组,第0列为Description,第1列为Value,第2列为Text</returns> public static List<EnumOperation> getEnumOpt(Type type) { List<EnumOperation> ret = new List<EnumOperation>(); FieldInfo[] fields = type.GetFields(); for (int i = 1, count = fields.Length; i < count; i++) { EnumOperation eo = new EnumOperation(); FieldInfo field = fields[i]; //枚举值 eo.value = (int)Enum.Parse(type, field.Name); //枚举名称 eo.name = field.Name; //枚举描述信息 object[] objs = field.GetCustomAttributes(typeof(isip.assembly.EnumDescriptionAttribute), false); if (objs == null || objs.Length == 0) { eo.desc = field.Name; } else { isip.assembly.EnumDescriptionAttribute da = (isip.assembly.EnumDescriptionAttribute)objs[0]; string[] arr = da.Description.Split(new string[] { "," }, StringSplitOptions.None); eo.desc = AppCommon.convertLanguage(arr); } ret.Add(eo); } return ret; } [Serializable] public class EnumOperation { public string name { get; set; } public string desc { get; set; } public int value { get; set; } public Dictionary<string, int[]> section { get; set; } }