DeviceManager/DeviceRepair.Models/ExtendFuncHelper.cs

31 lines
854 B
C#
Raw Normal View History

2024-07-01 16:52:48 +00:00
using DeviceRepair.Models.Attr;
using System;
using System.Reflection;
namespace DeviceRepair.Models
{
public static class ExtendFuncHelper
{
/// <summary>
/// 获取枚举的描述文本信息
/// </summary>
/// <param name="em"></param>
/// <returns></returns>
public static string Description(this System.Enum em)
{
Type type = em.GetType();
FieldInfo fd = type.GetField(em.ToString());
if (fd == null)
return string.Empty;
object[] attrs = fd.GetCustomAttributes(typeof(EnumDescriptionAttribute), false);
string name = string.Empty;
foreach (EnumDescriptionAttribute attr in attrs)
{
name = attr.Desciption;
}
return name;
}
}
}