/// <summary> /// 获得指定枚举类型中,指定值的描述文本 /// </summary> /// <param name="enumValue">枚举值,不要作任何类型转换</param> /// <param name="isFormatStr">格式化描述文本,即格式化掉显示字符串前边的数字以及空格 例:"1 合理咯"==>"合理咯"</param> /// <returns>描述字符串</returns> public static string GetFieldText(object enumValue, bool isFormatStr) { ALEnumDescription[] descriptions = GetFieldTexts(enumValue.GetType(), SortType.Default); foreach (ALEnumDescription ed in descriptions) { if (ed.fieldIno.Name == enumValue.ToString()) { return(isFormatStr ? ALFormater.FormatStringNumber(ed.EnumDisplayText) : ed.EnumDisplayText); } } return(string.Empty); }
/// <summary> /// 获得指定枚举类型中,指定值的描述文本 /// </summary> /// <param name="enumType">传入枚举大类型(如:GenderEnum)</param> /// <param name="enumItem">所指定枚举项的value值</param> /// <param name="isFormatStr">格式化描述文本,即去掉文本前的数字</param> /// <returns></returns> public static string GetFieldText(Type enumType, int enumItem, bool isFormatStr) { ALEnumDescription[] descriptions = GetFieldTexts(enumType, SortType.Default); foreach (ALEnumDescription ed in descriptions) { if (ed.EnumValue == enumItem) { return(isFormatStr ? ALFormater.FormatStringNumber(ed.EnumDisplayText) : ed.EnumDisplayText); } } return(string.Empty); }