using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
namespace TempTask.WebEntry.Tools
{
public class EnumHelper
{
///
/// 得到枚举的DescriptionAttribute值。
///
///
///
///
static public string GetEnumDescription(object value)
{
Type enumType = typeof(TEnum);
if (!enumType.IsEnum)
throw new ArgumentException("不是枚举类型");
var name = Enum.GetName(enumType, value);
if (name == null)
return string.Empty;
object[] objs = enumType.GetField(name).GetCustomAttributes(typeof(DescriptionAttribute), false);
if (objs == null || objs.Length == 0)
return string.Empty;
DescriptionAttribute attr = objs[0] as DescriptionAttribute;
return attr.Description;
}
}
}