读取 泛型 的描述 属性

public enum FAnXing
{
[Description("成功")]
Success=0,

}

//////////////////////////////////////////////////

public static string GetEnumDescription(Enum enumValue)
{
string str = enumValue.ToString();
System.Reflection.FieldInfo field = enumValue.GetType().GetField(str);
object[] objs = field.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
if (objs == null || objs.Length == 0) return str;
System.ComponentModel.DescriptionAttribute da = (System.ComponentModel.DescriptionAttribute)objs[0];
return da.Description;
}

////////////////////////////////

GetEnumDescription(FAnXing.Success)------成功

原文地址:https://www.cnblogs.com/zhangxiaoshuai/p/7551427.html