2using System.Xml.Serialization;
18[XmlType(TypeName =
"inventory")]
23 private double _initialInventory;
50 double initialInventory = 0.0)
73 int standaloneWarehouseId,
74 double initialInventory = 0.0)
80 standaloneWarehouseId),
100 double initialInventory = 0.0)
113 [XmlAttribute(
"itemId")]
122 throw new ArgumentOutOfRangeException(
125 "The item identifier cannot be negative.");
129 SetProperty(ref _itemId, value);
139 [XmlElement(
"warehouse")]
146 ArgumentNullException.ThrowIfNull(value);
149 if (SetProperty(ref _warehouse, value))
162 [XmlAttribute(
"initialInventory")]
165 get => _initialInventory;
169 ValidateNonNegativeFiniteValue(
175 ref _initialInventory,
207 return other is not
null
209 && Warehouse.Kind == other.Warehouse.Kind
210 && Warehouse.ReferenceId ==
230 ArgumentNullException.ThrowIfNull(warehouse);
233 return Warehouse.Kind == warehouse.Kind
234 && Warehouse.ReferenceId ==
246 private static void ValidateNonNegativeFiniteValue(
248 string parameterName)
251 if (
double.IsNaN(value) ||
252 double.IsInfinity(value))
254 throw new ArgumentOutOfRangeException(
257 "The initial inventory must be a finite number.");
263 throw new ArgumentOutOfRangeException(
266 "The initial inventory cannot be negative.");
Base class for model objects that notify listeners when one of their properties changes.
Represents a serializable reference to a warehouse.
int ReferenceId
Gets or sets the referenced identifier.
static WarehouseReference ForPlantWarehouse(int plantId)
Creates a reference to the warehouse attached to a plant.
static WarehouseReference ForStandaloneWarehouse(int warehouseId)
Creates a reference to a standalone warehouse.
WarehouseReferenceKind WarehouseKind
Gets the kind of referenced warehouse.
Inventory()
Initializes an empty inventory association.
static Inventory ForPlantWarehouse(int itemId, int plantId, double initialInventory=0.0)
Initializes an inventory association for an item stored in a warehouse attached to a plant.
Inventory(int itemId, WarehouseReference warehouse, double initialInventory=0.0)
Initializes an inventory association.
int ItemId
Gets or sets the identifier of the item stored in the warehouse.
bool ConcernsWarehouse(WarehouseReference warehouse)
Determines whether this inventory concerns the specified warehouse.
WarehouseReference Warehouse
Gets or sets the warehouse storing the item.
static Inventory ForStandaloneWarehouse(int itemId, int standaloneWarehouseId, double initialInventory=0.0)
Initializes an inventory association for an item stored in a standalone warehouse.
double InitialInventory
Gets or sets the initial inventory level.
int WarehouseReferenceId
Gets the identifier used to reference the warehouse.
bool ConcernsItem(int itemId)
Determines whether this inventory concerns the specified item.
bool RefersToSameInventory(Inventory? other)
Determines whether this object represents the same item/warehouse association as another inventory ob...
WarehouseReferenceKind
Identifies the type of warehouse referenced by a relationship.