/// <summary> /// Creates the quantity with the given numeric value and unit. /// </summary> /// <param name="numericValue">The numeric value to contruct this quantity with.</param> /// <param name="unit">The unit representation to contruct this quantity with.</param> /// <exception cref="ArgumentException">If value is NaN or Infinity.</exception> public ReactiveEnergy(double numericValue, ReactiveEnergyUnit unit) { if (unit == ReactiveEnergyUnit.Undefined) { throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); } _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); _unit = unit; }
/// <summary> /// Creates the quantity with the given numeric value and unit. /// </summary> /// <param name="value">The numeric value to construct this quantity with.</param> /// <param name="unit">The unit representation to construct this quantity with.</param> /// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks> /// <exception cref="ArgumentException">If value is NaN or Infinity.</exception> private ReactiveEnergy(double value, ReactiveEnergyUnit unit) { if (unit == ReactiveEnergyUnit.Undefined) { throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); } _value = value; _unit = unit; }
/// <summary> /// Creates an instance of the quantity with the given numeric value in units compatible with the given <see cref="UnitSystem"/>. /// </summary> /// <param name="numericValue">The numeric value to contruct this quantity with.</param> /// <param name="unitSystem">The unit system to create the quantity with.</param> /// <exception cref="ArgumentNullException">The given <see cref="UnitSystem"/> is null.</exception> /// <exception cref="InvalidOperationException">No unit was found for the given <see cref="UnitSystem"/>.</exception> /// <exception cref="InvalidOperationException">More than one unit was found for the given <see cref="UnitSystem"/>.</exception> public ReactiveEnergy(double numericValue, UnitSystem unitSystem) { if (unitSystem == null) { throw new ArgumentNullException(nameof(unitSystem)); } _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); _unit = Info.GetUnitInfoFor(unitSystem.BaseUnits).Value; }
/// <summary> /// Creates an instance of the quantity with the given numeric value in units compatible with the given <see cref="UnitSystem"/>. /// If multiple compatible units were found, the first match is used. /// </summary> /// <param name="numericValue">The numeric value to contruct this quantity with.</param> /// <param name="unitSystem">The unit system to create the quantity with.</param> /// <exception cref="ArgumentNullException">The given <see cref="UnitSystem"/> is null.</exception> /// <exception cref="ArgumentException">No unit was found for the given <see cref="UnitSystem"/>.</exception> public ReactiveEnergy(double numericValue, UnitSystem unitSystem) { if (unitSystem == null) { throw new ArgumentNullException(nameof(unitSystem)); } var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); }
public ReactiveEnergy(double value, UnitSystem unitSystem) { if (unitSystem is null) { throw new ArgumentNullException(nameof(unitSystem)); } _value = Guard.EnsureValidNumber(value, nameof(value)); var defaultUnitInfo = unitSystem.GetDefaultUnitInfo(QuantityType) as UnitInfo <ReactiveEnergyUnit>; _unit = defaultUnitInfo?.Value ?? throw new ArgumentException("No default unit was defined for the given UnitSystem.", nameof(unitSystem)); }
public ReactiveEnergy(decimal value, UnitSystem unitSystem) { if (unitSystem is null) { throw new ArgumentNullException(nameof(unitSystem)); } var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); var firstUnitInfo = unitInfos.FirstOrDefault(); _value = value; _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); }
public ReactiveEnergy(double voltamperereactivehours) { _value = Convert.ToDouble(voltamperereactivehours); _unit = BaseUnit; }
ReactiveEnergy(double numericValue, ReactiveEnergyUnit unit) { _value = numericValue; _unit = unit; }
// Windows Runtime Component requires a default constructor #if WINDOWS_UWP public ReactiveEnergy() { _value = 0; _unit = BaseUnit; }