/// <summary> /// 獲取根據枚舉名稱獲取枚舉描述 /// </summary> /// <typeparam name="T">枚舉類型</typeparam> /// <param name="enumName">枚舉名稱</param> /// <returns></returns> public static string GetEnumDescription<T>(string enumName){ string result = string.Empty; System.Reflection.FieldInfo field = typeof(T).GetField(enumName); if (field != null) { object[] objs = field.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false); if (objs == null || objs.Length == 0) result = enumName; else { System.ComponentModel.DescriptionAttribute da = (System.ComponentModel.DescriptionAttribute)objs[0]; result = da.Description; } } else { result = enumName; } return result; } /// <summary> /// 獲取枚舉的description /// </summary> /// <param name="enumSubitem">枚舉值</param> /// <returns>枚舉對應的介紹</returns> public static string GetEnumDescription(object enumSubitem) { enumSubitem = (Enum)enumSubitem; string strValue = enumSubitem.ToString(); FieldInfo fieldinfo = enumSubitem.GetType().GetField(strValue); if (fieldinfo != null) { Object[] objs = fieldinfo.GetCustomAttributes(typeof(DescriptionAttribute), false); if (objs == null || objs.Length == 0) { return strValue; } else { DescriptionAttribute da = (DescriptionAttribute)objs[0]; return da.Description; } } else { return "不限"; } }