/// <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;
}

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2021-10-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2021-11-26
  • 2021-12-24
  • 2021-10-07
  • 2022-12-23
相关资源
相似解决方案