فهرست منبع

修复获取枚举类系统参数问题

qinchaoyue 1 هفته پیش
والد
کامیت
b849f1d8f8
1فایلهای تغییر یافته به همراه8 افزوده شده و 0 حذف شده
  1. 8 0
      src/Hotline/Caching/Services/SystemSettingCacheManager.cs

+ 8 - 0
src/Hotline/Caching/Services/SystemSettingCacheManager.cs

@@ -79,6 +79,14 @@ namespace Hotline.Caching.Services
 
                 try
                 {
+                    var targetType = typeof(T);
+                    if (targetType.IsEnum)
+                    {
+                        if (value is string strValue)
+                            return (T)Enum.Parse(targetType, strValue, ignoreCase: true);
+                        else
+                            return (T)Enum.ToObject(targetType, value);
+                    }
                     return (T)Convert.ChangeType(value, typeof(T));
                 }
                 catch (InvalidCastException e)