更新 Admin.NET/Admin.NET.Core/Extension/EnumExtension.cs

获取描述时检查值是否为空
This commit is contained in:
coolcalf 2025-05-23 00:00:19 +08:00
parent 586d130138
commit 02cea4e1fc

View File

@ -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;
}