/// <summary>
        ///     Constructs an instance.
        /// </summary>
        /// <param name="quantityType">The quantity enum value.</param>
        /// <param name="unitInfos">The information about the units for this quantity.</param>
        /// <param name="baseUnit">The base unit enum value.</param>
        /// <param name="zero">The zero quantity.</param>
        /// <param name="baseDimensions">The base dimensions of the quantity.</param>
        /// <exception cref="ArgumentException">Quantity type can not be undefined.</exception>
        /// <exception cref="ArgumentNullException">If units -or- baseUnit -or- zero -or- baseDimensions is null.</exception>
        public QuantityInfo(QuantityType quantityType, [NotNull] UnitInfo[] unitInfos, [NotNull] Enum baseUnit, [NotNull] IQuantity zero, [NotNull] BaseDimensions baseDimensions)
        {
            if (quantityType == QuantityType.Undefined)
            {
                throw new ArgumentException("Quantity type can not be undefined.", nameof(quantityType));
            }
            if (baseUnit == null)
            {
                throw new ArgumentNullException(nameof(baseUnit));
            }

            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));


            Name           = quantityType.ToString();
            QuantityType   = quantityType;
            UnitType       = UnitEnumTypes.First(t => t.Name == $"{quantityType}Unit");
            UnitInfos      = unitInfos ?? throw new ArgumentNullException(nameof(unitInfos));
            BaseUnitInfo   = UnitInfos.First(unitInfo => unitInfo.Value.Equals(baseUnit));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));
            ValueType      = zero.GetType();
            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));

            // Obsolete members
#pragma warning disable 618
            UnitNames = UnitInfos.Select(unitInfo => unitInfo.Name).ToArray();
            Units     = UnitInfos.Select(unitInfo => unitInfo.Value).ToArray();
            BaseUnit  = BaseUnitInfo.Value;
#pragma warning restore 618
        }
示例#2
0
        /// <summary>
        ///     Constructs an instance.
        /// </summary>
        /// <param name="name">Name of the quantity.</param>
        /// <param name="unitInfos">The information about the units for this quantity.</param>
        /// <param name="baseUnit">The base unit enum value.</param>
        /// <param name="zero">The zero quantity.</param>
        /// <param name="baseDimensions">The base dimensions of the quantity.</param>
        /// <param name="quantityType">The the quantity type. Defaults to Undefined.</param>
        /// <exception cref="ArgumentException">Quantity type can not be undefined.</exception>
        /// <exception cref="ArgumentNullException">If units -or- baseUnit -or- zero -or- baseDimensions is null.</exception>
        public QuantityInfo([NotNull] string name, [NotNull] UnitInfo[] unitInfos, [NotNull] Enum baseUnit, [NotNull] IQuantity zero, [NotNull] BaseDimensions baseDimensions,
                            QuantityType quantityType = QuantityType.Undefined)
        {
            if (baseUnit == null)
            {
                throw new ArgumentNullException(nameof(baseUnit));
            }

            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));

            Name           = name;
            UnitType       = UnitEnumTypes.First(t => t.Name == $"{name}Unit");
            UnitInfos      = unitInfos ?? throw new ArgumentNullException(nameof(unitInfos));
            BaseUnitInfo   = UnitInfos.First(unitInfo => unitInfo.Value.Equals(baseUnit));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));
            ValueType      = zero.GetType();
            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));

            // Obsolete members
            UnitNames    = UnitInfos.Select(unitInfo => unitInfo.Name).ToArray();
            Units        = UnitInfos.Select(unitInfo => unitInfo.Value).ToArray();
            BaseUnit     = BaseUnitInfo.Value;
            QuantityType = quantityType;
        }
示例#3
0
        /// <summary>
        ///     Constructs an instance.
        /// </summary>
        /// <param name="name">Name of the quantity.</param>
        /// <param name="unitType">The unit enum type, such as <see cref="LengthUnit" />.</param>
        /// <param name="unitInfos">The information about the units for this quantity.</param>
        /// <param name="baseUnit">The base unit enum value.</param>
        /// <param name="zero">The zero quantity.</param>
        /// <param name="baseDimensions">The base dimensions of the quantity.</param>
        /// <param name="quantityType">The the quantity type. Defaults to Undefined.</param>
        /// <exception cref="ArgumentException">Quantity type can not be undefined.</exception>
        /// <exception cref="ArgumentNullException">If units -or- baseUnit -or- zero -or- baseDimensions is null.</exception>
        public QuantityInfo(string name, Type unitType, UnitInfo[] unitInfos, Enum baseUnit, IQuantity zero, Dimensions baseDimensions,
                            QuantityType quantityType = QuantityType.Undefined)
        {
            if (baseUnit == null)
            {
                throw new ArgumentNullException(nameof(baseUnit));
            }

            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));

            Name           = name ?? throw new ArgumentNullException(nameof(name));
            UnitType       = unitType ?? throw new ArgumentNullException(nameof(unitType));
            UnitInfos      = unitInfos ?? throw new ArgumentNullException(nameof(unitInfos));
            BaseUnitInfo   = UnitInfos.First(unitInfo => unitInfo.Value.Equals(baseUnit));
            Zero           = zero ?? throw new ArgumentNullException(nameof(zero));
            ValueType      = zero.GetType();
            BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions));

            // Obsolete members
            QuantityType = quantityType;
        }