From ca1dfc2da3a92e7b15c94a9ba37fcd98dae00111 Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Fri, 1 Mar 2019 10:36:37 -0500 Subject: [PATCH 1/2] IQuantity As/ToUnit methods would allow casting an Enum to the wrong unit type. Throw exception. --- UnitsNet.Tests/IQuantityTests.cs | 26 +++++++++++++++++++ .../Quantities/Acceleration.NetFramework.g.cs | 23 +++++++++++----- .../AmountOfSubstance.NetFramework.g.cs | 23 +++++++++++----- .../AmplitudeRatio.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Angle.NetFramework.g.cs | 23 +++++++++++----- .../ApparentEnergy.NetFramework.g.cs | 23 +++++++++++----- .../ApparentPower.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Area.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/AreaDensity.NetFramework.g.cs | 23 +++++++++++----- .../AreaMomentOfInertia.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/BitRate.NetFramework.g.cs | 23 +++++++++++----- ...eSpecificFuelConsumption.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Capacitance.NetFramework.g.cs | 23 +++++++++++----- ...icientOfThermalExpansion.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Density.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Duration.NetFramework.g.cs | 23 +++++++++++----- .../DynamicViscosity.NetFramework.g.cs | 23 +++++++++++----- .../ElectricAdmittance.NetFramework.g.cs | 23 +++++++++++----- .../ElectricCharge.NetFramework.g.cs | 23 +++++++++++----- .../ElectricChargeDensity.NetFramework.g.cs | 23 +++++++++++----- .../ElectricConductance.NetFramework.g.cs | 23 +++++++++++----- .../ElectricConductivity.NetFramework.g.cs | 23 +++++++++++----- .../ElectricCurrent.NetFramework.g.cs | 23 +++++++++++----- .../ElectricCurrentDensity.NetFramework.g.cs | 23 +++++++++++----- .../ElectricCurrentGradient.NetFramework.g.cs | 23 +++++++++++----- .../ElectricField.NetFramework.g.cs | 23 +++++++++++----- .../ElectricInductance.NetFramework.g.cs | 23 +++++++++++----- .../ElectricPotential.NetFramework.g.cs | 23 +++++++++++----- .../ElectricPotentialAc.NetFramework.g.cs | 23 +++++++++++----- .../ElectricPotentialDc.NetFramework.g.cs | 23 +++++++++++----- .../ElectricResistance.NetFramework.g.cs | 23 +++++++++++----- .../ElectricResistivity.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Energy.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Entropy.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Force.NetFramework.g.cs | 23 +++++++++++----- .../ForceChangeRate.NetFramework.g.cs | 23 +++++++++++----- .../ForcePerLength.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Frequency.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/HeatFlux.NetFramework.g.cs | 23 +++++++++++----- .../HeatTransferCoefficient.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Illuminance.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Information.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Irradiance.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Irradiation.NetFramework.g.cs | 23 +++++++++++----- .../KinematicViscosity.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/LapseRate.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Length.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Level.NetFramework.g.cs | 23 +++++++++++----- .../LinearDensity.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/LuminousFlux.NetFramework.g.cs | 23 +++++++++++----- .../LuminousIntensity.NetFramework.g.cs | 23 +++++++++++----- .../MagneticField.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/MagneticFlux.NetFramework.g.cs | 23 +++++++++++----- .../Magnetization.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Mass.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/MassFlow.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/MassFlux.NetFramework.g.cs | 23 +++++++++++----- .../MassMomentOfInertia.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/MolarEnergy.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/MolarEntropy.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/MolarMass.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Molarity.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Permeability.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Permittivity.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Power.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/PowerDensity.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/PowerRatio.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Pressure.NetFramework.g.cs | 23 +++++++++++----- .../PressureChangeRate.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Ratio.NetFramework.g.cs | 23 +++++++++++----- .../ReactiveEnergy.NetFramework.g.cs | 23 +++++++++++----- .../ReactivePower.NetFramework.g.cs | 23 +++++++++++----- .../RotationalAcceleration.NetFramework.g.cs | 23 +++++++++++----- .../RotationalSpeed.NetFramework.g.cs | 23 +++++++++++----- .../RotationalStiffness.NetFramework.g.cs | 23 +++++++++++----- ...tionalStiffnessPerLength.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/SolidAngle.NetFramework.g.cs | 23 +++++++++++----- .../SpecificEnergy.NetFramework.g.cs | 23 +++++++++++----- .../SpecificEntropy.NetFramework.g.cs | 23 +++++++++++----- .../SpecificVolume.NetFramework.g.cs | 23 +++++++++++----- .../SpecificWeight.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Speed.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Temperature.NetFramework.g.cs | 23 +++++++++++----- .../TemperatureChangeRate.NetFramework.g.cs | 23 +++++++++++----- .../TemperatureDelta.NetFramework.g.cs | 23 +++++++++++----- .../ThermalConductivity.NetFramework.g.cs | 23 +++++++++++----- .../ThermalResistance.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Torque.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/VitaminA.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/Volume.NetFramework.g.cs | 23 +++++++++++----- .../Quantities/VolumeFlow.NetFramework.g.cs | 23 +++++++++++----- .../Include-GenerateQuantitySourceCode.ps1 | 23 +++++++++++----- 92 files changed, 1573 insertions(+), 546 deletions(-) create mode 100644 UnitsNet.Tests/IQuantityTests.cs diff --git a/UnitsNet.Tests/IQuantityTests.cs b/UnitsNet.Tests/IQuantityTests.cs new file mode 100644 index 0000000000..dd27d34bdb --- /dev/null +++ b/UnitsNet.Tests/IQuantityTests.cs @@ -0,0 +1,26 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using UnitsNet.Units; +using Xunit; + +namespace UnitsNet.Tests +{ + public class IQuantityTests + { + [Fact] + public void As_GivenWrongUnitType_ThrowsArgumentException() + { + IQuantity quantity = Length.FromMeters(1.2345); + Assert.Throws(() => quantity.As(MassUnit.Kilogram)); + } + + [Fact] + public void ToUnit_GivenWrongUnitType_ThrowsArgumentException() + { + IQuantity quantity = Length.FromMeters(1.2345); + Assert.Throws(() => quantity.ToUnit(MassUnit.Kilogram)); + } + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/Acceleration.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Acceleration.NetFramework.g.cs index a92db7995f..ea819acce6 100644 --- a/UnitsNet/GeneratedCode/Quantities/Acceleration.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Acceleration.NetFramework.g.cs @@ -723,7 +723,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((AccelerationUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AccelerationUnit)) + throw new ArgumentException("The given unit is not of type AccelerationUnit.", nameof(unit)); + + return As((AccelerationUnit)unit); + } /// /// Convert to the unit representation . @@ -738,9 +745,6 @@ public double As(AccelerationUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((AccelerationUnit) unit); - /// /// Converts this Acceleration to another Acceleration with the unit representation . /// @@ -751,10 +755,17 @@ public Acceleration ToUnit(AccelerationUnit unit) return new Acceleration(convertedValue, unit); } - IQuantity IQuantity.ToUnit(AccelerationUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is AccelerationUnit)) + throw new ArgumentException("The given unit is not of type AccelerationUnit.", nameof(unit)); + + return ToUnit((AccelerationUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((AccelerationUnit) unit); + IQuantity IQuantity.ToUnit(AccelerationUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.NetFramework.g.cs index c4d133dd0d..01c5174c89 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.NetFramework.g.cs @@ -753,7 +753,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((AmountOfSubstanceUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AmountOfSubstanceUnit)) + throw new ArgumentException("The given unit is not of type AmountOfSubstanceUnit.", nameof(unit)); + + return As((AmountOfSubstanceUnit)unit); + } /// /// Convert to the unit representation . @@ -768,9 +775,6 @@ public double As(AmountOfSubstanceUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((AmountOfSubstanceUnit) unit); - /// /// Converts this AmountOfSubstance to another AmountOfSubstance with the unit representation . /// @@ -781,10 +785,17 @@ public AmountOfSubstance ToUnit(AmountOfSubstanceUnit unit) return new AmountOfSubstance(convertedValue, unit); } - IQuantity IQuantity.ToUnit(AmountOfSubstanceUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is AmountOfSubstanceUnit)) + throw new ArgumentException("The given unit is not of type AmountOfSubstanceUnit.", nameof(unit)); + + return ToUnit((AmountOfSubstanceUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((AmountOfSubstanceUnit) unit); + IQuantity IQuantity.ToUnit(AmountOfSubstanceUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.NetFramework.g.cs index 8ad44eab05..14a8f76d58 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.NetFramework.g.cs @@ -596,7 +596,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((AmplitudeRatioUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AmplitudeRatioUnit)) + throw new ArgumentException("The given unit is not of type AmplitudeRatioUnit.", nameof(unit)); + + return As((AmplitudeRatioUnit)unit); + } /// /// Convert to the unit representation . @@ -611,9 +618,6 @@ public double As(AmplitudeRatioUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((AmplitudeRatioUnit) unit); - /// /// Converts this AmplitudeRatio to another AmplitudeRatio with the unit representation . /// @@ -624,10 +628,17 @@ public AmplitudeRatio ToUnit(AmplitudeRatioUnit unit) return new AmplitudeRatio(convertedValue, unit); } - IQuantity IQuantity.ToUnit(AmplitudeRatioUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is AmplitudeRatioUnit)) + throw new ArgumentException("The given unit is not of type AmplitudeRatioUnit.", nameof(unit)); + + return ToUnit((AmplitudeRatioUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((AmplitudeRatioUnit) unit); + IQuantity IQuantity.ToUnit(AmplitudeRatioUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Angle.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Angle.NetFramework.g.cs index 7ad6e701fa..c219f3cf72 100644 --- a/UnitsNet/GeneratedCode/Quantities/Angle.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Angle.NetFramework.g.cs @@ -738,7 +738,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((AngleUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AngleUnit)) + throw new ArgumentException("The given unit is not of type AngleUnit.", nameof(unit)); + + return As((AngleUnit)unit); + } /// /// Convert to the unit representation . @@ -753,9 +760,6 @@ public double As(AngleUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((AngleUnit) unit); - /// /// Converts this Angle to another Angle with the unit representation . /// @@ -766,10 +770,17 @@ public Angle ToUnit(AngleUnit unit) return new Angle(convertedValue, unit); } - IQuantity IQuantity.ToUnit(AngleUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is AngleUnit)) + throw new ArgumentException("The given unit is not of type AngleUnit.", nameof(unit)); + + return ToUnit((AngleUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((AngleUnit) unit); + IQuantity IQuantity.ToUnit(AngleUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.NetFramework.g.cs index af223d8933..0cf81f4af6 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.NetFramework.g.cs @@ -573,7 +573,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ApparentEnergyUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ApparentEnergyUnit)) + throw new ArgumentException("The given unit is not of type ApparentEnergyUnit.", nameof(unit)); + + return As((ApparentEnergyUnit)unit); + } /// /// Convert to the unit representation . @@ -588,9 +595,6 @@ public double As(ApparentEnergyUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ApparentEnergyUnit) unit); - /// /// Converts this ApparentEnergy to another ApparentEnergy with the unit representation . /// @@ -601,10 +605,17 @@ public ApparentEnergy ToUnit(ApparentEnergyUnit unit) return new ApparentEnergy(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ApparentEnergyUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ApparentEnergyUnit)) + throw new ArgumentException("The given unit is not of type ApparentEnergyUnit.", nameof(unit)); + + return ToUnit((ApparentEnergyUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ApparentEnergyUnit) unit); + IQuantity IQuantity.ToUnit(ApparentEnergyUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentPower.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentPower.NetFramework.g.cs index aa580e415a..a00a2a9640 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentPower.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentPower.NetFramework.g.cs @@ -588,7 +588,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ApparentPowerUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ApparentPowerUnit)) + throw new ArgumentException("The given unit is not of type ApparentPowerUnit.", nameof(unit)); + + return As((ApparentPowerUnit)unit); + } /// /// Convert to the unit representation . @@ -603,9 +610,6 @@ public double As(ApparentPowerUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ApparentPowerUnit) unit); - /// /// Converts this ApparentPower to another ApparentPower with the unit representation . /// @@ -616,10 +620,17 @@ public ApparentPower ToUnit(ApparentPowerUnit unit) return new ApparentPower(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ApparentPowerUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ApparentPowerUnit)) + throw new ArgumentException("The given unit is not of type ApparentPowerUnit.", nameof(unit)); + + return ToUnit((ApparentPowerUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ApparentPowerUnit) unit); + IQuantity IQuantity.ToUnit(ApparentPowerUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Area.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Area.NetFramework.g.cs index 165e1ce48d..837f77969d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Area.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Area.NetFramework.g.cs @@ -723,7 +723,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((AreaUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AreaUnit)) + throw new ArgumentException("The given unit is not of type AreaUnit.", nameof(unit)); + + return As((AreaUnit)unit); + } /// /// Convert to the unit representation . @@ -738,9 +745,6 @@ public double As(AreaUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((AreaUnit) unit); - /// /// Converts this Area to another Area with the unit representation . /// @@ -751,10 +755,17 @@ public Area ToUnit(AreaUnit unit) return new Area(convertedValue, unit); } - IQuantity IQuantity.ToUnit(AreaUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is AreaUnit)) + throw new ArgumentException("The given unit is not of type AreaUnit.", nameof(unit)); + + return ToUnit((AreaUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((AreaUnit) unit); + IQuantity IQuantity.ToUnit(AreaUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/AreaDensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaDensity.NetFramework.g.cs index 276c32d12b..d2a975b622 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaDensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaDensity.NetFramework.g.cs @@ -543,7 +543,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((AreaDensityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AreaDensityUnit)) + throw new ArgumentException("The given unit is not of type AreaDensityUnit.", nameof(unit)); + + return As((AreaDensityUnit)unit); + } /// /// Convert to the unit representation . @@ -558,9 +565,6 @@ public double As(AreaDensityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((AreaDensityUnit) unit); - /// /// Converts this AreaDensity to another AreaDensity with the unit representation . /// @@ -571,10 +575,17 @@ public AreaDensity ToUnit(AreaDensityUnit unit) return new AreaDensity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(AreaDensityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is AreaDensityUnit)) + throw new ArgumentException("The given unit is not of type AreaDensityUnit.", nameof(unit)); + + return ToUnit((AreaDensityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((AreaDensityUnit) unit); + IQuantity IQuantity.ToUnit(AreaDensityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.NetFramework.g.cs index 4fbf9bee6f..9bd7c99b8d 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.NetFramework.g.cs @@ -618,7 +618,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((AreaMomentOfInertiaUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AreaMomentOfInertiaUnit)) + throw new ArgumentException("The given unit is not of type AreaMomentOfInertiaUnit.", nameof(unit)); + + return As((AreaMomentOfInertiaUnit)unit); + } /// /// Convert to the unit representation . @@ -633,9 +640,6 @@ public double As(AreaMomentOfInertiaUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((AreaMomentOfInertiaUnit) unit); - /// /// Converts this AreaMomentOfInertia to another AreaMomentOfInertia with the unit representation . /// @@ -646,10 +650,17 @@ public AreaMomentOfInertia ToUnit(AreaMomentOfInertiaUnit unit) return new AreaMomentOfInertia(convertedValue, unit); } - IQuantity IQuantity.ToUnit(AreaMomentOfInertiaUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is AreaMomentOfInertiaUnit)) + throw new ArgumentException("The given unit is not of type AreaMomentOfInertiaUnit.", nameof(unit)); + + return ToUnit((AreaMomentOfInertiaUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((AreaMomentOfInertiaUnit) unit); + IQuantity IQuantity.ToUnit(AreaMomentOfInertiaUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs index 46b0f16066..c07e4d1d88 100644 --- a/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs @@ -923,7 +923,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((BitRateUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is BitRateUnit)) + throw new ArgumentException("The given unit is not of type BitRateUnit.", nameof(unit)); + + return As((BitRateUnit)unit); + } /// /// Convert to the unit representation . @@ -938,9 +945,6 @@ public double As(BitRateUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((BitRateUnit) unit); - /// /// Converts this BitRate to another BitRate with the unit representation . /// @@ -951,10 +955,17 @@ public BitRate ToUnit(BitRateUnit unit) return new BitRate(convertedValue, unit); } - IQuantity IQuantity.ToUnit(BitRateUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is BitRateUnit)) + throw new ArgumentException("The given unit is not of type BitRateUnit.", nameof(unit)); + + return ToUnit((BitRateUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((BitRateUnit) unit); + IQuantity IQuantity.ToUnit(BitRateUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.NetFramework.g.cs index 2787e6019e..f0255fc931 100644 --- a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.NetFramework.g.cs @@ -573,7 +573,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((BrakeSpecificFuelConsumptionUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is BrakeSpecificFuelConsumptionUnit)) + throw new ArgumentException("The given unit is not of type BrakeSpecificFuelConsumptionUnit.", nameof(unit)); + + return As((BrakeSpecificFuelConsumptionUnit)unit); + } /// /// Convert to the unit representation . @@ -588,9 +595,6 @@ public double As(BrakeSpecificFuelConsumptionUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((BrakeSpecificFuelConsumptionUnit) unit); - /// /// Converts this BrakeSpecificFuelConsumption to another BrakeSpecificFuelConsumption with the unit representation . /// @@ -601,10 +605,17 @@ public BrakeSpecificFuelConsumption ToUnit(BrakeSpecificFuelConsumptionUnit unit return new BrakeSpecificFuelConsumption(convertedValue, unit); } - IQuantity IQuantity.ToUnit(BrakeSpecificFuelConsumptionUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is BrakeSpecificFuelConsumptionUnit)) + throw new ArgumentException("The given unit is not of type BrakeSpecificFuelConsumptionUnit.", nameof(unit)); + + return ToUnit((BrakeSpecificFuelConsumptionUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((BrakeSpecificFuelConsumptionUnit) unit); + IQuantity IQuantity.ToUnit(BrakeSpecificFuelConsumptionUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Capacitance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Capacitance.NetFramework.g.cs index 79e2323a44..433c30290c 100644 --- a/UnitsNet/GeneratedCode/Quantities/Capacitance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Capacitance.NetFramework.g.cs @@ -636,7 +636,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((CapacitanceUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is CapacitanceUnit)) + throw new ArgumentException("The given unit is not of type CapacitanceUnit.", nameof(unit)); + + return As((CapacitanceUnit)unit); + } /// /// Convert to the unit representation . @@ -651,9 +658,6 @@ public double As(CapacitanceUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((CapacitanceUnit) unit); - /// /// Converts this Capacitance to another Capacitance with the unit representation . /// @@ -664,10 +668,17 @@ public Capacitance ToUnit(CapacitanceUnit unit) return new Capacitance(convertedValue, unit); } - IQuantity IQuantity.ToUnit(CapacitanceUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is CapacitanceUnit)) + throw new ArgumentException("The given unit is not of type CapacitanceUnit.", nameof(unit)); + + return ToUnit((CapacitanceUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((CapacitanceUnit) unit); + IQuantity IQuantity.ToUnit(CapacitanceUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.NetFramework.g.cs index 22e2977f09..3e2cf05b4e 100644 --- a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.NetFramework.g.cs @@ -573,7 +573,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((CoefficientOfThermalExpansionUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is CoefficientOfThermalExpansionUnit)) + throw new ArgumentException("The given unit is not of type CoefficientOfThermalExpansionUnit.", nameof(unit)); + + return As((CoefficientOfThermalExpansionUnit)unit); + } /// /// Convert to the unit representation . @@ -588,9 +595,6 @@ public double As(CoefficientOfThermalExpansionUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((CoefficientOfThermalExpansionUnit) unit); - /// /// Converts this CoefficientOfThermalExpansion to another CoefficientOfThermalExpansion with the unit representation . /// @@ -601,10 +605,17 @@ public CoefficientOfThermalExpansion ToUnit(CoefficientOfThermalExpansionUnit un return new CoefficientOfThermalExpansion(convertedValue, unit); } - IQuantity IQuantity.ToUnit(CoefficientOfThermalExpansionUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is CoefficientOfThermalExpansionUnit)) + throw new ArgumentException("The given unit is not of type CoefficientOfThermalExpansionUnit.", nameof(unit)); + + return ToUnit((CoefficientOfThermalExpansionUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((CoefficientOfThermalExpansionUnit) unit); + IQuantity IQuantity.ToUnit(CoefficientOfThermalExpansionUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Density.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Density.NetFramework.g.cs index a3a5ef2cb5..6a2c2843da 100644 --- a/UnitsNet/GeneratedCode/Quantities/Density.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Density.NetFramework.g.cs @@ -1116,7 +1116,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((DensityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is DensityUnit)) + throw new ArgumentException("The given unit is not of type DensityUnit.", nameof(unit)); + + return As((DensityUnit)unit); + } /// /// Convert to the unit representation . @@ -1131,9 +1138,6 @@ public double As(DensityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((DensityUnit) unit); - /// /// Converts this Density to another Density with the unit representation . /// @@ -1144,10 +1148,17 @@ public Density ToUnit(DensityUnit unit) return new Density(convertedValue, unit); } - IQuantity IQuantity.ToUnit(DensityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is DensityUnit)) + throw new ArgumentException("The given unit is not of type DensityUnit.", nameof(unit)); + + return ToUnit((DensityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((DensityUnit) unit); + IQuantity IQuantity.ToUnit(DensityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Duration.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Duration.NetFramework.g.cs index 95d95546b6..365b9f4674 100644 --- a/UnitsNet/GeneratedCode/Quantities/Duration.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Duration.NetFramework.g.cs @@ -678,7 +678,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((DurationUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is DurationUnit)) + throw new ArgumentException("The given unit is not of type DurationUnit.", nameof(unit)); + + return As((DurationUnit)unit); + } /// /// Convert to the unit representation . @@ -693,9 +700,6 @@ public double As(DurationUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((DurationUnit) unit); - /// /// Converts this Duration to another Duration with the unit representation . /// @@ -706,10 +710,17 @@ public Duration ToUnit(DurationUnit unit) return new Duration(convertedValue, unit); } - IQuantity IQuantity.ToUnit(DurationUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is DurationUnit)) + throw new ArgumentException("The given unit is not of type DurationUnit.", nameof(unit)); + + return ToUnit((DurationUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((DurationUnit) unit); + IQuantity IQuantity.ToUnit(DurationUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.NetFramework.g.cs index 557eb94187..c5a5adc63d 100644 --- a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.NetFramework.g.cs @@ -621,7 +621,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((DynamicViscosityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is DynamicViscosityUnit)) + throw new ArgumentException("The given unit is not of type DynamicViscosityUnit.", nameof(unit)); + + return As((DynamicViscosityUnit)unit); + } /// /// Convert to the unit representation . @@ -636,9 +643,6 @@ public double As(DynamicViscosityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((DynamicViscosityUnit) unit); - /// /// Converts this DynamicViscosity to another DynamicViscosity with the unit representation . /// @@ -649,10 +653,17 @@ public DynamicViscosity ToUnit(DynamicViscosityUnit unit) return new DynamicViscosity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(DynamicViscosityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is DynamicViscosityUnit)) + throw new ArgumentException("The given unit is not of type DynamicViscosityUnit.", nameof(unit)); + + return ToUnit((DynamicViscosityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((DynamicViscosityUnit) unit); + IQuantity IQuantity.ToUnit(DynamicViscosityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.NetFramework.g.cs index bd77994e92..e11d0ed85c 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.NetFramework.g.cs @@ -588,7 +588,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricAdmittanceUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricAdmittanceUnit)) + throw new ArgumentException("The given unit is not of type ElectricAdmittanceUnit.", nameof(unit)); + + return As((ElectricAdmittanceUnit)unit); + } /// /// Convert to the unit representation . @@ -603,9 +610,6 @@ public double As(ElectricAdmittanceUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricAdmittanceUnit) unit); - /// /// Converts this ElectricAdmittance to another ElectricAdmittance with the unit representation . /// @@ -616,10 +620,17 @@ public ElectricAdmittance ToUnit(ElectricAdmittanceUnit unit) return new ElectricAdmittance(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricAdmittanceUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricAdmittanceUnit)) + throw new ArgumentException("The given unit is not of type ElectricAdmittanceUnit.", nameof(unit)); + + return ToUnit((ElectricAdmittanceUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricAdmittanceUnit) unit); + IQuantity IQuantity.ToUnit(ElectricAdmittanceUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.NetFramework.g.cs index 075c83478a..d39e920eca 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricChargeUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricChargeUnit)) + throw new ArgumentException("The given unit is not of type ElectricChargeUnit.", nameof(unit)); + + return As((ElectricChargeUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(ElectricChargeUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricChargeUnit) unit); - /// /// Converts this ElectricCharge to another ElectricCharge with the unit representation . /// @@ -574,10 +578,17 @@ public ElectricCharge ToUnit(ElectricChargeUnit unit) return new ElectricCharge(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricChargeUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricChargeUnit)) + throw new ArgumentException("The given unit is not of type ElectricChargeUnit.", nameof(unit)); + + return ToUnit((ElectricChargeUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricChargeUnit) unit); + IQuantity IQuantity.ToUnit(ElectricChargeUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.NetFramework.g.cs index e4439bf55f..d15f777abb 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricChargeDensityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricChargeDensityUnit)) + throw new ArgumentException("The given unit is not of type ElectricChargeDensityUnit.", nameof(unit)); + + return As((ElectricChargeDensityUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(ElectricChargeDensityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricChargeDensityUnit) unit); - /// /// Converts this ElectricChargeDensity to another ElectricChargeDensity with the unit representation . /// @@ -574,10 +578,17 @@ public ElectricChargeDensity ToUnit(ElectricChargeDensityUnit unit) return new ElectricChargeDensity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricChargeDensityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricChargeDensityUnit)) + throw new ArgumentException("The given unit is not of type ElectricChargeDensityUnit.", nameof(unit)); + + return ToUnit((ElectricChargeDensityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricChargeDensityUnit) unit); + IQuantity IQuantity.ToUnit(ElectricChargeDensityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.NetFramework.g.cs index b02ec48875..64625be935 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.NetFramework.g.cs @@ -576,7 +576,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricConductanceUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricConductanceUnit)) + throw new ArgumentException("The given unit is not of type ElectricConductanceUnit.", nameof(unit)); + + return As((ElectricConductanceUnit)unit); + } /// /// Convert to the unit representation . @@ -591,9 +598,6 @@ public double As(ElectricConductanceUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricConductanceUnit) unit); - /// /// Converts this ElectricConductance to another ElectricConductance with the unit representation . /// @@ -604,10 +608,17 @@ public ElectricConductance ToUnit(ElectricConductanceUnit unit) return new ElectricConductance(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricConductanceUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricConductanceUnit)) + throw new ArgumentException("The given unit is not of type ElectricConductanceUnit.", nameof(unit)); + + return ToUnit((ElectricConductanceUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricConductanceUnit) unit); + IQuantity IQuantity.ToUnit(ElectricConductanceUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.NetFramework.g.cs index 9bfe9d3437..beaa363d18 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricConductivityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricConductivityUnit)) + throw new ArgumentException("The given unit is not of type ElectricConductivityUnit.", nameof(unit)); + + return As((ElectricConductivityUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(ElectricConductivityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricConductivityUnit) unit); - /// /// Converts this ElectricConductivity to another ElectricConductivity with the unit representation . /// @@ -574,10 +578,17 @@ public ElectricConductivity ToUnit(ElectricConductivityUnit unit) return new ElectricConductivity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricConductivityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricConductivityUnit)) + throw new ArgumentException("The given unit is not of type ElectricConductivityUnit.", nameof(unit)); + + return ToUnit((ElectricConductivityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricConductivityUnit) unit); + IQuantity IQuantity.ToUnit(ElectricConductivityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.NetFramework.g.cs index e0cbb46e83..4868747a2d 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.NetFramework.g.cs @@ -648,7 +648,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricCurrentUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricCurrentUnit)) + throw new ArgumentException("The given unit is not of type ElectricCurrentUnit.", nameof(unit)); + + return As((ElectricCurrentUnit)unit); + } /// /// Convert to the unit representation . @@ -663,9 +670,6 @@ public double As(ElectricCurrentUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricCurrentUnit) unit); - /// /// Converts this ElectricCurrent to another ElectricCurrent with the unit representation . /// @@ -676,10 +680,17 @@ public ElectricCurrent ToUnit(ElectricCurrentUnit unit) return new ElectricCurrent(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricCurrentUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricCurrentUnit)) + throw new ArgumentException("The given unit is not of type ElectricCurrentUnit.", nameof(unit)); + + return ToUnit((ElectricCurrentUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricCurrentUnit) unit); + IQuantity IQuantity.ToUnit(ElectricCurrentUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.NetFramework.g.cs index 27a6420441..aef6fb4815 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricCurrentDensityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricCurrentDensityUnit)) + throw new ArgumentException("The given unit is not of type ElectricCurrentDensityUnit.", nameof(unit)); + + return As((ElectricCurrentDensityUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(ElectricCurrentDensityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricCurrentDensityUnit) unit); - /// /// Converts this ElectricCurrentDensity to another ElectricCurrentDensity with the unit representation . /// @@ -574,10 +578,17 @@ public ElectricCurrentDensity ToUnit(ElectricCurrentDensityUnit unit) return new ElectricCurrentDensity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricCurrentDensityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricCurrentDensityUnit)) + throw new ArgumentException("The given unit is not of type ElectricCurrentDensityUnit.", nameof(unit)); + + return ToUnit((ElectricCurrentDensityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricCurrentDensityUnit) unit); + IQuantity IQuantity.ToUnit(ElectricCurrentDensityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.NetFramework.g.cs index 04c6ad1809..704f6fbf22 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.NetFramework.g.cs @@ -543,7 +543,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricCurrentGradientUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricCurrentGradientUnit)) + throw new ArgumentException("The given unit is not of type ElectricCurrentGradientUnit.", nameof(unit)); + + return As((ElectricCurrentGradientUnit)unit); + } /// /// Convert to the unit representation . @@ -558,9 +565,6 @@ public double As(ElectricCurrentGradientUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricCurrentGradientUnit) unit); - /// /// Converts this ElectricCurrentGradient to another ElectricCurrentGradient with the unit representation . /// @@ -571,10 +575,17 @@ public ElectricCurrentGradient ToUnit(ElectricCurrentGradientUnit unit) return new ElectricCurrentGradient(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricCurrentGradientUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricCurrentGradientUnit)) + throw new ArgumentException("The given unit is not of type ElectricCurrentGradientUnit.", nameof(unit)); + + return ToUnit((ElectricCurrentGradientUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricCurrentGradientUnit) unit); + IQuantity IQuantity.ToUnit(ElectricCurrentGradientUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricField.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricField.NetFramework.g.cs index 5005bcf876..9b3445ce9b 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricField.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricField.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricFieldUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricFieldUnit)) + throw new ArgumentException("The given unit is not of type ElectricFieldUnit.", nameof(unit)); + + return As((ElectricFieldUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(ElectricFieldUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricFieldUnit) unit); - /// /// Converts this ElectricField to another ElectricField with the unit representation . /// @@ -574,10 +578,17 @@ public ElectricField ToUnit(ElectricFieldUnit unit) return new ElectricField(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricFieldUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricFieldUnit)) + throw new ArgumentException("The given unit is not of type ElectricFieldUnit.", nameof(unit)); + + return ToUnit((ElectricFieldUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricFieldUnit) unit); + IQuantity IQuantity.ToUnit(ElectricFieldUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.NetFramework.g.cs index e4d40e5109..522e6346f6 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.NetFramework.g.cs @@ -591,7 +591,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricInductanceUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricInductanceUnit)) + throw new ArgumentException("The given unit is not of type ElectricInductanceUnit.", nameof(unit)); + + return As((ElectricInductanceUnit)unit); + } /// /// Convert to the unit representation . @@ -606,9 +613,6 @@ public double As(ElectricInductanceUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricInductanceUnit) unit); - /// /// Converts this ElectricInductance to another ElectricInductance with the unit representation . /// @@ -619,10 +623,17 @@ public ElectricInductance ToUnit(ElectricInductanceUnit unit) return new ElectricInductance(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricInductanceUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricInductanceUnit)) + throw new ArgumentException("The given unit is not of type ElectricInductanceUnit.", nameof(unit)); + + return ToUnit((ElectricInductanceUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricInductanceUnit) unit); + IQuantity IQuantity.ToUnit(ElectricInductanceUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.NetFramework.g.cs index e4866357f5..d33e015610 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.NetFramework.g.cs @@ -603,7 +603,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricPotentialUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricPotentialUnit)) + throw new ArgumentException("The given unit is not of type ElectricPotentialUnit.", nameof(unit)); + + return As((ElectricPotentialUnit)unit); + } /// /// Convert to the unit representation . @@ -618,9 +625,6 @@ public double As(ElectricPotentialUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricPotentialUnit) unit); - /// /// Converts this ElectricPotential to another ElectricPotential with the unit representation . /// @@ -631,10 +635,17 @@ public ElectricPotential ToUnit(ElectricPotentialUnit unit) return new ElectricPotential(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricPotentialUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricPotentialUnit)) + throw new ArgumentException("The given unit is not of type ElectricPotentialUnit.", nameof(unit)); + + return ToUnit((ElectricPotentialUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricPotentialUnit) unit); + IQuantity IQuantity.ToUnit(ElectricPotentialUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.NetFramework.g.cs index 1819f200c8..fb72a9e984 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.NetFramework.g.cs @@ -603,7 +603,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricPotentialAcUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricPotentialAcUnit)) + throw new ArgumentException("The given unit is not of type ElectricPotentialAcUnit.", nameof(unit)); + + return As((ElectricPotentialAcUnit)unit); + } /// /// Convert to the unit representation . @@ -618,9 +625,6 @@ public double As(ElectricPotentialAcUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricPotentialAcUnit) unit); - /// /// Converts this ElectricPotentialAc to another ElectricPotentialAc with the unit representation . /// @@ -631,10 +635,17 @@ public ElectricPotentialAc ToUnit(ElectricPotentialAcUnit unit) return new ElectricPotentialAc(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricPotentialAcUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricPotentialAcUnit)) + throw new ArgumentException("The given unit is not of type ElectricPotentialAcUnit.", nameof(unit)); + + return ToUnit((ElectricPotentialAcUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricPotentialAcUnit) unit); + IQuantity IQuantity.ToUnit(ElectricPotentialAcUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.NetFramework.g.cs index c24f2da1b6..b5c493f16f 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.NetFramework.g.cs @@ -603,7 +603,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricPotentialDcUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricPotentialDcUnit)) + throw new ArgumentException("The given unit is not of type ElectricPotentialDcUnit.", nameof(unit)); + + return As((ElectricPotentialDcUnit)unit); + } /// /// Convert to the unit representation . @@ -618,9 +625,6 @@ public double As(ElectricPotentialDcUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricPotentialDcUnit) unit); - /// /// Converts this ElectricPotentialDc to another ElectricPotentialDc with the unit representation . /// @@ -631,10 +635,17 @@ public ElectricPotentialDc ToUnit(ElectricPotentialDcUnit unit) return new ElectricPotentialDc(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricPotentialDcUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricPotentialDcUnit)) + throw new ArgumentException("The given unit is not of type ElectricPotentialDcUnit.", nameof(unit)); + + return ToUnit((ElectricPotentialDcUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricPotentialDcUnit) unit); + IQuantity IQuantity.ToUnit(ElectricPotentialDcUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.NetFramework.g.cs index 723bbab2e9..c1aed1c586 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.NetFramework.g.cs @@ -603,7 +603,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricResistanceUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricResistanceUnit)) + throw new ArgumentException("The given unit is not of type ElectricResistanceUnit.", nameof(unit)); + + return As((ElectricResistanceUnit)unit); + } /// /// Convert to the unit representation . @@ -618,9 +625,6 @@ public double As(ElectricResistanceUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricResistanceUnit) unit); - /// /// Converts this ElectricResistance to another ElectricResistance with the unit representation . /// @@ -631,10 +635,17 @@ public ElectricResistance ToUnit(ElectricResistanceUnit unit) return new ElectricResistance(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricResistanceUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricResistanceUnit)) + throw new ArgumentException("The given unit is not of type ElectricResistanceUnit.", nameof(unit)); + + return ToUnit((ElectricResistanceUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricResistanceUnit) unit); + IQuantity IQuantity.ToUnit(ElectricResistanceUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.NetFramework.g.cs index 2611f9c063..0d107415c7 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.NetFramework.g.cs @@ -741,7 +741,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ElectricResistivityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricResistivityUnit)) + throw new ArgumentException("The given unit is not of type ElectricResistivityUnit.", nameof(unit)); + + return As((ElectricResistivityUnit)unit); + } /// /// Convert to the unit representation . @@ -756,9 +763,6 @@ public double As(ElectricResistivityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ElectricResistivityUnit) unit); - /// /// Converts this ElectricResistivity to another ElectricResistivity with the unit representation . /// @@ -769,10 +773,17 @@ public ElectricResistivity ToUnit(ElectricResistivityUnit unit) return new ElectricResistivity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ElectricResistivityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ElectricResistivityUnit)) + throw new ArgumentException("The given unit is not of type ElectricResistivityUnit.", nameof(unit)); + + return ToUnit((ElectricResistivityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ElectricResistivityUnit) unit); + IQuantity IQuantity.ToUnit(ElectricResistivityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs index e7162f57bc..025f439723 100644 --- a/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs @@ -873,7 +873,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((EnergyUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is EnergyUnit)) + throw new ArgumentException("The given unit is not of type EnergyUnit.", nameof(unit)); + + return As((EnergyUnit)unit); + } /// /// Convert to the unit representation . @@ -888,9 +895,6 @@ public double As(EnergyUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((EnergyUnit) unit); - /// /// Converts this Energy to another Energy with the unit representation . /// @@ -901,10 +905,17 @@ public Energy ToUnit(EnergyUnit unit) return new Energy(convertedValue, unit); } - IQuantity IQuantity.ToUnit(EnergyUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is EnergyUnit)) + throw new ArgumentException("The given unit is not of type EnergyUnit.", nameof(unit)); + + return ToUnit((EnergyUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((EnergyUnit) unit); + IQuantity IQuantity.ToUnit(EnergyUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Entropy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Entropy.NetFramework.g.cs index 7fb3fa89cd..6fb2c1d775 100644 --- a/UnitsNet/GeneratedCode/Quantities/Entropy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Entropy.NetFramework.g.cs @@ -633,7 +633,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((EntropyUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is EntropyUnit)) + throw new ArgumentException("The given unit is not of type EntropyUnit.", nameof(unit)); + + return As((EntropyUnit)unit); + } /// /// Convert to the unit representation . @@ -648,9 +655,6 @@ public double As(EntropyUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((EntropyUnit) unit); - /// /// Converts this Entropy to another Entropy with the unit representation . /// @@ -661,10 +665,17 @@ public Entropy ToUnit(EntropyUnit unit) return new Entropy(convertedValue, unit); } - IQuantity IQuantity.ToUnit(EntropyUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is EntropyUnit)) + throw new ArgumentException("The given unit is not of type EntropyUnit.", nameof(unit)); + + return ToUnit((EntropyUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((EntropyUnit) unit); + IQuantity IQuantity.ToUnit(EntropyUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Force.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Force.NetFramework.g.cs index c1877c0d24..5fe80fae50 100644 --- a/UnitsNet/GeneratedCode/Quantities/Force.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Force.NetFramework.g.cs @@ -723,7 +723,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ForceUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ForceUnit)) + throw new ArgumentException("The given unit is not of type ForceUnit.", nameof(unit)); + + return As((ForceUnit)unit); + } /// /// Convert to the unit representation . @@ -738,9 +745,6 @@ public double As(ForceUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ForceUnit) unit); - /// /// Converts this Force to another Force with the unit representation . /// @@ -751,10 +755,17 @@ public Force ToUnit(ForceUnit unit) return new Force(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ForceUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ForceUnit)) + throw new ArgumentException("The given unit is not of type ForceUnit.", nameof(unit)); + + return ToUnit((ForceUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ForceUnit) unit); + IQuantity IQuantity.ToUnit(ForceUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.NetFramework.g.cs index 9664365fa8..7f8a53a492 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.NetFramework.g.cs @@ -693,7 +693,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ForceChangeRateUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ForceChangeRateUnit)) + throw new ArgumentException("The given unit is not of type ForceChangeRateUnit.", nameof(unit)); + + return As((ForceChangeRateUnit)unit); + } /// /// Convert to the unit representation . @@ -708,9 +715,6 @@ public double As(ForceChangeRateUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ForceChangeRateUnit) unit); - /// /// Converts this ForceChangeRate to another ForceChangeRate with the unit representation . /// @@ -721,10 +725,17 @@ public ForceChangeRate ToUnit(ForceChangeRateUnit unit) return new ForceChangeRate(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ForceChangeRateUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ForceChangeRateUnit)) + throw new ArgumentException("The given unit is not of type ForceChangeRateUnit.", nameof(unit)); + + return ToUnit((ForceChangeRateUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ForceChangeRateUnit) unit); + IQuantity IQuantity.ToUnit(ForceChangeRateUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.NetFramework.g.cs index 3cb4d872e9..b5e2f990a6 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.NetFramework.g.cs @@ -663,7 +663,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ForcePerLengthUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ForcePerLengthUnit)) + throw new ArgumentException("The given unit is not of type ForcePerLengthUnit.", nameof(unit)); + + return As((ForcePerLengthUnit)unit); + } /// /// Convert to the unit representation . @@ -678,9 +685,6 @@ public double As(ForcePerLengthUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ForcePerLengthUnit) unit); - /// /// Converts this ForcePerLength to another ForcePerLength with the unit representation . /// @@ -691,10 +695,17 @@ public ForcePerLength ToUnit(ForcePerLengthUnit unit) return new ForcePerLength(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ForcePerLengthUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ForcePerLengthUnit)) + throw new ArgumentException("The given unit is not of type ForcePerLengthUnit.", nameof(unit)); + + return ToUnit((ForcePerLengthUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ForcePerLengthUnit) unit); + IQuantity IQuantity.ToUnit(ForcePerLengthUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs index bdae656504..74e8eb7fef 100644 --- a/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs @@ -663,7 +663,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((FrequencyUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is FrequencyUnit)) + throw new ArgumentException("The given unit is not of type FrequencyUnit.", nameof(unit)); + + return As((FrequencyUnit)unit); + } /// /// Convert to the unit representation . @@ -678,9 +685,6 @@ public double As(FrequencyUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((FrequencyUnit) unit); - /// /// Converts this Frequency to another Frequency with the unit representation . /// @@ -691,10 +695,17 @@ public Frequency ToUnit(FrequencyUnit unit) return new Frequency(convertedValue, unit); } - IQuantity IQuantity.ToUnit(FrequencyUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is FrequencyUnit)) + throw new ArgumentException("The given unit is not of type FrequencyUnit.", nameof(unit)); + + return ToUnit((FrequencyUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((FrequencyUnit) unit); + IQuantity IQuantity.ToUnit(FrequencyUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/HeatFlux.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatFlux.NetFramework.g.cs index f52520d4b1..73ba67e181 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatFlux.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatFlux.NetFramework.g.cs @@ -798,7 +798,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((HeatFluxUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is HeatFluxUnit)) + throw new ArgumentException("The given unit is not of type HeatFluxUnit.", nameof(unit)); + + return As((HeatFluxUnit)unit); + } /// /// Convert to the unit representation . @@ -813,9 +820,6 @@ public double As(HeatFluxUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((HeatFluxUnit) unit); - /// /// Converts this HeatFlux to another HeatFlux with the unit representation . /// @@ -826,10 +830,17 @@ public HeatFlux ToUnit(HeatFluxUnit unit) return new HeatFlux(convertedValue, unit); } - IQuantity IQuantity.ToUnit(HeatFluxUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is HeatFluxUnit)) + throw new ArgumentException("The given unit is not of type HeatFluxUnit.", nameof(unit)); + + return ToUnit((HeatFluxUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((HeatFluxUnit) unit); + IQuantity IQuantity.ToUnit(HeatFluxUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.NetFramework.g.cs index 9141e6c20a..8b8de8b16e 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.NetFramework.g.cs @@ -558,7 +558,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((HeatTransferCoefficientUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is HeatTransferCoefficientUnit)) + throw new ArgumentException("The given unit is not of type HeatTransferCoefficientUnit.", nameof(unit)); + + return As((HeatTransferCoefficientUnit)unit); + } /// /// Convert to the unit representation . @@ -573,9 +580,6 @@ public double As(HeatTransferCoefficientUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((HeatTransferCoefficientUnit) unit); - /// /// Converts this HeatTransferCoefficient to another HeatTransferCoefficient with the unit representation . /// @@ -586,10 +590,17 @@ public HeatTransferCoefficient ToUnit(HeatTransferCoefficientUnit unit) return new HeatTransferCoefficient(convertedValue, unit); } - IQuantity IQuantity.ToUnit(HeatTransferCoefficientUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is HeatTransferCoefficientUnit)) + throw new ArgumentException("The given unit is not of type HeatTransferCoefficientUnit.", nameof(unit)); + + return ToUnit((HeatTransferCoefficientUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((HeatTransferCoefficientUnit) unit); + IQuantity IQuantity.ToUnit(HeatTransferCoefficientUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Illuminance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Illuminance.NetFramework.g.cs index b0c2d99059..ffe51215f1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Illuminance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Illuminance.NetFramework.g.cs @@ -591,7 +591,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((IlluminanceUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is IlluminanceUnit)) + throw new ArgumentException("The given unit is not of type IlluminanceUnit.", nameof(unit)); + + return As((IlluminanceUnit)unit); + } /// /// Convert to the unit representation . @@ -606,9 +613,6 @@ public double As(IlluminanceUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((IlluminanceUnit) unit); - /// /// Converts this Illuminance to another Illuminance with the unit representation . /// @@ -619,10 +623,17 @@ public Illuminance ToUnit(IlluminanceUnit unit) return new Illuminance(convertedValue, unit); } - IQuantity IQuantity.ToUnit(IlluminanceUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is IlluminanceUnit)) + throw new ArgumentException("The given unit is not of type IlluminanceUnit.", nameof(unit)); + + return ToUnit((IlluminanceUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((IlluminanceUnit) unit); + IQuantity IQuantity.ToUnit(IlluminanceUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs index 4dd43262b7..8b6179e1b1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs @@ -920,7 +920,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((InformationUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is InformationUnit)) + throw new ArgumentException("The given unit is not of type InformationUnit.", nameof(unit)); + + return As((InformationUnit)unit); + } /// /// Convert to the unit representation . @@ -935,9 +942,6 @@ public double As(InformationUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((InformationUnit) unit); - /// /// Converts this Information to another Information with the unit representation . /// @@ -948,10 +952,17 @@ public Information ToUnit(InformationUnit unit) return new Information(convertedValue, unit); } - IQuantity IQuantity.ToUnit(InformationUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is InformationUnit)) + throw new ArgumentException("The given unit is not of type InformationUnit.", nameof(unit)); + + return ToUnit((InformationUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((InformationUnit) unit); + IQuantity IQuantity.ToUnit(InformationUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiance.NetFramework.g.cs index 0d55364ccf..2680ca351b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiance.NetFramework.g.cs @@ -738,7 +738,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((IrradianceUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is IrradianceUnit)) + throw new ArgumentException("The given unit is not of type IrradianceUnit.", nameof(unit)); + + return As((IrradianceUnit)unit); + } /// /// Convert to the unit representation . @@ -753,9 +760,6 @@ public double As(IrradianceUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((IrradianceUnit) unit); - /// /// Converts this Irradiance to another Irradiance with the unit representation . /// @@ -766,10 +770,17 @@ public Irradiance ToUnit(IrradianceUnit unit) return new Irradiance(convertedValue, unit); } - IQuantity IQuantity.ToUnit(IrradianceUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is IrradianceUnit)) + throw new ArgumentException("The given unit is not of type IrradianceUnit.", nameof(unit)); + + return ToUnit((IrradianceUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((IrradianceUnit) unit); + IQuantity IQuantity.ToUnit(IrradianceUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiation.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiation.NetFramework.g.cs index b3d2019e2f..9935c73e9f 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiation.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiation.NetFramework.g.cs @@ -621,7 +621,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((IrradiationUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is IrradiationUnit)) + throw new ArgumentException("The given unit is not of type IrradiationUnit.", nameof(unit)); + + return As((IrradiationUnit)unit); + } /// /// Convert to the unit representation . @@ -636,9 +643,6 @@ public double As(IrradiationUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((IrradiationUnit) unit); - /// /// Converts this Irradiation to another Irradiation with the unit representation . /// @@ -649,10 +653,17 @@ public Irradiation ToUnit(IrradiationUnit unit) return new Irradiation(convertedValue, unit); } - IQuantity IQuantity.ToUnit(IrradiationUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is IrradiationUnit)) + throw new ArgumentException("The given unit is not of type IrradiationUnit.", nameof(unit)); + + return ToUnit((IrradiationUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((IrradiationUnit) unit); + IQuantity IQuantity.ToUnit(IrradiationUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.NetFramework.g.cs index 562e5c068b..bd9ffe0517 100644 --- a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.NetFramework.g.cs @@ -651,7 +651,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((KinematicViscosityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is KinematicViscosityUnit)) + throw new ArgumentException("The given unit is not of type KinematicViscosityUnit.", nameof(unit)); + + return As((KinematicViscosityUnit)unit); + } /// /// Convert to the unit representation . @@ -666,9 +673,6 @@ public double As(KinematicViscosityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((KinematicViscosityUnit) unit); - /// /// Converts this KinematicViscosity to another KinematicViscosity with the unit representation . /// @@ -679,10 +683,17 @@ public KinematicViscosity ToUnit(KinematicViscosityUnit unit) return new KinematicViscosity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(KinematicViscosityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is KinematicViscosityUnit)) + throw new ArgumentException("The given unit is not of type KinematicViscosityUnit.", nameof(unit)); + + return ToUnit((KinematicViscosityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((KinematicViscosityUnit) unit); + IQuantity IQuantity.ToUnit(KinematicViscosityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/LapseRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/LapseRate.NetFramework.g.cs index 07e3f55bda..3c541f5f44 100644 --- a/UnitsNet/GeneratedCode/Quantities/LapseRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LapseRate.NetFramework.g.cs @@ -543,7 +543,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((LapseRateUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LapseRateUnit)) + throw new ArgumentException("The given unit is not of type LapseRateUnit.", nameof(unit)); + + return As((LapseRateUnit)unit); + } /// /// Convert to the unit representation . @@ -558,9 +565,6 @@ public double As(LapseRateUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((LapseRateUnit) unit); - /// /// Converts this LapseRate to another LapseRate with the unit representation . /// @@ -571,10 +575,17 @@ public LapseRate ToUnit(LapseRateUnit unit) return new LapseRate(convertedValue, unit); } - IQuantity IQuantity.ToUnit(LapseRateUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is LapseRateUnit)) + throw new ArgumentException("The given unit is not of type LapseRateUnit.", nameof(unit)); + + return ToUnit((LapseRateUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((LapseRateUnit) unit); + IQuantity IQuantity.ToUnit(LapseRateUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Length.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.NetFramework.g.cs index 1c94d82da8..05c4dda067 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.NetFramework.g.cs @@ -858,7 +858,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((LengthUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LengthUnit)) + throw new ArgumentException("The given unit is not of type LengthUnit.", nameof(unit)); + + return As((LengthUnit)unit); + } /// /// Convert to the unit representation . @@ -873,9 +880,6 @@ public double As(LengthUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((LengthUnit) unit); - /// /// Converts this Length to another Length with the unit representation . /// @@ -886,10 +890,17 @@ public Length ToUnit(LengthUnit unit) return new Length(convertedValue, unit); } - IQuantity IQuantity.ToUnit(LengthUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is LengthUnit)) + throw new ArgumentException("The given unit is not of type LengthUnit.", nameof(unit)); + + return ToUnit((LengthUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((LengthUnit) unit); + IQuantity IQuantity.ToUnit(LengthUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Level.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Level.NetFramework.g.cs index 5a6d5ccf02..9ebd3845ce 100644 --- a/UnitsNet/GeneratedCode/Quantities/Level.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Level.NetFramework.g.cs @@ -566,7 +566,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((LevelUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LevelUnit)) + throw new ArgumentException("The given unit is not of type LevelUnit.", nameof(unit)); + + return As((LevelUnit)unit); + } /// /// Convert to the unit representation . @@ -581,9 +588,6 @@ public double As(LevelUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((LevelUnit) unit); - /// /// Converts this Level to another Level with the unit representation . /// @@ -594,10 +598,17 @@ public Level ToUnit(LevelUnit unit) return new Level(convertedValue, unit); } - IQuantity IQuantity.ToUnit(LevelUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is LevelUnit)) + throw new ArgumentException("The given unit is not of type LevelUnit.", nameof(unit)); + + return ToUnit((LevelUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((LevelUnit) unit); + IQuantity IQuantity.ToUnit(LevelUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/LinearDensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearDensity.NetFramework.g.cs index 8a936b8190..8b1a77e222 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearDensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearDensity.NetFramework.g.cs @@ -576,7 +576,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((LinearDensityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LinearDensityUnit)) + throw new ArgumentException("The given unit is not of type LinearDensityUnit.", nameof(unit)); + + return As((LinearDensityUnit)unit); + } /// /// Convert to the unit representation . @@ -591,9 +598,6 @@ public double As(LinearDensityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((LinearDensityUnit) unit); - /// /// Converts this LinearDensity to another LinearDensity with the unit representation . /// @@ -604,10 +608,17 @@ public LinearDensity ToUnit(LinearDensityUnit unit) return new LinearDensity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(LinearDensityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is LinearDensityUnit)) + throw new ArgumentException("The given unit is not of type LinearDensityUnit.", nameof(unit)); + + return ToUnit((LinearDensityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((LinearDensityUnit) unit); + IQuantity IQuantity.ToUnit(LinearDensityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.NetFramework.g.cs index cb72be3ba5..3937742930 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((LuminousFluxUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LuminousFluxUnit)) + throw new ArgumentException("The given unit is not of type LuminousFluxUnit.", nameof(unit)); + + return As((LuminousFluxUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(LuminousFluxUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((LuminousFluxUnit) unit); - /// /// Converts this LuminousFlux to another LuminousFlux with the unit representation . /// @@ -574,10 +578,17 @@ public LuminousFlux ToUnit(LuminousFluxUnit unit) return new LuminousFlux(convertedValue, unit); } - IQuantity IQuantity.ToUnit(LuminousFluxUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is LuminousFluxUnit)) + throw new ArgumentException("The given unit is not of type LuminousFluxUnit.", nameof(unit)); + + return ToUnit((LuminousFluxUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((LuminousFluxUnit) unit); + IQuantity IQuantity.ToUnit(LuminousFluxUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.NetFramework.g.cs index cd289b785f..f1a7002b7f 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((LuminousIntensityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LuminousIntensityUnit)) + throw new ArgumentException("The given unit is not of type LuminousIntensityUnit.", nameof(unit)); + + return As((LuminousIntensityUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(LuminousIntensityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((LuminousIntensityUnit) unit); - /// /// Converts this LuminousIntensity to another LuminousIntensity with the unit representation . /// @@ -574,10 +578,17 @@ public LuminousIntensity ToUnit(LuminousIntensityUnit unit) return new LuminousIntensity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(LuminousIntensityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is LuminousIntensityUnit)) + throw new ArgumentException("The given unit is not of type LuminousIntensityUnit.", nameof(unit)); + + return ToUnit((LuminousIntensityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((LuminousIntensityUnit) unit); + IQuantity IQuantity.ToUnit(LuminousIntensityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticField.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticField.NetFramework.g.cs index 0845537d76..69580dc2a3 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticField.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticField.NetFramework.g.cs @@ -591,7 +591,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((MagneticFieldUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MagneticFieldUnit)) + throw new ArgumentException("The given unit is not of type MagneticFieldUnit.", nameof(unit)); + + return As((MagneticFieldUnit)unit); + } /// /// Convert to the unit representation . @@ -606,9 +613,6 @@ public double As(MagneticFieldUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((MagneticFieldUnit) unit); - /// /// Converts this MagneticField to another MagneticField with the unit representation . /// @@ -619,10 +623,17 @@ public MagneticField ToUnit(MagneticFieldUnit unit) return new MagneticField(convertedValue, unit); } - IQuantity IQuantity.ToUnit(MagneticFieldUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MagneticFieldUnit)) + throw new ArgumentException("The given unit is not of type MagneticFieldUnit.", nameof(unit)); + + return ToUnit((MagneticFieldUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((MagneticFieldUnit) unit); + IQuantity IQuantity.ToUnit(MagneticFieldUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.NetFramework.g.cs index 35bb98976c..eb42affbd7 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((MagneticFluxUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MagneticFluxUnit)) + throw new ArgumentException("The given unit is not of type MagneticFluxUnit.", nameof(unit)); + + return As((MagneticFluxUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(MagneticFluxUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((MagneticFluxUnit) unit); - /// /// Converts this MagneticFlux to another MagneticFlux with the unit representation . /// @@ -574,10 +578,17 @@ public MagneticFlux ToUnit(MagneticFluxUnit unit) return new MagneticFlux(convertedValue, unit); } - IQuantity IQuantity.ToUnit(MagneticFluxUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MagneticFluxUnit)) + throw new ArgumentException("The given unit is not of type MagneticFluxUnit.", nameof(unit)); + + return ToUnit((MagneticFluxUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((MagneticFluxUnit) unit); + IQuantity IQuantity.ToUnit(MagneticFluxUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Magnetization.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Magnetization.NetFramework.g.cs index 870fc4b9a4..98a94de054 100644 --- a/UnitsNet/GeneratedCode/Quantities/Magnetization.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Magnetization.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((MagnetizationUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MagnetizationUnit)) + throw new ArgumentException("The given unit is not of type MagnetizationUnit.", nameof(unit)); + + return As((MagnetizationUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(MagnetizationUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((MagnetizationUnit) unit); - /// /// Converts this Magnetization to another Magnetization with the unit representation . /// @@ -574,10 +578,17 @@ public Magnetization ToUnit(MagnetizationUnit unit) return new Magnetization(convertedValue, unit); } - IQuantity IQuantity.ToUnit(MagnetizationUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MagnetizationUnit)) + throw new ArgumentException("The given unit is not of type MagnetizationUnit.", nameof(unit)); + + return ToUnit((MagnetizationUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((MagnetizationUnit) unit); + IQuantity IQuantity.ToUnit(MagnetizationUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs index 2da65a46e6..9cc253476b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs @@ -873,7 +873,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((MassUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MassUnit)) + throw new ArgumentException("The given unit is not of type MassUnit.", nameof(unit)); + + return As((MassUnit)unit); + } /// /// Convert to the unit representation . @@ -888,9 +895,6 @@ public double As(MassUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((MassUnit) unit); - /// /// Converts this Mass to another Mass with the unit representation . /// @@ -901,10 +905,17 @@ public Mass ToUnit(MassUnit unit) return new Mass(convertedValue, unit); } - IQuantity IQuantity.ToUnit(MassUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MassUnit)) + throw new ArgumentException("The given unit is not of type MassUnit.", nameof(unit)); + + return ToUnit((MassUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((MassUnit) unit); + IQuantity IQuantity.ToUnit(MassUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlow.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlow.NetFramework.g.cs index 15f9f845d3..944784fa61 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlow.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlow.NetFramework.g.cs @@ -993,7 +993,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((MassFlowUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MassFlowUnit)) + throw new ArgumentException("The given unit is not of type MassFlowUnit.", nameof(unit)); + + return As((MassFlowUnit)unit); + } /// /// Convert to the unit representation . @@ -1008,9 +1015,6 @@ public double As(MassFlowUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((MassFlowUnit) unit); - /// /// Converts this MassFlow to another MassFlow with the unit representation . /// @@ -1021,10 +1025,17 @@ public MassFlow ToUnit(MassFlowUnit unit) return new MassFlow(convertedValue, unit); } - IQuantity IQuantity.ToUnit(MassFlowUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MassFlowUnit)) + throw new ArgumentException("The given unit is not of type MassFlowUnit.", nameof(unit)); + + return ToUnit((MassFlowUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((MassFlowUnit) unit); + IQuantity IQuantity.ToUnit(MassFlowUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlux.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlux.NetFramework.g.cs index cfcc82fb6f..3db79074dd 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlux.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlux.NetFramework.g.cs @@ -558,7 +558,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((MassFluxUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MassFluxUnit)) + throw new ArgumentException("The given unit is not of type MassFluxUnit.", nameof(unit)); + + return As((MassFluxUnit)unit); + } /// /// Convert to the unit representation . @@ -573,9 +580,6 @@ public double As(MassFluxUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((MassFluxUnit) unit); - /// /// Converts this MassFlux to another MassFlux with the unit representation . /// @@ -586,10 +590,17 @@ public MassFlux ToUnit(MassFluxUnit unit) return new MassFlux(convertedValue, unit); } - IQuantity IQuantity.ToUnit(MassFluxUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MassFluxUnit)) + throw new ArgumentException("The given unit is not of type MassFluxUnit.", nameof(unit)); + + return ToUnit((MassFluxUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((MassFluxUnit) unit); + IQuantity IQuantity.ToUnit(MassFluxUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs index 16e3b8335d..fd551d3b4f 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs @@ -948,7 +948,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((MassMomentOfInertiaUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MassMomentOfInertiaUnit)) + throw new ArgumentException("The given unit is not of type MassMomentOfInertiaUnit.", nameof(unit)); + + return As((MassMomentOfInertiaUnit)unit); + } /// /// Convert to the unit representation . @@ -963,9 +970,6 @@ public double As(MassMomentOfInertiaUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((MassMomentOfInertiaUnit) unit); - /// /// Converts this MassMomentOfInertia to another MassMomentOfInertia with the unit representation . /// @@ -976,10 +980,17 @@ public MassMomentOfInertia ToUnit(MassMomentOfInertiaUnit unit) return new MassMomentOfInertia(convertedValue, unit); } - IQuantity IQuantity.ToUnit(MassMomentOfInertiaUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MassMomentOfInertiaUnit)) + throw new ArgumentException("The given unit is not of type MassMomentOfInertiaUnit.", nameof(unit)); + + return ToUnit((MassMomentOfInertiaUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((MassMomentOfInertiaUnit) unit); + IQuantity IQuantity.ToUnit(MassMomentOfInertiaUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.NetFramework.g.cs index f73668b9a8..bde9124537 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.NetFramework.g.cs @@ -573,7 +573,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((MolarEnergyUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MolarEnergyUnit)) + throw new ArgumentException("The given unit is not of type MolarEnergyUnit.", nameof(unit)); + + return As((MolarEnergyUnit)unit); + } /// /// Convert to the unit representation . @@ -588,9 +595,6 @@ public double As(MolarEnergyUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((MolarEnergyUnit) unit); - /// /// Converts this MolarEnergy to another MolarEnergy with the unit representation . /// @@ -601,10 +605,17 @@ public MolarEnergy ToUnit(MolarEnergyUnit unit) return new MolarEnergy(convertedValue, unit); } - IQuantity IQuantity.ToUnit(MolarEnergyUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MolarEnergyUnit)) + throw new ArgumentException("The given unit is not of type MolarEnergyUnit.", nameof(unit)); + + return ToUnit((MolarEnergyUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((MolarEnergyUnit) unit); + IQuantity IQuantity.ToUnit(MolarEnergyUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.NetFramework.g.cs index 6051f01206..b327fc2112 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.NetFramework.g.cs @@ -573,7 +573,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((MolarEntropyUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MolarEntropyUnit)) + throw new ArgumentException("The given unit is not of type MolarEntropyUnit.", nameof(unit)); + + return As((MolarEntropyUnit)unit); + } /// /// Convert to the unit representation . @@ -588,9 +595,6 @@ public double As(MolarEntropyUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((MolarEntropyUnit) unit); - /// /// Converts this MolarEntropy to another MolarEntropy with the unit representation . /// @@ -601,10 +605,17 @@ public MolarEntropy ToUnit(MolarEntropyUnit unit) return new MolarEntropy(convertedValue, unit); } - IQuantity IQuantity.ToUnit(MolarEntropyUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MolarEntropyUnit)) + throw new ArgumentException("The given unit is not of type MolarEntropyUnit.", nameof(unit)); + + return ToUnit((MolarEntropyUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((MolarEntropyUnit) unit); + IQuantity IQuantity.ToUnit(MolarEntropyUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/MolarMass.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarMass.NetFramework.g.cs index d36b38c96a..b2ade25c57 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarMass.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarMass.NetFramework.g.cs @@ -708,7 +708,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((MolarMassUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MolarMassUnit)) + throw new ArgumentException("The given unit is not of type MolarMassUnit.", nameof(unit)); + + return As((MolarMassUnit)unit); + } /// /// Convert to the unit representation . @@ -723,9 +730,6 @@ public double As(MolarMassUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((MolarMassUnit) unit); - /// /// Converts this MolarMass to another MolarMass with the unit representation . /// @@ -736,10 +740,17 @@ public MolarMass ToUnit(MolarMassUnit unit) return new MolarMass(convertedValue, unit); } - IQuantity IQuantity.ToUnit(MolarMassUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MolarMassUnit)) + throw new ArgumentException("The given unit is not of type MolarMassUnit.", nameof(unit)); + + return ToUnit((MolarMassUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((MolarMassUnit) unit); + IQuantity IQuantity.ToUnit(MolarMassUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs index a499b07e48..310db5f2d3 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs @@ -651,7 +651,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((MolarityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MolarityUnit)) + throw new ArgumentException("The given unit is not of type MolarityUnit.", nameof(unit)); + + return As((MolarityUnit)unit); + } /// /// Convert to the unit representation . @@ -666,9 +673,6 @@ public double As(MolarityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((MolarityUnit) unit); - /// /// Converts this Molarity to another Molarity with the unit representation . /// @@ -679,10 +683,17 @@ public Molarity ToUnit(MolarityUnit unit) return new Molarity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(MolarityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is MolarityUnit)) + throw new ArgumentException("The given unit is not of type MolarityUnit.", nameof(unit)); + + return ToUnit((MolarityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((MolarityUnit) unit); + IQuantity IQuantity.ToUnit(MolarityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Permeability.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Permeability.NetFramework.g.cs index 585f494869..7e4bbb1663 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permeability.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permeability.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((PermeabilityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PermeabilityUnit)) + throw new ArgumentException("The given unit is not of type PermeabilityUnit.", nameof(unit)); + + return As((PermeabilityUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(PermeabilityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((PermeabilityUnit) unit); - /// /// Converts this Permeability to another Permeability with the unit representation . /// @@ -574,10 +578,17 @@ public Permeability ToUnit(PermeabilityUnit unit) return new Permeability(convertedValue, unit); } - IQuantity IQuantity.ToUnit(PermeabilityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is PermeabilityUnit)) + throw new ArgumentException("The given unit is not of type PermeabilityUnit.", nameof(unit)); + + return ToUnit((PermeabilityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((PermeabilityUnit) unit); + IQuantity IQuantity.ToUnit(PermeabilityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Permittivity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Permittivity.NetFramework.g.cs index 40e506f8fc..b0aef361d4 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permittivity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permittivity.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((PermittivityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PermittivityUnit)) + throw new ArgumentException("The given unit is not of type PermittivityUnit.", nameof(unit)); + + return As((PermittivityUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(PermittivityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((PermittivityUnit) unit); - /// /// Converts this Permittivity to another Permittivity with the unit representation . /// @@ -574,10 +578,17 @@ public Permittivity ToUnit(PermittivityUnit unit) return new Permittivity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(PermittivityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is PermittivityUnit)) + throw new ArgumentException("The given unit is not of type PermittivityUnit.", nameof(unit)); + + return ToUnit((PermittivityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((PermittivityUnit) unit); + IQuantity IQuantity.ToUnit(PermittivityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs index f5fcf71b3e..9bc1bb44e6 100644 --- a/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs @@ -830,7 +830,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((PowerUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PowerUnit)) + throw new ArgumentException("The given unit is not of type PowerUnit.", nameof(unit)); + + return As((PowerUnit)unit); + } /// /// Convert to the unit representation . @@ -845,9 +852,6 @@ public double As(PowerUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((PowerUnit) unit); - /// /// Converts this Power to another Power with the unit representation . /// @@ -858,10 +862,17 @@ public Power ToUnit(PowerUnit unit) return new Power(convertedValue, unit); } - IQuantity IQuantity.ToUnit(PowerUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is PowerUnit)) + throw new ArgumentException("The given unit is not of type PowerUnit.", nameof(unit)); + + return ToUnit((PowerUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((PowerUnit) unit); + IQuantity IQuantity.ToUnit(PowerUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/PowerDensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerDensity.NetFramework.g.cs index 68bfc8c282..b8a0993cd1 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerDensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerDensity.NetFramework.g.cs @@ -1188,7 +1188,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((PowerDensityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PowerDensityUnit)) + throw new ArgumentException("The given unit is not of type PowerDensityUnit.", nameof(unit)); + + return As((PowerDensityUnit)unit); + } /// /// Convert to the unit representation . @@ -1203,9 +1210,6 @@ public double As(PowerDensityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((PowerDensityUnit) unit); - /// /// Converts this PowerDensity to another PowerDensity with the unit representation . /// @@ -1216,10 +1220,17 @@ public PowerDensity ToUnit(PowerDensityUnit unit) return new PowerDensity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(PowerDensityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is PowerDensityUnit)) + throw new ArgumentException("The given unit is not of type PowerDensityUnit.", nameof(unit)); + + return ToUnit((PowerDensityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((PowerDensityUnit) unit); + IQuantity IQuantity.ToUnit(PowerDensityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/PowerRatio.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerRatio.NetFramework.g.cs index 30b3aba752..591859e3d2 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerRatio.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerRatio.NetFramework.g.cs @@ -566,7 +566,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((PowerRatioUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PowerRatioUnit)) + throw new ArgumentException("The given unit is not of type PowerRatioUnit.", nameof(unit)); + + return As((PowerRatioUnit)unit); + } /// /// Convert to the unit representation . @@ -581,9 +588,6 @@ public double As(PowerRatioUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((PowerRatioUnit) unit); - /// /// Converts this PowerRatio to another PowerRatio with the unit representation . /// @@ -594,10 +598,17 @@ public PowerRatio ToUnit(PowerRatioUnit unit) return new PowerRatio(convertedValue, unit); } - IQuantity IQuantity.ToUnit(PowerRatioUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is PowerRatioUnit)) + throw new ArgumentException("The given unit is not of type PowerRatioUnit.", nameof(unit)); + + return ToUnit((PowerRatioUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((PowerRatioUnit) unit); + IQuantity IQuantity.ToUnit(PowerRatioUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Pressure.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Pressure.NetFramework.g.cs index 080407e2cc..9ce8c0403e 100644 --- a/UnitsNet/GeneratedCode/Quantities/Pressure.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Pressure.NetFramework.g.cs @@ -1158,7 +1158,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((PressureUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PressureUnit)) + throw new ArgumentException("The given unit is not of type PressureUnit.", nameof(unit)); + + return As((PressureUnit)unit); + } /// /// Convert to the unit representation . @@ -1173,9 +1180,6 @@ public double As(PressureUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((PressureUnit) unit); - /// /// Converts this Pressure to another Pressure with the unit representation . /// @@ -1186,10 +1190,17 @@ public Pressure ToUnit(PressureUnit unit) return new Pressure(convertedValue, unit); } - IQuantity IQuantity.ToUnit(PressureUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is PressureUnit)) + throw new ArgumentException("The given unit is not of type PressureUnit.", nameof(unit)); + + return ToUnit((PressureUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((PressureUnit) unit); + IQuantity IQuantity.ToUnit(PressureUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.NetFramework.g.cs index 3f29473d98..f2f47f0f76 100644 --- a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.NetFramework.g.cs @@ -633,7 +633,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((PressureChangeRateUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PressureChangeRateUnit)) + throw new ArgumentException("The given unit is not of type PressureChangeRateUnit.", nameof(unit)); + + return As((PressureChangeRateUnit)unit); + } /// /// Convert to the unit representation . @@ -648,9 +655,6 @@ public double As(PressureChangeRateUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((PressureChangeRateUnit) unit); - /// /// Converts this PressureChangeRate to another PressureChangeRate with the unit representation . /// @@ -661,10 +665,17 @@ public PressureChangeRate ToUnit(PressureChangeRateUnit unit) return new PressureChangeRate(convertedValue, unit); } - IQuantity IQuantity.ToUnit(PressureChangeRateUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is PressureChangeRateUnit)) + throw new ArgumentException("The given unit is not of type PressureChangeRateUnit.", nameof(unit)); + + return ToUnit((PressureChangeRateUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((PressureChangeRateUnit) unit); + IQuantity IQuantity.ToUnit(PressureChangeRateUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Ratio.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Ratio.NetFramework.g.cs index a23c174e11..8cadd4cabe 100644 --- a/UnitsNet/GeneratedCode/Quantities/Ratio.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Ratio.NetFramework.g.cs @@ -618,7 +618,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((RatioUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is RatioUnit)) + throw new ArgumentException("The given unit is not of type RatioUnit.", nameof(unit)); + + return As((RatioUnit)unit); + } /// /// Convert to the unit representation . @@ -633,9 +640,6 @@ public double As(RatioUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((RatioUnit) unit); - /// /// Converts this Ratio to another Ratio with the unit representation . /// @@ -646,10 +650,17 @@ public Ratio ToUnit(RatioUnit unit) return new Ratio(convertedValue, unit); } - IQuantity IQuantity.ToUnit(RatioUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is RatioUnit)) + throw new ArgumentException("The given unit is not of type RatioUnit.", nameof(unit)); + + return ToUnit((RatioUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((RatioUnit) unit); + IQuantity IQuantity.ToUnit(RatioUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.NetFramework.g.cs index 7cd6e1a617..f34e10783c 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.NetFramework.g.cs @@ -573,7 +573,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ReactiveEnergyUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ReactiveEnergyUnit)) + throw new ArgumentException("The given unit is not of type ReactiveEnergyUnit.", nameof(unit)); + + return As((ReactiveEnergyUnit)unit); + } /// /// Convert to the unit representation . @@ -588,9 +595,6 @@ public double As(ReactiveEnergyUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ReactiveEnergyUnit) unit); - /// /// Converts this ReactiveEnergy to another ReactiveEnergy with the unit representation . /// @@ -601,10 +605,17 @@ public ReactiveEnergy ToUnit(ReactiveEnergyUnit unit) return new ReactiveEnergy(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ReactiveEnergyUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ReactiveEnergyUnit)) + throw new ArgumentException("The given unit is not of type ReactiveEnergyUnit.", nameof(unit)); + + return ToUnit((ReactiveEnergyUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ReactiveEnergyUnit) unit); + IQuantity IQuantity.ToUnit(ReactiveEnergyUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ReactivePower.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactivePower.NetFramework.g.cs index ba9efbe22a..171cb3fded 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactivePower.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactivePower.NetFramework.g.cs @@ -588,7 +588,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ReactivePowerUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ReactivePowerUnit)) + throw new ArgumentException("The given unit is not of type ReactivePowerUnit.", nameof(unit)); + + return As((ReactivePowerUnit)unit); + } /// /// Convert to the unit representation . @@ -603,9 +610,6 @@ public double As(ReactivePowerUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ReactivePowerUnit) unit); - /// /// Converts this ReactivePower to another ReactivePower with the unit representation . /// @@ -616,10 +620,17 @@ public ReactivePower ToUnit(ReactivePowerUnit unit) return new ReactivePower(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ReactivePowerUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ReactivePowerUnit)) + throw new ArgumentException("The given unit is not of type ReactivePowerUnit.", nameof(unit)); + + return ToUnit((ReactivePowerUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ReactivePowerUnit) unit); + IQuantity IQuantity.ToUnit(ReactivePowerUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.NetFramework.g.cs index 9344a94abc..b5928a135d 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.NetFramework.g.cs @@ -573,7 +573,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((RotationalAccelerationUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is RotationalAccelerationUnit)) + throw new ArgumentException("The given unit is not of type RotationalAccelerationUnit.", nameof(unit)); + + return As((RotationalAccelerationUnit)unit); + } /// /// Convert to the unit representation . @@ -588,9 +595,6 @@ public double As(RotationalAccelerationUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((RotationalAccelerationUnit) unit); - /// /// Converts this RotationalAcceleration to another RotationalAcceleration with the unit representation . /// @@ -601,10 +605,17 @@ public RotationalAcceleration ToUnit(RotationalAccelerationUnit unit) return new RotationalAcceleration(convertedValue, unit); } - IQuantity IQuantity.ToUnit(RotationalAccelerationUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is RotationalAccelerationUnit)) + throw new ArgumentException("The given unit is not of type RotationalAccelerationUnit.", nameof(unit)); + + return ToUnit((RotationalAccelerationUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((RotationalAccelerationUnit) unit); + IQuantity IQuantity.ToUnit(RotationalAccelerationUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.NetFramework.g.cs index ed4fb1c79f..d88e6cdb24 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.NetFramework.g.cs @@ -723,7 +723,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((RotationalSpeedUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is RotationalSpeedUnit)) + throw new ArgumentException("The given unit is not of type RotationalSpeedUnit.", nameof(unit)); + + return As((RotationalSpeedUnit)unit); + } /// /// Convert to the unit representation . @@ -738,9 +745,6 @@ public double As(RotationalSpeedUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((RotationalSpeedUnit) unit); - /// /// Converts this RotationalSpeed to another RotationalSpeed with the unit representation . /// @@ -751,10 +755,17 @@ public RotationalSpeed ToUnit(RotationalSpeedUnit unit) return new RotationalSpeed(convertedValue, unit); } - IQuantity IQuantity.ToUnit(RotationalSpeedUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is RotationalSpeedUnit)) + throw new ArgumentException("The given unit is not of type RotationalSpeedUnit.", nameof(unit)); + + return ToUnit((RotationalSpeedUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((RotationalSpeedUnit) unit); + IQuantity IQuantity.ToUnit(RotationalSpeedUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.NetFramework.g.cs index f1ef773447..fc3f0554a0 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.NetFramework.g.cs @@ -573,7 +573,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((RotationalStiffnessUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is RotationalStiffnessUnit)) + throw new ArgumentException("The given unit is not of type RotationalStiffnessUnit.", nameof(unit)); + + return As((RotationalStiffnessUnit)unit); + } /// /// Convert to the unit representation . @@ -588,9 +595,6 @@ public double As(RotationalStiffnessUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((RotationalStiffnessUnit) unit); - /// /// Converts this RotationalStiffness to another RotationalStiffness with the unit representation . /// @@ -601,10 +605,17 @@ public RotationalStiffness ToUnit(RotationalStiffnessUnit unit) return new RotationalStiffness(convertedValue, unit); } - IQuantity IQuantity.ToUnit(RotationalStiffnessUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is RotationalStiffnessUnit)) + throw new ArgumentException("The given unit is not of type RotationalStiffnessUnit.", nameof(unit)); + + return ToUnit((RotationalStiffnessUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((RotationalStiffnessUnit) unit); + IQuantity IQuantity.ToUnit(RotationalStiffnessUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.NetFramework.g.cs index c4c5bb595f..d3280928b6 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.NetFramework.g.cs @@ -573,7 +573,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((RotationalStiffnessPerLengthUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is RotationalStiffnessPerLengthUnit)) + throw new ArgumentException("The given unit is not of type RotationalStiffnessPerLengthUnit.", nameof(unit)); + + return As((RotationalStiffnessPerLengthUnit)unit); + } /// /// Convert to the unit representation . @@ -588,9 +595,6 @@ public double As(RotationalStiffnessPerLengthUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((RotationalStiffnessPerLengthUnit) unit); - /// /// Converts this RotationalStiffnessPerLength to another RotationalStiffnessPerLength with the unit representation . /// @@ -601,10 +605,17 @@ public RotationalStiffnessPerLength ToUnit(RotationalStiffnessPerLengthUnit unit return new RotationalStiffnessPerLength(convertedValue, unit); } - IQuantity IQuantity.ToUnit(RotationalStiffnessPerLengthUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is RotationalStiffnessPerLengthUnit)) + throw new ArgumentException("The given unit is not of type RotationalStiffnessPerLengthUnit.", nameof(unit)); + + return ToUnit((RotationalStiffnessPerLengthUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((RotationalStiffnessPerLengthUnit) unit); + IQuantity IQuantity.ToUnit(RotationalStiffnessPerLengthUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/SolidAngle.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/SolidAngle.NetFramework.g.cs index a9c136c3a4..cbcd4b5519 100644 --- a/UnitsNet/GeneratedCode/Quantities/SolidAngle.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SolidAngle.NetFramework.g.cs @@ -546,7 +546,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((SolidAngleUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SolidAngleUnit)) + throw new ArgumentException("The given unit is not of type SolidAngleUnit.", nameof(unit)); + + return As((SolidAngleUnit)unit); + } /// /// Convert to the unit representation . @@ -561,9 +568,6 @@ public double As(SolidAngleUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((SolidAngleUnit) unit); - /// /// Converts this SolidAngle to another SolidAngle with the unit representation . /// @@ -574,10 +578,17 @@ public SolidAngle ToUnit(SolidAngleUnit unit) return new SolidAngle(convertedValue, unit); } - IQuantity IQuantity.ToUnit(SolidAngleUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is SolidAngleUnit)) + throw new ArgumentException("The given unit is not of type SolidAngleUnit.", nameof(unit)); + + return ToUnit((SolidAngleUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((SolidAngleUnit) unit); + IQuantity IQuantity.ToUnit(SolidAngleUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.NetFramework.g.cs index 113664efa3..569840c497 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.NetFramework.g.cs @@ -666,7 +666,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((SpecificEnergyUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SpecificEnergyUnit)) + throw new ArgumentException("The given unit is not of type SpecificEnergyUnit.", nameof(unit)); + + return As((SpecificEnergyUnit)unit); + } /// /// Convert to the unit representation . @@ -681,9 +688,6 @@ public double As(SpecificEnergyUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((SpecificEnergyUnit) unit); - /// /// Converts this SpecificEnergy to another SpecificEnergy with the unit representation . /// @@ -694,10 +698,17 @@ public SpecificEnergy ToUnit(SpecificEnergyUnit unit) return new SpecificEnergy(convertedValue, unit); } - IQuantity IQuantity.ToUnit(SpecificEnergyUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is SpecificEnergyUnit)) + throw new ArgumentException("The given unit is not of type SpecificEnergyUnit.", nameof(unit)); + + return ToUnit((SpecificEnergyUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((SpecificEnergyUnit) unit); + IQuantity IQuantity.ToUnit(SpecificEnergyUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.NetFramework.g.cs index 1c50821997..7d9b6b7bb5 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.NetFramework.g.cs @@ -648,7 +648,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((SpecificEntropyUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SpecificEntropyUnit)) + throw new ArgumentException("The given unit is not of type SpecificEntropyUnit.", nameof(unit)); + + return As((SpecificEntropyUnit)unit); + } /// /// Convert to the unit representation . @@ -663,9 +670,6 @@ public double As(SpecificEntropyUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((SpecificEntropyUnit) unit); - /// /// Converts this SpecificEntropy to another SpecificEntropy with the unit representation . /// @@ -676,10 +680,17 @@ public SpecificEntropy ToUnit(SpecificEntropyUnit unit) return new SpecificEntropy(convertedValue, unit); } - IQuantity IQuantity.ToUnit(SpecificEntropyUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is SpecificEntropyUnit)) + throw new ArgumentException("The given unit is not of type SpecificEntropyUnit.", nameof(unit)); + + return ToUnit((SpecificEntropyUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((SpecificEntropyUnit) unit); + IQuantity IQuantity.ToUnit(SpecificEntropyUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.NetFramework.g.cs index 9f78f2e74a..8b12852d22 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.NetFramework.g.cs @@ -573,7 +573,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((SpecificVolumeUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SpecificVolumeUnit)) + throw new ArgumentException("The given unit is not of type SpecificVolumeUnit.", nameof(unit)); + + return As((SpecificVolumeUnit)unit); + } /// /// Convert to the unit representation . @@ -588,9 +595,6 @@ public double As(SpecificVolumeUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((SpecificVolumeUnit) unit); - /// /// Converts this SpecificVolume to another SpecificVolume with the unit representation . /// @@ -601,10 +605,17 @@ public SpecificVolume ToUnit(SpecificVolumeUnit unit) return new SpecificVolume(convertedValue, unit); } - IQuantity IQuantity.ToUnit(SpecificVolumeUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is SpecificVolumeUnit)) + throw new ArgumentException("The given unit is not of type SpecificVolumeUnit.", nameof(unit)); + + return ToUnit((SpecificVolumeUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((SpecificVolumeUnit) unit); + IQuantity IQuantity.ToUnit(SpecificVolumeUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.NetFramework.g.cs index 69132ce56d..5f4e50b093 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.NetFramework.g.cs @@ -786,7 +786,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((SpecificWeightUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SpecificWeightUnit)) + throw new ArgumentException("The given unit is not of type SpecificWeightUnit.", nameof(unit)); + + return As((SpecificWeightUnit)unit); + } /// /// Convert to the unit representation . @@ -801,9 +808,6 @@ public double As(SpecificWeightUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((SpecificWeightUnit) unit); - /// /// Converts this SpecificWeight to another SpecificWeight with the unit representation . /// @@ -814,10 +818,17 @@ public SpecificWeight ToUnit(SpecificWeightUnit unit) return new SpecificWeight(convertedValue, unit); } - IQuantity IQuantity.ToUnit(SpecificWeightUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is SpecificWeightUnit)) + throw new ArgumentException("The given unit is not of type SpecificWeightUnit.", nameof(unit)); + + return ToUnit((SpecificWeightUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((SpecificWeightUnit) unit); + IQuantity IQuantity.ToUnit(SpecificWeightUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Speed.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Speed.NetFramework.g.cs index faf9409a7f..faf37f6b87 100644 --- a/UnitsNet/GeneratedCode/Quantities/Speed.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Speed.NetFramework.g.cs @@ -1008,7 +1008,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((SpeedUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SpeedUnit)) + throw new ArgumentException("The given unit is not of type SpeedUnit.", nameof(unit)); + + return As((SpeedUnit)unit); + } /// /// Convert to the unit representation . @@ -1023,9 +1030,6 @@ public double As(SpeedUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((SpeedUnit) unit); - /// /// Converts this Speed to another Speed with the unit representation . /// @@ -1036,10 +1040,17 @@ public Speed ToUnit(SpeedUnit unit) return new Speed(convertedValue, unit); } - IQuantity IQuantity.ToUnit(SpeedUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is SpeedUnit)) + throw new ArgumentException("The given unit is not of type SpeedUnit.", nameof(unit)); + + return ToUnit((SpeedUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((SpeedUnit) unit); + IQuantity IQuantity.ToUnit(SpeedUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Temperature.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Temperature.NetFramework.g.cs index 973a69ac2b..e640d25efd 100644 --- a/UnitsNet/GeneratedCode/Quantities/Temperature.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Temperature.NetFramework.g.cs @@ -602,7 +602,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((TemperatureUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is TemperatureUnit)) + throw new ArgumentException("The given unit is not of type TemperatureUnit.", nameof(unit)); + + return As((TemperatureUnit)unit); + } /// /// Convert to the unit representation . @@ -617,9 +624,6 @@ public double As(TemperatureUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((TemperatureUnit) unit); - /// /// Converts this Temperature to another Temperature with the unit representation . /// @@ -630,10 +634,17 @@ public Temperature ToUnit(TemperatureUnit unit) return new Temperature(convertedValue, unit); } - IQuantity IQuantity.ToUnit(TemperatureUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is TemperatureUnit)) + throw new ArgumentException("The given unit is not of type TemperatureUnit.", nameof(unit)); + + return ToUnit((TemperatureUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((TemperatureUnit) unit); + IQuantity IQuantity.ToUnit(TemperatureUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.NetFramework.g.cs index 61a8bfdc8f..c1d55332e5 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.NetFramework.g.cs @@ -678,7 +678,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((TemperatureChangeRateUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is TemperatureChangeRateUnit)) + throw new ArgumentException("The given unit is not of type TemperatureChangeRateUnit.", nameof(unit)); + + return As((TemperatureChangeRateUnit)unit); + } /// /// Convert to the unit representation . @@ -693,9 +700,6 @@ public double As(TemperatureChangeRateUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((TemperatureChangeRateUnit) unit); - /// /// Converts this TemperatureChangeRate to another TemperatureChangeRate with the unit representation . /// @@ -706,10 +710,17 @@ public TemperatureChangeRate ToUnit(TemperatureChangeRateUnit unit) return new TemperatureChangeRate(convertedValue, unit); } - IQuantity IQuantity.ToUnit(TemperatureChangeRateUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is TemperatureChangeRateUnit)) + throw new ArgumentException("The given unit is not of type TemperatureChangeRateUnit.", nameof(unit)); + + return ToUnit((TemperatureChangeRateUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((TemperatureChangeRateUnit) unit); + IQuantity IQuantity.ToUnit(TemperatureChangeRateUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.NetFramework.g.cs index 59174479ae..3288783afe 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.NetFramework.g.cs @@ -648,7 +648,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((TemperatureDeltaUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is TemperatureDeltaUnit)) + throw new ArgumentException("The given unit is not of type TemperatureDeltaUnit.", nameof(unit)); + + return As((TemperatureDeltaUnit)unit); + } /// /// Convert to the unit representation . @@ -663,9 +670,6 @@ public double As(TemperatureDeltaUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((TemperatureDeltaUnit) unit); - /// /// Converts this TemperatureDelta to another TemperatureDelta with the unit representation . /// @@ -676,10 +680,17 @@ public TemperatureDelta ToUnit(TemperatureDeltaUnit unit) return new TemperatureDelta(convertedValue, unit); } - IQuantity IQuantity.ToUnit(TemperatureDeltaUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is TemperatureDeltaUnit)) + throw new ArgumentException("The given unit is not of type TemperatureDeltaUnit.", nameof(unit)); + + return ToUnit((TemperatureDeltaUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((TemperatureDeltaUnit) unit); + IQuantity IQuantity.ToUnit(TemperatureDeltaUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.NetFramework.g.cs index 02dbd56cce..941ba285a6 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.NetFramework.g.cs @@ -561,7 +561,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ThermalConductivityUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ThermalConductivityUnit)) + throw new ArgumentException("The given unit is not of type ThermalConductivityUnit.", nameof(unit)); + + return As((ThermalConductivityUnit)unit); + } /// /// Convert to the unit representation . @@ -576,9 +583,6 @@ public double As(ThermalConductivityUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ThermalConductivityUnit) unit); - /// /// Converts this ThermalConductivity to another ThermalConductivity with the unit representation . /// @@ -589,10 +593,17 @@ public ThermalConductivity ToUnit(ThermalConductivityUnit unit) return new ThermalConductivity(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ThermalConductivityUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ThermalConductivityUnit)) + throw new ArgumentException("The given unit is not of type ThermalConductivityUnit.", nameof(unit)); + + return ToUnit((ThermalConductivityUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ThermalConductivityUnit) unit); + IQuantity IQuantity.ToUnit(ThermalConductivityUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalResistance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalResistance.NetFramework.g.cs index 872075dfeb..94152410ad 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalResistance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalResistance.NetFramework.g.cs @@ -603,7 +603,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((ThermalResistanceUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ThermalResistanceUnit)) + throw new ArgumentException("The given unit is not of type ThermalResistanceUnit.", nameof(unit)); + + return As((ThermalResistanceUnit)unit); + } /// /// Convert to the unit representation . @@ -618,9 +625,6 @@ public double As(ThermalResistanceUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((ThermalResistanceUnit) unit); - /// /// Converts this ThermalResistance to another ThermalResistance with the unit representation . /// @@ -631,10 +635,17 @@ public ThermalResistance ToUnit(ThermalResistanceUnit unit) return new ThermalResistance(convertedValue, unit); } - IQuantity IQuantity.ToUnit(ThermalResistanceUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is ThermalResistanceUnit)) + throw new ArgumentException("The given unit is not of type ThermalResistanceUnit.", nameof(unit)); + + return ToUnit((ThermalResistanceUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((ThermalResistanceUnit) unit); + IQuantity IQuantity.ToUnit(ThermalResistanceUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Torque.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Torque.NetFramework.g.cs index 8f5e5df9d7..a51cc1458f 100644 --- a/UnitsNet/GeneratedCode/Quantities/Torque.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Torque.NetFramework.g.cs @@ -843,7 +843,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((TorqueUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is TorqueUnit)) + throw new ArgumentException("The given unit is not of type TorqueUnit.", nameof(unit)); + + return As((TorqueUnit)unit); + } /// /// Convert to the unit representation . @@ -858,9 +865,6 @@ public double As(TorqueUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((TorqueUnit) unit); - /// /// Converts this Torque to another Torque with the unit representation . /// @@ -871,10 +875,17 @@ public Torque ToUnit(TorqueUnit unit) return new Torque(convertedValue, unit); } - IQuantity IQuantity.ToUnit(TorqueUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is TorqueUnit)) + throw new ArgumentException("The given unit is not of type TorqueUnit.", nameof(unit)); + + return ToUnit((TorqueUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((TorqueUnit) unit); + IQuantity IQuantity.ToUnit(TorqueUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/VitaminA.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/VitaminA.NetFramework.g.cs index 1f7322bc56..ab3a99de4c 100644 --- a/UnitsNet/GeneratedCode/Quantities/VitaminA.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VitaminA.NetFramework.g.cs @@ -543,7 +543,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((VitaminAUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is VitaminAUnit)) + throw new ArgumentException("The given unit is not of type VitaminAUnit.", nameof(unit)); + + return As((VitaminAUnit)unit); + } /// /// Convert to the unit representation . @@ -558,9 +565,6 @@ public double As(VitaminAUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((VitaminAUnit) unit); - /// /// Converts this VitaminA to another VitaminA with the unit representation . /// @@ -571,10 +575,17 @@ public VitaminA ToUnit(VitaminAUnit unit) return new VitaminA(convertedValue, unit); } - IQuantity IQuantity.ToUnit(VitaminAUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is VitaminAUnit)) + throw new ArgumentException("The given unit is not of type VitaminAUnit.", nameof(unit)); + + return ToUnit((VitaminAUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((VitaminAUnit) unit); + IQuantity IQuantity.ToUnit(VitaminAUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.NetFramework.g.cs index fedfc1ece1..0ce95b10ff 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.NetFramework.g.cs @@ -1203,7 +1203,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((VolumeUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is VolumeUnit)) + throw new ArgumentException("The given unit is not of type VolumeUnit.", nameof(unit)); + + return As((VolumeUnit)unit); + } /// /// Convert to the unit representation . @@ -1218,9 +1225,6 @@ public double As(VolumeUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((VolumeUnit) unit); - /// /// Converts this Volume to another Volume with the unit representation . /// @@ -1231,10 +1235,17 @@ public Volume ToUnit(VolumeUnit unit) return new Volume(convertedValue, unit); } - IQuantity IQuantity.ToUnit(VolumeUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is VolumeUnit)) + throw new ArgumentException("The given unit is not of type VolumeUnit.", nameof(unit)); + + return ToUnit((VolumeUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((VolumeUnit) unit); + IQuantity IQuantity.ToUnit(VolumeUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.NetFramework.g.cs index e9afab17ac..f54dc0ba31 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.NetFramework.g.cs @@ -1248,7 +1248,14 @@ public override int GetHashCode() #region Conversion Methods - double IQuantity.As(Enum unit) => As((VolumeFlowUnit)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is VolumeFlowUnit)) + throw new ArgumentException("The given unit is not of type VolumeFlowUnit.", nameof(unit)); + + return As((VolumeFlowUnit)unit); + } /// /// Convert to the unit representation . @@ -1263,9 +1270,6 @@ public double As(VolumeFlowUnit unit) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As((VolumeFlowUnit) unit); - /// /// Converts this VolumeFlow to another VolumeFlow with the unit representation . /// @@ -1276,10 +1280,17 @@ public VolumeFlow ToUnit(VolumeFlowUnit unit) return new VolumeFlow(convertedValue, unit); } - IQuantity IQuantity.ToUnit(VolumeFlowUnit unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is VolumeFlowUnit)) + throw new ArgumentException("The given unit is not of type VolumeFlowUnit.", nameof(unit)); + + return ToUnit((VolumeFlowUnit)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit((VolumeFlowUnit) unit); + IQuantity IQuantity.ToUnit(VolumeFlowUnit unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. diff --git a/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 b/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 index 28c5205399..b2ee705277 100644 --- a/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 +++ b/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 @@ -969,7 +969,14 @@ function GenerateConversionMethods([GeneratorArgs]$genArgs) #region Conversion Methods - double IQuantity.As(Enum unit) => As(($unitEnumName)unit); + /// + double IQuantity.As(Enum unit) + { + if(!(unit is $unitEnumName)) + throw new ArgumentException("The given unit is not of type $unitEnumName.", nameof(unit)); + + return As(($unitEnumName)unit); + } /// /// Convert to the unit representation . @@ -984,9 +991,6 @@ function GenerateConversionMethods([GeneratorArgs]$genArgs) return Convert.ToDouble(converted); } - /// - public double As(Enum unit) => As(($unitEnumName) unit); - /// /// Converts this $quantityName to another $quantityName with the unit representation . /// @@ -997,10 +1001,17 @@ function GenerateConversionMethods([GeneratorArgs]$genArgs) return new $quantityName(convertedValue, unit); } - IQuantity<$unitEnumName> IQuantity<$unitEnumName>.ToUnit($unitEnumName unit) => ToUnit(unit); + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is $unitEnumName)) + throw new ArgumentException("The given unit is not of type $unitEnumName.", nameof(unit)); + + return ToUnit(($unitEnumName)unit); + } /// - public IQuantity ToUnit(Enum unit) => ToUnit(($unitEnumName) unit); + IQuantity<$unitEnumName> IQuantity<$unitEnumName>.ToUnit($unitEnumName unit) => ToUnit(unit); /// /// Converts the current value + unit to the base unit. From 01c6dfc933dba9893e91f1fb249be9a33f83a191 Mon Sep 17 00:00:00 2001 From: Tristan Milnthorp Date: Fri, 1 Mar 2019 11:43:11 -0500 Subject: [PATCH 2/2] Pretty :) --- UnitsNet.Tests/IQuantityTests.cs | 8 +++---- .../Quantities/Acceleration.NetFramework.g.cs | 24 +++++++++---------- .../AmountOfSubstance.NetFramework.g.cs | 24 +++++++++---------- .../AmplitudeRatio.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Angle.NetFramework.g.cs | 24 +++++++++---------- .../ApparentEnergy.NetFramework.g.cs | 24 +++++++++---------- .../ApparentPower.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Area.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/AreaDensity.NetFramework.g.cs | 24 +++++++++---------- .../AreaMomentOfInertia.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/BitRate.NetFramework.g.cs | 24 +++++++++---------- ...eSpecificFuelConsumption.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Capacitance.NetFramework.g.cs | 24 +++++++++---------- ...icientOfThermalExpansion.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Density.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Duration.NetFramework.g.cs | 24 +++++++++---------- .../DynamicViscosity.NetFramework.g.cs | 24 +++++++++---------- .../ElectricAdmittance.NetFramework.g.cs | 24 +++++++++---------- .../ElectricCharge.NetFramework.g.cs | 24 +++++++++---------- .../ElectricChargeDensity.NetFramework.g.cs | 24 +++++++++---------- .../ElectricConductance.NetFramework.g.cs | 24 +++++++++---------- .../ElectricConductivity.NetFramework.g.cs | 24 +++++++++---------- .../ElectricCurrent.NetFramework.g.cs | 24 +++++++++---------- .../ElectricCurrentDensity.NetFramework.g.cs | 24 +++++++++---------- .../ElectricCurrentGradient.NetFramework.g.cs | 24 +++++++++---------- .../ElectricField.NetFramework.g.cs | 24 +++++++++---------- .../ElectricInductance.NetFramework.g.cs | 24 +++++++++---------- .../ElectricPotential.NetFramework.g.cs | 24 +++++++++---------- .../ElectricPotentialAc.NetFramework.g.cs | 24 +++++++++---------- .../ElectricPotentialDc.NetFramework.g.cs | 24 +++++++++---------- .../ElectricResistance.NetFramework.g.cs | 24 +++++++++---------- .../ElectricResistivity.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Energy.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Entropy.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Force.NetFramework.g.cs | 24 +++++++++---------- .../ForceChangeRate.NetFramework.g.cs | 24 +++++++++---------- .../ForcePerLength.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Frequency.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/HeatFlux.NetFramework.g.cs | 24 +++++++++---------- .../HeatTransferCoefficient.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Illuminance.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Information.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Irradiance.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Irradiation.NetFramework.g.cs | 24 +++++++++---------- .../KinematicViscosity.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/LapseRate.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Length.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Level.NetFramework.g.cs | 24 +++++++++---------- .../LinearDensity.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/LuminousFlux.NetFramework.g.cs | 24 +++++++++---------- .../LuminousIntensity.NetFramework.g.cs | 24 +++++++++---------- .../MagneticField.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/MagneticFlux.NetFramework.g.cs | 24 +++++++++---------- .../Magnetization.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Mass.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/MassFlow.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/MassFlux.NetFramework.g.cs | 24 +++++++++---------- .../MassMomentOfInertia.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/MolarEnergy.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/MolarEntropy.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/MolarMass.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Molarity.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Permeability.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Permittivity.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Power.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/PowerDensity.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/PowerRatio.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Pressure.NetFramework.g.cs | 24 +++++++++---------- .../PressureChangeRate.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Ratio.NetFramework.g.cs | 24 +++++++++---------- .../ReactiveEnergy.NetFramework.g.cs | 24 +++++++++---------- .../ReactivePower.NetFramework.g.cs | 24 +++++++++---------- .../RotationalAcceleration.NetFramework.g.cs | 24 +++++++++---------- .../RotationalSpeed.NetFramework.g.cs | 24 +++++++++---------- .../RotationalStiffness.NetFramework.g.cs | 24 +++++++++---------- ...tionalStiffnessPerLength.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/SolidAngle.NetFramework.g.cs | 24 +++++++++---------- .../SpecificEnergy.NetFramework.g.cs | 24 +++++++++---------- .../SpecificEntropy.NetFramework.g.cs | 24 +++++++++---------- .../SpecificVolume.NetFramework.g.cs | 24 +++++++++---------- .../SpecificWeight.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Speed.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Temperature.NetFramework.g.cs | 24 +++++++++---------- .../TemperatureChangeRate.NetFramework.g.cs | 24 +++++++++---------- .../TemperatureDelta.NetFramework.g.cs | 24 +++++++++---------- .../ThermalConductivity.NetFramework.g.cs | 24 +++++++++---------- .../ThermalResistance.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Torque.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/VitaminA.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/Volume.NetFramework.g.cs | 24 +++++++++---------- .../Quantities/VolumeFlow.NetFramework.g.cs | 24 +++++++++---------- .../Include-GenerateQuantitySourceCode.ps1 | 24 +++++++++---------- 92 files changed, 1096 insertions(+), 1096 deletions(-) diff --git a/UnitsNet.Tests/IQuantityTests.cs b/UnitsNet.Tests/IQuantityTests.cs index dd27d34bdb..1e2a91d1d6 100644 --- a/UnitsNet.Tests/IQuantityTests.cs +++ b/UnitsNet.Tests/IQuantityTests.cs @@ -12,15 +12,15 @@ public class IQuantityTests [Fact] public void As_GivenWrongUnitType_ThrowsArgumentException() { - IQuantity quantity = Length.FromMeters(1.2345); - Assert.Throws(() => quantity.As(MassUnit.Kilogram)); + IQuantity length = Length.FromMeters(1.2345); + Assert.Throws(() => length.As(MassUnit.Kilogram)); } [Fact] public void ToUnit_GivenWrongUnitType_ThrowsArgumentException() { - IQuantity quantity = Length.FromMeters(1.2345); - Assert.Throws(() => quantity.ToUnit(MassUnit.Kilogram)); + IQuantity length = Length.FromMeters(1.2345); + Assert.Throws(() => length.ToUnit(MassUnit.Kilogram)); } } } diff --git a/UnitsNet/GeneratedCode/Quantities/Acceleration.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Acceleration.NetFramework.g.cs index ea819acce6..8b2f9bfaae 100644 --- a/UnitsNet/GeneratedCode/Quantities/Acceleration.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Acceleration.NetFramework.g.cs @@ -723,15 +723,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is AccelerationUnit)) - throw new ArgumentException("The given unit is not of type AccelerationUnit.", nameof(unit)); - - return As((AccelerationUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -745,6 +736,15 @@ public double As(AccelerationUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AccelerationUnit unitAsAccelerationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AccelerationUnit)} is supported.", nameof(unit)); + + return As(unitAsAccelerationUnit); + } + /// /// Converts this Acceleration to another Acceleration with the unit representation . /// @@ -758,10 +758,10 @@ public Acceleration ToUnit(AccelerationUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is AccelerationUnit)) - throw new ArgumentException("The given unit is not of type AccelerationUnit.", nameof(unit)); + if(!(unit is AccelerationUnit unitAsAccelerationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AccelerationUnit)} is supported.", nameof(unit)); - return ToUnit((AccelerationUnit)unit); + return ToUnit(unitAsAccelerationUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.NetFramework.g.cs index 01c5174c89..66aa015af7 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.NetFramework.g.cs @@ -753,15 +753,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is AmountOfSubstanceUnit)) - throw new ArgumentException("The given unit is not of type AmountOfSubstanceUnit.", nameof(unit)); - - return As((AmountOfSubstanceUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -775,6 +766,15 @@ public double As(AmountOfSubstanceUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AmountOfSubstanceUnit unitAsAmountOfSubstanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmountOfSubstanceUnit)} is supported.", nameof(unit)); + + return As(unitAsAmountOfSubstanceUnit); + } + /// /// Converts this AmountOfSubstance to another AmountOfSubstance with the unit representation . /// @@ -788,10 +788,10 @@ public AmountOfSubstance ToUnit(AmountOfSubstanceUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is AmountOfSubstanceUnit)) - throw new ArgumentException("The given unit is not of type AmountOfSubstanceUnit.", nameof(unit)); + if(!(unit is AmountOfSubstanceUnit unitAsAmountOfSubstanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmountOfSubstanceUnit)} is supported.", nameof(unit)); - return ToUnit((AmountOfSubstanceUnit)unit); + return ToUnit(unitAsAmountOfSubstanceUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.NetFramework.g.cs index 14a8f76d58..7059ba51b2 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.NetFramework.g.cs @@ -596,15 +596,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is AmplitudeRatioUnit)) - throw new ArgumentException("The given unit is not of type AmplitudeRatioUnit.", nameof(unit)); - - return As((AmplitudeRatioUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -618,6 +609,15 @@ public double As(AmplitudeRatioUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AmplitudeRatioUnit unitAsAmplitudeRatioUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmplitudeRatioUnit)} is supported.", nameof(unit)); + + return As(unitAsAmplitudeRatioUnit); + } + /// /// Converts this AmplitudeRatio to another AmplitudeRatio with the unit representation . /// @@ -631,10 +631,10 @@ public AmplitudeRatio ToUnit(AmplitudeRatioUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is AmplitudeRatioUnit)) - throw new ArgumentException("The given unit is not of type AmplitudeRatioUnit.", nameof(unit)); + if(!(unit is AmplitudeRatioUnit unitAsAmplitudeRatioUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AmplitudeRatioUnit)} is supported.", nameof(unit)); - return ToUnit((AmplitudeRatioUnit)unit); + return ToUnit(unitAsAmplitudeRatioUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Angle.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Angle.NetFramework.g.cs index c219f3cf72..398e3d23c2 100644 --- a/UnitsNet/GeneratedCode/Quantities/Angle.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Angle.NetFramework.g.cs @@ -738,15 +738,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is AngleUnit)) - throw new ArgumentException("The given unit is not of type AngleUnit.", nameof(unit)); - - return As((AngleUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -760,6 +751,15 @@ public double As(AngleUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AngleUnit unitAsAngleUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AngleUnit)} is supported.", nameof(unit)); + + return As(unitAsAngleUnit); + } + /// /// Converts this Angle to another Angle with the unit representation . /// @@ -773,10 +773,10 @@ public Angle ToUnit(AngleUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is AngleUnit)) - throw new ArgumentException("The given unit is not of type AngleUnit.", nameof(unit)); + if(!(unit is AngleUnit unitAsAngleUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AngleUnit)} is supported.", nameof(unit)); - return ToUnit((AngleUnit)unit); + return ToUnit(unitAsAngleUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.NetFramework.g.cs index 0cf81f4af6..adb531a510 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentEnergy.NetFramework.g.cs @@ -573,15 +573,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ApparentEnergyUnit)) - throw new ArgumentException("The given unit is not of type ApparentEnergyUnit.", nameof(unit)); - - return As((ApparentEnergyUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -595,6 +586,15 @@ public double As(ApparentEnergyUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ApparentEnergyUnit unitAsApparentEnergyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ApparentEnergyUnit)} is supported.", nameof(unit)); + + return As(unitAsApparentEnergyUnit); + } + /// /// Converts this ApparentEnergy to another ApparentEnergy with the unit representation . /// @@ -608,10 +608,10 @@ public ApparentEnergy ToUnit(ApparentEnergyUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ApparentEnergyUnit)) - throw new ArgumentException("The given unit is not of type ApparentEnergyUnit.", nameof(unit)); + if(!(unit is ApparentEnergyUnit unitAsApparentEnergyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ApparentEnergyUnit)} is supported.", nameof(unit)); - return ToUnit((ApparentEnergyUnit)unit); + return ToUnit(unitAsApparentEnergyUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ApparentPower.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ApparentPower.NetFramework.g.cs index a00a2a9640..7a2e29efa3 100644 --- a/UnitsNet/GeneratedCode/Quantities/ApparentPower.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ApparentPower.NetFramework.g.cs @@ -588,15 +588,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ApparentPowerUnit)) - throw new ArgumentException("The given unit is not of type ApparentPowerUnit.", nameof(unit)); - - return As((ApparentPowerUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -610,6 +601,15 @@ public double As(ApparentPowerUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ApparentPowerUnit unitAsApparentPowerUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ApparentPowerUnit)} is supported.", nameof(unit)); + + return As(unitAsApparentPowerUnit); + } + /// /// Converts this ApparentPower to another ApparentPower with the unit representation . /// @@ -623,10 +623,10 @@ public ApparentPower ToUnit(ApparentPowerUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ApparentPowerUnit)) - throw new ArgumentException("The given unit is not of type ApparentPowerUnit.", nameof(unit)); + if(!(unit is ApparentPowerUnit unitAsApparentPowerUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ApparentPowerUnit)} is supported.", nameof(unit)); - return ToUnit((ApparentPowerUnit)unit); + return ToUnit(unitAsApparentPowerUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Area.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Area.NetFramework.g.cs index 837f77969d..1454a3bb36 100644 --- a/UnitsNet/GeneratedCode/Quantities/Area.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Area.NetFramework.g.cs @@ -723,15 +723,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is AreaUnit)) - throw new ArgumentException("The given unit is not of type AreaUnit.", nameof(unit)); - - return As((AreaUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -745,6 +736,15 @@ public double As(AreaUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AreaUnit unitAsAreaUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaUnit)} is supported.", nameof(unit)); + + return As(unitAsAreaUnit); + } + /// /// Converts this Area to another Area with the unit representation . /// @@ -758,10 +758,10 @@ public Area ToUnit(AreaUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is AreaUnit)) - throw new ArgumentException("The given unit is not of type AreaUnit.", nameof(unit)); + if(!(unit is AreaUnit unitAsAreaUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaUnit)} is supported.", nameof(unit)); - return ToUnit((AreaUnit)unit); + return ToUnit(unitAsAreaUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AreaDensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaDensity.NetFramework.g.cs index d2a975b622..5bb00408a8 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaDensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaDensity.NetFramework.g.cs @@ -543,15 +543,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is AreaDensityUnit)) - throw new ArgumentException("The given unit is not of type AreaDensityUnit.", nameof(unit)); - - return As((AreaDensityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -565,6 +556,15 @@ public double As(AreaDensityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AreaDensityUnit unitAsAreaDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaDensityUnit)} is supported.", nameof(unit)); + + return As(unitAsAreaDensityUnit); + } + /// /// Converts this AreaDensity to another AreaDensity with the unit representation . /// @@ -578,10 +578,10 @@ public AreaDensity ToUnit(AreaDensityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is AreaDensityUnit)) - throw new ArgumentException("The given unit is not of type AreaDensityUnit.", nameof(unit)); + if(!(unit is AreaDensityUnit unitAsAreaDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaDensityUnit)} is supported.", nameof(unit)); - return ToUnit((AreaDensityUnit)unit); + return ToUnit(unitAsAreaDensityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.NetFramework.g.cs index 9bd7c99b8d..45299eddf3 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.NetFramework.g.cs @@ -618,15 +618,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is AreaMomentOfInertiaUnit)) - throw new ArgumentException("The given unit is not of type AreaMomentOfInertiaUnit.", nameof(unit)); - - return As((AreaMomentOfInertiaUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -640,6 +631,15 @@ public double As(AreaMomentOfInertiaUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is AreaMomentOfInertiaUnit unitAsAreaMomentOfInertiaUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaMomentOfInertiaUnit)} is supported.", nameof(unit)); + + return As(unitAsAreaMomentOfInertiaUnit); + } + /// /// Converts this AreaMomentOfInertia to another AreaMomentOfInertia with the unit representation . /// @@ -653,10 +653,10 @@ public AreaMomentOfInertia ToUnit(AreaMomentOfInertiaUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is AreaMomentOfInertiaUnit)) - throw new ArgumentException("The given unit is not of type AreaMomentOfInertiaUnit.", nameof(unit)); + if(!(unit is AreaMomentOfInertiaUnit unitAsAreaMomentOfInertiaUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(AreaMomentOfInertiaUnit)} is supported.", nameof(unit)); - return ToUnit((AreaMomentOfInertiaUnit)unit); + return ToUnit(unitAsAreaMomentOfInertiaUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs index c07e4d1d88..4d99ce759e 100644 --- a/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BitRate.NetFramework.g.cs @@ -923,15 +923,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is BitRateUnit)) - throw new ArgumentException("The given unit is not of type BitRateUnit.", nameof(unit)); - - return As((BitRateUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -945,6 +936,15 @@ public double As(BitRateUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is BitRateUnit unitAsBitRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BitRateUnit)} is supported.", nameof(unit)); + + return As(unitAsBitRateUnit); + } + /// /// Converts this BitRate to another BitRate with the unit representation . /// @@ -958,10 +958,10 @@ public BitRate ToUnit(BitRateUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is BitRateUnit)) - throw new ArgumentException("The given unit is not of type BitRateUnit.", nameof(unit)); + if(!(unit is BitRateUnit unitAsBitRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BitRateUnit)} is supported.", nameof(unit)); - return ToUnit((BitRateUnit)unit); + return ToUnit(unitAsBitRateUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.NetFramework.g.cs index f0255fc931..2015220a4f 100644 --- a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.NetFramework.g.cs @@ -573,15 +573,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is BrakeSpecificFuelConsumptionUnit)) - throw new ArgumentException("The given unit is not of type BrakeSpecificFuelConsumptionUnit.", nameof(unit)); - - return As((BrakeSpecificFuelConsumptionUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -595,6 +586,15 @@ public double As(BrakeSpecificFuelConsumptionUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is BrakeSpecificFuelConsumptionUnit unitAsBrakeSpecificFuelConsumptionUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BrakeSpecificFuelConsumptionUnit)} is supported.", nameof(unit)); + + return As(unitAsBrakeSpecificFuelConsumptionUnit); + } + /// /// Converts this BrakeSpecificFuelConsumption to another BrakeSpecificFuelConsumption with the unit representation . /// @@ -608,10 +608,10 @@ public BrakeSpecificFuelConsumption ToUnit(BrakeSpecificFuelConsumptionUnit unit /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is BrakeSpecificFuelConsumptionUnit)) - throw new ArgumentException("The given unit is not of type BrakeSpecificFuelConsumptionUnit.", nameof(unit)); + if(!(unit is BrakeSpecificFuelConsumptionUnit unitAsBrakeSpecificFuelConsumptionUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(BrakeSpecificFuelConsumptionUnit)} is supported.", nameof(unit)); - return ToUnit((BrakeSpecificFuelConsumptionUnit)unit); + return ToUnit(unitAsBrakeSpecificFuelConsumptionUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Capacitance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Capacitance.NetFramework.g.cs index 433c30290c..f6011d3287 100644 --- a/UnitsNet/GeneratedCode/Quantities/Capacitance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Capacitance.NetFramework.g.cs @@ -636,15 +636,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is CapacitanceUnit)) - throw new ArgumentException("The given unit is not of type CapacitanceUnit.", nameof(unit)); - - return As((CapacitanceUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -658,6 +649,15 @@ public double As(CapacitanceUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is CapacitanceUnit unitAsCapacitanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CapacitanceUnit)} is supported.", nameof(unit)); + + return As(unitAsCapacitanceUnit); + } + /// /// Converts this Capacitance to another Capacitance with the unit representation . /// @@ -671,10 +671,10 @@ public Capacitance ToUnit(CapacitanceUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is CapacitanceUnit)) - throw new ArgumentException("The given unit is not of type CapacitanceUnit.", nameof(unit)); + if(!(unit is CapacitanceUnit unitAsCapacitanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CapacitanceUnit)} is supported.", nameof(unit)); - return ToUnit((CapacitanceUnit)unit); + return ToUnit(unitAsCapacitanceUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.NetFramework.g.cs index 3e2cf05b4e..6fe65d47f4 100644 --- a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.NetFramework.g.cs @@ -573,15 +573,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is CoefficientOfThermalExpansionUnit)) - throw new ArgumentException("The given unit is not of type CoefficientOfThermalExpansionUnit.", nameof(unit)); - - return As((CoefficientOfThermalExpansionUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -595,6 +586,15 @@ public double As(CoefficientOfThermalExpansionUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is CoefficientOfThermalExpansionUnit unitAsCoefficientOfThermalExpansionUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CoefficientOfThermalExpansionUnit)} is supported.", nameof(unit)); + + return As(unitAsCoefficientOfThermalExpansionUnit); + } + /// /// Converts this CoefficientOfThermalExpansion to another CoefficientOfThermalExpansion with the unit representation . /// @@ -608,10 +608,10 @@ public CoefficientOfThermalExpansion ToUnit(CoefficientOfThermalExpansionUnit un /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is CoefficientOfThermalExpansionUnit)) - throw new ArgumentException("The given unit is not of type CoefficientOfThermalExpansionUnit.", nameof(unit)); + if(!(unit is CoefficientOfThermalExpansionUnit unitAsCoefficientOfThermalExpansionUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CoefficientOfThermalExpansionUnit)} is supported.", nameof(unit)); - return ToUnit((CoefficientOfThermalExpansionUnit)unit); + return ToUnit(unitAsCoefficientOfThermalExpansionUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Density.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Density.NetFramework.g.cs index 6a2c2843da..0a1280a34a 100644 --- a/UnitsNet/GeneratedCode/Quantities/Density.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Density.NetFramework.g.cs @@ -1116,15 +1116,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is DensityUnit)) - throw new ArgumentException("The given unit is not of type DensityUnit.", nameof(unit)); - - return As((DensityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -1138,6 +1129,15 @@ public double As(DensityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is DensityUnit unitAsDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DensityUnit)} is supported.", nameof(unit)); + + return As(unitAsDensityUnit); + } + /// /// Converts this Density to another Density with the unit representation . /// @@ -1151,10 +1151,10 @@ public Density ToUnit(DensityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is DensityUnit)) - throw new ArgumentException("The given unit is not of type DensityUnit.", nameof(unit)); + if(!(unit is DensityUnit unitAsDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DensityUnit)} is supported.", nameof(unit)); - return ToUnit((DensityUnit)unit); + return ToUnit(unitAsDensityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Duration.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Duration.NetFramework.g.cs index 365b9f4674..b506281ae5 100644 --- a/UnitsNet/GeneratedCode/Quantities/Duration.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Duration.NetFramework.g.cs @@ -678,15 +678,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is DurationUnit)) - throw new ArgumentException("The given unit is not of type DurationUnit.", nameof(unit)); - - return As((DurationUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -700,6 +691,15 @@ public double As(DurationUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is DurationUnit unitAsDurationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DurationUnit)} is supported.", nameof(unit)); + + return As(unitAsDurationUnit); + } + /// /// Converts this Duration to another Duration with the unit representation . /// @@ -713,10 +713,10 @@ public Duration ToUnit(DurationUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is DurationUnit)) - throw new ArgumentException("The given unit is not of type DurationUnit.", nameof(unit)); + if(!(unit is DurationUnit unitAsDurationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DurationUnit)} is supported.", nameof(unit)); - return ToUnit((DurationUnit)unit); + return ToUnit(unitAsDurationUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.NetFramework.g.cs index c5a5adc63d..8a56deb711 100644 --- a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.NetFramework.g.cs @@ -621,15 +621,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is DynamicViscosityUnit)) - throw new ArgumentException("The given unit is not of type DynamicViscosityUnit.", nameof(unit)); - - return As((DynamicViscosityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -643,6 +634,15 @@ public double As(DynamicViscosityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is DynamicViscosityUnit unitAsDynamicViscosityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DynamicViscosityUnit)} is supported.", nameof(unit)); + + return As(unitAsDynamicViscosityUnit); + } + /// /// Converts this DynamicViscosity to another DynamicViscosity with the unit representation . /// @@ -656,10 +656,10 @@ public DynamicViscosity ToUnit(DynamicViscosityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is DynamicViscosityUnit)) - throw new ArgumentException("The given unit is not of type DynamicViscosityUnit.", nameof(unit)); + if(!(unit is DynamicViscosityUnit unitAsDynamicViscosityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(DynamicViscosityUnit)} is supported.", nameof(unit)); - return ToUnit((DynamicViscosityUnit)unit); + return ToUnit(unitAsDynamicViscosityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.NetFramework.g.cs index e11d0ed85c..74808cb923 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.NetFramework.g.cs @@ -588,15 +588,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricAdmittanceUnit)) - throw new ArgumentException("The given unit is not of type ElectricAdmittanceUnit.", nameof(unit)); - - return As((ElectricAdmittanceUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -610,6 +601,15 @@ public double As(ElectricAdmittanceUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricAdmittanceUnit unitAsElectricAdmittanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricAdmittanceUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricAdmittanceUnit); + } + /// /// Converts this ElectricAdmittance to another ElectricAdmittance with the unit representation . /// @@ -623,10 +623,10 @@ public ElectricAdmittance ToUnit(ElectricAdmittanceUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricAdmittanceUnit)) - throw new ArgumentException("The given unit is not of type ElectricAdmittanceUnit.", nameof(unit)); + if(!(unit is ElectricAdmittanceUnit unitAsElectricAdmittanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricAdmittanceUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricAdmittanceUnit)unit); + return ToUnit(unitAsElectricAdmittanceUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.NetFramework.g.cs index d39e920eca..f5ab761e53 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricChargeUnit)) - throw new ArgumentException("The given unit is not of type ElectricChargeUnit.", nameof(unit)); - - return As((ElectricChargeUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(ElectricChargeUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricChargeUnit unitAsElectricChargeUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricChargeUnit); + } + /// /// Converts this ElectricCharge to another ElectricCharge with the unit representation . /// @@ -581,10 +581,10 @@ public ElectricCharge ToUnit(ElectricChargeUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricChargeUnit)) - throw new ArgumentException("The given unit is not of type ElectricChargeUnit.", nameof(unit)); + if(!(unit is ElectricChargeUnit unitAsElectricChargeUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricChargeUnit)unit); + return ToUnit(unitAsElectricChargeUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.NetFramework.g.cs index d15f777abb..914c6e26f9 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricChargeDensityUnit)) - throw new ArgumentException("The given unit is not of type ElectricChargeDensityUnit.", nameof(unit)); - - return As((ElectricChargeDensityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(ElectricChargeDensityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricChargeDensityUnit unitAsElectricChargeDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeDensityUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricChargeDensityUnit); + } + /// /// Converts this ElectricChargeDensity to another ElectricChargeDensity with the unit representation . /// @@ -581,10 +581,10 @@ public ElectricChargeDensity ToUnit(ElectricChargeDensityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricChargeDensityUnit)) - throw new ArgumentException("The given unit is not of type ElectricChargeDensityUnit.", nameof(unit)); + if(!(unit is ElectricChargeDensityUnit unitAsElectricChargeDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricChargeDensityUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricChargeDensityUnit)unit); + return ToUnit(unitAsElectricChargeDensityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.NetFramework.g.cs index 64625be935..a6012068ec 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.NetFramework.g.cs @@ -576,15 +576,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricConductanceUnit)) - throw new ArgumentException("The given unit is not of type ElectricConductanceUnit.", nameof(unit)); - - return As((ElectricConductanceUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -598,6 +589,15 @@ public double As(ElectricConductanceUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricConductanceUnit unitAsElectricConductanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductanceUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricConductanceUnit); + } + /// /// Converts this ElectricConductance to another ElectricConductance with the unit representation . /// @@ -611,10 +611,10 @@ public ElectricConductance ToUnit(ElectricConductanceUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricConductanceUnit)) - throw new ArgumentException("The given unit is not of type ElectricConductanceUnit.", nameof(unit)); + if(!(unit is ElectricConductanceUnit unitAsElectricConductanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductanceUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricConductanceUnit)unit); + return ToUnit(unitAsElectricConductanceUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.NetFramework.g.cs index beaa363d18..97cd39356e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricConductivityUnit)) - throw new ArgumentException("The given unit is not of type ElectricConductivityUnit.", nameof(unit)); - - return As((ElectricConductivityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(ElectricConductivityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricConductivityUnit unitAsElectricConductivityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductivityUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricConductivityUnit); + } + /// /// Converts this ElectricConductivity to another ElectricConductivity with the unit representation . /// @@ -581,10 +581,10 @@ public ElectricConductivity ToUnit(ElectricConductivityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricConductivityUnit)) - throw new ArgumentException("The given unit is not of type ElectricConductivityUnit.", nameof(unit)); + if(!(unit is ElectricConductivityUnit unitAsElectricConductivityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricConductivityUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricConductivityUnit)unit); + return ToUnit(unitAsElectricConductivityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.NetFramework.g.cs index 4868747a2d..ed9e0197f4 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.NetFramework.g.cs @@ -648,15 +648,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricCurrentUnit)) - throw new ArgumentException("The given unit is not of type ElectricCurrentUnit.", nameof(unit)); - - return As((ElectricCurrentUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -670,6 +661,15 @@ public double As(ElectricCurrentUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricCurrentUnit unitAsElectricCurrentUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricCurrentUnit); + } + /// /// Converts this ElectricCurrent to another ElectricCurrent with the unit representation . /// @@ -683,10 +683,10 @@ public ElectricCurrent ToUnit(ElectricCurrentUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricCurrentUnit)) - throw new ArgumentException("The given unit is not of type ElectricCurrentUnit.", nameof(unit)); + if(!(unit is ElectricCurrentUnit unitAsElectricCurrentUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricCurrentUnit)unit); + return ToUnit(unitAsElectricCurrentUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.NetFramework.g.cs index aef6fb4815..5472043c7e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricCurrentDensityUnit)) - throw new ArgumentException("The given unit is not of type ElectricCurrentDensityUnit.", nameof(unit)); - - return As((ElectricCurrentDensityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(ElectricCurrentDensityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricCurrentDensityUnit unitAsElectricCurrentDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentDensityUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricCurrentDensityUnit); + } + /// /// Converts this ElectricCurrentDensity to another ElectricCurrentDensity with the unit representation . /// @@ -581,10 +581,10 @@ public ElectricCurrentDensity ToUnit(ElectricCurrentDensityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricCurrentDensityUnit)) - throw new ArgumentException("The given unit is not of type ElectricCurrentDensityUnit.", nameof(unit)); + if(!(unit is ElectricCurrentDensityUnit unitAsElectricCurrentDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentDensityUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricCurrentDensityUnit)unit); + return ToUnit(unitAsElectricCurrentDensityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.NetFramework.g.cs index 704f6fbf22..661610d895 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.NetFramework.g.cs @@ -543,15 +543,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricCurrentGradientUnit)) - throw new ArgumentException("The given unit is not of type ElectricCurrentGradientUnit.", nameof(unit)); - - return As((ElectricCurrentGradientUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -565,6 +556,15 @@ public double As(ElectricCurrentGradientUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricCurrentGradientUnit unitAsElectricCurrentGradientUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentGradientUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricCurrentGradientUnit); + } + /// /// Converts this ElectricCurrentGradient to another ElectricCurrentGradient with the unit representation . /// @@ -578,10 +578,10 @@ public ElectricCurrentGradient ToUnit(ElectricCurrentGradientUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricCurrentGradientUnit)) - throw new ArgumentException("The given unit is not of type ElectricCurrentGradientUnit.", nameof(unit)); + if(!(unit is ElectricCurrentGradientUnit unitAsElectricCurrentGradientUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricCurrentGradientUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricCurrentGradientUnit)unit); + return ToUnit(unitAsElectricCurrentGradientUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricField.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricField.NetFramework.g.cs index 9b3445ce9b..2e2105a832 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricField.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricField.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricFieldUnit)) - throw new ArgumentException("The given unit is not of type ElectricFieldUnit.", nameof(unit)); - - return As((ElectricFieldUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(ElectricFieldUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricFieldUnit unitAsElectricFieldUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricFieldUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricFieldUnit); + } + /// /// Converts this ElectricField to another ElectricField with the unit representation . /// @@ -581,10 +581,10 @@ public ElectricField ToUnit(ElectricFieldUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricFieldUnit)) - throw new ArgumentException("The given unit is not of type ElectricFieldUnit.", nameof(unit)); + if(!(unit is ElectricFieldUnit unitAsElectricFieldUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricFieldUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricFieldUnit)unit); + return ToUnit(unitAsElectricFieldUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.NetFramework.g.cs index 522e6346f6..5648d72c8e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.NetFramework.g.cs @@ -591,15 +591,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricInductanceUnit)) - throw new ArgumentException("The given unit is not of type ElectricInductanceUnit.", nameof(unit)); - - return As((ElectricInductanceUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -613,6 +604,15 @@ public double As(ElectricInductanceUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricInductanceUnit unitAsElectricInductanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricInductanceUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricInductanceUnit); + } + /// /// Converts this ElectricInductance to another ElectricInductance with the unit representation . /// @@ -626,10 +626,10 @@ public ElectricInductance ToUnit(ElectricInductanceUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricInductanceUnit)) - throw new ArgumentException("The given unit is not of type ElectricInductanceUnit.", nameof(unit)); + if(!(unit is ElectricInductanceUnit unitAsElectricInductanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricInductanceUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricInductanceUnit)unit); + return ToUnit(unitAsElectricInductanceUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.NetFramework.g.cs index d33e015610..3b9ca20b53 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.NetFramework.g.cs @@ -603,15 +603,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricPotentialUnit)) - throw new ArgumentException("The given unit is not of type ElectricPotentialUnit.", nameof(unit)); - - return As((ElectricPotentialUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -625,6 +616,15 @@ public double As(ElectricPotentialUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricPotentialUnit unitAsElectricPotentialUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricPotentialUnit); + } + /// /// Converts this ElectricPotential to another ElectricPotential with the unit representation . /// @@ -638,10 +638,10 @@ public ElectricPotential ToUnit(ElectricPotentialUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricPotentialUnit)) - throw new ArgumentException("The given unit is not of type ElectricPotentialUnit.", nameof(unit)); + if(!(unit is ElectricPotentialUnit unitAsElectricPotentialUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricPotentialUnit)unit); + return ToUnit(unitAsElectricPotentialUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.NetFramework.g.cs index fb72a9e984..c8642e5aa7 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialAc.NetFramework.g.cs @@ -603,15 +603,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricPotentialAcUnit)) - throw new ArgumentException("The given unit is not of type ElectricPotentialAcUnit.", nameof(unit)); - - return As((ElectricPotentialAcUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -625,6 +616,15 @@ public double As(ElectricPotentialAcUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricPotentialAcUnit unitAsElectricPotentialAcUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialAcUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricPotentialAcUnit); + } + /// /// Converts this ElectricPotentialAc to another ElectricPotentialAc with the unit representation . /// @@ -638,10 +638,10 @@ public ElectricPotentialAc ToUnit(ElectricPotentialAcUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricPotentialAcUnit)) - throw new ArgumentException("The given unit is not of type ElectricPotentialAcUnit.", nameof(unit)); + if(!(unit is ElectricPotentialAcUnit unitAsElectricPotentialAcUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialAcUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricPotentialAcUnit)unit); + return ToUnit(unitAsElectricPotentialAcUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.NetFramework.g.cs index b5c493f16f..539e0294f4 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialDc.NetFramework.g.cs @@ -603,15 +603,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricPotentialDcUnit)) - throw new ArgumentException("The given unit is not of type ElectricPotentialDcUnit.", nameof(unit)); - - return As((ElectricPotentialDcUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -625,6 +616,15 @@ public double As(ElectricPotentialDcUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricPotentialDcUnit unitAsElectricPotentialDcUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialDcUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricPotentialDcUnit); + } + /// /// Converts this ElectricPotentialDc to another ElectricPotentialDc with the unit representation . /// @@ -638,10 +638,10 @@ public ElectricPotentialDc ToUnit(ElectricPotentialDcUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricPotentialDcUnit)) - throw new ArgumentException("The given unit is not of type ElectricPotentialDcUnit.", nameof(unit)); + if(!(unit is ElectricPotentialDcUnit unitAsElectricPotentialDcUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricPotentialDcUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricPotentialDcUnit)unit); + return ToUnit(unitAsElectricPotentialDcUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.NetFramework.g.cs index c1aed1c586..fa2f71b8d9 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.NetFramework.g.cs @@ -603,15 +603,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricResistanceUnit)) - throw new ArgumentException("The given unit is not of type ElectricResistanceUnit.", nameof(unit)); - - return As((ElectricResistanceUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -625,6 +616,15 @@ public double As(ElectricResistanceUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricResistanceUnit unitAsElectricResistanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistanceUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricResistanceUnit); + } + /// /// Converts this ElectricResistance to another ElectricResistance with the unit representation . /// @@ -638,10 +638,10 @@ public ElectricResistance ToUnit(ElectricResistanceUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricResistanceUnit)) - throw new ArgumentException("The given unit is not of type ElectricResistanceUnit.", nameof(unit)); + if(!(unit is ElectricResistanceUnit unitAsElectricResistanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistanceUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricResistanceUnit)unit); + return ToUnit(unitAsElectricResistanceUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.NetFramework.g.cs index 0d107415c7..819a37ed64 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.NetFramework.g.cs @@ -741,15 +741,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ElectricResistivityUnit)) - throw new ArgumentException("The given unit is not of type ElectricResistivityUnit.", nameof(unit)); - - return As((ElectricResistivityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -763,6 +754,15 @@ public double As(ElectricResistivityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ElectricResistivityUnit unitAsElectricResistivityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistivityUnit)} is supported.", nameof(unit)); + + return As(unitAsElectricResistivityUnit); + } + /// /// Converts this ElectricResistivity to another ElectricResistivity with the unit representation . /// @@ -776,10 +776,10 @@ public ElectricResistivity ToUnit(ElectricResistivityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ElectricResistivityUnit)) - throw new ArgumentException("The given unit is not of type ElectricResistivityUnit.", nameof(unit)); + if(!(unit is ElectricResistivityUnit unitAsElectricResistivityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ElectricResistivityUnit)} is supported.", nameof(unit)); - return ToUnit((ElectricResistivityUnit)unit); + return ToUnit(unitAsElectricResistivityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs index 025f439723..cc9ff73c65 100644 --- a/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Energy.NetFramework.g.cs @@ -873,15 +873,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is EnergyUnit)) - throw new ArgumentException("The given unit is not of type EnergyUnit.", nameof(unit)); - - return As((EnergyUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -895,6 +886,15 @@ public double As(EnergyUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is EnergyUnit unitAsEnergyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyUnit)} is supported.", nameof(unit)); + + return As(unitAsEnergyUnit); + } + /// /// Converts this Energy to another Energy with the unit representation . /// @@ -908,10 +908,10 @@ public Energy ToUnit(EnergyUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is EnergyUnit)) - throw new ArgumentException("The given unit is not of type EnergyUnit.", nameof(unit)); + if(!(unit is EnergyUnit unitAsEnergyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyUnit)} is supported.", nameof(unit)); - return ToUnit((EnergyUnit)unit); + return ToUnit(unitAsEnergyUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Entropy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Entropy.NetFramework.g.cs index 6fb2c1d775..b0feaa1471 100644 --- a/UnitsNet/GeneratedCode/Quantities/Entropy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Entropy.NetFramework.g.cs @@ -633,15 +633,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is EntropyUnit)) - throw new ArgumentException("The given unit is not of type EntropyUnit.", nameof(unit)); - - return As((EntropyUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -655,6 +646,15 @@ public double As(EntropyUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is EntropyUnit unitAsEntropyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EntropyUnit)} is supported.", nameof(unit)); + + return As(unitAsEntropyUnit); + } + /// /// Converts this Entropy to another Entropy with the unit representation . /// @@ -668,10 +668,10 @@ public Entropy ToUnit(EntropyUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is EntropyUnit)) - throw new ArgumentException("The given unit is not of type EntropyUnit.", nameof(unit)); + if(!(unit is EntropyUnit unitAsEntropyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EntropyUnit)} is supported.", nameof(unit)); - return ToUnit((EntropyUnit)unit); + return ToUnit(unitAsEntropyUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Force.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Force.NetFramework.g.cs index 5fe80fae50..0e156e1e6f 100644 --- a/UnitsNet/GeneratedCode/Quantities/Force.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Force.NetFramework.g.cs @@ -723,15 +723,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ForceUnit)) - throw new ArgumentException("The given unit is not of type ForceUnit.", nameof(unit)); - - return As((ForceUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -745,6 +736,15 @@ public double As(ForceUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ForceUnit unitAsForceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceUnit)} is supported.", nameof(unit)); + + return As(unitAsForceUnit); + } + /// /// Converts this Force to another Force with the unit representation . /// @@ -758,10 +758,10 @@ public Force ToUnit(ForceUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ForceUnit)) - throw new ArgumentException("The given unit is not of type ForceUnit.", nameof(unit)); + if(!(unit is ForceUnit unitAsForceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceUnit)} is supported.", nameof(unit)); - return ToUnit((ForceUnit)unit); + return ToUnit(unitAsForceUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.NetFramework.g.cs index 7f8a53a492..5f94b3b775 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.NetFramework.g.cs @@ -693,15 +693,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ForceChangeRateUnit)) - throw new ArgumentException("The given unit is not of type ForceChangeRateUnit.", nameof(unit)); - - return As((ForceChangeRateUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -715,6 +706,15 @@ public double As(ForceChangeRateUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ForceChangeRateUnit unitAsForceChangeRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceChangeRateUnit)} is supported.", nameof(unit)); + + return As(unitAsForceChangeRateUnit); + } + /// /// Converts this ForceChangeRate to another ForceChangeRate with the unit representation . /// @@ -728,10 +728,10 @@ public ForceChangeRate ToUnit(ForceChangeRateUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ForceChangeRateUnit)) - throw new ArgumentException("The given unit is not of type ForceChangeRateUnit.", nameof(unit)); + if(!(unit is ForceChangeRateUnit unitAsForceChangeRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForceChangeRateUnit)} is supported.", nameof(unit)); - return ToUnit((ForceChangeRateUnit)unit); + return ToUnit(unitAsForceChangeRateUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.NetFramework.g.cs index b5e2f990a6..5ce7908585 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.NetFramework.g.cs @@ -663,15 +663,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ForcePerLengthUnit)) - throw new ArgumentException("The given unit is not of type ForcePerLengthUnit.", nameof(unit)); - - return As((ForcePerLengthUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -685,6 +676,15 @@ public double As(ForcePerLengthUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ForcePerLengthUnit unitAsForcePerLengthUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForcePerLengthUnit)} is supported.", nameof(unit)); + + return As(unitAsForcePerLengthUnit); + } + /// /// Converts this ForcePerLength to another ForcePerLength with the unit representation . /// @@ -698,10 +698,10 @@ public ForcePerLength ToUnit(ForcePerLengthUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ForcePerLengthUnit)) - throw new ArgumentException("The given unit is not of type ForcePerLengthUnit.", nameof(unit)); + if(!(unit is ForcePerLengthUnit unitAsForcePerLengthUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ForcePerLengthUnit)} is supported.", nameof(unit)); - return ToUnit((ForcePerLengthUnit)unit); + return ToUnit(unitAsForcePerLengthUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs index 74e8eb7fef..4c3af49c64 100644 --- a/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Frequency.NetFramework.g.cs @@ -663,15 +663,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is FrequencyUnit)) - throw new ArgumentException("The given unit is not of type FrequencyUnit.", nameof(unit)); - - return As((FrequencyUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -685,6 +676,15 @@ public double As(FrequencyUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is FrequencyUnit unitAsFrequencyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(FrequencyUnit)} is supported.", nameof(unit)); + + return As(unitAsFrequencyUnit); + } + /// /// Converts this Frequency to another Frequency with the unit representation . /// @@ -698,10 +698,10 @@ public Frequency ToUnit(FrequencyUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is FrequencyUnit)) - throw new ArgumentException("The given unit is not of type FrequencyUnit.", nameof(unit)); + if(!(unit is FrequencyUnit unitAsFrequencyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(FrequencyUnit)} is supported.", nameof(unit)); - return ToUnit((FrequencyUnit)unit); + return ToUnit(unitAsFrequencyUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/HeatFlux.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatFlux.NetFramework.g.cs index 73ba67e181..4ea7b3d4ec 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatFlux.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatFlux.NetFramework.g.cs @@ -798,15 +798,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is HeatFluxUnit)) - throw new ArgumentException("The given unit is not of type HeatFluxUnit.", nameof(unit)); - - return As((HeatFluxUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -820,6 +811,15 @@ public double As(HeatFluxUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is HeatFluxUnit unitAsHeatFluxUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatFluxUnit)} is supported.", nameof(unit)); + + return As(unitAsHeatFluxUnit); + } + /// /// Converts this HeatFlux to another HeatFlux with the unit representation . /// @@ -833,10 +833,10 @@ public HeatFlux ToUnit(HeatFluxUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is HeatFluxUnit)) - throw new ArgumentException("The given unit is not of type HeatFluxUnit.", nameof(unit)); + if(!(unit is HeatFluxUnit unitAsHeatFluxUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatFluxUnit)} is supported.", nameof(unit)); - return ToUnit((HeatFluxUnit)unit); + return ToUnit(unitAsHeatFluxUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.NetFramework.g.cs index 8b8de8b16e..455e206e6a 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.NetFramework.g.cs @@ -558,15 +558,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is HeatTransferCoefficientUnit)) - throw new ArgumentException("The given unit is not of type HeatTransferCoefficientUnit.", nameof(unit)); - - return As((HeatTransferCoefficientUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -580,6 +571,15 @@ public double As(HeatTransferCoefficientUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is HeatTransferCoefficientUnit unitAsHeatTransferCoefficientUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatTransferCoefficientUnit)} is supported.", nameof(unit)); + + return As(unitAsHeatTransferCoefficientUnit); + } + /// /// Converts this HeatTransferCoefficient to another HeatTransferCoefficient with the unit representation . /// @@ -593,10 +593,10 @@ public HeatTransferCoefficient ToUnit(HeatTransferCoefficientUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is HeatTransferCoefficientUnit)) - throw new ArgumentException("The given unit is not of type HeatTransferCoefficientUnit.", nameof(unit)); + if(!(unit is HeatTransferCoefficientUnit unitAsHeatTransferCoefficientUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(HeatTransferCoefficientUnit)} is supported.", nameof(unit)); - return ToUnit((HeatTransferCoefficientUnit)unit); + return ToUnit(unitAsHeatTransferCoefficientUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Illuminance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Illuminance.NetFramework.g.cs index ffe51215f1..03068209cf 100644 --- a/UnitsNet/GeneratedCode/Quantities/Illuminance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Illuminance.NetFramework.g.cs @@ -591,15 +591,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is IlluminanceUnit)) - throw new ArgumentException("The given unit is not of type IlluminanceUnit.", nameof(unit)); - - return As((IlluminanceUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -613,6 +604,15 @@ public double As(IlluminanceUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is IlluminanceUnit unitAsIlluminanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IlluminanceUnit)} is supported.", nameof(unit)); + + return As(unitAsIlluminanceUnit); + } + /// /// Converts this Illuminance to another Illuminance with the unit representation . /// @@ -626,10 +626,10 @@ public Illuminance ToUnit(IlluminanceUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is IlluminanceUnit)) - throw new ArgumentException("The given unit is not of type IlluminanceUnit.", nameof(unit)); + if(!(unit is IlluminanceUnit unitAsIlluminanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IlluminanceUnit)} is supported.", nameof(unit)); - return ToUnit((IlluminanceUnit)unit); + return ToUnit(unitAsIlluminanceUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs index 8b6179e1b1..6f24d02884 100644 --- a/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Information.NetFramework.g.cs @@ -920,15 +920,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is InformationUnit)) - throw new ArgumentException("The given unit is not of type InformationUnit.", nameof(unit)); - - return As((InformationUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -942,6 +933,15 @@ public double As(InformationUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is InformationUnit unitAsInformationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(InformationUnit)} is supported.", nameof(unit)); + + return As(unitAsInformationUnit); + } + /// /// Converts this Information to another Information with the unit representation . /// @@ -955,10 +955,10 @@ public Information ToUnit(InformationUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is InformationUnit)) - throw new ArgumentException("The given unit is not of type InformationUnit.", nameof(unit)); + if(!(unit is InformationUnit unitAsInformationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(InformationUnit)} is supported.", nameof(unit)); - return ToUnit((InformationUnit)unit); + return ToUnit(unitAsInformationUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiance.NetFramework.g.cs index 2680ca351b..fbbb279d7b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiance.NetFramework.g.cs @@ -738,15 +738,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is IrradianceUnit)) - throw new ArgumentException("The given unit is not of type IrradianceUnit.", nameof(unit)); - - return As((IrradianceUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -760,6 +751,15 @@ public double As(IrradianceUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is IrradianceUnit unitAsIrradianceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradianceUnit)} is supported.", nameof(unit)); + + return As(unitAsIrradianceUnit); + } + /// /// Converts this Irradiance to another Irradiance with the unit representation . /// @@ -773,10 +773,10 @@ public Irradiance ToUnit(IrradianceUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is IrradianceUnit)) - throw new ArgumentException("The given unit is not of type IrradianceUnit.", nameof(unit)); + if(!(unit is IrradianceUnit unitAsIrradianceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradianceUnit)} is supported.", nameof(unit)); - return ToUnit((IrradianceUnit)unit); + return ToUnit(unitAsIrradianceUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiation.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiation.NetFramework.g.cs index 9935c73e9f..11bc89d2f6 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiation.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiation.NetFramework.g.cs @@ -621,15 +621,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is IrradiationUnit)) - throw new ArgumentException("The given unit is not of type IrradiationUnit.", nameof(unit)); - - return As((IrradiationUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -643,6 +634,15 @@ public double As(IrradiationUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is IrradiationUnit unitAsIrradiationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradiationUnit)} is supported.", nameof(unit)); + + return As(unitAsIrradiationUnit); + } + /// /// Converts this Irradiation to another Irradiation with the unit representation . /// @@ -656,10 +656,10 @@ public Irradiation ToUnit(IrradiationUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is IrradiationUnit)) - throw new ArgumentException("The given unit is not of type IrradiationUnit.", nameof(unit)); + if(!(unit is IrradiationUnit unitAsIrradiationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(IrradiationUnit)} is supported.", nameof(unit)); - return ToUnit((IrradiationUnit)unit); + return ToUnit(unitAsIrradiationUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.NetFramework.g.cs index bd9ffe0517..eb76c91baa 100644 --- a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.NetFramework.g.cs @@ -651,15 +651,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is KinematicViscosityUnit)) - throw new ArgumentException("The given unit is not of type KinematicViscosityUnit.", nameof(unit)); - - return As((KinematicViscosityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -673,6 +664,15 @@ public double As(KinematicViscosityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is KinematicViscosityUnit unitAsKinematicViscosityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(KinematicViscosityUnit)} is supported.", nameof(unit)); + + return As(unitAsKinematicViscosityUnit); + } + /// /// Converts this KinematicViscosity to another KinematicViscosity with the unit representation . /// @@ -686,10 +686,10 @@ public KinematicViscosity ToUnit(KinematicViscosityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is KinematicViscosityUnit)) - throw new ArgumentException("The given unit is not of type KinematicViscosityUnit.", nameof(unit)); + if(!(unit is KinematicViscosityUnit unitAsKinematicViscosityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(KinematicViscosityUnit)} is supported.", nameof(unit)); - return ToUnit((KinematicViscosityUnit)unit); + return ToUnit(unitAsKinematicViscosityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LapseRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/LapseRate.NetFramework.g.cs index 3c541f5f44..a9abed3de6 100644 --- a/UnitsNet/GeneratedCode/Quantities/LapseRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LapseRate.NetFramework.g.cs @@ -543,15 +543,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is LapseRateUnit)) - throw new ArgumentException("The given unit is not of type LapseRateUnit.", nameof(unit)); - - return As((LapseRateUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -565,6 +556,15 @@ public double As(LapseRateUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LapseRateUnit unitAsLapseRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LapseRateUnit)} is supported.", nameof(unit)); + + return As(unitAsLapseRateUnit); + } + /// /// Converts this LapseRate to another LapseRate with the unit representation . /// @@ -578,10 +578,10 @@ public LapseRate ToUnit(LapseRateUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is LapseRateUnit)) - throw new ArgumentException("The given unit is not of type LapseRateUnit.", nameof(unit)); + if(!(unit is LapseRateUnit unitAsLapseRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LapseRateUnit)} is supported.", nameof(unit)); - return ToUnit((LapseRateUnit)unit); + return ToUnit(unitAsLapseRateUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Length.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.NetFramework.g.cs index 05c4dda067..9f91a50bf1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.NetFramework.g.cs @@ -858,15 +858,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is LengthUnit)) - throw new ArgumentException("The given unit is not of type LengthUnit.", nameof(unit)); - - return As((LengthUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -880,6 +871,15 @@ public double As(LengthUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LengthUnit unitAsLengthUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LengthUnit)} is supported.", nameof(unit)); + + return As(unitAsLengthUnit); + } + /// /// Converts this Length to another Length with the unit representation . /// @@ -893,10 +893,10 @@ public Length ToUnit(LengthUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is LengthUnit)) - throw new ArgumentException("The given unit is not of type LengthUnit.", nameof(unit)); + if(!(unit is LengthUnit unitAsLengthUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LengthUnit)} is supported.", nameof(unit)); - return ToUnit((LengthUnit)unit); + return ToUnit(unitAsLengthUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Level.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Level.NetFramework.g.cs index 9ebd3845ce..085611f919 100644 --- a/UnitsNet/GeneratedCode/Quantities/Level.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Level.NetFramework.g.cs @@ -566,15 +566,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is LevelUnit)) - throw new ArgumentException("The given unit is not of type LevelUnit.", nameof(unit)); - - return As((LevelUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -588,6 +579,15 @@ public double As(LevelUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LevelUnit unitAsLevelUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LevelUnit)} is supported.", nameof(unit)); + + return As(unitAsLevelUnit); + } + /// /// Converts this Level to another Level with the unit representation . /// @@ -601,10 +601,10 @@ public Level ToUnit(LevelUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is LevelUnit)) - throw new ArgumentException("The given unit is not of type LevelUnit.", nameof(unit)); + if(!(unit is LevelUnit unitAsLevelUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LevelUnit)} is supported.", nameof(unit)); - return ToUnit((LevelUnit)unit); + return ToUnit(unitAsLevelUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LinearDensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearDensity.NetFramework.g.cs index 8b1a77e222..1861f18f2f 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearDensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearDensity.NetFramework.g.cs @@ -576,15 +576,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is LinearDensityUnit)) - throw new ArgumentException("The given unit is not of type LinearDensityUnit.", nameof(unit)); - - return As((LinearDensityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -598,6 +589,15 @@ public double As(LinearDensityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LinearDensityUnit unitAsLinearDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearDensityUnit)} is supported.", nameof(unit)); + + return As(unitAsLinearDensityUnit); + } + /// /// Converts this LinearDensity to another LinearDensity with the unit representation . /// @@ -611,10 +611,10 @@ public LinearDensity ToUnit(LinearDensityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is LinearDensityUnit)) - throw new ArgumentException("The given unit is not of type LinearDensityUnit.", nameof(unit)); + if(!(unit is LinearDensityUnit unitAsLinearDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearDensityUnit)} is supported.", nameof(unit)); - return ToUnit((LinearDensityUnit)unit); + return ToUnit(unitAsLinearDensityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.NetFramework.g.cs index 3937742930..d4b59caeb6 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is LuminousFluxUnit)) - throw new ArgumentException("The given unit is not of type LuminousFluxUnit.", nameof(unit)); - - return As((LuminousFluxUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(LuminousFluxUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LuminousFluxUnit unitAsLuminousFluxUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousFluxUnit)} is supported.", nameof(unit)); + + return As(unitAsLuminousFluxUnit); + } + /// /// Converts this LuminousFlux to another LuminousFlux with the unit representation . /// @@ -581,10 +581,10 @@ public LuminousFlux ToUnit(LuminousFluxUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is LuminousFluxUnit)) - throw new ArgumentException("The given unit is not of type LuminousFluxUnit.", nameof(unit)); + if(!(unit is LuminousFluxUnit unitAsLuminousFluxUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousFluxUnit)} is supported.", nameof(unit)); - return ToUnit((LuminousFluxUnit)unit); + return ToUnit(unitAsLuminousFluxUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.NetFramework.g.cs index f1a7002b7f..6f3c5656f4 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is LuminousIntensityUnit)) - throw new ArgumentException("The given unit is not of type LuminousIntensityUnit.", nameof(unit)); - - return As((LuminousIntensityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(LuminousIntensityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LuminousIntensityUnit unitAsLuminousIntensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousIntensityUnit)} is supported.", nameof(unit)); + + return As(unitAsLuminousIntensityUnit); + } + /// /// Converts this LuminousIntensity to another LuminousIntensity with the unit representation . /// @@ -581,10 +581,10 @@ public LuminousIntensity ToUnit(LuminousIntensityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is LuminousIntensityUnit)) - throw new ArgumentException("The given unit is not of type LuminousIntensityUnit.", nameof(unit)); + if(!(unit is LuminousIntensityUnit unitAsLuminousIntensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminousIntensityUnit)} is supported.", nameof(unit)); - return ToUnit((LuminousIntensityUnit)unit); + return ToUnit(unitAsLuminousIntensityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticField.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticField.NetFramework.g.cs index 69580dc2a3..a32bd2cc37 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticField.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticField.NetFramework.g.cs @@ -591,15 +591,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is MagneticFieldUnit)) - throw new ArgumentException("The given unit is not of type MagneticFieldUnit.", nameof(unit)); - - return As((MagneticFieldUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -613,6 +604,15 @@ public double As(MagneticFieldUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MagneticFieldUnit unitAsMagneticFieldUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFieldUnit)} is supported.", nameof(unit)); + + return As(unitAsMagneticFieldUnit); + } + /// /// Converts this MagneticField to another MagneticField with the unit representation . /// @@ -626,10 +626,10 @@ public MagneticField ToUnit(MagneticFieldUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is MagneticFieldUnit)) - throw new ArgumentException("The given unit is not of type MagneticFieldUnit.", nameof(unit)); + if(!(unit is MagneticFieldUnit unitAsMagneticFieldUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFieldUnit)} is supported.", nameof(unit)); - return ToUnit((MagneticFieldUnit)unit); + return ToUnit(unitAsMagneticFieldUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.NetFramework.g.cs index eb42affbd7..d84fbcecfa 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is MagneticFluxUnit)) - throw new ArgumentException("The given unit is not of type MagneticFluxUnit.", nameof(unit)); - - return As((MagneticFluxUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(MagneticFluxUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MagneticFluxUnit unitAsMagneticFluxUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFluxUnit)} is supported.", nameof(unit)); + + return As(unitAsMagneticFluxUnit); + } + /// /// Converts this MagneticFlux to another MagneticFlux with the unit representation . /// @@ -581,10 +581,10 @@ public MagneticFlux ToUnit(MagneticFluxUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is MagneticFluxUnit)) - throw new ArgumentException("The given unit is not of type MagneticFluxUnit.", nameof(unit)); + if(!(unit is MagneticFluxUnit unitAsMagneticFluxUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagneticFluxUnit)} is supported.", nameof(unit)); - return ToUnit((MagneticFluxUnit)unit); + return ToUnit(unitAsMagneticFluxUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Magnetization.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Magnetization.NetFramework.g.cs index 98a94de054..835e6daf37 100644 --- a/UnitsNet/GeneratedCode/Quantities/Magnetization.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Magnetization.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is MagnetizationUnit)) - throw new ArgumentException("The given unit is not of type MagnetizationUnit.", nameof(unit)); - - return As((MagnetizationUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(MagnetizationUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MagnetizationUnit unitAsMagnetizationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagnetizationUnit)} is supported.", nameof(unit)); + + return As(unitAsMagnetizationUnit); + } + /// /// Converts this Magnetization to another Magnetization with the unit representation . /// @@ -581,10 +581,10 @@ public Magnetization ToUnit(MagnetizationUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is MagnetizationUnit)) - throw new ArgumentException("The given unit is not of type MagnetizationUnit.", nameof(unit)); + if(!(unit is MagnetizationUnit unitAsMagnetizationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MagnetizationUnit)} is supported.", nameof(unit)); - return ToUnit((MagnetizationUnit)unit); + return ToUnit(unitAsMagnetizationUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs index 9cc253476b..2e2d84bd18 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.NetFramework.g.cs @@ -873,15 +873,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is MassUnit)) - throw new ArgumentException("The given unit is not of type MassUnit.", nameof(unit)); - - return As((MassUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -895,6 +886,15 @@ public double As(MassUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MassUnit unitAsMassUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassUnit)} is supported.", nameof(unit)); + + return As(unitAsMassUnit); + } + /// /// Converts this Mass to another Mass with the unit representation . /// @@ -908,10 +908,10 @@ public Mass ToUnit(MassUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is MassUnit)) - throw new ArgumentException("The given unit is not of type MassUnit.", nameof(unit)); + if(!(unit is MassUnit unitAsMassUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassUnit)} is supported.", nameof(unit)); - return ToUnit((MassUnit)unit); + return ToUnit(unitAsMassUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlow.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlow.NetFramework.g.cs index 944784fa61..1f853fd20c 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlow.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlow.NetFramework.g.cs @@ -993,15 +993,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is MassFlowUnit)) - throw new ArgumentException("The given unit is not of type MassFlowUnit.", nameof(unit)); - - return As((MassFlowUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -1015,6 +1006,15 @@ public double As(MassFlowUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MassFlowUnit unitAsMassFlowUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFlowUnit)} is supported.", nameof(unit)); + + return As(unitAsMassFlowUnit); + } + /// /// Converts this MassFlow to another MassFlow with the unit representation . /// @@ -1028,10 +1028,10 @@ public MassFlow ToUnit(MassFlowUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is MassFlowUnit)) - throw new ArgumentException("The given unit is not of type MassFlowUnit.", nameof(unit)); + if(!(unit is MassFlowUnit unitAsMassFlowUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFlowUnit)} is supported.", nameof(unit)); - return ToUnit((MassFlowUnit)unit); + return ToUnit(unitAsMassFlowUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlux.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlux.NetFramework.g.cs index 3db79074dd..9a080c17b2 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlux.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlux.NetFramework.g.cs @@ -558,15 +558,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is MassFluxUnit)) - throw new ArgumentException("The given unit is not of type MassFluxUnit.", nameof(unit)); - - return As((MassFluxUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -580,6 +571,15 @@ public double As(MassFluxUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MassFluxUnit unitAsMassFluxUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFluxUnit)} is supported.", nameof(unit)); + + return As(unitAsMassFluxUnit); + } + /// /// Converts this MassFlux to another MassFlux with the unit representation . /// @@ -593,10 +593,10 @@ public MassFlux ToUnit(MassFluxUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is MassFluxUnit)) - throw new ArgumentException("The given unit is not of type MassFluxUnit.", nameof(unit)); + if(!(unit is MassFluxUnit unitAsMassFluxUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassFluxUnit)} is supported.", nameof(unit)); - return ToUnit((MassFluxUnit)unit); + return ToUnit(unitAsMassFluxUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs index fd551d3b4f..3ebb5db9e3 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.NetFramework.g.cs @@ -948,15 +948,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is MassMomentOfInertiaUnit)) - throw new ArgumentException("The given unit is not of type MassMomentOfInertiaUnit.", nameof(unit)); - - return As((MassMomentOfInertiaUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -970,6 +961,15 @@ public double As(MassMomentOfInertiaUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MassMomentOfInertiaUnit unitAsMassMomentOfInertiaUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassMomentOfInertiaUnit)} is supported.", nameof(unit)); + + return As(unitAsMassMomentOfInertiaUnit); + } + /// /// Converts this MassMomentOfInertia to another MassMomentOfInertia with the unit representation . /// @@ -983,10 +983,10 @@ public MassMomentOfInertia ToUnit(MassMomentOfInertiaUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is MassMomentOfInertiaUnit)) - throw new ArgumentException("The given unit is not of type MassMomentOfInertiaUnit.", nameof(unit)); + if(!(unit is MassMomentOfInertiaUnit unitAsMassMomentOfInertiaUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MassMomentOfInertiaUnit)} is supported.", nameof(unit)); - return ToUnit((MassMomentOfInertiaUnit)unit); + return ToUnit(unitAsMassMomentOfInertiaUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.NetFramework.g.cs index bde9124537..f2b70bc69b 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.NetFramework.g.cs @@ -573,15 +573,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is MolarEnergyUnit)) - throw new ArgumentException("The given unit is not of type MolarEnergyUnit.", nameof(unit)); - - return As((MolarEnergyUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -595,6 +586,15 @@ public double As(MolarEnergyUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MolarEnergyUnit unitAsMolarEnergyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEnergyUnit)} is supported.", nameof(unit)); + + return As(unitAsMolarEnergyUnit); + } + /// /// Converts this MolarEnergy to another MolarEnergy with the unit representation . /// @@ -608,10 +608,10 @@ public MolarEnergy ToUnit(MolarEnergyUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is MolarEnergyUnit)) - throw new ArgumentException("The given unit is not of type MolarEnergyUnit.", nameof(unit)); + if(!(unit is MolarEnergyUnit unitAsMolarEnergyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEnergyUnit)} is supported.", nameof(unit)); - return ToUnit((MolarEnergyUnit)unit); + return ToUnit(unitAsMolarEnergyUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.NetFramework.g.cs index b327fc2112..5c083dcf44 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.NetFramework.g.cs @@ -573,15 +573,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is MolarEntropyUnit)) - throw new ArgumentException("The given unit is not of type MolarEntropyUnit.", nameof(unit)); - - return As((MolarEntropyUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -595,6 +586,15 @@ public double As(MolarEntropyUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MolarEntropyUnit unitAsMolarEntropyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEntropyUnit)} is supported.", nameof(unit)); + + return As(unitAsMolarEntropyUnit); + } + /// /// Converts this MolarEntropy to another MolarEntropy with the unit representation . /// @@ -608,10 +608,10 @@ public MolarEntropy ToUnit(MolarEntropyUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is MolarEntropyUnit)) - throw new ArgumentException("The given unit is not of type MolarEntropyUnit.", nameof(unit)); + if(!(unit is MolarEntropyUnit unitAsMolarEntropyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarEntropyUnit)} is supported.", nameof(unit)); - return ToUnit((MolarEntropyUnit)unit); + return ToUnit(unitAsMolarEntropyUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/MolarMass.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarMass.NetFramework.g.cs index b2ade25c57..c3c50457ec 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarMass.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarMass.NetFramework.g.cs @@ -708,15 +708,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is MolarMassUnit)) - throw new ArgumentException("The given unit is not of type MolarMassUnit.", nameof(unit)); - - return As((MolarMassUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -730,6 +721,15 @@ public double As(MolarMassUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MolarMassUnit unitAsMolarMassUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarMassUnit)} is supported.", nameof(unit)); + + return As(unitAsMolarMassUnit); + } + /// /// Converts this MolarMass to another MolarMass with the unit representation . /// @@ -743,10 +743,10 @@ public MolarMass ToUnit(MolarMassUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is MolarMassUnit)) - throw new ArgumentException("The given unit is not of type MolarMassUnit.", nameof(unit)); + if(!(unit is MolarMassUnit unitAsMolarMassUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarMassUnit)} is supported.", nameof(unit)); - return ToUnit((MolarMassUnit)unit); + return ToUnit(unitAsMolarMassUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs index 310db5f2d3..2e25137e8f 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.NetFramework.g.cs @@ -651,15 +651,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is MolarityUnit)) - throw new ArgumentException("The given unit is not of type MolarityUnit.", nameof(unit)); - - return As((MolarityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -673,6 +664,15 @@ public double As(MolarityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is MolarityUnit unitAsMolarityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarityUnit)} is supported.", nameof(unit)); + + return As(unitAsMolarityUnit); + } + /// /// Converts this Molarity to another Molarity with the unit representation . /// @@ -686,10 +686,10 @@ public Molarity ToUnit(MolarityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is MolarityUnit)) - throw new ArgumentException("The given unit is not of type MolarityUnit.", nameof(unit)); + if(!(unit is MolarityUnit unitAsMolarityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(MolarityUnit)} is supported.", nameof(unit)); - return ToUnit((MolarityUnit)unit); + return ToUnit(unitAsMolarityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Permeability.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Permeability.NetFramework.g.cs index 7e4bbb1663..495727d600 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permeability.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permeability.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is PermeabilityUnit)) - throw new ArgumentException("The given unit is not of type PermeabilityUnit.", nameof(unit)); - - return As((PermeabilityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(PermeabilityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PermeabilityUnit unitAsPermeabilityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermeabilityUnit)} is supported.", nameof(unit)); + + return As(unitAsPermeabilityUnit); + } + /// /// Converts this Permeability to another Permeability with the unit representation . /// @@ -581,10 +581,10 @@ public Permeability ToUnit(PermeabilityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is PermeabilityUnit)) - throw new ArgumentException("The given unit is not of type PermeabilityUnit.", nameof(unit)); + if(!(unit is PermeabilityUnit unitAsPermeabilityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermeabilityUnit)} is supported.", nameof(unit)); - return ToUnit((PermeabilityUnit)unit); + return ToUnit(unitAsPermeabilityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Permittivity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Permittivity.NetFramework.g.cs index b0aef361d4..5ae9a8fff6 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permittivity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permittivity.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is PermittivityUnit)) - throw new ArgumentException("The given unit is not of type PermittivityUnit.", nameof(unit)); - - return As((PermittivityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(PermittivityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PermittivityUnit unitAsPermittivityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermittivityUnit)} is supported.", nameof(unit)); + + return As(unitAsPermittivityUnit); + } + /// /// Converts this Permittivity to another Permittivity with the unit representation . /// @@ -581,10 +581,10 @@ public Permittivity ToUnit(PermittivityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is PermittivityUnit)) - throw new ArgumentException("The given unit is not of type PermittivityUnit.", nameof(unit)); + if(!(unit is PermittivityUnit unitAsPermittivityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PermittivityUnit)} is supported.", nameof(unit)); - return ToUnit((PermittivityUnit)unit); + return ToUnit(unitAsPermittivityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs index 9bc1bb44e6..26133d8e78 100644 --- a/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Power.NetFramework.g.cs @@ -830,15 +830,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is PowerUnit)) - throw new ArgumentException("The given unit is not of type PowerUnit.", nameof(unit)); - - return As((PowerUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -852,6 +843,15 @@ public double As(PowerUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PowerUnit unitAsPowerUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerUnit)} is supported.", nameof(unit)); + + return As(unitAsPowerUnit); + } + /// /// Converts this Power to another Power with the unit representation . /// @@ -865,10 +865,10 @@ public Power ToUnit(PowerUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is PowerUnit)) - throw new ArgumentException("The given unit is not of type PowerUnit.", nameof(unit)); + if(!(unit is PowerUnit unitAsPowerUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerUnit)} is supported.", nameof(unit)); - return ToUnit((PowerUnit)unit); + return ToUnit(unitAsPowerUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/PowerDensity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerDensity.NetFramework.g.cs index b8a0993cd1..e0d16ba632 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerDensity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerDensity.NetFramework.g.cs @@ -1188,15 +1188,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is PowerDensityUnit)) - throw new ArgumentException("The given unit is not of type PowerDensityUnit.", nameof(unit)); - - return As((PowerDensityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -1210,6 +1201,15 @@ public double As(PowerDensityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PowerDensityUnit unitAsPowerDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerDensityUnit)} is supported.", nameof(unit)); + + return As(unitAsPowerDensityUnit); + } + /// /// Converts this PowerDensity to another PowerDensity with the unit representation . /// @@ -1223,10 +1223,10 @@ public PowerDensity ToUnit(PowerDensityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is PowerDensityUnit)) - throw new ArgumentException("The given unit is not of type PowerDensityUnit.", nameof(unit)); + if(!(unit is PowerDensityUnit unitAsPowerDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerDensityUnit)} is supported.", nameof(unit)); - return ToUnit((PowerDensityUnit)unit); + return ToUnit(unitAsPowerDensityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/PowerRatio.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerRatio.NetFramework.g.cs index 591859e3d2..bc83cdb03f 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerRatio.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerRatio.NetFramework.g.cs @@ -566,15 +566,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is PowerRatioUnit)) - throw new ArgumentException("The given unit is not of type PowerRatioUnit.", nameof(unit)); - - return As((PowerRatioUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -588,6 +579,15 @@ public double As(PowerRatioUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PowerRatioUnit unitAsPowerRatioUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerRatioUnit)} is supported.", nameof(unit)); + + return As(unitAsPowerRatioUnit); + } + /// /// Converts this PowerRatio to another PowerRatio with the unit representation . /// @@ -601,10 +601,10 @@ public PowerRatio ToUnit(PowerRatioUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is PowerRatioUnit)) - throw new ArgumentException("The given unit is not of type PowerRatioUnit.", nameof(unit)); + if(!(unit is PowerRatioUnit unitAsPowerRatioUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PowerRatioUnit)} is supported.", nameof(unit)); - return ToUnit((PowerRatioUnit)unit); + return ToUnit(unitAsPowerRatioUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Pressure.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Pressure.NetFramework.g.cs index 9ce8c0403e..27465118ad 100644 --- a/UnitsNet/GeneratedCode/Quantities/Pressure.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Pressure.NetFramework.g.cs @@ -1158,15 +1158,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is PressureUnit)) - throw new ArgumentException("The given unit is not of type PressureUnit.", nameof(unit)); - - return As((PressureUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -1180,6 +1171,15 @@ public double As(PressureUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PressureUnit unitAsPressureUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureUnit)} is supported.", nameof(unit)); + + return As(unitAsPressureUnit); + } + /// /// Converts this Pressure to another Pressure with the unit representation . /// @@ -1193,10 +1193,10 @@ public Pressure ToUnit(PressureUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is PressureUnit)) - throw new ArgumentException("The given unit is not of type PressureUnit.", nameof(unit)); + if(!(unit is PressureUnit unitAsPressureUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureUnit)} is supported.", nameof(unit)); - return ToUnit((PressureUnit)unit); + return ToUnit(unitAsPressureUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.NetFramework.g.cs index f2f47f0f76..1e8d62a7e7 100644 --- a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.NetFramework.g.cs @@ -633,15 +633,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is PressureChangeRateUnit)) - throw new ArgumentException("The given unit is not of type PressureChangeRateUnit.", nameof(unit)); - - return As((PressureChangeRateUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -655,6 +646,15 @@ public double As(PressureChangeRateUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is PressureChangeRateUnit unitAsPressureChangeRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureChangeRateUnit)} is supported.", nameof(unit)); + + return As(unitAsPressureChangeRateUnit); + } + /// /// Converts this PressureChangeRate to another PressureChangeRate with the unit representation . /// @@ -668,10 +668,10 @@ public PressureChangeRate ToUnit(PressureChangeRateUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is PressureChangeRateUnit)) - throw new ArgumentException("The given unit is not of type PressureChangeRateUnit.", nameof(unit)); + if(!(unit is PressureChangeRateUnit unitAsPressureChangeRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(PressureChangeRateUnit)} is supported.", nameof(unit)); - return ToUnit((PressureChangeRateUnit)unit); + return ToUnit(unitAsPressureChangeRateUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Ratio.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Ratio.NetFramework.g.cs index 8cadd4cabe..a894e1f018 100644 --- a/UnitsNet/GeneratedCode/Quantities/Ratio.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Ratio.NetFramework.g.cs @@ -618,15 +618,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is RatioUnit)) - throw new ArgumentException("The given unit is not of type RatioUnit.", nameof(unit)); - - return As((RatioUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -640,6 +631,15 @@ public double As(RatioUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is RatioUnit unitAsRatioUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RatioUnit)} is supported.", nameof(unit)); + + return As(unitAsRatioUnit); + } + /// /// Converts this Ratio to another Ratio with the unit representation . /// @@ -653,10 +653,10 @@ public Ratio ToUnit(RatioUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is RatioUnit)) - throw new ArgumentException("The given unit is not of type RatioUnit.", nameof(unit)); + if(!(unit is RatioUnit unitAsRatioUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RatioUnit)} is supported.", nameof(unit)); - return ToUnit((RatioUnit)unit); + return ToUnit(unitAsRatioUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.NetFramework.g.cs index f34e10783c..84a0047631 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactiveEnergy.NetFramework.g.cs @@ -573,15 +573,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ReactiveEnergyUnit)) - throw new ArgumentException("The given unit is not of type ReactiveEnergyUnit.", nameof(unit)); - - return As((ReactiveEnergyUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -595,6 +586,15 @@ public double As(ReactiveEnergyUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ReactiveEnergyUnit unitAsReactiveEnergyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReactiveEnergyUnit)} is supported.", nameof(unit)); + + return As(unitAsReactiveEnergyUnit); + } + /// /// Converts this ReactiveEnergy to another ReactiveEnergy with the unit representation . /// @@ -608,10 +608,10 @@ public ReactiveEnergy ToUnit(ReactiveEnergyUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ReactiveEnergyUnit)) - throw new ArgumentException("The given unit is not of type ReactiveEnergyUnit.", nameof(unit)); + if(!(unit is ReactiveEnergyUnit unitAsReactiveEnergyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReactiveEnergyUnit)} is supported.", nameof(unit)); - return ToUnit((ReactiveEnergyUnit)unit); + return ToUnit(unitAsReactiveEnergyUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ReactivePower.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ReactivePower.NetFramework.g.cs index 171cb3fded..fab20deff1 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReactivePower.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReactivePower.NetFramework.g.cs @@ -588,15 +588,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ReactivePowerUnit)) - throw new ArgumentException("The given unit is not of type ReactivePowerUnit.", nameof(unit)); - - return As((ReactivePowerUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -610,6 +601,15 @@ public double As(ReactivePowerUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ReactivePowerUnit unitAsReactivePowerUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReactivePowerUnit)} is supported.", nameof(unit)); + + return As(unitAsReactivePowerUnit); + } + /// /// Converts this ReactivePower to another ReactivePower with the unit representation . /// @@ -623,10 +623,10 @@ public ReactivePower ToUnit(ReactivePowerUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ReactivePowerUnit)) - throw new ArgumentException("The given unit is not of type ReactivePowerUnit.", nameof(unit)); + if(!(unit is ReactivePowerUnit unitAsReactivePowerUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ReactivePowerUnit)} is supported.", nameof(unit)); - return ToUnit((ReactivePowerUnit)unit); + return ToUnit(unitAsReactivePowerUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.NetFramework.g.cs index b5928a135d..2566dc57be 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.NetFramework.g.cs @@ -573,15 +573,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is RotationalAccelerationUnit)) - throw new ArgumentException("The given unit is not of type RotationalAccelerationUnit.", nameof(unit)); - - return As((RotationalAccelerationUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -595,6 +586,15 @@ public double As(RotationalAccelerationUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is RotationalAccelerationUnit unitAsRotationalAccelerationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalAccelerationUnit)} is supported.", nameof(unit)); + + return As(unitAsRotationalAccelerationUnit); + } + /// /// Converts this RotationalAcceleration to another RotationalAcceleration with the unit representation . /// @@ -608,10 +608,10 @@ public RotationalAcceleration ToUnit(RotationalAccelerationUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is RotationalAccelerationUnit)) - throw new ArgumentException("The given unit is not of type RotationalAccelerationUnit.", nameof(unit)); + if(!(unit is RotationalAccelerationUnit unitAsRotationalAccelerationUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalAccelerationUnit)} is supported.", nameof(unit)); - return ToUnit((RotationalAccelerationUnit)unit); + return ToUnit(unitAsRotationalAccelerationUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.NetFramework.g.cs index d88e6cdb24..2d4c20e3ab 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.NetFramework.g.cs @@ -723,15 +723,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is RotationalSpeedUnit)) - throw new ArgumentException("The given unit is not of type RotationalSpeedUnit.", nameof(unit)); - - return As((RotationalSpeedUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -745,6 +736,15 @@ public double As(RotationalSpeedUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is RotationalSpeedUnit unitAsRotationalSpeedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalSpeedUnit)} is supported.", nameof(unit)); + + return As(unitAsRotationalSpeedUnit); + } + /// /// Converts this RotationalSpeed to another RotationalSpeed with the unit representation . /// @@ -758,10 +758,10 @@ public RotationalSpeed ToUnit(RotationalSpeedUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is RotationalSpeedUnit)) - throw new ArgumentException("The given unit is not of type RotationalSpeedUnit.", nameof(unit)); + if(!(unit is RotationalSpeedUnit unitAsRotationalSpeedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalSpeedUnit)} is supported.", nameof(unit)); - return ToUnit((RotationalSpeedUnit)unit); + return ToUnit(unitAsRotationalSpeedUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.NetFramework.g.cs index fc3f0554a0..bebf7c5c35 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.NetFramework.g.cs @@ -573,15 +573,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is RotationalStiffnessUnit)) - throw new ArgumentException("The given unit is not of type RotationalStiffnessUnit.", nameof(unit)); - - return As((RotationalStiffnessUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -595,6 +586,15 @@ public double As(RotationalStiffnessUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is RotationalStiffnessUnit unitAsRotationalStiffnessUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessUnit)} is supported.", nameof(unit)); + + return As(unitAsRotationalStiffnessUnit); + } + /// /// Converts this RotationalStiffness to another RotationalStiffness with the unit representation . /// @@ -608,10 +608,10 @@ public RotationalStiffness ToUnit(RotationalStiffnessUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is RotationalStiffnessUnit)) - throw new ArgumentException("The given unit is not of type RotationalStiffnessUnit.", nameof(unit)); + if(!(unit is RotationalStiffnessUnit unitAsRotationalStiffnessUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessUnit)} is supported.", nameof(unit)); - return ToUnit((RotationalStiffnessUnit)unit); + return ToUnit(unitAsRotationalStiffnessUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.NetFramework.g.cs index d3280928b6..e6229d7d1b 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.NetFramework.g.cs @@ -573,15 +573,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is RotationalStiffnessPerLengthUnit)) - throw new ArgumentException("The given unit is not of type RotationalStiffnessPerLengthUnit.", nameof(unit)); - - return As((RotationalStiffnessPerLengthUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -595,6 +586,15 @@ public double As(RotationalStiffnessPerLengthUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is RotationalStiffnessPerLengthUnit unitAsRotationalStiffnessPerLengthUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessPerLengthUnit)} is supported.", nameof(unit)); + + return As(unitAsRotationalStiffnessPerLengthUnit); + } + /// /// Converts this RotationalStiffnessPerLength to another RotationalStiffnessPerLength with the unit representation . /// @@ -608,10 +608,10 @@ public RotationalStiffnessPerLength ToUnit(RotationalStiffnessPerLengthUnit unit /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is RotationalStiffnessPerLengthUnit)) - throw new ArgumentException("The given unit is not of type RotationalStiffnessPerLengthUnit.", nameof(unit)); + if(!(unit is RotationalStiffnessPerLengthUnit unitAsRotationalStiffnessPerLengthUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RotationalStiffnessPerLengthUnit)} is supported.", nameof(unit)); - return ToUnit((RotationalStiffnessPerLengthUnit)unit); + return ToUnit(unitAsRotationalStiffnessPerLengthUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SolidAngle.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/SolidAngle.NetFramework.g.cs index cbcd4b5519..7045df5cef 100644 --- a/UnitsNet/GeneratedCode/Quantities/SolidAngle.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SolidAngle.NetFramework.g.cs @@ -546,15 +546,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is SolidAngleUnit)) - throw new ArgumentException("The given unit is not of type SolidAngleUnit.", nameof(unit)); - - return As((SolidAngleUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -568,6 +559,15 @@ public double As(SolidAngleUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SolidAngleUnit unitAsSolidAngleUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SolidAngleUnit)} is supported.", nameof(unit)); + + return As(unitAsSolidAngleUnit); + } + /// /// Converts this SolidAngle to another SolidAngle with the unit representation . /// @@ -581,10 +581,10 @@ public SolidAngle ToUnit(SolidAngleUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is SolidAngleUnit)) - throw new ArgumentException("The given unit is not of type SolidAngleUnit.", nameof(unit)); + if(!(unit is SolidAngleUnit unitAsSolidAngleUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SolidAngleUnit)} is supported.", nameof(unit)); - return ToUnit((SolidAngleUnit)unit); + return ToUnit(unitAsSolidAngleUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.NetFramework.g.cs index 569840c497..4e1361117d 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.NetFramework.g.cs @@ -666,15 +666,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is SpecificEnergyUnit)) - throw new ArgumentException("The given unit is not of type SpecificEnergyUnit.", nameof(unit)); - - return As((SpecificEnergyUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -688,6 +679,15 @@ public double As(SpecificEnergyUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SpecificEnergyUnit unitAsSpecificEnergyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEnergyUnit)} is supported.", nameof(unit)); + + return As(unitAsSpecificEnergyUnit); + } + /// /// Converts this SpecificEnergy to another SpecificEnergy with the unit representation . /// @@ -701,10 +701,10 @@ public SpecificEnergy ToUnit(SpecificEnergyUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is SpecificEnergyUnit)) - throw new ArgumentException("The given unit is not of type SpecificEnergyUnit.", nameof(unit)); + if(!(unit is SpecificEnergyUnit unitAsSpecificEnergyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEnergyUnit)} is supported.", nameof(unit)); - return ToUnit((SpecificEnergyUnit)unit); + return ToUnit(unitAsSpecificEnergyUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.NetFramework.g.cs index 7d9b6b7bb5..82c36fb2e4 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.NetFramework.g.cs @@ -648,15 +648,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is SpecificEntropyUnit)) - throw new ArgumentException("The given unit is not of type SpecificEntropyUnit.", nameof(unit)); - - return As((SpecificEntropyUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -670,6 +661,15 @@ public double As(SpecificEntropyUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SpecificEntropyUnit unitAsSpecificEntropyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEntropyUnit)} is supported.", nameof(unit)); + + return As(unitAsSpecificEntropyUnit); + } + /// /// Converts this SpecificEntropy to another SpecificEntropy with the unit representation . /// @@ -683,10 +683,10 @@ public SpecificEntropy ToUnit(SpecificEntropyUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is SpecificEntropyUnit)) - throw new ArgumentException("The given unit is not of type SpecificEntropyUnit.", nameof(unit)); + if(!(unit is SpecificEntropyUnit unitAsSpecificEntropyUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificEntropyUnit)} is supported.", nameof(unit)); - return ToUnit((SpecificEntropyUnit)unit); + return ToUnit(unitAsSpecificEntropyUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.NetFramework.g.cs index 8b12852d22..eea5cdb3a1 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.NetFramework.g.cs @@ -573,15 +573,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is SpecificVolumeUnit)) - throw new ArgumentException("The given unit is not of type SpecificVolumeUnit.", nameof(unit)); - - return As((SpecificVolumeUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -595,6 +586,15 @@ public double As(SpecificVolumeUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SpecificVolumeUnit unitAsSpecificVolumeUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificVolumeUnit)} is supported.", nameof(unit)); + + return As(unitAsSpecificVolumeUnit); + } + /// /// Converts this SpecificVolume to another SpecificVolume with the unit representation . /// @@ -608,10 +608,10 @@ public SpecificVolume ToUnit(SpecificVolumeUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is SpecificVolumeUnit)) - throw new ArgumentException("The given unit is not of type SpecificVolumeUnit.", nameof(unit)); + if(!(unit is SpecificVolumeUnit unitAsSpecificVolumeUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificVolumeUnit)} is supported.", nameof(unit)); - return ToUnit((SpecificVolumeUnit)unit); + return ToUnit(unitAsSpecificVolumeUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.NetFramework.g.cs index 5f4e50b093..33f0d35baf 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.NetFramework.g.cs @@ -786,15 +786,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is SpecificWeightUnit)) - throw new ArgumentException("The given unit is not of type SpecificWeightUnit.", nameof(unit)); - - return As((SpecificWeightUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -808,6 +799,15 @@ public double As(SpecificWeightUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SpecificWeightUnit unitAsSpecificWeightUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificWeightUnit)} is supported.", nameof(unit)); + + return As(unitAsSpecificWeightUnit); + } + /// /// Converts this SpecificWeight to another SpecificWeight with the unit representation . /// @@ -821,10 +821,10 @@ public SpecificWeight ToUnit(SpecificWeightUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is SpecificWeightUnit)) - throw new ArgumentException("The given unit is not of type SpecificWeightUnit.", nameof(unit)); + if(!(unit is SpecificWeightUnit unitAsSpecificWeightUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpecificWeightUnit)} is supported.", nameof(unit)); - return ToUnit((SpecificWeightUnit)unit); + return ToUnit(unitAsSpecificWeightUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Speed.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Speed.NetFramework.g.cs index faf37f6b87..40bc721df2 100644 --- a/UnitsNet/GeneratedCode/Quantities/Speed.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Speed.NetFramework.g.cs @@ -1008,15 +1008,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is SpeedUnit)) - throw new ArgumentException("The given unit is not of type SpeedUnit.", nameof(unit)); - - return As((SpeedUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -1030,6 +1021,15 @@ public double As(SpeedUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is SpeedUnit unitAsSpeedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpeedUnit)} is supported.", nameof(unit)); + + return As(unitAsSpeedUnit); + } + /// /// Converts this Speed to another Speed with the unit representation . /// @@ -1043,10 +1043,10 @@ public Speed ToUnit(SpeedUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is SpeedUnit)) - throw new ArgumentException("The given unit is not of type SpeedUnit.", nameof(unit)); + if(!(unit is SpeedUnit unitAsSpeedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(SpeedUnit)} is supported.", nameof(unit)); - return ToUnit((SpeedUnit)unit); + return ToUnit(unitAsSpeedUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Temperature.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Temperature.NetFramework.g.cs index e640d25efd..db04d15d6b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Temperature.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Temperature.NetFramework.g.cs @@ -602,15 +602,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is TemperatureUnit)) - throw new ArgumentException("The given unit is not of type TemperatureUnit.", nameof(unit)); - - return As((TemperatureUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -624,6 +615,15 @@ public double As(TemperatureUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is TemperatureUnit unitAsTemperatureUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureUnit)} is supported.", nameof(unit)); + + return As(unitAsTemperatureUnit); + } + /// /// Converts this Temperature to another Temperature with the unit representation . /// @@ -637,10 +637,10 @@ public Temperature ToUnit(TemperatureUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is TemperatureUnit)) - throw new ArgumentException("The given unit is not of type TemperatureUnit.", nameof(unit)); + if(!(unit is TemperatureUnit unitAsTemperatureUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureUnit)} is supported.", nameof(unit)); - return ToUnit((TemperatureUnit)unit); + return ToUnit(unitAsTemperatureUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.NetFramework.g.cs index c1d55332e5..6341ab88b0 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.NetFramework.g.cs @@ -678,15 +678,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is TemperatureChangeRateUnit)) - throw new ArgumentException("The given unit is not of type TemperatureChangeRateUnit.", nameof(unit)); - - return As((TemperatureChangeRateUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -700,6 +691,15 @@ public double As(TemperatureChangeRateUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is TemperatureChangeRateUnit unitAsTemperatureChangeRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureChangeRateUnit)} is supported.", nameof(unit)); + + return As(unitAsTemperatureChangeRateUnit); + } + /// /// Converts this TemperatureChangeRate to another TemperatureChangeRate with the unit representation . /// @@ -713,10 +713,10 @@ public TemperatureChangeRate ToUnit(TemperatureChangeRateUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is TemperatureChangeRateUnit)) - throw new ArgumentException("The given unit is not of type TemperatureChangeRateUnit.", nameof(unit)); + if(!(unit is TemperatureChangeRateUnit unitAsTemperatureChangeRateUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureChangeRateUnit)} is supported.", nameof(unit)); - return ToUnit((TemperatureChangeRateUnit)unit); + return ToUnit(unitAsTemperatureChangeRateUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.NetFramework.g.cs index 3288783afe..abb6759f07 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.NetFramework.g.cs @@ -648,15 +648,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is TemperatureDeltaUnit)) - throw new ArgumentException("The given unit is not of type TemperatureDeltaUnit.", nameof(unit)); - - return As((TemperatureDeltaUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -670,6 +661,15 @@ public double As(TemperatureDeltaUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is TemperatureDeltaUnit unitAsTemperatureDeltaUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureDeltaUnit)} is supported.", nameof(unit)); + + return As(unitAsTemperatureDeltaUnit); + } + /// /// Converts this TemperatureDelta to another TemperatureDelta with the unit representation . /// @@ -683,10 +683,10 @@ public TemperatureDelta ToUnit(TemperatureDeltaUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is TemperatureDeltaUnit)) - throw new ArgumentException("The given unit is not of type TemperatureDeltaUnit.", nameof(unit)); + if(!(unit is TemperatureDeltaUnit unitAsTemperatureDeltaUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TemperatureDeltaUnit)} is supported.", nameof(unit)); - return ToUnit((TemperatureDeltaUnit)unit); + return ToUnit(unitAsTemperatureDeltaUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.NetFramework.g.cs index 941ba285a6..61be4f2706 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.NetFramework.g.cs @@ -561,15 +561,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ThermalConductivityUnit)) - throw new ArgumentException("The given unit is not of type ThermalConductivityUnit.", nameof(unit)); - - return As((ThermalConductivityUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -583,6 +574,15 @@ public double As(ThermalConductivityUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ThermalConductivityUnit unitAsThermalConductivityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalConductivityUnit)} is supported.", nameof(unit)); + + return As(unitAsThermalConductivityUnit); + } + /// /// Converts this ThermalConductivity to another ThermalConductivity with the unit representation . /// @@ -596,10 +596,10 @@ public ThermalConductivity ToUnit(ThermalConductivityUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ThermalConductivityUnit)) - throw new ArgumentException("The given unit is not of type ThermalConductivityUnit.", nameof(unit)); + if(!(unit is ThermalConductivityUnit unitAsThermalConductivityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalConductivityUnit)} is supported.", nameof(unit)); - return ToUnit((ThermalConductivityUnit)unit); + return ToUnit(unitAsThermalConductivityUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalResistance.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalResistance.NetFramework.g.cs index 94152410ad..4d96f4cb3d 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalResistance.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalResistance.NetFramework.g.cs @@ -603,15 +603,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is ThermalResistanceUnit)) - throw new ArgumentException("The given unit is not of type ThermalResistanceUnit.", nameof(unit)); - - return As((ThermalResistanceUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -625,6 +616,15 @@ public double As(ThermalResistanceUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is ThermalResistanceUnit unitAsThermalResistanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalResistanceUnit)} is supported.", nameof(unit)); + + return As(unitAsThermalResistanceUnit); + } + /// /// Converts this ThermalResistance to another ThermalResistance with the unit representation . /// @@ -638,10 +638,10 @@ public ThermalResistance ToUnit(ThermalResistanceUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is ThermalResistanceUnit)) - throw new ArgumentException("The given unit is not of type ThermalResistanceUnit.", nameof(unit)); + if(!(unit is ThermalResistanceUnit unitAsThermalResistanceUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(ThermalResistanceUnit)} is supported.", nameof(unit)); - return ToUnit((ThermalResistanceUnit)unit); + return ToUnit(unitAsThermalResistanceUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Torque.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Torque.NetFramework.g.cs index a51cc1458f..17442ff684 100644 --- a/UnitsNet/GeneratedCode/Quantities/Torque.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Torque.NetFramework.g.cs @@ -843,15 +843,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is TorqueUnit)) - throw new ArgumentException("The given unit is not of type TorqueUnit.", nameof(unit)); - - return As((TorqueUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -865,6 +856,15 @@ public double As(TorqueUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is TorqueUnit unitAsTorqueUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TorqueUnit)} is supported.", nameof(unit)); + + return As(unitAsTorqueUnit); + } + /// /// Converts this Torque to another Torque with the unit representation . /// @@ -878,10 +878,10 @@ public Torque ToUnit(TorqueUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is TorqueUnit)) - throw new ArgumentException("The given unit is not of type TorqueUnit.", nameof(unit)); + if(!(unit is TorqueUnit unitAsTorqueUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(TorqueUnit)} is supported.", nameof(unit)); - return ToUnit((TorqueUnit)unit); + return ToUnit(unitAsTorqueUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VitaminA.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/VitaminA.NetFramework.g.cs index ab3a99de4c..fd613666b8 100644 --- a/UnitsNet/GeneratedCode/Quantities/VitaminA.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VitaminA.NetFramework.g.cs @@ -543,15 +543,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is VitaminAUnit)) - throw new ArgumentException("The given unit is not of type VitaminAUnit.", nameof(unit)); - - return As((VitaminAUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -565,6 +556,15 @@ public double As(VitaminAUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is VitaminAUnit unitAsVitaminAUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VitaminAUnit)} is supported.", nameof(unit)); + + return As(unitAsVitaminAUnit); + } + /// /// Converts this VitaminA to another VitaminA with the unit representation . /// @@ -578,10 +578,10 @@ public VitaminA ToUnit(VitaminAUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is VitaminAUnit)) - throw new ArgumentException("The given unit is not of type VitaminAUnit.", nameof(unit)); + if(!(unit is VitaminAUnit unitAsVitaminAUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VitaminAUnit)} is supported.", nameof(unit)); - return ToUnit((VitaminAUnit)unit); + return ToUnit(unitAsVitaminAUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.NetFramework.g.cs index 0ce95b10ff..87c99bf496 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.NetFramework.g.cs @@ -1203,15 +1203,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is VolumeUnit)) - throw new ArgumentException("The given unit is not of type VolumeUnit.", nameof(unit)); - - return As((VolumeUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -1225,6 +1216,15 @@ public double As(VolumeUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is VolumeUnit unitAsVolumeUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeUnit)} is supported.", nameof(unit)); + + return As(unitAsVolumeUnit); + } + /// /// Converts this Volume to another Volume with the unit representation . /// @@ -1238,10 +1238,10 @@ public Volume ToUnit(VolumeUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is VolumeUnit)) - throw new ArgumentException("The given unit is not of type VolumeUnit.", nameof(unit)); + if(!(unit is VolumeUnit unitAsVolumeUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeUnit)} is supported.", nameof(unit)); - return ToUnit((VolumeUnit)unit); + return ToUnit(unitAsVolumeUnit); } /// diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.NetFramework.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.NetFramework.g.cs index f54dc0ba31..0c050a3258 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.NetFramework.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.NetFramework.g.cs @@ -1248,15 +1248,6 @@ public override int GetHashCode() #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is VolumeFlowUnit)) - throw new ArgumentException("The given unit is not of type VolumeFlowUnit.", nameof(unit)); - - return As((VolumeFlowUnit)unit); - } - /// /// Convert to the unit representation . /// @@ -1270,6 +1261,15 @@ public double As(VolumeFlowUnit unit) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is VolumeFlowUnit unitAsVolumeFlowUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeFlowUnit)} is supported.", nameof(unit)); + + return As(unitAsVolumeFlowUnit); + } + /// /// Converts this VolumeFlow to another VolumeFlow with the unit representation . /// @@ -1283,10 +1283,10 @@ public VolumeFlow ToUnit(VolumeFlowUnit unit) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is VolumeFlowUnit)) - throw new ArgumentException("The given unit is not of type VolumeFlowUnit.", nameof(unit)); + if(!(unit is VolumeFlowUnit unitAsVolumeFlowUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(VolumeFlowUnit)} is supported.", nameof(unit)); - return ToUnit((VolumeFlowUnit)unit); + return ToUnit(unitAsVolumeFlowUnit); } /// diff --git a/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 b/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 index b2ee705277..b56e28a3bf 100644 --- a/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 +++ b/UnitsNet/Scripts/Include-GenerateQuantitySourceCode.ps1 @@ -969,15 +969,6 @@ function GenerateConversionMethods([GeneratorArgs]$genArgs) #region Conversion Methods - /// - double IQuantity.As(Enum unit) - { - if(!(unit is $unitEnumName)) - throw new ArgumentException("The given unit is not of type $unitEnumName.", nameof(unit)); - - return As(($unitEnumName)unit); - } - /// /// Convert to the unit representation . /// @@ -991,6 +982,15 @@ function GenerateConversionMethods([GeneratorArgs]$genArgs) return Convert.ToDouble(converted); } + /// + double IQuantity.As(Enum unit) + { + if(!(unit is $unitEnumName unitAs$unitEnumName)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof($unitEnumName)} is supported.", nameof(unit)); + + return As(unitAs$unitEnumName); + } + /// /// Converts this $quantityName to another $quantityName with the unit representation . /// @@ -1004,10 +1004,10 @@ function GenerateConversionMethods([GeneratorArgs]$genArgs) /// IQuantity IQuantity.ToUnit(Enum unit) { - if(!(unit is $unitEnumName)) - throw new ArgumentException("The given unit is not of type $unitEnumName.", nameof(unit)); + if(!(unit is $unitEnumName unitAs$unitEnumName)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof($unitEnumName)} is supported.", nameof(unit)); - return ToUnit(($unitEnumName)unit); + return ToUnit(unitAs$unitEnumName); } ///