using System; using System.Collections.Generic; using System.Reflection; using System.Text; namespace WMS.Web.Core { public class EnumRemarkAttribute : Attribute { public string Remark { get; set; } public EnumRemarkAttribute(string remark) { this.Remark = remark; } } public static class EnumOperate { public static string GetRemark(this Enum enumInfo) { if (enumInfo == null) return ""; Type type = enumInfo.GetType(); //获取字段信息 FieldInfo field = type.GetField(enumInfo.ToString()); if (field == null) return ""; //检查字段是否含有指定特性 if (field.IsDefined(typeof(EnumRemarkAttribute), true)) { //获取字段上的自定义特性 EnumRemarkAttribute remarkAttribute = (EnumRemarkAttribute)field.GetCustomAttribute(typeof(EnumRemarkAttribute)); return remarkAttribute.Remark; } else { return enumInfo.ToString(); } } } public class PropertyRemarkAttribute : Attribute { public string Remark { get; set; } public PropertyRemarkAttribute(string remark) { this.Remark = remark; } } }