protected Dimension(double value, UnitOfMeasure unitOfMeasure) { Guard.NotNull(unitOfMeasure, "unitOfMeasure"); _dimensionType = unitOfMeasure.DimensionType; _currentValue = value; _currentUnits = unitOfMeasure; _baseUnitsValue = _currentUnits.UnitConverter.ToBaseUnit(value); }
public void Add(UnitOfMeasure unitOfMeasure) { try { _byAbbreviation.Add(unitOfMeasure.Abbreviation, unitOfMeasure); _byName.Add(unitOfMeasure.Name, unitOfMeasure); _byValue.Add(unitOfMeasure.EnumValue, unitOfMeasure); } catch (Exception) { string message = string.Format("UoM: {0} {1} ({2})", unitOfMeasure.Name, unitOfMeasure.Abbreviation, unitOfMeasure.EnumValue); Debug.WriteLine(message); throw; } }
protected string ToString(UnitOfMeasure desiredUnits, int precision) { string format = "{0:N[pre]} {1}".Replace("[pre]", precision.ToString(CultureInfo.InvariantCulture)); return string.Format(format, In(desiredUnits), desiredUnits.Abbreviation); }
protected string ToString(UnitOfMeasure desiredUnits) { desiredUnits.DimensionType.ShouldBe(_dimensionType); return string.Format("{0} {1}", In(desiredUnits), desiredUnits.Abbreviation); }
/// <summary> /// Gets the current value in the desired units. The object's value is not changed. /// </summary> /// <param name="desiredUnits">The desired units.</param> /// <returns></returns> protected double In(UnitOfMeasure desiredUnits) { desiredUnits.DimensionType.ShouldBe(_dimensionType); return (_currentUnits == desiredUnits) ? _currentValue : desiredUnits.UnitConverter.FromBaseUnit(_baseUnitsValue); }
public ResultViewModel(UnitOfMeasure units) { _units = units; }