Browse Source

Let's be modern

Piotr Czajkowski 6 months ago
parent
commit
c626ac5af2
1 changed files with 6 additions and 7 deletions
  1. 6 7
      ExcelORM/ExcelORM/Mapping.cs

+ 6 - 7
ExcelORM/ExcelORM/Mapping.cs

@@ -18,14 +18,13 @@ namespace ExcelORM
             {
                 if (property.Skip()) continue;
 
-                int? position;
-
-                if (property.GetCustomAttributes(typeof(ColumnAttribute), false).FirstOrDefault() is ColumnAttribute { Names.Length: > 0 } attribute)
-                    position = headerCells.FirstOrDefault(x => !x.Value.IsBlank && Array.Exists(attribute.Names,
+                var position = property.GetCustomAttributes(typeof(ColumnAttribute), false).FirstOrDefault() switch
+                {
+                    ColumnAttribute { Names.Length: > 0 } attribute => headerCells.FirstOrDefault(x => !x.Value.IsBlank && Array.Exists(attribute.Names,
                             y => y.Equals(x.Value.ToString(), StringComparison.InvariantCultureIgnoreCase)))?.Address
-                        .ColumnNumber;
-                else
-                    position = headerCells.FirstOrDefault(x => !x.Value.IsBlank && property.Name.Equals(x.Value.ToString(), StringComparison.InvariantCultureIgnoreCase))?.Address.ColumnNumber;
+                        .ColumnNumber,
+                    _ => headerCells.FirstOrDefault(x => !x.Value.IsBlank && property.Name.Equals(x.Value.ToString(), StringComparison.InvariantCultureIgnoreCase))?.Address.ColumnNumber
+                };
 
                 if (position == null) continue;
                 map.Add(new Mapping { PropertyName = property.Name, Position = position });