1.获取枚举的描述字典
public static Dictionary<string, string> GetEnumDescriptionDict(Type t)
{
Dictionary<string, string> enumDescDict = new ();
if (!t.IsEnum)
{
return enumDescDict;
}
FieldInfo[] fields = t.GetFields();
foreach (FieldInfo field in fields)
{
if (field.FieldType.IsEnum)
{
string description = field.GetXmlDocsSummary();
if (string.IsNullOrEmpty(description))
{
var attrDesc = field.GetCustomAttribute<DescriptionAttribute>();
if (attrDesc != null)
description = attrDesc.Description;
}
enumDescDict.Add(field.Name, description);
}
}
return enumDescDict;
}
标签:attrDesc,description,Dictionary,C#,field,枚举,enumDescDict,工具
From: https://www.cnblogs.com/fanqisoft/p/17414293.html