From 1e168c7e926434006b9a59ecfb838013d6d0afb6 Mon Sep 17 00:00:00 2001 From: AJ Date: Sat, 22 Nov 2025 23:02:49 -0500 Subject: [PATCH] Improve Document model encapsulation and null safety MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add backing fields for PartsToNest and StockBins collections - Ensure collections are never null through property setters - Add read-only views of collections via new properties - Improve XML documentation - Make LastFilePath internally settable for better control 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- CutList/Forms/Document.cs | 41 ++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/CutList/Forms/Document.cs b/CutList/Forms/Document.cs index 5323259..1f93caa 100644 --- a/CutList/Forms/Document.cs +++ b/CutList/Forms/Document.cs @@ -11,19 +11,50 @@ namespace CutList.Forms { public class Document { + private List _partsToNest; + private List _stockBins; + public Document() { - PartsToNest = new List(); - StockBins = new List(); + _partsToNest = new List(); + _stockBins = new List(); } [JsonIgnore] - public string LastFilePath { get; private set; } + public string LastFilePath { get; internal set; } - public List PartsToNest { get; set; } + /// + /// Parts to be nested. For JSON serialization, this exposes the list. + /// For runtime use, prefer using methods to modify the collection. + /// + public List PartsToNest + { + get => _partsToNest; + set => _partsToNest = value ?? new List(); + } - public List StockBins { get; set; } + /// + /// Stock bins available. For JSON serialization, this exposes the list. + /// For runtime use, prefer using methods to modify the collection. + /// + public List StockBins + { + get => _stockBins; + set => _stockBins = value ?? new List(); + } public Tool Tool { get; set; } + + /// + /// Gets a read-only view of parts to nest. + /// + [JsonIgnore] + public IReadOnlyList PartsReadOnly => _partsToNest.AsReadOnly(); + + /// + /// Gets a read-only view of stock bins. + /// + [JsonIgnore] + public IReadOnlyList StockBinsReadOnly => _stockBins.AsReadOnly(); } } \ No newline at end of file