Piotr Czajkowski 2 周之前
父節點
當前提交
f9642b1ff1
共有 3 個文件被更改,包括 6 次插入3 次删除
  1. 2 2
      ExcelORM/ExcelORM/ExcelWriter.cs
  2. 1 1
      ExcelORM/ExcelORM/Mapping.cs
  3. 3 0
      ExcelORM/ExcelORM/TypeExtensions.cs

+ 2 - 2
ExcelORM/ExcelORM/ExcelWriter.cs

@@ -18,7 +18,7 @@ public class ExcelWriter
         var properties = typeof(T).GetProperties();
         foreach (var property in properties)
         {
-            if (property.GetCustomAttributes(typeof(SkipAttribute), false).FirstOrDefault() != null) continue;
+            if (property.Skip()) continue;
 
             var columnAttribute = property.GetCustomAttributes(typeof(ColumnAttribute), false).FirstOrDefault() as ColumnAttribute;
             worksheet.Cell(rowIndex, cellIndex).Value = columnAttribute is { Names.Length: > 0 } ? columnAttribute.Names.First() : property.Name;
@@ -44,7 +44,7 @@ public class ExcelWriter
             var properties = typeof(T).GetProperties();
             foreach (var property in properties)
             {
-                if (property.GetCustomAttributes(typeof(SkipAttribute), false).FirstOrDefault() != null) continue;
+                if (property.Skip()) continue;
 
                 cellIndex++;
                 var valueToSet = property.GetValue(value);

+ 1 - 1
ExcelORM/ExcelORM/Mapping.cs

@@ -16,7 +16,7 @@ namespace ExcelORM
             var properties = typeof(T).GetProperties();
             foreach (var property in properties)
             {
-                if (property.GetCustomAttributes(typeof(SkipAttribute), false).FirstOrDefault() != null) continue;
+                if (property.Skip()) continue;
 
                 int? position;
 

+ 3 - 0
ExcelORM/ExcelORM/TypeExtensions.cs

@@ -1,5 +1,6 @@
 using System.Reflection;
 using ClosedXML.Excel;
+using ExcelORM.Attributes;
 
 namespace ExcelORM;
 
@@ -50,4 +51,6 @@ public static class TypeExtensions
             property.SetValue(currentObject, valueToSet);
         }
     }
+
+    public static bool Skip(this PropertyInfo property) => property.GetCustomAttributes(typeof(SkipAttribute), false).FirstOrDefault() != null;
 }