ex-int-04-shipping-cost/ShippingCosts/Implementations/Package.cs
2025-05-09 10:25:33 +02:00

42 lines
926 B
C#

using System.Numerics;
using ShippingCosts.Contracts;
namespace ShippingCosts.Implementations;
/// <summary>
/// A package with dimensions and weight
/// </summary>
/// <inheritdoc cref="IMeasuredBox"/>
public sealed class Package : IMeasuredBox
{
private readonly int _width;
private readonly int _height;
private readonly int _depth;
private readonly double _weight;
public int Width
{
get => _width;
init => _width = SanitizeValue(value);
}
public int Height
{
get => _height;
init => _height = SanitizeValue(value);
}
public int Depth
{
get => _depth;
init => _depth = SanitizeValue(value);
}
public double Weight
{
get => _weight;
init => _weight = SanitizeValue(value);
}
private static T SanitizeValue<T>(T value) where T : INumber<T> => value > T.Zero ? value : T.Zero;
}