Piotr Czajkowski hai 5 meses
pai
achega
7a69a20dbc

+ 2 - 1
ExcelORM/ExcelORM/ExcelReader.cs

@@ -20,6 +20,7 @@ public class ExcelReader
             if (SkipHidden && row.IsHidden) continue;
 
             var current = new T();
+            var type = typeof(T);
             foreach (var item in mapping)
             {
                 if (item.Position == null || item.PropertyName == null) continue;
@@ -27,7 +28,7 @@ public class ExcelReader
                 var cell = row.Cell(item.Position.Value);
                 if (cell == null || cell.Value.IsBlank) continue;
 
-                var property = current.GetType().GetProperty(item.PropertyName);
+                var property = type.GetProperty(item.PropertyName);
                 if (property == null) continue;
 
                 current.SetValue(property, cell);

+ 4 - 4
ExcelORM/ExcelORM/ExcelWriter.cs

@@ -10,11 +10,11 @@ public class ExcelWriter
         xlWorkbook = File.Exists(path) ? new XLWorkbook(path) : new XLWorkbook();
     }
 
-    private static int GenerateHeader<T>(T value, IXLWorksheet worksheet) where T : class, new()
+    private static int GenerateHeader<T>(IXLWorksheet worksheet) where T : class, new()
     {
         var rowIndex = 1;
         var cellIndex = 1;
-        var properties = value.GetType().GetProperties();
+        var properties = typeof(T).GetProperties();
         foreach (var property in properties)
         {
             var columnAttribute = property.GetCustomAttributes(typeof(ColumnAttribute), false).FirstOrDefault() as ColumnAttribute;
@@ -44,13 +44,13 @@ public class ExcelWriter
         var rowIndex = append switch
         {
             true => worksheet.LastRowUsed().RowNumber() + 1,
-            false => GenerateHeader(enumerable.First(), worksheet),
+            false => GenerateHeader<T>(worksheet),
         };
 
         foreach (var value in enumerable)
         {
             var cellIndex = 1;
-            var properties = value.GetType().GetProperties();
+            var properties = typeof(T).GetProperties();
             foreach (var property in properties)
             {
                 worksheet.Cell(rowIndex, cellIndex).Value = property.GetValue(value) as string;

+ 1 - 2
ExcelORM/ExcelORM/Mapping.cs

@@ -11,9 +11,8 @@ namespace ExcelORM
         {
             if (headerCells == null || !headerCells.Any()) return null;
 
-            var objectToRead = new T();
             var map = new List<Mapping>();
-            var properties = objectToRead.GetType().GetProperties();
+            var properties = typeof(T).GetProperties();
             foreach (var property in properties)
             {
                 var position = property.GetCustomAttributes(typeof(ColumnAttribute), false).FirstOrDefault() is ColumnAttribute { Names.Length: > 0 } columnAttribute