c# GetDescription
public static string? GetDescription(this Enum value, bool nameInstead = true)
{
Type type = value.GetType();
string? name = Enum.GetName(type, value);
if (name == null)return null;
FieldInfo ? field = type.GetField(name);
if (field == null) return null;
DescriptionAttribute? attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
if (attribute == null && nameInstead) return name;
return attribute?.Description;
}

浙公网安备 33010602011771号