public enum AuditEnum { [Description("未送审")] Holding=0, [Description("审核中")] Auditing=1, [Description("审核通过")] Pass=2, [Description("驳回")] Reject=3 }
自定义一个类EnumService.cs , 增加静态方法GetDescription()根据传入的枚举值来读取Description信息
public class EnumService { public static string GetDescription(Enum obj) { string objName = obj.ToString(); Type t = obj.GetType(); FieldInfo fi = t.GetField(objName); DescriptionAttribute[] arrDesc = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); return arrDesc[0].Description; } }
在输出枚举值的地方增加对EnumService.GetDescription()的调用