(精华)2020年6月26日 C#类库 Enum(扩展方法)
作者:互联网
using System;
using System.ComponentModel;
using System.Linq;
namespace Core.Util
{
/// <summary>
/// 拓展类
/// </summary>
public static partial class Extention
{
/// <summary>
/// 获取枚举描述
/// </summary>
/// <param name="value">枚举值</param>
/// <returns></returns>
public static string GetDescription(this Enum value)
{
DescriptionAttribute attribute = value.GetType()
.GetField(value.ToString())
.GetCustomAttributes(typeof(DescriptionAttribute), false)
.SingleOrDefault() as DescriptionAttribute;
return attribute == null ? value.ToString() : attribute.Description;
}
}
}
标签:类库,26,DescriptionAttribute,C#,attribute,Enum,System,value,using 来源: https://blog.csdn.net/aa2528877987/article/details/106971639