Explorar o código

Makes more sense

Piotr Czajkowski hai 1 semana
pai
achega
646ac12475

+ 1 - 1
ExcelORM/ExcelORM/ExcelReader.cs

@@ -73,7 +73,7 @@ public sealed class ExcelReader : IDisposable
         if (firstRow == null || firstRow.IsEmpty()) yield break;
 
         var mapping = Mapping.MapProperties<T>(firstRow.CellsUsed(), FallbackToPropertyName);
-        if (mapping == null) yield break;
+        if (mapping.Count == 0) yield break;
 
         var rowsToProcess = (ObeyFilter && worksheet.AutoFilter.IsEnabled) switch
         {

+ 1 - 1
ExcelORM/ExcelORM/ExcelWriter.cs

@@ -102,7 +102,7 @@ public sealed class ExcelWriter : IDisposable
         {
             var headerCells = headerRowIndex != null ? worksheet.Row((int)headerRowIndex).CellsUsed() : worksheet.FirstRowUsed()?.CellsUsed();
             mapping = Mapping.MapProperties<T>(headerCells, FallbackToPropertyName);
-            if (mapping == null || mapping.Count == 0) return;
+            if (mapping.Count == 0) return;
         }
 
         foreach (var value in values)

+ 4 - 4
ExcelORM/ExcelORM/Mapping.cs

@@ -31,11 +31,11 @@ namespace ExcelORM
                 .ColumnNumber;
         }
         
-        public static List<Mapping>? MapProperties<T>(IXLCells? headerCells, bool fallbackToPropertyName = false) where T : class
+        public static List<Mapping> MapProperties<T>(IXLCells? headerCells, bool fallbackToPropertyName = false) where T : class
         {
-            if (headerCells == null || !headerCells.Any()) return null;
-
             var map = new List<Mapping>();
+            if (headerCells == null || !headerCells.Any()) return map;
+
             var properties = typeof(T).GetProperties();
             foreach (var property in properties)
             {
@@ -47,7 +47,7 @@ namespace ExcelORM
                 map.Add(new Mapping { PropertyName = property.Name, Position = position });
             }
 
-            return map.Count > 0 ? map : null;
+            return map;
         }
     }
 }