Ejemplo n.º 1
0
        new Measure(decimal.Parse(quantity), unit, unitLookup, power);     //Warning : Beware of System.Globalization.CultureInfo.CurrentCulture

        protected Measure(decimal quantity, string unitCode, IUnitLookup unitLookup, int power)
        {
            if (string.IsNullOrEmpty(unitCode))
            {
                throw new ArgumentNullException(
                          nameof(unitCode), "Unit code must be specified");
            }

            var unit = unitLookup.FindUnit(unitCode);

            if (!unit.InUse)
            {
                throw new ArgumentException($"Unit {unitCode} is not valid");
            }

            if (decimal.Round(quantity, unit.DecimalPositions) != quantity)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(quantity),
                          $"Quantity in {unitCode} cannot have more than {unit.DecimalPositions} decimals");
            }

            Quantity = quantity;
            Unit     = unit;
            Power    = power;
        }
Ejemplo n.º 2
0
 public static Measure FromString(string quantity, string unit,
                                  IUnitLookup unitLookup, int power) =>
 new Measure(decimal.Parse(quantity), unit, unitLookup, power);     //Warning : Beware of System.Globalization.CultureInfo.CurrentCulture
Ejemplo n.º 3
0
 public static Measure FromDecimal(decimal quantity, string unit,
                                   IUnitLookup unitLookup, int power) =>
 new Measure(quantity, unit, unitLookup, power);