Piotr Czajkowski 6 months ago
parent
commit
f9642b1ff1

+ 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;
 }