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; }
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
public static Measure FromDecimal(decimal quantity, string unit, IUnitLookup unitLookup, int power) => new Measure(quantity, unit, unitLookup, power);