diff --git a/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs b/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs index b793c3f452..6e3eef62dd 100644 --- a/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs +++ b/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs @@ -93,7 +93,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist object unit = Enum.Parse(reflectedUnitEnumType, unitEnumValue); // Mass.From() method, assume no overloads exist - MethodInfo fromMethod = reflectedUnitType.GetMethod("From"); + MethodInfo fromMethod = (from m in reflectedUnitType.GetMethods() + where m.Name.Equals("From", StringComparison.InvariantCulture) && + !m.ReturnType.IsGenericType // we want the non nullable type + select m).Single(); // Ex: Mass.From(55, MassUnit.Gram) // TODO: there is a possible loss of precision if base value requires higher precision than double can represent. diff --git a/UnitsNet.Tests/NullableConstructors.cs b/UnitsNet.Tests/NullableConstructors.cs new file mode 100644 index 0000000000..85a725b922 --- /dev/null +++ b/UnitsNet.Tests/NullableConstructors.cs @@ -0,0 +1,90 @@ +// Copyright(c) 2007 Andreas Gullberg Larsen +// https://github.com/anjdreas/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using NUnit.Framework; +using UnitsNet.Units; + +namespace UnitsNet.Tests +{ + public class NullableConstructors + { + [Test] + public void StaticConstructorWithNullReturnsNullWhenBackingTypeIsDouble() + { + Length? meter = Length.FromMeters(null); + Assert.IsFalse(meter.HasValue); + } + + [Test] + public void StaticConstructorWithNullAndEnumReturnsNullWhenBackingTypeIsDouble() + { + Length? meter = Length.From(null, LengthUnit.Meter); + Assert.IsFalse(meter.HasValue); + } + + [Test] + public void StaticConstructorWithNullAndEnumArgumentReturnsValueWhenInputArgumentHasValueWhenBackingTypeIsDouble() + { + double? value = 1.0; + Length? meter = Length.From(value, LengthUnit.Meter); + Assert.IsTrue(meter.HasValue); + } + + [Test] + public void StaticConstructorWithNullArgumentReturnsValueWhenInputArgumentHasValueWhenBackingTypeIsDouble() + { + double? value = 1.0; + Length? meter = Length.FromMeters(value); + Assert.IsTrue(meter.HasValue); + } + + [Test] + public void StaticConstructorWithNullReturnsNullWhenBackingTypeIsDecimal() + { + Information? meter = Information.FromBytes(null); + Assert.IsFalse(meter.HasValue); + } + + [Test] + public void StaticConstructorWithNullAndEnumReturnsNullWhenBackingTypeIsDecimal() + { + Information? meter = Information.From(null, InformationUnit.Byte); + Assert.IsFalse(meter.HasValue); + } + + [Test] + public void StaticConstructorWithNullAndEnumArgumentReturnsValueWhenInputArgumentHasValueWhenBackingTypeIsDecimal() + { + double? value = 1.0; + Information? meter = Information.From(value, InformationUnit.Byte); + Assert.IsTrue(meter.HasValue); + } + + [Test] + public void StaticConstructorWithNullArgumentReturnsValueWhenInputArgumentHasValueWhenBackingTypeIsDecimal() + { + double? value = 1.0; + Information? meter = Information.FromBytes(value); + Assert.IsTrue(meter.HasValue); + } + } +} \ No newline at end of file diff --git a/UnitsNet/GeneratedCode/UnitClasses/Acceleration.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Acceleration.g.cs index 1b53030d48..2b8e7ac7b7 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Acceleration.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Acceleration.g.cs @@ -176,6 +176,112 @@ public static Acceleration FromNanometerPerSecondSquared(double nanometerperseco } + /// + /// Get nullable Acceleration from nullable CentimeterPerSecondSquared. + /// + public static Acceleration? FromCentimeterPerSecondSquared(double? centimeterpersecondsquared) + { + if (centimeterpersecondsquared.HasValue) + { + return FromCentimeterPerSecondSquared(centimeterpersecondsquared.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Acceleration from nullable DecimeterPerSecondSquared. + /// + public static Acceleration? FromDecimeterPerSecondSquared(double? decimeterpersecondsquared) + { + if (decimeterpersecondsquared.HasValue) + { + return FromDecimeterPerSecondSquared(decimeterpersecondsquared.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Acceleration from nullable KilometerPerSecondSquared. + /// + public static Acceleration? FromKilometerPerSecondSquared(double? kilometerpersecondsquared) + { + if (kilometerpersecondsquared.HasValue) + { + return FromKilometerPerSecondSquared(kilometerpersecondsquared.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Acceleration from nullable MeterPerSecondSquared. + /// + public static Acceleration? FromMeterPerSecondSquared(double? meterpersecondsquared) + { + if (meterpersecondsquared.HasValue) + { + return FromMeterPerSecondSquared(meterpersecondsquared.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Acceleration from nullable MicrometerPerSecondSquared. + /// + public static Acceleration? FromMicrometerPerSecondSquared(double? micrometerpersecondsquared) + { + if (micrometerpersecondsquared.HasValue) + { + return FromMicrometerPerSecondSquared(micrometerpersecondsquared.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Acceleration from nullable MillimeterPerSecondSquared. + /// + public static Acceleration? FromMillimeterPerSecondSquared(double? millimeterpersecondsquared) + { + if (millimeterpersecondsquared.HasValue) + { + return FromMillimeterPerSecondSquared(millimeterpersecondsquared.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Acceleration from nullable NanometerPerSecondSquared. + /// + public static Acceleration? FromNanometerPerSecondSquared(double? nanometerpersecondsquared) + { + if (nanometerpersecondsquared.HasValue) + { + return FromNanometerPerSecondSquared(nanometerpersecondsquared.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -206,6 +312,40 @@ public static Acceleration From(double value, AccelerationUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Acceleration unit value. + public static Acceleration? From(double? value, AccelerationUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case AccelerationUnit.CentimeterPerSecondSquared: + return FromCentimeterPerSecondSquared(value.Value); + case AccelerationUnit.DecimeterPerSecondSquared: + return FromDecimeterPerSecondSquared(value.Value); + case AccelerationUnit.KilometerPerSecondSquared: + return FromKilometerPerSecondSquared(value.Value); + case AccelerationUnit.MeterPerSecondSquared: + return FromMeterPerSecondSquared(value.Value); + case AccelerationUnit.MicrometerPerSecondSquared: + return FromMicrometerPerSecondSquared(value.Value); + case AccelerationUnit.MillimeterPerSecondSquared: + return FromMillimeterPerSecondSquared(value.Value); + case AccelerationUnit.NanometerPerSecondSquared: + return FromNanometerPerSecondSquared(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -371,14 +511,14 @@ public double As(AccelerationUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Acceleration Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/AmplitudeRatio.g.cs b/UnitsNet/GeneratedCode/UnitClasses/AmplitudeRatio.g.cs index 8b7b8340e5..1c4f00cf33 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/AmplitudeRatio.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/AmplitudeRatio.g.cs @@ -112,6 +112,52 @@ public static AmplitudeRatio FromDecibelVolts(double decibelvolts) } + /// + /// Get nullable AmplitudeRatio from nullable DecibelMicrovolts. + /// + public static AmplitudeRatio? FromDecibelMicrovolts(double? decibelmicrovolts) + { + if (decibelmicrovolts.HasValue) + { + return FromDecibelMicrovolts(decibelmicrovolts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable AmplitudeRatio from nullable DecibelMillivolts. + /// + public static AmplitudeRatio? FromDecibelMillivolts(double? decibelmillivolts) + { + if (decibelmillivolts.HasValue) + { + return FromDecibelMillivolts(decibelmillivolts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable AmplitudeRatio from nullable DecibelVolts. + /// + public static AmplitudeRatio? FromDecibelVolts(double? decibelvolts) + { + if (decibelvolts.HasValue) + { + return FromDecibelVolts(decibelvolts.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -134,6 +180,32 @@ public static AmplitudeRatio From(double value, AmplitudeRatioUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// AmplitudeRatio unit value. + public static AmplitudeRatio? From(double? value, AmplitudeRatioUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case AmplitudeRatioUnit.DecibelMicrovolt: + return FromDecibelMicrovolts(value.Value); + case AmplitudeRatioUnit.DecibelMillivolt: + return FromDecibelMillivolts(value.Value); + case AmplitudeRatioUnit.DecibelVolt: + return FromDecibelVolts(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -299,14 +371,14 @@ public double As(AmplitudeRatioUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static AmplitudeRatio Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Angle.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Angle.g.cs index cdd3d974bc..3cd71600f9 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Angle.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Angle.g.cs @@ -224,6 +224,157 @@ public static Angle FromRadians(double radians) } + /// + /// Get nullable Angle from nullable Arcminutes. + /// + public static Angle? FromArcminutes(double? arcminutes) + { + if (arcminutes.HasValue) + { + return FromArcminutes(arcminutes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Angle from nullable Arcseconds. + /// + public static Angle? FromArcseconds(double? arcseconds) + { + if (arcseconds.HasValue) + { + return FromArcseconds(arcseconds.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Angle from nullable Centiradians. + /// + public static Angle? FromCentiradians(double? centiradians) + { + if (centiradians.HasValue) + { + return FromCentiradians(centiradians.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Angle from nullable Deciradians. + /// + public static Angle? FromDeciradians(double? deciradians) + { + if (deciradians.HasValue) + { + return FromDeciradians(deciradians.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Angle from nullable Degrees. + /// + public static Angle? FromDegrees(double? degrees) + { + if (degrees.HasValue) + { + return FromDegrees(degrees.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Angle from nullable Gradians. + /// + public static Angle? FromGradians(double? gradians) + { + if (gradians.HasValue) + { + return FromGradians(gradians.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Angle from nullable Microradians. + /// + public static Angle? FromMicroradians(double? microradians) + { + if (microradians.HasValue) + { + return FromMicroradians(microradians.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Angle from nullable Milliradians. + /// + public static Angle? FromMilliradians(double? milliradians) + { + if (milliradians.HasValue) + { + return FromMilliradians(milliradians.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Angle from nullable Nanoradians. + /// + public static Angle? FromNanoradians(double? nanoradians) + { + if (nanoradians.HasValue) + { + return FromNanoradians(nanoradians.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Angle from nullable Radians. + /// + public static Angle? FromRadians(double? radians) + { + if (radians.HasValue) + { + return FromRadians(radians.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -260,6 +411,46 @@ public static Angle From(double value, AngleUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Angle unit value. + public static Angle? From(double? value, AngleUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case AngleUnit.Arcminute: + return FromArcminutes(value.Value); + case AngleUnit.Arcsecond: + return FromArcseconds(value.Value); + case AngleUnit.Centiradian: + return FromCentiradians(value.Value); + case AngleUnit.Deciradian: + return FromDeciradians(value.Value); + case AngleUnit.Degree: + return FromDegrees(value.Value); + case AngleUnit.Gradian: + return FromGradians(value.Value); + case AngleUnit.Microradian: + return FromMicroradians(value.Value); + case AngleUnit.Milliradian: + return FromMilliradians(value.Value); + case AngleUnit.Nanoradian: + return FromNanoradians(value.Value); + case AngleUnit.Radian: + return FromRadians(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -431,14 +622,14 @@ public double As(AngleUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Angle Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Area.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Area.g.cs index 5cb78c55e1..ceef566ce3 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Area.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Area.g.cs @@ -224,6 +224,157 @@ public static Area FromSquareYards(double squareyards) } + /// + /// Get nullable Area from nullable SquareCentimeters. + /// + public static Area? FromSquareCentimeters(double? squarecentimeters) + { + if (squarecentimeters.HasValue) + { + return FromSquareCentimeters(squarecentimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Area from nullable SquareDecimeters. + /// + public static Area? FromSquareDecimeters(double? squaredecimeters) + { + if (squaredecimeters.HasValue) + { + return FromSquareDecimeters(squaredecimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Area from nullable SquareFeet. + /// + public static Area? FromSquareFeet(double? squarefeet) + { + if (squarefeet.HasValue) + { + return FromSquareFeet(squarefeet.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Area from nullable SquareInches. + /// + public static Area? FromSquareInches(double? squareinches) + { + if (squareinches.HasValue) + { + return FromSquareInches(squareinches.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Area from nullable SquareKilometers. + /// + public static Area? FromSquareKilometers(double? squarekilometers) + { + if (squarekilometers.HasValue) + { + return FromSquareKilometers(squarekilometers.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Area from nullable SquareMeters. + /// + public static Area? FromSquareMeters(double? squaremeters) + { + if (squaremeters.HasValue) + { + return FromSquareMeters(squaremeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Area from nullable SquareMicrometers. + /// + public static Area? FromSquareMicrometers(double? squaremicrometers) + { + if (squaremicrometers.HasValue) + { + return FromSquareMicrometers(squaremicrometers.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Area from nullable SquareMiles. + /// + public static Area? FromSquareMiles(double? squaremiles) + { + if (squaremiles.HasValue) + { + return FromSquareMiles(squaremiles.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Area from nullable SquareMillimeters. + /// + public static Area? FromSquareMillimeters(double? squaremillimeters) + { + if (squaremillimeters.HasValue) + { + return FromSquareMillimeters(squaremillimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Area from nullable SquareYards. + /// + public static Area? FromSquareYards(double? squareyards) + { + if (squareyards.HasValue) + { + return FromSquareYards(squareyards.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -260,6 +411,46 @@ public static Area From(double value, AreaUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Area unit value. + public static Area? From(double? value, AreaUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case AreaUnit.SquareCentimeter: + return FromSquareCentimeters(value.Value); + case AreaUnit.SquareDecimeter: + return FromSquareDecimeters(value.Value); + case AreaUnit.SquareFoot: + return FromSquareFeet(value.Value); + case AreaUnit.SquareInch: + return FromSquareInches(value.Value); + case AreaUnit.SquareKilometer: + return FromSquareKilometers(value.Value); + case AreaUnit.SquareMeter: + return FromSquareMeters(value.Value); + case AreaUnit.SquareMicrometer: + return FromSquareMicrometers(value.Value); + case AreaUnit.SquareMile: + return FromSquareMiles(value.Value); + case AreaUnit.SquareMillimeter: + return FromSquareMillimeters(value.Value); + case AreaUnit.SquareYard: + return FromSquareYards(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -431,14 +622,14 @@ public double As(AreaUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Area Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Density.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Density.g.cs index 4c8181addb..63fe1504f5 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Density.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Density.g.cs @@ -224,6 +224,157 @@ public static Density FromTonnesPerCubicMillimeter(double tonnespercubicmillimet } + /// + /// Get nullable Density from nullable KilogramsPerCubicCentimeter. + /// + public static Density? FromKilogramsPerCubicCentimeter(double? kilogramspercubiccentimeter) + { + if (kilogramspercubiccentimeter.HasValue) + { + return FromKilogramsPerCubicCentimeter(kilogramspercubiccentimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Density from nullable KilogramsPerCubicMeter. + /// + public static Density? FromKilogramsPerCubicMeter(double? kilogramspercubicmeter) + { + if (kilogramspercubicmeter.HasValue) + { + return FromKilogramsPerCubicMeter(kilogramspercubicmeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Density from nullable KilogramsPerCubicMillimeter. + /// + public static Density? FromKilogramsPerCubicMillimeter(double? kilogramspercubicmillimeter) + { + if (kilogramspercubicmillimeter.HasValue) + { + return FromKilogramsPerCubicMillimeter(kilogramspercubicmillimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Density from nullable KilopoundsPerCubicFoot. + /// + public static Density? FromKilopoundsPerCubicFoot(double? kilopoundspercubicfoot) + { + if (kilopoundspercubicfoot.HasValue) + { + return FromKilopoundsPerCubicFoot(kilopoundspercubicfoot.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Density from nullable KilopoundsPerCubicInch. + /// + public static Density? FromKilopoundsPerCubicInch(double? kilopoundspercubicinch) + { + if (kilopoundspercubicinch.HasValue) + { + return FromKilopoundsPerCubicInch(kilopoundspercubicinch.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Density from nullable PoundsPerCubicFoot. + /// + public static Density? FromPoundsPerCubicFoot(double? poundspercubicfoot) + { + if (poundspercubicfoot.HasValue) + { + return FromPoundsPerCubicFoot(poundspercubicfoot.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Density from nullable PoundsPerCubicInch. + /// + public static Density? FromPoundsPerCubicInch(double? poundspercubicinch) + { + if (poundspercubicinch.HasValue) + { + return FromPoundsPerCubicInch(poundspercubicinch.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Density from nullable TonnesPerCubicCentimeter. + /// + public static Density? FromTonnesPerCubicCentimeter(double? tonnespercubiccentimeter) + { + if (tonnespercubiccentimeter.HasValue) + { + return FromTonnesPerCubicCentimeter(tonnespercubiccentimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Density from nullable TonnesPerCubicMeter. + /// + public static Density? FromTonnesPerCubicMeter(double? tonnespercubicmeter) + { + if (tonnespercubicmeter.HasValue) + { + return FromTonnesPerCubicMeter(tonnespercubicmeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Density from nullable TonnesPerCubicMillimeter. + /// + public static Density? FromTonnesPerCubicMillimeter(double? tonnespercubicmillimeter) + { + if (tonnespercubicmillimeter.HasValue) + { + return FromTonnesPerCubicMillimeter(tonnespercubicmillimeter.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -260,6 +411,46 @@ public static Density From(double value, DensityUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Density unit value. + public static Density? From(double? value, DensityUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case DensityUnit.KilogramPerCubicCentimeter: + return FromKilogramsPerCubicCentimeter(value.Value); + case DensityUnit.KilogramPerCubicMeter: + return FromKilogramsPerCubicMeter(value.Value); + case DensityUnit.KilogramPerCubicMillimeter: + return FromKilogramsPerCubicMillimeter(value.Value); + case DensityUnit.KilopoundPerCubicFoot: + return FromKilopoundsPerCubicFoot(value.Value); + case DensityUnit.KilopoundPerCubicInch: + return FromKilopoundsPerCubicInch(value.Value); + case DensityUnit.PoundPerCubicFoot: + return FromPoundsPerCubicFoot(value.Value); + case DensityUnit.PoundPerCubicInch: + return FromPoundsPerCubicInch(value.Value); + case DensityUnit.TonnePerCubicCentimeter: + return FromTonnesPerCubicCentimeter(value.Value); + case DensityUnit.TonnePerCubicMeter: + return FromTonnesPerCubicMeter(value.Value); + case DensityUnit.TonnePerCubicMillimeter: + return FromTonnesPerCubicMillimeter(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -431,14 +622,14 @@ public double As(DensityUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Density Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Duration.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Duration.g.cs index 12edc70311..c61a489418 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Duration.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Duration.g.cs @@ -224,6 +224,157 @@ public static Duration FromYears(double years) } + /// + /// Get nullable Duration from nullable Days. + /// + public static Duration? FromDays(double? days) + { + if (days.HasValue) + { + return FromDays(days.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Duration from nullable Hours. + /// + public static Duration? FromHours(double? hours) + { + if (hours.HasValue) + { + return FromHours(hours.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Duration from nullable Microseconds. + /// + public static Duration? FromMicroseconds(double? microseconds) + { + if (microseconds.HasValue) + { + return FromMicroseconds(microseconds.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Duration from nullable Milliseconds. + /// + public static Duration? FromMilliseconds(double? milliseconds) + { + if (milliseconds.HasValue) + { + return FromMilliseconds(milliseconds.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Duration from nullable Minutes. + /// + public static Duration? FromMinutes(double? minutes) + { + if (minutes.HasValue) + { + return FromMinutes(minutes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Duration from nullable Months. + /// + public static Duration? FromMonths(double? months) + { + if (months.HasValue) + { + return FromMonths(months.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Duration from nullable Nanoseconds. + /// + public static Duration? FromNanoseconds(double? nanoseconds) + { + if (nanoseconds.HasValue) + { + return FromNanoseconds(nanoseconds.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Duration from nullable Seconds. + /// + public static Duration? FromSeconds(double? seconds) + { + if (seconds.HasValue) + { + return FromSeconds(seconds.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Duration from nullable Weeks. + /// + public static Duration? FromWeeks(double? weeks) + { + if (weeks.HasValue) + { + return FromWeeks(weeks.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Duration from nullable Years. + /// + public static Duration? FromYears(double? years) + { + if (years.HasValue) + { + return FromYears(years.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -260,6 +411,46 @@ public static Duration From(double value, DurationUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Duration unit value. + public static Duration? From(double? value, DurationUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case DurationUnit.Day: + return FromDays(value.Value); + case DurationUnit.Hour: + return FromHours(value.Value); + case DurationUnit.Microsecond: + return FromMicroseconds(value.Value); + case DurationUnit.Millisecond: + return FromMilliseconds(value.Value); + case DurationUnit.Minute: + return FromMinutes(value.Value); + case DurationUnit.Month: + return FromMonths(value.Value); + case DurationUnit.Nanosecond: + return FromNanoseconds(value.Value); + case DurationUnit.Second: + return FromSeconds(value.Value); + case DurationUnit.Week: + return FromWeeks(value.Value); + case DurationUnit.Year: + return FromYears(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -431,14 +622,14 @@ public double As(DurationUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Duration Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/DynamicViscosity.g.cs b/UnitsNet/GeneratedCode/UnitClasses/DynamicViscosity.g.cs index e64dcbc49b..20b001055a 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/DynamicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/DynamicViscosity.g.cs @@ -144,6 +144,82 @@ public static DynamicViscosity FromPoise(double poise) } + /// + /// Get nullable DynamicViscosity from nullable Centipoise. + /// + public static DynamicViscosity? FromCentipoise(double? centipoise) + { + if (centipoise.HasValue) + { + return FromCentipoise(centipoise.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable DynamicViscosity from nullable MillipascalSeconds. + /// + public static DynamicViscosity? FromMillipascalSeconds(double? millipascalseconds) + { + if (millipascalseconds.HasValue) + { + return FromMillipascalSeconds(millipascalseconds.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable DynamicViscosity from nullable NewtonSecondsPerMeterSquared. + /// + public static DynamicViscosity? FromNewtonSecondsPerMeterSquared(double? newtonsecondspermetersquared) + { + if (newtonsecondspermetersquared.HasValue) + { + return FromNewtonSecondsPerMeterSquared(newtonsecondspermetersquared.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable DynamicViscosity from nullable PascalSeconds. + /// + public static DynamicViscosity? FromPascalSeconds(double? pascalseconds) + { + if (pascalseconds.HasValue) + { + return FromPascalSeconds(pascalseconds.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable DynamicViscosity from nullable Poise. + /// + public static DynamicViscosity? FromPoise(double? poise) + { + if (poise.HasValue) + { + return FromPoise(poise.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -170,6 +246,36 @@ public static DynamicViscosity From(double value, DynamicViscosityUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// DynamicViscosity unit value. + public static DynamicViscosity? From(double? value, DynamicViscosityUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case DynamicViscosityUnit.Centipoise: + return FromCentipoise(value.Value); + case DynamicViscosityUnit.MillipascalSecond: + return FromMillipascalSeconds(value.Value); + case DynamicViscosityUnit.NewtonSecondPerMeterSquared: + return FromNewtonSecondsPerMeterSquared(value.Value); + case DynamicViscosityUnit.PascalSecond: + return FromPascalSeconds(value.Value); + case DynamicViscosityUnit.Poise: + return FromPoise(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -331,14 +437,14 @@ public double As(DynamicViscosityUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static DynamicViscosity Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/ElectricCurrent.g.cs b/UnitsNet/GeneratedCode/UnitClasses/ElectricCurrent.g.cs index c0fa48fdea..57528f0206 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/ElectricCurrent.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/ElectricCurrent.g.cs @@ -160,6 +160,97 @@ public static ElectricCurrent FromNanoamperes(double nanoamperes) } + /// + /// Get nullable ElectricCurrent from nullable Amperes. + /// + public static ElectricCurrent? FromAmperes(double? amperes) + { + if (amperes.HasValue) + { + return FromAmperes(amperes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricCurrent from nullable Kiloamperes. + /// + public static ElectricCurrent? FromKiloamperes(double? kiloamperes) + { + if (kiloamperes.HasValue) + { + return FromKiloamperes(kiloamperes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricCurrent from nullable Megaamperes. + /// + public static ElectricCurrent? FromMegaamperes(double? megaamperes) + { + if (megaamperes.HasValue) + { + return FromMegaamperes(megaamperes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricCurrent from nullable Microamperes. + /// + public static ElectricCurrent? FromMicroamperes(double? microamperes) + { + if (microamperes.HasValue) + { + return FromMicroamperes(microamperes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricCurrent from nullable Milliamperes. + /// + public static ElectricCurrent? FromMilliamperes(double? milliamperes) + { + if (milliamperes.HasValue) + { + return FromMilliamperes(milliamperes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricCurrent from nullable Nanoamperes. + /// + public static ElectricCurrent? FromNanoamperes(double? nanoamperes) + { + if (nanoamperes.HasValue) + { + return FromNanoamperes(nanoamperes.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -188,6 +279,38 @@ public static ElectricCurrent From(double value, ElectricCurrentUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricCurrent unit value. + public static ElectricCurrent? From(double? value, ElectricCurrentUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case ElectricCurrentUnit.Ampere: + return FromAmperes(value.Value); + case ElectricCurrentUnit.Kiloampere: + return FromKiloamperes(value.Value); + case ElectricCurrentUnit.Megaampere: + return FromMegaamperes(value.Value); + case ElectricCurrentUnit.Microampere: + return FromMicroamperes(value.Value); + case ElectricCurrentUnit.Milliampere: + return FromMilliamperes(value.Value); + case ElectricCurrentUnit.Nanoampere: + return FromNanoamperes(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -351,14 +474,14 @@ public double As(ElectricCurrentUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static ElectricCurrent Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/ElectricPotential.g.cs b/UnitsNet/GeneratedCode/UnitClasses/ElectricPotential.g.cs index e90ee4b000..5969775fa5 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/ElectricPotential.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/ElectricPotential.g.cs @@ -144,6 +144,82 @@ public static ElectricPotential FromVolts(double volts) } + /// + /// Get nullable ElectricPotential from nullable Kilovolts. + /// + public static ElectricPotential? FromKilovolts(double? kilovolts) + { + if (kilovolts.HasValue) + { + return FromKilovolts(kilovolts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricPotential from nullable Megavolts. + /// + public static ElectricPotential? FromMegavolts(double? megavolts) + { + if (megavolts.HasValue) + { + return FromMegavolts(megavolts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricPotential from nullable Microvolts. + /// + public static ElectricPotential? FromMicrovolts(double? microvolts) + { + if (microvolts.HasValue) + { + return FromMicrovolts(microvolts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricPotential from nullable Millivolts. + /// + public static ElectricPotential? FromMillivolts(double? millivolts) + { + if (millivolts.HasValue) + { + return FromMillivolts(millivolts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricPotential from nullable Volts. + /// + public static ElectricPotential? FromVolts(double? volts) + { + if (volts.HasValue) + { + return FromVolts(volts.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -170,6 +246,36 @@ public static ElectricPotential From(double value, ElectricPotentialUnit fromUni } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricPotential unit value. + public static ElectricPotential? From(double? value, ElectricPotentialUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case ElectricPotentialUnit.Kilovolt: + return FromKilovolts(value.Value); + case ElectricPotentialUnit.Megavolt: + return FromMegavolts(value.Value); + case ElectricPotentialUnit.Microvolt: + return FromMicrovolts(value.Value); + case ElectricPotentialUnit.Millivolt: + return FromMillivolts(value.Value); + case ElectricPotentialUnit.Volt: + return FromVolts(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -331,14 +437,14 @@ public double As(ElectricPotentialUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static ElectricPotential Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/ElectricResistance.g.cs b/UnitsNet/GeneratedCode/UnitClasses/ElectricResistance.g.cs index 75fcdf4d2d..812fac2ee6 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/ElectricResistance.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/ElectricResistance.g.cs @@ -112,6 +112,52 @@ public static ElectricResistance FromOhms(double ohms) } + /// + /// Get nullable ElectricResistance from nullable Kiloohms. + /// + public static ElectricResistance? FromKiloohms(double? kiloohms) + { + if (kiloohms.HasValue) + { + return FromKiloohms(kiloohms.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricResistance from nullable Megaohms. + /// + public static ElectricResistance? FromMegaohms(double? megaohms) + { + if (megaohms.HasValue) + { + return FromMegaohms(megaohms.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable ElectricResistance from nullable Ohms. + /// + public static ElectricResistance? FromOhms(double? ohms) + { + if (ohms.HasValue) + { + return FromOhms(ohms.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -134,6 +180,32 @@ public static ElectricResistance From(double value, ElectricResistanceUnit fromU } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ElectricResistance unit value. + public static ElectricResistance? From(double? value, ElectricResistanceUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case ElectricResistanceUnit.Kiloohm: + return FromKiloohms(value.Value); + case ElectricResistanceUnit.Megaohm: + return FromMegaohms(value.Value); + case ElectricResistanceUnit.Ohm: + return FromOhms(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -291,14 +363,14 @@ public double As(ElectricResistanceUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static ElectricResistance Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Energy.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Energy.g.cs index adff0909e5..85f2a9c87f 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Energy.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Energy.g.cs @@ -272,6 +272,202 @@ public static Energy FromWattHours(double watthours) } + /// + /// Get nullable Energy from nullable BritishThermalUnits. + /// + public static Energy? FromBritishThermalUnits(double? britishthermalunits) + { + if (britishthermalunits.HasValue) + { + return FromBritishThermalUnits(britishthermalunits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable Calories. + /// + public static Energy? FromCalories(double? calories) + { + if (calories.HasValue) + { + return FromCalories(calories.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable ElectronVolts. + /// + public static Energy? FromElectronVolts(double? electronvolts) + { + if (electronvolts.HasValue) + { + return FromElectronVolts(electronvolts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable Ergs. + /// + public static Energy? FromErgs(double? ergs) + { + if (ergs.HasValue) + { + return FromErgs(ergs.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable FootPounds. + /// + public static Energy? FromFootPounds(double? footpounds) + { + if (footpounds.HasValue) + { + return FromFootPounds(footpounds.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable GigawattHours. + /// + public static Energy? FromGigawattHours(double? gigawatthours) + { + if (gigawatthours.HasValue) + { + return FromGigawattHours(gigawatthours.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable Joules. + /// + public static Energy? FromJoules(double? joules) + { + if (joules.HasValue) + { + return FromJoules(joules.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable Kilocalories. + /// + public static Energy? FromKilocalories(double? kilocalories) + { + if (kilocalories.HasValue) + { + return FromKilocalories(kilocalories.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable Kilojoules. + /// + public static Energy? FromKilojoules(double? kilojoules) + { + if (kilojoules.HasValue) + { + return FromKilojoules(kilojoules.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable KilowattHours. + /// + public static Energy? FromKilowattHours(double? kilowatthours) + { + if (kilowatthours.HasValue) + { + return FromKilowattHours(kilowatthours.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable Megajoules. + /// + public static Energy? FromMegajoules(double? megajoules) + { + if (megajoules.HasValue) + { + return FromMegajoules(megajoules.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable MegawattHours. + /// + public static Energy? FromMegawattHours(double? megawatthours) + { + if (megawatthours.HasValue) + { + return FromMegawattHours(megawatthours.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Energy from nullable WattHours. + /// + public static Energy? FromWattHours(double? watthours) + { + if (watthours.HasValue) + { + return FromWattHours(watthours.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -314,6 +510,52 @@ public static Energy From(double value, EnergyUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Energy unit value. + public static Energy? From(double? value, EnergyUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case EnergyUnit.BritishThermalUnit: + return FromBritishThermalUnits(value.Value); + case EnergyUnit.Calorie: + return FromCalories(value.Value); + case EnergyUnit.ElectronVolt: + return FromElectronVolts(value.Value); + case EnergyUnit.Erg: + return FromErgs(value.Value); + case EnergyUnit.FootPound: + return FromFootPounds(value.Value); + case EnergyUnit.GigawattHour: + return FromGigawattHours(value.Value); + case EnergyUnit.Joule: + return FromJoules(value.Value); + case EnergyUnit.Kilocalorie: + return FromKilocalories(value.Value); + case EnergyUnit.Kilojoule: + return FromKilojoules(value.Value); + case EnergyUnit.KilowattHour: + return FromKilowattHours(value.Value); + case EnergyUnit.Megajoule: + return FromMegajoules(value.Value); + case EnergyUnit.MegawattHour: + return FromMegawattHours(value.Value); + case EnergyUnit.WattHour: + return FromWattHours(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -491,14 +733,14 @@ public double As(EnergyUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Energy Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Flow.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Flow.g.cs index c174e41f5f..be2d15704b 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Flow.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Flow.g.cs @@ -160,6 +160,97 @@ public static Flow FromUsGallonsPerMinute(double usgallonsperminute) } + /// + /// Get nullable Flow from nullable CubicFeetPerSecond. + /// + public static Flow? FromCubicFeetPerSecond(double? cubicfeetpersecond) + { + if (cubicfeetpersecond.HasValue) + { + return FromCubicFeetPerSecond(cubicfeetpersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Flow from nullable CubicMetersPerHour. + /// + public static Flow? FromCubicMetersPerHour(double? cubicmetersperhour) + { + if (cubicmetersperhour.HasValue) + { + return FromCubicMetersPerHour(cubicmetersperhour.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Flow from nullable CubicMetersPerSecond. + /// + public static Flow? FromCubicMetersPerSecond(double? cubicmeterspersecond) + { + if (cubicmeterspersecond.HasValue) + { + return FromCubicMetersPerSecond(cubicmeterspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Flow from nullable LitersPerMinute. + /// + public static Flow? FromLitersPerMinute(double? litersperminute) + { + if (litersperminute.HasValue) + { + return FromLitersPerMinute(litersperminute.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Flow from nullable MillionUsGallonsPerDay. + /// + public static Flow? FromMillionUsGallonsPerDay(double? millionusgallonsperday) + { + if (millionusgallonsperday.HasValue) + { + return FromMillionUsGallonsPerDay(millionusgallonsperday.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Flow from nullable UsGallonsPerMinute. + /// + public static Flow? FromUsGallonsPerMinute(double? usgallonsperminute) + { + if (usgallonsperminute.HasValue) + { + return FromUsGallonsPerMinute(usgallonsperminute.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -188,6 +279,38 @@ public static Flow From(double value, FlowUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Flow unit value. + public static Flow? From(double? value, FlowUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case FlowUnit.CubicFootPerSecond: + return FromCubicFeetPerSecond(value.Value); + case FlowUnit.CubicMeterPerHour: + return FromCubicMetersPerHour(value.Value); + case FlowUnit.CubicMeterPerSecond: + return FromCubicMetersPerSecond(value.Value); + case FlowUnit.LitersPerMinute: + return FromLitersPerMinute(value.Value); + case FlowUnit.MillionUsGallonsPerDay: + return FromMillionUsGallonsPerDay(value.Value); + case FlowUnit.UsGallonsPerMinute: + return FromUsGallonsPerMinute(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -351,14 +474,14 @@ public double As(FlowUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Flow Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Force.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Force.g.cs index b88727b337..b9af6953be 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Force.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Force.g.cs @@ -192,6 +192,127 @@ public static Force FromTonnesForce(double tonnesforce) } + /// + /// Get nullable Force from nullable Dyne. + /// + public static Force? FromDyne(double? dyne) + { + if (dyne.HasValue) + { + return FromDyne(dyne.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Force from nullable KilogramsForce. + /// + public static Force? FromKilogramsForce(double? kilogramsforce) + { + if (kilogramsforce.HasValue) + { + return FromKilogramsForce(kilogramsforce.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Force from nullable Kilonewtons. + /// + public static Force? FromKilonewtons(double? kilonewtons) + { + if (kilonewtons.HasValue) + { + return FromKilonewtons(kilonewtons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Force from nullable KiloPonds. + /// + public static Force? FromKiloPonds(double? kiloponds) + { + if (kiloponds.HasValue) + { + return FromKiloPonds(kiloponds.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Force from nullable Newtons. + /// + public static Force? FromNewtons(double? newtons) + { + if (newtons.HasValue) + { + return FromNewtons(newtons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Force from nullable Poundals. + /// + public static Force? FromPoundals(double? poundals) + { + if (poundals.HasValue) + { + return FromPoundals(poundals.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Force from nullable PoundsForce. + /// + public static Force? FromPoundsForce(double? poundsforce) + { + if (poundsforce.HasValue) + { + return FromPoundsForce(poundsforce.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Force from nullable TonnesForce. + /// + public static Force? FromTonnesForce(double? tonnesforce) + { + if (tonnesforce.HasValue) + { + return FromTonnesForce(tonnesforce.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -224,6 +345,42 @@ public static Force From(double value, ForceUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Force unit value. + public static Force? From(double? value, ForceUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case ForceUnit.Dyn: + return FromDyne(value.Value); + case ForceUnit.KilogramForce: + return FromKilogramsForce(value.Value); + case ForceUnit.Kilonewton: + return FromKilonewtons(value.Value); + case ForceUnit.KiloPond: + return FromKiloPonds(value.Value); + case ForceUnit.Newton: + return FromNewtons(value.Value); + case ForceUnit.Poundal: + return FromPoundals(value.Value); + case ForceUnit.PoundForce: + return FromPoundsForce(value.Value); + case ForceUnit.TonneForce: + return FromTonnesForce(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -391,14 +548,14 @@ public double As(ForceUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Force Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/ForceChangeRate.g.cs b/UnitsNet/GeneratedCode/UnitClasses/ForceChangeRate.g.cs index 3fec0d7ad0..8c1adf8ef1 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/ForceChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/ForceChangeRate.g.cs @@ -80,6 +80,22 @@ public static ForceChangeRate FromNewtonsPerSecond(double newtonspersecond) } + /// + /// Get nullable ForceChangeRate from nullable NewtonsPerSecond. + /// + public static ForceChangeRate? FromNewtonsPerSecond(double? newtonspersecond) + { + if (newtonspersecond.HasValue) + { + return FromNewtonsPerSecond(newtonspersecond.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -98,6 +114,28 @@ public static ForceChangeRate From(double value, ForceChangeRateUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// ForceChangeRate unit value. + public static ForceChangeRate? From(double? value, ForceChangeRateUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case ForceChangeRateUnit.NewtonPerSecond: + return FromNewtonsPerSecond(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -251,14 +289,14 @@ public double As(ForceChangeRateUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static ForceChangeRate Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Frequency.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Frequency.g.cs index b15c2e4552..c72c7fbd88 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Frequency.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Frequency.g.cs @@ -192,6 +192,127 @@ public static Frequency FromTerahertz(double terahertz) } + /// + /// Get nullable Frequency from nullable CyclesPerHour. + /// + public static Frequency? FromCyclesPerHour(double? cyclesperhour) + { + if (cyclesperhour.HasValue) + { + return FromCyclesPerHour(cyclesperhour.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Frequency from nullable CyclesPerMinute. + /// + public static Frequency? FromCyclesPerMinute(double? cyclesperminute) + { + if (cyclesperminute.HasValue) + { + return FromCyclesPerMinute(cyclesperminute.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Frequency from nullable Gigahertz. + /// + public static Frequency? FromGigahertz(double? gigahertz) + { + if (gigahertz.HasValue) + { + return FromGigahertz(gigahertz.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Frequency from nullable Hertz. + /// + public static Frequency? FromHertz(double? hertz) + { + if (hertz.HasValue) + { + return FromHertz(hertz.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Frequency from nullable Kilohertz. + /// + public static Frequency? FromKilohertz(double? kilohertz) + { + if (kilohertz.HasValue) + { + return FromKilohertz(kilohertz.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Frequency from nullable Megahertz. + /// + public static Frequency? FromMegahertz(double? megahertz) + { + if (megahertz.HasValue) + { + return FromMegahertz(megahertz.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Frequency from nullable RadiansPerSecond. + /// + public static Frequency? FromRadiansPerSecond(double? radianspersecond) + { + if (radianspersecond.HasValue) + { + return FromRadiansPerSecond(radianspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Frequency from nullable Terahertz. + /// + public static Frequency? FromTerahertz(double? terahertz) + { + if (terahertz.HasValue) + { + return FromTerahertz(terahertz.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -224,6 +345,42 @@ public static Frequency From(double value, FrequencyUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Frequency unit value. + public static Frequency? From(double? value, FrequencyUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case FrequencyUnit.CyclePerHour: + return FromCyclesPerHour(value.Value); + case FrequencyUnit.CyclePerMinute: + return FromCyclesPerMinute(value.Value); + case FrequencyUnit.Gigahertz: + return FromGigahertz(value.Value); + case FrequencyUnit.Hertz: + return FromHertz(value.Value); + case FrequencyUnit.Kilohertz: + return FromKilohertz(value.Value); + case FrequencyUnit.Megahertz: + return FromMegahertz(value.Value); + case FrequencyUnit.RadianPerSecond: + return FromRadiansPerSecond(value.Value); + case FrequencyUnit.Terahertz: + return FromTerahertz(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -391,14 +548,14 @@ public double As(FrequencyUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Frequency Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Information.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Information.g.cs index 2db1dc55cc..b1226d22b2 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Information.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Information.g.cs @@ -480,6 +480,397 @@ public static Information FromTerabytes(double terabytes) } + /// + /// Get nullable Information from nullable Bits. + /// + public static Information? FromBits(double? bits) + { + if (bits.HasValue) + { + return FromBits(bits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Bytes. + /// + public static Information? FromBytes(double? bytes) + { + if (bytes.HasValue) + { + return FromBytes(bytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Exabits. + /// + public static Information? FromExabits(double? exabits) + { + if (exabits.HasValue) + { + return FromExabits(exabits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Exabytes. + /// + public static Information? FromExabytes(double? exabytes) + { + if (exabytes.HasValue) + { + return FromExabytes(exabytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Exbibits. + /// + public static Information? FromExbibits(double? exbibits) + { + if (exbibits.HasValue) + { + return FromExbibits(exbibits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Exbibytes. + /// + public static Information? FromExbibytes(double? exbibytes) + { + if (exbibytes.HasValue) + { + return FromExbibytes(exbibytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Gibibits. + /// + public static Information? FromGibibits(double? gibibits) + { + if (gibibits.HasValue) + { + return FromGibibits(gibibits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Gibibytes. + /// + public static Information? FromGibibytes(double? gibibytes) + { + if (gibibytes.HasValue) + { + return FromGibibytes(gibibytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Gigabits. + /// + public static Information? FromGigabits(double? gigabits) + { + if (gigabits.HasValue) + { + return FromGigabits(gigabits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Gigabytes. + /// + public static Information? FromGigabytes(double? gigabytes) + { + if (gigabytes.HasValue) + { + return FromGigabytes(gigabytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Kibibits. + /// + public static Information? FromKibibits(double? kibibits) + { + if (kibibits.HasValue) + { + return FromKibibits(kibibits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Kibibytes. + /// + public static Information? FromKibibytes(double? kibibytes) + { + if (kibibytes.HasValue) + { + return FromKibibytes(kibibytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Kilobits. + /// + public static Information? FromKilobits(double? kilobits) + { + if (kilobits.HasValue) + { + return FromKilobits(kilobits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Kilobytes. + /// + public static Information? FromKilobytes(double? kilobytes) + { + if (kilobytes.HasValue) + { + return FromKilobytes(kilobytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Mebibits. + /// + public static Information? FromMebibits(double? mebibits) + { + if (mebibits.HasValue) + { + return FromMebibits(mebibits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Mebibytes. + /// + public static Information? FromMebibytes(double? mebibytes) + { + if (mebibytes.HasValue) + { + return FromMebibytes(mebibytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Megabits. + /// + public static Information? FromMegabits(double? megabits) + { + if (megabits.HasValue) + { + return FromMegabits(megabits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Megabytes. + /// + public static Information? FromMegabytes(double? megabytes) + { + if (megabytes.HasValue) + { + return FromMegabytes(megabytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Pebibits. + /// + public static Information? FromPebibits(double? pebibits) + { + if (pebibits.HasValue) + { + return FromPebibits(pebibits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Pebibytes. + /// + public static Information? FromPebibytes(double? pebibytes) + { + if (pebibytes.HasValue) + { + return FromPebibytes(pebibytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Petabits. + /// + public static Information? FromPetabits(double? petabits) + { + if (petabits.HasValue) + { + return FromPetabits(petabits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Petabytes. + /// + public static Information? FromPetabytes(double? petabytes) + { + if (petabytes.HasValue) + { + return FromPetabytes(petabytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Tebibits. + /// + public static Information? FromTebibits(double? tebibits) + { + if (tebibits.HasValue) + { + return FromTebibits(tebibits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Tebibytes. + /// + public static Information? FromTebibytes(double? tebibytes) + { + if (tebibytes.HasValue) + { + return FromTebibytes(tebibytes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Terabits. + /// + public static Information? FromTerabits(double? terabits) + { + if (terabits.HasValue) + { + return FromTerabits(terabits.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Information from nullable Terabytes. + /// + public static Information? FromTerabytes(double? terabytes) + { + if (terabytes.HasValue) + { + return FromTerabytes(terabytes.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -548,6 +939,78 @@ public static Information From(double value, InformationUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Information unit value. + public static Information? From(double? value, InformationUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case InformationUnit.Bit: + return FromBits(value.Value); + case InformationUnit.Byte: + return FromBytes(value.Value); + case InformationUnit.Exabit: + return FromExabits(value.Value); + case InformationUnit.Exabyte: + return FromExabytes(value.Value); + case InformationUnit.Exbibit: + return FromExbibits(value.Value); + case InformationUnit.Exbibyte: + return FromExbibytes(value.Value); + case InformationUnit.Gibibit: + return FromGibibits(value.Value); + case InformationUnit.Gibibyte: + return FromGibibytes(value.Value); + case InformationUnit.Gigabit: + return FromGigabits(value.Value); + case InformationUnit.Gigabyte: + return FromGigabytes(value.Value); + case InformationUnit.Kibibit: + return FromKibibits(value.Value); + case InformationUnit.Kibibyte: + return FromKibibytes(value.Value); + case InformationUnit.Kilobit: + return FromKilobits(value.Value); + case InformationUnit.Kilobyte: + return FromKilobytes(value.Value); + case InformationUnit.Mebibit: + return FromMebibits(value.Value); + case InformationUnit.Mebibyte: + return FromMebibytes(value.Value); + case InformationUnit.Megabit: + return FromMegabits(value.Value); + case InformationUnit.Megabyte: + return FromMegabytes(value.Value); + case InformationUnit.Pebibit: + return FromPebibits(value.Value); + case InformationUnit.Pebibyte: + return FromPebibytes(value.Value); + case InformationUnit.Petabit: + return FromPetabits(value.Value); + case InformationUnit.Petabyte: + return FromPetabytes(value.Value); + case InformationUnit.Tebibit: + return FromTebibits(value.Value); + case InformationUnit.Tebibyte: + return FromTebibytes(value.Value); + case InformationUnit.Terabit: + return FromTerabits(value.Value); + case InformationUnit.Terabyte: + return FromTerabytes(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -751,14 +1214,14 @@ public double As(InformationUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Information Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/KinematicViscosity.g.cs b/UnitsNet/GeneratedCode/UnitClasses/KinematicViscosity.g.cs index 1cbb6a254b..0655861156 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/KinematicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/KinematicViscosity.g.cs @@ -192,6 +192,127 @@ public static KinematicViscosity FromStokes(double stokes) } + /// + /// Get nullable KinematicViscosity from nullable Centistokes. + /// + public static KinematicViscosity? FromCentistokes(double? centistokes) + { + if (centistokes.HasValue) + { + return FromCentistokes(centistokes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable KinematicViscosity from nullable Decistokes. + /// + public static KinematicViscosity? FromDecistokes(double? decistokes) + { + if (decistokes.HasValue) + { + return FromDecistokes(decistokes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable KinematicViscosity from nullable Kilostokes. + /// + public static KinematicViscosity? FromKilostokes(double? kilostokes) + { + if (kilostokes.HasValue) + { + return FromKilostokes(kilostokes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable KinematicViscosity from nullable Microstokes. + /// + public static KinematicViscosity? FromMicrostokes(double? microstokes) + { + if (microstokes.HasValue) + { + return FromMicrostokes(microstokes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable KinematicViscosity from nullable Millistokes. + /// + public static KinematicViscosity? FromMillistokes(double? millistokes) + { + if (millistokes.HasValue) + { + return FromMillistokes(millistokes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable KinematicViscosity from nullable Nanostokes. + /// + public static KinematicViscosity? FromNanostokes(double? nanostokes) + { + if (nanostokes.HasValue) + { + return FromNanostokes(nanostokes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable KinematicViscosity from nullable SquareMetersPerSecond. + /// + public static KinematicViscosity? FromSquareMetersPerSecond(double? squaremeterspersecond) + { + if (squaremeterspersecond.HasValue) + { + return FromSquareMetersPerSecond(squaremeterspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable KinematicViscosity from nullable Stokes. + /// + public static KinematicViscosity? FromStokes(double? stokes) + { + if (stokes.HasValue) + { + return FromStokes(stokes.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -224,6 +345,42 @@ public static KinematicViscosity From(double value, KinematicViscosityUnit fromU } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// KinematicViscosity unit value. + public static KinematicViscosity? From(double? value, KinematicViscosityUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case KinematicViscosityUnit.Centistokes: + return FromCentistokes(value.Value); + case KinematicViscosityUnit.Decistokes: + return FromDecistokes(value.Value); + case KinematicViscosityUnit.Kilostokes: + return FromKilostokes(value.Value); + case KinematicViscosityUnit.Microstokes: + return FromMicrostokes(value.Value); + case KinematicViscosityUnit.Millistokes: + return FromMillistokes(value.Value); + case KinematicViscosityUnit.Nanostokes: + return FromNanostokes(value.Value); + case KinematicViscosityUnit.SquareMeterPerSecond: + return FromSquareMetersPerSecond(value.Value); + case KinematicViscosityUnit.Stokes: + return FromStokes(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -391,14 +548,14 @@ public double As(KinematicViscosityUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static KinematicViscosity Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Length.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Length.g.cs index ce4bc8855a..6fad6c79da 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Length.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Length.g.cs @@ -288,6 +288,217 @@ public static Length FromYards(double yards) } + /// + /// Get nullable Length from nullable Centimeters. + /// + public static Length? FromCentimeters(double? centimeters) + { + if (centimeters.HasValue) + { + return FromCentimeters(centimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Decimeters. + /// + public static Length? FromDecimeters(double? decimeters) + { + if (decimeters.HasValue) + { + return FromDecimeters(decimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Feet. + /// + public static Length? FromFeet(double? feet) + { + if (feet.HasValue) + { + return FromFeet(feet.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Inches. + /// + public static Length? FromInches(double? inches) + { + if (inches.HasValue) + { + return FromInches(inches.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Kilometers. + /// + public static Length? FromKilometers(double? kilometers) + { + if (kilometers.HasValue) + { + return FromKilometers(kilometers.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Meters. + /// + public static Length? FromMeters(double? meters) + { + if (meters.HasValue) + { + return FromMeters(meters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Microinches. + /// + public static Length? FromMicroinches(double? microinches) + { + if (microinches.HasValue) + { + return FromMicroinches(microinches.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Micrometers. + /// + public static Length? FromMicrometers(double? micrometers) + { + if (micrometers.HasValue) + { + return FromMicrometers(micrometers.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Mils. + /// + public static Length? FromMils(double? mils) + { + if (mils.HasValue) + { + return FromMils(mils.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Miles. + /// + public static Length? FromMiles(double? miles) + { + if (miles.HasValue) + { + return FromMiles(miles.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Millimeters. + /// + public static Length? FromMillimeters(double? millimeters) + { + if (millimeters.HasValue) + { + return FromMillimeters(millimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Nanometers. + /// + public static Length? FromNanometers(double? nanometers) + { + if (nanometers.HasValue) + { + return FromNanometers(nanometers.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable NauticalMiles. + /// + public static Length? FromNauticalMiles(double? nauticalmiles) + { + if (nauticalmiles.HasValue) + { + return FromNauticalMiles(nauticalmiles.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Length from nullable Yards. + /// + public static Length? FromYards(double? yards) + { + if (yards.HasValue) + { + return FromYards(yards.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -332,6 +543,54 @@ public static Length From(double value, LengthUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Length unit value. + public static Length? From(double? value, LengthUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case LengthUnit.Centimeter: + return FromCentimeters(value.Value); + case LengthUnit.Decimeter: + return FromDecimeters(value.Value); + case LengthUnit.Foot: + return FromFeet(value.Value); + case LengthUnit.Inch: + return FromInches(value.Value); + case LengthUnit.Kilometer: + return FromKilometers(value.Value); + case LengthUnit.Meter: + return FromMeters(value.Value); + case LengthUnit.Microinch: + return FromMicroinches(value.Value); + case LengthUnit.Micrometer: + return FromMicrometers(value.Value); + case LengthUnit.Mil: + return FromMils(value.Value); + case LengthUnit.Mile: + return FromMiles(value.Value); + case LengthUnit.Millimeter: + return FromMillimeters(value.Value); + case LengthUnit.Nanometer: + return FromNanometers(value.Value); + case LengthUnit.NauticalMile: + return FromNauticalMiles(value.Value); + case LengthUnit.Yard: + return FromYards(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -511,14 +770,14 @@ public double As(LengthUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Length Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Level.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Level.g.cs index 885f091286..2f909295b8 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Level.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Level.g.cs @@ -96,6 +96,37 @@ public static Level FromNepers(double nepers) } + /// + /// Get nullable Level from nullable Decibels. + /// + public static Level? FromDecibels(double? decibels) + { + if (decibels.HasValue) + { + return FromDecibels(decibels.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Level from nullable Nepers. + /// + public static Level? FromNepers(double? nepers) + { + if (nepers.HasValue) + { + return FromNepers(nepers.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -116,6 +147,30 @@ public static Level From(double value, LevelUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Level unit value. + public static Level? From(double? value, LevelUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case LevelUnit.Decibel: + return FromDecibels(value.Value); + case LevelUnit.Neper: + return FromNepers(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -279,14 +334,14 @@ public double As(LevelUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Level Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Mass.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Mass.g.cs index e97964b3b8..da440d22ad 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Mass.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Mass.g.cs @@ -336,6 +336,262 @@ public static Mass FromTonnes(double tonnes) } + /// + /// Get nullable Mass from nullable Centigrams. + /// + public static Mass? FromCentigrams(double? centigrams) + { + if (centigrams.HasValue) + { + return FromCentigrams(centigrams.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Decagrams. + /// + public static Mass? FromDecagrams(double? decagrams) + { + if (decagrams.HasValue) + { + return FromDecagrams(decagrams.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Decigrams. + /// + public static Mass? FromDecigrams(double? decigrams) + { + if (decigrams.HasValue) + { + return FromDecigrams(decigrams.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Grams. + /// + public static Mass? FromGrams(double? grams) + { + if (grams.HasValue) + { + return FromGrams(grams.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Hectograms. + /// + public static Mass? FromHectograms(double? hectograms) + { + if (hectograms.HasValue) + { + return FromHectograms(hectograms.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Kilograms. + /// + public static Mass? FromKilograms(double? kilograms) + { + if (kilograms.HasValue) + { + return FromKilograms(kilograms.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Kilotonnes. + /// + public static Mass? FromKilotonnes(double? kilotonnes) + { + if (kilotonnes.HasValue) + { + return FromKilotonnes(kilotonnes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable LongTons. + /// + public static Mass? FromLongTons(double? longtons) + { + if (longtons.HasValue) + { + return FromLongTons(longtons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Megatonnes. + /// + public static Mass? FromMegatonnes(double? megatonnes) + { + if (megatonnes.HasValue) + { + return FromMegatonnes(megatonnes.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Micrograms. + /// + public static Mass? FromMicrograms(double? micrograms) + { + if (micrograms.HasValue) + { + return FromMicrograms(micrograms.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Milligrams. + /// + public static Mass? FromMilligrams(double? milligrams) + { + if (milligrams.HasValue) + { + return FromMilligrams(milligrams.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Nanograms. + /// + public static Mass? FromNanograms(double? nanograms) + { + if (nanograms.HasValue) + { + return FromNanograms(nanograms.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Ounces. + /// + public static Mass? FromOunces(double? ounces) + { + if (ounces.HasValue) + { + return FromOunces(ounces.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Pounds. + /// + public static Mass? FromPounds(double? pounds) + { + if (pounds.HasValue) + { + return FromPounds(pounds.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable ShortTons. + /// + public static Mass? FromShortTons(double? shorttons) + { + if (shorttons.HasValue) + { + return FromShortTons(shorttons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Stone. + /// + public static Mass? FromStone(double? stone) + { + if (stone.HasValue) + { + return FromStone(stone.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Mass from nullable Tonnes. + /// + public static Mass? FromTonnes(double? tonnes) + { + if (tonnes.HasValue) + { + return FromTonnes(tonnes.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -386,6 +642,60 @@ public static Mass From(double value, MassUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Mass unit value. + public static Mass? From(double? value, MassUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case MassUnit.Centigram: + return FromCentigrams(value.Value); + case MassUnit.Decagram: + return FromDecagrams(value.Value); + case MassUnit.Decigram: + return FromDecigrams(value.Value); + case MassUnit.Gram: + return FromGrams(value.Value); + case MassUnit.Hectogram: + return FromHectograms(value.Value); + case MassUnit.Kilogram: + return FromKilograms(value.Value); + case MassUnit.Kilotonne: + return FromKilotonnes(value.Value); + case MassUnit.LongTon: + return FromLongTons(value.Value); + case MassUnit.Megatonne: + return FromMegatonnes(value.Value); + case MassUnit.Microgram: + return FromMicrograms(value.Value); + case MassUnit.Milligram: + return FromMilligrams(value.Value); + case MassUnit.Nanogram: + return FromNanograms(value.Value); + case MassUnit.Ounce: + return FromOunces(value.Value); + case MassUnit.Pound: + return FromPounds(value.Value); + case MassUnit.ShortTon: + return FromShortTons(value.Value); + case MassUnit.Stone: + return FromStone(value.Value); + case MassUnit.Tonne: + return FromTonnes(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -571,14 +881,14 @@ public double As(MassUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Mass Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/MassFlow.g.cs b/UnitsNet/GeneratedCode/UnitClasses/MassFlow.g.cs index 56fbc5a073..3fc05f5646 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/MassFlow.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/MassFlow.g.cs @@ -224,6 +224,157 @@ public static MassFlow FromTonnesPerDay(double tonnesperday) } + /// + /// Get nullable MassFlow from nullable CentigramsPerSecond. + /// + public static MassFlow? FromCentigramsPerSecond(double? centigramspersecond) + { + if (centigramspersecond.HasValue) + { + return FromCentigramsPerSecond(centigramspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MassFlow from nullable DecagramsPerSecond. + /// + public static MassFlow? FromDecagramsPerSecond(double? decagramspersecond) + { + if (decagramspersecond.HasValue) + { + return FromDecagramsPerSecond(decagramspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MassFlow from nullable DecigramsPerSecond. + /// + public static MassFlow? FromDecigramsPerSecond(double? decigramspersecond) + { + if (decigramspersecond.HasValue) + { + return FromDecigramsPerSecond(decigramspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MassFlow from nullable GramsPerSecond. + /// + public static MassFlow? FromGramsPerSecond(double? gramspersecond) + { + if (gramspersecond.HasValue) + { + return FromGramsPerSecond(gramspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MassFlow from nullable HectogramsPerSecond. + /// + public static MassFlow? FromHectogramsPerSecond(double? hectogramspersecond) + { + if (hectogramspersecond.HasValue) + { + return FromHectogramsPerSecond(hectogramspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MassFlow from nullable KilogramsPerSecond. + /// + public static MassFlow? FromKilogramsPerSecond(double? kilogramspersecond) + { + if (kilogramspersecond.HasValue) + { + return FromKilogramsPerSecond(kilogramspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MassFlow from nullable MicrogramsPerSecond. + /// + public static MassFlow? FromMicrogramsPerSecond(double? microgramspersecond) + { + if (microgramspersecond.HasValue) + { + return FromMicrogramsPerSecond(microgramspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MassFlow from nullable MilligramsPerSecond. + /// + public static MassFlow? FromMilligramsPerSecond(double? milligramspersecond) + { + if (milligramspersecond.HasValue) + { + return FromMilligramsPerSecond(milligramspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MassFlow from nullable NanogramsPerSecond. + /// + public static MassFlow? FromNanogramsPerSecond(double? nanogramspersecond) + { + if (nanogramspersecond.HasValue) + { + return FromNanogramsPerSecond(nanogramspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MassFlow from nullable TonnesPerDay. + /// + public static MassFlow? FromTonnesPerDay(double? tonnesperday) + { + if (tonnesperday.HasValue) + { + return FromTonnesPerDay(tonnesperday.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -260,6 +411,46 @@ public static MassFlow From(double value, MassFlowUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// MassFlow unit value. + public static MassFlow? From(double? value, MassFlowUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case MassFlowUnit.CentigramPerSecond: + return FromCentigramsPerSecond(value.Value); + case MassFlowUnit.DecagramPerSecond: + return FromDecagramsPerSecond(value.Value); + case MassFlowUnit.DecigramPerSecond: + return FromDecigramsPerSecond(value.Value); + case MassFlowUnit.GramPerSecond: + return FromGramsPerSecond(value.Value); + case MassFlowUnit.HectogramPerSecond: + return FromHectogramsPerSecond(value.Value); + case MassFlowUnit.KilogramPerSecond: + return FromKilogramsPerSecond(value.Value); + case MassFlowUnit.MicrogramPerSecond: + return FromMicrogramsPerSecond(value.Value); + case MassFlowUnit.MilligramPerSecond: + return FromMilligramsPerSecond(value.Value); + case MassFlowUnit.NanogramPerSecond: + return FromNanogramsPerSecond(value.Value); + case MassFlowUnit.TonnePerDay: + return FromTonnesPerDay(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -431,14 +622,14 @@ public double As(MassFlowUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static MassFlow Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Power.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Power.g.cs index e5e7b67ab9..b43ad6e2e9 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Power.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Power.g.cs @@ -320,6 +320,247 @@ public static Power FromWatts(double watts) } + /// + /// Get nullable Power from nullable BoilerHorsepower. + /// + public static Power? FromBoilerHorsepower(double? boilerhorsepower) + { + if (boilerhorsepower.HasValue) + { + return FromBoilerHorsepower(boilerhorsepower.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable ElectricalHorsepower. + /// + public static Power? FromElectricalHorsepower(double? electricalhorsepower) + { + if (electricalhorsepower.HasValue) + { + return FromElectricalHorsepower(electricalhorsepower.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable Femtowatts. + /// + public static Power? FromFemtowatts(double? femtowatts) + { + if (femtowatts.HasValue) + { + return FromFemtowatts(femtowatts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable Gigawatts. + /// + public static Power? FromGigawatts(double? gigawatts) + { + if (gigawatts.HasValue) + { + return FromGigawatts(gigawatts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable HydraulicHorsepower. + /// + public static Power? FromHydraulicHorsepower(double? hydraulichorsepower) + { + if (hydraulichorsepower.HasValue) + { + return FromHydraulicHorsepower(hydraulichorsepower.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable Kilowatts. + /// + public static Power? FromKilowatts(double? kilowatts) + { + if (kilowatts.HasValue) + { + return FromKilowatts(kilowatts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable MechanicalHorsepower. + /// + public static Power? FromMechanicalHorsepower(double? mechanicalhorsepower) + { + if (mechanicalhorsepower.HasValue) + { + return FromMechanicalHorsepower(mechanicalhorsepower.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable Megawatts. + /// + public static Power? FromMegawatts(double? megawatts) + { + if (megawatts.HasValue) + { + return FromMegawatts(megawatts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable MetricHorsepower. + /// + public static Power? FromMetricHorsepower(double? metrichorsepower) + { + if (metrichorsepower.HasValue) + { + return FromMetricHorsepower(metrichorsepower.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable Microwatts. + /// + public static Power? FromMicrowatts(double? microwatts) + { + if (microwatts.HasValue) + { + return FromMicrowatts(microwatts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable Milliwatts. + /// + public static Power? FromMilliwatts(double? milliwatts) + { + if (milliwatts.HasValue) + { + return FromMilliwatts(milliwatts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable Nanowatts. + /// + public static Power? FromNanowatts(double? nanowatts) + { + if (nanowatts.HasValue) + { + return FromNanowatts(nanowatts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable Petawatts. + /// + public static Power? FromPetawatts(double? petawatts) + { + if (petawatts.HasValue) + { + return FromPetawatts(petawatts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable Picowatts. + /// + public static Power? FromPicowatts(double? picowatts) + { + if (picowatts.HasValue) + { + return FromPicowatts(picowatts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable Terawatts. + /// + public static Power? FromTerawatts(double? terawatts) + { + if (terawatts.HasValue) + { + return FromTerawatts(terawatts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Power from nullable Watts. + /// + public static Power? FromWatts(double? watts) + { + if (watts.HasValue) + { + return FromWatts(watts.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -368,6 +609,58 @@ public static Power From(double value, PowerUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Power unit value. + public static Power? From(double? value, PowerUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case PowerUnit.BoilerHorsepower: + return FromBoilerHorsepower(value.Value); + case PowerUnit.ElectricalHorsepower: + return FromElectricalHorsepower(value.Value); + case PowerUnit.Femtowatt: + return FromFemtowatts(value.Value); + case PowerUnit.Gigawatt: + return FromGigawatts(value.Value); + case PowerUnit.HydraulicHorsepower: + return FromHydraulicHorsepower(value.Value); + case PowerUnit.Kilowatt: + return FromKilowatts(value.Value); + case PowerUnit.MechanicalHorsepower: + return FromMechanicalHorsepower(value.Value); + case PowerUnit.Megawatt: + return FromMegawatts(value.Value); + case PowerUnit.MetricHorsepower: + return FromMetricHorsepower(value.Value); + case PowerUnit.Microwatt: + return FromMicrowatts(value.Value); + case PowerUnit.Milliwatt: + return FromMilliwatts(value.Value); + case PowerUnit.Nanowatt: + return FromNanowatts(value.Value); + case PowerUnit.Petawatt: + return FromPetawatts(value.Value); + case PowerUnit.Picowatt: + return FromPicowatts(value.Value); + case PowerUnit.Terawatt: + return FromTerawatts(value.Value); + case PowerUnit.Watt: + return FromWatts(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -551,14 +844,14 @@ public double As(PowerUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Power Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/PowerRatio.g.cs b/UnitsNet/GeneratedCode/UnitClasses/PowerRatio.g.cs index 0d29971640..b038e7785b 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/PowerRatio.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/PowerRatio.g.cs @@ -96,6 +96,37 @@ public static PowerRatio FromDecibelWatts(double decibelwatts) } + /// + /// Get nullable PowerRatio from nullable DecibelMilliwatts. + /// + public static PowerRatio? FromDecibelMilliwatts(double? decibelmilliwatts) + { + if (decibelmilliwatts.HasValue) + { + return FromDecibelMilliwatts(decibelmilliwatts.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable PowerRatio from nullable DecibelWatts. + /// + public static PowerRatio? FromDecibelWatts(double? decibelwatts) + { + if (decibelwatts.HasValue) + { + return FromDecibelWatts(decibelwatts.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -116,6 +147,30 @@ public static PowerRatio From(double value, PowerRatioUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// PowerRatio unit value. + public static PowerRatio? From(double? value, PowerRatioUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case PowerRatioUnit.DecibelMilliwatt: + return FromDecibelMilliwatts(value.Value); + case PowerRatioUnit.DecibelWatt: + return FromDecibelWatts(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -279,14 +334,14 @@ public double As(PowerRatioUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static PowerRatio Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Pressure.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Pressure.g.cs index 1b2f8f3cd1..55fa3cf395 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Pressure.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Pressure.g.cs @@ -592,6 +592,502 @@ public static Pressure FromTorrs(double torrs) } + /// + /// Get nullable Pressure from nullable Atmospheres. + /// + public static Pressure? FromAtmospheres(double? atmospheres) + { + if (atmospheres.HasValue) + { + return FromAtmospheres(atmospheres.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Bars. + /// + public static Pressure? FromBars(double? bars) + { + if (bars.HasValue) + { + return FromBars(bars.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Centibars. + /// + public static Pressure? FromCentibars(double? centibars) + { + if (centibars.HasValue) + { + return FromCentibars(centibars.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Decapascals. + /// + public static Pressure? FromDecapascals(double? decapascals) + { + if (decapascals.HasValue) + { + return FromDecapascals(decapascals.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Decibars. + /// + public static Pressure? FromDecibars(double? decibars) + { + if (decibars.HasValue) + { + return FromDecibars(decibars.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Gigapascals. + /// + public static Pressure? FromGigapascals(double? gigapascals) + { + if (gigapascals.HasValue) + { + return FromGigapascals(gigapascals.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Hectopascals. + /// + public static Pressure? FromHectopascals(double? hectopascals) + { + if (hectopascals.HasValue) + { + return FromHectopascals(hectopascals.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Kilobars. + /// + public static Pressure? FromKilobars(double? kilobars) + { + if (kilobars.HasValue) + { + return FromKilobars(kilobars.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable KilogramsForcePerSquareCentimeter. + /// + public static Pressure? FromKilogramsForcePerSquareCentimeter(double? kilogramsforcepersquarecentimeter) + { + if (kilogramsforcepersquarecentimeter.HasValue) + { + return FromKilogramsForcePerSquareCentimeter(kilogramsforcepersquarecentimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable KilogramsForcePerSquareMeter. + /// + public static Pressure? FromKilogramsForcePerSquareMeter(double? kilogramsforcepersquaremeter) + { + if (kilogramsforcepersquaremeter.HasValue) + { + return FromKilogramsForcePerSquareMeter(kilogramsforcepersquaremeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable KilogramsForcePerSquareMillimeter. + /// + public static Pressure? FromKilogramsForcePerSquareMillimeter(double? kilogramsforcepersquaremillimeter) + { + if (kilogramsforcepersquaremillimeter.HasValue) + { + return FromKilogramsForcePerSquareMillimeter(kilogramsforcepersquaremillimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable KilonewtonsPerSquareCentimeter. + /// + public static Pressure? FromKilonewtonsPerSquareCentimeter(double? kilonewtonspersquarecentimeter) + { + if (kilonewtonspersquarecentimeter.HasValue) + { + return FromKilonewtonsPerSquareCentimeter(kilonewtonspersquarecentimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable KilonewtonsPerSquareMeter. + /// + public static Pressure? FromKilonewtonsPerSquareMeter(double? kilonewtonspersquaremeter) + { + if (kilonewtonspersquaremeter.HasValue) + { + return FromKilonewtonsPerSquareMeter(kilonewtonspersquaremeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable KilonewtonsPerSquareMillimeter. + /// + public static Pressure? FromKilonewtonsPerSquareMillimeter(double? kilonewtonspersquaremillimeter) + { + if (kilonewtonspersquaremillimeter.HasValue) + { + return FromKilonewtonsPerSquareMillimeter(kilonewtonspersquaremillimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Kilopascals. + /// + public static Pressure? FromKilopascals(double? kilopascals) + { + if (kilopascals.HasValue) + { + return FromKilopascals(kilopascals.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable KilopoundsForcePerSquareFoot. + /// + public static Pressure? FromKilopoundsForcePerSquareFoot(double? kilopoundsforcepersquarefoot) + { + if (kilopoundsforcepersquarefoot.HasValue) + { + return FromKilopoundsForcePerSquareFoot(kilopoundsforcepersquarefoot.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable KilopoundsForcePerSquareInch. + /// + public static Pressure? FromKilopoundsForcePerSquareInch(double? kilopoundsforcepersquareinch) + { + if (kilopoundsforcepersquareinch.HasValue) + { + return FromKilopoundsForcePerSquareInch(kilopoundsforcepersquareinch.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Megabars. + /// + public static Pressure? FromMegabars(double? megabars) + { + if (megabars.HasValue) + { + return FromMegabars(megabars.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Megapascals. + /// + public static Pressure? FromMegapascals(double? megapascals) + { + if (megapascals.HasValue) + { + return FromMegapascals(megapascals.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Micropascals. + /// + public static Pressure? FromMicropascals(double? micropascals) + { + if (micropascals.HasValue) + { + return FromMicropascals(micropascals.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Millibars. + /// + public static Pressure? FromMillibars(double? millibars) + { + if (millibars.HasValue) + { + return FromMillibars(millibars.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable NewtonsPerSquareCentimeter. + /// + public static Pressure? FromNewtonsPerSquareCentimeter(double? newtonspersquarecentimeter) + { + if (newtonspersquarecentimeter.HasValue) + { + return FromNewtonsPerSquareCentimeter(newtonspersquarecentimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable NewtonsPerSquareMeter. + /// + public static Pressure? FromNewtonsPerSquareMeter(double? newtonspersquaremeter) + { + if (newtonspersquaremeter.HasValue) + { + return FromNewtonsPerSquareMeter(newtonspersquaremeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable NewtonsPerSquareMillimeter. + /// + public static Pressure? FromNewtonsPerSquareMillimeter(double? newtonspersquaremillimeter) + { + if (newtonspersquaremillimeter.HasValue) + { + return FromNewtonsPerSquareMillimeter(newtonspersquaremillimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Pascals. + /// + public static Pressure? FromPascals(double? pascals) + { + if (pascals.HasValue) + { + return FromPascals(pascals.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable PoundsForcePerSquareFoot. + /// + public static Pressure? FromPoundsForcePerSquareFoot(double? poundsforcepersquarefoot) + { + if (poundsforcepersquarefoot.HasValue) + { + return FromPoundsForcePerSquareFoot(poundsforcepersquarefoot.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable PoundsForcePerSquareInch. + /// + public static Pressure? FromPoundsForcePerSquareInch(double? poundsforcepersquareinch) + { + if (poundsforcepersquareinch.HasValue) + { + return FromPoundsForcePerSquareInch(poundsforcepersquareinch.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Psi. + /// + public static Pressure? FromPsi(double? psi) + { + if (psi.HasValue) + { + return FromPsi(psi.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable TechnicalAtmospheres. + /// + public static Pressure? FromTechnicalAtmospheres(double? technicalatmospheres) + { + if (technicalatmospheres.HasValue) + { + return FromTechnicalAtmospheres(technicalatmospheres.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable TonnesForcePerSquareCentimeter. + /// + public static Pressure? FromTonnesForcePerSquareCentimeter(double? tonnesforcepersquarecentimeter) + { + if (tonnesforcepersquarecentimeter.HasValue) + { + return FromTonnesForcePerSquareCentimeter(tonnesforcepersquarecentimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable TonnesForcePerSquareMeter. + /// + public static Pressure? FromTonnesForcePerSquareMeter(double? tonnesforcepersquaremeter) + { + if (tonnesforcepersquaremeter.HasValue) + { + return FromTonnesForcePerSquareMeter(tonnesforcepersquaremeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable TonnesForcePerSquareMillimeter. + /// + public static Pressure? FromTonnesForcePerSquareMillimeter(double? tonnesforcepersquaremillimeter) + { + if (tonnesforcepersquaremillimeter.HasValue) + { + return FromTonnesForcePerSquareMillimeter(tonnesforcepersquaremillimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Pressure from nullable Torrs. + /// + public static Pressure? FromTorrs(double? torrs) + { + if (torrs.HasValue) + { + return FromTorrs(torrs.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -674,6 +1170,92 @@ public static Pressure From(double value, PressureUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Pressure unit value. + public static Pressure? From(double? value, PressureUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case PressureUnit.Atmosphere: + return FromAtmospheres(value.Value); + case PressureUnit.Bar: + return FromBars(value.Value); + case PressureUnit.Centibar: + return FromCentibars(value.Value); + case PressureUnit.Decapascal: + return FromDecapascals(value.Value); + case PressureUnit.Decibar: + return FromDecibars(value.Value); + case PressureUnit.Gigapascal: + return FromGigapascals(value.Value); + case PressureUnit.Hectopascal: + return FromHectopascals(value.Value); + case PressureUnit.Kilobar: + return FromKilobars(value.Value); + case PressureUnit.KilogramForcePerSquareCentimeter: + return FromKilogramsForcePerSquareCentimeter(value.Value); + case PressureUnit.KilogramForcePerSquareMeter: + return FromKilogramsForcePerSquareMeter(value.Value); + case PressureUnit.KilogramForcePerSquareMillimeter: + return FromKilogramsForcePerSquareMillimeter(value.Value); + case PressureUnit.KilonewtonPerSquareCentimeter: + return FromKilonewtonsPerSquareCentimeter(value.Value); + case PressureUnit.KilonewtonPerSquareMeter: + return FromKilonewtonsPerSquareMeter(value.Value); + case PressureUnit.KilonewtonPerSquareMillimeter: + return FromKilonewtonsPerSquareMillimeter(value.Value); + case PressureUnit.Kilopascal: + return FromKilopascals(value.Value); + case PressureUnit.KilopoundForcePerSquareFoot: + return FromKilopoundsForcePerSquareFoot(value.Value); + case PressureUnit.KilopoundForcePerSquareInch: + return FromKilopoundsForcePerSquareInch(value.Value); + case PressureUnit.Megabar: + return FromMegabars(value.Value); + case PressureUnit.Megapascal: + return FromMegapascals(value.Value); + case PressureUnit.Micropascal: + return FromMicropascals(value.Value); + case PressureUnit.Millibar: + return FromMillibars(value.Value); + case PressureUnit.NewtonPerSquareCentimeter: + return FromNewtonsPerSquareCentimeter(value.Value); + case PressureUnit.NewtonPerSquareMeter: + return FromNewtonsPerSquareMeter(value.Value); + case PressureUnit.NewtonPerSquareMillimeter: + return FromNewtonsPerSquareMillimeter(value.Value); + case PressureUnit.Pascal: + return FromPascals(value.Value); + case PressureUnit.PoundForcePerSquareFoot: + return FromPoundsForcePerSquareFoot(value.Value); + case PressureUnit.PoundForcePerSquareInch: + return FromPoundsForcePerSquareInch(value.Value); + case PressureUnit.Psi: + return FromPsi(value.Value); + case PressureUnit.TechnicalAtmosphere: + return FromTechnicalAtmospheres(value.Value); + case PressureUnit.TonneForcePerSquareCentimeter: + return FromTonnesForcePerSquareCentimeter(value.Value); + case PressureUnit.TonneForcePerSquareMeter: + return FromTonnesForcePerSquareMeter(value.Value); + case PressureUnit.TonneForcePerSquareMillimeter: + return FromTonnesForcePerSquareMillimeter(value.Value); + case PressureUnit.Torr: + return FromTorrs(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -891,14 +1473,14 @@ public double As(PressureUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Pressure Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/PressureChangeRate.g.cs b/UnitsNet/GeneratedCode/UnitClasses/PressureChangeRate.g.cs index 6bb181914f..4cc2002765 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/PressureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/PressureChangeRate.g.cs @@ -128,6 +128,67 @@ public static PressureChangeRate FromPascalsPerSecond(double pascalspersecond) } + /// + /// Get nullable PressureChangeRate from nullable AtmospheresPerSecond. + /// + public static PressureChangeRate? FromAtmospheresPerSecond(double? atmospherespersecond) + { + if (atmospherespersecond.HasValue) + { + return FromAtmospheresPerSecond(atmospherespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable PressureChangeRate from nullable KilopascalsPerSecond. + /// + public static PressureChangeRate? FromKilopascalsPerSecond(double? kilopascalspersecond) + { + if (kilopascalspersecond.HasValue) + { + return FromKilopascalsPerSecond(kilopascalspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable PressureChangeRate from nullable MegapascalsPerSecond. + /// + public static PressureChangeRate? FromMegapascalsPerSecond(double? megapascalspersecond) + { + if (megapascalspersecond.HasValue) + { + return FromMegapascalsPerSecond(megapascalspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable PressureChangeRate from nullable PascalsPerSecond. + /// + public static PressureChangeRate? FromPascalsPerSecond(double? pascalspersecond) + { + if (pascalspersecond.HasValue) + { + return FromPascalsPerSecond(pascalspersecond.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -152,6 +213,34 @@ public static PressureChangeRate From(double value, PressureChangeRateUnit fromU } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// PressureChangeRate unit value. + public static PressureChangeRate? From(double? value, PressureChangeRateUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case PressureChangeRateUnit.AtmospherePerSecond: + return FromAtmospheresPerSecond(value.Value); + case PressureChangeRateUnit.KilopascalPerSecond: + return FromKilopascalsPerSecond(value.Value); + case PressureChangeRateUnit.MegapascalPerSecond: + return FromMegapascalsPerSecond(value.Value); + case PressureChangeRateUnit.PascalPerSecond: + return FromPascalsPerSecond(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -311,14 +400,14 @@ public double As(PressureChangeRateUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static PressureChangeRate Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Ratio.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Ratio.g.cs index e4022df6e6..9b89e45d6b 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Ratio.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Ratio.g.cs @@ -160,6 +160,97 @@ public static Ratio FromPercent(double percent) } + /// + /// Get nullable Ratio from nullable DecimalFractions. + /// + public static Ratio? FromDecimalFractions(double? decimalfractions) + { + if (decimalfractions.HasValue) + { + return FromDecimalFractions(decimalfractions.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Ratio from nullable PartsPerBillion. + /// + public static Ratio? FromPartsPerBillion(double? partsperbillion) + { + if (partsperbillion.HasValue) + { + return FromPartsPerBillion(partsperbillion.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Ratio from nullable PartsPerMillion. + /// + public static Ratio? FromPartsPerMillion(double? partspermillion) + { + if (partspermillion.HasValue) + { + return FromPartsPerMillion(partspermillion.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Ratio from nullable PartsPerThousand. + /// + public static Ratio? FromPartsPerThousand(double? partsperthousand) + { + if (partsperthousand.HasValue) + { + return FromPartsPerThousand(partsperthousand.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Ratio from nullable PartsPerTrillion. + /// + public static Ratio? FromPartsPerTrillion(double? partspertrillion) + { + if (partspertrillion.HasValue) + { + return FromPartsPerTrillion(partspertrillion.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Ratio from nullable Percent. + /// + public static Ratio? FromPercent(double? percent) + { + if (percent.HasValue) + { + return FromPercent(percent.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -188,6 +279,38 @@ public static Ratio From(double value, RatioUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Ratio unit value. + public static Ratio? From(double? value, RatioUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case RatioUnit.DecimalFraction: + return FromDecimalFractions(value.Value); + case RatioUnit.PartPerBillion: + return FromPartsPerBillion(value.Value); + case RatioUnit.PartPerMillion: + return FromPartsPerMillion(value.Value); + case RatioUnit.PartPerThousand: + return FromPartsPerThousand(value.Value); + case RatioUnit.PartPerTrillion: + return FromPartsPerTrillion(value.Value); + case RatioUnit.Percent: + return FromPercent(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -351,14 +474,14 @@ public double As(RatioUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Ratio Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/RotationalSpeed.g.cs b/UnitsNet/GeneratedCode/UnitClasses/RotationalSpeed.g.cs index 3e054a5cb1..bfa5733e21 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/RotationalSpeed.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/RotationalSpeed.g.cs @@ -192,6 +192,127 @@ public static RotationalSpeed FromRevolutionsPerSecond(double revolutionsperseco } + /// + /// Get nullable RotationalSpeed from nullable CentiradiansPerSecond. + /// + public static RotationalSpeed? FromCentiradiansPerSecond(double? centiradianspersecond) + { + if (centiradianspersecond.HasValue) + { + return FromCentiradiansPerSecond(centiradianspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable RotationalSpeed from nullable DeciradiansPerSecond. + /// + public static RotationalSpeed? FromDeciradiansPerSecond(double? deciradianspersecond) + { + if (deciradianspersecond.HasValue) + { + return FromDeciradiansPerSecond(deciradianspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable RotationalSpeed from nullable MicroradiansPerSecond. + /// + public static RotationalSpeed? FromMicroradiansPerSecond(double? microradianspersecond) + { + if (microradianspersecond.HasValue) + { + return FromMicroradiansPerSecond(microradianspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable RotationalSpeed from nullable MilliradiansPerSecond. + /// + public static RotationalSpeed? FromMilliradiansPerSecond(double? milliradianspersecond) + { + if (milliradianspersecond.HasValue) + { + return FromMilliradiansPerSecond(milliradianspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable RotationalSpeed from nullable NanoradiansPerSecond. + /// + public static RotationalSpeed? FromNanoradiansPerSecond(double? nanoradianspersecond) + { + if (nanoradianspersecond.HasValue) + { + return FromNanoradiansPerSecond(nanoradianspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable RotationalSpeed from nullable RadiansPerSecond. + /// + public static RotationalSpeed? FromRadiansPerSecond(double? radianspersecond) + { + if (radianspersecond.HasValue) + { + return FromRadiansPerSecond(radianspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable RotationalSpeed from nullable RevolutionsPerMinute. + /// + public static RotationalSpeed? FromRevolutionsPerMinute(double? revolutionsperminute) + { + if (revolutionsperminute.HasValue) + { + return FromRevolutionsPerMinute(revolutionsperminute.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable RotationalSpeed from nullable RevolutionsPerSecond. + /// + public static RotationalSpeed? FromRevolutionsPerSecond(double? revolutionspersecond) + { + if (revolutionspersecond.HasValue) + { + return FromRevolutionsPerSecond(revolutionspersecond.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -224,6 +345,42 @@ public static RotationalSpeed From(double value, RotationalSpeedUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// RotationalSpeed unit value. + public static RotationalSpeed? From(double? value, RotationalSpeedUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case RotationalSpeedUnit.CentiradianPerSecond: + return FromCentiradiansPerSecond(value.Value); + case RotationalSpeedUnit.DeciradianPerSecond: + return FromDeciradiansPerSecond(value.Value); + case RotationalSpeedUnit.MicroradianPerSecond: + return FromMicroradiansPerSecond(value.Value); + case RotationalSpeedUnit.MilliradianPerSecond: + return FromMilliradiansPerSecond(value.Value); + case RotationalSpeedUnit.NanoradianPerSecond: + return FromNanoradiansPerSecond(value.Value); + case RotationalSpeedUnit.RadianPerSecond: + return FromRadiansPerSecond(value.Value); + case RotationalSpeedUnit.RevolutionPerMinute: + return FromRevolutionsPerMinute(value.Value); + case RotationalSpeedUnit.RevolutionPerSecond: + return FromRevolutionsPerSecond(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -391,14 +548,14 @@ public double As(RotationalSpeedUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static RotationalSpeed Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/SpecificEnergy.g.cs b/UnitsNet/GeneratedCode/UnitClasses/SpecificEnergy.g.cs index afd83690a9..f1c2fab79a 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/SpecificEnergy.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/SpecificEnergy.g.cs @@ -192,6 +192,127 @@ public static SpecificEnergy FromWattHoursPerKilogram(double watthoursperkilogra } + /// + /// Get nullable SpecificEnergy from nullable CaloriesPerGram. + /// + public static SpecificEnergy? FromCaloriesPerGram(double? caloriespergram) + { + if (caloriespergram.HasValue) + { + return FromCaloriesPerGram(caloriespergram.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificEnergy from nullable JoulesPerKilogram. + /// + public static SpecificEnergy? FromJoulesPerKilogram(double? joulesperkilogram) + { + if (joulesperkilogram.HasValue) + { + return FromJoulesPerKilogram(joulesperkilogram.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificEnergy from nullable KilocaloriesPerGram. + /// + public static SpecificEnergy? FromKilocaloriesPerGram(double? kilocaloriespergram) + { + if (kilocaloriespergram.HasValue) + { + return FromKilocaloriesPerGram(kilocaloriespergram.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificEnergy from nullable KilojoulesPerKilogram. + /// + public static SpecificEnergy? FromKilojoulesPerKilogram(double? kilojoulesperkilogram) + { + if (kilojoulesperkilogram.HasValue) + { + return FromKilojoulesPerKilogram(kilojoulesperkilogram.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificEnergy from nullable KilowattHoursPerKilogram. + /// + public static SpecificEnergy? FromKilowattHoursPerKilogram(double? kilowatthoursperkilogram) + { + if (kilowatthoursperkilogram.HasValue) + { + return FromKilowattHoursPerKilogram(kilowatthoursperkilogram.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificEnergy from nullable MegajoulesPerKilogram. + /// + public static SpecificEnergy? FromMegajoulesPerKilogram(double? megajoulesperkilogram) + { + if (megajoulesperkilogram.HasValue) + { + return FromMegajoulesPerKilogram(megajoulesperkilogram.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificEnergy from nullable MegawattHoursPerKilogram. + /// + public static SpecificEnergy? FromMegawattHoursPerKilogram(double? megawatthoursperkilogram) + { + if (megawatthoursperkilogram.HasValue) + { + return FromMegawattHoursPerKilogram(megawatthoursperkilogram.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificEnergy from nullable WattHoursPerKilogram. + /// + public static SpecificEnergy? FromWattHoursPerKilogram(double? watthoursperkilogram) + { + if (watthoursperkilogram.HasValue) + { + return FromWattHoursPerKilogram(watthoursperkilogram.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -224,6 +345,42 @@ public static SpecificEnergy From(double value, SpecificEnergyUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// SpecificEnergy unit value. + public static SpecificEnergy? From(double? value, SpecificEnergyUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case SpecificEnergyUnit.CaloriePerGram: + return FromCaloriesPerGram(value.Value); + case SpecificEnergyUnit.JoulePerKilogram: + return FromJoulesPerKilogram(value.Value); + case SpecificEnergyUnit.KilocaloriePerGram: + return FromKilocaloriesPerGram(value.Value); + case SpecificEnergyUnit.KilojoulePerKilogram: + return FromKilojoulesPerKilogram(value.Value); + case SpecificEnergyUnit.KilowattHourPerKilogram: + return FromKilowattHoursPerKilogram(value.Value); + case SpecificEnergyUnit.MegajoulePerKilogram: + return FromMegajoulesPerKilogram(value.Value); + case SpecificEnergyUnit.MegawattHourPerKilogram: + return FromMegawattHoursPerKilogram(value.Value); + case SpecificEnergyUnit.WattHourPerKilogram: + return FromWattHoursPerKilogram(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -391,14 +548,14 @@ public double As(SpecificEnergyUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static SpecificEnergy Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/SpecificWeight.g.cs b/UnitsNet/GeneratedCode/UnitClasses/SpecificWeight.g.cs index f08d267818..dd2bc3b01f 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/SpecificWeight.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/SpecificWeight.g.cs @@ -320,6 +320,247 @@ public static SpecificWeight FromTonnesForcePerCubicMillimeter(double tonnesforc } + /// + /// Get nullable SpecificWeight from nullable KilogramsForcePerCubicCentimeter. + /// + public static SpecificWeight? FromKilogramsForcePerCubicCentimeter(double? kilogramsforcepercubiccentimeter) + { + if (kilogramsforcepercubiccentimeter.HasValue) + { + return FromKilogramsForcePerCubicCentimeter(kilogramsforcepercubiccentimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable KilogramsForcePerCubicMeter. + /// + public static SpecificWeight? FromKilogramsForcePerCubicMeter(double? kilogramsforcepercubicmeter) + { + if (kilogramsforcepercubicmeter.HasValue) + { + return FromKilogramsForcePerCubicMeter(kilogramsforcepercubicmeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable KilogramsForcePerCubicMillimeter. + /// + public static SpecificWeight? FromKilogramsForcePerCubicMillimeter(double? kilogramsforcepercubicmillimeter) + { + if (kilogramsforcepercubicmillimeter.HasValue) + { + return FromKilogramsForcePerCubicMillimeter(kilogramsforcepercubicmillimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable KilonewtonsPerCubicCentimeter. + /// + public static SpecificWeight? FromKilonewtonsPerCubicCentimeter(double? kilonewtonspercubiccentimeter) + { + if (kilonewtonspercubiccentimeter.HasValue) + { + return FromKilonewtonsPerCubicCentimeter(kilonewtonspercubiccentimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable KilonewtonsPerCubicMeter. + /// + public static SpecificWeight? FromKilonewtonsPerCubicMeter(double? kilonewtonspercubicmeter) + { + if (kilonewtonspercubicmeter.HasValue) + { + return FromKilonewtonsPerCubicMeter(kilonewtonspercubicmeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable KilonewtonsPerCubicMillimeter. + /// + public static SpecificWeight? FromKilonewtonsPerCubicMillimeter(double? kilonewtonspercubicmillimeter) + { + if (kilonewtonspercubicmillimeter.HasValue) + { + return FromKilonewtonsPerCubicMillimeter(kilonewtonspercubicmillimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable KilopoundsForcePerCubicFoot. + /// + public static SpecificWeight? FromKilopoundsForcePerCubicFoot(double? kilopoundsforcepercubicfoot) + { + if (kilopoundsforcepercubicfoot.HasValue) + { + return FromKilopoundsForcePerCubicFoot(kilopoundsforcepercubicfoot.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable KilopoundsForcePerCubicInch. + /// + public static SpecificWeight? FromKilopoundsForcePerCubicInch(double? kilopoundsforcepercubicinch) + { + if (kilopoundsforcepercubicinch.HasValue) + { + return FromKilopoundsForcePerCubicInch(kilopoundsforcepercubicinch.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable NewtonsPerCubicCentimeter. + /// + public static SpecificWeight? FromNewtonsPerCubicCentimeter(double? newtonspercubiccentimeter) + { + if (newtonspercubiccentimeter.HasValue) + { + return FromNewtonsPerCubicCentimeter(newtonspercubiccentimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable NewtonsPerCubicMeter. + /// + public static SpecificWeight? FromNewtonsPerCubicMeter(double? newtonspercubicmeter) + { + if (newtonspercubicmeter.HasValue) + { + return FromNewtonsPerCubicMeter(newtonspercubicmeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable NewtonsPerCubicMillimeter. + /// + public static SpecificWeight? FromNewtonsPerCubicMillimeter(double? newtonspercubicmillimeter) + { + if (newtonspercubicmillimeter.HasValue) + { + return FromNewtonsPerCubicMillimeter(newtonspercubicmillimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable PoundsForcePerCubicFoot. + /// + public static SpecificWeight? FromPoundsForcePerCubicFoot(double? poundsforcepercubicfoot) + { + if (poundsforcepercubicfoot.HasValue) + { + return FromPoundsForcePerCubicFoot(poundsforcepercubicfoot.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable PoundsForcePerCubicInch. + /// + public static SpecificWeight? FromPoundsForcePerCubicInch(double? poundsforcepercubicinch) + { + if (poundsforcepercubicinch.HasValue) + { + return FromPoundsForcePerCubicInch(poundsforcepercubicinch.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable TonnesForcePerCubicCentimeter. + /// + public static SpecificWeight? FromTonnesForcePerCubicCentimeter(double? tonnesforcepercubiccentimeter) + { + if (tonnesforcepercubiccentimeter.HasValue) + { + return FromTonnesForcePerCubicCentimeter(tonnesforcepercubiccentimeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable TonnesForcePerCubicMeter. + /// + public static SpecificWeight? FromTonnesForcePerCubicMeter(double? tonnesforcepercubicmeter) + { + if (tonnesforcepercubicmeter.HasValue) + { + return FromTonnesForcePerCubicMeter(tonnesforcepercubicmeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable SpecificWeight from nullable TonnesForcePerCubicMillimeter. + /// + public static SpecificWeight? FromTonnesForcePerCubicMillimeter(double? tonnesforcepercubicmillimeter) + { + if (tonnesforcepercubicmillimeter.HasValue) + { + return FromTonnesForcePerCubicMillimeter(tonnesforcepercubicmillimeter.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -368,6 +609,58 @@ public static SpecificWeight From(double value, SpecificWeightUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// SpecificWeight unit value. + public static SpecificWeight? From(double? value, SpecificWeightUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case SpecificWeightUnit.KilogramForcePerCubicCentimeter: + return FromKilogramsForcePerCubicCentimeter(value.Value); + case SpecificWeightUnit.KilogramForcePerCubicMeter: + return FromKilogramsForcePerCubicMeter(value.Value); + case SpecificWeightUnit.KilogramForcePerCubicMillimeter: + return FromKilogramsForcePerCubicMillimeter(value.Value); + case SpecificWeightUnit.KilonewtonPerCubicCentimeter: + return FromKilonewtonsPerCubicCentimeter(value.Value); + case SpecificWeightUnit.KilonewtonPerCubicMeter: + return FromKilonewtonsPerCubicMeter(value.Value); + case SpecificWeightUnit.KilonewtonPerCubicMillimeter: + return FromKilonewtonsPerCubicMillimeter(value.Value); + case SpecificWeightUnit.KilopoundForcePerCubicFoot: + return FromKilopoundsForcePerCubicFoot(value.Value); + case SpecificWeightUnit.KilopoundForcePerCubicInch: + return FromKilopoundsForcePerCubicInch(value.Value); + case SpecificWeightUnit.NewtonPerCubicCentimeter: + return FromNewtonsPerCubicCentimeter(value.Value); + case SpecificWeightUnit.NewtonPerCubicMeter: + return FromNewtonsPerCubicMeter(value.Value); + case SpecificWeightUnit.NewtonPerCubicMillimeter: + return FromNewtonsPerCubicMillimeter(value.Value); + case SpecificWeightUnit.PoundForcePerCubicFoot: + return FromPoundsForcePerCubicFoot(value.Value); + case SpecificWeightUnit.PoundForcePerCubicInch: + return FromPoundsForcePerCubicInch(value.Value); + case SpecificWeightUnit.TonneForcePerCubicCentimeter: + return FromTonnesForcePerCubicCentimeter(value.Value); + case SpecificWeightUnit.TonneForcePerCubicMeter: + return FromTonnesForcePerCubicMeter(value.Value); + case SpecificWeightUnit.TonneForcePerCubicMillimeter: + return FromTonnesForcePerCubicMillimeter(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -551,14 +844,14 @@ public double As(SpecificWeightUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static SpecificWeight Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Speed.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Speed.g.cs index 3f4543a9f5..1036a37a4f 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Speed.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Speed.g.cs @@ -256,6 +256,187 @@ public static Speed FromNanometersPerSecond(double nanometerspersecond) } + /// + /// Get nullable Speed from nullable CentimetersPerSecond. + /// + public static Speed? FromCentimetersPerSecond(double? centimeterspersecond) + { + if (centimeterspersecond.HasValue) + { + return FromCentimetersPerSecond(centimeterspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Speed from nullable DecimetersPerSecond. + /// + public static Speed? FromDecimetersPerSecond(double? decimeterspersecond) + { + if (decimeterspersecond.HasValue) + { + return FromDecimetersPerSecond(decimeterspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Speed from nullable FeetPerSecond. + /// + public static Speed? FromFeetPerSecond(double? feetpersecond) + { + if (feetpersecond.HasValue) + { + return FromFeetPerSecond(feetpersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Speed from nullable KilometersPerHour. + /// + public static Speed? FromKilometersPerHour(double? kilometersperhour) + { + if (kilometersperhour.HasValue) + { + return FromKilometersPerHour(kilometersperhour.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Speed from nullable KilometersPerSecond. + /// + public static Speed? FromKilometersPerSecond(double? kilometerspersecond) + { + if (kilometerspersecond.HasValue) + { + return FromKilometersPerSecond(kilometerspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Speed from nullable Knots. + /// + public static Speed? FromKnots(double? knots) + { + if (knots.HasValue) + { + return FromKnots(knots.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Speed from nullable MetersPerHour. + /// + public static Speed? FromMetersPerHour(double? metersperhour) + { + if (metersperhour.HasValue) + { + return FromMetersPerHour(metersperhour.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Speed from nullable MetersPerSecond. + /// + public static Speed? FromMetersPerSecond(double? meterspersecond) + { + if (meterspersecond.HasValue) + { + return FromMetersPerSecond(meterspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Speed from nullable MicrometersPerSecond. + /// + public static Speed? FromMicrometersPerSecond(double? micrometerspersecond) + { + if (micrometerspersecond.HasValue) + { + return FromMicrometersPerSecond(micrometerspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Speed from nullable MilesPerHour. + /// + public static Speed? FromMilesPerHour(double? milesperhour) + { + if (milesperhour.HasValue) + { + return FromMilesPerHour(milesperhour.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Speed from nullable MillimetersPerSecond. + /// + public static Speed? FromMillimetersPerSecond(double? millimeterspersecond) + { + if (millimeterspersecond.HasValue) + { + return FromMillimetersPerSecond(millimeterspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Speed from nullable NanometersPerSecond. + /// + public static Speed? FromNanometersPerSecond(double? nanometerspersecond) + { + if (nanometerspersecond.HasValue) + { + return FromNanometersPerSecond(nanometerspersecond.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -296,6 +477,50 @@ public static Speed From(double value, SpeedUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Speed unit value. + public static Speed? From(double? value, SpeedUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case SpeedUnit.CentimeterPerSecond: + return FromCentimetersPerSecond(value.Value); + case SpeedUnit.DecimeterPerSecond: + return FromDecimetersPerSecond(value.Value); + case SpeedUnit.FootPerSecond: + return FromFeetPerSecond(value.Value); + case SpeedUnit.KilometerPerHour: + return FromKilometersPerHour(value.Value); + case SpeedUnit.KilometerPerSecond: + return FromKilometersPerSecond(value.Value); + case SpeedUnit.Knot: + return FromKnots(value.Value); + case SpeedUnit.MeterPerHour: + return FromMetersPerHour(value.Value); + case SpeedUnit.MeterPerSecond: + return FromMetersPerSecond(value.Value); + case SpeedUnit.MicrometerPerSecond: + return FromMicrometersPerSecond(value.Value); + case SpeedUnit.MilePerHour: + return FromMilesPerHour(value.Value); + case SpeedUnit.MillimeterPerSecond: + return FromMillimetersPerSecond(value.Value); + case SpeedUnit.NanometerPerSecond: + return FromNanometersPerSecond(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -471,14 +696,14 @@ public double As(SpeedUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Speed Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Temperature.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Temperature.g.cs index 0be2dc313b..eaee3a5316 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Temperature.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Temperature.g.cs @@ -192,6 +192,127 @@ public static Temperature FromKelvins(double kelvins) } + /// + /// Get nullable Temperature from nullable DegreesCelsius. + /// + public static Temperature? FromDegreesCelsius(double? degreescelsius) + { + if (degreescelsius.HasValue) + { + return FromDegreesCelsius(degreescelsius.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Temperature from nullable DegreesDelisle. + /// + public static Temperature? FromDegreesDelisle(double? degreesdelisle) + { + if (degreesdelisle.HasValue) + { + return FromDegreesDelisle(degreesdelisle.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Temperature from nullable DegreesFahrenheit. + /// + public static Temperature? FromDegreesFahrenheit(double? degreesfahrenheit) + { + if (degreesfahrenheit.HasValue) + { + return FromDegreesFahrenheit(degreesfahrenheit.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Temperature from nullable DegreesNewton. + /// + public static Temperature? FromDegreesNewton(double? degreesnewton) + { + if (degreesnewton.HasValue) + { + return FromDegreesNewton(degreesnewton.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Temperature from nullable DegreesRankine. + /// + public static Temperature? FromDegreesRankine(double? degreesrankine) + { + if (degreesrankine.HasValue) + { + return FromDegreesRankine(degreesrankine.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Temperature from nullable DegreesReaumur. + /// + public static Temperature? FromDegreesReaumur(double? degreesreaumur) + { + if (degreesreaumur.HasValue) + { + return FromDegreesReaumur(degreesreaumur.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Temperature from nullable DegreesRoemer. + /// + public static Temperature? FromDegreesRoemer(double? degreesroemer) + { + if (degreesroemer.HasValue) + { + return FromDegreesRoemer(degreesroemer.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Temperature from nullable Kelvins. + /// + public static Temperature? FromKelvins(double? kelvins) + { + if (kelvins.HasValue) + { + return FromKelvins(kelvins.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -224,6 +345,42 @@ public static Temperature From(double value, TemperatureUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Temperature unit value. + public static Temperature? From(double? value, TemperatureUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case TemperatureUnit.DegreeCelsius: + return FromDegreesCelsius(value.Value); + case TemperatureUnit.DegreeDelisle: + return FromDegreesDelisle(value.Value); + case TemperatureUnit.DegreeFahrenheit: + return FromDegreesFahrenheit(value.Value); + case TemperatureUnit.DegreeNewton: + return FromDegreesNewton(value.Value); + case TemperatureUnit.DegreeRankine: + return FromDegreesRankine(value.Value); + case TemperatureUnit.DegreeReaumur: + return FromDegreesReaumur(value.Value); + case TemperatureUnit.DegreeRoemer: + return FromDegreesRoemer(value.Value); + case TemperatureUnit.Kelvin: + return FromKelvins(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -391,14 +548,14 @@ public double As(TemperatureUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Temperature Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/TemperatureChangeRate.g.cs b/UnitsNet/GeneratedCode/UnitClasses/TemperatureChangeRate.g.cs index f1f255075d..222cba5442 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/TemperatureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/TemperatureChangeRate.g.cs @@ -208,6 +208,142 @@ public static TemperatureChangeRate FromNanodegreesCelsiusPerSecond(double nanod } + /// + /// Get nullable TemperatureChangeRate from nullable CentidegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate? FromCentidegreesCelsiusPerSecond(double? centidegreescelsiuspersecond) + { + if (centidegreescelsiuspersecond.HasValue) + { + return FromCentidegreesCelsiusPerSecond(centidegreescelsiuspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable TemperatureChangeRate from nullable DecadegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate? FromDecadegreesCelsiusPerSecond(double? decadegreescelsiuspersecond) + { + if (decadegreescelsiuspersecond.HasValue) + { + return FromDecadegreesCelsiusPerSecond(decadegreescelsiuspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable TemperatureChangeRate from nullable DecidegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate? FromDecidegreesCelsiusPerSecond(double? decidegreescelsiuspersecond) + { + if (decidegreescelsiuspersecond.HasValue) + { + return FromDecidegreesCelsiusPerSecond(decidegreescelsiuspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable TemperatureChangeRate from nullable DegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate? FromDegreesCelsiusPerSecond(double? degreescelsiuspersecond) + { + if (degreescelsiuspersecond.HasValue) + { + return FromDegreesCelsiusPerSecond(degreescelsiuspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable TemperatureChangeRate from nullable HectodegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate? FromHectodegreesCelsiusPerSecond(double? hectodegreescelsiuspersecond) + { + if (hectodegreescelsiuspersecond.HasValue) + { + return FromHectodegreesCelsiusPerSecond(hectodegreescelsiuspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable TemperatureChangeRate from nullable KilodegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate? FromKilodegreesCelsiusPerSecond(double? kilodegreescelsiuspersecond) + { + if (kilodegreescelsiuspersecond.HasValue) + { + return FromKilodegreesCelsiusPerSecond(kilodegreescelsiuspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable TemperatureChangeRate from nullable MicrodegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate? FromMicrodegreesCelsiusPerSecond(double? microdegreescelsiuspersecond) + { + if (microdegreescelsiuspersecond.HasValue) + { + return FromMicrodegreesCelsiusPerSecond(microdegreescelsiuspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable TemperatureChangeRate from nullable MillidegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate? FromMillidegreesCelsiusPerSecond(double? millidegreescelsiuspersecond) + { + if (millidegreescelsiuspersecond.HasValue) + { + return FromMillidegreesCelsiusPerSecond(millidegreescelsiuspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable TemperatureChangeRate from nullable NanodegreesCelsiusPerSecond. + /// + public static TemperatureChangeRate? FromNanodegreesCelsiusPerSecond(double? nanodegreescelsiuspersecond) + { + if (nanodegreescelsiuspersecond.HasValue) + { + return FromNanodegreesCelsiusPerSecond(nanodegreescelsiuspersecond.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -242,6 +378,44 @@ public static TemperatureChangeRate From(double value, TemperatureChangeRateUnit } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// TemperatureChangeRate unit value. + public static TemperatureChangeRate? From(double? value, TemperatureChangeRateUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond: + return FromCentidegreesCelsiusPerSecond(value.Value); + case TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond: + return FromDecadegreesCelsiusPerSecond(value.Value); + case TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond: + return FromDecidegreesCelsiusPerSecond(value.Value); + case TemperatureChangeRateUnit.DegreeCelsiusPerSecond: + return FromDegreesCelsiusPerSecond(value.Value); + case TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond: + return FromHectodegreesCelsiusPerSecond(value.Value); + case TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond: + return FromKilodegreesCelsiusPerSecond(value.Value); + case TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond: + return FromMicrodegreesCelsiusPerSecond(value.Value); + case TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond: + return FromMillidegreesCelsiusPerSecond(value.Value); + case TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond: + return FromNanodegreesCelsiusPerSecond(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -411,14 +585,14 @@ public double As(TemperatureChangeRateUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static TemperatureChangeRate Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Torque.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Torque.g.cs index 015bff6d90..12b641554e 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Torque.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Torque.g.cs @@ -320,6 +320,247 @@ public static Torque FromTonneForceMillimeters(double tonneforcemillimeters) } + /// + /// Get nullable Torque from nullable KilogramForceCentimeters. + /// + public static Torque? FromKilogramForceCentimeters(double? kilogramforcecentimeters) + { + if (kilogramforcecentimeters.HasValue) + { + return FromKilogramForceCentimeters(kilogramforcecentimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable KilogramForceMeters. + /// + public static Torque? FromKilogramForceMeters(double? kilogramforcemeters) + { + if (kilogramforcemeters.HasValue) + { + return FromKilogramForceMeters(kilogramforcemeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable KilogramForceMillimeters. + /// + public static Torque? FromKilogramForceMillimeters(double? kilogramforcemillimeters) + { + if (kilogramforcemillimeters.HasValue) + { + return FromKilogramForceMillimeters(kilogramforcemillimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable KilonewtonCentimeters. + /// + public static Torque? FromKilonewtonCentimeters(double? kilonewtoncentimeters) + { + if (kilonewtoncentimeters.HasValue) + { + return FromKilonewtonCentimeters(kilonewtoncentimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable KilonewtonMeters. + /// + public static Torque? FromKilonewtonMeters(double? kilonewtonmeters) + { + if (kilonewtonmeters.HasValue) + { + return FromKilonewtonMeters(kilonewtonmeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable KilonewtonMillimeters. + /// + public static Torque? FromKilonewtonMillimeters(double? kilonewtonmillimeters) + { + if (kilonewtonmillimeters.HasValue) + { + return FromKilonewtonMillimeters(kilonewtonmillimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable KilopoundForceFeet. + /// + public static Torque? FromKilopoundForceFeet(double? kilopoundforcefeet) + { + if (kilopoundforcefeet.HasValue) + { + return FromKilopoundForceFeet(kilopoundforcefeet.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable KilopoundForceInches. + /// + public static Torque? FromKilopoundForceInches(double? kilopoundforceinches) + { + if (kilopoundforceinches.HasValue) + { + return FromKilopoundForceInches(kilopoundforceinches.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable NewtonCentimeters. + /// + public static Torque? FromNewtonCentimeters(double? newtoncentimeters) + { + if (newtoncentimeters.HasValue) + { + return FromNewtonCentimeters(newtoncentimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable NewtonMeters. + /// + public static Torque? FromNewtonMeters(double? newtonmeters) + { + if (newtonmeters.HasValue) + { + return FromNewtonMeters(newtonmeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable NewtonMillimeters. + /// + public static Torque? FromNewtonMillimeters(double? newtonmillimeters) + { + if (newtonmillimeters.HasValue) + { + return FromNewtonMillimeters(newtonmillimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable PoundForceFeet. + /// + public static Torque? FromPoundForceFeet(double? poundforcefeet) + { + if (poundforcefeet.HasValue) + { + return FromPoundForceFeet(poundforcefeet.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable PoundForceInches. + /// + public static Torque? FromPoundForceInches(double? poundforceinches) + { + if (poundforceinches.HasValue) + { + return FromPoundForceInches(poundforceinches.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable TonneForceCentimeters. + /// + public static Torque? FromTonneForceCentimeters(double? tonneforcecentimeters) + { + if (tonneforcecentimeters.HasValue) + { + return FromTonneForceCentimeters(tonneforcecentimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable TonneForceMeters. + /// + public static Torque? FromTonneForceMeters(double? tonneforcemeters) + { + if (tonneforcemeters.HasValue) + { + return FromTonneForceMeters(tonneforcemeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Torque from nullable TonneForceMillimeters. + /// + public static Torque? FromTonneForceMillimeters(double? tonneforcemillimeters) + { + if (tonneforcemillimeters.HasValue) + { + return FromTonneForceMillimeters(tonneforcemillimeters.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -368,6 +609,58 @@ public static Torque From(double value, TorqueUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Torque unit value. + public static Torque? From(double? value, TorqueUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case TorqueUnit.KilogramForceCentimeter: + return FromKilogramForceCentimeters(value.Value); + case TorqueUnit.KilogramForceMeter: + return FromKilogramForceMeters(value.Value); + case TorqueUnit.KilogramForceMillimeter: + return FromKilogramForceMillimeters(value.Value); + case TorqueUnit.KilonewtonCentimeter: + return FromKilonewtonCentimeters(value.Value); + case TorqueUnit.KilonewtonMeter: + return FromKilonewtonMeters(value.Value); + case TorqueUnit.KilonewtonMillimeter: + return FromKilonewtonMillimeters(value.Value); + case TorqueUnit.KilopoundForceFoot: + return FromKilopoundForceFeet(value.Value); + case TorqueUnit.KilopoundForceInch: + return FromKilopoundForceInches(value.Value); + case TorqueUnit.NewtonCentimeter: + return FromNewtonCentimeters(value.Value); + case TorqueUnit.NewtonMeter: + return FromNewtonMeters(value.Value); + case TorqueUnit.NewtonMillimeter: + return FromNewtonMillimeters(value.Value); + case TorqueUnit.PoundForceFoot: + return FromPoundForceFeet(value.Value); + case TorqueUnit.PoundForceInch: + return FromPoundForceInches(value.Value); + case TorqueUnit.TonneForceCentimeter: + return FromTonneForceCentimeters(value.Value); + case TorqueUnit.TonneForceMeter: + return FromTonneForceMeters(value.Value); + case TorqueUnit.TonneForceMillimeter: + return FromTonneForceMillimeters(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -551,14 +844,14 @@ public double As(TorqueUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Torque Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/VitaminA.g.cs b/UnitsNet/GeneratedCode/UnitClasses/VitaminA.g.cs index 263cb8ad92..6685831db2 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/VitaminA.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/VitaminA.g.cs @@ -80,6 +80,22 @@ public static VitaminA FromInternationalUnits(double internationalunits) } + /// + /// Get nullable VitaminA from nullable InternationalUnits. + /// + public static VitaminA? FromInternationalUnits(double? internationalunits) + { + if (internationalunits.HasValue) + { + return FromInternationalUnits(internationalunits.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -98,6 +114,28 @@ public static VitaminA From(double value, VitaminAUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// VitaminA unit value. + public static VitaminA? From(double? value, VitaminAUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case VitaminAUnit.InternationalUnit: + return FromInternationalUnits(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -251,14 +289,14 @@ public double As(VitaminAUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static VitaminA Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/GeneratedCode/UnitClasses/Volume.g.cs b/UnitsNet/GeneratedCode/UnitClasses/Volume.g.cs index dfe189db07..50bdeff1ca 100644 --- a/UnitsNet/GeneratedCode/UnitClasses/Volume.g.cs +++ b/UnitsNet/GeneratedCode/UnitClasses/Volume.g.cs @@ -530,6 +530,442 @@ public static Volume FromUsTeaspoons(double usteaspoons) } + /// + /// Get nullable Volume from nullable AuTablespoons. + /// + public static Volume? FromAuTablespoons(double? autablespoons) + { + if (autablespoons.HasValue) + { + return FromAuTablespoons(autablespoons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable Centiliters. + /// + public static Volume? FromCentiliters(double? centiliters) + { + if (centiliters.HasValue) + { + return FromCentiliters(centiliters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable CubicCentimeters. + /// + public static Volume? FromCubicCentimeters(double? cubiccentimeters) + { + if (cubiccentimeters.HasValue) + { + return FromCubicCentimeters(cubiccentimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable CubicDecimeters. + /// + public static Volume? FromCubicDecimeters(double? cubicdecimeters) + { + if (cubicdecimeters.HasValue) + { + return FromCubicDecimeters(cubicdecimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable CubicFeet. + /// + public static Volume? FromCubicFeet(double? cubicfeet) + { + if (cubicfeet.HasValue) + { + return FromCubicFeet(cubicfeet.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable CubicInches. + /// + public static Volume? FromCubicInches(double? cubicinches) + { + if (cubicinches.HasValue) + { + return FromCubicInches(cubicinches.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable CubicKilometers. + /// + public static Volume? FromCubicKilometers(double? cubickilometers) + { + if (cubickilometers.HasValue) + { + return FromCubicKilometers(cubickilometers.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable CubicMeters. + /// + public static Volume? FromCubicMeters(double? cubicmeters) + { + if (cubicmeters.HasValue) + { + return FromCubicMeters(cubicmeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable CubicMicrometers. + /// + public static Volume? FromCubicMicrometers(double? cubicmicrometers) + { + if (cubicmicrometers.HasValue) + { + return FromCubicMicrometers(cubicmicrometers.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable CubicMiles. + /// + public static Volume? FromCubicMiles(double? cubicmiles) + { + if (cubicmiles.HasValue) + { + return FromCubicMiles(cubicmiles.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable CubicMillimeters. + /// + public static Volume? FromCubicMillimeters(double? cubicmillimeters) + { + if (cubicmillimeters.HasValue) + { + return FromCubicMillimeters(cubicmillimeters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable CubicYards. + /// + public static Volume? FromCubicYards(double? cubicyards) + { + if (cubicyards.HasValue) + { + return FromCubicYards(cubicyards.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable Deciliters. + /// + public static Volume? FromDeciliters(double? deciliters) + { + if (deciliters.HasValue) + { + return FromDeciliters(deciliters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable Hectoliters. + /// + public static Volume? FromHectoliters(double? hectoliters) + { + if (hectoliters.HasValue) + { + return FromHectoliters(hectoliters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable ImperialGallons. + /// + public static Volume? FromImperialGallons(double? imperialgallons) + { + if (imperialgallons.HasValue) + { + return FromImperialGallons(imperialgallons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable ImperialOunces. + /// + public static Volume? FromImperialOunces(double? imperialounces) + { + if (imperialounces.HasValue) + { + return FromImperialOunces(imperialounces.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable Liters. + /// + public static Volume? FromLiters(double? liters) + { + if (liters.HasValue) + { + return FromLiters(liters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable MetricCups. + /// + public static Volume? FromMetricCups(double? metriccups) + { + if (metriccups.HasValue) + { + return FromMetricCups(metriccups.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable MetricTeaspoons. + /// + public static Volume? FromMetricTeaspoons(double? metricteaspoons) + { + if (metricteaspoons.HasValue) + { + return FromMetricTeaspoons(metricteaspoons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable Milliliters. + /// + public static Volume? FromMilliliters(double? milliliters) + { + if (milliliters.HasValue) + { + return FromMilliliters(milliliters.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable Tablespoons. + /// + public static Volume? FromTablespoons(double? tablespoons) + { + if (tablespoons.HasValue) + { + return FromTablespoons(tablespoons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable Teaspoons. + /// + public static Volume? FromTeaspoons(double? teaspoons) + { + if (teaspoons.HasValue) + { + return FromTeaspoons(teaspoons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable UkTablespoons. + /// + public static Volume? FromUkTablespoons(double? uktablespoons) + { + if (uktablespoons.HasValue) + { + return FromUkTablespoons(uktablespoons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable UsCustomaryCups. + /// + public static Volume? FromUsCustomaryCups(double? uscustomarycups) + { + if (uscustomarycups.HasValue) + { + return FromUsCustomaryCups(uscustomarycups.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable UsGallons. + /// + public static Volume? FromUsGallons(double? usgallons) + { + if (usgallons.HasValue) + { + return FromUsGallons(usgallons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable UsLegalCups. + /// + public static Volume? FromUsLegalCups(double? uslegalcups) + { + if (uslegalcups.HasValue) + { + return FromUsLegalCups(uslegalcups.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable UsOunces. + /// + public static Volume? FromUsOunces(double? usounces) + { + if (usounces.HasValue) + { + return FromUsOunces(usounces.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable UsTablespoons. + /// + public static Volume? FromUsTablespoons(double? ustablespoons) + { + if (ustablespoons.HasValue) + { + return FromUsTablespoons(ustablespoons.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable Volume from nullable UsTeaspoons. + /// + public static Volume? FromUsTeaspoons(double? usteaspoons) + { + if (usteaspoons.HasValue) + { + return FromUsTeaspoons(usteaspoons.Value); + } + else + { + return null; + } + } + + /// /// Dynamically convert from value and unit enum to . /// @@ -604,6 +1040,84 @@ public static Volume From(double value, VolumeUnit fromUnit) } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Volume unit value. + public static Volume? From(double? value, VolumeUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case VolumeUnit.AuTablespoon: + return FromAuTablespoons(value.Value); + case VolumeUnit.Centiliter: + return FromCentiliters(value.Value); + case VolumeUnit.CubicCentimeter: + return FromCubicCentimeters(value.Value); + case VolumeUnit.CubicDecimeter: + return FromCubicDecimeters(value.Value); + case VolumeUnit.CubicFoot: + return FromCubicFeet(value.Value); + case VolumeUnit.CubicInch: + return FromCubicInches(value.Value); + case VolumeUnit.CubicKilometer: + return FromCubicKilometers(value.Value); + case VolumeUnit.CubicMeter: + return FromCubicMeters(value.Value); + case VolumeUnit.CubicMicrometer: + return FromCubicMicrometers(value.Value); + case VolumeUnit.CubicMile: + return FromCubicMiles(value.Value); + case VolumeUnit.CubicMillimeter: + return FromCubicMillimeters(value.Value); + case VolumeUnit.CubicYard: + return FromCubicYards(value.Value); + case VolumeUnit.Deciliter: + return FromDeciliters(value.Value); + case VolumeUnit.Hectoliter: + return FromHectoliters(value.Value); + case VolumeUnit.ImperialGallon: + return FromImperialGallons(value.Value); + case VolumeUnit.ImperialOunce: + return FromImperialOunces(value.Value); + case VolumeUnit.Liter: + return FromLiters(value.Value); + case VolumeUnit.MetricCup: + return FromMetricCups(value.Value); + case VolumeUnit.MetricTeaspoon: + return FromMetricTeaspoons(value.Value); + case VolumeUnit.Milliliter: + return FromMilliliters(value.Value); + case VolumeUnit.Tablespoon: + return FromTablespoons(value.Value); + case VolumeUnit.Teaspoon: + return FromTeaspoons(value.Value); + case VolumeUnit.UkTablespoon: + return FromUkTablespoons(value.Value); + case VolumeUnit.UsCustomaryCup: + return FromUsCustomaryCups(value.Value); + case VolumeUnit.UsGallon: + return FromUsGallons(value.Value); + case VolumeUnit.UsLegalCup: + return FromUsLegalCups(value.Value); + case VolumeUnit.UsOunce: + return FromUsOunces(value.Value); + case VolumeUnit.UsTablespoon: + return FromUsTablespoons(value.Value); + case VolumeUnit.UsTeaspoon: + return FromUsTeaspoons(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -813,14 +1327,14 @@ public double As(VolumeUnit unit) /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static Volume Parse(string str, IFormatProvider formatProvider = null) { diff --git a/UnitsNet/Scripts/Include-GenerateUnitClassSourceCode.ps1 b/UnitsNet/Scripts/Include-GenerateUnitClassSourceCode.ps1 index e0ba4c35eb..19aa75fbc0 100644 --- a/UnitsNet/Scripts/Include-GenerateUnitClassSourceCode.ps1 +++ b/UnitsNet/Scripts/Include-GenerateUnitClassSourceCode.ps1 @@ -72,10 +72,10 @@ namespace UnitsNet $propertyName = $unit.PluralName; $obsoleteAttribute = GetObsoleteAttribute($unit); if ($obsoleteAttribute) - { - $obsoleteAttribute = "`r`n " + $obsoleteAttribute; # apply padding to conformance with code format in this page - } - + { + $obsoleteAttribute = "`r`n " + $obsoleteAttribute; # apply padding to conformance with code format in this page + } + $fromBaseToUnitFunc = $unit.FromBaseToUnitFunc.Replace("x", $baseUnitFieldName);@" /// @@ -107,6 +107,26 @@ namespace UnitsNet return new $className($func); } +"@; }@" + +"@; foreach ($unit in $units) { + $valueParamName = $unit.PluralName.ToLowerInvariant(); + $func = $unit.FromUnitToBaseFunc.Replace("x", "$($valueParamName).Value");@" + /// + /// Get nullable $className from nullable $($unit.PluralName). + /// + public static $($className)? From$($unit.PluralName)(double? $valueParamName) + { + if ($($valueParamName).HasValue) + { + return From$($unit.PluralName)($($valueParamName).Value); + } + else + { + return null; + } + } + "@; }@" /// @@ -129,6 +149,30 @@ namespace UnitsNet } } + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// $className unit value. + public static $($className)? From(double? value, $unitEnumName fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { +"@; foreach ($unit in $units) {@" + case $unitEnumName.$($unit.SingularName): + return From$($unit.PluralName)(value.Value); +"@; }@" + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + /// /// Get unit abbreviation string. /// @@ -292,14 +336,14 @@ namespace UnitsNet /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" /// /// - /// More than one unit is represented by the specified unit abbreviation. - /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of - /// , and . + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . /// /// - /// If anything else goes wrong, typically due to a bug or unhandled case. - /// We wrap exceptions in to allow you to distinguish - /// Units.NET exceptions from other exceptions. + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. /// public static $className Parse(string str, IFormatProvider formatProvider = null) {