获取枚举值上的Description特性说明


/// <summary>
/// 获取枚举值上的Description特性说明
/// </summary>
/// <typeparam name="T">枚举类型</typeparam>
/// <param name="obj">枚举值</param>
/// <returns></returns>
public static string GetDescription<T>(T obj)
{
Type type = obj.GetType();
FieldInfo field = type.GetField(Enum.GetName(type, obj));
DescriptionAttribute desc = Attribute.GetCustomAttribute
(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
if(desc == null)
{
return string.Empty;
} return desc.Description;
}

 
上一篇:MSSQLSERVER添加c# clr程序集的使用方法


下一篇:vueHistory 模式下,布置到服务器上路由刷新会报nginx404错误