using System;
using System.ComponentModel;
public enum TimeOfDay
{
[Description("上午")]
Moning,
[Description("下午")]
Afternoon,
[Description("晚上")]
Evening,
};
public static Dictionary<string, string> GetEnumDic(Type enumType)
{
Dictionary<string, string> dic =new Dictionary<string, string>();
FieldInfo[] fieldinfos = enumType.GetFields();
foreach (FieldInfo field in fieldinfos)
{
if (field.FieldType.IsEnum)
{
Object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
dic.Add(field.Name, ((DescriptionAttribute)objs[0]).Description);
}
}
return dic;
}
请发表评论