mirror of
https://github.com/nsnail/ns-ext.git
synced 2025-06-16 14:03:21 +08:00
<feat> 从资源文件读取Description-可继承
This commit is contained in:
parent
d23092e8fc
commit
cc761e4939
@ -17,13 +17,13 @@ public static class EnumExtensions
|
||||
{
|
||||
var t = e.GetType();
|
||||
var fi = t.GetField(Enum.GetName(t, e)!);
|
||||
var descAttr = fi!.GetCustomAttribute<DescriptionAttribute>(false);
|
||||
var descAttr = fi!.GetCustomAttribute<DescriptionAttribute>(true);
|
||||
if (descAttr is null) {
|
||||
return Enum.GetName(t, e);
|
||||
}
|
||||
|
||||
var str = descAttr.Description;
|
||||
var locAttr = fi!.GetCustomAttribute<LocalizationAttribute>(false);
|
||||
var locAttr = fi!.GetCustomAttribute<LocalizationAttribute>(true);
|
||||
return locAttr is null ? str : locAttr.ResourceClass.GetProperty(str)?.GetValue(default) as string ?? str;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user