Beispiel #1
0
        /// <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 MolarityUnit molarityUnit:
                quantity = Molarity.From(value, molarityUnit);
                return(true);

            case MolarMassUnit molarMassUnit:
                quantity = MolarMass.From(value, molarMassUnit);
                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 ReciprocalAreaUnit reciprocalAreaUnit:
                quantity = ReciprocalArea.From(value, reciprocalAreaUnit);
                return(true);

            case ReciprocalLengthUnit reciprocalLengthUnit:
                quantity = ReciprocalLength.From(value, reciprocalLengthUnit);
                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 SpecificFuelConsumptionUnit specificFuelConsumptionUnit:
                quantity = SpecificFuelConsumption.From(value, specificFuelConsumptionUnit);
                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 VolumetricHeatCapacityUnit volumetricHeatCapacityUnit:
                quantity = VolumetricHeatCapacity.From(value, volumetricHeatCapacityUnit);
                return(true);

            case WarpingMomentOfInertiaUnit warpingMomentOfInertiaUnit:
                quantity = WarpingMomentOfInertia.From(value, warpingMomentOfInertiaUnit);
                return(true);

            default:
            {
                quantity = default(IQuantity);
                return(false);
            }
            }
        }