Browse Source

Stop reinventing the wheel and RTFM (or code)

Piotr Czajkowski 3 months ago
parent
commit
dd7d00aeee
2 changed files with 1 additions and 16 deletions
  1. 1 1
      ExcelORM/ExcelORM/ExcelWriter.cs
  2. 0 15
      ExcelORM/ExcelORM/TypeExtensions.cs

+ 1 - 1
ExcelORM/ExcelORM/ExcelWriter.cs

@@ -57,7 +57,7 @@ public class ExcelWriter
                 var valueToSet = property.GetValue(value);
                 if (valueToSet == null) continue;
                 
-                worksheet.Cell(rowIndex, cellIndex).SetCellValue(property, valueToSet);
+                worksheet.Cell(rowIndex, cellIndex).Value = XLCellValue.FromObject(valueToSet);
                 cellIndex++;
             }
 

+ 0 - 15
ExcelORM/ExcelORM/TypeExtensions.cs

@@ -20,19 +20,4 @@ public static class TypeExtensions
         if (valueToSet != null)
             property.SetValue(currentObject, valueToSet); 
     }
-
-    public static void SetCellValue(this IXLCell cell, PropertyInfo property, object? valueToSet)
-    {
-        if (valueToSet == null) return;
-        
-        cell.Value = property.PropertyType switch
-        {
-            not null when property.PropertyType == typeof(string) => valueToSet as string,
-            not null when property.PropertyType == typeof(DateTime?) => valueToSet as DateTime?,
-            not null when property.PropertyType == typeof(TimeSpan?) => valueToSet as TimeSpan?,
-            not null when property.PropertyType == typeof(double?) => valueToSet as double?,
-            not null when property.PropertyType == typeof(int?) => valueToSet as int?,
-            _ => throw new NotSupportedException($"{property.PropertyType} isn't supported!")
-        };
-    }
 }