LotSizingDataModel.Core 2.0.1
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
WorkCenterReference.cs
Go to the documentation of this file.
1using System;
2using System.Xml.Serialization;
4
6
7/// <summary>
8/// Represents a serializable reference to a work center.
9///
10/// A work center is identified by:
11/// - the identifier of its owning plant;
12/// - its identifier inside that plant.
13///
14/// This class avoids duplicating complete Plant and WorkCenter objects
15/// inside association classes.
16/// </summary>
17[Serializable]
18[XmlType(TypeName = "workCenterReference")]
19public sealed class WorkCenterReference : ModelObject
20{
21 private int _plantId;
22 private int _workCenterId;
23
24 /// <summary>
25 /// Initializes an empty work-center reference.
26 ///
27 /// This public parameterless constructor is required
28 /// by <see cref="XmlSerializer"/>.
29 /// </summary>
31 {
32 }
33
34 /// <summary>
35 /// Initializes a work-center reference.
36 /// </summary>
37 /// <param name="plantId">
38 /// Identifier of the plant owning the work center.
39 /// </param>
40 /// <param name="workCenterId">
41 /// Identifier of the work center inside the plant.
42 /// </param>
44 int plantId,
45 int workCenterId)
46 {
47 // Initialize work center reference properties (validation occurs in setters)
48 PlantId = plantId;
49 WorkCenterId = workCenterId;
50 }
51
52 /// <summary>
53 /// Gets or sets the identifier of the plant
54 /// owning the referenced work center.
55 /// </summary>
56 [XmlAttribute("plantId")]
57 public int PlantId
58 {
59 get => _plantId;
60 set
61 {
62 // Validate that the plant identifier is non-negative
63 if (value < 0)
64 {
65 throw new ArgumentOutOfRangeException(
66 nameof(value),
67 value,
68 "The plant identifier cannot be negative.");
69 }
70
71 // Update the backing field and notify property change if value differs
72 SetProperty(ref _plantId, value);
73 }
74 }
75
76 /// <summary>
77 /// Gets or sets the identifier of the referenced work center.
78 /// </summary>
79 [XmlAttribute("workCenterId")]
80 public int WorkCenterId
81 {
82 get => _workCenterId;
83 set
84 {
85 // Validate that the work center identifier is non-negative
86 if (value < 0)
87 {
88 throw new ArgumentOutOfRangeException(
89 nameof(value),
90 value,
91 "The work-center identifier cannot be negative.");
92 }
93
94 // Update the backing field and notify property change if value differs
95 SetProperty(ref _workCenterId, value);
96 }
97 }
98
99 /// <summary>
100 /// Determines whether this reference identifies the same
101 /// work center as another reference.
102 /// </summary>
104 WorkCenterReference? other)
105 {
106 // Compare both plant ID and work center ID for equality
107 return other is not null
108 && PlantId == other.PlantId
109 && WorkCenterId == other.WorkCenterId;
110 }
111
112 /// <summary>
113 /// Returns a readable representation of the reference.
114 /// </summary>
115 public override string ToString()
116 {
117 return $"Plant:{PlantId}/WorkCenter:{WorkCenterId}";
118 }
119}
Base class for model objects that notify listeners when one of their properties changes.
int PlantId
Gets or sets the identifier of the plant owning the referenced work center.
WorkCenterReference(int plantId, int workCenterId)
Initializes a work-center reference.
override string ToString()
Returns a readable representation of the reference.
bool RefersToSameWorkCenter(WorkCenterReference? other)
Determines whether this reference identifies the same work center as another reference.
WorkCenterReference()
Initializes an empty work-center reference.
int WorkCenterId
Gets or sets the identifier of the referenced work center.