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:
@@ -11,19 +11,50 @@ namespace CutList.Forms
|
||||
{
|
||||
public class Document
|
||||
{
|
||||
private List<PartInputItem> _partsToNest;
|
||||
private List<BinInputItem> _stockBins;
|
||||
|
||||
public Document()
|
||||
{
|
||||
PartsToNest = new List<PartInputItem>();
|
||||
StockBins = new List<BinInputItem>();
|
||||
_partsToNest = new List<PartInputItem>();
|
||||
_stockBins = new List<BinInputItem>();
|
||||
}
|
||||
|
||||
[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; }
|
||||
|
||||
/// <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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user