瀏覽代碼

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

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)