Browse Source

Starting with dynamic

Piotr Czajkowski 2 months ago
parent
commit
ffa0ea667a

+ 2 - 2
ExcelORM/ExcelORM/ExcelORM.csproj

@@ -19,8 +19,8 @@
 
     <ItemGroup>
 	    <PackageReference Include="ClosedXML" Version="0.102.1" />
-	    <None Include="../../README.md" Pack="true" PackagePath="\"/>
-	    <None Include="../../LICENSE" Pack="true" PackagePath=""/>
+	    <None Include="../../README.md" Pack="true" PackagePath="\" />
+	    <None Include="../../LICENSE" Pack="true" PackagePath="" />
     </ItemGroup>
 
 </Project>

+ 10 - 0
ExcelORM/ExcelORM/Models/DynamicCell.cs

@@ -0,0 +1,10 @@
+namespace ExcelORM.Models
+{
+    public record DynamicCell
+    {
+        public int Position { get; set; }
+        public string? Header { get; set; }
+        public Type? Type { get; set; }
+        public object? Value { get; set; }
+    }
+}

+ 15 - 1
ExcelORM/ExcelORM/TypeExtensions.cs

@@ -3,9 +3,9 @@ using ClosedXML.Excel;
 
 namespace ExcelORM;
 
-// Borrowed from https://github.com/ClosedXML/ClosedXML/blob/develop/ClosedXML/Excel/XLCellValue.cs#L361
 public static class TypeExtensions
 {
+    // Borrowed from https://github.com/ClosedXML/ClosedXML/blob/develop/ClosedXML/Excel/XLCellValue.cs#L361
     private static object? ToObject(this XLCellValue value)
     {
         return value.Type switch
@@ -21,6 +21,20 @@ public static class TypeExtensions
         };
     }
 
+    private static Type ValueType(this XLCellValue value)
+    {
+        return value.Type switch
+        {
+            XLDataType.Blank => typeof(string),
+            XLDataType.Boolean => typeof(bool),
+            XLDataType.Number => typeof(double?),
+            XLDataType.Text => typeof(string),
+            XLDataType.DateTime => typeof(DateTime?),
+            XLDataType.TimeSpan => typeof(TimeSpan?),
+            _ => throw new InvalidCastException()
+        };
+    }
+
     public static void SetPropertyValue<T>(this T currentObject, PropertyInfo property, XLCellValue value)
     {
         var valueToSet = value.ToObject();