Piotr Czajkowski il y a 2 mois
Parent
commit
783fbf07fa

+ 6 - 10
ExcelORM/ExcelORM/ExcelDynamicReader.cs

@@ -35,8 +35,7 @@ public class ExcelDynamicReader : IDisposable
                     continue;
                 }
 
-                if (item.Type == null) item.Type = cell.Value.ValueType();
-
+                item.Type ??= cell.Value.ValueType();
                 var cellItem = item with
                 {
                     Value = cell.Value.ToObject()
@@ -98,15 +97,12 @@ public class ExcelDynamicReader : IDisposable
 
     public IEnumerable<DynamicWorksheet> ReadAll(uint startFrom = 1, uint skip = 0)
     {
-        foreach (var worksheet in xlWorkbook.Worksheets)
+        return xlWorkbook.Worksheets.Select(worksheet => new DynamicWorksheet
         {
-            yield return new DynamicWorksheet
-            {
-                Name = worksheet.Name,
-                Position = worksheet.Position,
-                Cells = Read(worksheet, startFrom, skip)
-            };
-        }
+            Name = worksheet.Name,
+            Position = worksheet.Position,
+            Cells = Read(worksheet, startFrom, skip)
+        });
     }
 
     public void Dispose()

+ 1 - 5
ExcelORM/ExcelORM/ExcelReader.cs

@@ -110,11 +110,7 @@ public class ExcelReader : IDisposable
 
     public IEnumerable<T> ReadAll<T>(uint startFrom = 1, uint skip = 0) where T : class
     {
-        foreach (var worksheet in xlWorkbook.Worksheets)
-        {
-            foreach (var item in Read<T>(worksheet, startFrom, skip))
-                yield return item;
-        }
+        return xlWorkbook.Worksheets.SelectMany(worksheet => Read<T>(worksheet, startFrom, skip));
     }
 
     public void Dispose()

+ 1 - 1
ExcelORM/ExcelORM/ExcelWriter.cs

@@ -56,7 +56,7 @@ public class ExcelWriter : IDisposable
             if (property.Skip()) continue;
 
             var mapped = mapping.FirstOrDefault(x => x.PropertyName != null && x.PropertyName.Equals(property.Name));
-            if (mapped == null || mapped.Position == null) continue;
+            if (mapped?.Position == null) continue;
 
             WriteCell(value, property, worksheet.Cell(rowIndex, mapped.Position.Value));
         }