using System; using System.Collections.Generic; using System.ComponentModel; using System.Reflection; using System.Text; namespace JFJT.GemStockpiles.Helpers { public static class EnumHelper { /// <summary> /// 根据值得到中文备注 /// </summary> /// <param name="e"></param> /// <param name="value"></param> /// <returns></returns> public static String GetEnumDesc(this Type e, int? value) { FieldInfo[] fields = e.GetFields(); for (int i = 1, count = fields.Length; i < count; i++) { if ((int)System.Enum.Parse(e, fields[i].Name) == value) { DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])fields[i]. GetCustomAttributes(typeof(DescriptionAttribute), false); if (EnumAttributes.Length > 0) { return EnumAttributes[0].Description; } } } return ""; } } }
调用
原文地址:https://www.cnblogs.com/Cein/p/9151821.html
时间: 2024-11-10 15:12:38