瀏覽代碼

Added HandleGuid

Piotr Czajkowski 1 周之前
父節點
當前提交
7c2619e145
共有 1 個文件被更改,包括 10 次插入7 次删除
  1. 10 7
      ExcelORM/ExcelORM/TypeExtensions.cs

+ 10 - 7
ExcelORM/ExcelORM/TypeExtensions.cs

@@ -7,18 +7,21 @@ namespace ExcelORM;
 
 public static class TypeExtensions
 {
+    private static object? HandleGuid(XLCellValue value, PropertyInfo property)
+    {
+        if (Guid.TryParse(value.GetText(), out var guid))
+            return guid;
+
+        if (property.PropertyType == typeof(Guid?)) return null;
+        return Guid.Empty; 
+    }
+    
     private static object? GetAdditionalTypeFromText(XLCellValue value, PropertyInfo? property = null)
     {
         if (property == null) return value.GetText();
         
         if (property.PropertyType == typeof(Guid) || property.PropertyType == typeof(Guid?))
-        {
-            if (Guid.TryParse(value.GetText(), out var guid))
-                return guid;
-
-            if (property.PropertyType == typeof(Guid?)) return null;
-            return Guid.Empty;
-        }
+            return HandleGuid(value, property);
 
         if (property.PropertyType.IsEnum)
         {