/// <summary> /// 通过枚举值取枚举 EnumDescriptionAttribute 描述 /// </summary> /// <param name="enumCode"></param> /// <param name="value"></param> /// <returns></returns> public static string GetItemDescriptionByValue(this Enum enumCode, int value) { foreach (var enObj in Enum.GetValues(enumCode.GetType())) { if (value == (int)enObj) { return(EnumDescriptionAttribute.GetFieldText(enObj)); } } return(null); }
/// <summary> /// 获取枚举 EnumDescriptionAttribute 描述 /// </summary> /// <param name="enumCode"></param> /// <returns></returns> public static string ToFullDescription(this Enum enumCode) { return(string.Format("{0}: {1}", enumCode, EnumDescriptionAttribute.GetFieldText(enumCode))); }
/// <summary> /// 获取枚举 EnumDescriptionAttribute 描述 /// </summary> /// <param name="enumCode"></param> /// <returns></returns> public static string ToDescription(this Enum enumCode) { return(EnumDescriptionAttribute.GetFieldText(enumCode)); }