Improve Document model encapsulation and null safety

- 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 <noreply@anthropic.com>
This commit is contained in:
AJ
2025-11-22 23:02:49 -05:00
parent d1a5dd279c
commit 1e168c7e92

View File

@@ -11,19 +11,50 @@ namespace CutList.Forms
{ {
public class Document public class Document
{ {
private List<PartInputItem> _partsToNest;
private List<BinInputItem> _stockBins;
public Document() public Document()
{ {
PartsToNest = new List<PartInputItem>(); _partsToNest = new List<PartInputItem>();
StockBins = new List<BinInputItem>(); _stockBins = new List<BinInputItem>();
} }
[JsonIgnore] [JsonIgnore]
public string LastFilePath { get; private set; } public string LastFilePath { get; internal set; }
public List<PartInputItem> PartsToNest { get; set; } /// <summary>
/// Parts to be nested. For JSON serialization, this exposes the list.
/// For runtime use, prefer using methods to modify the collection.
/// </summary>
public List<PartInputItem> PartsToNest
{
get => _partsToNest;
set => _partsToNest = value ?? new List<PartInputItem>();
}
public List<BinInputItem> StockBins { get; set; } /// <summary>
/// Stock bins available. For JSON serialization, this exposes the list.
/// For runtime use, prefer using methods to modify the collection.
/// </summary>
public List<BinInputItem> StockBins
{
get => _stockBins;
set => _stockBins = value ?? new List<BinInputItem>();
}
public Tool Tool { get; set; } public Tool Tool { get; set; }
/// <summary>
/// Gets a read-only view of parts to nest.
/// </summary>
[JsonIgnore]
public IReadOnlyList<PartInputItem> PartsReadOnly => _partsToNest.AsReadOnly();
/// <summary>
/// Gets a read-only view of stock bins.
/// </summary>
[JsonIgnore]
public IReadOnlyList<BinInputItem> StockBinsReadOnly => _stockBins.AsReadOnly();
} }
} }