public void Masscompare() { UnitsNet.Mass L1 = new UnitsNet.Mass(5674.889, UnitsNet.Units.MassUnit.Kilogram); EngineeringUnits.Mass L2 = new EngineeringUnits.Mass(5674.889, EngineeringUnits.MassUnit.Kilogram); //UnitsNet has some small numerical-error that show off as big in small units like Nanometer Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Centigram) - L1.As(UnitsNet.Units.MassUnit.Centigram), 0); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Decigram) - L1.As(UnitsNet.Units.MassUnit.Decigram), 0); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Decagram) - L1.As(UnitsNet.Units.MassUnit.Decagram), 0); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.EarthMass) - L1.As(UnitsNet.Units.MassUnit.EarthMass), 9.5E-20); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Grain) - L1.As(UnitsNet.Units.MassUnit.Grain), 0); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Gram) - L1.As(UnitsNet.Units.MassUnit.Gram), 0); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Hectogram) - L1.As(UnitsNet.Units.MassUnit.Hectogram), 0); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Kilogram) - L1.As(UnitsNet.Units.MassUnit.Kilogram), 0); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Microgram) - L1.As(UnitsNet.Units.MassUnit.Microgram), 0); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Milligram) - L1.As(UnitsNet.Units.MassUnit.Milligram), 0); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Nanogram) - L1.As(UnitsNet.Units.MassUnit.Nanogram), 0); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Ounce) - L1.As(UnitsNet.Units.MassUnit.Ounce), 0.0003); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Pound) - L1.As(UnitsNet.Units.MassUnit.Pound), 1.9E-12); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.ShortTon) - L1.As(UnitsNet.Units.MassUnit.ShortTon), 0); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Stone) - L1.As(UnitsNet.Units.MassUnit.Stone), 0.0008); Assert.AreEqual(0, L2.As(EngineeringUnits.MassUnit.Tonne) - L1.As(UnitsNet.Units.MassUnit.Tonne), 0); //Assert.AreEqual(0, UnitsNet.Length.FromKilometers(435).Meters - EngineeringUnits.Length.FromKilometers(435).Meters, 0); }
public void MassCompareAutoTest() { UnitsNet.Mass A1 = new UnitsNet.Mass(65.743, UnitsNet.Units.MassUnit.Kilogram); EngineeringUnits.Mass A2 = new EngineeringUnits.Mass(65.743, EngineeringUnits.MassUnit.Kilogram); var EU11 = EngineeringUnits.MassUnit.List(); var UN11 = UnitsNet.Mass.Units; int DiffCount = 0; for (int i = 0; i < UnitsNet.Mass.Units.Length; i++) { if (UnitsNet.Mass.Units[i] == UnitsNet.Units.MassUnit.SolarMass) { DiffCount++; continue; } //Getting Units var EU = EngineeringUnits.MassUnit.List().ToList()[i - DiffCount]; var UN = UnitsNet.Mass.Units[i]; //All units absolute difference Assert.AreEqual(0, A2.As(EU) - A1.As(UN), 0.008); //All units relative difference Assert.AreEqual(0, HelperClass.Percent(A2.As(EU), A1.As(UN)), 1E-3); //All units symbol compare Assert.AreEqual(A2.ToUnit(EU).DisplaySymbol(), A1.ToUnit(UN).ToString("a")); } }
public static Mass operator *(TimeSpan time, MassFlow massFlow) { return(Mass.FromKilograms(massFlow.KilogramsPerSecond * time.TotalSeconds)); }
/// <summary>Get <see cref="Mass"/> from <see cref="Force"/> divided by <see cref="Acceleration"/>.</summary> public static Mass operator /(Force force, Acceleration acceleration) { return(Mass.FromKilograms(force.Newtons / acceleration.MetersPerSecondSquared)); }
/// <summary>Get <see cref="Force"/> from <see cref="Mass"/> times <see cref="Acceleration"/>.</summary> public static Force FromMassByAcceleration(Mass mass, Acceleration acceleration) { return(new Force(mass.Kilograms * acceleration.MetersPerSecondSquared, ForceUnit.Newton)); }
/// <summary> /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". /// </summary> /// <param name="str">String to parse. Typically in the form: {number} {unit}</param> /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="UnitSystem" />'s default culture.</param> /// <param name="result">Resulting unit quantity if successful.</param> /// <example> /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// </example> public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Mass result) { try { result = Parse(str, cultureName); return(true); } catch { result = default(Mass); return(false); } }
/// <summary> /// Try to dynamically construct a quantity. /// </summary> /// <param name="value">Numeric value.</param> /// <param name="unit">Unit enum value.</param> /// <param name="quantity">The resulting quantity if successful, otherwise <c>default</c>.</param> /// <returns><c>True</c> if successful with <paramref name="quantity"/> assigned the value, otherwise <c>false</c>.</returns> internal static bool TryFrom(double value, Enum unit, out IQuantity quantity) { switch (unit) { case AccelerationUnit accelerationUnit: quantity = Acceleration.From(value, accelerationUnit); return(true); case AmountOfSubstanceUnit amountOfSubstanceUnit: quantity = AmountOfSubstance.From(value, amountOfSubstanceUnit); return(true); case AmplitudeRatioUnit amplitudeRatioUnit: quantity = AmplitudeRatio.From(value, amplitudeRatioUnit); return(true); case AngleUnit angleUnit: quantity = Angle.From(value, angleUnit); return(true); case ApparentEnergyUnit apparentEnergyUnit: quantity = ApparentEnergy.From(value, apparentEnergyUnit); return(true); case ApparentPowerUnit apparentPowerUnit: quantity = ApparentPower.From(value, apparentPowerUnit); return(true); case AreaUnit areaUnit: quantity = Area.From(value, areaUnit); return(true); case AreaDensityUnit areaDensityUnit: quantity = AreaDensity.From(value, areaDensityUnit); return(true); case AreaMomentOfInertiaUnit areaMomentOfInertiaUnit: quantity = AreaMomentOfInertia.From(value, areaMomentOfInertiaUnit); return(true); case BitRateUnit bitRateUnit: quantity = BitRate.From(value, bitRateUnit); return(true); case BrakeSpecificFuelConsumptionUnit brakeSpecificFuelConsumptionUnit: quantity = BrakeSpecificFuelConsumption.From(value, brakeSpecificFuelConsumptionUnit); return(true); case CapacitanceUnit capacitanceUnit: quantity = Capacitance.From(value, capacitanceUnit); return(true); case CoefficientOfThermalExpansionUnit coefficientOfThermalExpansionUnit: quantity = CoefficientOfThermalExpansion.From(value, coefficientOfThermalExpansionUnit); return(true); case DensityUnit densityUnit: quantity = Density.From(value, densityUnit); return(true); case DurationUnit durationUnit: quantity = Duration.From(value, durationUnit); return(true); case DynamicViscosityUnit dynamicViscosityUnit: quantity = DynamicViscosity.From(value, dynamicViscosityUnit); return(true); case ElectricAdmittanceUnit electricAdmittanceUnit: quantity = ElectricAdmittance.From(value, electricAdmittanceUnit); return(true); case ElectricChargeUnit electricChargeUnit: quantity = ElectricCharge.From(value, electricChargeUnit); return(true); case ElectricChargeDensityUnit electricChargeDensityUnit: quantity = ElectricChargeDensity.From(value, electricChargeDensityUnit); return(true); case ElectricConductanceUnit electricConductanceUnit: quantity = ElectricConductance.From(value, electricConductanceUnit); return(true); case ElectricConductivityUnit electricConductivityUnit: quantity = ElectricConductivity.From(value, electricConductivityUnit); return(true); case ElectricCurrentUnit electricCurrentUnit: quantity = ElectricCurrent.From(value, electricCurrentUnit); return(true); case ElectricCurrentDensityUnit electricCurrentDensityUnit: quantity = ElectricCurrentDensity.From(value, electricCurrentDensityUnit); return(true); case ElectricCurrentGradientUnit electricCurrentGradientUnit: quantity = ElectricCurrentGradient.From(value, electricCurrentGradientUnit); return(true); case ElectricFieldUnit electricFieldUnit: quantity = ElectricField.From(value, electricFieldUnit); return(true); case ElectricInductanceUnit electricInductanceUnit: quantity = ElectricInductance.From(value, electricInductanceUnit); return(true); case ElectricPotentialUnit electricPotentialUnit: quantity = ElectricPotential.From(value, electricPotentialUnit); return(true); case ElectricPotentialAcUnit electricPotentialAcUnit: quantity = ElectricPotentialAc.From(value, electricPotentialAcUnit); return(true); case ElectricPotentialChangeRateUnit electricPotentialChangeRateUnit: quantity = ElectricPotentialChangeRate.From(value, electricPotentialChangeRateUnit); return(true); case ElectricPotentialDcUnit electricPotentialDcUnit: quantity = ElectricPotentialDc.From(value, electricPotentialDcUnit); return(true); case ElectricResistanceUnit electricResistanceUnit: quantity = ElectricResistance.From(value, electricResistanceUnit); return(true); case ElectricResistivityUnit electricResistivityUnit: quantity = ElectricResistivity.From(value, electricResistivityUnit); return(true); case ElectricSurfaceChargeDensityUnit electricSurfaceChargeDensityUnit: quantity = ElectricSurfaceChargeDensity.From(value, electricSurfaceChargeDensityUnit); return(true); case EnergyUnit energyUnit: quantity = Energy.From(value, energyUnit); return(true); case EntropyUnit entropyUnit: quantity = Entropy.From(value, entropyUnit); return(true); case ForceUnit forceUnit: quantity = Force.From(value, forceUnit); return(true); case ForceChangeRateUnit forceChangeRateUnit: quantity = ForceChangeRate.From(value, forceChangeRateUnit); return(true); case ForcePerLengthUnit forcePerLengthUnit: quantity = ForcePerLength.From(value, forcePerLengthUnit); return(true); case FrequencyUnit frequencyUnit: quantity = Frequency.From(value, frequencyUnit); return(true); case FuelEfficiencyUnit fuelEfficiencyUnit: quantity = FuelEfficiency.From(value, fuelEfficiencyUnit); return(true); case HeatFluxUnit heatFluxUnit: quantity = HeatFlux.From(value, heatFluxUnit); return(true); case HeatTransferCoefficientUnit heatTransferCoefficientUnit: quantity = HeatTransferCoefficient.From(value, heatTransferCoefficientUnit); return(true); case IlluminanceUnit illuminanceUnit: quantity = Illuminance.From(value, illuminanceUnit); return(true); case InformationUnit informationUnit: quantity = Information.From(value, informationUnit); return(true); case IrradianceUnit irradianceUnit: quantity = Irradiance.From(value, irradianceUnit); return(true); case IrradiationUnit irradiationUnit: quantity = Irradiation.From(value, irradiationUnit); return(true); case KinematicViscosityUnit kinematicViscosityUnit: quantity = KinematicViscosity.From(value, kinematicViscosityUnit); return(true); case LapseRateUnit lapseRateUnit: quantity = LapseRate.From(value, lapseRateUnit); return(true); case LengthUnit lengthUnit: quantity = Length.From(value, lengthUnit); return(true); case LevelUnit levelUnit: quantity = Level.From(value, levelUnit); return(true); case LinearDensityUnit linearDensityUnit: quantity = LinearDensity.From(value, linearDensityUnit); return(true); case LinearPowerDensityUnit linearPowerDensityUnit: quantity = LinearPowerDensity.From(value, linearPowerDensityUnit); return(true); case LuminosityUnit luminosityUnit: quantity = Luminosity.From(value, luminosityUnit); return(true); case LuminousFluxUnit luminousFluxUnit: quantity = LuminousFlux.From(value, luminousFluxUnit); return(true); case LuminousIntensityUnit luminousIntensityUnit: quantity = LuminousIntensity.From(value, luminousIntensityUnit); return(true); case MagneticFieldUnit magneticFieldUnit: quantity = MagneticField.From(value, magneticFieldUnit); return(true); case MagneticFluxUnit magneticFluxUnit: quantity = MagneticFlux.From(value, magneticFluxUnit); return(true); case MagnetizationUnit magnetizationUnit: quantity = Magnetization.From(value, magnetizationUnit); return(true); case MassUnit massUnit: quantity = Mass.From(value, massUnit); return(true); case MassConcentrationUnit massConcentrationUnit: quantity = MassConcentration.From(value, massConcentrationUnit); return(true); case MassFlowUnit massFlowUnit: quantity = MassFlow.From(value, massFlowUnit); return(true); case MassFluxUnit massFluxUnit: quantity = MassFlux.From(value, massFluxUnit); return(true); case MassFractionUnit massFractionUnit: quantity = MassFraction.From(value, massFractionUnit); return(true); case MassMomentOfInertiaUnit massMomentOfInertiaUnit: quantity = MassMomentOfInertia.From(value, massMomentOfInertiaUnit); return(true); case MolarEnergyUnit molarEnergyUnit: quantity = MolarEnergy.From(value, molarEnergyUnit); return(true); case MolarEntropyUnit molarEntropyUnit: quantity = MolarEntropy.From(value, molarEntropyUnit); return(true); case MolarFlowUnit molarFlowUnit: quantity = MolarFlow.From(value, molarFlowUnit); return(true); case MolarityUnit molarityUnit: quantity = Molarity.From(value, molarityUnit); return(true); case MolarMassUnit molarMassUnit: quantity = MolarMass.From(value, molarMassUnit); return(true); case MolarMaximumRateOfReactionUnit molarMaximumRateOfReactionUnit: quantity = MolarMaximumRateOfReaction.From(value, molarMaximumRateOfReactionUnit); return(true); case PermeabilityUnit permeabilityUnit: quantity = Permeability.From(value, permeabilityUnit); return(true); case PermittivityUnit permittivityUnit: quantity = Permittivity.From(value, permittivityUnit); return(true); case PowerUnit powerUnit: quantity = Power.From(value, powerUnit); return(true); case PowerDensityUnit powerDensityUnit: quantity = PowerDensity.From(value, powerDensityUnit); return(true); case PowerRatioUnit powerRatioUnit: quantity = PowerRatio.From(value, powerRatioUnit); return(true); case PressureUnit pressureUnit: quantity = Pressure.From(value, pressureUnit); return(true); case PressureChangeRateUnit pressureChangeRateUnit: quantity = PressureChangeRate.From(value, pressureChangeRateUnit); return(true); case RatioUnit ratioUnit: quantity = Ratio.From(value, ratioUnit); return(true); case RatioChangeRateUnit ratioChangeRateUnit: quantity = RatioChangeRate.From(value, ratioChangeRateUnit); return(true); case ReactiveEnergyUnit reactiveEnergyUnit: quantity = ReactiveEnergy.From(value, reactiveEnergyUnit); return(true); case ReactivePowerUnit reactivePowerUnit: quantity = ReactivePower.From(value, reactivePowerUnit); return(true); case RelativeHumidityUnit relativeHumidityUnit: quantity = RelativeHumidity.From(value, relativeHumidityUnit); return(true); case RotationalAccelerationUnit rotationalAccelerationUnit: quantity = RotationalAcceleration.From(value, rotationalAccelerationUnit); return(true); case RotationalSpeedUnit rotationalSpeedUnit: quantity = RotationalSpeed.From(value, rotationalSpeedUnit); return(true); case RotationalStiffnessUnit rotationalStiffnessUnit: quantity = RotationalStiffness.From(value, rotationalStiffnessUnit); return(true); case RotationalStiffnessPerLengthUnit rotationalStiffnessPerLengthUnit: quantity = RotationalStiffnessPerLength.From(value, rotationalStiffnessPerLengthUnit); return(true); case ScalarUnit scalarUnit: quantity = Scalar.From(value, scalarUnit); return(true); case SolidAngleUnit solidAngleUnit: quantity = SolidAngle.From(value, solidAngleUnit); return(true); case SpecificEnergyUnit specificEnergyUnit: quantity = SpecificEnergy.From(value, specificEnergyUnit); return(true); case SpecificEntropyUnit specificEntropyUnit: quantity = SpecificEntropy.From(value, specificEntropyUnit); return(true); case SpecificVolumeUnit specificVolumeUnit: quantity = SpecificVolume.From(value, specificVolumeUnit); return(true); case SpecificWeightUnit specificWeightUnit: quantity = SpecificWeight.From(value, specificWeightUnit); return(true); case SpeedUnit speedUnit: quantity = Speed.From(value, speedUnit); return(true); case StandardVolumeFlowUnit standardVolumeFlowUnit: quantity = StandardVolumeFlow.From(value, standardVolumeFlowUnit); return(true); case TemperatureUnit temperatureUnit: quantity = Temperature.From(value, temperatureUnit); return(true); case TemperatureChangeRateUnit temperatureChangeRateUnit: quantity = TemperatureChangeRate.From(value, temperatureChangeRateUnit); return(true); case TemperatureDeltaUnit temperatureDeltaUnit: quantity = TemperatureDelta.From(value, temperatureDeltaUnit); return(true); case ThermalConductivityUnit thermalConductivityUnit: quantity = ThermalConductivity.From(value, thermalConductivityUnit); return(true); case ThermalResistanceUnit thermalResistanceUnit: quantity = ThermalResistance.From(value, thermalResistanceUnit); return(true); case TorqueUnit torqueUnit: quantity = Torque.From(value, torqueUnit); return(true); case TorquePerLengthUnit torquePerLengthUnit: quantity = TorquePerLength.From(value, torquePerLengthUnit); return(true); case TurbidityUnit turbidityUnit: quantity = Turbidity.From(value, turbidityUnit); return(true); case VitaminAUnit vitaminAUnit: quantity = VitaminA.From(value, vitaminAUnit); return(true); case VolumeUnit volumeUnit: quantity = Volume.From(value, volumeUnit); return(true); case VolumeConcentrationUnit volumeConcentrationUnit: quantity = VolumeConcentration.From(value, volumeConcentrationUnit); return(true); case VolumeFlowUnit volumeFlowUnit: quantity = VolumeFlow.From(value, volumeFlowUnit); return(true); case VolumePerLengthUnit volumePerLengthUnit: quantity = VolumePerLength.From(value, volumePerLengthUnit); return(true); case WarpingMomentOfInertiaUnit warpingMomentOfInertiaUnit: quantity = WarpingMomentOfInertia.From(value, warpingMomentOfInertiaUnit); return(true); default: { quantity = default(IQuantity); return(false); } } }
/// <summary> /// Get <see cref="Molarity"/> from <see cref="Density"/>. /// </summary> /// <param name="density"></param> /// <param name="molecularWeight"></param> public static Molarity FromDensity(Density density, Mass molecularWeight) { return(new Molarity(density, molecularWeight)); }
// Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods internal int CompareTo(Mass other) { return(_value.CompareTo(other.AsBaseNumericType(this.Unit))); }
/// <summary> /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". /// </summary> /// <param name="str">String to parse. Typically in the form: {number} {unit}</param> /// <param name="result">Resulting unit quantity if successful.</param> /// <returns>True if successful, otherwise false.</returns> /// <example> /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// </example> /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" /> if null.</param> public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Mass result) { IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); return(QuantityParser.Default.TryParse <Mass, MassUnit>( str, provider, From, out result)); }
/// <summary> /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". /// </summary> /// <param name="str">String to parse. Typically in the form: {number} {unit}</param> /// <param name="result">Resulting unit quantity if successful.</param> /// <example> /// Length.Parse("5.5 m", new CultureInfo("en-US")); /// </example> public static bool TryParse([CanBeNull] string str, out Mass result) { return(TryParse(str, null, out result)); }
/// <summary>Get <see cref="Mass" /> from <see cref="AmountOfSubstance" /> for a given <see cref="MolarMass" />.</summary> public static Mass operator *(MolarMass molarMass, AmountOfSubstance amountOfSubstance) { return(Mass.FromGrams(amountOfSubstance.Moles * molarMass.GramsPerMole)); }
/// <summary>Get <see cref="AmountOfSubstance" /> from <see cref="Mass" /> and a given <see cref="MolarMass" />.</summary> public static AmountOfSubstance FromMass(Mass mass, MolarMass molarMass) { return(mass / molarMass); }
/// <summary>Get <see cref="Mass" /> from <see cref="MassConcentration" /> times <see cref="Volume" />.</summary> public static Mass operator *(MassConcentration density, Volume volume) { return(Mass.FromKilograms(density.KilogramsPerCubicMeter * volume.CubicMeters)); }
public static Mass operator *(Duration duration, MassFlow massFlow) { return(Mass.FromKilograms(massFlow.KilogramsPerSecond * duration.Seconds)); }
/// <summary> /// Get a <see cref="Density"/> from this <see cref="Molarity"/>. /// </summary> /// <param name="molecularWeight"></param> public Density ToDensity(Mass molecularWeight) { return(Density.FromKilogramsPerCubicMeter(MolesPerCubicMeter * molecularWeight.Kilograms)); }
public bool Equals(Mass other) { return(_value.Equals(other.AsBaseNumericType(this.Unit))); }
public Molarity(Density density, Mass molecularWeight) : this() { _value = density.KilogramsPerCubicMeter / molecularWeight.Kilograms; _unit = MolarityUnit.MolesPerCubicMeter; }
/// <summary> /// Gets <see cref="Molarity" /> from this <see cref="Density" />. /// </summary> /// <param name="molecularWeight"></param> public Molarity ToMolarity(Mass molecularWeight) { return(Molarity.FromMolesPerCubicMeter(KilogramsPerCubicMeter / molecularWeight.Kilograms)); }
/// <summary> /// Get <see cref="Density" /> from <see cref="Molarity" />. /// </summary> /// <param name="molarity"></param> /// <param name="molecularWeight"></param> public static Density FromMolarity(Molarity molarity, Mass molecularWeight) { return(new Density(molarity.MolesPerCubicMeter * molecularWeight.Kilograms, DensityUnit.KilogramPerCubicMeter)); }
public static Mass operator *(Volume volume, Density density) { return(Mass.FromKilograms(density.KilogramsPerCubicMeter * volume.CubicMeters)); }
private static bool TryConvert(Mass m, Unit toUnit, out double newValue) { switch (toUnit) { case Unit.Megatonne: newValue = m.Megatonnes; return true; case Unit.Kilotonne: newValue = m.Kilotonnes; return true; case Unit.Tonne: newValue = m.Tonnes; return true; case Unit.Kilogram: newValue = m.Kilograms; return true; case Unit.Hectogram: newValue = m.Hectograms; return true; case Unit.Decagram: newValue = m.Decagrams; return true; case Unit.Gram: newValue = m.Grams; return true; case Unit.Decigram: newValue = m.Decigrams; return true; case Unit.Centigram: newValue = m.Centigrams; return true; case Unit.Milligram: newValue = m.Milligrams; return true; //case Unit.Microgram: // newValue = m.Micrograms; //return true; //case Unit.Nanogram: // newValue = m.Nanograms; //return true; case Unit.ShortTon: newValue = m.ShortTons; return true; case Unit.LongTon: newValue = m.LongTons; return true; default: newValue = 0; return false; } }
/// <summary> /// Dynamically constructs a quantity of the given <see cref="QuantityType"/> with the value in the quantity's base units. /// </summary> /// <param name="quantityType">The <see cref="QuantityType"/> of the quantity to create.</param> /// <param name="value">The value to construct the quantity with.</param> /// <returns>The created quantity.</returns> public static IQuantity FromQuantityType(QuantityType quantityType, QuantityValue value) { switch (quantityType) { case QuantityType.Acceleration: return(Acceleration.From(value, Acceleration.BaseUnit)); case QuantityType.AmountOfSubstance: return(AmountOfSubstance.From(value, AmountOfSubstance.BaseUnit)); case QuantityType.AmplitudeRatio: return(AmplitudeRatio.From(value, AmplitudeRatio.BaseUnit)); case QuantityType.Angle: return(Angle.From(value, Angle.BaseUnit)); case QuantityType.ApparentEnergy: return(ApparentEnergy.From(value, ApparentEnergy.BaseUnit)); case QuantityType.ApparentPower: return(ApparentPower.From(value, ApparentPower.BaseUnit)); case QuantityType.Area: return(Area.From(value, Area.BaseUnit)); case QuantityType.AreaDensity: return(AreaDensity.From(value, AreaDensity.BaseUnit)); case QuantityType.AreaMomentOfInertia: return(AreaMomentOfInertia.From(value, AreaMomentOfInertia.BaseUnit)); case QuantityType.BitRate: return(BitRate.From(value, BitRate.BaseUnit)); case QuantityType.BrakeSpecificFuelConsumption: return(BrakeSpecificFuelConsumption.From(value, BrakeSpecificFuelConsumption.BaseUnit)); case QuantityType.Capacitance: return(Capacitance.From(value, Capacitance.BaseUnit)); case QuantityType.CoefficientOfThermalExpansion: return(CoefficientOfThermalExpansion.From(value, CoefficientOfThermalExpansion.BaseUnit)); case QuantityType.Density: return(Density.From(value, Density.BaseUnit)); case QuantityType.Duration: return(Duration.From(value, Duration.BaseUnit)); case QuantityType.DynamicViscosity: return(DynamicViscosity.From(value, DynamicViscosity.BaseUnit)); case QuantityType.ElectricAdmittance: return(ElectricAdmittance.From(value, ElectricAdmittance.BaseUnit)); case QuantityType.ElectricCharge: return(ElectricCharge.From(value, ElectricCharge.BaseUnit)); case QuantityType.ElectricChargeDensity: return(ElectricChargeDensity.From(value, ElectricChargeDensity.BaseUnit)); case QuantityType.ElectricConductance: return(ElectricConductance.From(value, ElectricConductance.BaseUnit)); case QuantityType.ElectricConductivity: return(ElectricConductivity.From(value, ElectricConductivity.BaseUnit)); case QuantityType.ElectricCurrent: return(ElectricCurrent.From(value, ElectricCurrent.BaseUnit)); case QuantityType.ElectricCurrentDensity: return(ElectricCurrentDensity.From(value, ElectricCurrentDensity.BaseUnit)); case QuantityType.ElectricCurrentGradient: return(ElectricCurrentGradient.From(value, ElectricCurrentGradient.BaseUnit)); case QuantityType.ElectricField: return(ElectricField.From(value, ElectricField.BaseUnit)); case QuantityType.ElectricInductance: return(ElectricInductance.From(value, ElectricInductance.BaseUnit)); case QuantityType.ElectricPotential: return(ElectricPotential.From(value, ElectricPotential.BaseUnit)); case QuantityType.ElectricPotentialAc: return(ElectricPotentialAc.From(value, ElectricPotentialAc.BaseUnit)); case QuantityType.ElectricPotentialDc: return(ElectricPotentialDc.From(value, ElectricPotentialDc.BaseUnit)); case QuantityType.ElectricResistance: return(ElectricResistance.From(value, ElectricResistance.BaseUnit)); case QuantityType.ElectricResistivity: return(ElectricResistivity.From(value, ElectricResistivity.BaseUnit)); case QuantityType.Energy: return(Energy.From(value, Energy.BaseUnit)); case QuantityType.Entropy: return(Entropy.From(value, Entropy.BaseUnit)); case QuantityType.Force: return(Force.From(value, Force.BaseUnit)); case QuantityType.ForceChangeRate: return(ForceChangeRate.From(value, ForceChangeRate.BaseUnit)); case QuantityType.ForcePerLength: return(ForcePerLength.From(value, ForcePerLength.BaseUnit)); case QuantityType.Frequency: return(Frequency.From(value, Frequency.BaseUnit)); case QuantityType.HeatFlux: return(HeatFlux.From(value, HeatFlux.BaseUnit)); case QuantityType.HeatTransferCoefficient: return(HeatTransferCoefficient.From(value, HeatTransferCoefficient.BaseUnit)); case QuantityType.Illuminance: return(Illuminance.From(value, Illuminance.BaseUnit)); case QuantityType.Information: return(Information.From(value, Information.BaseUnit)); case QuantityType.Irradiance: return(Irradiance.From(value, Irradiance.BaseUnit)); case QuantityType.Irradiation: return(Irradiation.From(value, Irradiation.BaseUnit)); case QuantityType.KinematicViscosity: return(KinematicViscosity.From(value, KinematicViscosity.BaseUnit)); case QuantityType.LapseRate: return(LapseRate.From(value, LapseRate.BaseUnit)); case QuantityType.Length: return(Length.From(value, Length.BaseUnit)); case QuantityType.Level: return(Level.From(value, Level.BaseUnit)); case QuantityType.LinearDensity: return(LinearDensity.From(value, LinearDensity.BaseUnit)); case QuantityType.LuminousFlux: return(LuminousFlux.From(value, LuminousFlux.BaseUnit)); case QuantityType.LuminousIntensity: return(LuminousIntensity.From(value, LuminousIntensity.BaseUnit)); case QuantityType.MagneticField: return(MagneticField.From(value, MagneticField.BaseUnit)); case QuantityType.MagneticFlux: return(MagneticFlux.From(value, MagneticFlux.BaseUnit)); case QuantityType.Magnetization: return(Magnetization.From(value, Magnetization.BaseUnit)); case QuantityType.Mass: return(Mass.From(value, Mass.BaseUnit)); case QuantityType.MassFlow: return(MassFlow.From(value, MassFlow.BaseUnit)); case QuantityType.MassFlux: return(MassFlux.From(value, MassFlux.BaseUnit)); case QuantityType.MassMomentOfInertia: return(MassMomentOfInertia.From(value, MassMomentOfInertia.BaseUnit)); case QuantityType.MolarEnergy: return(MolarEnergy.From(value, MolarEnergy.BaseUnit)); case QuantityType.MolarEntropy: return(MolarEntropy.From(value, MolarEntropy.BaseUnit)); case QuantityType.Molarity: return(Molarity.From(value, Molarity.BaseUnit)); case QuantityType.MolarMass: return(MolarMass.From(value, MolarMass.BaseUnit)); case QuantityType.Permeability: return(Permeability.From(value, Permeability.BaseUnit)); case QuantityType.Permittivity: return(Permittivity.From(value, Permittivity.BaseUnit)); case QuantityType.Power: return(Power.From(value, Power.BaseUnit)); case QuantityType.PowerDensity: return(PowerDensity.From(value, PowerDensity.BaseUnit)); case QuantityType.PowerRatio: return(PowerRatio.From(value, PowerRatio.BaseUnit)); case QuantityType.Pressure: return(Pressure.From(value, Pressure.BaseUnit)); case QuantityType.PressureChangeRate: return(PressureChangeRate.From(value, PressureChangeRate.BaseUnit)); case QuantityType.Ratio: return(Ratio.From(value, Ratio.BaseUnit)); case QuantityType.ReactiveEnergy: return(ReactiveEnergy.From(value, ReactiveEnergy.BaseUnit)); case QuantityType.ReactivePower: return(ReactivePower.From(value, ReactivePower.BaseUnit)); case QuantityType.RotationalAcceleration: return(RotationalAcceleration.From(value, RotationalAcceleration.BaseUnit)); case QuantityType.RotationalSpeed: return(RotationalSpeed.From(value, RotationalSpeed.BaseUnit)); case QuantityType.RotationalStiffness: return(RotationalStiffness.From(value, RotationalStiffness.BaseUnit)); case QuantityType.RotationalStiffnessPerLength: return(RotationalStiffnessPerLength.From(value, RotationalStiffnessPerLength.BaseUnit)); case QuantityType.SolidAngle: return(SolidAngle.From(value, SolidAngle.BaseUnit)); case QuantityType.SpecificEnergy: return(SpecificEnergy.From(value, SpecificEnergy.BaseUnit)); case QuantityType.SpecificEntropy: return(SpecificEntropy.From(value, SpecificEntropy.BaseUnit)); case QuantityType.SpecificVolume: return(SpecificVolume.From(value, SpecificVolume.BaseUnit)); case QuantityType.SpecificWeight: return(SpecificWeight.From(value, SpecificWeight.BaseUnit)); case QuantityType.Speed: return(Speed.From(value, Speed.BaseUnit)); case QuantityType.Temperature: return(Temperature.From(value, Temperature.BaseUnit)); case QuantityType.TemperatureChangeRate: return(TemperatureChangeRate.From(value, TemperatureChangeRate.BaseUnit)); case QuantityType.TemperatureDelta: return(TemperatureDelta.From(value, TemperatureDelta.BaseUnit)); case QuantityType.ThermalConductivity: return(ThermalConductivity.From(value, ThermalConductivity.BaseUnit)); case QuantityType.ThermalResistance: return(ThermalResistance.From(value, ThermalResistance.BaseUnit)); case QuantityType.Torque: return(Torque.From(value, Torque.BaseUnit)); case QuantityType.VitaminA: return(VitaminA.From(value, VitaminA.BaseUnit)); case QuantityType.Volume: return(Volume.From(value, Volume.BaseUnit)); case QuantityType.VolumeFlow: return(VolumeFlow.From(value, VolumeFlow.BaseUnit)); case QuantityType.VolumePerLength: return(VolumePerLength.From(value, VolumePerLength.BaseUnit)); default: throw new ArgumentException($"{quantityType} is not a supported quantity type."); } }