Piotr Czajkowski 1 周之前
父节点
当前提交
672d4bd705
共有 1 个文件被更改,包括 4 次插入7 次删除
  1. 4 7
      ExcelORM/ExcelORM/TypeExtensions.cs

+ 4 - 7
ExcelORM/ExcelORM/TypeExtensions.cs

@@ -18,14 +18,11 @@ public static class TypeExtensions
             return null;
         }
 
-        if (Nullable.GetUnderlyingType(property.PropertyType) != null)
+        var nullableUnderlyingType = Nullable.GetUnderlyingType(property.PropertyType);
+        if (nullableUnderlyingType is { IsEnum: true })
         {
-            var genericType = property.PropertyType.GetGenericArguments().FirstOrDefault();
-            if (genericType == null) return null;
-            
-            if (genericType.IsEnum)
-                return Enum.TryParse(genericType, value.GetText(), true, out var enumValue)
-                    ? enumValue : null;
+            return Enum.TryParse(nullableUnderlyingType, value.GetText(), true, out var enumValue)
+                ? enumValue : null;
         }
         
         return value.GetText();