From 094b522644d370e2fdcf3db73d563610b47ef7b4 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Fri, 27 Mar 2026 17:24:15 -0400 Subject: [PATCH] feat: add ColumnAttribute and CellExtensions for BOM parsing --- OpenNest.IO/Bom/CellExtensions.cs | 23 +++++++++++++++++++++++ OpenNest.IO/Bom/ColumnAttribute.cs | 15 +++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 OpenNest.IO/Bom/CellExtensions.cs create mode 100644 OpenNest.IO/Bom/ColumnAttribute.cs diff --git a/OpenNest.IO/Bom/CellExtensions.cs b/OpenNest.IO/Bom/CellExtensions.cs new file mode 100644 index 0000000..8d35afd --- /dev/null +++ b/OpenNest.IO/Bom/CellExtensions.cs @@ -0,0 +1,23 @@ +using ClosedXML.Excel; + +namespace OpenNest.IO.Bom +{ + public static class CellExtensions + { + public static int? ToIntOrNull(this IXLCell cell) + { + if (cell.IsEmpty()) return null; + if (cell.DataType == XLDataType.Number) return (int)cell.GetDouble(); + if (int.TryParse(cell.GetString(), out var i)) return i; + return null; + } + + public static double? ToDoubleOrNull(this IXLCell cell) + { + if (cell.IsEmpty()) return null; + if (cell.DataType == XLDataType.Number) return cell.GetDouble(); + if (double.TryParse(cell.GetString(), out var result)) return result; + return null; + } + } +} diff --git a/OpenNest.IO/Bom/ColumnAttribute.cs b/OpenNest.IO/Bom/ColumnAttribute.cs new file mode 100644 index 0000000..7b1e5a0 --- /dev/null +++ b/OpenNest.IO/Bom/ColumnAttribute.cs @@ -0,0 +1,15 @@ +using System; + +namespace OpenNest.IO.Bom +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + public ColumnAttribute(params string[] names) + { + Names = names; + } + + public string[] Names { get; } + } +}