Skip to content

Commit

Permalink
Merge pull request #502 from angularsen/v4-throw-on-nan
Browse files Browse the repository at this point in the history
Do not allow NaN or Infinity
  • Loading branch information
tmilnthorp authored Oct 2, 2018
2 parents f677ec1 + 83db4ec commit 02ae423
Show file tree
Hide file tree
Showing 183 changed files with 3,477 additions and 202 deletions.
17 changes: 16 additions & 1 deletion Common/GeneratedCode/Quantities/Acceleration.Common.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
using System.Text.RegularExpressions;
using System.Linq;
using JetBrains.Annotations;
using UnitsNet.InternalHelpers;
using UnitsNet.Units;

// ReSharper disable once CheckNamespace
Expand Down Expand Up @@ -88,6 +89,7 @@ static Acceleration()
/// <param name="numericValue">The numeric value to contruct this quantity with.</param>
/// <param name="unit">The unit representation to contruct this quantity with.</param>
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
private
#else
Expand All @@ -98,7 +100,7 @@ static Acceleration()
if(unit == AccelerationUnit.Undefined)
throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));

_value = numericValue;
_value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
_unit = unit;
}

Expand Down Expand Up @@ -204,6 +206,7 @@ public static BaseDimensions BaseDimensions
/// <summary>
/// Get Acceleration from CentimetersPerSecondSquared.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromCentimetersPerSecondSquared(double centimeterspersecondsquared)
Expand All @@ -218,6 +221,7 @@ public static Acceleration FromCentimetersPerSecondSquared(QuantityValue centime
/// <summary>
/// Get Acceleration from DecimetersPerSecondSquared.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromDecimetersPerSecondSquared(double decimeterspersecondsquared)
Expand All @@ -232,6 +236,7 @@ public static Acceleration FromDecimetersPerSecondSquared(QuantityValue decimete
/// <summary>
/// Get Acceleration from FeetPerSecondSquared.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromFeetPerSecondSquared(double feetpersecondsquared)
Expand All @@ -246,6 +251,7 @@ public static Acceleration FromFeetPerSecondSquared(QuantityValue feetperseconds
/// <summary>
/// Get Acceleration from InchesPerSecondSquared.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromInchesPerSecondSquared(double inchespersecondsquared)
Expand All @@ -260,6 +266,7 @@ public static Acceleration FromInchesPerSecondSquared(QuantityValue inchespersec
/// <summary>
/// Get Acceleration from KilometersPerSecondSquared.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromKilometersPerSecondSquared(double kilometerspersecondsquared)
Expand All @@ -274,6 +281,7 @@ public static Acceleration FromKilometersPerSecondSquared(QuantityValue kilomete
/// <summary>
/// Get Acceleration from KnotsPerHour.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromKnotsPerHour(double knotsperhour)
Expand All @@ -288,6 +296,7 @@ public static Acceleration FromKnotsPerHour(QuantityValue knotsperhour)
/// <summary>
/// Get Acceleration from KnotsPerMinute.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromKnotsPerMinute(double knotsperminute)
Expand All @@ -302,6 +311,7 @@ public static Acceleration FromKnotsPerMinute(QuantityValue knotsperminute)
/// <summary>
/// Get Acceleration from KnotsPerSecond.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromKnotsPerSecond(double knotspersecond)
Expand All @@ -316,6 +326,7 @@ public static Acceleration FromKnotsPerSecond(QuantityValue knotspersecond)
/// <summary>
/// Get Acceleration from MetersPerSecondSquared.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromMetersPerSecondSquared(double meterspersecondsquared)
Expand All @@ -330,6 +341,7 @@ public static Acceleration FromMetersPerSecondSquared(QuantityValue meterspersec
/// <summary>
/// Get Acceleration from MicrometersPerSecondSquared.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromMicrometersPerSecondSquared(double micrometerspersecondsquared)
Expand All @@ -344,6 +356,7 @@ public static Acceleration FromMicrometersPerSecondSquared(QuantityValue microme
/// <summary>
/// Get Acceleration from MillimetersPerSecondSquared.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromMillimetersPerSecondSquared(double millimeterspersecondsquared)
Expand All @@ -358,6 +371,7 @@ public static Acceleration FromMillimetersPerSecondSquared(QuantityValue millime
/// <summary>
/// Get Acceleration from NanometersPerSecondSquared.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromNanometersPerSecondSquared(double nanometerspersecondsquared)
Expand All @@ -372,6 +386,7 @@ public static Acceleration FromNanometersPerSecondSquared(QuantityValue nanomete
/// <summary>
/// Get Acceleration from StandardGravity.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static Acceleration FromStandardGravity(double standardgravity)
Expand Down
18 changes: 17 additions & 1 deletion Common/GeneratedCode/Quantities/AmountOfSubstance.Common.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
using System.Text.RegularExpressions;
using System.Linq;
using JetBrains.Annotations;
using UnitsNet.InternalHelpers;
using UnitsNet.Units;

// ReSharper disable once CheckNamespace
Expand Down Expand Up @@ -88,6 +89,7 @@ static AmountOfSubstance()
/// <param name="numericValue">The numeric value to contruct this quantity with.</param>
/// <param name="unit">The unit representation to contruct this quantity with.</param>
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
private
#else
Expand All @@ -98,7 +100,7 @@ static AmountOfSubstance()
if(unit == AmountOfSubstanceUnit.Undefined)
throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));

_value = numericValue;
_value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
_unit = unit;
}

Expand Down Expand Up @@ -209,6 +211,7 @@ public static BaseDimensions BaseDimensions
/// <summary>
/// Get AmountOfSubstance from Centimoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromCentimoles(double centimoles)
Expand All @@ -223,6 +226,7 @@ public static AmountOfSubstance FromCentimoles(QuantityValue centimoles)
/// <summary>
/// Get AmountOfSubstance from CentipoundMoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromCentipoundMoles(double centipoundmoles)
Expand All @@ -237,6 +241,7 @@ public static AmountOfSubstance FromCentipoundMoles(QuantityValue centipoundmole
/// <summary>
/// Get AmountOfSubstance from Decimoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromDecimoles(double decimoles)
Expand All @@ -251,6 +256,7 @@ public static AmountOfSubstance FromDecimoles(QuantityValue decimoles)
/// <summary>
/// Get AmountOfSubstance from DecipoundMoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromDecipoundMoles(double decipoundmoles)
Expand All @@ -265,6 +271,7 @@ public static AmountOfSubstance FromDecipoundMoles(QuantityValue decipoundmoles)
/// <summary>
/// Get AmountOfSubstance from Kilomoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromKilomoles(double kilomoles)
Expand All @@ -279,6 +286,7 @@ public static AmountOfSubstance FromKilomoles(QuantityValue kilomoles)
/// <summary>
/// Get AmountOfSubstance from KilopoundMoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromKilopoundMoles(double kilopoundmoles)
Expand All @@ -293,6 +301,7 @@ public static AmountOfSubstance FromKilopoundMoles(QuantityValue kilopoundmoles)
/// <summary>
/// Get AmountOfSubstance from Micromoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromMicromoles(double micromoles)
Expand All @@ -307,6 +316,7 @@ public static AmountOfSubstance FromMicromoles(QuantityValue micromoles)
/// <summary>
/// Get AmountOfSubstance from MicropoundMoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromMicropoundMoles(double micropoundmoles)
Expand All @@ -321,6 +331,7 @@ public static AmountOfSubstance FromMicropoundMoles(QuantityValue micropoundmole
/// <summary>
/// Get AmountOfSubstance from Millimoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromMillimoles(double millimoles)
Expand All @@ -335,6 +346,7 @@ public static AmountOfSubstance FromMillimoles(QuantityValue millimoles)
/// <summary>
/// Get AmountOfSubstance from MillipoundMoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromMillipoundMoles(double millipoundmoles)
Expand All @@ -349,6 +361,7 @@ public static AmountOfSubstance FromMillipoundMoles(QuantityValue millipoundmole
/// <summary>
/// Get AmountOfSubstance from Moles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromMoles(double moles)
Expand All @@ -363,6 +376,7 @@ public static AmountOfSubstance FromMoles(QuantityValue moles)
/// <summary>
/// Get AmountOfSubstance from Nanomoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromNanomoles(double nanomoles)
Expand All @@ -377,6 +391,7 @@ public static AmountOfSubstance FromNanomoles(QuantityValue nanomoles)
/// <summary>
/// Get AmountOfSubstance from NanopoundMoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromNanopoundMoles(double nanopoundmoles)
Expand All @@ -391,6 +406,7 @@ public static AmountOfSubstance FromNanopoundMoles(QuantityValue nanopoundmoles)
/// <summary>
/// Get AmountOfSubstance from PoundMoles.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmountOfSubstance FromPoundMoles(double poundmoles)
Expand Down
8 changes: 7 additions & 1 deletion Common/GeneratedCode/Quantities/AmplitudeRatio.Common.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
using System.Text.RegularExpressions;
using System.Linq;
using JetBrains.Annotations;
using UnitsNet.InternalHelpers;
using UnitsNet.Units;

// ReSharper disable once CheckNamespace
Expand Down Expand Up @@ -87,6 +88,7 @@ static AmplitudeRatio()
/// <param name="numericValue">The numeric value to contruct this quantity with.</param>
/// <param name="unit">The unit representation to contruct this quantity with.</param>
/// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
private
#else
Expand All @@ -97,7 +99,7 @@ static AmplitudeRatio()
if(unit == AmplitudeRatioUnit.Undefined)
throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));

_value = numericValue;
_value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
_unit = unit;
}

Expand Down Expand Up @@ -158,6 +160,7 @@ public static BaseDimensions BaseDimensions
/// <summary>
/// Get AmplitudeRatio from DecibelMicrovolts.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmplitudeRatio FromDecibelMicrovolts(double decibelmicrovolts)
Expand All @@ -172,6 +175,7 @@ public static AmplitudeRatio FromDecibelMicrovolts(QuantityValue decibelmicrovol
/// <summary>
/// Get AmplitudeRatio from DecibelMillivolts.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmplitudeRatio FromDecibelMillivolts(double decibelmillivolts)
Expand All @@ -186,6 +190,7 @@ public static AmplitudeRatio FromDecibelMillivolts(QuantityValue decibelmillivol
/// <summary>
/// Get AmplitudeRatio from DecibelsUnloaded.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmplitudeRatio FromDecibelsUnloaded(double decibelsunloaded)
Expand All @@ -200,6 +205,7 @@ public static AmplitudeRatio FromDecibelsUnloaded(QuantityValue decibelsunloaded
/// <summary>
/// Get AmplitudeRatio from DecibelVolts.
/// </summary>
/// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
#if WINDOWS_UWP
[Windows.Foundation.Metadata.DefaultOverload]
public static AmplitudeRatio FromDecibelVolts(double decibelvolts)
Expand Down
Loading

0 comments on commit 02ae423

Please sign in to comment.