Merge pull request '更新 Admin.NET/Admin.NET.Core/Extension/EnumExtension.cs' (#343) from coolcalf/Admin.NET.Pro:v2 into v2

Reviewed-on: https://code.adminnet.top/Admin.NET/Admin.NET.Pro/pulls/343
This commit is contained in:
zuohuaijun 2025-05-23 02:01:57 +08:00
commit fcd9b2e88f

View File

@ -151,6 +151,7 @@ public static class EnumExtension
/// <returns></returns> /// <returns></returns>
public static string GetDescription(this Enum value) public static string GetDescription(this Enum value)
{ {
if (value == null) return "";
return value.GetType().GetField(value.ToString())?.GetCustomAttribute<DescriptionAttribute>()?.Description; return value.GetType().GetField(value.ToString())?.GetCustomAttribute<DescriptionAttribute>()?.Description;
} }
@ -161,6 +162,7 @@ public static class EnumExtension
/// <returns></returns> /// <returns></returns>
public static string GetDescription(this object value) public static string GetDescription(this object value)
{ {
if (value == null) return "";
return value.GetType().GetField(value.ToString()!)?.GetCustomAttribute<DescriptionAttribute>()?.Description; return value.GetType().GetField(value.ToString()!)?.GetCustomAttribute<DescriptionAttribute>()?.Description;
} }
@ -171,6 +173,7 @@ public static class EnumExtension
/// <returns></returns> /// <returns></returns>
public static string GetTheme(this object value) public static string GetTheme(this object value)
{ {
if (value == null) return "";
return value.GetType().GetField(value.ToString()!)?.GetCustomAttribute<ThemeAttribute>()?.Theme; return value.GetType().GetField(value.ToString()!)?.GetCustomAttribute<ThemeAttribute>()?.Theme;
} }