Exemplo n.º 1
0
        public ElectricResistance(double value, ElectricResistanceUnit unit)
        {
            if (unit == ElectricResistanceUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = Guard.EnsureValidNumber(value, nameof(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 ElectricResistance(double numericValue, UnitSystem unitSystem)
        {
            if (unitSystem == null)
            {
                throw new ArgumentNullException(nameof(unitSystem));
            }

            _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
            _unit  = Info.GetUnitInfoFor(unitSystem.BaseUnits).Value;
        }
Exemplo n.º 3
0
        public ElectricResistance(decimal value, ElectricResistanceUnit unit)
        {
            if (unit == ElectricResistanceUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = value;
            _unit  = unit;
        }
Exemplo n.º 4
0
        public ElectricResistance(double value, UnitSystem unitSystem)
        {
            if (unitSystem is null)
            {
                throw new ArgumentNullException(nameof(unitSystem));
            }

            var unitInfos     = Info.GetUnitInfosFor(unitSystem.BaseUnits);
            var firstUnitInfo = unitInfos.FirstOrDefault();

            _value = Guard.EnsureValidNumber(value, nameof(value));
            _unit  = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem));
        }
Exemplo n.º 5
0
        public ElectricResistance(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 <ElectricResistanceUnit>;

            _unit = defaultUnitInfo?.Value ?? throw new ArgumentException("No default unit was defined for the given UnitSystem.", nameof(unitSystem));
        }
Exemplo n.º 6
0
        /// <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 ElectricResistance(double numericValue, UnitSystem unitSystem)
        {
            if (unitSystem == null)
            {
                throw new ArgumentNullException(nameof(unitSystem));
            }

            var unitInfos     = Info.GetUnitInfosFor(unitSystem.BaseUnits);
            var firstUnitInfo = unitInfos.FirstOrDefault(u => u.Value.Equals(BaseUnit));

            // for custom units, sometimes we don't find the base unit, this grabs the first off the list.
            if (Equals(firstUnitInfo, null))
            {
                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));
        }
Exemplo n.º 7
0
 /// <summary>
 ///     Creates the quantity with a value of 0 in the base unit Ohm.
 /// </summary>
 /// <remarks>
 ///     Windows Runtime Component requires a default constructor.
 /// </remarks>
 public ElectricResistance()
 {
     _value = 0;
     _unit  = BaseUnit;
 }
Exemplo n.º 8
0
 public ElectricResistance(double ohms)
 {
     _value = Convert.ToDouble(ohms);
     _unit  = BaseUnit;
 }
Exemplo n.º 9
0
 ElectricResistance(double numericValue, ElectricResistanceUnit unit)
 {
     _value = numericValue;
     _unit  = unit;
 }