更新 Admin.NET/Admin.NET.Core/Extension/EnumExtension.cs
获取描述时检查值是否为空
This commit is contained in:
parent
586d130138
commit
02cea4e1fc
@ -151,6 +151,7 @@ public static class EnumExtension
|
||||
/// <returns></returns>
|
||||
public static string GetDescription(this Enum value)
|
||||
{
|
||||
if (value == null) return "";
|
||||
return value.GetType().GetField(value.ToString())?.GetCustomAttribute<DescriptionAttribute>()?.Description;
|
||||
}
|
||||
|
||||
@ -161,6 +162,7 @@ public static class EnumExtension
|
||||
/// <returns></returns>
|
||||
public static string GetDescription(this object value)
|
||||
{
|
||||
if (value == null) return "";
|
||||
return value.GetType().GetField(value.ToString()!)?.GetCustomAttribute<DescriptionAttribute>()?.Description;
|
||||
}
|
||||
|
||||
@ -171,6 +173,7 @@ public static class EnumExtension
|
||||
/// <returns></returns>
|
||||
public static string GetTheme(this object value)
|
||||
{
|
||||
if (value == null) return "";
|
||||
return value.GetType().GetField(value.ToString()!)?.GetCustomAttribute<ThemeAttribute>()?.Theme;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user