using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace CMS.Plugin.HIAWms
{
public class GetEnumDescriptionUtil
{
///
/// 获取枚举的描述
///
///
///
public static string GetEnumDescription(Enum enumValue)
{
string value = enumValue.ToString();
if (string.IsNullOrWhiteSpace(value) || value == "0") return "";
FieldInfo field = enumValue.GetType().GetField(value);
object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false); //获取描述属性
if (objs == null || objs.Length == 0) //当描述属性没有时,直接返回名称
return value;
DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0];
return descriptionAttribute.Description;
}
}
}