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();