枚举备注读取
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; } public static string GetDescription(int enumValue) { VaildStateEnum obj = (VaildStateEnum)enumValue; return GetDescription(obj); } /// <summary> /// 获取枚举名称 /// </summary> /// <param name="enumValue">枚举值</param> /// <returns></returns> public static string GetEnumName(int enumValue) { return Enum.GetName(typeof(VaildStateEnum), enumValue); } /// <summary> /// 获取枚举值 /// </summary> /// <param name="enumName">枚举名称</param> /// <returns></returns> public static int GetEnumValue(string enumName) { VaildStateEnum enumValue; if (Enum.TryParse(enumName, out enumValue)) { return (int)enumValue; } return 0; } }