diff --git a/.gitattributes b/.gitattributes
index 443c437442..72b8ab0ea9 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -20,27 +20,9 @@
*.filters text eol=crlf
*.vcxitems text eol=crlf
-
-#*.sln merge=binary
-#*.csproj merge=binary
-#*.vbproj merge=binary
-#*.vcxproj merge=binary
-#*.vcproj merge=binary
-#*.dbproj merge=binary
-#*.fsproj merge=binary
-#*.lsproj merge=binary
-#*.wixproj merge=binary
-#*.modelproj merge=binary
-#*.sqlproj merge=binary
-#*.wwaproj merge=binary
-
-#*.xproj merge=binary
-#*.props merge=binary
-#*.filters merge=binary
-#*.vcxitems merge=binary
-
# C#
-*.cs diff=csharp
+*.cs diff=csharp
+*.g.cs linguist-generated
# Powershell
*.ps1 text eol=crlf
diff --git a/Build/build-functions.psm1 b/Build/build-functions.psm1
index 6f58691d85..5ff85c1875 100644
--- a/Build/build-functions.psm1
+++ b/Build/build-functions.psm1
@@ -101,7 +101,7 @@ function Start-PackNugets {
}
write-host -foreground yellow "WindowsRuntimeComponent project not yet supported by dotnet CLI, using nuget.exe instead"
- & $nuget pack "$root\UnitsNet.WindowsRuntimeComponent\UnitsNet.WindowsRuntimeComponent.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir" -Symbols
+ & $nuget pack "$root\UnitsNet.WindowsRuntimeComponent\UnitsNet.WindowsRuntimeComponent.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir"
write-host -foreground blue "Pack nugets...END`n"
}
diff --git a/UnitsNet.Serialization.JsonNet/UnitsNet.Serialization.JsonNet.Common.props b/UnitsNet.Serialization.JsonNet/UnitsNet.Serialization.JsonNet.Common.props
index 2854b8b1cb..3c59dfcb57 100644
--- a/UnitsNet.Serialization.JsonNet/UnitsNet.Serialization.JsonNet.Common.props
+++ b/UnitsNet.Serialization.JsonNet/UnitsNet.Serialization.JsonNet.Common.props
@@ -7,8 +7,6 @@
Units.NET Serialization with Json.NET
A helper library for serializing and deserializing types in Units.NET using Json.NET.
Copyright (c) 2015 Andreas Gullberg Larsen
- true
- true
true
https://github.com/angularsen/UnitsNet
https://raw.githubusercontent.com/angularsen/UnitsNet/ce85185429be345d77eb2ce09c99d59cc9ab8aed/Docs/Images/logo-32.png
@@ -23,11 +21,17 @@
netstandard2.0;net40
UnitsNet.Serialization.JsonNet
CS1701;CS1702;CS1705;CS0618
+
+
+ true
+ true
+ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
+
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/.gitignore b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/.gitignore
deleted file mode 100644
index ccb86a88b8..0000000000
--- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-*.g.cs
-!Information.WindowsRuntimeComponent.g.cs
-!Length.WindowsRuntimeComponent.g.cs
-!Level.WindowsRuntimeComponent.g.cs
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Acceleration.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Acceleration.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..eb339e199a
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Acceleration.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,774 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Acceleration, in physics, is the rate at which the velocity of an object changes over time. An object's acceleration is the net result of any and all forces acting on the object, as described by Newton's Second Law. The SI unit for acceleration is the Meter per second squared (m/s²). Accelerations are vector quantities (they have magnitude and direction) and add according to the parallelogram law. As a vector, the calculated net force is equal to the product of the object's mass (a scalar quantity) and the acceleration.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Acceleration : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly AccelerationUnit? _unit;
+
+ static Acceleration()
+ {
+ BaseDimensions = new BaseDimensions(1, 0, -2, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit MeterPerSecondSquared.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Acceleration()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Acceleration(double numericValue, AccelerationUnit unit)
+ {
+ if(unit == AccelerationUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Acceleration, which is MeterPerSecondSquared. All conversions go via this value.
+ ///
+ public static AccelerationUnit BaseUnit => AccelerationUnit.MeterPerSecondSquared;
+
+ ///
+ /// Represents the largest possible value of Acceleration
+ ///
+ public static Acceleration MaxValue => new Acceleration(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Acceleration
+ ///
+ public static Acceleration MinValue => new Acceleration(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Acceleration;
+
+ ///
+ /// All units of measurement for the Acceleration quantity.
+ ///
+ public static AccelerationUnit[] Units { get; } = Enum.GetValues(typeof(AccelerationUnit)).Cast().Except(new AccelerationUnit[]{ AccelerationUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit MeterPerSecondSquared.
+ ///
+ public static Acceleration Zero => new Acceleration(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public AccelerationUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Acceleration.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Acceleration.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Acceleration in CentimetersPerSecondSquared.
+ ///
+ public double CentimetersPerSecondSquared => As(AccelerationUnit.CentimeterPerSecondSquared);
+
+ ///
+ /// Get Acceleration in DecimetersPerSecondSquared.
+ ///
+ public double DecimetersPerSecondSquared => As(AccelerationUnit.DecimeterPerSecondSquared);
+
+ ///
+ /// Get Acceleration in FeetPerSecondSquared.
+ ///
+ public double FeetPerSecondSquared => As(AccelerationUnit.FootPerSecondSquared);
+
+ ///
+ /// Get Acceleration in InchesPerSecondSquared.
+ ///
+ public double InchesPerSecondSquared => As(AccelerationUnit.InchPerSecondSquared);
+
+ ///
+ /// Get Acceleration in KilometersPerSecondSquared.
+ ///
+ public double KilometersPerSecondSquared => As(AccelerationUnit.KilometerPerSecondSquared);
+
+ ///
+ /// Get Acceleration in KnotsPerHour.
+ ///
+ public double KnotsPerHour => As(AccelerationUnit.KnotPerHour);
+
+ ///
+ /// Get Acceleration in KnotsPerMinute.
+ ///
+ public double KnotsPerMinute => As(AccelerationUnit.KnotPerMinute);
+
+ ///
+ /// Get Acceleration in KnotsPerSecond.
+ ///
+ public double KnotsPerSecond => As(AccelerationUnit.KnotPerSecond);
+
+ ///
+ /// Get Acceleration in MetersPerSecondSquared.
+ ///
+ public double MetersPerSecondSquared => As(AccelerationUnit.MeterPerSecondSquared);
+
+ ///
+ /// Get Acceleration in MicrometersPerSecondSquared.
+ ///
+ public double MicrometersPerSecondSquared => As(AccelerationUnit.MicrometerPerSecondSquared);
+
+ ///
+ /// Get Acceleration in MillimetersPerSecondSquared.
+ ///
+ public double MillimetersPerSecondSquared => As(AccelerationUnit.MillimeterPerSecondSquared);
+
+ ///
+ /// Get Acceleration in NanometersPerSecondSquared.
+ ///
+ public double NanometersPerSecondSquared => As(AccelerationUnit.NanometerPerSecondSquared);
+
+ ///
+ /// Get Acceleration in StandardGravity.
+ ///
+ public double StandardGravity => As(AccelerationUnit.StandardGravity);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(AccelerationUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(AccelerationUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Acceleration from CentimetersPerSecondSquared.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromCentimetersPerSecondSquared(double centimeterspersecondsquared)
+ {
+ double value = (double) centimeterspersecondsquared;
+ return new Acceleration(value, AccelerationUnit.CentimeterPerSecondSquared);
+ }
+ ///
+ /// Get Acceleration from DecimetersPerSecondSquared.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromDecimetersPerSecondSquared(double decimeterspersecondsquared)
+ {
+ double value = (double) decimeterspersecondsquared;
+ return new Acceleration(value, AccelerationUnit.DecimeterPerSecondSquared);
+ }
+ ///
+ /// Get Acceleration from FeetPerSecondSquared.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromFeetPerSecondSquared(double feetpersecondsquared)
+ {
+ double value = (double) feetpersecondsquared;
+ return new Acceleration(value, AccelerationUnit.FootPerSecondSquared);
+ }
+ ///
+ /// Get Acceleration from InchesPerSecondSquared.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromInchesPerSecondSquared(double inchespersecondsquared)
+ {
+ double value = (double) inchespersecondsquared;
+ return new Acceleration(value, AccelerationUnit.InchPerSecondSquared);
+ }
+ ///
+ /// Get Acceleration from KilometersPerSecondSquared.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromKilometersPerSecondSquared(double kilometerspersecondsquared)
+ {
+ double value = (double) kilometerspersecondsquared;
+ return new Acceleration(value, AccelerationUnit.KilometerPerSecondSquared);
+ }
+ ///
+ /// Get Acceleration from KnotsPerHour.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromKnotsPerHour(double knotsperhour)
+ {
+ double value = (double) knotsperhour;
+ return new Acceleration(value, AccelerationUnit.KnotPerHour);
+ }
+ ///
+ /// Get Acceleration from KnotsPerMinute.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromKnotsPerMinute(double knotsperminute)
+ {
+ double value = (double) knotsperminute;
+ return new Acceleration(value, AccelerationUnit.KnotPerMinute);
+ }
+ ///
+ /// Get Acceleration from KnotsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromKnotsPerSecond(double knotspersecond)
+ {
+ double value = (double) knotspersecond;
+ return new Acceleration(value, AccelerationUnit.KnotPerSecond);
+ }
+ ///
+ /// Get Acceleration from MetersPerSecondSquared.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromMetersPerSecondSquared(double meterspersecondsquared)
+ {
+ double value = (double) meterspersecondsquared;
+ return new Acceleration(value, AccelerationUnit.MeterPerSecondSquared);
+ }
+ ///
+ /// Get Acceleration from MicrometersPerSecondSquared.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromMicrometersPerSecondSquared(double micrometerspersecondsquared)
+ {
+ double value = (double) micrometerspersecondsquared;
+ return new Acceleration(value, AccelerationUnit.MicrometerPerSecondSquared);
+ }
+ ///
+ /// Get Acceleration from MillimetersPerSecondSquared.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromMillimetersPerSecondSquared(double millimeterspersecondsquared)
+ {
+ double value = (double) millimeterspersecondsquared;
+ return new Acceleration(value, AccelerationUnit.MillimeterPerSecondSquared);
+ }
+ ///
+ /// Get Acceleration from NanometersPerSecondSquared.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromNanometersPerSecondSquared(double nanometerspersecondsquared)
+ {
+ double value = (double) nanometerspersecondsquared;
+ return new Acceleration(value, AccelerationUnit.NanometerPerSecondSquared);
+ }
+ ///
+ /// Get Acceleration from StandardGravity.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Acceleration FromStandardGravity(double standardgravity)
+ {
+ double value = (double) standardgravity;
+ return new Acceleration(value, AccelerationUnit.StandardGravity);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Acceleration unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Acceleration From(double value, AccelerationUnit fromUnit)
+ {
+ return new Acceleration((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Acceleration Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Acceleration result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Acceleration result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static AccelerationUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static AccelerationUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out AccelerationUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out AccelerationUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Acceleration)) throw new ArgumentException("Expected type Acceleration.", nameof(obj));
+
+ return CompareTo((Acceleration)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Acceleration other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Acceleration within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Acceleration other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Acceleration.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(AccelerationUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Acceleration to another Acceleration with the unit representation .
+ ///
+ /// A Acceleration with the specified unit.
+ public Acceleration ToUnit(AccelerationUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Acceleration(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case AccelerationUnit.CentimeterPerSecondSquared: return (_value) * 1e-2d;
+ case AccelerationUnit.DecimeterPerSecondSquared: return (_value) * 1e-1d;
+ case AccelerationUnit.FootPerSecondSquared: return _value*0.304800;
+ case AccelerationUnit.InchPerSecondSquared: return _value*0.0254;
+ case AccelerationUnit.KilometerPerSecondSquared: return (_value) * 1e3d;
+ case AccelerationUnit.KnotPerHour: return _value*0.5144444444444/3600;
+ case AccelerationUnit.KnotPerMinute: return _value*0.5144444444444/60;
+ case AccelerationUnit.KnotPerSecond: return _value*0.5144444444444;
+ case AccelerationUnit.MeterPerSecondSquared: return _value;
+ case AccelerationUnit.MicrometerPerSecondSquared: return (_value) * 1e-6d;
+ case AccelerationUnit.MillimeterPerSecondSquared: return (_value) * 1e-3d;
+ case AccelerationUnit.NanometerPerSecondSquared: return (_value) * 1e-9d;
+ case AccelerationUnit.StandardGravity: return _value*9.80665;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(AccelerationUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case AccelerationUnit.CentimeterPerSecondSquared: return (baseUnitValue) / 1e-2d;
+ case AccelerationUnit.DecimeterPerSecondSquared: return (baseUnitValue) / 1e-1d;
+ case AccelerationUnit.FootPerSecondSquared: return baseUnitValue/0.304800;
+ case AccelerationUnit.InchPerSecondSquared: return baseUnitValue/0.0254;
+ case AccelerationUnit.KilometerPerSecondSquared: return (baseUnitValue) / 1e3d;
+ case AccelerationUnit.KnotPerHour: return baseUnitValue/0.5144444444444*3600;
+ case AccelerationUnit.KnotPerMinute: return baseUnitValue/0.5144444444444*60;
+ case AccelerationUnit.KnotPerSecond: return baseUnitValue/0.5144444444444;
+ case AccelerationUnit.MeterPerSecondSquared: return baseUnitValue;
+ case AccelerationUnit.MicrometerPerSecondSquared: return (baseUnitValue) / 1e-6d;
+ case AccelerationUnit.MillimeterPerSecondSquared: return (baseUnitValue) / 1e-3d;
+ case AccelerationUnit.NanometerPerSecondSquared: return (baseUnitValue) / 1e-9d;
+ case AccelerationUnit.StandardGravity: return baseUnitValue/9.80665;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AmountOfSubstance.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AmountOfSubstance.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..ce290025ca
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AmountOfSubstance.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,791 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Mole is the amount of substance containing Avagadro's Number (6.02 x 10 ^ 23) of real particles such as molecules,atoms, ions or radicals.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class AmountOfSubstance : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly AmountOfSubstanceUnit? _unit;
+
+ static AmountOfSubstance()
+ {
+ BaseDimensions = new BaseDimensions(0, 0, 0, 0, 0, 1, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Mole.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public AmountOfSubstance()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private AmountOfSubstance(double numericValue, AmountOfSubstanceUnit unit)
+ {
+ if(unit == AmountOfSubstanceUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of AmountOfSubstance, which is Mole. All conversions go via this value.
+ ///
+ public static AmountOfSubstanceUnit BaseUnit => AmountOfSubstanceUnit.Mole;
+
+ ///
+ /// Represents the largest possible value of AmountOfSubstance
+ ///
+ public static AmountOfSubstance MaxValue => new AmountOfSubstance(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of AmountOfSubstance
+ ///
+ public static AmountOfSubstance MinValue => new AmountOfSubstance(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.AmountOfSubstance;
+
+ ///
+ /// All units of measurement for the AmountOfSubstance quantity.
+ ///
+ public static AmountOfSubstanceUnit[] Units { get; } = Enum.GetValues(typeof(AmountOfSubstanceUnit)).Cast().Except(new AmountOfSubstanceUnit[]{ AmountOfSubstanceUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Mole.
+ ///
+ public static AmountOfSubstance Zero => new AmountOfSubstance(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public AmountOfSubstanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => AmountOfSubstance.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => AmountOfSubstance.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get AmountOfSubstance in Centimoles.
+ ///
+ public double Centimoles => As(AmountOfSubstanceUnit.Centimole);
+
+ ///
+ /// Get AmountOfSubstance in CentipoundMoles.
+ ///
+ public double CentipoundMoles => As(AmountOfSubstanceUnit.CentipoundMole);
+
+ ///
+ /// Get AmountOfSubstance in Decimoles.
+ ///
+ public double Decimoles => As(AmountOfSubstanceUnit.Decimole);
+
+ ///
+ /// Get AmountOfSubstance in DecipoundMoles.
+ ///
+ public double DecipoundMoles => As(AmountOfSubstanceUnit.DecipoundMole);
+
+ ///
+ /// Get AmountOfSubstance in Kilomoles.
+ ///
+ public double Kilomoles => As(AmountOfSubstanceUnit.Kilomole);
+
+ ///
+ /// Get AmountOfSubstance in KilopoundMoles.
+ ///
+ public double KilopoundMoles => As(AmountOfSubstanceUnit.KilopoundMole);
+
+ ///
+ /// Get AmountOfSubstance in Micromoles.
+ ///
+ public double Micromoles => As(AmountOfSubstanceUnit.Micromole);
+
+ ///
+ /// Get AmountOfSubstance in MicropoundMoles.
+ ///
+ public double MicropoundMoles => As(AmountOfSubstanceUnit.MicropoundMole);
+
+ ///
+ /// Get AmountOfSubstance in Millimoles.
+ ///
+ public double Millimoles => As(AmountOfSubstanceUnit.Millimole);
+
+ ///
+ /// Get AmountOfSubstance in MillipoundMoles.
+ ///
+ public double MillipoundMoles => As(AmountOfSubstanceUnit.MillipoundMole);
+
+ ///
+ /// Get AmountOfSubstance in Moles.
+ ///
+ public double Moles => As(AmountOfSubstanceUnit.Mole);
+
+ ///
+ /// Get AmountOfSubstance in Nanomoles.
+ ///
+ public double Nanomoles => As(AmountOfSubstanceUnit.Nanomole);
+
+ ///
+ /// Get AmountOfSubstance in NanopoundMoles.
+ ///
+ public double NanopoundMoles => As(AmountOfSubstanceUnit.NanopoundMole);
+
+ ///
+ /// Get AmountOfSubstance in PoundMoles.
+ ///
+ public double PoundMoles => As(AmountOfSubstanceUnit.PoundMole);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(AmountOfSubstanceUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(AmountOfSubstanceUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get AmountOfSubstance from Centimoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromCentimoles(double centimoles)
+ {
+ double value = (double) centimoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.Centimole);
+ }
+ ///
+ /// Get AmountOfSubstance from CentipoundMoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromCentipoundMoles(double centipoundmoles)
+ {
+ double value = (double) centipoundmoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.CentipoundMole);
+ }
+ ///
+ /// Get AmountOfSubstance from Decimoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromDecimoles(double decimoles)
+ {
+ double value = (double) decimoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.Decimole);
+ }
+ ///
+ /// Get AmountOfSubstance from DecipoundMoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromDecipoundMoles(double decipoundmoles)
+ {
+ double value = (double) decipoundmoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.DecipoundMole);
+ }
+ ///
+ /// Get AmountOfSubstance from Kilomoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromKilomoles(double kilomoles)
+ {
+ double value = (double) kilomoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.Kilomole);
+ }
+ ///
+ /// Get AmountOfSubstance from KilopoundMoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromKilopoundMoles(double kilopoundmoles)
+ {
+ double value = (double) kilopoundmoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.KilopoundMole);
+ }
+ ///
+ /// Get AmountOfSubstance from Micromoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromMicromoles(double micromoles)
+ {
+ double value = (double) micromoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.Micromole);
+ }
+ ///
+ /// Get AmountOfSubstance from MicropoundMoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromMicropoundMoles(double micropoundmoles)
+ {
+ double value = (double) micropoundmoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.MicropoundMole);
+ }
+ ///
+ /// Get AmountOfSubstance from Millimoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromMillimoles(double millimoles)
+ {
+ double value = (double) millimoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.Millimole);
+ }
+ ///
+ /// Get AmountOfSubstance from MillipoundMoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromMillipoundMoles(double millipoundmoles)
+ {
+ double value = (double) millipoundmoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.MillipoundMole);
+ }
+ ///
+ /// Get AmountOfSubstance from Moles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromMoles(double moles)
+ {
+ double value = (double) moles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.Mole);
+ }
+ ///
+ /// Get AmountOfSubstance from Nanomoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromNanomoles(double nanomoles)
+ {
+ double value = (double) nanomoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.Nanomole);
+ }
+ ///
+ /// Get AmountOfSubstance from NanopoundMoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromNanopoundMoles(double nanopoundmoles)
+ {
+ double value = (double) nanopoundmoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.NanopoundMole);
+ }
+ ///
+ /// Get AmountOfSubstance from PoundMoles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmountOfSubstance FromPoundMoles(double poundmoles)
+ {
+ double value = (double) poundmoles;
+ return new AmountOfSubstance(value, AmountOfSubstanceUnit.PoundMole);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// AmountOfSubstance unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static AmountOfSubstance From(double value, AmountOfSubstanceUnit fromUnit)
+ {
+ return new AmountOfSubstance((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 AmountOfSubstance Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static AmountOfSubstance Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out AmountOfSubstance result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out AmountOfSubstance result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static AmountOfSubstanceUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static AmountOfSubstanceUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out AmountOfSubstanceUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out AmountOfSubstanceUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is AmountOfSubstance)) throw new ArgumentException("Expected type AmountOfSubstance.", nameof(obj));
+
+ return CompareTo((AmountOfSubstance)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(AmountOfSubstance other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another AmountOfSubstance within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(AmountOfSubstance other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current AmountOfSubstance.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(AmountOfSubstanceUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this AmountOfSubstance to another AmountOfSubstance with the unit representation .
+ ///
+ /// A AmountOfSubstance with the specified unit.
+ public AmountOfSubstance ToUnit(AmountOfSubstanceUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new AmountOfSubstance(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case AmountOfSubstanceUnit.Centimole: return (_value) * 1e-2d;
+ case AmountOfSubstanceUnit.CentipoundMole: return (_value*453.59237) * 1e-2d;
+ case AmountOfSubstanceUnit.Decimole: return (_value) * 1e-1d;
+ case AmountOfSubstanceUnit.DecipoundMole: return (_value*453.59237) * 1e-1d;
+ case AmountOfSubstanceUnit.Kilomole: return (_value) * 1e3d;
+ case AmountOfSubstanceUnit.KilopoundMole: return (_value*453.59237) * 1e3d;
+ case AmountOfSubstanceUnit.Micromole: return (_value) * 1e-6d;
+ case AmountOfSubstanceUnit.MicropoundMole: return (_value*453.59237) * 1e-6d;
+ case AmountOfSubstanceUnit.Millimole: return (_value) * 1e-3d;
+ case AmountOfSubstanceUnit.MillipoundMole: return (_value*453.59237) * 1e-3d;
+ case AmountOfSubstanceUnit.Mole: return _value;
+ case AmountOfSubstanceUnit.Nanomole: return (_value) * 1e-9d;
+ case AmountOfSubstanceUnit.NanopoundMole: return (_value*453.59237) * 1e-9d;
+ case AmountOfSubstanceUnit.PoundMole: return _value*453.59237;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(AmountOfSubstanceUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case AmountOfSubstanceUnit.Centimole: return (baseUnitValue) / 1e-2d;
+ case AmountOfSubstanceUnit.CentipoundMole: return (baseUnitValue/453.59237) / 1e-2d;
+ case AmountOfSubstanceUnit.Decimole: return (baseUnitValue) / 1e-1d;
+ case AmountOfSubstanceUnit.DecipoundMole: return (baseUnitValue/453.59237) / 1e-1d;
+ case AmountOfSubstanceUnit.Kilomole: return (baseUnitValue) / 1e3d;
+ case AmountOfSubstanceUnit.KilopoundMole: return (baseUnitValue/453.59237) / 1e3d;
+ case AmountOfSubstanceUnit.Micromole: return (baseUnitValue) / 1e-6d;
+ case AmountOfSubstanceUnit.MicropoundMole: return (baseUnitValue/453.59237) / 1e-6d;
+ case AmountOfSubstanceUnit.Millimole: return (baseUnitValue) / 1e-3d;
+ case AmountOfSubstanceUnit.MillipoundMole: return (baseUnitValue/453.59237) / 1e-3d;
+ case AmountOfSubstanceUnit.Mole: return baseUnitValue;
+ case AmountOfSubstanceUnit.Nanomole: return (baseUnitValue) / 1e-9d;
+ case AmountOfSubstanceUnit.NanopoundMole: return (baseUnitValue/453.59237) / 1e-9d;
+ case AmountOfSubstanceUnit.PoundMole: return baseUnitValue/453.59237;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AmplitudeRatio.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AmplitudeRatio.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..ce45c7407c
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AmplitudeRatio.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,621 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The strength of a signal expressed in decibels (dB) relative to one volt RMS.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class AmplitudeRatio : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly AmplitudeRatioUnit? _unit;
+
+ static AmplitudeRatio()
+ {
+ BaseDimensions = BaseDimensions.Dimensionless;
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit DecibelVolt.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public AmplitudeRatio()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private AmplitudeRatio(double numericValue, AmplitudeRatioUnit unit)
+ {
+ if(unit == AmplitudeRatioUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of AmplitudeRatio, which is DecibelVolt. All conversions go via this value.
+ ///
+ public static AmplitudeRatioUnit BaseUnit => AmplitudeRatioUnit.DecibelVolt;
+
+ ///
+ /// Represents the largest possible value of AmplitudeRatio
+ ///
+ public static AmplitudeRatio MaxValue => new AmplitudeRatio(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of AmplitudeRatio
+ ///
+ public static AmplitudeRatio MinValue => new AmplitudeRatio(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.AmplitudeRatio;
+
+ ///
+ /// All units of measurement for the AmplitudeRatio quantity.
+ ///
+ public static AmplitudeRatioUnit[] Units { get; } = Enum.GetValues(typeof(AmplitudeRatioUnit)).Cast().Except(new AmplitudeRatioUnit[]{ AmplitudeRatioUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit DecibelVolt.
+ ///
+ public static AmplitudeRatio Zero => new AmplitudeRatio(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public AmplitudeRatioUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => AmplitudeRatio.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => AmplitudeRatio.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get AmplitudeRatio in DecibelMicrovolts.
+ ///
+ public double DecibelMicrovolts => As(AmplitudeRatioUnit.DecibelMicrovolt);
+
+ ///
+ /// Get AmplitudeRatio in DecibelMillivolts.
+ ///
+ public double DecibelMillivolts => As(AmplitudeRatioUnit.DecibelMillivolt);
+
+ ///
+ /// Get AmplitudeRatio in DecibelsUnloaded.
+ ///
+ public double DecibelsUnloaded => As(AmplitudeRatioUnit.DecibelUnloaded);
+
+ ///
+ /// Get AmplitudeRatio in DecibelVolts.
+ ///
+ public double DecibelVolts => As(AmplitudeRatioUnit.DecibelVolt);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(AmplitudeRatioUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(AmplitudeRatioUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get AmplitudeRatio from DecibelMicrovolts.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmplitudeRatio FromDecibelMicrovolts(double decibelmicrovolts)
+ {
+ double value = (double) decibelmicrovolts;
+ return new AmplitudeRatio(value, AmplitudeRatioUnit.DecibelMicrovolt);
+ }
+ ///
+ /// Get AmplitudeRatio from DecibelMillivolts.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmplitudeRatio FromDecibelMillivolts(double decibelmillivolts)
+ {
+ double value = (double) decibelmillivolts;
+ return new AmplitudeRatio(value, AmplitudeRatioUnit.DecibelMillivolt);
+ }
+ ///
+ /// Get AmplitudeRatio from DecibelsUnloaded.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmplitudeRatio FromDecibelsUnloaded(double decibelsunloaded)
+ {
+ double value = (double) decibelsunloaded;
+ return new AmplitudeRatio(value, AmplitudeRatioUnit.DecibelUnloaded);
+ }
+ ///
+ /// Get AmplitudeRatio from DecibelVolts.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AmplitudeRatio FromDecibelVolts(double decibelvolts)
+ {
+ double value = (double) decibelvolts;
+ return new AmplitudeRatio(value, AmplitudeRatioUnit.DecibelVolt);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// AmplitudeRatio unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static AmplitudeRatio From(double value, AmplitudeRatioUnit fromUnit)
+ {
+ return new AmplitudeRatio((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static AmplitudeRatio Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out AmplitudeRatio result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out AmplitudeRatio result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static AmplitudeRatioUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static AmplitudeRatioUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out AmplitudeRatioUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out AmplitudeRatioUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is AmplitudeRatio)) throw new ArgumentException("Expected type AmplitudeRatio.", nameof(obj));
+
+ return CompareTo((AmplitudeRatio)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(AmplitudeRatio other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another AmplitudeRatio within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(AmplitudeRatio other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current AmplitudeRatio.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(AmplitudeRatioUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this AmplitudeRatio to another AmplitudeRatio with the unit representation .
+ ///
+ /// A AmplitudeRatio with the specified unit.
+ public AmplitudeRatio ToUnit(AmplitudeRatioUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new AmplitudeRatio(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case AmplitudeRatioUnit.DecibelMicrovolt: return _value - 120;
+ case AmplitudeRatioUnit.DecibelMillivolt: return _value - 60;
+ case AmplitudeRatioUnit.DecibelUnloaded: return _value - 2.218487499;
+ case AmplitudeRatioUnit.DecibelVolt: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(AmplitudeRatioUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case AmplitudeRatioUnit.DecibelMicrovolt: return baseUnitValue + 120;
+ case AmplitudeRatioUnit.DecibelMillivolt: return baseUnitValue + 60;
+ case AmplitudeRatioUnit.DecibelUnloaded: return baseUnitValue + 2.218487499;
+ case AmplitudeRatioUnit.DecibelVolt: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Angle.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Angle.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..d721fd78bb
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Angle.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,791 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In geometry, an angle is the figure formed by two rays, called the sides of the angle, sharing a common endpoint, called the vertex of the angle.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Angle : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly AngleUnit? _unit;
+
+ static Angle()
+ {
+ BaseDimensions = BaseDimensions.Dimensionless;
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Degree.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Angle()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Angle(double numericValue, AngleUnit unit)
+ {
+ if(unit == AngleUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Angle, which is Degree. All conversions go via this value.
+ ///
+ public static AngleUnit BaseUnit => AngleUnit.Degree;
+
+ ///
+ /// Represents the largest possible value of Angle
+ ///
+ public static Angle MaxValue => new Angle(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Angle
+ ///
+ public static Angle MinValue => new Angle(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Angle;
+
+ ///
+ /// All units of measurement for the Angle quantity.
+ ///
+ public static AngleUnit[] Units { get; } = Enum.GetValues(typeof(AngleUnit)).Cast().Except(new AngleUnit[]{ AngleUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Degree.
+ ///
+ public static Angle Zero => new Angle(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public AngleUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Angle.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Angle.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Angle in Arcminutes.
+ ///
+ public double Arcminutes => As(AngleUnit.Arcminute);
+
+ ///
+ /// Get Angle in Arcseconds.
+ ///
+ public double Arcseconds => As(AngleUnit.Arcsecond);
+
+ ///
+ /// Get Angle in Centiradians.
+ ///
+ public double Centiradians => As(AngleUnit.Centiradian);
+
+ ///
+ /// Get Angle in Deciradians.
+ ///
+ public double Deciradians => As(AngleUnit.Deciradian);
+
+ ///
+ /// Get Angle in Degrees.
+ ///
+ public double Degrees => As(AngleUnit.Degree);
+
+ ///
+ /// Get Angle in Gradians.
+ ///
+ public double Gradians => As(AngleUnit.Gradian);
+
+ ///
+ /// Get Angle in Microdegrees.
+ ///
+ public double Microdegrees => As(AngleUnit.Microdegree);
+
+ ///
+ /// Get Angle in Microradians.
+ ///
+ public double Microradians => As(AngleUnit.Microradian);
+
+ ///
+ /// Get Angle in Millidegrees.
+ ///
+ public double Millidegrees => As(AngleUnit.Millidegree);
+
+ ///
+ /// Get Angle in Milliradians.
+ ///
+ public double Milliradians => As(AngleUnit.Milliradian);
+
+ ///
+ /// Get Angle in Nanodegrees.
+ ///
+ public double Nanodegrees => As(AngleUnit.Nanodegree);
+
+ ///
+ /// Get Angle in Nanoradians.
+ ///
+ public double Nanoradians => As(AngleUnit.Nanoradian);
+
+ ///
+ /// Get Angle in Radians.
+ ///
+ public double Radians => As(AngleUnit.Radian);
+
+ ///
+ /// Get Angle in Revolutions.
+ ///
+ public double Revolutions => As(AngleUnit.Revolution);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(AngleUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(AngleUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Angle from Arcminutes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromArcminutes(double arcminutes)
+ {
+ double value = (double) arcminutes;
+ return new Angle(value, AngleUnit.Arcminute);
+ }
+ ///
+ /// Get Angle from Arcseconds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromArcseconds(double arcseconds)
+ {
+ double value = (double) arcseconds;
+ return new Angle(value, AngleUnit.Arcsecond);
+ }
+ ///
+ /// Get Angle from Centiradians.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromCentiradians(double centiradians)
+ {
+ double value = (double) centiradians;
+ return new Angle(value, AngleUnit.Centiradian);
+ }
+ ///
+ /// Get Angle from Deciradians.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromDeciradians(double deciradians)
+ {
+ double value = (double) deciradians;
+ return new Angle(value, AngleUnit.Deciradian);
+ }
+ ///
+ /// Get Angle from Degrees.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromDegrees(double degrees)
+ {
+ double value = (double) degrees;
+ return new Angle(value, AngleUnit.Degree);
+ }
+ ///
+ /// Get Angle from Gradians.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromGradians(double gradians)
+ {
+ double value = (double) gradians;
+ return new Angle(value, AngleUnit.Gradian);
+ }
+ ///
+ /// Get Angle from Microdegrees.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromMicrodegrees(double microdegrees)
+ {
+ double value = (double) microdegrees;
+ return new Angle(value, AngleUnit.Microdegree);
+ }
+ ///
+ /// Get Angle from Microradians.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromMicroradians(double microradians)
+ {
+ double value = (double) microradians;
+ return new Angle(value, AngleUnit.Microradian);
+ }
+ ///
+ /// Get Angle from Millidegrees.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromMillidegrees(double millidegrees)
+ {
+ double value = (double) millidegrees;
+ return new Angle(value, AngleUnit.Millidegree);
+ }
+ ///
+ /// Get Angle from Milliradians.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromMilliradians(double milliradians)
+ {
+ double value = (double) milliradians;
+ return new Angle(value, AngleUnit.Milliradian);
+ }
+ ///
+ /// Get Angle from Nanodegrees.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromNanodegrees(double nanodegrees)
+ {
+ double value = (double) nanodegrees;
+ return new Angle(value, AngleUnit.Nanodegree);
+ }
+ ///
+ /// Get Angle from Nanoradians.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromNanoradians(double nanoradians)
+ {
+ double value = (double) nanoradians;
+ return new Angle(value, AngleUnit.Nanoradian);
+ }
+ ///
+ /// Get Angle from Radians.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromRadians(double radians)
+ {
+ double value = (double) radians;
+ return new Angle(value, AngleUnit.Radian);
+ }
+ ///
+ /// Get Angle from Revolutions.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Angle FromRevolutions(double revolutions)
+ {
+ double value = (double) revolutions;
+ return new Angle(value, AngleUnit.Revolution);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Angle unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Angle From(double value, AngleUnit fromUnit)
+ {
+ return new Angle((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Angle Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Angle result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Angle result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static AngleUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static AngleUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out AngleUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out AngleUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Angle)) throw new ArgumentException("Expected type Angle.", nameof(obj));
+
+ return CompareTo((Angle)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Angle other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Angle within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Angle other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Angle.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(AngleUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Angle to another Angle with the unit representation .
+ ///
+ /// A Angle with the specified unit.
+ public Angle ToUnit(AngleUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Angle(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case AngleUnit.Arcminute: return _value/60;
+ case AngleUnit.Arcsecond: return _value/3600;
+ case AngleUnit.Centiradian: return (_value*180/Math.PI) * 1e-2d;
+ case AngleUnit.Deciradian: return (_value*180/Math.PI) * 1e-1d;
+ case AngleUnit.Degree: return _value;
+ case AngleUnit.Gradian: return _value*0.9;
+ case AngleUnit.Microdegree: return (_value) * 1e-6d;
+ case AngleUnit.Microradian: return (_value*180/Math.PI) * 1e-6d;
+ case AngleUnit.Millidegree: return (_value) * 1e-3d;
+ case AngleUnit.Milliradian: return (_value*180/Math.PI) * 1e-3d;
+ case AngleUnit.Nanodegree: return (_value) * 1e-9d;
+ case AngleUnit.Nanoradian: return (_value*180/Math.PI) * 1e-9d;
+ case AngleUnit.Radian: return _value*180/Math.PI;
+ case AngleUnit.Revolution: return _value*360;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(AngleUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case AngleUnit.Arcminute: return baseUnitValue*60;
+ case AngleUnit.Arcsecond: return baseUnitValue*3600;
+ case AngleUnit.Centiradian: return (baseUnitValue/180*Math.PI) / 1e-2d;
+ case AngleUnit.Deciradian: return (baseUnitValue/180*Math.PI) / 1e-1d;
+ case AngleUnit.Degree: return baseUnitValue;
+ case AngleUnit.Gradian: return baseUnitValue/0.9;
+ case AngleUnit.Microdegree: return (baseUnitValue) / 1e-6d;
+ case AngleUnit.Microradian: return (baseUnitValue/180*Math.PI) / 1e-6d;
+ case AngleUnit.Millidegree: return (baseUnitValue) / 1e-3d;
+ case AngleUnit.Milliradian: return (baseUnitValue/180*Math.PI) / 1e-3d;
+ case AngleUnit.Nanodegree: return (baseUnitValue) / 1e-9d;
+ case AngleUnit.Nanoradian: return (baseUnitValue/180*Math.PI) / 1e-9d;
+ case AngleUnit.Radian: return baseUnitValue/180*Math.PI;
+ case AngleUnit.Revolution: return baseUnitValue/360;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ApparentEnergy.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ApparentEnergy.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..6af6c3626d
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ApparentEnergy.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,604 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// A unit for expressing the integral of apparent power over time, equal to the product of 1 volt-ampere and 1 hour, or to 3600 joules.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ApparentEnergy : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ApparentEnergyUnit? _unit;
+
+ static ApparentEnergy()
+ {
+ BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit VoltampereHour.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ApparentEnergy()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ApparentEnergy(double numericValue, ApparentEnergyUnit unit)
+ {
+ if(unit == ApparentEnergyUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ApparentEnergy, which is VoltampereHour. All conversions go via this value.
+ ///
+ public static ApparentEnergyUnit BaseUnit => ApparentEnergyUnit.VoltampereHour;
+
+ ///
+ /// Represents the largest possible value of ApparentEnergy
+ ///
+ public static ApparentEnergy MaxValue => new ApparentEnergy(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ApparentEnergy
+ ///
+ public static ApparentEnergy MinValue => new ApparentEnergy(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ApparentEnergy;
+
+ ///
+ /// All units of measurement for the ApparentEnergy quantity.
+ ///
+ public static ApparentEnergyUnit[] Units { get; } = Enum.GetValues(typeof(ApparentEnergyUnit)).Cast().Except(new ApparentEnergyUnit[]{ ApparentEnergyUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit VoltampereHour.
+ ///
+ public static ApparentEnergy Zero => new ApparentEnergy(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ApparentEnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ApparentEnergy.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ApparentEnergy.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ApparentEnergy in KilovoltampereHours.
+ ///
+ public double KilovoltampereHours => As(ApparentEnergyUnit.KilovoltampereHour);
+
+ ///
+ /// Get ApparentEnergy in MegavoltampereHours.
+ ///
+ public double MegavoltampereHours => As(ApparentEnergyUnit.MegavoltampereHour);
+
+ ///
+ /// Get ApparentEnergy in VoltampereHours.
+ ///
+ public double VoltampereHours => As(ApparentEnergyUnit.VoltampereHour);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ApparentEnergyUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ApparentEnergyUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ApparentEnergy from KilovoltampereHours.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ApparentEnergy FromKilovoltampereHours(double kilovoltamperehours)
+ {
+ double value = (double) kilovoltamperehours;
+ return new ApparentEnergy(value, ApparentEnergyUnit.KilovoltampereHour);
+ }
+ ///
+ /// Get ApparentEnergy from MegavoltampereHours.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ApparentEnergy FromMegavoltampereHours(double megavoltamperehours)
+ {
+ double value = (double) megavoltamperehours;
+ return new ApparentEnergy(value, ApparentEnergyUnit.MegavoltampereHour);
+ }
+ ///
+ /// Get ApparentEnergy from VoltampereHours.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ApparentEnergy FromVoltampereHours(double voltamperehours)
+ {
+ double value = (double) voltamperehours;
+ return new ApparentEnergy(value, ApparentEnergyUnit.VoltampereHour);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ApparentEnergy unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ApparentEnergy From(double value, ApparentEnergyUnit fromUnit)
+ {
+ return new ApparentEnergy((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ApparentEnergy Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ApparentEnergy Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ApparentEnergy result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ApparentEnergy result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ApparentEnergyUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ApparentEnergyUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ApparentEnergyUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ApparentEnergyUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ApparentEnergy)) throw new ArgumentException("Expected type ApparentEnergy.", nameof(obj));
+
+ return CompareTo((ApparentEnergy)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ApparentEnergy other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ApparentEnergy within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ApparentEnergy other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ApparentEnergy.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ApparentEnergyUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ApparentEnergy to another ApparentEnergy with the unit representation .
+ ///
+ /// A ApparentEnergy with the specified unit.
+ public ApparentEnergy ToUnit(ApparentEnergyUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ApparentEnergy(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ApparentEnergyUnit.KilovoltampereHour: return (_value) * 1e3d;
+ case ApparentEnergyUnit.MegavoltampereHour: return (_value) * 1e6d;
+ case ApparentEnergyUnit.VoltampereHour: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ApparentEnergyUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ApparentEnergyUnit.KilovoltampereHour: return (baseUnitValue) / 1e3d;
+ case ApparentEnergyUnit.MegavoltampereHour: return (baseUnitValue) / 1e6d;
+ case ApparentEnergyUnit.VoltampereHour: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ApparentPower.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ApparentPower.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..3f17f61de0
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ApparentPower.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,621 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Power engineers measure apparent power as the magnitude of the vector sum of active and reactive power. Apparent power is the product of the root-mean-square of voltage and current.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ApparentPower : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ApparentPowerUnit? _unit;
+
+ static ApparentPower()
+ {
+ BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Voltampere.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ApparentPower()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ApparentPower(double numericValue, ApparentPowerUnit unit)
+ {
+ if(unit == ApparentPowerUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ApparentPower, which is Voltampere. All conversions go via this value.
+ ///
+ public static ApparentPowerUnit BaseUnit => ApparentPowerUnit.Voltampere;
+
+ ///
+ /// Represents the largest possible value of ApparentPower
+ ///
+ public static ApparentPower MaxValue => new ApparentPower(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ApparentPower
+ ///
+ public static ApparentPower MinValue => new ApparentPower(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ApparentPower;
+
+ ///
+ /// All units of measurement for the ApparentPower quantity.
+ ///
+ public static ApparentPowerUnit[] Units { get; } = Enum.GetValues(typeof(ApparentPowerUnit)).Cast().Except(new ApparentPowerUnit[]{ ApparentPowerUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Voltampere.
+ ///
+ public static ApparentPower Zero => new ApparentPower(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ApparentPowerUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ApparentPower.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ApparentPower.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ApparentPower in Gigavoltamperes.
+ ///
+ public double Gigavoltamperes => As(ApparentPowerUnit.Gigavoltampere);
+
+ ///
+ /// Get ApparentPower in Kilovoltamperes.
+ ///
+ public double Kilovoltamperes => As(ApparentPowerUnit.Kilovoltampere);
+
+ ///
+ /// Get ApparentPower in Megavoltamperes.
+ ///
+ public double Megavoltamperes => As(ApparentPowerUnit.Megavoltampere);
+
+ ///
+ /// Get ApparentPower in Voltamperes.
+ ///
+ public double Voltamperes => As(ApparentPowerUnit.Voltampere);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ApparentPowerUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ApparentPowerUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ApparentPower from Gigavoltamperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ApparentPower FromGigavoltamperes(double gigavoltamperes)
+ {
+ double value = (double) gigavoltamperes;
+ return new ApparentPower(value, ApparentPowerUnit.Gigavoltampere);
+ }
+ ///
+ /// Get ApparentPower from Kilovoltamperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ApparentPower FromKilovoltamperes(double kilovoltamperes)
+ {
+ double value = (double) kilovoltamperes;
+ return new ApparentPower(value, ApparentPowerUnit.Kilovoltampere);
+ }
+ ///
+ /// Get ApparentPower from Megavoltamperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ApparentPower FromMegavoltamperes(double megavoltamperes)
+ {
+ double value = (double) megavoltamperes;
+ return new ApparentPower(value, ApparentPowerUnit.Megavoltampere);
+ }
+ ///
+ /// Get ApparentPower from Voltamperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ApparentPower FromVoltamperes(double voltamperes)
+ {
+ double value = (double) voltamperes;
+ return new ApparentPower(value, ApparentPowerUnit.Voltampere);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ApparentPower unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ApparentPower From(double value, ApparentPowerUnit fromUnit)
+ {
+ return new ApparentPower((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ApparentPower Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ApparentPower Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ApparentPower result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ApparentPower result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ApparentPowerUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ApparentPowerUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ApparentPowerUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ApparentPowerUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ApparentPower)) throw new ArgumentException("Expected type ApparentPower.", nameof(obj));
+
+ return CompareTo((ApparentPower)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ApparentPower other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ApparentPower within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ApparentPower other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ApparentPower.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ApparentPowerUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ApparentPower to another ApparentPower with the unit representation .
+ ///
+ /// A ApparentPower with the specified unit.
+ public ApparentPower ToUnit(ApparentPowerUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ApparentPower(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ApparentPowerUnit.Gigavoltampere: return (_value) * 1e9d;
+ case ApparentPowerUnit.Kilovoltampere: return (_value) * 1e3d;
+ case ApparentPowerUnit.Megavoltampere: return (_value) * 1e6d;
+ case ApparentPowerUnit.Voltampere: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ApparentPowerUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ApparentPowerUnit.Gigavoltampere: return (baseUnitValue) / 1e9d;
+ case ApparentPowerUnit.Kilovoltampere: return (baseUnitValue) / 1e3d;
+ case ApparentPowerUnit.Megavoltampere: return (baseUnitValue) / 1e6d;
+ case ApparentPowerUnit.Voltampere: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Area.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Area.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..7ea98e2ea6
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Area.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,774 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Area is a quantity that expresses the extent of a two-dimensional surface or shape, or planar lamina, in the plane. Area can be understood as the amount of material with a given thickness that would be necessary to fashion a model of the shape, or the amount of paint necessary to cover the surface with a single coat.[1] It is the two-dimensional analog of the length of a curve (a one-dimensional concept) or the volume of a solid (a three-dimensional concept).
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Area : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly AreaUnit? _unit;
+
+ static Area()
+ {
+ BaseDimensions = new BaseDimensions(2, 0, 0, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit SquareMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Area()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Area(double numericValue, AreaUnit unit)
+ {
+ if(unit == AreaUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Area, which is SquareMeter. All conversions go via this value.
+ ///
+ public static AreaUnit BaseUnit => AreaUnit.SquareMeter;
+
+ ///
+ /// Represents the largest possible value of Area
+ ///
+ public static Area MaxValue => new Area(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Area
+ ///
+ public static Area MinValue => new Area(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Area;
+
+ ///
+ /// All units of measurement for the Area quantity.
+ ///
+ public static AreaUnit[] Units { get; } = Enum.GetValues(typeof(AreaUnit)).Cast().Except(new AreaUnit[]{ AreaUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit SquareMeter.
+ ///
+ public static Area Zero => new Area(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public AreaUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Area.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Area.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Area in Acres.
+ ///
+ public double Acres => As(AreaUnit.Acre);
+
+ ///
+ /// Get Area in Hectares.
+ ///
+ public double Hectares => As(AreaUnit.Hectare);
+
+ ///
+ /// Get Area in SquareCentimeters.
+ ///
+ public double SquareCentimeters => As(AreaUnit.SquareCentimeter);
+
+ ///
+ /// Get Area in SquareDecimeters.
+ ///
+ public double SquareDecimeters => As(AreaUnit.SquareDecimeter);
+
+ ///
+ /// Get Area in SquareFeet.
+ ///
+ public double SquareFeet => As(AreaUnit.SquareFoot);
+
+ ///
+ /// Get Area in SquareInches.
+ ///
+ public double SquareInches => As(AreaUnit.SquareInch);
+
+ ///
+ /// Get Area in SquareKilometers.
+ ///
+ public double SquareKilometers => As(AreaUnit.SquareKilometer);
+
+ ///
+ /// Get Area in SquareMeters.
+ ///
+ public double SquareMeters => As(AreaUnit.SquareMeter);
+
+ ///
+ /// Get Area in SquareMicrometers.
+ ///
+ public double SquareMicrometers => As(AreaUnit.SquareMicrometer);
+
+ ///
+ /// Get Area in SquareMiles.
+ ///
+ public double SquareMiles => As(AreaUnit.SquareMile);
+
+ ///
+ /// Get Area in SquareMillimeters.
+ ///
+ public double SquareMillimeters => As(AreaUnit.SquareMillimeter);
+
+ ///
+ /// Get Area in SquareYards.
+ ///
+ public double SquareYards => As(AreaUnit.SquareYard);
+
+ ///
+ /// Get Area in UsSurveySquareFeet.
+ ///
+ public double UsSurveySquareFeet => As(AreaUnit.UsSurveySquareFoot);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(AreaUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(AreaUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Area from Acres.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromAcres(double acres)
+ {
+ double value = (double) acres;
+ return new Area(value, AreaUnit.Acre);
+ }
+ ///
+ /// Get Area from Hectares.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromHectares(double hectares)
+ {
+ double value = (double) hectares;
+ return new Area(value, AreaUnit.Hectare);
+ }
+ ///
+ /// Get Area from SquareCentimeters.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromSquareCentimeters(double squarecentimeters)
+ {
+ double value = (double) squarecentimeters;
+ return new Area(value, AreaUnit.SquareCentimeter);
+ }
+ ///
+ /// Get Area from SquareDecimeters.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromSquareDecimeters(double squaredecimeters)
+ {
+ double value = (double) squaredecimeters;
+ return new Area(value, AreaUnit.SquareDecimeter);
+ }
+ ///
+ /// Get Area from SquareFeet.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromSquareFeet(double squarefeet)
+ {
+ double value = (double) squarefeet;
+ return new Area(value, AreaUnit.SquareFoot);
+ }
+ ///
+ /// Get Area from SquareInches.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromSquareInches(double squareinches)
+ {
+ double value = (double) squareinches;
+ return new Area(value, AreaUnit.SquareInch);
+ }
+ ///
+ /// Get Area from SquareKilometers.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromSquareKilometers(double squarekilometers)
+ {
+ double value = (double) squarekilometers;
+ return new Area(value, AreaUnit.SquareKilometer);
+ }
+ ///
+ /// Get Area from SquareMeters.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromSquareMeters(double squaremeters)
+ {
+ double value = (double) squaremeters;
+ return new Area(value, AreaUnit.SquareMeter);
+ }
+ ///
+ /// Get Area from SquareMicrometers.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromSquareMicrometers(double squaremicrometers)
+ {
+ double value = (double) squaremicrometers;
+ return new Area(value, AreaUnit.SquareMicrometer);
+ }
+ ///
+ /// Get Area from SquareMiles.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromSquareMiles(double squaremiles)
+ {
+ double value = (double) squaremiles;
+ return new Area(value, AreaUnit.SquareMile);
+ }
+ ///
+ /// Get Area from SquareMillimeters.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromSquareMillimeters(double squaremillimeters)
+ {
+ double value = (double) squaremillimeters;
+ return new Area(value, AreaUnit.SquareMillimeter);
+ }
+ ///
+ /// Get Area from SquareYards.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromSquareYards(double squareyards)
+ {
+ double value = (double) squareyards;
+ return new Area(value, AreaUnit.SquareYard);
+ }
+ ///
+ /// Get Area from UsSurveySquareFeet.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Area FromUsSurveySquareFeet(double ussurveysquarefeet)
+ {
+ double value = (double) ussurveysquarefeet;
+ return new Area(value, AreaUnit.UsSurveySquareFoot);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Area unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Area From(double value, AreaUnit fromUnit)
+ {
+ return new Area((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Area Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Area result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Area result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static AreaUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static AreaUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out AreaUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out AreaUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Area)) throw new ArgumentException("Expected type Area.", nameof(obj));
+
+ return CompareTo((Area)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Area other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Area within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Area other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Area.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(AreaUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Area to another Area with the unit representation .
+ ///
+ /// A Area with the specified unit.
+ public Area ToUnit(AreaUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Area(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case AreaUnit.Acre: return _value*4046.85642;
+ case AreaUnit.Hectare: return _value*1e4;
+ case AreaUnit.SquareCentimeter: return _value*1e-4;
+ case AreaUnit.SquareDecimeter: return _value*1e-2;
+ case AreaUnit.SquareFoot: return _value*0.092903;
+ case AreaUnit.SquareInch: return _value*0.00064516;
+ case AreaUnit.SquareKilometer: return _value*1e6;
+ case AreaUnit.SquareMeter: return _value;
+ case AreaUnit.SquareMicrometer: return _value*1e-12;
+ case AreaUnit.SquareMile: return _value*2.59e6;
+ case AreaUnit.SquareMillimeter: return _value*1e-6;
+ case AreaUnit.SquareYard: return _value*0.836127;
+ case AreaUnit.UsSurveySquareFoot: return _value*0.09290341161;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(AreaUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case AreaUnit.Acre: return baseUnitValue/4046.85642;
+ case AreaUnit.Hectare: return baseUnitValue/1e4;
+ case AreaUnit.SquareCentimeter: return baseUnitValue/1e-4;
+ case AreaUnit.SquareDecimeter: return baseUnitValue/1e-2;
+ case AreaUnit.SquareFoot: return baseUnitValue/0.092903;
+ case AreaUnit.SquareInch: return baseUnitValue/0.00064516;
+ case AreaUnit.SquareKilometer: return baseUnitValue/1e6;
+ case AreaUnit.SquareMeter: return baseUnitValue;
+ case AreaUnit.SquareMicrometer: return baseUnitValue/1e-12;
+ case AreaUnit.SquareMile: return baseUnitValue/2.59e6;
+ case AreaUnit.SquareMillimeter: return baseUnitValue/1e-6;
+ case AreaUnit.SquareYard: return baseUnitValue/0.836127;
+ case AreaUnit.UsSurveySquareFoot: return baseUnitValue/0.09290341161;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AreaDensity.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AreaDensity.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..f13fa07cad
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AreaDensity.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,570 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The area density of a two-dimensional object is calculated as the mass per unit area.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class AreaDensity : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly AreaDensityUnit? _unit;
+
+ static AreaDensity()
+ {
+ BaseDimensions = new BaseDimensions(-2, 1, 0, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit KilogramPerSquareMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public AreaDensity()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private AreaDensity(double numericValue, AreaDensityUnit unit)
+ {
+ if(unit == AreaDensityUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of AreaDensity, which is KilogramPerSquareMeter. All conversions go via this value.
+ ///
+ public static AreaDensityUnit BaseUnit => AreaDensityUnit.KilogramPerSquareMeter;
+
+ ///
+ /// Represents the largest possible value of AreaDensity
+ ///
+ public static AreaDensity MaxValue => new AreaDensity(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of AreaDensity
+ ///
+ public static AreaDensity MinValue => new AreaDensity(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.AreaDensity;
+
+ ///
+ /// All units of measurement for the AreaDensity quantity.
+ ///
+ public static AreaDensityUnit[] Units { get; } = Enum.GetValues(typeof(AreaDensityUnit)).Cast().Except(new AreaDensityUnit[]{ AreaDensityUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerSquareMeter.
+ ///
+ public static AreaDensity Zero => new AreaDensity(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public AreaDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => AreaDensity.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => AreaDensity.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get AreaDensity in KilogramsPerSquareMeter.
+ ///
+ public double KilogramsPerSquareMeter => As(AreaDensityUnit.KilogramPerSquareMeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(AreaDensityUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(AreaDensityUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get AreaDensity from KilogramsPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AreaDensity FromKilogramsPerSquareMeter(double kilogramspersquaremeter)
+ {
+ double value = (double) kilogramspersquaremeter;
+ return new AreaDensity(value, AreaDensityUnit.KilogramPerSquareMeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// AreaDensity unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static AreaDensity From(double value, AreaDensityUnit fromUnit)
+ {
+ return new AreaDensity((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 AreaDensity Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static AreaDensity Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out AreaDensity result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out AreaDensity result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static AreaDensityUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static AreaDensityUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out AreaDensityUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out AreaDensityUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is AreaDensity)) throw new ArgumentException("Expected type AreaDensity.", nameof(obj));
+
+ return CompareTo((AreaDensity)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(AreaDensity other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another AreaDensity within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(AreaDensity other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current AreaDensity.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(AreaDensityUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this AreaDensity to another AreaDensity with the unit representation .
+ ///
+ /// A AreaDensity with the specified unit.
+ public AreaDensity ToUnit(AreaDensityUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new AreaDensity(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case AreaDensityUnit.KilogramPerSquareMeter: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(AreaDensityUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case AreaDensityUnit.KilogramPerSquareMeter: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AreaMomentOfInertia.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AreaMomentOfInertia.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..40ba8402c8
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/AreaMomentOfInertia.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,655 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// A geometric property of an area that reflects how its points are distributed with regard to an axis.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class AreaMomentOfInertia : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly AreaMomentOfInertiaUnit? _unit;
+
+ static AreaMomentOfInertia()
+ {
+ BaseDimensions = new BaseDimensions(4, 0, 0, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit MeterToTheFourth.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public AreaMomentOfInertia()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private AreaMomentOfInertia(double numericValue, AreaMomentOfInertiaUnit unit)
+ {
+ if(unit == AreaMomentOfInertiaUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of AreaMomentOfInertia, which is MeterToTheFourth. All conversions go via this value.
+ ///
+ public static AreaMomentOfInertiaUnit BaseUnit => AreaMomentOfInertiaUnit.MeterToTheFourth;
+
+ ///
+ /// Represents the largest possible value of AreaMomentOfInertia
+ ///
+ public static AreaMomentOfInertia MaxValue => new AreaMomentOfInertia(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of AreaMomentOfInertia
+ ///
+ public static AreaMomentOfInertia MinValue => new AreaMomentOfInertia(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.AreaMomentOfInertia;
+
+ ///
+ /// All units of measurement for the AreaMomentOfInertia quantity.
+ ///
+ public static AreaMomentOfInertiaUnit[] Units { get; } = Enum.GetValues(typeof(AreaMomentOfInertiaUnit)).Cast().Except(new AreaMomentOfInertiaUnit[]{ AreaMomentOfInertiaUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit MeterToTheFourth.
+ ///
+ public static AreaMomentOfInertia Zero => new AreaMomentOfInertia(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public AreaMomentOfInertiaUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => AreaMomentOfInertia.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => AreaMomentOfInertia.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get AreaMomentOfInertia in CentimetersToTheFourth.
+ ///
+ public double CentimetersToTheFourth => As(AreaMomentOfInertiaUnit.CentimeterToTheFourth);
+
+ ///
+ /// Get AreaMomentOfInertia in DecimetersToTheFourth.
+ ///
+ public double DecimetersToTheFourth => As(AreaMomentOfInertiaUnit.DecimeterToTheFourth);
+
+ ///
+ /// Get AreaMomentOfInertia in FeetToTheFourth.
+ ///
+ public double FeetToTheFourth => As(AreaMomentOfInertiaUnit.FootToTheFourth);
+
+ ///
+ /// Get AreaMomentOfInertia in InchesToTheFourth.
+ ///
+ public double InchesToTheFourth => As(AreaMomentOfInertiaUnit.InchToTheFourth);
+
+ ///
+ /// Get AreaMomentOfInertia in MetersToTheFourth.
+ ///
+ public double MetersToTheFourth => As(AreaMomentOfInertiaUnit.MeterToTheFourth);
+
+ ///
+ /// Get AreaMomentOfInertia in MillimetersToTheFourth.
+ ///
+ public double MillimetersToTheFourth => As(AreaMomentOfInertiaUnit.MillimeterToTheFourth);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(AreaMomentOfInertiaUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(AreaMomentOfInertiaUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get AreaMomentOfInertia from CentimetersToTheFourth.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AreaMomentOfInertia FromCentimetersToTheFourth(double centimeterstothefourth)
+ {
+ double value = (double) centimeterstothefourth;
+ return new AreaMomentOfInertia(value, AreaMomentOfInertiaUnit.CentimeterToTheFourth);
+ }
+ ///
+ /// Get AreaMomentOfInertia from DecimetersToTheFourth.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AreaMomentOfInertia FromDecimetersToTheFourth(double decimeterstothefourth)
+ {
+ double value = (double) decimeterstothefourth;
+ return new AreaMomentOfInertia(value, AreaMomentOfInertiaUnit.DecimeterToTheFourth);
+ }
+ ///
+ /// Get AreaMomentOfInertia from FeetToTheFourth.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AreaMomentOfInertia FromFeetToTheFourth(double feettothefourth)
+ {
+ double value = (double) feettothefourth;
+ return new AreaMomentOfInertia(value, AreaMomentOfInertiaUnit.FootToTheFourth);
+ }
+ ///
+ /// Get AreaMomentOfInertia from InchesToTheFourth.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AreaMomentOfInertia FromInchesToTheFourth(double inchestothefourth)
+ {
+ double value = (double) inchestothefourth;
+ return new AreaMomentOfInertia(value, AreaMomentOfInertiaUnit.InchToTheFourth);
+ }
+ ///
+ /// Get AreaMomentOfInertia from MetersToTheFourth.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AreaMomentOfInertia FromMetersToTheFourth(double meterstothefourth)
+ {
+ double value = (double) meterstothefourth;
+ return new AreaMomentOfInertia(value, AreaMomentOfInertiaUnit.MeterToTheFourth);
+ }
+ ///
+ /// Get AreaMomentOfInertia from MillimetersToTheFourth.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static AreaMomentOfInertia FromMillimetersToTheFourth(double millimeterstothefourth)
+ {
+ double value = (double) millimeterstothefourth;
+ return new AreaMomentOfInertia(value, AreaMomentOfInertiaUnit.MillimeterToTheFourth);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// AreaMomentOfInertia unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static AreaMomentOfInertia From(double value, AreaMomentOfInertiaUnit fromUnit)
+ {
+ return new AreaMomentOfInertia((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 AreaMomentOfInertia Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static AreaMomentOfInertia Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out AreaMomentOfInertia result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out AreaMomentOfInertia result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static AreaMomentOfInertiaUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static AreaMomentOfInertiaUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out AreaMomentOfInertiaUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out AreaMomentOfInertiaUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is AreaMomentOfInertia)) throw new ArgumentException("Expected type AreaMomentOfInertia.", nameof(obj));
+
+ return CompareTo((AreaMomentOfInertia)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(AreaMomentOfInertia other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another AreaMomentOfInertia within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(AreaMomentOfInertia other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current AreaMomentOfInertia.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(AreaMomentOfInertiaUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this AreaMomentOfInertia to another AreaMomentOfInertia with the unit representation .
+ ///
+ /// A AreaMomentOfInertia with the specified unit.
+ public AreaMomentOfInertia ToUnit(AreaMomentOfInertiaUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new AreaMomentOfInertia(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case AreaMomentOfInertiaUnit.CentimeterToTheFourth: return _value/1e8;
+ case AreaMomentOfInertiaUnit.DecimeterToTheFourth: return _value/1e4;
+ case AreaMomentOfInertiaUnit.FootToTheFourth: return _value*Math.Pow(0.3048, 4);
+ case AreaMomentOfInertiaUnit.InchToTheFourth: return _value*Math.Pow(2.54e-2, 4);
+ case AreaMomentOfInertiaUnit.MeterToTheFourth: return _value;
+ case AreaMomentOfInertiaUnit.MillimeterToTheFourth: return _value/1e12;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(AreaMomentOfInertiaUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case AreaMomentOfInertiaUnit.CentimeterToTheFourth: return baseUnitValue*1e8;
+ case AreaMomentOfInertiaUnit.DecimeterToTheFourth: return baseUnitValue*1e4;
+ case AreaMomentOfInertiaUnit.FootToTheFourth: return baseUnitValue/Math.Pow(0.3048, 4);
+ case AreaMomentOfInertiaUnit.InchToTheFourth: return baseUnitValue/Math.Pow(2.54e-2, 4);
+ case AreaMomentOfInertiaUnit.MeterToTheFourth: return baseUnitValue;
+ case AreaMomentOfInertiaUnit.MillimeterToTheFourth: return baseUnitValue*1e12;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/BitRate.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/BitRate.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..550439140c
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/BitRate.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,998 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In telecommunications and computing, bit rate is the number of bits that are conveyed or processed per unit of time.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Bit_rate
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class BitRate : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly decimal _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly BitRateUnit? _unit;
+
+ static BitRate()
+ {
+ BaseDimensions = BaseDimensions.Dimensionless;
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit BitPerSecond.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public BitRate()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private BitRate(decimal numericValue, BitRateUnit unit)
+ {
+ if(unit == BitRateUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = numericValue;
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of BitRate, which is BitPerSecond. All conversions go via this value.
+ ///
+ public static BitRateUnit BaseUnit => BitRateUnit.BitPerSecond;
+
+ ///
+ /// Represents the largest possible value of BitRate
+ ///
+ public static BitRate MaxValue => new BitRate(decimal.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of BitRate
+ ///
+ public static BitRate MinValue => new BitRate(decimal.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.BitRate;
+
+ ///
+ /// All units of measurement for the BitRate quantity.
+ ///
+ public static BitRateUnit[] Units { get; } = Enum.GetValues(typeof(BitRateUnit)).Cast().Except(new BitRateUnit[]{ BitRateUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit BitPerSecond.
+ ///
+ public static BitRate Zero => new BitRate(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public BitRateUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => BitRate.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => BitRate.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get BitRate in BitsPerSecond.
+ ///
+ public double BitsPerSecond => As(BitRateUnit.BitPerSecond);
+
+ ///
+ /// Get BitRate in BytesPerSecond.
+ ///
+ public double BytesPerSecond => As(BitRateUnit.BytePerSecond);
+
+ ///
+ /// Get BitRate in ExabitsPerSecond.
+ ///
+ public double ExabitsPerSecond => As(BitRateUnit.ExabitPerSecond);
+
+ ///
+ /// Get BitRate in ExabytesPerSecond.
+ ///
+ public double ExabytesPerSecond => As(BitRateUnit.ExabytePerSecond);
+
+ ///
+ /// Get BitRate in ExbibitsPerSecond.
+ ///
+ public double ExbibitsPerSecond => As(BitRateUnit.ExbibitPerSecond);
+
+ ///
+ /// Get BitRate in ExbibytesPerSecond.
+ ///
+ public double ExbibytesPerSecond => As(BitRateUnit.ExbibytePerSecond);
+
+ ///
+ /// Get BitRate in GibibitsPerSecond.
+ ///
+ public double GibibitsPerSecond => As(BitRateUnit.GibibitPerSecond);
+
+ ///
+ /// Get BitRate in GibibytesPerSecond.
+ ///
+ public double GibibytesPerSecond => As(BitRateUnit.GibibytePerSecond);
+
+ ///
+ /// Get BitRate in GigabitsPerSecond.
+ ///
+ public double GigabitsPerSecond => As(BitRateUnit.GigabitPerSecond);
+
+ ///
+ /// Get BitRate in GigabytesPerSecond.
+ ///
+ public double GigabytesPerSecond => As(BitRateUnit.GigabytePerSecond);
+
+ ///
+ /// Get BitRate in KibibitsPerSecond.
+ ///
+ public double KibibitsPerSecond => As(BitRateUnit.KibibitPerSecond);
+
+ ///
+ /// Get BitRate in KibibytesPerSecond.
+ ///
+ public double KibibytesPerSecond => As(BitRateUnit.KibibytePerSecond);
+
+ ///
+ /// Get BitRate in KilobitsPerSecond.
+ ///
+ public double KilobitsPerSecond => As(BitRateUnit.KilobitPerSecond);
+
+ ///
+ /// Get BitRate in KilobytesPerSecond.
+ ///
+ public double KilobytesPerSecond => As(BitRateUnit.KilobytePerSecond);
+
+ ///
+ /// Get BitRate in MebibitsPerSecond.
+ ///
+ public double MebibitsPerSecond => As(BitRateUnit.MebibitPerSecond);
+
+ ///
+ /// Get BitRate in MebibytesPerSecond.
+ ///
+ public double MebibytesPerSecond => As(BitRateUnit.MebibytePerSecond);
+
+ ///
+ /// Get BitRate in MegabitsPerSecond.
+ ///
+ public double MegabitsPerSecond => As(BitRateUnit.MegabitPerSecond);
+
+ ///
+ /// Get BitRate in MegabytesPerSecond.
+ ///
+ public double MegabytesPerSecond => As(BitRateUnit.MegabytePerSecond);
+
+ ///
+ /// Get BitRate in PebibitsPerSecond.
+ ///
+ public double PebibitsPerSecond => As(BitRateUnit.PebibitPerSecond);
+
+ ///
+ /// Get BitRate in PebibytesPerSecond.
+ ///
+ public double PebibytesPerSecond => As(BitRateUnit.PebibytePerSecond);
+
+ ///
+ /// Get BitRate in PetabitsPerSecond.
+ ///
+ public double PetabitsPerSecond => As(BitRateUnit.PetabitPerSecond);
+
+ ///
+ /// Get BitRate in PetabytesPerSecond.
+ ///
+ public double PetabytesPerSecond => As(BitRateUnit.PetabytePerSecond);
+
+ ///
+ /// Get BitRate in TebibitsPerSecond.
+ ///
+ public double TebibitsPerSecond => As(BitRateUnit.TebibitPerSecond);
+
+ ///
+ /// Get BitRate in TebibytesPerSecond.
+ ///
+ public double TebibytesPerSecond => As(BitRateUnit.TebibytePerSecond);
+
+ ///
+ /// Get BitRate in TerabitsPerSecond.
+ ///
+ public double TerabitsPerSecond => As(BitRateUnit.TerabitPerSecond);
+
+ ///
+ /// Get BitRate in TerabytesPerSecond.
+ ///
+ public double TerabytesPerSecond => As(BitRateUnit.TerabytePerSecond);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(BitRateUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(BitRateUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get BitRate from BitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromBitsPerSecond(double bitspersecond)
+ {
+ decimal value = (decimal) bitspersecond;
+ return new BitRate(value, BitRateUnit.BitPerSecond);
+ }
+ ///
+ /// Get BitRate from BytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromBytesPerSecond(double bytespersecond)
+ {
+ decimal value = (decimal) bytespersecond;
+ return new BitRate(value, BitRateUnit.BytePerSecond);
+ }
+ ///
+ /// Get BitRate from ExabitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromExabitsPerSecond(double exabitspersecond)
+ {
+ decimal value = (decimal) exabitspersecond;
+ return new BitRate(value, BitRateUnit.ExabitPerSecond);
+ }
+ ///
+ /// Get BitRate from ExabytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromExabytesPerSecond(double exabytespersecond)
+ {
+ decimal value = (decimal) exabytespersecond;
+ return new BitRate(value, BitRateUnit.ExabytePerSecond);
+ }
+ ///
+ /// Get BitRate from ExbibitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromExbibitsPerSecond(double exbibitspersecond)
+ {
+ decimal value = (decimal) exbibitspersecond;
+ return new BitRate(value, BitRateUnit.ExbibitPerSecond);
+ }
+ ///
+ /// Get BitRate from ExbibytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromExbibytesPerSecond(double exbibytespersecond)
+ {
+ decimal value = (decimal) exbibytespersecond;
+ return new BitRate(value, BitRateUnit.ExbibytePerSecond);
+ }
+ ///
+ /// Get BitRate from GibibitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromGibibitsPerSecond(double gibibitspersecond)
+ {
+ decimal value = (decimal) gibibitspersecond;
+ return new BitRate(value, BitRateUnit.GibibitPerSecond);
+ }
+ ///
+ /// Get BitRate from GibibytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromGibibytesPerSecond(double gibibytespersecond)
+ {
+ decimal value = (decimal) gibibytespersecond;
+ return new BitRate(value, BitRateUnit.GibibytePerSecond);
+ }
+ ///
+ /// Get BitRate from GigabitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromGigabitsPerSecond(double gigabitspersecond)
+ {
+ decimal value = (decimal) gigabitspersecond;
+ return new BitRate(value, BitRateUnit.GigabitPerSecond);
+ }
+ ///
+ /// Get BitRate from GigabytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromGigabytesPerSecond(double gigabytespersecond)
+ {
+ decimal value = (decimal) gigabytespersecond;
+ return new BitRate(value, BitRateUnit.GigabytePerSecond);
+ }
+ ///
+ /// Get BitRate from KibibitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromKibibitsPerSecond(double kibibitspersecond)
+ {
+ decimal value = (decimal) kibibitspersecond;
+ return new BitRate(value, BitRateUnit.KibibitPerSecond);
+ }
+ ///
+ /// Get BitRate from KibibytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromKibibytesPerSecond(double kibibytespersecond)
+ {
+ decimal value = (decimal) kibibytespersecond;
+ return new BitRate(value, BitRateUnit.KibibytePerSecond);
+ }
+ ///
+ /// Get BitRate from KilobitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromKilobitsPerSecond(double kilobitspersecond)
+ {
+ decimal value = (decimal) kilobitspersecond;
+ return new BitRate(value, BitRateUnit.KilobitPerSecond);
+ }
+ ///
+ /// Get BitRate from KilobytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromKilobytesPerSecond(double kilobytespersecond)
+ {
+ decimal value = (decimal) kilobytespersecond;
+ return new BitRate(value, BitRateUnit.KilobytePerSecond);
+ }
+ ///
+ /// Get BitRate from MebibitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromMebibitsPerSecond(double mebibitspersecond)
+ {
+ decimal value = (decimal) mebibitspersecond;
+ return new BitRate(value, BitRateUnit.MebibitPerSecond);
+ }
+ ///
+ /// Get BitRate from MebibytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromMebibytesPerSecond(double mebibytespersecond)
+ {
+ decimal value = (decimal) mebibytespersecond;
+ return new BitRate(value, BitRateUnit.MebibytePerSecond);
+ }
+ ///
+ /// Get BitRate from MegabitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromMegabitsPerSecond(double megabitspersecond)
+ {
+ decimal value = (decimal) megabitspersecond;
+ return new BitRate(value, BitRateUnit.MegabitPerSecond);
+ }
+ ///
+ /// Get BitRate from MegabytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromMegabytesPerSecond(double megabytespersecond)
+ {
+ decimal value = (decimal) megabytespersecond;
+ return new BitRate(value, BitRateUnit.MegabytePerSecond);
+ }
+ ///
+ /// Get BitRate from PebibitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromPebibitsPerSecond(double pebibitspersecond)
+ {
+ decimal value = (decimal) pebibitspersecond;
+ return new BitRate(value, BitRateUnit.PebibitPerSecond);
+ }
+ ///
+ /// Get BitRate from PebibytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromPebibytesPerSecond(double pebibytespersecond)
+ {
+ decimal value = (decimal) pebibytespersecond;
+ return new BitRate(value, BitRateUnit.PebibytePerSecond);
+ }
+ ///
+ /// Get BitRate from PetabitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromPetabitsPerSecond(double petabitspersecond)
+ {
+ decimal value = (decimal) petabitspersecond;
+ return new BitRate(value, BitRateUnit.PetabitPerSecond);
+ }
+ ///
+ /// Get BitRate from PetabytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromPetabytesPerSecond(double petabytespersecond)
+ {
+ decimal value = (decimal) petabytespersecond;
+ return new BitRate(value, BitRateUnit.PetabytePerSecond);
+ }
+ ///
+ /// Get BitRate from TebibitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromTebibitsPerSecond(double tebibitspersecond)
+ {
+ decimal value = (decimal) tebibitspersecond;
+ return new BitRate(value, BitRateUnit.TebibitPerSecond);
+ }
+ ///
+ /// Get BitRate from TebibytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromTebibytesPerSecond(double tebibytespersecond)
+ {
+ decimal value = (decimal) tebibytespersecond;
+ return new BitRate(value, BitRateUnit.TebibytePerSecond);
+ }
+ ///
+ /// Get BitRate from TerabitsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromTerabitsPerSecond(double terabitspersecond)
+ {
+ decimal value = (decimal) terabitspersecond;
+ return new BitRate(value, BitRateUnit.TerabitPerSecond);
+ }
+ ///
+ /// Get BitRate from TerabytesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BitRate FromTerabytesPerSecond(double terabytespersecond)
+ {
+ decimal value = (decimal) terabytespersecond;
+ return new BitRate(value, BitRateUnit.TerabytePerSecond);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// BitRate unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static BitRate From(double value, BitRateUnit fromUnit)
+ {
+ return new BitRate((decimal)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 BitRate Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static BitRate Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out BitRate result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out BitRate result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static BitRateUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static BitRateUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out BitRateUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out BitRateUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is BitRate)) throw new ArgumentException("Expected type BitRate.", nameof(obj));
+
+ return CompareTo((BitRate)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(BitRate other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another BitRate within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(BitRate other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current BitRate.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(BitRateUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this BitRate to another BitRate with the unit representation .
+ ///
+ /// A BitRate with the specified unit.
+ public BitRate ToUnit(BitRateUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new BitRate(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private decimal AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case BitRateUnit.BitPerSecond: return _value;
+ case BitRateUnit.BytePerSecond: return _value*8m;
+ case BitRateUnit.ExabitPerSecond: return (_value) * 1e18m;
+ case BitRateUnit.ExabytePerSecond: return (_value*8m) * 1e18m;
+ case BitRateUnit.ExbibitPerSecond: return (_value) * (1024m * 1024 * 1024 * 1024 * 1024 * 1024);
+ case BitRateUnit.ExbibytePerSecond: return (_value*8m) * (1024m * 1024 * 1024 * 1024 * 1024 * 1024);
+ case BitRateUnit.GibibitPerSecond: return (_value) * (1024m * 1024 * 1024);
+ case BitRateUnit.GibibytePerSecond: return (_value*8m) * (1024m * 1024 * 1024);
+ case BitRateUnit.GigabitPerSecond: return (_value) * 1e9m;
+ case BitRateUnit.GigabytePerSecond: return (_value*8m) * 1e9m;
+ case BitRateUnit.KibibitPerSecond: return (_value) * 1024m;
+ case BitRateUnit.KibibytePerSecond: return (_value*8m) * 1024m;
+ case BitRateUnit.KilobitPerSecond: return (_value) * 1e3m;
+ case BitRateUnit.KilobytePerSecond: return (_value*8m) * 1e3m;
+ case BitRateUnit.MebibitPerSecond: return (_value) * (1024m * 1024);
+ case BitRateUnit.MebibytePerSecond: return (_value*8m) * (1024m * 1024);
+ case BitRateUnit.MegabitPerSecond: return (_value) * 1e6m;
+ case BitRateUnit.MegabytePerSecond: return (_value*8m) * 1e6m;
+ case BitRateUnit.PebibitPerSecond: return (_value) * (1024m * 1024 * 1024 * 1024 * 1024);
+ case BitRateUnit.PebibytePerSecond: return (_value*8m) * (1024m * 1024 * 1024 * 1024 * 1024);
+ case BitRateUnit.PetabitPerSecond: return (_value) * 1e15m;
+ case BitRateUnit.PetabytePerSecond: return (_value*8m) * 1e15m;
+ case BitRateUnit.TebibitPerSecond: return (_value) * (1024m * 1024 * 1024 * 1024);
+ case BitRateUnit.TebibytePerSecond: return (_value*8m) * (1024m * 1024 * 1024 * 1024);
+ case BitRateUnit.TerabitPerSecond: return (_value) * 1e12m;
+ case BitRateUnit.TerabytePerSecond: return (_value*8m) * 1e12m;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private decimal AsBaseNumericType(BitRateUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case BitRateUnit.BitPerSecond: return baseUnitValue;
+ case BitRateUnit.BytePerSecond: return baseUnitValue/8m;
+ case BitRateUnit.ExabitPerSecond: return (baseUnitValue) / 1e18m;
+ case BitRateUnit.ExabytePerSecond: return (baseUnitValue/8m) / 1e18m;
+ case BitRateUnit.ExbibitPerSecond: return (baseUnitValue) / (1024m * 1024 * 1024 * 1024 * 1024 * 1024);
+ case BitRateUnit.ExbibytePerSecond: return (baseUnitValue/8m) / (1024m * 1024 * 1024 * 1024 * 1024 * 1024);
+ case BitRateUnit.GibibitPerSecond: return (baseUnitValue) / (1024m * 1024 * 1024);
+ case BitRateUnit.GibibytePerSecond: return (baseUnitValue/8m) / (1024m * 1024 * 1024);
+ case BitRateUnit.GigabitPerSecond: return (baseUnitValue) / 1e9m;
+ case BitRateUnit.GigabytePerSecond: return (baseUnitValue/8m) / 1e9m;
+ case BitRateUnit.KibibitPerSecond: return (baseUnitValue) / 1024m;
+ case BitRateUnit.KibibytePerSecond: return (baseUnitValue/8m) / 1024m;
+ case BitRateUnit.KilobitPerSecond: return (baseUnitValue) / 1e3m;
+ case BitRateUnit.KilobytePerSecond: return (baseUnitValue/8m) / 1e3m;
+ case BitRateUnit.MebibitPerSecond: return (baseUnitValue) / (1024m * 1024);
+ case BitRateUnit.MebibytePerSecond: return (baseUnitValue/8m) / (1024m * 1024);
+ case BitRateUnit.MegabitPerSecond: return (baseUnitValue) / 1e6m;
+ case BitRateUnit.MegabytePerSecond: return (baseUnitValue/8m) / 1e6m;
+ case BitRateUnit.PebibitPerSecond: return (baseUnitValue) / (1024m * 1024 * 1024 * 1024 * 1024);
+ case BitRateUnit.PebibytePerSecond: return (baseUnitValue/8m) / (1024m * 1024 * 1024 * 1024 * 1024);
+ case BitRateUnit.PetabitPerSecond: return (baseUnitValue) / 1e15m;
+ case BitRateUnit.PetabytePerSecond: return (baseUnitValue/8m) / 1e15m;
+ case BitRateUnit.TebibitPerSecond: return (baseUnitValue) / (1024m * 1024 * 1024 * 1024);
+ case BitRateUnit.TebibytePerSecond: return (baseUnitValue/8m) / (1024m * 1024 * 1024 * 1024);
+ case BitRateUnit.TerabitPerSecond: return (baseUnitValue) / 1e12m;
+ case BitRateUnit.TerabytePerSecond: return (baseUnitValue/8m) / 1e12m;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..63ab43d231
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,604 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Brake specific fuel consumption (BSFC) is a measure of the fuel efficiency of any prime mover that burns fuel and produces rotational, or shaft, power. It is typically used for comparing the efficiency of internal combustion engines with a shaft output.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class BrakeSpecificFuelConsumption : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly BrakeSpecificFuelConsumptionUnit? _unit;
+
+ static BrakeSpecificFuelConsumption()
+ {
+ BaseDimensions = new BaseDimensions(-2, 0, 2, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit KilogramPerJoule.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public BrakeSpecificFuelConsumption()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private BrakeSpecificFuelConsumption(double numericValue, BrakeSpecificFuelConsumptionUnit unit)
+ {
+ if(unit == BrakeSpecificFuelConsumptionUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of BrakeSpecificFuelConsumption, which is KilogramPerJoule. All conversions go via this value.
+ ///
+ public static BrakeSpecificFuelConsumptionUnit BaseUnit => BrakeSpecificFuelConsumptionUnit.KilogramPerJoule;
+
+ ///
+ /// Represents the largest possible value of BrakeSpecificFuelConsumption
+ ///
+ public static BrakeSpecificFuelConsumption MaxValue => new BrakeSpecificFuelConsumption(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of BrakeSpecificFuelConsumption
+ ///
+ public static BrakeSpecificFuelConsumption MinValue => new BrakeSpecificFuelConsumption(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.BrakeSpecificFuelConsumption;
+
+ ///
+ /// All units of measurement for the BrakeSpecificFuelConsumption quantity.
+ ///
+ public static BrakeSpecificFuelConsumptionUnit[] Units { get; } = Enum.GetValues(typeof(BrakeSpecificFuelConsumptionUnit)).Cast().Except(new BrakeSpecificFuelConsumptionUnit[]{ BrakeSpecificFuelConsumptionUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerJoule.
+ ///
+ public static BrakeSpecificFuelConsumption Zero => new BrakeSpecificFuelConsumption(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public BrakeSpecificFuelConsumptionUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => BrakeSpecificFuelConsumption.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => BrakeSpecificFuelConsumption.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get BrakeSpecificFuelConsumption in GramsPerKiloWattHour.
+ ///
+ public double GramsPerKiloWattHour => As(BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour);
+
+ ///
+ /// Get BrakeSpecificFuelConsumption in KilogramsPerJoule.
+ ///
+ public double KilogramsPerJoule => As(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule);
+
+ ///
+ /// Get BrakeSpecificFuelConsumption in PoundsPerMechanicalHorsepowerHour.
+ ///
+ public double PoundsPerMechanicalHorsepowerHour => As(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(BrakeSpecificFuelConsumptionUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(BrakeSpecificFuelConsumptionUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get BrakeSpecificFuelConsumption from GramsPerKiloWattHour.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BrakeSpecificFuelConsumption FromGramsPerKiloWattHour(double gramsperkilowatthour)
+ {
+ double value = (double) gramsperkilowatthour;
+ return new BrakeSpecificFuelConsumption(value, BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour);
+ }
+ ///
+ /// Get BrakeSpecificFuelConsumption from KilogramsPerJoule.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BrakeSpecificFuelConsumption FromKilogramsPerJoule(double kilogramsperjoule)
+ {
+ double value = (double) kilogramsperjoule;
+ return new BrakeSpecificFuelConsumption(value, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule);
+ }
+ ///
+ /// Get BrakeSpecificFuelConsumption from PoundsPerMechanicalHorsepowerHour.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static BrakeSpecificFuelConsumption FromPoundsPerMechanicalHorsepowerHour(double poundspermechanicalhorsepowerhour)
+ {
+ double value = (double) poundspermechanicalhorsepowerhour;
+ return new BrakeSpecificFuelConsumption(value, BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// BrakeSpecificFuelConsumption unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static BrakeSpecificFuelConsumption From(double value, BrakeSpecificFuelConsumptionUnit fromUnit)
+ {
+ return new BrakeSpecificFuelConsumption((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 BrakeSpecificFuelConsumption Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static BrakeSpecificFuelConsumption Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out BrakeSpecificFuelConsumption result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out BrakeSpecificFuelConsumption result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static BrakeSpecificFuelConsumptionUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static BrakeSpecificFuelConsumptionUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out BrakeSpecificFuelConsumptionUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out BrakeSpecificFuelConsumptionUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is BrakeSpecificFuelConsumption)) throw new ArgumentException("Expected type BrakeSpecificFuelConsumption.", nameof(obj));
+
+ return CompareTo((BrakeSpecificFuelConsumption)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(BrakeSpecificFuelConsumption other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another BrakeSpecificFuelConsumption within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(BrakeSpecificFuelConsumption other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current BrakeSpecificFuelConsumption.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(BrakeSpecificFuelConsumptionUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this BrakeSpecificFuelConsumption to another BrakeSpecificFuelConsumption with the unit representation .
+ ///
+ /// A BrakeSpecificFuelConsumption with the specified unit.
+ public BrakeSpecificFuelConsumption ToUnit(BrakeSpecificFuelConsumptionUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new BrakeSpecificFuelConsumption(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour: return _value/3.6e9;
+ case BrakeSpecificFuelConsumptionUnit.KilogramPerJoule: return _value;
+ case BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour: return _value*1.689659410672e-7;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(BrakeSpecificFuelConsumptionUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour: return baseUnitValue*3.6e9;
+ case BrakeSpecificFuelConsumptionUnit.KilogramPerJoule: return baseUnitValue;
+ case BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour: return baseUnitValue/1.689659410672e-7;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Capacitance.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Capacitance.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..e420af6a62
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Capacitance.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Capacitance is the ability of a body to store an electric charge.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Capacitance
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Capacitance : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly CapacitanceUnit? _unit;
+
+ static Capacitance()
+ {
+ BaseDimensions = new BaseDimensions(-2, -1, 4, 2, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Farad.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Capacitance()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Capacitance(double numericValue, CapacitanceUnit unit)
+ {
+ if(unit == CapacitanceUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Capacitance, which is Farad. All conversions go via this value.
+ ///
+ public static CapacitanceUnit BaseUnit => CapacitanceUnit.Farad;
+
+ ///
+ /// Represents the largest possible value of Capacitance
+ ///
+ public static Capacitance MaxValue => new Capacitance(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Capacitance
+ ///
+ public static Capacitance MinValue => new Capacitance(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Capacitance;
+
+ ///
+ /// All units of measurement for the Capacitance quantity.
+ ///
+ public static CapacitanceUnit[] Units { get; } = Enum.GetValues(typeof(CapacitanceUnit)).Cast().Except(new CapacitanceUnit[]{ CapacitanceUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Farad.
+ ///
+ public static Capacitance Zero => new Capacitance(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public CapacitanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Capacitance.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Capacitance.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Capacitance in Farads.
+ ///
+ public double Farads => As(CapacitanceUnit.Farad);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(CapacitanceUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(CapacitanceUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Capacitance from Farads.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Capacitance FromFarads(double farads)
+ {
+ double value = (double) farads;
+ return new Capacitance(value, CapacitanceUnit.Farad);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Capacitance unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Capacitance From(double value, CapacitanceUnit fromUnit)
+ {
+ return new Capacitance((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 Capacitance Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Capacitance Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Capacitance result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Capacitance result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static CapacitanceUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static CapacitanceUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out CapacitanceUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out CapacitanceUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Capacitance)) throw new ArgumentException("Expected type Capacitance.", nameof(obj));
+
+ return CompareTo((Capacitance)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Capacitance other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Capacitance within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Capacitance other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Capacitance.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(CapacitanceUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Capacitance to another Capacitance with the unit representation .
+ ///
+ /// A Capacitance with the specified unit.
+ public Capacitance ToUnit(CapacitanceUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Capacitance(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case CapacitanceUnit.Farad: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(CapacitanceUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case CapacitanceUnit.Farad: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/CoefficientOfThermalExpansion.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/CoefficientOfThermalExpansion.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..1173f6f511
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/CoefficientOfThermalExpansion.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,604 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// A unit that represents a fractional change in size in response to a change in temperature.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class CoefficientOfThermalExpansion : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly CoefficientOfThermalExpansionUnit? _unit;
+
+ static CoefficientOfThermalExpansion()
+ {
+ BaseDimensions = new BaseDimensions(0, 0, 0, 0, -1, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit InverseKelvin.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public CoefficientOfThermalExpansion()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private CoefficientOfThermalExpansion(double numericValue, CoefficientOfThermalExpansionUnit unit)
+ {
+ if(unit == CoefficientOfThermalExpansionUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of CoefficientOfThermalExpansion, which is InverseKelvin. All conversions go via this value.
+ ///
+ public static CoefficientOfThermalExpansionUnit BaseUnit => CoefficientOfThermalExpansionUnit.InverseKelvin;
+
+ ///
+ /// Represents the largest possible value of CoefficientOfThermalExpansion
+ ///
+ public static CoefficientOfThermalExpansion MaxValue => new CoefficientOfThermalExpansion(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of CoefficientOfThermalExpansion
+ ///
+ public static CoefficientOfThermalExpansion MinValue => new CoefficientOfThermalExpansion(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.CoefficientOfThermalExpansion;
+
+ ///
+ /// All units of measurement for the CoefficientOfThermalExpansion quantity.
+ ///
+ public static CoefficientOfThermalExpansionUnit[] Units { get; } = Enum.GetValues(typeof(CoefficientOfThermalExpansionUnit)).Cast().Except(new CoefficientOfThermalExpansionUnit[]{ CoefficientOfThermalExpansionUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit InverseKelvin.
+ ///
+ public static CoefficientOfThermalExpansion Zero => new CoefficientOfThermalExpansion(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public CoefficientOfThermalExpansionUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => CoefficientOfThermalExpansion.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => CoefficientOfThermalExpansion.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get CoefficientOfThermalExpansion in InverseDegreeCelsius.
+ ///
+ public double InverseDegreeCelsius => As(CoefficientOfThermalExpansionUnit.InverseDegreeCelsius);
+
+ ///
+ /// Get CoefficientOfThermalExpansion in InverseDegreeFahrenheit.
+ ///
+ public double InverseDegreeFahrenheit => As(CoefficientOfThermalExpansionUnit.InverseDegreeFahrenheit);
+
+ ///
+ /// Get CoefficientOfThermalExpansion in InverseKelvin.
+ ///
+ public double InverseKelvin => As(CoefficientOfThermalExpansionUnit.InverseKelvin);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(CoefficientOfThermalExpansionUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(CoefficientOfThermalExpansionUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get CoefficientOfThermalExpansion from InverseDegreeCelsius.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static CoefficientOfThermalExpansion FromInverseDegreeCelsius(double inversedegreecelsius)
+ {
+ double value = (double) inversedegreecelsius;
+ return new CoefficientOfThermalExpansion(value, CoefficientOfThermalExpansionUnit.InverseDegreeCelsius);
+ }
+ ///
+ /// Get CoefficientOfThermalExpansion from InverseDegreeFahrenheit.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static CoefficientOfThermalExpansion FromInverseDegreeFahrenheit(double inversedegreefahrenheit)
+ {
+ double value = (double) inversedegreefahrenheit;
+ return new CoefficientOfThermalExpansion(value, CoefficientOfThermalExpansionUnit.InverseDegreeFahrenheit);
+ }
+ ///
+ /// Get CoefficientOfThermalExpansion from InverseKelvin.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static CoefficientOfThermalExpansion FromInverseKelvin(double inversekelvin)
+ {
+ double value = (double) inversekelvin;
+ return new CoefficientOfThermalExpansion(value, CoefficientOfThermalExpansionUnit.InverseKelvin);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// CoefficientOfThermalExpansion unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static CoefficientOfThermalExpansion From(double value, CoefficientOfThermalExpansionUnit fromUnit)
+ {
+ return new CoefficientOfThermalExpansion((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 CoefficientOfThermalExpansion Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static CoefficientOfThermalExpansion Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out CoefficientOfThermalExpansion result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out CoefficientOfThermalExpansion result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static CoefficientOfThermalExpansionUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static CoefficientOfThermalExpansionUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out CoefficientOfThermalExpansionUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out CoefficientOfThermalExpansionUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is CoefficientOfThermalExpansion)) throw new ArgumentException("Expected type CoefficientOfThermalExpansion.", nameof(obj));
+
+ return CompareTo((CoefficientOfThermalExpansion)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(CoefficientOfThermalExpansion other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another CoefficientOfThermalExpansion within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(CoefficientOfThermalExpansion other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current CoefficientOfThermalExpansion.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(CoefficientOfThermalExpansionUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this CoefficientOfThermalExpansion to another CoefficientOfThermalExpansion with the unit representation .
+ ///
+ /// A CoefficientOfThermalExpansion with the specified unit.
+ public CoefficientOfThermalExpansion ToUnit(CoefficientOfThermalExpansionUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new CoefficientOfThermalExpansion(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case CoefficientOfThermalExpansionUnit.InverseDegreeCelsius: return _value;
+ case CoefficientOfThermalExpansionUnit.InverseDegreeFahrenheit: return _value*5/9;
+ case CoefficientOfThermalExpansionUnit.InverseKelvin: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(CoefficientOfThermalExpansionUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case CoefficientOfThermalExpansionUnit.InverseDegreeCelsius: return baseUnitValue;
+ case CoefficientOfThermalExpansionUnit.InverseDegreeFahrenheit: return baseUnitValue*9/5;
+ case CoefficientOfThermalExpansionUnit.InverseKelvin: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Density.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Density.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..ccd0e18225
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Density.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,1202 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The density, or more precisely, the volumetric mass density, of a substance is its mass per unit volume.
+ ///
+ ///
+ /// http://en.wikipedia.org/wiki/Density
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Density : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly DensityUnit? _unit;
+
+ static Density()
+ {
+ BaseDimensions = new BaseDimensions(-3, 1, 0, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit KilogramPerCubicMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Density()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Density(double numericValue, DensityUnit unit)
+ {
+ if(unit == DensityUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Density, which is KilogramPerCubicMeter. All conversions go via this value.
+ ///
+ public static DensityUnit BaseUnit => DensityUnit.KilogramPerCubicMeter;
+
+ ///
+ /// Represents the largest possible value of Density
+ ///
+ public static Density MaxValue => new Density(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Density
+ ///
+ public static Density MinValue => new Density(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Density;
+
+ ///
+ /// All units of measurement for the Density quantity.
+ ///
+ public static DensityUnit[] Units { get; } = Enum.GetValues(typeof(DensityUnit)).Cast().Except(new DensityUnit[]{ DensityUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerCubicMeter.
+ ///
+ public static Density Zero => new Density(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public DensityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Density.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Density.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Density in CentigramsPerDeciLiter.
+ ///
+ public double CentigramsPerDeciLiter => As(DensityUnit.CentigramPerDeciliter);
+
+ ///
+ /// Get Density in CentigramsPerLiter.
+ ///
+ public double CentigramsPerLiter => As(DensityUnit.CentigramPerLiter);
+
+ ///
+ /// Get Density in CentigramsPerMilliliter.
+ ///
+ public double CentigramsPerMilliliter => As(DensityUnit.CentigramPerMilliliter);
+
+ ///
+ /// Get Density in DecigramsPerDeciLiter.
+ ///
+ public double DecigramsPerDeciLiter => As(DensityUnit.DecigramPerDeciliter);
+
+ ///
+ /// Get Density in DecigramsPerLiter.
+ ///
+ public double DecigramsPerLiter => As(DensityUnit.DecigramPerLiter);
+
+ ///
+ /// Get Density in DecigramsPerMilliliter.
+ ///
+ public double DecigramsPerMilliliter => As(DensityUnit.DecigramPerMilliliter);
+
+ ///
+ /// Get Density in GramsPerCubicCentimeter.
+ ///
+ public double GramsPerCubicCentimeter => As(DensityUnit.GramPerCubicCentimeter);
+
+ ///
+ /// Get Density in GramsPerCubicMeter.
+ ///
+ public double GramsPerCubicMeter => As(DensityUnit.GramPerCubicMeter);
+
+ ///
+ /// Get Density in GramsPerCubicMillimeter.
+ ///
+ public double GramsPerCubicMillimeter => As(DensityUnit.GramPerCubicMillimeter);
+
+ ///
+ /// Get Density in GramsPerDeciLiter.
+ ///
+ public double GramsPerDeciLiter => As(DensityUnit.GramPerDeciliter);
+
+ ///
+ /// Get Density in GramsPerLiter.
+ ///
+ public double GramsPerLiter => As(DensityUnit.GramPerLiter);
+
+ ///
+ /// Get Density in GramsPerMilliliter.
+ ///
+ public double GramsPerMilliliter => As(DensityUnit.GramPerMilliliter);
+
+ ///
+ /// Get Density in KilogramsPerCubicCentimeter.
+ ///
+ public double KilogramsPerCubicCentimeter => As(DensityUnit.KilogramPerCubicCentimeter);
+
+ ///
+ /// Get Density in KilogramsPerCubicMeter.
+ ///
+ public double KilogramsPerCubicMeter => As(DensityUnit.KilogramPerCubicMeter);
+
+ ///
+ /// Get Density in KilogramsPerCubicMillimeter.
+ ///
+ public double KilogramsPerCubicMillimeter => As(DensityUnit.KilogramPerCubicMillimeter);
+
+ ///
+ /// Get Density in KilopoundsPerCubicFoot.
+ ///
+ public double KilopoundsPerCubicFoot => As(DensityUnit.KilopoundPerCubicFoot);
+
+ ///
+ /// Get Density in KilopoundsPerCubicInch.
+ ///
+ public double KilopoundsPerCubicInch => As(DensityUnit.KilopoundPerCubicInch);
+
+ ///
+ /// Get Density in MicrogramsPerDeciLiter.
+ ///
+ public double MicrogramsPerDeciLiter => As(DensityUnit.MicrogramPerDeciliter);
+
+ ///
+ /// Get Density in MicrogramsPerLiter.
+ ///
+ public double MicrogramsPerLiter => As(DensityUnit.MicrogramPerLiter);
+
+ ///
+ /// Get Density in MicrogramsPerMilliliter.
+ ///
+ public double MicrogramsPerMilliliter => As(DensityUnit.MicrogramPerMilliliter);
+
+ ///
+ /// Get Density in MilligramsPerCubicMeter.
+ ///
+ public double MilligramsPerCubicMeter => As(DensityUnit.MilligramPerCubicMeter);
+
+ ///
+ /// Get Density in MilligramsPerDeciLiter.
+ ///
+ public double MilligramsPerDeciLiter => As(DensityUnit.MilligramPerDeciliter);
+
+ ///
+ /// Get Density in MilligramsPerLiter.
+ ///
+ public double MilligramsPerLiter => As(DensityUnit.MilligramPerLiter);
+
+ ///
+ /// Get Density in MilligramsPerMilliliter.
+ ///
+ public double MilligramsPerMilliliter => As(DensityUnit.MilligramPerMilliliter);
+
+ ///
+ /// Get Density in NanogramsPerDeciLiter.
+ ///
+ public double NanogramsPerDeciLiter => As(DensityUnit.NanogramPerDeciliter);
+
+ ///
+ /// Get Density in NanogramsPerLiter.
+ ///
+ public double NanogramsPerLiter => As(DensityUnit.NanogramPerLiter);
+
+ ///
+ /// Get Density in NanogramsPerMilliliter.
+ ///
+ public double NanogramsPerMilliliter => As(DensityUnit.NanogramPerMilliliter);
+
+ ///
+ /// Get Density in PicogramsPerDeciLiter.
+ ///
+ public double PicogramsPerDeciLiter => As(DensityUnit.PicogramPerDeciliter);
+
+ ///
+ /// Get Density in PicogramsPerLiter.
+ ///
+ public double PicogramsPerLiter => As(DensityUnit.PicogramPerLiter);
+
+ ///
+ /// Get Density in PicogramsPerMilliliter.
+ ///
+ public double PicogramsPerMilliliter => As(DensityUnit.PicogramPerMilliliter);
+
+ ///
+ /// Get Density in PoundsPerCubicFoot.
+ ///
+ public double PoundsPerCubicFoot => As(DensityUnit.PoundPerCubicFoot);
+
+ ///
+ /// Get Density in PoundsPerCubicInch.
+ ///
+ public double PoundsPerCubicInch => As(DensityUnit.PoundPerCubicInch);
+
+ ///
+ /// Get Density in PoundsPerImperialGallon.
+ ///
+ public double PoundsPerImperialGallon => As(DensityUnit.PoundPerImperialGallon);
+
+ ///
+ /// Get Density in PoundsPerUSGallon.
+ ///
+ public double PoundsPerUSGallon => As(DensityUnit.PoundPerUSGallon);
+
+ ///
+ /// Get Density in SlugsPerCubicFoot.
+ ///
+ public double SlugsPerCubicFoot => As(DensityUnit.SlugPerCubicFoot);
+
+ ///
+ /// Get Density in TonnesPerCubicCentimeter.
+ ///
+ public double TonnesPerCubicCentimeter => As(DensityUnit.TonnePerCubicCentimeter);
+
+ ///
+ /// Get Density in TonnesPerCubicMeter.
+ ///
+ public double TonnesPerCubicMeter => As(DensityUnit.TonnePerCubicMeter);
+
+ ///
+ /// Get Density in TonnesPerCubicMillimeter.
+ ///
+ public double TonnesPerCubicMillimeter => As(DensityUnit.TonnePerCubicMillimeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(DensityUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(DensityUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Density from CentigramsPerDeciLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromCentigramsPerDeciLiter(double centigramsperdeciliter)
+ {
+ double value = (double) centigramsperdeciliter;
+ return new Density(value, DensityUnit.CentigramPerDeciliter);
+ }
+ ///
+ /// Get Density from CentigramsPerLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromCentigramsPerLiter(double centigramsperliter)
+ {
+ double value = (double) centigramsperliter;
+ return new Density(value, DensityUnit.CentigramPerLiter);
+ }
+ ///
+ /// Get Density from CentigramsPerMilliliter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromCentigramsPerMilliliter(double centigramspermilliliter)
+ {
+ double value = (double) centigramspermilliliter;
+ return new Density(value, DensityUnit.CentigramPerMilliliter);
+ }
+ ///
+ /// Get Density from DecigramsPerDeciLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromDecigramsPerDeciLiter(double decigramsperdeciliter)
+ {
+ double value = (double) decigramsperdeciliter;
+ return new Density(value, DensityUnit.DecigramPerDeciliter);
+ }
+ ///
+ /// Get Density from DecigramsPerLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromDecigramsPerLiter(double decigramsperliter)
+ {
+ double value = (double) decigramsperliter;
+ return new Density(value, DensityUnit.DecigramPerLiter);
+ }
+ ///
+ /// Get Density from DecigramsPerMilliliter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromDecigramsPerMilliliter(double decigramspermilliliter)
+ {
+ double value = (double) decigramspermilliliter;
+ return new Density(value, DensityUnit.DecigramPerMilliliter);
+ }
+ ///
+ /// Get Density from GramsPerCubicCentimeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromGramsPerCubicCentimeter(double gramspercubiccentimeter)
+ {
+ double value = (double) gramspercubiccentimeter;
+ return new Density(value, DensityUnit.GramPerCubicCentimeter);
+ }
+ ///
+ /// Get Density from GramsPerCubicMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromGramsPerCubicMeter(double gramspercubicmeter)
+ {
+ double value = (double) gramspercubicmeter;
+ return new Density(value, DensityUnit.GramPerCubicMeter);
+ }
+ ///
+ /// Get Density from GramsPerCubicMillimeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromGramsPerCubicMillimeter(double gramspercubicmillimeter)
+ {
+ double value = (double) gramspercubicmillimeter;
+ return new Density(value, DensityUnit.GramPerCubicMillimeter);
+ }
+ ///
+ /// Get Density from GramsPerDeciLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromGramsPerDeciLiter(double gramsperdeciliter)
+ {
+ double value = (double) gramsperdeciliter;
+ return new Density(value, DensityUnit.GramPerDeciliter);
+ }
+ ///
+ /// Get Density from GramsPerLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromGramsPerLiter(double gramsperliter)
+ {
+ double value = (double) gramsperliter;
+ return new Density(value, DensityUnit.GramPerLiter);
+ }
+ ///
+ /// Get Density from GramsPerMilliliter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromGramsPerMilliliter(double gramspermilliliter)
+ {
+ double value = (double) gramspermilliliter;
+ return new Density(value, DensityUnit.GramPerMilliliter);
+ }
+ ///
+ /// Get Density from KilogramsPerCubicCentimeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromKilogramsPerCubicCentimeter(double kilogramspercubiccentimeter)
+ {
+ double value = (double) kilogramspercubiccentimeter;
+ return new Density(value, DensityUnit.KilogramPerCubicCentimeter);
+ }
+ ///
+ /// Get Density from KilogramsPerCubicMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromKilogramsPerCubicMeter(double kilogramspercubicmeter)
+ {
+ double value = (double) kilogramspercubicmeter;
+ return new Density(value, DensityUnit.KilogramPerCubicMeter);
+ }
+ ///
+ /// Get Density from KilogramsPerCubicMillimeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromKilogramsPerCubicMillimeter(double kilogramspercubicmillimeter)
+ {
+ double value = (double) kilogramspercubicmillimeter;
+ return new Density(value, DensityUnit.KilogramPerCubicMillimeter);
+ }
+ ///
+ /// Get Density from KilopoundsPerCubicFoot.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromKilopoundsPerCubicFoot(double kilopoundspercubicfoot)
+ {
+ double value = (double) kilopoundspercubicfoot;
+ return new Density(value, DensityUnit.KilopoundPerCubicFoot);
+ }
+ ///
+ /// Get Density from KilopoundsPerCubicInch.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromKilopoundsPerCubicInch(double kilopoundspercubicinch)
+ {
+ double value = (double) kilopoundspercubicinch;
+ return new Density(value, DensityUnit.KilopoundPerCubicInch);
+ }
+ ///
+ /// Get Density from MicrogramsPerDeciLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromMicrogramsPerDeciLiter(double microgramsperdeciliter)
+ {
+ double value = (double) microgramsperdeciliter;
+ return new Density(value, DensityUnit.MicrogramPerDeciliter);
+ }
+ ///
+ /// Get Density from MicrogramsPerLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromMicrogramsPerLiter(double microgramsperliter)
+ {
+ double value = (double) microgramsperliter;
+ return new Density(value, DensityUnit.MicrogramPerLiter);
+ }
+ ///
+ /// Get Density from MicrogramsPerMilliliter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromMicrogramsPerMilliliter(double microgramspermilliliter)
+ {
+ double value = (double) microgramspermilliliter;
+ return new Density(value, DensityUnit.MicrogramPerMilliliter);
+ }
+ ///
+ /// Get Density from MilligramsPerCubicMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromMilligramsPerCubicMeter(double milligramspercubicmeter)
+ {
+ double value = (double) milligramspercubicmeter;
+ return new Density(value, DensityUnit.MilligramPerCubicMeter);
+ }
+ ///
+ /// Get Density from MilligramsPerDeciLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromMilligramsPerDeciLiter(double milligramsperdeciliter)
+ {
+ double value = (double) milligramsperdeciliter;
+ return new Density(value, DensityUnit.MilligramPerDeciliter);
+ }
+ ///
+ /// Get Density from MilligramsPerLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromMilligramsPerLiter(double milligramsperliter)
+ {
+ double value = (double) milligramsperliter;
+ return new Density(value, DensityUnit.MilligramPerLiter);
+ }
+ ///
+ /// Get Density from MilligramsPerMilliliter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromMilligramsPerMilliliter(double milligramspermilliliter)
+ {
+ double value = (double) milligramspermilliliter;
+ return new Density(value, DensityUnit.MilligramPerMilliliter);
+ }
+ ///
+ /// Get Density from NanogramsPerDeciLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromNanogramsPerDeciLiter(double nanogramsperdeciliter)
+ {
+ double value = (double) nanogramsperdeciliter;
+ return new Density(value, DensityUnit.NanogramPerDeciliter);
+ }
+ ///
+ /// Get Density from NanogramsPerLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromNanogramsPerLiter(double nanogramsperliter)
+ {
+ double value = (double) nanogramsperliter;
+ return new Density(value, DensityUnit.NanogramPerLiter);
+ }
+ ///
+ /// Get Density from NanogramsPerMilliliter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromNanogramsPerMilliliter(double nanogramspermilliliter)
+ {
+ double value = (double) nanogramspermilliliter;
+ return new Density(value, DensityUnit.NanogramPerMilliliter);
+ }
+ ///
+ /// Get Density from PicogramsPerDeciLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromPicogramsPerDeciLiter(double picogramsperdeciliter)
+ {
+ double value = (double) picogramsperdeciliter;
+ return new Density(value, DensityUnit.PicogramPerDeciliter);
+ }
+ ///
+ /// Get Density from PicogramsPerLiter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromPicogramsPerLiter(double picogramsperliter)
+ {
+ double value = (double) picogramsperliter;
+ return new Density(value, DensityUnit.PicogramPerLiter);
+ }
+ ///
+ /// Get Density from PicogramsPerMilliliter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromPicogramsPerMilliliter(double picogramspermilliliter)
+ {
+ double value = (double) picogramspermilliliter;
+ return new Density(value, DensityUnit.PicogramPerMilliliter);
+ }
+ ///
+ /// Get Density from PoundsPerCubicFoot.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromPoundsPerCubicFoot(double poundspercubicfoot)
+ {
+ double value = (double) poundspercubicfoot;
+ return new Density(value, DensityUnit.PoundPerCubicFoot);
+ }
+ ///
+ /// Get Density from PoundsPerCubicInch.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromPoundsPerCubicInch(double poundspercubicinch)
+ {
+ double value = (double) poundspercubicinch;
+ return new Density(value, DensityUnit.PoundPerCubicInch);
+ }
+ ///
+ /// Get Density from PoundsPerImperialGallon.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromPoundsPerImperialGallon(double poundsperimperialgallon)
+ {
+ double value = (double) poundsperimperialgallon;
+ return new Density(value, DensityUnit.PoundPerImperialGallon);
+ }
+ ///
+ /// Get Density from PoundsPerUSGallon.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromPoundsPerUSGallon(double poundsperusgallon)
+ {
+ double value = (double) poundsperusgallon;
+ return new Density(value, DensityUnit.PoundPerUSGallon);
+ }
+ ///
+ /// Get Density from SlugsPerCubicFoot.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromSlugsPerCubicFoot(double slugspercubicfoot)
+ {
+ double value = (double) slugspercubicfoot;
+ return new Density(value, DensityUnit.SlugPerCubicFoot);
+ }
+ ///
+ /// Get Density from TonnesPerCubicCentimeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromTonnesPerCubicCentimeter(double tonnespercubiccentimeter)
+ {
+ double value = (double) tonnespercubiccentimeter;
+ return new Density(value, DensityUnit.TonnePerCubicCentimeter);
+ }
+ ///
+ /// Get Density from TonnesPerCubicMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromTonnesPerCubicMeter(double tonnespercubicmeter)
+ {
+ double value = (double) tonnespercubicmeter;
+ return new Density(value, DensityUnit.TonnePerCubicMeter);
+ }
+ ///
+ /// Get Density from TonnesPerCubicMillimeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Density FromTonnesPerCubicMillimeter(double tonnespercubicmillimeter)
+ {
+ double value = (double) tonnespercubicmillimeter;
+ return new Density(value, DensityUnit.TonnePerCubicMillimeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Density unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Density From(double value, DensityUnit fromUnit)
+ {
+ return new Density((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Density Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Density result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Density result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static DensityUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static DensityUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out DensityUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out DensityUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Density)) throw new ArgumentException("Expected type Density.", nameof(obj));
+
+ return CompareTo((Density)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Density other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Density within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Density other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Density.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(DensityUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Density to another Density with the unit representation .
+ ///
+ /// A Density with the specified unit.
+ public Density ToUnit(DensityUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Density(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case DensityUnit.CentigramPerDeciliter: return (_value/1e-1) * 1e-2d;
+ case DensityUnit.CentigramPerLiter: return (_value/1) * 1e-2d;
+ case DensityUnit.CentigramPerMilliliter: return (_value/1e-3) * 1e-2d;
+ case DensityUnit.DecigramPerDeciliter: return (_value/1e-1) * 1e-1d;
+ case DensityUnit.DecigramPerLiter: return (_value/1) * 1e-1d;
+ case DensityUnit.DecigramPerMilliliter: return (_value/1e-3) * 1e-1d;
+ case DensityUnit.GramPerCubicCentimeter: return _value/1e-3;
+ case DensityUnit.GramPerCubicMeter: return _value/1e3;
+ case DensityUnit.GramPerCubicMillimeter: return _value/1e-6;
+ case DensityUnit.GramPerDeciliter: return _value/1e-1;
+ case DensityUnit.GramPerLiter: return _value/1;
+ case DensityUnit.GramPerMilliliter: return _value/1e-3;
+ case DensityUnit.KilogramPerCubicCentimeter: return (_value/1e-3) * 1e3d;
+ case DensityUnit.KilogramPerCubicMeter: return (_value/1e3) * 1e3d;
+ case DensityUnit.KilogramPerCubicMillimeter: return (_value/1e-6) * 1e3d;
+ case DensityUnit.KilopoundPerCubicFoot: return (_value/0.062427961) * 1e3d;
+ case DensityUnit.KilopoundPerCubicInch: return (_value/3.6127298147753e-5) * 1e3d;
+ case DensityUnit.MicrogramPerDeciliter: return (_value/1e-1) * 1e-6d;
+ case DensityUnit.MicrogramPerLiter: return (_value/1) * 1e-6d;
+ case DensityUnit.MicrogramPerMilliliter: return (_value/1e-3) * 1e-6d;
+ case DensityUnit.MilligramPerCubicMeter: return (_value/1e3) * 1e-3d;
+ case DensityUnit.MilligramPerDeciliter: return (_value/1e-1) * 1e-3d;
+ case DensityUnit.MilligramPerLiter: return (_value/1) * 1e-3d;
+ case DensityUnit.MilligramPerMilliliter: return (_value/1e-3) * 1e-3d;
+ case DensityUnit.NanogramPerDeciliter: return (_value/1e-1) * 1e-9d;
+ case DensityUnit.NanogramPerLiter: return (_value/1) * 1e-9d;
+ case DensityUnit.NanogramPerMilliliter: return (_value/1e-3) * 1e-9d;
+ case DensityUnit.PicogramPerDeciliter: return (_value/1e-1) * 1e-12d;
+ case DensityUnit.PicogramPerLiter: return (_value/1) * 1e-12d;
+ case DensityUnit.PicogramPerMilliliter: return (_value/1e-3) * 1e-12d;
+ case DensityUnit.PoundPerCubicFoot: return _value/0.062427961;
+ case DensityUnit.PoundPerCubicInch: return _value/3.6127298147753e-5;
+ case DensityUnit.PoundPerImperialGallon: return _value*9.9776398e1;
+ case DensityUnit.PoundPerUSGallon: return _value*1.19826427e2;
+ case DensityUnit.SlugPerCubicFoot: return _value*515.378818;
+ case DensityUnit.TonnePerCubicCentimeter: return _value/1e-9;
+ case DensityUnit.TonnePerCubicMeter: return _value/0.001;
+ case DensityUnit.TonnePerCubicMillimeter: return _value/1e-12;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(DensityUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case DensityUnit.CentigramPerDeciliter: return (baseUnitValue*1e-1) / 1e-2d;
+ case DensityUnit.CentigramPerLiter: return (baseUnitValue*1) / 1e-2d;
+ case DensityUnit.CentigramPerMilliliter: return (baseUnitValue*1e-3) / 1e-2d;
+ case DensityUnit.DecigramPerDeciliter: return (baseUnitValue*1e-1) / 1e-1d;
+ case DensityUnit.DecigramPerLiter: return (baseUnitValue*1) / 1e-1d;
+ case DensityUnit.DecigramPerMilliliter: return (baseUnitValue*1e-3) / 1e-1d;
+ case DensityUnit.GramPerCubicCentimeter: return baseUnitValue*1e-3;
+ case DensityUnit.GramPerCubicMeter: return baseUnitValue*1e3;
+ case DensityUnit.GramPerCubicMillimeter: return baseUnitValue*1e-6;
+ case DensityUnit.GramPerDeciliter: return baseUnitValue*1e-1;
+ case DensityUnit.GramPerLiter: return baseUnitValue*1;
+ case DensityUnit.GramPerMilliliter: return baseUnitValue*1e-3;
+ case DensityUnit.KilogramPerCubicCentimeter: return (baseUnitValue*1e-3) / 1e3d;
+ case DensityUnit.KilogramPerCubicMeter: return (baseUnitValue*1e3) / 1e3d;
+ case DensityUnit.KilogramPerCubicMillimeter: return (baseUnitValue*1e-6) / 1e3d;
+ case DensityUnit.KilopoundPerCubicFoot: return (baseUnitValue*0.062427961) / 1e3d;
+ case DensityUnit.KilopoundPerCubicInch: return (baseUnitValue*3.6127298147753e-5) / 1e3d;
+ case DensityUnit.MicrogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-6d;
+ case DensityUnit.MicrogramPerLiter: return (baseUnitValue*1) / 1e-6d;
+ case DensityUnit.MicrogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-6d;
+ case DensityUnit.MilligramPerCubicMeter: return (baseUnitValue*1e3) / 1e-3d;
+ case DensityUnit.MilligramPerDeciliter: return (baseUnitValue*1e-1) / 1e-3d;
+ case DensityUnit.MilligramPerLiter: return (baseUnitValue*1) / 1e-3d;
+ case DensityUnit.MilligramPerMilliliter: return (baseUnitValue*1e-3) / 1e-3d;
+ case DensityUnit.NanogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-9d;
+ case DensityUnit.NanogramPerLiter: return (baseUnitValue*1) / 1e-9d;
+ case DensityUnit.NanogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-9d;
+ case DensityUnit.PicogramPerDeciliter: return (baseUnitValue*1e-1) / 1e-12d;
+ case DensityUnit.PicogramPerLiter: return (baseUnitValue*1) / 1e-12d;
+ case DensityUnit.PicogramPerMilliliter: return (baseUnitValue*1e-3) / 1e-12d;
+ case DensityUnit.PoundPerCubicFoot: return baseUnitValue*0.062427961;
+ case DensityUnit.PoundPerCubicInch: return baseUnitValue*3.6127298147753e-5;
+ case DensityUnit.PoundPerImperialGallon: return baseUnitValue/9.9776398e1;
+ case DensityUnit.PoundPerUSGallon: return baseUnitValue/1.19826427e2;
+ case DensityUnit.SlugPerCubicFoot: return baseUnitValue*0.00194032033;
+ case DensityUnit.TonnePerCubicCentimeter: return baseUnitValue*1e-9;
+ case DensityUnit.TonnePerCubicMeter: return baseUnitValue*0.001;
+ case DensityUnit.TonnePerCubicMillimeter: return baseUnitValue*1e-12;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Duration.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Duration.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..d6da3f36c3
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Duration.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,723 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Time is a dimension in which events can be ordered from the past through the present into the future, and also the measure of durations of events and the intervals between them.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Duration : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly DurationUnit? _unit;
+
+ static Duration()
+ {
+ BaseDimensions = new BaseDimensions(0, 0, 1, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Second.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Duration()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Duration(double numericValue, DurationUnit unit)
+ {
+ if(unit == DurationUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Duration, which is Second. All conversions go via this value.
+ ///
+ public static DurationUnit BaseUnit => DurationUnit.Second;
+
+ ///
+ /// Represents the largest possible value of Duration
+ ///
+ public static Duration MaxValue => new Duration(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Duration
+ ///
+ public static Duration MinValue => new Duration(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Duration;
+
+ ///
+ /// All units of measurement for the Duration quantity.
+ ///
+ public static DurationUnit[] Units { get; } = Enum.GetValues(typeof(DurationUnit)).Cast().Except(new DurationUnit[]{ DurationUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Second.
+ ///
+ public static Duration Zero => new Duration(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public DurationUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Duration.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Duration.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Duration in Days.
+ ///
+ public double Days => As(DurationUnit.Day);
+
+ ///
+ /// Get Duration in Hours.
+ ///
+ public double Hours => As(DurationUnit.Hour);
+
+ ///
+ /// Get Duration in Microseconds.
+ ///
+ public double Microseconds => As(DurationUnit.Microsecond);
+
+ ///
+ /// Get Duration in Milliseconds.
+ ///
+ public double Milliseconds => As(DurationUnit.Millisecond);
+
+ ///
+ /// Get Duration in Minutes.
+ ///
+ public double Minutes => As(DurationUnit.Minute);
+
+ ///
+ /// Get Duration in Months30.
+ ///
+ public double Months30 => As(DurationUnit.Month30);
+
+ ///
+ /// Get Duration in Nanoseconds.
+ ///
+ public double Nanoseconds => As(DurationUnit.Nanosecond);
+
+ ///
+ /// Get Duration in Seconds.
+ ///
+ public double Seconds => As(DurationUnit.Second);
+
+ ///
+ /// Get Duration in Weeks.
+ ///
+ public double Weeks => As(DurationUnit.Week);
+
+ ///
+ /// Get Duration in Years365.
+ ///
+ public double Years365 => As(DurationUnit.Year365);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(DurationUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(DurationUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Duration from Days.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Duration FromDays(double days)
+ {
+ double value = (double) days;
+ return new Duration(value, DurationUnit.Day);
+ }
+ ///
+ /// Get Duration from Hours.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Duration FromHours(double hours)
+ {
+ double value = (double) hours;
+ return new Duration(value, DurationUnit.Hour);
+ }
+ ///
+ /// Get Duration from Microseconds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Duration FromMicroseconds(double microseconds)
+ {
+ double value = (double) microseconds;
+ return new Duration(value, DurationUnit.Microsecond);
+ }
+ ///
+ /// Get Duration from Milliseconds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Duration FromMilliseconds(double milliseconds)
+ {
+ double value = (double) milliseconds;
+ return new Duration(value, DurationUnit.Millisecond);
+ }
+ ///
+ /// Get Duration from Minutes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Duration FromMinutes(double minutes)
+ {
+ double value = (double) minutes;
+ return new Duration(value, DurationUnit.Minute);
+ }
+ ///
+ /// Get Duration from Months30.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Duration FromMonths30(double months30)
+ {
+ double value = (double) months30;
+ return new Duration(value, DurationUnit.Month30);
+ }
+ ///
+ /// Get Duration from Nanoseconds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Duration FromNanoseconds(double nanoseconds)
+ {
+ double value = (double) nanoseconds;
+ return new Duration(value, DurationUnit.Nanosecond);
+ }
+ ///
+ /// Get Duration from Seconds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Duration FromSeconds(double seconds)
+ {
+ double value = (double) seconds;
+ return new Duration(value, DurationUnit.Second);
+ }
+ ///
+ /// Get Duration from Weeks.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Duration FromWeeks(double weeks)
+ {
+ double value = (double) weeks;
+ return new Duration(value, DurationUnit.Week);
+ }
+ ///
+ /// Get Duration from Years365.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Duration FromYears365(double years365)
+ {
+ double value = (double) years365;
+ return new Duration(value, DurationUnit.Year365);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Duration unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Duration From(double value, DurationUnit fromUnit)
+ {
+ return new Duration((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Duration Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Duration result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Duration result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static DurationUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static DurationUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out DurationUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out DurationUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Duration)) throw new ArgumentException("Expected type Duration.", nameof(obj));
+
+ return CompareTo((Duration)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Duration other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Duration within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Duration other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Duration.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(DurationUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Duration to another Duration with the unit representation .
+ ///
+ /// A Duration with the specified unit.
+ public Duration ToUnit(DurationUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Duration(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case DurationUnit.Day: return _value*24*3600;
+ case DurationUnit.Hour: return _value*3600;
+ case DurationUnit.Microsecond: return (_value) * 1e-6d;
+ case DurationUnit.Millisecond: return (_value) * 1e-3d;
+ case DurationUnit.Minute: return _value*60;
+ case DurationUnit.Month30: return _value*30*24*3600;
+ case DurationUnit.Nanosecond: return (_value) * 1e-9d;
+ case DurationUnit.Second: return _value;
+ case DurationUnit.Week: return _value*7*24*3600;
+ case DurationUnit.Year365: return _value*365*24*3600;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(DurationUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case DurationUnit.Day: return baseUnitValue/(24*3600);
+ case DurationUnit.Hour: return baseUnitValue/3600;
+ case DurationUnit.Microsecond: return (baseUnitValue) / 1e-6d;
+ case DurationUnit.Millisecond: return (baseUnitValue) / 1e-3d;
+ case DurationUnit.Minute: return baseUnitValue/60;
+ case DurationUnit.Month30: return baseUnitValue/(30*24*3600);
+ case DurationUnit.Nanosecond: return (baseUnitValue) / 1e-9d;
+ case DurationUnit.Second: return baseUnitValue;
+ case DurationUnit.Week: return baseUnitValue/(7*24*3600);
+ case DurationUnit.Year365: return baseUnitValue/(365*24*3600);
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/DynamicViscosity.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/DynamicViscosity.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..4faa9c6a73
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/DynamicViscosity.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,658 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The dynamic (shear) viscosity of a fluid expresses its resistance to shearing flows, where adjacent layers move parallel to each other with different speeds
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Viscosity#Dynamic_.28shear.29_viscosity
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class DynamicViscosity : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly DynamicViscosityUnit? _unit;
+
+ static DynamicViscosity()
+ {
+ BaseDimensions = new BaseDimensions(-1, 1, -1, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit NewtonSecondPerMeterSquared.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public DynamicViscosity()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private DynamicViscosity(double numericValue, DynamicViscosityUnit unit)
+ {
+ if(unit == DynamicViscosityUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of DynamicViscosity, which is NewtonSecondPerMeterSquared. All conversions go via this value.
+ ///
+ public static DynamicViscosityUnit BaseUnit => DynamicViscosityUnit.NewtonSecondPerMeterSquared;
+
+ ///
+ /// Represents the largest possible value of DynamicViscosity
+ ///
+ public static DynamicViscosity MaxValue => new DynamicViscosity(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of DynamicViscosity
+ ///
+ public static DynamicViscosity MinValue => new DynamicViscosity(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.DynamicViscosity;
+
+ ///
+ /// All units of measurement for the DynamicViscosity quantity.
+ ///
+ public static DynamicViscosityUnit[] Units { get; } = Enum.GetValues(typeof(DynamicViscosityUnit)).Cast().Except(new DynamicViscosityUnit[]{ DynamicViscosityUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit NewtonSecondPerMeterSquared.
+ ///
+ public static DynamicViscosity Zero => new DynamicViscosity(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public DynamicViscosityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => DynamicViscosity.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => DynamicViscosity.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get DynamicViscosity in Centipoise.
+ ///
+ public double Centipoise => As(DynamicViscosityUnit.Centipoise);
+
+ ///
+ /// Get DynamicViscosity in MicropascalSeconds.
+ ///
+ public double MicropascalSeconds => As(DynamicViscosityUnit.MicropascalSecond);
+
+ ///
+ /// Get DynamicViscosity in MillipascalSeconds.
+ ///
+ public double MillipascalSeconds => As(DynamicViscosityUnit.MillipascalSecond);
+
+ ///
+ /// Get DynamicViscosity in NewtonSecondsPerMeterSquared.
+ ///
+ public double NewtonSecondsPerMeterSquared => As(DynamicViscosityUnit.NewtonSecondPerMeterSquared);
+
+ ///
+ /// Get DynamicViscosity in PascalSeconds.
+ ///
+ public double PascalSeconds => As(DynamicViscosityUnit.PascalSecond);
+
+ ///
+ /// Get DynamicViscosity in Poise.
+ ///
+ public double Poise => As(DynamicViscosityUnit.Poise);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(DynamicViscosityUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(DynamicViscosityUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get DynamicViscosity from Centipoise.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static DynamicViscosity FromCentipoise(double centipoise)
+ {
+ double value = (double) centipoise;
+ return new DynamicViscosity(value, DynamicViscosityUnit.Centipoise);
+ }
+ ///
+ /// Get DynamicViscosity from MicropascalSeconds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static DynamicViscosity FromMicropascalSeconds(double micropascalseconds)
+ {
+ double value = (double) micropascalseconds;
+ return new DynamicViscosity(value, DynamicViscosityUnit.MicropascalSecond);
+ }
+ ///
+ /// Get DynamicViscosity from MillipascalSeconds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static DynamicViscosity FromMillipascalSeconds(double millipascalseconds)
+ {
+ double value = (double) millipascalseconds;
+ return new DynamicViscosity(value, DynamicViscosityUnit.MillipascalSecond);
+ }
+ ///
+ /// Get DynamicViscosity from NewtonSecondsPerMeterSquared.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static DynamicViscosity FromNewtonSecondsPerMeterSquared(double newtonsecondspermetersquared)
+ {
+ double value = (double) newtonsecondspermetersquared;
+ return new DynamicViscosity(value, DynamicViscosityUnit.NewtonSecondPerMeterSquared);
+ }
+ ///
+ /// Get DynamicViscosity from PascalSeconds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static DynamicViscosity FromPascalSeconds(double pascalseconds)
+ {
+ double value = (double) pascalseconds;
+ return new DynamicViscosity(value, DynamicViscosityUnit.PascalSecond);
+ }
+ ///
+ /// Get DynamicViscosity from Poise.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static DynamicViscosity FromPoise(double poise)
+ {
+ double value = (double) poise;
+ return new DynamicViscosity(value, DynamicViscosityUnit.Poise);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// DynamicViscosity unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static DynamicViscosity From(double value, DynamicViscosityUnit fromUnit)
+ {
+ return new DynamicViscosity((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static DynamicViscosity Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out DynamicViscosity result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out DynamicViscosity result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static DynamicViscosityUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static DynamicViscosityUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out DynamicViscosityUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out DynamicViscosityUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is DynamicViscosity)) throw new ArgumentException("Expected type DynamicViscosity.", nameof(obj));
+
+ return CompareTo((DynamicViscosity)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(DynamicViscosity other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another DynamicViscosity within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(DynamicViscosity other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current DynamicViscosity.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(DynamicViscosityUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this DynamicViscosity to another DynamicViscosity with the unit representation .
+ ///
+ /// A DynamicViscosity with the specified unit.
+ public DynamicViscosity ToUnit(DynamicViscosityUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new DynamicViscosity(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case DynamicViscosityUnit.Centipoise: return (_value/10) * 1e-2d;
+ case DynamicViscosityUnit.MicropascalSecond: return (_value) * 1e-6d;
+ case DynamicViscosityUnit.MillipascalSecond: return (_value) * 1e-3d;
+ case DynamicViscosityUnit.NewtonSecondPerMeterSquared: return _value;
+ case DynamicViscosityUnit.PascalSecond: return _value;
+ case DynamicViscosityUnit.Poise: return _value/10;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(DynamicViscosityUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case DynamicViscosityUnit.Centipoise: return (baseUnitValue*10) / 1e-2d;
+ case DynamicViscosityUnit.MicropascalSecond: return (baseUnitValue) / 1e-6d;
+ case DynamicViscosityUnit.MillipascalSecond: return (baseUnitValue) / 1e-3d;
+ case DynamicViscosityUnit.NewtonSecondPerMeterSquared: return baseUnitValue;
+ case DynamicViscosityUnit.PascalSecond: return baseUnitValue;
+ case DynamicViscosityUnit.Poise: return baseUnitValue*10;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricAdmittance.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricAdmittance.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..42f0c6faaa
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricAdmittance.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,621 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Electric admittance is a measure of how easily a circuit or device will allow a current to flow. It is defined as the inverse of impedance. The SI unit of admittance is the siemens (symbol S).
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricAdmittance : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricAdmittanceUnit? _unit;
+
+ static ElectricAdmittance()
+ {
+ BaseDimensions = new BaseDimensions(-2, -1, 3, 2, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Siemens.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricAdmittance()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricAdmittance(double numericValue, ElectricAdmittanceUnit unit)
+ {
+ if(unit == ElectricAdmittanceUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricAdmittance, which is Siemens. All conversions go via this value.
+ ///
+ public static ElectricAdmittanceUnit BaseUnit => ElectricAdmittanceUnit.Siemens;
+
+ ///
+ /// Represents the largest possible value of ElectricAdmittance
+ ///
+ public static ElectricAdmittance MaxValue => new ElectricAdmittance(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricAdmittance
+ ///
+ public static ElectricAdmittance MinValue => new ElectricAdmittance(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricAdmittance;
+
+ ///
+ /// All units of measurement for the ElectricAdmittance quantity.
+ ///
+ public static ElectricAdmittanceUnit[] Units { get; } = Enum.GetValues(typeof(ElectricAdmittanceUnit)).Cast().Except(new ElectricAdmittanceUnit[]{ ElectricAdmittanceUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Siemens.
+ ///
+ public static ElectricAdmittance Zero => new ElectricAdmittance(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricAdmittanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricAdmittance.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricAdmittance.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricAdmittance in Microsiemens.
+ ///
+ public double Microsiemens => As(ElectricAdmittanceUnit.Microsiemens);
+
+ ///
+ /// Get ElectricAdmittance in Millisiemens.
+ ///
+ public double Millisiemens => As(ElectricAdmittanceUnit.Millisiemens);
+
+ ///
+ /// Get ElectricAdmittance in Nanosiemens.
+ ///
+ public double Nanosiemens => As(ElectricAdmittanceUnit.Nanosiemens);
+
+ ///
+ /// Get ElectricAdmittance in Siemens.
+ ///
+ public double Siemens => As(ElectricAdmittanceUnit.Siemens);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricAdmittanceUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricAdmittanceUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricAdmittance from Microsiemens.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricAdmittance FromMicrosiemens(double microsiemens)
+ {
+ double value = (double) microsiemens;
+ return new ElectricAdmittance(value, ElectricAdmittanceUnit.Microsiemens);
+ }
+ ///
+ /// Get ElectricAdmittance from Millisiemens.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricAdmittance FromMillisiemens(double millisiemens)
+ {
+ double value = (double) millisiemens;
+ return new ElectricAdmittance(value, ElectricAdmittanceUnit.Millisiemens);
+ }
+ ///
+ /// Get ElectricAdmittance from Nanosiemens.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricAdmittance FromNanosiemens(double nanosiemens)
+ {
+ double value = (double) nanosiemens;
+ return new ElectricAdmittance(value, ElectricAdmittanceUnit.Nanosiemens);
+ }
+ ///
+ /// Get ElectricAdmittance from Siemens.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricAdmittance FromSiemens(double siemens)
+ {
+ double value = (double) siemens;
+ return new ElectricAdmittance(value, ElectricAdmittanceUnit.Siemens);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricAdmittance unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricAdmittance From(double value, ElectricAdmittanceUnit fromUnit)
+ {
+ return new ElectricAdmittance((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricAdmittance Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricAdmittance Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricAdmittance result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricAdmittance result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricAdmittanceUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricAdmittanceUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricAdmittanceUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricAdmittanceUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricAdmittance)) throw new ArgumentException("Expected type ElectricAdmittance.", nameof(obj));
+
+ return CompareTo((ElectricAdmittance)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricAdmittance other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricAdmittance within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricAdmittance other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricAdmittance.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricAdmittanceUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricAdmittance to another ElectricAdmittance with the unit representation .
+ ///
+ /// A ElectricAdmittance with the specified unit.
+ public ElectricAdmittance ToUnit(ElectricAdmittanceUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricAdmittance(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricAdmittanceUnit.Microsiemens: return (_value) * 1e-6d;
+ case ElectricAdmittanceUnit.Millisiemens: return (_value) * 1e-3d;
+ case ElectricAdmittanceUnit.Nanosiemens: return (_value) * 1e-9d;
+ case ElectricAdmittanceUnit.Siemens: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricAdmittanceUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricAdmittanceUnit.Microsiemens: return (baseUnitValue) / 1e-6d;
+ case ElectricAdmittanceUnit.Millisiemens: return (baseUnitValue) / 1e-3d;
+ case ElectricAdmittanceUnit.Nanosiemens: return (baseUnitValue) / 1e-9d;
+ case ElectricAdmittanceUnit.Siemens: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCharge.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCharge.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..a3f707e4d3
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCharge.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Electric charge is the physical property of matter that causes it to experience a force when placed in an electromagnetic field.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Electric_charge
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricCharge : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricChargeUnit? _unit;
+
+ static ElectricCharge()
+ {
+ BaseDimensions = new BaseDimensions(0, 0, 1, 1, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Coulomb.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricCharge()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricCharge(double numericValue, ElectricChargeUnit unit)
+ {
+ if(unit == ElectricChargeUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricCharge, which is Coulomb. All conversions go via this value.
+ ///
+ public static ElectricChargeUnit BaseUnit => ElectricChargeUnit.Coulomb;
+
+ ///
+ /// Represents the largest possible value of ElectricCharge
+ ///
+ public static ElectricCharge MaxValue => new ElectricCharge(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricCharge
+ ///
+ public static ElectricCharge MinValue => new ElectricCharge(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricCharge;
+
+ ///
+ /// All units of measurement for the ElectricCharge quantity.
+ ///
+ public static ElectricChargeUnit[] Units { get; } = Enum.GetValues(typeof(ElectricChargeUnit)).Cast().Except(new ElectricChargeUnit[]{ ElectricChargeUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Coulomb.
+ ///
+ public static ElectricCharge Zero => new ElectricCharge(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricChargeUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricCharge.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricCharge.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricCharge in Coulombs.
+ ///
+ public double Coulombs => As(ElectricChargeUnit.Coulomb);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricChargeUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricChargeUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricCharge from Coulombs.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricCharge FromCoulombs(double coulombs)
+ {
+ double value = (double) coulombs;
+ return new ElectricCharge(value, ElectricChargeUnit.Coulomb);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricCharge unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricCharge From(double value, ElectricChargeUnit fromUnit)
+ {
+ return new ElectricCharge((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricCharge Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricCharge Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricCharge result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricCharge result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricChargeUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricChargeUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricChargeUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricChargeUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricCharge)) throw new ArgumentException("Expected type ElectricCharge.", nameof(obj));
+
+ return CompareTo((ElectricCharge)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricCharge other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricCharge within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricCharge other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricCharge.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricChargeUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricCharge to another ElectricCharge with the unit representation .
+ ///
+ /// A ElectricCharge with the specified unit.
+ public ElectricCharge ToUnit(ElectricChargeUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricCharge(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricChargeUnit.Coulomb: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricChargeUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricChargeUnit.Coulomb: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricChargeDensity.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricChargeDensity.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..0e81c2f40b
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricChargeDensity.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In electromagnetism, charge density is a measure of the amount of electric charge per unit length, surface area, or volume.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Charge_density
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricChargeDensity : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricChargeDensityUnit? _unit;
+
+ static ElectricChargeDensity()
+ {
+ BaseDimensions = new BaseDimensions(-3, 0, 1, 1, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit CoulombPerCubicMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricChargeDensity()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricChargeDensity(double numericValue, ElectricChargeDensityUnit unit)
+ {
+ if(unit == ElectricChargeDensityUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricChargeDensity, which is CoulombPerCubicMeter. All conversions go via this value.
+ ///
+ public static ElectricChargeDensityUnit BaseUnit => ElectricChargeDensityUnit.CoulombPerCubicMeter;
+
+ ///
+ /// Represents the largest possible value of ElectricChargeDensity
+ ///
+ public static ElectricChargeDensity MaxValue => new ElectricChargeDensity(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricChargeDensity
+ ///
+ public static ElectricChargeDensity MinValue => new ElectricChargeDensity(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricChargeDensity;
+
+ ///
+ /// All units of measurement for the ElectricChargeDensity quantity.
+ ///
+ public static ElectricChargeDensityUnit[] Units { get; } = Enum.GetValues(typeof(ElectricChargeDensityUnit)).Cast().Except(new ElectricChargeDensityUnit[]{ ElectricChargeDensityUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit CoulombPerCubicMeter.
+ ///
+ public static ElectricChargeDensity Zero => new ElectricChargeDensity(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricChargeDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricChargeDensity.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricChargeDensity.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricChargeDensity in CoulombsPerCubicMeter.
+ ///
+ public double CoulombsPerCubicMeter => As(ElectricChargeDensityUnit.CoulombPerCubicMeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricChargeDensityUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricChargeDensityUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricChargeDensity from CoulombsPerCubicMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricChargeDensity FromCoulombsPerCubicMeter(double coulombspercubicmeter)
+ {
+ double value = (double) coulombspercubicmeter;
+ return new ElectricChargeDensity(value, ElectricChargeDensityUnit.CoulombPerCubicMeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricChargeDensity unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricChargeDensity From(double value, ElectricChargeDensityUnit fromUnit)
+ {
+ return new ElectricChargeDensity((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricChargeDensity Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricChargeDensity Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricChargeDensity result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricChargeDensity result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricChargeDensityUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricChargeDensityUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricChargeDensityUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricChargeDensityUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricChargeDensity)) throw new ArgumentException("Expected type ElectricChargeDensity.", nameof(obj));
+
+ return CompareTo((ElectricChargeDensity)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricChargeDensity other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricChargeDensity within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricChargeDensity other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricChargeDensity.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricChargeDensityUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricChargeDensity to another ElectricChargeDensity with the unit representation .
+ ///
+ /// A ElectricChargeDensity with the specified unit.
+ public ElectricChargeDensity ToUnit(ElectricChargeDensityUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricChargeDensity(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricChargeDensityUnit.CoulombPerCubicMeter: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricChargeDensityUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricChargeDensityUnit.CoulombPerCubicMeter: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricConductance.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricConductance.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..17b4739907
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricConductance.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,607 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The electrical conductance of an electrical conductor is a measure of the easeness to pass an electric current through that conductor.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Electrical_resistance_and_conductance
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricConductance : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricConductanceUnit? _unit;
+
+ static ElectricConductance()
+ {
+ BaseDimensions = new BaseDimensions(-2, -1, 3, 2, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Siemens.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricConductance()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricConductance(double numericValue, ElectricConductanceUnit unit)
+ {
+ if(unit == ElectricConductanceUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricConductance, which is Siemens. All conversions go via this value.
+ ///
+ public static ElectricConductanceUnit BaseUnit => ElectricConductanceUnit.Siemens;
+
+ ///
+ /// Represents the largest possible value of ElectricConductance
+ ///
+ public static ElectricConductance MaxValue => new ElectricConductance(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricConductance
+ ///
+ public static ElectricConductance MinValue => new ElectricConductance(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricConductance;
+
+ ///
+ /// All units of measurement for the ElectricConductance quantity.
+ ///
+ public static ElectricConductanceUnit[] Units { get; } = Enum.GetValues(typeof(ElectricConductanceUnit)).Cast().Except(new ElectricConductanceUnit[]{ ElectricConductanceUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Siemens.
+ ///
+ public static ElectricConductance Zero => new ElectricConductance(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricConductanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricConductance.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricConductance.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricConductance in Microsiemens.
+ ///
+ public double Microsiemens => As(ElectricConductanceUnit.Microsiemens);
+
+ ///
+ /// Get ElectricConductance in Millisiemens.
+ ///
+ public double Millisiemens => As(ElectricConductanceUnit.Millisiemens);
+
+ ///
+ /// Get ElectricConductance in Siemens.
+ ///
+ public double Siemens => As(ElectricConductanceUnit.Siemens);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricConductanceUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricConductanceUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricConductance from Microsiemens.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricConductance FromMicrosiemens(double microsiemens)
+ {
+ double value = (double) microsiemens;
+ return new ElectricConductance(value, ElectricConductanceUnit.Microsiemens);
+ }
+ ///
+ /// Get ElectricConductance from Millisiemens.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricConductance FromMillisiemens(double millisiemens)
+ {
+ double value = (double) millisiemens;
+ return new ElectricConductance(value, ElectricConductanceUnit.Millisiemens);
+ }
+ ///
+ /// Get ElectricConductance from Siemens.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricConductance FromSiemens(double siemens)
+ {
+ double value = (double) siemens;
+ return new ElectricConductance(value, ElectricConductanceUnit.Siemens);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricConductance unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricConductance From(double value, ElectricConductanceUnit fromUnit)
+ {
+ return new ElectricConductance((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricConductance Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricConductance Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricConductance result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricConductance result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricConductanceUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricConductanceUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricConductanceUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricConductanceUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricConductance)) throw new ArgumentException("Expected type ElectricConductance.", nameof(obj));
+
+ return CompareTo((ElectricConductance)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricConductance other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricConductance within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricConductance other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricConductance.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricConductanceUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricConductance to another ElectricConductance with the unit representation .
+ ///
+ /// A ElectricConductance with the specified unit.
+ public ElectricConductance ToUnit(ElectricConductanceUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricConductance(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricConductanceUnit.Microsiemens: return (_value) * 1e-6d;
+ case ElectricConductanceUnit.Millisiemens: return (_value) * 1e-3d;
+ case ElectricConductanceUnit.Siemens: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricConductanceUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricConductanceUnit.Microsiemens: return (baseUnitValue) / 1e-6d;
+ case ElectricConductanceUnit.Millisiemens: return (baseUnitValue) / 1e-3d;
+ case ElectricConductanceUnit.Siemens: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricConductivity.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricConductivity.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..5f0854098d
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricConductivity.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Electrical conductivity or specific conductance is the reciprocal of electrical resistivity, and measures a material's ability to conduct an electric current.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Electrical_resistivity_and_conductivity
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricConductivity : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricConductivityUnit? _unit;
+
+ static ElectricConductivity()
+ {
+ BaseDimensions = new BaseDimensions(-3, -1, 3, 2, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit SiemensPerMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricConductivity()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricConductivity(double numericValue, ElectricConductivityUnit unit)
+ {
+ if(unit == ElectricConductivityUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricConductivity, which is SiemensPerMeter. All conversions go via this value.
+ ///
+ public static ElectricConductivityUnit BaseUnit => ElectricConductivityUnit.SiemensPerMeter;
+
+ ///
+ /// Represents the largest possible value of ElectricConductivity
+ ///
+ public static ElectricConductivity MaxValue => new ElectricConductivity(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricConductivity
+ ///
+ public static ElectricConductivity MinValue => new ElectricConductivity(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricConductivity;
+
+ ///
+ /// All units of measurement for the ElectricConductivity quantity.
+ ///
+ public static ElectricConductivityUnit[] Units { get; } = Enum.GetValues(typeof(ElectricConductivityUnit)).Cast().Except(new ElectricConductivityUnit[]{ ElectricConductivityUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit SiemensPerMeter.
+ ///
+ public static ElectricConductivity Zero => new ElectricConductivity(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricConductivityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricConductivity.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricConductivity.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricConductivity in SiemensPerMeter.
+ ///
+ public double SiemensPerMeter => As(ElectricConductivityUnit.SiemensPerMeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricConductivityUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricConductivityUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricConductivity from SiemensPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricConductivity FromSiemensPerMeter(double siemenspermeter)
+ {
+ double value = (double) siemenspermeter;
+ return new ElectricConductivity(value, ElectricConductivityUnit.SiemensPerMeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricConductivity unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricConductivity From(double value, ElectricConductivityUnit fromUnit)
+ {
+ return new ElectricConductivity((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricConductivity Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricConductivity Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricConductivity result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricConductivity result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricConductivityUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricConductivityUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricConductivityUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricConductivityUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricConductivity)) throw new ArgumentException("Expected type ElectricConductivity.", nameof(obj));
+
+ return CompareTo((ElectricConductivity)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricConductivity other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricConductivity within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricConductivity other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricConductivity.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricConductivityUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricConductivity to another ElectricConductivity with the unit representation .
+ ///
+ /// A ElectricConductivity with the specified unit.
+ public ElectricConductivity ToUnit(ElectricConductivityUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricConductivity(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricConductivityUnit.SiemensPerMeter: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricConductivityUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricConductivityUnit.SiemensPerMeter: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCurrent.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCurrent.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..922de73b93
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCurrent.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,689 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// An electric current is a flow of electric charge. In electric circuits this charge is often carried by moving electrons in a wire. It can also be carried by ions in an electrolyte, or by both ions and electrons such as in a plasma.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricCurrent : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricCurrentUnit? _unit;
+
+ static ElectricCurrent()
+ {
+ BaseDimensions = new BaseDimensions(0, 0, 0, 1, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Ampere.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricCurrent()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricCurrent(double numericValue, ElectricCurrentUnit unit)
+ {
+ if(unit == ElectricCurrentUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricCurrent, which is Ampere. All conversions go via this value.
+ ///
+ public static ElectricCurrentUnit BaseUnit => ElectricCurrentUnit.Ampere;
+
+ ///
+ /// Represents the largest possible value of ElectricCurrent
+ ///
+ public static ElectricCurrent MaxValue => new ElectricCurrent(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricCurrent
+ ///
+ public static ElectricCurrent MinValue => new ElectricCurrent(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricCurrent;
+
+ ///
+ /// All units of measurement for the ElectricCurrent quantity.
+ ///
+ public static ElectricCurrentUnit[] Units { get; } = Enum.GetValues(typeof(ElectricCurrentUnit)).Cast().Except(new ElectricCurrentUnit[]{ ElectricCurrentUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Ampere.
+ ///
+ public static ElectricCurrent Zero => new ElectricCurrent(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricCurrentUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricCurrent.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricCurrent.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricCurrent in Amperes.
+ ///
+ public double Amperes => As(ElectricCurrentUnit.Ampere);
+
+ ///
+ /// Get ElectricCurrent in Centiamperes.
+ ///
+ public double Centiamperes => As(ElectricCurrentUnit.Centiampere);
+
+ ///
+ /// Get ElectricCurrent in Kiloamperes.
+ ///
+ public double Kiloamperes => As(ElectricCurrentUnit.Kiloampere);
+
+ ///
+ /// Get ElectricCurrent in Megaamperes.
+ ///
+ public double Megaamperes => As(ElectricCurrentUnit.Megaampere);
+
+ ///
+ /// Get ElectricCurrent in Microamperes.
+ ///
+ public double Microamperes => As(ElectricCurrentUnit.Microampere);
+
+ ///
+ /// Get ElectricCurrent in Milliamperes.
+ ///
+ public double Milliamperes => As(ElectricCurrentUnit.Milliampere);
+
+ ///
+ /// Get ElectricCurrent in Nanoamperes.
+ ///
+ public double Nanoamperes => As(ElectricCurrentUnit.Nanoampere);
+
+ ///
+ /// Get ElectricCurrent in Picoamperes.
+ ///
+ public double Picoamperes => As(ElectricCurrentUnit.Picoampere);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricCurrentUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricCurrentUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricCurrent from Amperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricCurrent FromAmperes(double amperes)
+ {
+ double value = (double) amperes;
+ return new ElectricCurrent(value, ElectricCurrentUnit.Ampere);
+ }
+ ///
+ /// Get ElectricCurrent from Centiamperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricCurrent FromCentiamperes(double centiamperes)
+ {
+ double value = (double) centiamperes;
+ return new ElectricCurrent(value, ElectricCurrentUnit.Centiampere);
+ }
+ ///
+ /// Get ElectricCurrent from Kiloamperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricCurrent FromKiloamperes(double kiloamperes)
+ {
+ double value = (double) kiloamperes;
+ return new ElectricCurrent(value, ElectricCurrentUnit.Kiloampere);
+ }
+ ///
+ /// Get ElectricCurrent from Megaamperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricCurrent FromMegaamperes(double megaamperes)
+ {
+ double value = (double) megaamperes;
+ return new ElectricCurrent(value, ElectricCurrentUnit.Megaampere);
+ }
+ ///
+ /// Get ElectricCurrent from Microamperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricCurrent FromMicroamperes(double microamperes)
+ {
+ double value = (double) microamperes;
+ return new ElectricCurrent(value, ElectricCurrentUnit.Microampere);
+ }
+ ///
+ /// Get ElectricCurrent from Milliamperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricCurrent FromMilliamperes(double milliamperes)
+ {
+ double value = (double) milliamperes;
+ return new ElectricCurrent(value, ElectricCurrentUnit.Milliampere);
+ }
+ ///
+ /// Get ElectricCurrent from Nanoamperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricCurrent FromNanoamperes(double nanoamperes)
+ {
+ double value = (double) nanoamperes;
+ return new ElectricCurrent(value, ElectricCurrentUnit.Nanoampere);
+ }
+ ///
+ /// Get ElectricCurrent from Picoamperes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricCurrent FromPicoamperes(double picoamperes)
+ {
+ double value = (double) picoamperes;
+ return new ElectricCurrent(value, ElectricCurrentUnit.Picoampere);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricCurrent unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricCurrent From(double value, ElectricCurrentUnit fromUnit)
+ {
+ return new ElectricCurrent((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricCurrent Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricCurrent result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricCurrent result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricCurrentUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricCurrentUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricCurrentUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricCurrentUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricCurrent)) throw new ArgumentException("Expected type ElectricCurrent.", nameof(obj));
+
+ return CompareTo((ElectricCurrent)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricCurrent other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricCurrent within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricCurrent other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricCurrent.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricCurrentUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricCurrent to another ElectricCurrent with the unit representation .
+ ///
+ /// A ElectricCurrent with the specified unit.
+ public ElectricCurrent ToUnit(ElectricCurrentUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricCurrent(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricCurrentUnit.Ampere: return _value;
+ case ElectricCurrentUnit.Centiampere: return (_value) * 1e-2d;
+ case ElectricCurrentUnit.Kiloampere: return (_value) * 1e3d;
+ case ElectricCurrentUnit.Megaampere: return (_value) * 1e6d;
+ case ElectricCurrentUnit.Microampere: return (_value) * 1e-6d;
+ case ElectricCurrentUnit.Milliampere: return (_value) * 1e-3d;
+ case ElectricCurrentUnit.Nanoampere: return (_value) * 1e-9d;
+ case ElectricCurrentUnit.Picoampere: return (_value) * 1e-12d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricCurrentUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricCurrentUnit.Ampere: return baseUnitValue;
+ case ElectricCurrentUnit.Centiampere: return (baseUnitValue) / 1e-2d;
+ case ElectricCurrentUnit.Kiloampere: return (baseUnitValue) / 1e3d;
+ case ElectricCurrentUnit.Megaampere: return (baseUnitValue) / 1e6d;
+ case ElectricCurrentUnit.Microampere: return (baseUnitValue) / 1e-6d;
+ case ElectricCurrentUnit.Milliampere: return (baseUnitValue) / 1e-3d;
+ case ElectricCurrentUnit.Nanoampere: return (baseUnitValue) / 1e-9d;
+ case ElectricCurrentUnit.Picoampere: return (baseUnitValue) / 1e-12d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCurrentDensity.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCurrentDensity.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..43963d75d5
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCurrentDensity.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In electromagnetism, current density is the electric current per unit area of cross section.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Current_density
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricCurrentDensity : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricCurrentDensityUnit? _unit;
+
+ static ElectricCurrentDensity()
+ {
+ BaseDimensions = new BaseDimensions(-2, 0, 0, 1, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit AmperePerSquareMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricCurrentDensity()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricCurrentDensity(double numericValue, ElectricCurrentDensityUnit unit)
+ {
+ if(unit == ElectricCurrentDensityUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricCurrentDensity, which is AmperePerSquareMeter. All conversions go via this value.
+ ///
+ public static ElectricCurrentDensityUnit BaseUnit => ElectricCurrentDensityUnit.AmperePerSquareMeter;
+
+ ///
+ /// Represents the largest possible value of ElectricCurrentDensity
+ ///
+ public static ElectricCurrentDensity MaxValue => new ElectricCurrentDensity(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricCurrentDensity
+ ///
+ public static ElectricCurrentDensity MinValue => new ElectricCurrentDensity(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricCurrentDensity;
+
+ ///
+ /// All units of measurement for the ElectricCurrentDensity quantity.
+ ///
+ public static ElectricCurrentDensityUnit[] Units { get; } = Enum.GetValues(typeof(ElectricCurrentDensityUnit)).Cast().Except(new ElectricCurrentDensityUnit[]{ ElectricCurrentDensityUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit AmperePerSquareMeter.
+ ///
+ public static ElectricCurrentDensity Zero => new ElectricCurrentDensity(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricCurrentDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricCurrentDensity.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricCurrentDensity.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricCurrentDensity in AmperesPerSquareMeter.
+ ///
+ public double AmperesPerSquareMeter => As(ElectricCurrentDensityUnit.AmperePerSquareMeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricCurrentDensityUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricCurrentDensityUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricCurrentDensity from AmperesPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricCurrentDensity FromAmperesPerSquareMeter(double amperespersquaremeter)
+ {
+ double value = (double) amperespersquaremeter;
+ return new ElectricCurrentDensity(value, ElectricCurrentDensityUnit.AmperePerSquareMeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricCurrentDensity unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricCurrentDensity From(double value, ElectricCurrentDensityUnit fromUnit)
+ {
+ return new ElectricCurrentDensity((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricCurrentDensity Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricCurrentDensity Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricCurrentDensity result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricCurrentDensity result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricCurrentDensityUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricCurrentDensityUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricCurrentDensityUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricCurrentDensityUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricCurrentDensity)) throw new ArgumentException("Expected type ElectricCurrentDensity.", nameof(obj));
+
+ return CompareTo((ElectricCurrentDensity)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricCurrentDensity other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricCurrentDensity within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricCurrentDensity other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricCurrentDensity.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricCurrentDensityUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricCurrentDensity to another ElectricCurrentDensity with the unit representation .
+ ///
+ /// A ElectricCurrentDensity with the specified unit.
+ public ElectricCurrentDensity ToUnit(ElectricCurrentDensityUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricCurrentDensity(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricCurrentDensityUnit.AmperePerSquareMeter: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricCurrentDensityUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricCurrentDensityUnit.AmperePerSquareMeter: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCurrentGradient.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCurrentGradient.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..88ea70ce25
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricCurrentGradient.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,570 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In electromagnetism, the current gradient describes how the current changes in time.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricCurrentGradient : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricCurrentGradientUnit? _unit;
+
+ static ElectricCurrentGradient()
+ {
+ BaseDimensions = new BaseDimensions(0, 0, -1, 1, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit AmperePerSecond.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricCurrentGradient()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricCurrentGradient(double numericValue, ElectricCurrentGradientUnit unit)
+ {
+ if(unit == ElectricCurrentGradientUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricCurrentGradient, which is AmperePerSecond. All conversions go via this value.
+ ///
+ public static ElectricCurrentGradientUnit BaseUnit => ElectricCurrentGradientUnit.AmperePerSecond;
+
+ ///
+ /// Represents the largest possible value of ElectricCurrentGradient
+ ///
+ public static ElectricCurrentGradient MaxValue => new ElectricCurrentGradient(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricCurrentGradient
+ ///
+ public static ElectricCurrentGradient MinValue => new ElectricCurrentGradient(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricCurrentGradient;
+
+ ///
+ /// All units of measurement for the ElectricCurrentGradient quantity.
+ ///
+ public static ElectricCurrentGradientUnit[] Units { get; } = Enum.GetValues(typeof(ElectricCurrentGradientUnit)).Cast().Except(new ElectricCurrentGradientUnit[]{ ElectricCurrentGradientUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit AmperePerSecond.
+ ///
+ public static ElectricCurrentGradient Zero => new ElectricCurrentGradient(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricCurrentGradientUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricCurrentGradient.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricCurrentGradient.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricCurrentGradient in AmperesPerSecond.
+ ///
+ public double AmperesPerSecond => As(ElectricCurrentGradientUnit.AmperePerSecond);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricCurrentGradientUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricCurrentGradientUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricCurrentGradient from AmperesPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricCurrentGradient FromAmperesPerSecond(double amperespersecond)
+ {
+ double value = (double) amperespersecond;
+ return new ElectricCurrentGradient(value, ElectricCurrentGradientUnit.AmperePerSecond);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricCurrentGradient unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricCurrentGradient From(double value, ElectricCurrentGradientUnit fromUnit)
+ {
+ return new ElectricCurrentGradient((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricCurrentGradient Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricCurrentGradient Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricCurrentGradient result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricCurrentGradient result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricCurrentGradientUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricCurrentGradientUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricCurrentGradientUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricCurrentGradientUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricCurrentGradient)) throw new ArgumentException("Expected type ElectricCurrentGradient.", nameof(obj));
+
+ return CompareTo((ElectricCurrentGradient)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricCurrentGradient other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricCurrentGradient within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricCurrentGradient other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricCurrentGradient.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricCurrentGradientUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricCurrentGradient to another ElectricCurrentGradient with the unit representation .
+ ///
+ /// A ElectricCurrentGradient with the specified unit.
+ public ElectricCurrentGradient ToUnit(ElectricCurrentGradientUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricCurrentGradient(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricCurrentGradientUnit.AmperePerSecond: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricCurrentGradientUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricCurrentGradientUnit.AmperePerSecond: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricField.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricField.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..7fc78e14f1
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricField.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// An electric field is a force field that surrounds electric charges that attracts or repels other electric charges.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Electric_field
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricField : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricFieldUnit? _unit;
+
+ static ElectricField()
+ {
+ BaseDimensions = new BaseDimensions(1, 1, -3, -1, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit VoltPerMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricField()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricField(double numericValue, ElectricFieldUnit unit)
+ {
+ if(unit == ElectricFieldUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricField, which is VoltPerMeter. All conversions go via this value.
+ ///
+ public static ElectricFieldUnit BaseUnit => ElectricFieldUnit.VoltPerMeter;
+
+ ///
+ /// Represents the largest possible value of ElectricField
+ ///
+ public static ElectricField MaxValue => new ElectricField(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricField
+ ///
+ public static ElectricField MinValue => new ElectricField(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricField;
+
+ ///
+ /// All units of measurement for the ElectricField quantity.
+ ///
+ public static ElectricFieldUnit[] Units { get; } = Enum.GetValues(typeof(ElectricFieldUnit)).Cast().Except(new ElectricFieldUnit[]{ ElectricFieldUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit VoltPerMeter.
+ ///
+ public static ElectricField Zero => new ElectricField(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricFieldUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricField.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricField.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricField in VoltsPerMeter.
+ ///
+ public double VoltsPerMeter => As(ElectricFieldUnit.VoltPerMeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricFieldUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricFieldUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricField from VoltsPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricField FromVoltsPerMeter(double voltspermeter)
+ {
+ double value = (double) voltspermeter;
+ return new ElectricField(value, ElectricFieldUnit.VoltPerMeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricField unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricField From(double value, ElectricFieldUnit fromUnit)
+ {
+ return new ElectricField((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricField Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricField Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricField result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricField result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricFieldUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricFieldUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricFieldUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricFieldUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricField)) throw new ArgumentException("Expected type ElectricField.", nameof(obj));
+
+ return CompareTo((ElectricField)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricField other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricField within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricField other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricField.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricFieldUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricField to another ElectricField with the unit representation .
+ ///
+ /// A ElectricField with the specified unit.
+ public ElectricField ToUnit(ElectricFieldUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricField(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricFieldUnit.VoltPerMeter: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricFieldUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricFieldUnit.VoltPerMeter: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricInductance.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricInductance.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..903a89b9d4
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricInductance.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Inductance is a property of an electrical conductor which opposes a change in current.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Inductance
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricInductance : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricInductanceUnit? _unit;
+
+ static ElectricInductance()
+ {
+ BaseDimensions = new BaseDimensions(2, 1, -2, -2, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Henry.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricInductance()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricInductance(double numericValue, ElectricInductanceUnit unit)
+ {
+ if(unit == ElectricInductanceUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricInductance, which is Henry. All conversions go via this value.
+ ///
+ public static ElectricInductanceUnit BaseUnit => ElectricInductanceUnit.Henry;
+
+ ///
+ /// Represents the largest possible value of ElectricInductance
+ ///
+ public static ElectricInductance MaxValue => new ElectricInductance(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricInductance
+ ///
+ public static ElectricInductance MinValue => new ElectricInductance(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricInductance;
+
+ ///
+ /// All units of measurement for the ElectricInductance quantity.
+ ///
+ public static ElectricInductanceUnit[] Units { get; } = Enum.GetValues(typeof(ElectricInductanceUnit)).Cast().Except(new ElectricInductanceUnit[]{ ElectricInductanceUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Henry.
+ ///
+ public static ElectricInductance Zero => new ElectricInductance(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricInductanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricInductance.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricInductance.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricInductance in Henries.
+ ///
+ public double Henries => As(ElectricInductanceUnit.Henry);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricInductanceUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricInductanceUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricInductance from Henries.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricInductance FromHenries(double henries)
+ {
+ double value = (double) henries;
+ return new ElectricInductance(value, ElectricInductanceUnit.Henry);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricInductance unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricInductance From(double value, ElectricInductanceUnit fromUnit)
+ {
+ return new ElectricInductance((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricInductance Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricInductance Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricInductance result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricInductance result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricInductanceUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricInductanceUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricInductanceUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricInductanceUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricInductance)) throw new ArgumentException("Expected type ElectricInductance.", nameof(obj));
+
+ return CompareTo((ElectricInductance)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricInductance other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricInductance within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricInductance other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricInductance.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricInductanceUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricInductance to another ElectricInductance with the unit representation .
+ ///
+ /// A ElectricInductance with the specified unit.
+ public ElectricInductance ToUnit(ElectricInductanceUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricInductance(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricInductanceUnit.Henry: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricInductanceUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricInductanceUnit.Henry: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotential.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotential.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..d908ead398
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotential.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,638 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In classical electromagnetism, the electric potential (a scalar quantity denoted by Φ, ΦE or V and also called the electric field potential or the electrostatic potential) at a point is the amount of electric potential energy that a unitary point charge would have when located at that point.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricPotential : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricPotentialUnit? _unit;
+
+ static ElectricPotential()
+ {
+ BaseDimensions = new BaseDimensions(2, 1, -3, -1, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Volt.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricPotential()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricPotential(double numericValue, ElectricPotentialUnit unit)
+ {
+ if(unit == ElectricPotentialUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricPotential, which is Volt. All conversions go via this value.
+ ///
+ public static ElectricPotentialUnit BaseUnit => ElectricPotentialUnit.Volt;
+
+ ///
+ /// Represents the largest possible value of ElectricPotential
+ ///
+ public static ElectricPotential MaxValue => new ElectricPotential(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricPotential
+ ///
+ public static ElectricPotential MinValue => new ElectricPotential(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricPotential;
+
+ ///
+ /// All units of measurement for the ElectricPotential quantity.
+ ///
+ public static ElectricPotentialUnit[] Units { get; } = Enum.GetValues(typeof(ElectricPotentialUnit)).Cast().Except(new ElectricPotentialUnit[]{ ElectricPotentialUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Volt.
+ ///
+ public static ElectricPotential Zero => new ElectricPotential(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricPotentialUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricPotential.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricPotential.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricPotential in Kilovolts.
+ ///
+ public double Kilovolts => As(ElectricPotentialUnit.Kilovolt);
+
+ ///
+ /// Get ElectricPotential in Megavolts.
+ ///
+ public double Megavolts => As(ElectricPotentialUnit.Megavolt);
+
+ ///
+ /// Get ElectricPotential in Microvolts.
+ ///
+ public double Microvolts => As(ElectricPotentialUnit.Microvolt);
+
+ ///
+ /// Get ElectricPotential in Millivolts.
+ ///
+ public double Millivolts => As(ElectricPotentialUnit.Millivolt);
+
+ ///
+ /// Get ElectricPotential in Volts.
+ ///
+ public double Volts => As(ElectricPotentialUnit.Volt);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricPotentialUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricPotentialUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricPotential from Kilovolts.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotential FromKilovolts(double kilovolts)
+ {
+ double value = (double) kilovolts;
+ return new ElectricPotential(value, ElectricPotentialUnit.Kilovolt);
+ }
+ ///
+ /// Get ElectricPotential from Megavolts.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotential FromMegavolts(double megavolts)
+ {
+ double value = (double) megavolts;
+ return new ElectricPotential(value, ElectricPotentialUnit.Megavolt);
+ }
+ ///
+ /// Get ElectricPotential from Microvolts.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotential FromMicrovolts(double microvolts)
+ {
+ double value = (double) microvolts;
+ return new ElectricPotential(value, ElectricPotentialUnit.Microvolt);
+ }
+ ///
+ /// Get ElectricPotential from Millivolts.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotential FromMillivolts(double millivolts)
+ {
+ double value = (double) millivolts;
+ return new ElectricPotential(value, ElectricPotentialUnit.Millivolt);
+ }
+ ///
+ /// Get ElectricPotential from Volts.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotential FromVolts(double volts)
+ {
+ double value = (double) volts;
+ return new ElectricPotential(value, ElectricPotentialUnit.Volt);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricPotential unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricPotential From(double value, ElectricPotentialUnit fromUnit)
+ {
+ return new ElectricPotential((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricPotential Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricPotential result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricPotential result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricPotentialUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricPotentialUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricPotentialUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricPotentialUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricPotential)) throw new ArgumentException("Expected type ElectricPotential.", nameof(obj));
+
+ return CompareTo((ElectricPotential)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricPotential other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricPotential within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricPotential other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricPotential.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricPotentialUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricPotential to another ElectricPotential with the unit representation .
+ ///
+ /// A ElectricPotential with the specified unit.
+ public ElectricPotential ToUnit(ElectricPotentialUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricPotential(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricPotentialUnit.Kilovolt: return (_value) * 1e3d;
+ case ElectricPotentialUnit.Megavolt: return (_value) * 1e6d;
+ case ElectricPotentialUnit.Microvolt: return (_value) * 1e-6d;
+ case ElectricPotentialUnit.Millivolt: return (_value) * 1e-3d;
+ case ElectricPotentialUnit.Volt: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricPotentialUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricPotentialUnit.Kilovolt: return (baseUnitValue) / 1e3d;
+ case ElectricPotentialUnit.Megavolt: return (baseUnitValue) / 1e6d;
+ case ElectricPotentialUnit.Microvolt: return (baseUnitValue) / 1e-6d;
+ case ElectricPotentialUnit.Millivolt: return (baseUnitValue) / 1e-3d;
+ case ElectricPotentialUnit.Volt: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotentialAc.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotentialAc.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..449568468e
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotentialAc.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,638 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The Electric Potential of a system known to use Alternating Current.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricPotentialAc : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricPotentialAcUnit? _unit;
+
+ static ElectricPotentialAc()
+ {
+ BaseDimensions = BaseDimensions.Dimensionless;
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit VoltAc.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricPotentialAc()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricPotentialAc(double numericValue, ElectricPotentialAcUnit unit)
+ {
+ if(unit == ElectricPotentialAcUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricPotentialAc, which is VoltAc. All conversions go via this value.
+ ///
+ public static ElectricPotentialAcUnit BaseUnit => ElectricPotentialAcUnit.VoltAc;
+
+ ///
+ /// Represents the largest possible value of ElectricPotentialAc
+ ///
+ public static ElectricPotentialAc MaxValue => new ElectricPotentialAc(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricPotentialAc
+ ///
+ public static ElectricPotentialAc MinValue => new ElectricPotentialAc(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricPotentialAc;
+
+ ///
+ /// All units of measurement for the ElectricPotentialAc quantity.
+ ///
+ public static ElectricPotentialAcUnit[] Units { get; } = Enum.GetValues(typeof(ElectricPotentialAcUnit)).Cast().Except(new ElectricPotentialAcUnit[]{ ElectricPotentialAcUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit VoltAc.
+ ///
+ public static ElectricPotentialAc Zero => new ElectricPotentialAc(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricPotentialAcUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricPotentialAc.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricPotentialAc.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricPotentialAc in KilovoltsAc.
+ ///
+ public double KilovoltsAc => As(ElectricPotentialAcUnit.KilovoltAc);
+
+ ///
+ /// Get ElectricPotentialAc in MegavoltsAc.
+ ///
+ public double MegavoltsAc => As(ElectricPotentialAcUnit.MegavoltAc);
+
+ ///
+ /// Get ElectricPotentialAc in MicrovoltsAc.
+ ///
+ public double MicrovoltsAc => As(ElectricPotentialAcUnit.MicrovoltAc);
+
+ ///
+ /// Get ElectricPotentialAc in MillivoltsAc.
+ ///
+ public double MillivoltsAc => As(ElectricPotentialAcUnit.MillivoltAc);
+
+ ///
+ /// Get ElectricPotentialAc in VoltsAc.
+ ///
+ public double VoltsAc => As(ElectricPotentialAcUnit.VoltAc);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricPotentialAcUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricPotentialAcUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricPotentialAc from KilovoltsAc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotentialAc FromKilovoltsAc(double kilovoltsac)
+ {
+ double value = (double) kilovoltsac;
+ return new ElectricPotentialAc(value, ElectricPotentialAcUnit.KilovoltAc);
+ }
+ ///
+ /// Get ElectricPotentialAc from MegavoltsAc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotentialAc FromMegavoltsAc(double megavoltsac)
+ {
+ double value = (double) megavoltsac;
+ return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MegavoltAc);
+ }
+ ///
+ /// Get ElectricPotentialAc from MicrovoltsAc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotentialAc FromMicrovoltsAc(double microvoltsac)
+ {
+ double value = (double) microvoltsac;
+ return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MicrovoltAc);
+ }
+ ///
+ /// Get ElectricPotentialAc from MillivoltsAc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotentialAc FromMillivoltsAc(double millivoltsac)
+ {
+ double value = (double) millivoltsac;
+ return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MillivoltAc);
+ }
+ ///
+ /// Get ElectricPotentialAc from VoltsAc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotentialAc FromVoltsAc(double voltsac)
+ {
+ double value = (double) voltsac;
+ return new ElectricPotentialAc(value, ElectricPotentialAcUnit.VoltAc);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricPotentialAc unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricPotentialAc From(double value, ElectricPotentialAcUnit fromUnit)
+ {
+ return new ElectricPotentialAc((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricPotentialAc Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricPotentialAc Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricPotentialAc result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricPotentialAc result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricPotentialAcUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricPotentialAcUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricPotentialAcUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricPotentialAcUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricPotentialAc)) throw new ArgumentException("Expected type ElectricPotentialAc.", nameof(obj));
+
+ return CompareTo((ElectricPotentialAc)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricPotentialAc other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricPotentialAc within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricPotentialAc other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricPotentialAc.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricPotentialAcUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricPotentialAc to another ElectricPotentialAc with the unit representation .
+ ///
+ /// A ElectricPotentialAc with the specified unit.
+ public ElectricPotentialAc ToUnit(ElectricPotentialAcUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricPotentialAc(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricPotentialAcUnit.KilovoltAc: return (_value) * 1e3d;
+ case ElectricPotentialAcUnit.MegavoltAc: return (_value) * 1e6d;
+ case ElectricPotentialAcUnit.MicrovoltAc: return (_value) * 1e-6d;
+ case ElectricPotentialAcUnit.MillivoltAc: return (_value) * 1e-3d;
+ case ElectricPotentialAcUnit.VoltAc: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricPotentialAcUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricPotentialAcUnit.KilovoltAc: return (baseUnitValue) / 1e3d;
+ case ElectricPotentialAcUnit.MegavoltAc: return (baseUnitValue) / 1e6d;
+ case ElectricPotentialAcUnit.MicrovoltAc: return (baseUnitValue) / 1e-6d;
+ case ElectricPotentialAcUnit.MillivoltAc: return (baseUnitValue) / 1e-3d;
+ case ElectricPotentialAcUnit.VoltAc: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotentialDc.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotentialDc.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..8d64cf696e
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricPotentialDc.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,638 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The Electric Potential of a system known to use Direct Current.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricPotentialDc : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricPotentialDcUnit? _unit;
+
+ static ElectricPotentialDc()
+ {
+ BaseDimensions = BaseDimensions.Dimensionless;
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit VoltDc.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricPotentialDc()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricPotentialDc(double numericValue, ElectricPotentialDcUnit unit)
+ {
+ if(unit == ElectricPotentialDcUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricPotentialDc, which is VoltDc. All conversions go via this value.
+ ///
+ public static ElectricPotentialDcUnit BaseUnit => ElectricPotentialDcUnit.VoltDc;
+
+ ///
+ /// Represents the largest possible value of ElectricPotentialDc
+ ///
+ public static ElectricPotentialDc MaxValue => new ElectricPotentialDc(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricPotentialDc
+ ///
+ public static ElectricPotentialDc MinValue => new ElectricPotentialDc(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricPotentialDc;
+
+ ///
+ /// All units of measurement for the ElectricPotentialDc quantity.
+ ///
+ public static ElectricPotentialDcUnit[] Units { get; } = Enum.GetValues(typeof(ElectricPotentialDcUnit)).Cast().Except(new ElectricPotentialDcUnit[]{ ElectricPotentialDcUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit VoltDc.
+ ///
+ public static ElectricPotentialDc Zero => new ElectricPotentialDc(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricPotentialDcUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricPotentialDc.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricPotentialDc.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricPotentialDc in KilovoltsDc.
+ ///
+ public double KilovoltsDc => As(ElectricPotentialDcUnit.KilovoltDc);
+
+ ///
+ /// Get ElectricPotentialDc in MegavoltsDc.
+ ///
+ public double MegavoltsDc => As(ElectricPotentialDcUnit.MegavoltDc);
+
+ ///
+ /// Get ElectricPotentialDc in MicrovoltsDc.
+ ///
+ public double MicrovoltsDc => As(ElectricPotentialDcUnit.MicrovoltDc);
+
+ ///
+ /// Get ElectricPotentialDc in MillivoltsDc.
+ ///
+ public double MillivoltsDc => As(ElectricPotentialDcUnit.MillivoltDc);
+
+ ///
+ /// Get ElectricPotentialDc in VoltsDc.
+ ///
+ public double VoltsDc => As(ElectricPotentialDcUnit.VoltDc);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricPotentialDcUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricPotentialDcUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricPotentialDc from KilovoltsDc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotentialDc FromKilovoltsDc(double kilovoltsdc)
+ {
+ double value = (double) kilovoltsdc;
+ return new ElectricPotentialDc(value, ElectricPotentialDcUnit.KilovoltDc);
+ }
+ ///
+ /// Get ElectricPotentialDc from MegavoltsDc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotentialDc FromMegavoltsDc(double megavoltsdc)
+ {
+ double value = (double) megavoltsdc;
+ return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MegavoltDc);
+ }
+ ///
+ /// Get ElectricPotentialDc from MicrovoltsDc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotentialDc FromMicrovoltsDc(double microvoltsdc)
+ {
+ double value = (double) microvoltsdc;
+ return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MicrovoltDc);
+ }
+ ///
+ /// Get ElectricPotentialDc from MillivoltsDc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotentialDc FromMillivoltsDc(double millivoltsdc)
+ {
+ double value = (double) millivoltsdc;
+ return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MillivoltDc);
+ }
+ ///
+ /// Get ElectricPotentialDc from VoltsDc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricPotentialDc FromVoltsDc(double voltsdc)
+ {
+ double value = (double) voltsdc;
+ return new ElectricPotentialDc(value, ElectricPotentialDcUnit.VoltDc);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricPotentialDc unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricPotentialDc From(double value, ElectricPotentialDcUnit fromUnit)
+ {
+ return new ElectricPotentialDc((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricPotentialDc Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricPotentialDc Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricPotentialDc result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricPotentialDc result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricPotentialDcUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricPotentialDcUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricPotentialDcUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricPotentialDcUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricPotentialDc)) throw new ArgumentException("Expected type ElectricPotentialDc.", nameof(obj));
+
+ return CompareTo((ElectricPotentialDc)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricPotentialDc other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricPotentialDc within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricPotentialDc other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricPotentialDc.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricPotentialDcUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricPotentialDc to another ElectricPotentialDc with the unit representation .
+ ///
+ /// A ElectricPotentialDc with the specified unit.
+ public ElectricPotentialDc ToUnit(ElectricPotentialDcUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricPotentialDc(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricPotentialDcUnit.KilovoltDc: return (_value) * 1e3d;
+ case ElectricPotentialDcUnit.MegavoltDc: return (_value) * 1e6d;
+ case ElectricPotentialDcUnit.MicrovoltDc: return (_value) * 1e-6d;
+ case ElectricPotentialDcUnit.MillivoltDc: return (_value) * 1e-3d;
+ case ElectricPotentialDcUnit.VoltDc: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricPotentialDcUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricPotentialDcUnit.KilovoltDc: return (baseUnitValue) / 1e3d;
+ case ElectricPotentialDcUnit.MegavoltDc: return (baseUnitValue) / 1e6d;
+ case ElectricPotentialDcUnit.MicrovoltDc: return (baseUnitValue) / 1e-6d;
+ case ElectricPotentialDcUnit.MillivoltDc: return (baseUnitValue) / 1e-3d;
+ case ElectricPotentialDcUnit.VoltDc: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricResistance.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricResistance.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..7978859d3d
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricResistance.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,621 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The electrical resistance of an electrical conductor is the opposition to the passage of an electric current through that conductor.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricResistance : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricResistanceUnit? _unit;
+
+ static ElectricResistance()
+ {
+ BaseDimensions = new BaseDimensions(2, 1, -3, -2, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Ohm.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricResistance()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricResistance(double numericValue, ElectricResistanceUnit unit)
+ {
+ if(unit == ElectricResistanceUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricResistance, which is Ohm. All conversions go via this value.
+ ///
+ public static ElectricResistanceUnit BaseUnit => ElectricResistanceUnit.Ohm;
+
+ ///
+ /// Represents the largest possible value of ElectricResistance
+ ///
+ public static ElectricResistance MaxValue => new ElectricResistance(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricResistance
+ ///
+ public static ElectricResistance MinValue => new ElectricResistance(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricResistance;
+
+ ///
+ /// All units of measurement for the ElectricResistance quantity.
+ ///
+ public static ElectricResistanceUnit[] Units { get; } = Enum.GetValues(typeof(ElectricResistanceUnit)).Cast().Except(new ElectricResistanceUnit[]{ ElectricResistanceUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Ohm.
+ ///
+ public static ElectricResistance Zero => new ElectricResistance(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricResistanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricResistance.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricResistance.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricResistance in Kiloohms.
+ ///
+ public double Kiloohms => As(ElectricResistanceUnit.Kiloohm);
+
+ ///
+ /// Get ElectricResistance in Megaohms.
+ ///
+ public double Megaohms => As(ElectricResistanceUnit.Megaohm);
+
+ ///
+ /// Get ElectricResistance in Milliohms.
+ ///
+ public double Milliohms => As(ElectricResistanceUnit.Milliohm);
+
+ ///
+ /// Get ElectricResistance in Ohms.
+ ///
+ public double Ohms => As(ElectricResistanceUnit.Ohm);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricResistanceUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricResistanceUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricResistance from Kiloohms.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricResistance FromKiloohms(double kiloohms)
+ {
+ double value = (double) kiloohms;
+ return new ElectricResistance(value, ElectricResistanceUnit.Kiloohm);
+ }
+ ///
+ /// Get ElectricResistance from Megaohms.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricResistance FromMegaohms(double megaohms)
+ {
+ double value = (double) megaohms;
+ return new ElectricResistance(value, ElectricResistanceUnit.Megaohm);
+ }
+ ///
+ /// Get ElectricResistance from Milliohms.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricResistance FromMilliohms(double milliohms)
+ {
+ double value = (double) milliohms;
+ return new ElectricResistance(value, ElectricResistanceUnit.Milliohm);
+ }
+ ///
+ /// Get ElectricResistance from Ohms.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricResistance FromOhms(double ohms)
+ {
+ double value = (double) ohms;
+ return new ElectricResistance(value, ElectricResistanceUnit.Ohm);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricResistance unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricResistance From(double value, ElectricResistanceUnit fromUnit)
+ {
+ return new ElectricResistance((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricResistance Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricResistance result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricResistance result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricResistanceUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricResistanceUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricResistanceUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricResistanceUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricResistance)) throw new ArgumentException("Expected type ElectricResistance.", nameof(obj));
+
+ return CompareTo((ElectricResistance)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricResistance other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricResistance within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricResistance other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricResistance.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricResistanceUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricResistance to another ElectricResistance with the unit representation .
+ ///
+ /// A ElectricResistance with the specified unit.
+ public ElectricResistance ToUnit(ElectricResistanceUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricResistance(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricResistanceUnit.Kiloohm: return (_value) * 1e3d;
+ case ElectricResistanceUnit.Megaohm: return (_value) * 1e6d;
+ case ElectricResistanceUnit.Milliohm: return (_value) * 1e-3d;
+ case ElectricResistanceUnit.Ohm: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricResistanceUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricResistanceUnit.Kiloohm: return (baseUnitValue) / 1e3d;
+ case ElectricResistanceUnit.Megaohm: return (baseUnitValue) / 1e6d;
+ case ElectricResistanceUnit.Milliohm: return (baseUnitValue) / 1e-3d;
+ case ElectricResistanceUnit.Ohm: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricResistivity.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricResistivity.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..62a12c9d78
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ElectricResistivity.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,624 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Electrical resistivity (also known as resistivity, specific electrical resistance, or volume resistivity) is a fundamental property that quantifies how strongly a given material opposes the flow of electric current.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Electrical_resistivity_and_conductivity
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ElectricResistivity : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ElectricResistivityUnit? _unit;
+
+ static ElectricResistivity()
+ {
+ BaseDimensions = new BaseDimensions(3, 1, -3, -2, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit OhmMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ElectricResistivity()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ElectricResistivity(double numericValue, ElectricResistivityUnit unit)
+ {
+ if(unit == ElectricResistivityUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ElectricResistivity, which is OhmMeter. All conversions go via this value.
+ ///
+ public static ElectricResistivityUnit BaseUnit => ElectricResistivityUnit.OhmMeter;
+
+ ///
+ /// Represents the largest possible value of ElectricResistivity
+ ///
+ public static ElectricResistivity MaxValue => new ElectricResistivity(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ElectricResistivity
+ ///
+ public static ElectricResistivity MinValue => new ElectricResistivity(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ElectricResistivity;
+
+ ///
+ /// All units of measurement for the ElectricResistivity quantity.
+ ///
+ public static ElectricResistivityUnit[] Units { get; } = Enum.GetValues(typeof(ElectricResistivityUnit)).Cast().Except(new ElectricResistivityUnit[]{ ElectricResistivityUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit OhmMeter.
+ ///
+ public static ElectricResistivity Zero => new ElectricResistivity(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ElectricResistivityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ElectricResistivity.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ElectricResistivity.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ElectricResistivity in MicroohmMeters.
+ ///
+ public double MicroohmMeters => As(ElectricResistivityUnit.MicroohmMeter);
+
+ ///
+ /// Get ElectricResistivity in MilliohmMeters.
+ ///
+ public double MilliohmMeters => As(ElectricResistivityUnit.MilliohmMeter);
+
+ ///
+ /// Get ElectricResistivity in NanoohmMeters.
+ ///
+ public double NanoohmMeters => As(ElectricResistivityUnit.NanoohmMeter);
+
+ ///
+ /// Get ElectricResistivity in OhmMeters.
+ ///
+ public double OhmMeters => As(ElectricResistivityUnit.OhmMeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ElectricResistivityUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ElectricResistivityUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ElectricResistivity from MicroohmMeters.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricResistivity FromMicroohmMeters(double microohmmeters)
+ {
+ double value = (double) microohmmeters;
+ return new ElectricResistivity(value, ElectricResistivityUnit.MicroohmMeter);
+ }
+ ///
+ /// Get ElectricResistivity from MilliohmMeters.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricResistivity FromMilliohmMeters(double milliohmmeters)
+ {
+ double value = (double) milliohmmeters;
+ return new ElectricResistivity(value, ElectricResistivityUnit.MilliohmMeter);
+ }
+ ///
+ /// Get ElectricResistivity from NanoohmMeters.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricResistivity FromNanoohmMeters(double nanoohmmeters)
+ {
+ double value = (double) nanoohmmeters;
+ return new ElectricResistivity(value, ElectricResistivityUnit.NanoohmMeter);
+ }
+ ///
+ /// Get ElectricResistivity from OhmMeters.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ElectricResistivity FromOhmMeters(double ohmmeters)
+ {
+ double value = (double) ohmmeters;
+ return new ElectricResistivity(value, ElectricResistivityUnit.OhmMeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ElectricResistivity unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ElectricResistivity From(double value, ElectricResistivityUnit fromUnit)
+ {
+ return new ElectricResistivity((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ElectricResistivity Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricResistivity Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ElectricResistivity result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ElectricResistivity result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ElectricResistivityUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ElectricResistivityUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ElectricResistivityUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ElectricResistivityUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ElectricResistivity)) throw new ArgumentException("Expected type ElectricResistivity.", nameof(obj));
+
+ return CompareTo((ElectricResistivity)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ElectricResistivity other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ElectricResistivity within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ElectricResistivity other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ElectricResistivity.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ElectricResistivityUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ElectricResistivity to another ElectricResistivity with the unit representation .
+ ///
+ /// A ElectricResistivity with the specified unit.
+ public ElectricResistivity ToUnit(ElectricResistivityUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ElectricResistivity(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ElectricResistivityUnit.MicroohmMeter: return (_value) * 1e-6d;
+ case ElectricResistivityUnit.MilliohmMeter: return (_value) * 1e-3d;
+ case ElectricResistivityUnit.NanoohmMeter: return (_value) * 1e-9d;
+ case ElectricResistivityUnit.OhmMeter: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ElectricResistivityUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ElectricResistivityUnit.MicroohmMeter: return (baseUnitValue) / 1e-6d;
+ case ElectricResistivityUnit.MilliohmMeter: return (baseUnitValue) / 1e-3d;
+ case ElectricResistivityUnit.NanoohmMeter: return (baseUnitValue) / 1e-9d;
+ case ElectricResistivityUnit.OhmMeter: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Energy.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Energy.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..1a019820bd
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Energy.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,927 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The joule, symbol J, is a derived unit of energy, work, or amount of heat in the International System of Units. It is equal to the energy transferred (or work done) when applying a force of one newton through a distance of one metre (1 newton metre or N·m), or in passing an electric current of one ampere through a resistance of one ohm for one second. Many other units of energy are included. Please do not confuse this definition of the calorie with the one colloquially used by the food industry, the large calorie, which is equivalent to 1 kcal. Thermochemical definition of the calorie is used. For BTU, the IT definition is used.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Energy : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly EnergyUnit? _unit;
+
+ static Energy()
+ {
+ BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Joule.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Energy()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Energy(double numericValue, EnergyUnit unit)
+ {
+ if(unit == EnergyUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Energy, which is Joule. All conversions go via this value.
+ ///
+ public static EnergyUnit BaseUnit => EnergyUnit.Joule;
+
+ ///
+ /// Represents the largest possible value of Energy
+ ///
+ public static Energy MaxValue => new Energy(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Energy
+ ///
+ public static Energy MinValue => new Energy(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Energy;
+
+ ///
+ /// All units of measurement for the Energy quantity.
+ ///
+ public static EnergyUnit[] Units { get; } = Enum.GetValues(typeof(EnergyUnit)).Cast().Except(new EnergyUnit[]{ EnergyUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Joule.
+ ///
+ public static Energy Zero => new Energy(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public EnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Energy.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Energy.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Energy in BritishThermalUnits.
+ ///
+ public double BritishThermalUnits => As(EnergyUnit.BritishThermalUnit);
+
+ ///
+ /// Get Energy in Calories.
+ ///
+ public double Calories => As(EnergyUnit.Calorie);
+
+ ///
+ /// Get Energy in DecathermsEc.
+ ///
+ public double DecathermsEc => As(EnergyUnit.DecathermEc);
+
+ ///
+ /// Get Energy in DecathermsImperial.
+ ///
+ public double DecathermsImperial => As(EnergyUnit.DecathermImperial);
+
+ ///
+ /// Get Energy in DecathermsUs.
+ ///
+ public double DecathermsUs => As(EnergyUnit.DecathermUs);
+
+ ///
+ /// Get Energy in ElectronVolts.
+ ///
+ public double ElectronVolts => As(EnergyUnit.ElectronVolt);
+
+ ///
+ /// Get Energy in Ergs.
+ ///
+ public double Ergs => As(EnergyUnit.Erg);
+
+ ///
+ /// Get Energy in FootPounds.
+ ///
+ public double FootPounds => As(EnergyUnit.FootPound);
+
+ ///
+ /// Get Energy in GigabritishThermalUnits.
+ ///
+ public double GigabritishThermalUnits => As(EnergyUnit.GigabritishThermalUnit);
+
+ ///
+ /// Get Energy in GigawattHours.
+ ///
+ public double GigawattHours => As(EnergyUnit.GigawattHour);
+
+ ///
+ /// Get Energy in Joules.
+ ///
+ public double Joules => As(EnergyUnit.Joule);
+
+ ///
+ /// Get Energy in KilobritishThermalUnits.
+ ///
+ public double KilobritishThermalUnits => As(EnergyUnit.KilobritishThermalUnit);
+
+ ///
+ /// Get Energy in Kilocalories.
+ ///
+ public double Kilocalories => As(EnergyUnit.Kilocalorie);
+
+ ///
+ /// Get Energy in Kilojoules.
+ ///
+ public double Kilojoules => As(EnergyUnit.Kilojoule);
+
+ ///
+ /// Get Energy in KilowattHours.
+ ///
+ public double KilowattHours => As(EnergyUnit.KilowattHour);
+
+ ///
+ /// Get Energy in MegabritishThermalUnits.
+ ///
+ public double MegabritishThermalUnits => As(EnergyUnit.MegabritishThermalUnit);
+
+ ///
+ /// Get Energy in Megajoules.
+ ///
+ public double Megajoules => As(EnergyUnit.Megajoule);
+
+ ///
+ /// Get Energy in MegawattHours.
+ ///
+ public double MegawattHours => As(EnergyUnit.MegawattHour);
+
+ ///
+ /// Get Energy in ThermsEc.
+ ///
+ public double ThermsEc => As(EnergyUnit.ThermEc);
+
+ ///
+ /// Get Energy in ThermsImperial.
+ ///
+ public double ThermsImperial => As(EnergyUnit.ThermImperial);
+
+ ///
+ /// Get Energy in ThermsUs.
+ ///
+ public double ThermsUs => As(EnergyUnit.ThermUs);
+
+ ///
+ /// Get Energy in WattHours.
+ ///
+ public double WattHours => As(EnergyUnit.WattHour);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(EnergyUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(EnergyUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Energy from BritishThermalUnits.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromBritishThermalUnits(double britishthermalunits)
+ {
+ double value = (double) britishthermalunits;
+ return new Energy(value, EnergyUnit.BritishThermalUnit);
+ }
+ ///
+ /// Get Energy from Calories.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromCalories(double calories)
+ {
+ double value = (double) calories;
+ return new Energy(value, EnergyUnit.Calorie);
+ }
+ ///
+ /// Get Energy from DecathermsEc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromDecathermsEc(double decathermsec)
+ {
+ double value = (double) decathermsec;
+ return new Energy(value, EnergyUnit.DecathermEc);
+ }
+ ///
+ /// Get Energy from DecathermsImperial.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromDecathermsImperial(double decathermsimperial)
+ {
+ double value = (double) decathermsimperial;
+ return new Energy(value, EnergyUnit.DecathermImperial);
+ }
+ ///
+ /// Get Energy from DecathermsUs.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromDecathermsUs(double decathermsus)
+ {
+ double value = (double) decathermsus;
+ return new Energy(value, EnergyUnit.DecathermUs);
+ }
+ ///
+ /// Get Energy from ElectronVolts.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromElectronVolts(double electronvolts)
+ {
+ double value = (double) electronvolts;
+ return new Energy(value, EnergyUnit.ElectronVolt);
+ }
+ ///
+ /// Get Energy from Ergs.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromErgs(double ergs)
+ {
+ double value = (double) ergs;
+ return new Energy(value, EnergyUnit.Erg);
+ }
+ ///
+ /// Get Energy from FootPounds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromFootPounds(double footpounds)
+ {
+ double value = (double) footpounds;
+ return new Energy(value, EnergyUnit.FootPound);
+ }
+ ///
+ /// Get Energy from GigabritishThermalUnits.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromGigabritishThermalUnits(double gigabritishthermalunits)
+ {
+ double value = (double) gigabritishthermalunits;
+ return new Energy(value, EnergyUnit.GigabritishThermalUnit);
+ }
+ ///
+ /// Get Energy from GigawattHours.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromGigawattHours(double gigawatthours)
+ {
+ double value = (double) gigawatthours;
+ return new Energy(value, EnergyUnit.GigawattHour);
+ }
+ ///
+ /// Get Energy from Joules.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromJoules(double joules)
+ {
+ double value = (double) joules;
+ return new Energy(value, EnergyUnit.Joule);
+ }
+ ///
+ /// Get Energy from KilobritishThermalUnits.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromKilobritishThermalUnits(double kilobritishthermalunits)
+ {
+ double value = (double) kilobritishthermalunits;
+ return new Energy(value, EnergyUnit.KilobritishThermalUnit);
+ }
+ ///
+ /// Get Energy from Kilocalories.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromKilocalories(double kilocalories)
+ {
+ double value = (double) kilocalories;
+ return new Energy(value, EnergyUnit.Kilocalorie);
+ }
+ ///
+ /// Get Energy from Kilojoules.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromKilojoules(double kilojoules)
+ {
+ double value = (double) kilojoules;
+ return new Energy(value, EnergyUnit.Kilojoule);
+ }
+ ///
+ /// Get Energy from KilowattHours.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromKilowattHours(double kilowatthours)
+ {
+ double value = (double) kilowatthours;
+ return new Energy(value, EnergyUnit.KilowattHour);
+ }
+ ///
+ /// Get Energy from MegabritishThermalUnits.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromMegabritishThermalUnits(double megabritishthermalunits)
+ {
+ double value = (double) megabritishthermalunits;
+ return new Energy(value, EnergyUnit.MegabritishThermalUnit);
+ }
+ ///
+ /// Get Energy from Megajoules.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromMegajoules(double megajoules)
+ {
+ double value = (double) megajoules;
+ return new Energy(value, EnergyUnit.Megajoule);
+ }
+ ///
+ /// Get Energy from MegawattHours.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromMegawattHours(double megawatthours)
+ {
+ double value = (double) megawatthours;
+ return new Energy(value, EnergyUnit.MegawattHour);
+ }
+ ///
+ /// Get Energy from ThermsEc.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromThermsEc(double thermsec)
+ {
+ double value = (double) thermsec;
+ return new Energy(value, EnergyUnit.ThermEc);
+ }
+ ///
+ /// Get Energy from ThermsImperial.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromThermsImperial(double thermsimperial)
+ {
+ double value = (double) thermsimperial;
+ return new Energy(value, EnergyUnit.ThermImperial);
+ }
+ ///
+ /// Get Energy from ThermsUs.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromThermsUs(double thermsus)
+ {
+ double value = (double) thermsus;
+ return new Energy(value, EnergyUnit.ThermUs);
+ }
+ ///
+ /// Get Energy from WattHours.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Energy FromWattHours(double watthours)
+ {
+ double value = (double) watthours;
+ return new Energy(value, EnergyUnit.WattHour);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Energy unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Energy From(double value, EnergyUnit fromUnit)
+ {
+ return new Energy((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Energy Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Energy result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Energy result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static EnergyUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static EnergyUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out EnergyUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out EnergyUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Energy)) throw new ArgumentException("Expected type Energy.", nameof(obj));
+
+ return CompareTo((Energy)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Energy other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Energy within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Energy other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Energy.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(EnergyUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Energy to another Energy with the unit representation .
+ ///
+ /// A Energy with the specified unit.
+ public Energy ToUnit(EnergyUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Energy(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case EnergyUnit.BritishThermalUnit: return _value*1055.05585262;
+ case EnergyUnit.Calorie: return _value*4.184;
+ case EnergyUnit.DecathermEc: return (_value*1.05505585262e8) * 1e1d;
+ case EnergyUnit.DecathermImperial: return (_value*1.05505585257348e8) * 1e1d;
+ case EnergyUnit.DecathermUs: return (_value*1.054804e8) * 1e1d;
+ case EnergyUnit.ElectronVolt: return _value*1.602176565e-19;
+ case EnergyUnit.Erg: return _value*1e-7;
+ case EnergyUnit.FootPound: return _value*1.355817948;
+ case EnergyUnit.GigabritishThermalUnit: return (_value*1055.05585262) * 1e9d;
+ case EnergyUnit.GigawattHour: return (_value*3600d) * 1e9d;
+ case EnergyUnit.Joule: return _value;
+ case EnergyUnit.KilobritishThermalUnit: return (_value*1055.05585262) * 1e3d;
+ case EnergyUnit.Kilocalorie: return (_value*4.184) * 1e3d;
+ case EnergyUnit.Kilojoule: return (_value) * 1e3d;
+ case EnergyUnit.KilowattHour: return (_value*3600d) * 1e3d;
+ case EnergyUnit.MegabritishThermalUnit: return (_value*1055.05585262) * 1e6d;
+ case EnergyUnit.Megajoule: return (_value) * 1e6d;
+ case EnergyUnit.MegawattHour: return (_value*3600d) * 1e6d;
+ case EnergyUnit.ThermEc: return _value*1.05505585262e8;
+ case EnergyUnit.ThermImperial: return _value*1.05505585257348e8;
+ case EnergyUnit.ThermUs: return _value*1.054804e8;
+ case EnergyUnit.WattHour: return _value*3600d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(EnergyUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case EnergyUnit.BritishThermalUnit: return baseUnitValue/1055.05585262;
+ case EnergyUnit.Calorie: return baseUnitValue/4.184;
+ case EnergyUnit.DecathermEc: return (baseUnitValue/1.05505585262e8) / 1e1d;
+ case EnergyUnit.DecathermImperial: return (baseUnitValue/1.05505585257348e8) / 1e1d;
+ case EnergyUnit.DecathermUs: return (baseUnitValue/1.054804e8) / 1e1d;
+ case EnergyUnit.ElectronVolt: return baseUnitValue/1.602176565e-19;
+ case EnergyUnit.Erg: return baseUnitValue/1e-7;
+ case EnergyUnit.FootPound: return baseUnitValue/1.355817948;
+ case EnergyUnit.GigabritishThermalUnit: return (baseUnitValue/1055.05585262) / 1e9d;
+ case EnergyUnit.GigawattHour: return (baseUnitValue/3600d) / 1e9d;
+ case EnergyUnit.Joule: return baseUnitValue;
+ case EnergyUnit.KilobritishThermalUnit: return (baseUnitValue/1055.05585262) / 1e3d;
+ case EnergyUnit.Kilocalorie: return (baseUnitValue/4.184) / 1e3d;
+ case EnergyUnit.Kilojoule: return (baseUnitValue) / 1e3d;
+ case EnergyUnit.KilowattHour: return (baseUnitValue/3600d) / 1e3d;
+ case EnergyUnit.MegabritishThermalUnit: return (baseUnitValue/1055.05585262) / 1e6d;
+ case EnergyUnit.Megajoule: return (baseUnitValue) / 1e6d;
+ case EnergyUnit.MegawattHour: return (baseUnitValue/3600d) / 1e6d;
+ case EnergyUnit.ThermEc: return baseUnitValue/1.05505585262e8;
+ case EnergyUnit.ThermImperial: return baseUnitValue/1.05505585257348e8;
+ case EnergyUnit.ThermUs: return baseUnitValue/1.054804e8;
+ case EnergyUnit.WattHour: return baseUnitValue/3600d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Entropy.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Entropy.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..5314156dfd
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Entropy.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,672 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Entropy is an important concept in the branch of science known as thermodynamics. The idea of "irreversibility" is central to the understanding of entropy. It is often said that entropy is an expression of the disorder, or randomness of a system, or of our lack of information about it. Entropy is an extensive property. It has the dimension of energy divided by temperature, which has a unit of joules per kelvin (J/K) in the International System of Units
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Entropy : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly EntropyUnit? _unit;
+
+ static Entropy()
+ {
+ BaseDimensions = new BaseDimensions(2, 1, -2, 0, -1, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit JoulePerKelvin.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Entropy()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Entropy(double numericValue, EntropyUnit unit)
+ {
+ if(unit == EntropyUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Entropy, which is JoulePerKelvin. All conversions go via this value.
+ ///
+ public static EntropyUnit BaseUnit => EntropyUnit.JoulePerKelvin;
+
+ ///
+ /// Represents the largest possible value of Entropy
+ ///
+ public static Entropy MaxValue => new Entropy(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Entropy
+ ///
+ public static Entropy MinValue => new Entropy(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Entropy;
+
+ ///
+ /// All units of measurement for the Entropy quantity.
+ ///
+ public static EntropyUnit[] Units { get; } = Enum.GetValues(typeof(EntropyUnit)).Cast().Except(new EntropyUnit[]{ EntropyUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerKelvin.
+ ///
+ public static Entropy Zero => new Entropy(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public EntropyUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Entropy.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Entropy.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Entropy in CaloriesPerKelvin.
+ ///
+ public double CaloriesPerKelvin => As(EntropyUnit.CaloriePerKelvin);
+
+ ///
+ /// Get Entropy in JoulesPerDegreeCelsius.
+ ///
+ public double JoulesPerDegreeCelsius => As(EntropyUnit.JoulePerDegreeCelsius);
+
+ ///
+ /// Get Entropy in JoulesPerKelvin.
+ ///
+ public double JoulesPerKelvin => As(EntropyUnit.JoulePerKelvin);
+
+ ///
+ /// Get Entropy in KilocaloriesPerKelvin.
+ ///
+ public double KilocaloriesPerKelvin => As(EntropyUnit.KilocaloriePerKelvin);
+
+ ///
+ /// Get Entropy in KilojoulesPerDegreeCelsius.
+ ///
+ public double KilojoulesPerDegreeCelsius => As(EntropyUnit.KilojoulePerDegreeCelsius);
+
+ ///
+ /// Get Entropy in KilojoulesPerKelvin.
+ ///
+ public double KilojoulesPerKelvin => As(EntropyUnit.KilojoulePerKelvin);
+
+ ///
+ /// Get Entropy in MegajoulesPerKelvin.
+ ///
+ public double MegajoulesPerKelvin => As(EntropyUnit.MegajoulePerKelvin);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(EntropyUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(EntropyUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Entropy from CaloriesPerKelvin.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Entropy FromCaloriesPerKelvin(double caloriesperkelvin)
+ {
+ double value = (double) caloriesperkelvin;
+ return new Entropy(value, EntropyUnit.CaloriePerKelvin);
+ }
+ ///
+ /// Get Entropy from JoulesPerDegreeCelsius.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Entropy FromJoulesPerDegreeCelsius(double joulesperdegreecelsius)
+ {
+ double value = (double) joulesperdegreecelsius;
+ return new Entropy(value, EntropyUnit.JoulePerDegreeCelsius);
+ }
+ ///
+ /// Get Entropy from JoulesPerKelvin.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Entropy FromJoulesPerKelvin(double joulesperkelvin)
+ {
+ double value = (double) joulesperkelvin;
+ return new Entropy(value, EntropyUnit.JoulePerKelvin);
+ }
+ ///
+ /// Get Entropy from KilocaloriesPerKelvin.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Entropy FromKilocaloriesPerKelvin(double kilocaloriesperkelvin)
+ {
+ double value = (double) kilocaloriesperkelvin;
+ return new Entropy(value, EntropyUnit.KilocaloriePerKelvin);
+ }
+ ///
+ /// Get Entropy from KilojoulesPerDegreeCelsius.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Entropy FromKilojoulesPerDegreeCelsius(double kilojoulesperdegreecelsius)
+ {
+ double value = (double) kilojoulesperdegreecelsius;
+ return new Entropy(value, EntropyUnit.KilojoulePerDegreeCelsius);
+ }
+ ///
+ /// Get Entropy from KilojoulesPerKelvin.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Entropy FromKilojoulesPerKelvin(double kilojoulesperkelvin)
+ {
+ double value = (double) kilojoulesperkelvin;
+ return new Entropy(value, EntropyUnit.KilojoulePerKelvin);
+ }
+ ///
+ /// Get Entropy from MegajoulesPerKelvin.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Entropy FromMegajoulesPerKelvin(double megajoulesperkelvin)
+ {
+ double value = (double) megajoulesperkelvin;
+ return new Entropy(value, EntropyUnit.MegajoulePerKelvin);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Entropy unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Entropy From(double value, EntropyUnit fromUnit)
+ {
+ return new Entropy((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 Entropy Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Entropy Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Entropy result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Entropy result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static EntropyUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static EntropyUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out EntropyUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out EntropyUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Entropy)) throw new ArgumentException("Expected type Entropy.", nameof(obj));
+
+ return CompareTo((Entropy)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Entropy other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Entropy within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Entropy other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Entropy.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(EntropyUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Entropy to another Entropy with the unit representation .
+ ///
+ /// A Entropy with the specified unit.
+ public Entropy ToUnit(EntropyUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Entropy(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case EntropyUnit.CaloriePerKelvin: return _value*4.184;
+ case EntropyUnit.JoulePerDegreeCelsius: return _value;
+ case EntropyUnit.JoulePerKelvin: return _value;
+ case EntropyUnit.KilocaloriePerKelvin: return (_value*4.184) * 1e3d;
+ case EntropyUnit.KilojoulePerDegreeCelsius: return (_value) * 1e3d;
+ case EntropyUnit.KilojoulePerKelvin: return (_value) * 1e3d;
+ case EntropyUnit.MegajoulePerKelvin: return (_value) * 1e6d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(EntropyUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case EntropyUnit.CaloriePerKelvin: return baseUnitValue/4.184;
+ case EntropyUnit.JoulePerDegreeCelsius: return baseUnitValue;
+ case EntropyUnit.JoulePerKelvin: return baseUnitValue;
+ case EntropyUnit.KilocaloriePerKelvin: return (baseUnitValue/4.184) / 1e3d;
+ case EntropyUnit.KilojoulePerDegreeCelsius: return (baseUnitValue) / 1e3d;
+ case EntropyUnit.KilojoulePerKelvin: return (baseUnitValue) / 1e3d;
+ case EntropyUnit.MegajoulePerKelvin: return (baseUnitValue) / 1e6d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Force.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Force.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..bbeb01758b
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Force.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,774 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In physics, a force is any influence that causes an object to undergo a certain change, either concerning its movement, direction, or geometrical construction. In other words, a force can cause an object with mass to change its velocity (which includes to begin moving from a state of rest), i.e., to accelerate, or a flexible object to deform, or both. Force can also be described by intuitive concepts such as a push or a pull. A force has both magnitude and direction, making it a vector quantity. It is measured in the SI unit of newtons and represented by the symbol F.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Force : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ForceUnit? _unit;
+
+ static Force()
+ {
+ BaseDimensions = new BaseDimensions(1, 1, -2, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Newton.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Force()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Force(double numericValue, ForceUnit unit)
+ {
+ if(unit == ForceUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Force, which is Newton. All conversions go via this value.
+ ///
+ public static ForceUnit BaseUnit => ForceUnit.Newton;
+
+ ///
+ /// Represents the largest possible value of Force
+ ///
+ public static Force MaxValue => new Force(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Force
+ ///
+ public static Force MinValue => new Force(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Force;
+
+ ///
+ /// All units of measurement for the Force quantity.
+ ///
+ public static ForceUnit[] Units { get; } = Enum.GetValues(typeof(ForceUnit)).Cast().Except(new ForceUnit[]{ ForceUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Newton.
+ ///
+ public static Force Zero => new Force(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ForceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Force.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Force.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Force in Decanewtons.
+ ///
+ public double Decanewtons => As(ForceUnit.Decanewton);
+
+ ///
+ /// Get Force in Dyne.
+ ///
+ public double Dyne => As(ForceUnit.Dyn);
+
+ ///
+ /// Get Force in KilogramsForce.
+ ///
+ public double KilogramsForce => As(ForceUnit.KilogramForce);
+
+ ///
+ /// Get Force in Kilonewtons.
+ ///
+ public double Kilonewtons => As(ForceUnit.Kilonewton);
+
+ ///
+ /// Get Force in KiloPonds.
+ ///
+ public double KiloPonds => As(ForceUnit.KiloPond);
+
+ ///
+ /// Get Force in Meganewtons.
+ ///
+ public double Meganewtons => As(ForceUnit.Meganewton);
+
+ ///
+ /// Get Force in Micronewtons.
+ ///
+ public double Micronewtons => As(ForceUnit.Micronewton);
+
+ ///
+ /// Get Force in Millinewtons.
+ ///
+ public double Millinewtons => As(ForceUnit.Millinewton);
+
+ ///
+ /// Get Force in Newtons.
+ ///
+ public double Newtons => As(ForceUnit.Newton);
+
+ ///
+ /// Get Force in OunceForce.
+ ///
+ public double OunceForce => As(ForceUnit.OunceForce);
+
+ ///
+ /// Get Force in Poundals.
+ ///
+ public double Poundals => As(ForceUnit.Poundal);
+
+ ///
+ /// Get Force in PoundsForce.
+ ///
+ public double PoundsForce => As(ForceUnit.PoundForce);
+
+ ///
+ /// Get Force in TonnesForce.
+ ///
+ public double TonnesForce => As(ForceUnit.TonneForce);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ForceUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ForceUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Force from Decanewtons.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromDecanewtons(double decanewtons)
+ {
+ double value = (double) decanewtons;
+ return new Force(value, ForceUnit.Decanewton);
+ }
+ ///
+ /// Get Force from Dyne.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromDyne(double dyne)
+ {
+ double value = (double) dyne;
+ return new Force(value, ForceUnit.Dyn);
+ }
+ ///
+ /// Get Force from KilogramsForce.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromKilogramsForce(double kilogramsforce)
+ {
+ double value = (double) kilogramsforce;
+ return new Force(value, ForceUnit.KilogramForce);
+ }
+ ///
+ /// Get Force from Kilonewtons.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromKilonewtons(double kilonewtons)
+ {
+ double value = (double) kilonewtons;
+ return new Force(value, ForceUnit.Kilonewton);
+ }
+ ///
+ /// Get Force from KiloPonds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromKiloPonds(double kiloponds)
+ {
+ double value = (double) kiloponds;
+ return new Force(value, ForceUnit.KiloPond);
+ }
+ ///
+ /// Get Force from Meganewtons.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromMeganewtons(double meganewtons)
+ {
+ double value = (double) meganewtons;
+ return new Force(value, ForceUnit.Meganewton);
+ }
+ ///
+ /// Get Force from Micronewtons.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromMicronewtons(double micronewtons)
+ {
+ double value = (double) micronewtons;
+ return new Force(value, ForceUnit.Micronewton);
+ }
+ ///
+ /// Get Force from Millinewtons.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromMillinewtons(double millinewtons)
+ {
+ double value = (double) millinewtons;
+ return new Force(value, ForceUnit.Millinewton);
+ }
+ ///
+ /// Get Force from Newtons.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromNewtons(double newtons)
+ {
+ double value = (double) newtons;
+ return new Force(value, ForceUnit.Newton);
+ }
+ ///
+ /// Get Force from OunceForce.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromOunceForce(double ounceforce)
+ {
+ double value = (double) ounceforce;
+ return new Force(value, ForceUnit.OunceForce);
+ }
+ ///
+ /// Get Force from Poundals.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromPoundals(double poundals)
+ {
+ double value = (double) poundals;
+ return new Force(value, ForceUnit.Poundal);
+ }
+ ///
+ /// Get Force from PoundsForce.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromPoundsForce(double poundsforce)
+ {
+ double value = (double) poundsforce;
+ return new Force(value, ForceUnit.PoundForce);
+ }
+ ///
+ /// Get Force from TonnesForce.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Force FromTonnesForce(double tonnesforce)
+ {
+ double value = (double) tonnesforce;
+ return new Force(value, ForceUnit.TonneForce);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Force unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Force From(double value, ForceUnit fromUnit)
+ {
+ return new Force((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Force Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Force result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Force result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ForceUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ForceUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ForceUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ForceUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Force)) throw new ArgumentException("Expected type Force.", nameof(obj));
+
+ return CompareTo((Force)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Force other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Force within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Force other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Force.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ForceUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Force to another Force with the unit representation .
+ ///
+ /// A Force with the specified unit.
+ public Force ToUnit(ForceUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Force(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ForceUnit.Decanewton: return (_value) * 1e1d;
+ case ForceUnit.Dyn: return _value/1e5;
+ case ForceUnit.KilogramForce: return _value*9.80665002864;
+ case ForceUnit.Kilonewton: return (_value) * 1e3d;
+ case ForceUnit.KiloPond: return _value*9.80665002864;
+ case ForceUnit.Meganewton: return (_value) * 1e6d;
+ case ForceUnit.Micronewton: return (_value) * 1e-6d;
+ case ForceUnit.Millinewton: return (_value) * 1e-3d;
+ case ForceUnit.Newton: return _value;
+ case ForceUnit.OunceForce: return _value*2.780138509537812e-1;
+ case ForceUnit.Poundal: return _value*0.13825502798973041652092282466083;
+ case ForceUnit.PoundForce: return _value*4.4482216152605095551842641431421;
+ case ForceUnit.TonneForce: return _value*9.80665002864e3;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ForceUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ForceUnit.Decanewton: return (baseUnitValue) / 1e1d;
+ case ForceUnit.Dyn: return baseUnitValue*1e5;
+ case ForceUnit.KilogramForce: return baseUnitValue/9.80665002864;
+ case ForceUnit.Kilonewton: return (baseUnitValue) / 1e3d;
+ case ForceUnit.KiloPond: return baseUnitValue/9.80665002864;
+ case ForceUnit.Meganewton: return (baseUnitValue) / 1e6d;
+ case ForceUnit.Micronewton: return (baseUnitValue) / 1e-6d;
+ case ForceUnit.Millinewton: return (baseUnitValue) / 1e-3d;
+ case ForceUnit.Newton: return baseUnitValue;
+ case ForceUnit.OunceForce: return baseUnitValue/2.780138509537812e-1;
+ case ForceUnit.Poundal: return baseUnitValue/0.13825502798973041652092282466083;
+ case ForceUnit.PoundForce: return baseUnitValue/4.4482216152605095551842641431421;
+ case ForceUnit.TonneForce: return baseUnitValue/9.80665002864e3;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ForceChangeRate.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ForceChangeRate.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..0c46661ff2
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ForceChangeRate.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,740 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Force change rate is the ratio of the force change to the time during which the change occurred (value of force changes per unit time).
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ForceChangeRate : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ForceChangeRateUnit? _unit;
+
+ static ForceChangeRate()
+ {
+ BaseDimensions = new BaseDimensions(1, 1, -3, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit NewtonPerSecond.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ForceChangeRate()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ForceChangeRate(double numericValue, ForceChangeRateUnit unit)
+ {
+ if(unit == ForceChangeRateUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ForceChangeRate, which is NewtonPerSecond. All conversions go via this value.
+ ///
+ public static ForceChangeRateUnit BaseUnit => ForceChangeRateUnit.NewtonPerSecond;
+
+ ///
+ /// Represents the largest possible value of ForceChangeRate
+ ///
+ public static ForceChangeRate MaxValue => new ForceChangeRate(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ForceChangeRate
+ ///
+ public static ForceChangeRate MinValue => new ForceChangeRate(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ForceChangeRate;
+
+ ///
+ /// All units of measurement for the ForceChangeRate quantity.
+ ///
+ public static ForceChangeRateUnit[] Units { get; } = Enum.GetValues(typeof(ForceChangeRateUnit)).Cast().Except(new ForceChangeRateUnit[]{ ForceChangeRateUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit NewtonPerSecond.
+ ///
+ public static ForceChangeRate Zero => new ForceChangeRate(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ForceChangeRateUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ForceChangeRate.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ForceChangeRate.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ForceChangeRate in CentinewtonsPerSecond.
+ ///
+ public double CentinewtonsPerSecond => As(ForceChangeRateUnit.CentinewtonPerSecond);
+
+ ///
+ /// Get ForceChangeRate in DecanewtonsPerMinute.
+ ///
+ public double DecanewtonsPerMinute => As(ForceChangeRateUnit.DecanewtonPerMinute);
+
+ ///
+ /// Get ForceChangeRate in DecanewtonsPerSecond.
+ ///
+ public double DecanewtonsPerSecond => As(ForceChangeRateUnit.DecanewtonPerSecond);
+
+ ///
+ /// Get ForceChangeRate in DecinewtonsPerSecond.
+ ///
+ public double DecinewtonsPerSecond => As(ForceChangeRateUnit.DecinewtonPerSecond);
+
+ ///
+ /// Get ForceChangeRate in KilonewtonsPerMinute.
+ ///
+ public double KilonewtonsPerMinute => As(ForceChangeRateUnit.KilonewtonPerMinute);
+
+ ///
+ /// Get ForceChangeRate in KilonewtonsPerSecond.
+ ///
+ public double KilonewtonsPerSecond => As(ForceChangeRateUnit.KilonewtonPerSecond);
+
+ ///
+ /// Get ForceChangeRate in MicronewtonsPerSecond.
+ ///
+ public double MicronewtonsPerSecond => As(ForceChangeRateUnit.MicronewtonPerSecond);
+
+ ///
+ /// Get ForceChangeRate in MillinewtonsPerSecond.
+ ///
+ public double MillinewtonsPerSecond => As(ForceChangeRateUnit.MillinewtonPerSecond);
+
+ ///
+ /// Get ForceChangeRate in NanonewtonsPerSecond.
+ ///
+ public double NanonewtonsPerSecond => As(ForceChangeRateUnit.NanonewtonPerSecond);
+
+ ///
+ /// Get ForceChangeRate in NewtonsPerMinute.
+ ///
+ public double NewtonsPerMinute => As(ForceChangeRateUnit.NewtonPerMinute);
+
+ ///
+ /// Get ForceChangeRate in NewtonsPerSecond.
+ ///
+ public double NewtonsPerSecond => As(ForceChangeRateUnit.NewtonPerSecond);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ForceChangeRateUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ForceChangeRateUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ForceChangeRate from CentinewtonsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForceChangeRate FromCentinewtonsPerSecond(double centinewtonspersecond)
+ {
+ double value = (double) centinewtonspersecond;
+ return new ForceChangeRate(value, ForceChangeRateUnit.CentinewtonPerSecond);
+ }
+ ///
+ /// Get ForceChangeRate from DecanewtonsPerMinute.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForceChangeRate FromDecanewtonsPerMinute(double decanewtonsperminute)
+ {
+ double value = (double) decanewtonsperminute;
+ return new ForceChangeRate(value, ForceChangeRateUnit.DecanewtonPerMinute);
+ }
+ ///
+ /// Get ForceChangeRate from DecanewtonsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForceChangeRate FromDecanewtonsPerSecond(double decanewtonspersecond)
+ {
+ double value = (double) decanewtonspersecond;
+ return new ForceChangeRate(value, ForceChangeRateUnit.DecanewtonPerSecond);
+ }
+ ///
+ /// Get ForceChangeRate from DecinewtonsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForceChangeRate FromDecinewtonsPerSecond(double decinewtonspersecond)
+ {
+ double value = (double) decinewtonspersecond;
+ return new ForceChangeRate(value, ForceChangeRateUnit.DecinewtonPerSecond);
+ }
+ ///
+ /// Get ForceChangeRate from KilonewtonsPerMinute.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForceChangeRate FromKilonewtonsPerMinute(double kilonewtonsperminute)
+ {
+ double value = (double) kilonewtonsperminute;
+ return new ForceChangeRate(value, ForceChangeRateUnit.KilonewtonPerMinute);
+ }
+ ///
+ /// Get ForceChangeRate from KilonewtonsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForceChangeRate FromKilonewtonsPerSecond(double kilonewtonspersecond)
+ {
+ double value = (double) kilonewtonspersecond;
+ return new ForceChangeRate(value, ForceChangeRateUnit.KilonewtonPerSecond);
+ }
+ ///
+ /// Get ForceChangeRate from MicronewtonsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForceChangeRate FromMicronewtonsPerSecond(double micronewtonspersecond)
+ {
+ double value = (double) micronewtonspersecond;
+ return new ForceChangeRate(value, ForceChangeRateUnit.MicronewtonPerSecond);
+ }
+ ///
+ /// Get ForceChangeRate from MillinewtonsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForceChangeRate FromMillinewtonsPerSecond(double millinewtonspersecond)
+ {
+ double value = (double) millinewtonspersecond;
+ return new ForceChangeRate(value, ForceChangeRateUnit.MillinewtonPerSecond);
+ }
+ ///
+ /// Get ForceChangeRate from NanonewtonsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForceChangeRate FromNanonewtonsPerSecond(double nanonewtonspersecond)
+ {
+ double value = (double) nanonewtonspersecond;
+ return new ForceChangeRate(value, ForceChangeRateUnit.NanonewtonPerSecond);
+ }
+ ///
+ /// Get ForceChangeRate from NewtonsPerMinute.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForceChangeRate FromNewtonsPerMinute(double newtonsperminute)
+ {
+ double value = (double) newtonsperminute;
+ return new ForceChangeRate(value, ForceChangeRateUnit.NewtonPerMinute);
+ }
+ ///
+ /// Get ForceChangeRate from NewtonsPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForceChangeRate FromNewtonsPerSecond(double newtonspersecond)
+ {
+ double value = (double) newtonspersecond;
+ return new ForceChangeRate(value, ForceChangeRateUnit.NewtonPerSecond);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ForceChangeRate unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ForceChangeRate From(double value, ForceChangeRateUnit fromUnit)
+ {
+ return new ForceChangeRate((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ForceChangeRate Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ForceChangeRate result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ForceChangeRate result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ForceChangeRateUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ForceChangeRateUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ForceChangeRateUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ForceChangeRateUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ForceChangeRate)) throw new ArgumentException("Expected type ForceChangeRate.", nameof(obj));
+
+ return CompareTo((ForceChangeRate)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ForceChangeRate other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ForceChangeRate within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ForceChangeRate other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ForceChangeRate.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ForceChangeRateUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ForceChangeRate to another ForceChangeRate with the unit representation .
+ ///
+ /// A ForceChangeRate with the specified unit.
+ public ForceChangeRate ToUnit(ForceChangeRateUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ForceChangeRate(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ForceChangeRateUnit.CentinewtonPerSecond: return (_value) * 1e-2d;
+ case ForceChangeRateUnit.DecanewtonPerMinute: return (_value/60) * 1e1d;
+ case ForceChangeRateUnit.DecanewtonPerSecond: return (_value) * 1e1d;
+ case ForceChangeRateUnit.DecinewtonPerSecond: return (_value) * 1e-1d;
+ case ForceChangeRateUnit.KilonewtonPerMinute: return (_value/60) * 1e3d;
+ case ForceChangeRateUnit.KilonewtonPerSecond: return (_value) * 1e3d;
+ case ForceChangeRateUnit.MicronewtonPerSecond: return (_value) * 1e-6d;
+ case ForceChangeRateUnit.MillinewtonPerSecond: return (_value) * 1e-3d;
+ case ForceChangeRateUnit.NanonewtonPerSecond: return (_value) * 1e-9d;
+ case ForceChangeRateUnit.NewtonPerMinute: return _value/60;
+ case ForceChangeRateUnit.NewtonPerSecond: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ForceChangeRateUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ForceChangeRateUnit.CentinewtonPerSecond: return (baseUnitValue) / 1e-2d;
+ case ForceChangeRateUnit.DecanewtonPerMinute: return (baseUnitValue*60) / 1e1d;
+ case ForceChangeRateUnit.DecanewtonPerSecond: return (baseUnitValue) / 1e1d;
+ case ForceChangeRateUnit.DecinewtonPerSecond: return (baseUnitValue) / 1e-1d;
+ case ForceChangeRateUnit.KilonewtonPerMinute: return (baseUnitValue*60) / 1e3d;
+ case ForceChangeRateUnit.KilonewtonPerSecond: return (baseUnitValue) / 1e3d;
+ case ForceChangeRateUnit.MicronewtonPerSecond: return (baseUnitValue) / 1e-6d;
+ case ForceChangeRateUnit.MillinewtonPerSecond: return (baseUnitValue) / 1e-3d;
+ case ForceChangeRateUnit.NanonewtonPerSecond: return (baseUnitValue) / 1e-9d;
+ case ForceChangeRateUnit.NewtonPerMinute: return baseUnitValue*60;
+ case ForceChangeRateUnit.NewtonPerSecond: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ForcePerLength.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ForcePerLength.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..05c3e249b4
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/ForcePerLength.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,706 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The magnitude of force per unit length.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class ForcePerLength : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly ForcePerLengthUnit? _unit;
+
+ static ForcePerLength()
+ {
+ BaseDimensions = new BaseDimensions(0, 1, -2, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit NewtonPerMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public ForcePerLength()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private ForcePerLength(double numericValue, ForcePerLengthUnit unit)
+ {
+ if(unit == ForcePerLengthUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of ForcePerLength, which is NewtonPerMeter. All conversions go via this value.
+ ///
+ public static ForcePerLengthUnit BaseUnit => ForcePerLengthUnit.NewtonPerMeter;
+
+ ///
+ /// Represents the largest possible value of ForcePerLength
+ ///
+ public static ForcePerLength MaxValue => new ForcePerLength(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of ForcePerLength
+ ///
+ public static ForcePerLength MinValue => new ForcePerLength(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.ForcePerLength;
+
+ ///
+ /// All units of measurement for the ForcePerLength quantity.
+ ///
+ public static ForcePerLengthUnit[] Units { get; } = Enum.GetValues(typeof(ForcePerLengthUnit)).Cast().Except(new ForcePerLengthUnit[]{ ForcePerLengthUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit NewtonPerMeter.
+ ///
+ public static ForcePerLength Zero => new ForcePerLength(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public ForcePerLengthUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => ForcePerLength.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => ForcePerLength.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get ForcePerLength in CentinewtonsPerMeter.
+ ///
+ public double CentinewtonsPerMeter => As(ForcePerLengthUnit.CentinewtonPerMeter);
+
+ ///
+ /// Get ForcePerLength in DecinewtonsPerMeter.
+ ///
+ public double DecinewtonsPerMeter => As(ForcePerLengthUnit.DecinewtonPerMeter);
+
+ ///
+ /// Get ForcePerLength in KilogramsForcePerMeter.
+ ///
+ public double KilogramsForcePerMeter => As(ForcePerLengthUnit.KilogramForcePerMeter);
+
+ ///
+ /// Get ForcePerLength in KilonewtonsPerMeter.
+ ///
+ public double KilonewtonsPerMeter => As(ForcePerLengthUnit.KilonewtonPerMeter);
+
+ ///
+ /// Get ForcePerLength in MeganewtonsPerMeter.
+ ///
+ public double MeganewtonsPerMeter => As(ForcePerLengthUnit.MeganewtonPerMeter);
+
+ ///
+ /// Get ForcePerLength in MicronewtonsPerMeter.
+ ///
+ public double MicronewtonsPerMeter => As(ForcePerLengthUnit.MicronewtonPerMeter);
+
+ ///
+ /// Get ForcePerLength in MillinewtonsPerMeter.
+ ///
+ public double MillinewtonsPerMeter => As(ForcePerLengthUnit.MillinewtonPerMeter);
+
+ ///
+ /// Get ForcePerLength in NanonewtonsPerMeter.
+ ///
+ public double NanonewtonsPerMeter => As(ForcePerLengthUnit.NanonewtonPerMeter);
+
+ ///
+ /// Get ForcePerLength in NewtonsPerMeter.
+ ///
+ public double NewtonsPerMeter => As(ForcePerLengthUnit.NewtonPerMeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(ForcePerLengthUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(ForcePerLengthUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get ForcePerLength from CentinewtonsPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForcePerLength FromCentinewtonsPerMeter(double centinewtonspermeter)
+ {
+ double value = (double) centinewtonspermeter;
+ return new ForcePerLength(value, ForcePerLengthUnit.CentinewtonPerMeter);
+ }
+ ///
+ /// Get ForcePerLength from DecinewtonsPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForcePerLength FromDecinewtonsPerMeter(double decinewtonspermeter)
+ {
+ double value = (double) decinewtonspermeter;
+ return new ForcePerLength(value, ForcePerLengthUnit.DecinewtonPerMeter);
+ }
+ ///
+ /// Get ForcePerLength from KilogramsForcePerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForcePerLength FromKilogramsForcePerMeter(double kilogramsforcepermeter)
+ {
+ double value = (double) kilogramsforcepermeter;
+ return new ForcePerLength(value, ForcePerLengthUnit.KilogramForcePerMeter);
+ }
+ ///
+ /// Get ForcePerLength from KilonewtonsPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForcePerLength FromKilonewtonsPerMeter(double kilonewtonspermeter)
+ {
+ double value = (double) kilonewtonspermeter;
+ return new ForcePerLength(value, ForcePerLengthUnit.KilonewtonPerMeter);
+ }
+ ///
+ /// Get ForcePerLength from MeganewtonsPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForcePerLength FromMeganewtonsPerMeter(double meganewtonspermeter)
+ {
+ double value = (double) meganewtonspermeter;
+ return new ForcePerLength(value, ForcePerLengthUnit.MeganewtonPerMeter);
+ }
+ ///
+ /// Get ForcePerLength from MicronewtonsPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForcePerLength FromMicronewtonsPerMeter(double micronewtonspermeter)
+ {
+ double value = (double) micronewtonspermeter;
+ return new ForcePerLength(value, ForcePerLengthUnit.MicronewtonPerMeter);
+ }
+ ///
+ /// Get ForcePerLength from MillinewtonsPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForcePerLength FromMillinewtonsPerMeter(double millinewtonspermeter)
+ {
+ double value = (double) millinewtonspermeter;
+ return new ForcePerLength(value, ForcePerLengthUnit.MillinewtonPerMeter);
+ }
+ ///
+ /// Get ForcePerLength from NanonewtonsPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForcePerLength FromNanonewtonsPerMeter(double nanonewtonspermeter)
+ {
+ double value = (double) nanonewtonspermeter;
+ return new ForcePerLength(value, ForcePerLengthUnit.NanonewtonPerMeter);
+ }
+ ///
+ /// Get ForcePerLength from NewtonsPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static ForcePerLength FromNewtonsPerMeter(double newtonspermeter)
+ {
+ double value = (double) newtonspermeter;
+ return new ForcePerLength(value, ForcePerLengthUnit.NewtonPerMeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// ForcePerLength unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static ForcePerLength From(double value, ForcePerLengthUnit fromUnit)
+ {
+ return new ForcePerLength((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 ForcePerLength Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ForcePerLength Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out ForcePerLength result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out ForcePerLength result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static ForcePerLengthUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static ForcePerLengthUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out ForcePerLengthUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out ForcePerLengthUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is ForcePerLength)) throw new ArgumentException("Expected type ForcePerLength.", nameof(obj));
+
+ return CompareTo((ForcePerLength)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(ForcePerLength other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another ForcePerLength within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(ForcePerLength other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current ForcePerLength.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(ForcePerLengthUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this ForcePerLength to another ForcePerLength with the unit representation .
+ ///
+ /// A ForcePerLength with the specified unit.
+ public ForcePerLength ToUnit(ForcePerLengthUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new ForcePerLength(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case ForcePerLengthUnit.CentinewtonPerMeter: return (_value) * 1e-2d;
+ case ForcePerLengthUnit.DecinewtonPerMeter: return (_value) * 1e-1d;
+ case ForcePerLengthUnit.KilogramForcePerMeter: return _value*9.80665002864;
+ case ForcePerLengthUnit.KilonewtonPerMeter: return (_value) * 1e3d;
+ case ForcePerLengthUnit.MeganewtonPerMeter: return (_value) * 1e6d;
+ case ForcePerLengthUnit.MicronewtonPerMeter: return (_value) * 1e-6d;
+ case ForcePerLengthUnit.MillinewtonPerMeter: return (_value) * 1e-3d;
+ case ForcePerLengthUnit.NanonewtonPerMeter: return (_value) * 1e-9d;
+ case ForcePerLengthUnit.NewtonPerMeter: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(ForcePerLengthUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case ForcePerLengthUnit.CentinewtonPerMeter: return (baseUnitValue) / 1e-2d;
+ case ForcePerLengthUnit.DecinewtonPerMeter: return (baseUnitValue) / 1e-1d;
+ case ForcePerLengthUnit.KilogramForcePerMeter: return baseUnitValue/9.80665002864;
+ case ForcePerLengthUnit.KilonewtonPerMeter: return (baseUnitValue) / 1e3d;
+ case ForcePerLengthUnit.MeganewtonPerMeter: return (baseUnitValue) / 1e6d;
+ case ForcePerLengthUnit.MicronewtonPerMeter: return (baseUnitValue) / 1e-6d;
+ case ForcePerLengthUnit.MillinewtonPerMeter: return (baseUnitValue) / 1e-3d;
+ case ForcePerLengthUnit.NanonewtonPerMeter: return (baseUnitValue) / 1e-9d;
+ case ForcePerLengthUnit.NewtonPerMeter: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Frequency.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Frequency.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..5822efad71
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Frequency.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,689 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The number of occurrences of a repeating event per unit time.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Frequency : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly FrequencyUnit? _unit;
+
+ static Frequency()
+ {
+ BaseDimensions = new BaseDimensions(0, 0, -1, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Hertz.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Frequency()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Frequency(double numericValue, FrequencyUnit unit)
+ {
+ if(unit == FrequencyUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Frequency, which is Hertz. All conversions go via this value.
+ ///
+ public static FrequencyUnit BaseUnit => FrequencyUnit.Hertz;
+
+ ///
+ /// Represents the largest possible value of Frequency
+ ///
+ public static Frequency MaxValue => new Frequency(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Frequency
+ ///
+ public static Frequency MinValue => new Frequency(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Frequency;
+
+ ///
+ /// All units of measurement for the Frequency quantity.
+ ///
+ public static FrequencyUnit[] Units { get; } = Enum.GetValues(typeof(FrequencyUnit)).Cast().Except(new FrequencyUnit[]{ FrequencyUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Hertz.
+ ///
+ public static Frequency Zero => new Frequency(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public FrequencyUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Frequency.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Frequency.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Frequency in CyclesPerHour.
+ ///
+ public double CyclesPerHour => As(FrequencyUnit.CyclePerHour);
+
+ ///
+ /// Get Frequency in CyclesPerMinute.
+ ///
+ public double CyclesPerMinute => As(FrequencyUnit.CyclePerMinute);
+
+ ///
+ /// Get Frequency in Gigahertz.
+ ///
+ public double Gigahertz => As(FrequencyUnit.Gigahertz);
+
+ ///
+ /// Get Frequency in Hertz.
+ ///
+ public double Hertz => As(FrequencyUnit.Hertz);
+
+ ///
+ /// Get Frequency in Kilohertz.
+ ///
+ public double Kilohertz => As(FrequencyUnit.Kilohertz);
+
+ ///
+ /// Get Frequency in Megahertz.
+ ///
+ public double Megahertz => As(FrequencyUnit.Megahertz);
+
+ ///
+ /// Get Frequency in RadiansPerSecond.
+ ///
+ public double RadiansPerSecond => As(FrequencyUnit.RadianPerSecond);
+
+ ///
+ /// Get Frequency in Terahertz.
+ ///
+ public double Terahertz => As(FrequencyUnit.Terahertz);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(FrequencyUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(FrequencyUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Frequency from CyclesPerHour.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Frequency FromCyclesPerHour(double cyclesperhour)
+ {
+ double value = (double) cyclesperhour;
+ return new Frequency(value, FrequencyUnit.CyclePerHour);
+ }
+ ///
+ /// Get Frequency from CyclesPerMinute.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Frequency FromCyclesPerMinute(double cyclesperminute)
+ {
+ double value = (double) cyclesperminute;
+ return new Frequency(value, FrequencyUnit.CyclePerMinute);
+ }
+ ///
+ /// Get Frequency from Gigahertz.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Frequency FromGigahertz(double gigahertz)
+ {
+ double value = (double) gigahertz;
+ return new Frequency(value, FrequencyUnit.Gigahertz);
+ }
+ ///
+ /// Get Frequency from Hertz.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Frequency FromHertz(double hertz)
+ {
+ double value = (double) hertz;
+ return new Frequency(value, FrequencyUnit.Hertz);
+ }
+ ///
+ /// Get Frequency from Kilohertz.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Frequency FromKilohertz(double kilohertz)
+ {
+ double value = (double) kilohertz;
+ return new Frequency(value, FrequencyUnit.Kilohertz);
+ }
+ ///
+ /// Get Frequency from Megahertz.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Frequency FromMegahertz(double megahertz)
+ {
+ double value = (double) megahertz;
+ return new Frequency(value, FrequencyUnit.Megahertz);
+ }
+ ///
+ /// Get Frequency from RadiansPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Frequency FromRadiansPerSecond(double radianspersecond)
+ {
+ double value = (double) radianspersecond;
+ return new Frequency(value, FrequencyUnit.RadianPerSecond);
+ }
+ ///
+ /// Get Frequency from Terahertz.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Frequency FromTerahertz(double terahertz)
+ {
+ double value = (double) terahertz;
+ return new Frequency(value, FrequencyUnit.Terahertz);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Frequency unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Frequency From(double value, FrequencyUnit fromUnit)
+ {
+ return new Frequency((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Frequency Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Frequency result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Frequency result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static FrequencyUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static FrequencyUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out FrequencyUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out FrequencyUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Frequency)) throw new ArgumentException("Expected type Frequency.", nameof(obj));
+
+ return CompareTo((Frequency)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Frequency other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Frequency within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Frequency other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Frequency.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(FrequencyUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Frequency to another Frequency with the unit representation .
+ ///
+ /// A Frequency with the specified unit.
+ public Frequency ToUnit(FrequencyUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Frequency(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case FrequencyUnit.CyclePerHour: return _value/3600;
+ case FrequencyUnit.CyclePerMinute: return _value/60;
+ case FrequencyUnit.Gigahertz: return (_value) * 1e9d;
+ case FrequencyUnit.Hertz: return _value;
+ case FrequencyUnit.Kilohertz: return (_value) * 1e3d;
+ case FrequencyUnit.Megahertz: return (_value) * 1e6d;
+ case FrequencyUnit.RadianPerSecond: return _value/6.2831853072;
+ case FrequencyUnit.Terahertz: return (_value) * 1e12d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(FrequencyUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case FrequencyUnit.CyclePerHour: return baseUnitValue*3600;
+ case FrequencyUnit.CyclePerMinute: return baseUnitValue*60;
+ case FrequencyUnit.Gigahertz: return (baseUnitValue) / 1e9d;
+ case FrequencyUnit.Hertz: return baseUnitValue;
+ case FrequencyUnit.Kilohertz: return (baseUnitValue) / 1e3d;
+ case FrequencyUnit.Megahertz: return (baseUnitValue) / 1e6d;
+ case FrequencyUnit.RadianPerSecond: return baseUnitValue*6.2831853072;
+ case FrequencyUnit.Terahertz: return (baseUnitValue) / 1e12d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/HeatFlux.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/HeatFlux.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..408b7d2c64
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/HeatFlux.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,825 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Heat flux is the flow of energy per unit of area per unit of time
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class HeatFlux : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly HeatFluxUnit? _unit;
+
+ static HeatFlux()
+ {
+ BaseDimensions = new BaseDimensions(0, 1, -3, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit WattPerSquareMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public HeatFlux()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private HeatFlux(double numericValue, HeatFluxUnit unit)
+ {
+ if(unit == HeatFluxUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of HeatFlux, which is WattPerSquareMeter. All conversions go via this value.
+ ///
+ public static HeatFluxUnit BaseUnit => HeatFluxUnit.WattPerSquareMeter;
+
+ ///
+ /// Represents the largest possible value of HeatFlux
+ ///
+ public static HeatFlux MaxValue => new HeatFlux(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of HeatFlux
+ ///
+ public static HeatFlux MinValue => new HeatFlux(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.HeatFlux;
+
+ ///
+ /// All units of measurement for the HeatFlux quantity.
+ ///
+ public static HeatFluxUnit[] Units { get; } = Enum.GetValues(typeof(HeatFluxUnit)).Cast().Except(new HeatFluxUnit[]{ HeatFluxUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit WattPerSquareMeter.
+ ///
+ public static HeatFlux Zero => new HeatFlux(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public HeatFluxUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => HeatFlux.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => HeatFlux.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get HeatFlux in BtusPerHourSquareFoot.
+ ///
+ public double BtusPerHourSquareFoot => As(HeatFluxUnit.BtuPerHourSquareFoot);
+
+ ///
+ /// Get HeatFlux in BtusPerMinuteSquareFoot.
+ ///
+ public double BtusPerMinuteSquareFoot => As(HeatFluxUnit.BtuPerMinuteSquareFoot);
+
+ ///
+ /// Get HeatFlux in BtusPerSecondSquareFoot.
+ ///
+ public double BtusPerSecondSquareFoot => As(HeatFluxUnit.BtuPerSecondSquareFoot);
+
+ ///
+ /// Get HeatFlux in BtusPerSecondSquareInch.
+ ///
+ public double BtusPerSecondSquareInch => As(HeatFluxUnit.BtuPerSecondSquareInch);
+
+ ///
+ /// Get HeatFlux in CaloriesPerSecondSquareCentimeter.
+ ///
+ public double CaloriesPerSecondSquareCentimeter => As(HeatFluxUnit.CaloriePerSecondSquareCentimeter);
+
+ ///
+ /// Get HeatFlux in CentiwattsPerSquareMeter.
+ ///
+ public double CentiwattsPerSquareMeter => As(HeatFluxUnit.CentiwattPerSquareMeter);
+
+ ///
+ /// Get HeatFlux in DeciwattsPerSquareMeter.
+ ///
+ public double DeciwattsPerSquareMeter => As(HeatFluxUnit.DeciwattPerSquareMeter);
+
+ ///
+ /// Get HeatFlux in KilocaloriesPerHourSquareMeter.
+ ///
+ public double KilocaloriesPerHourSquareMeter => As(HeatFluxUnit.KilocaloriePerHourSquareMeter);
+
+ ///
+ /// Get HeatFlux in KilocaloriesPerSecondSquareCentimeter.
+ ///
+ public double KilocaloriesPerSecondSquareCentimeter => As(HeatFluxUnit.KilocaloriePerSecondSquareCentimeter);
+
+ ///
+ /// Get HeatFlux in KilowattsPerSquareMeter.
+ ///
+ public double KilowattsPerSquareMeter => As(HeatFluxUnit.KilowattPerSquareMeter);
+
+ ///
+ /// Get HeatFlux in MicrowattsPerSquareMeter.
+ ///
+ public double MicrowattsPerSquareMeter => As(HeatFluxUnit.MicrowattPerSquareMeter);
+
+ ///
+ /// Get HeatFlux in MilliwattsPerSquareMeter.
+ ///
+ public double MilliwattsPerSquareMeter => As(HeatFluxUnit.MilliwattPerSquareMeter);
+
+ ///
+ /// Get HeatFlux in NanowattsPerSquareMeter.
+ ///
+ public double NanowattsPerSquareMeter => As(HeatFluxUnit.NanowattPerSquareMeter);
+
+ ///
+ /// Get HeatFlux in WattsPerSquareFoot.
+ ///
+ public double WattsPerSquareFoot => As(HeatFluxUnit.WattPerSquareFoot);
+
+ ///
+ /// Get HeatFlux in WattsPerSquareInch.
+ ///
+ public double WattsPerSquareInch => As(HeatFluxUnit.WattPerSquareInch);
+
+ ///
+ /// Get HeatFlux in WattsPerSquareMeter.
+ ///
+ public double WattsPerSquareMeter => As(HeatFluxUnit.WattPerSquareMeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(HeatFluxUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(HeatFluxUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get HeatFlux from BtusPerHourSquareFoot.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromBtusPerHourSquareFoot(double btusperhoursquarefoot)
+ {
+ double value = (double) btusperhoursquarefoot;
+ return new HeatFlux(value, HeatFluxUnit.BtuPerHourSquareFoot);
+ }
+ ///
+ /// Get HeatFlux from BtusPerMinuteSquareFoot.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromBtusPerMinuteSquareFoot(double btusperminutesquarefoot)
+ {
+ double value = (double) btusperminutesquarefoot;
+ return new HeatFlux(value, HeatFluxUnit.BtuPerMinuteSquareFoot);
+ }
+ ///
+ /// Get HeatFlux from BtusPerSecondSquareFoot.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromBtusPerSecondSquareFoot(double btuspersecondsquarefoot)
+ {
+ double value = (double) btuspersecondsquarefoot;
+ return new HeatFlux(value, HeatFluxUnit.BtuPerSecondSquareFoot);
+ }
+ ///
+ /// Get HeatFlux from BtusPerSecondSquareInch.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromBtusPerSecondSquareInch(double btuspersecondsquareinch)
+ {
+ double value = (double) btuspersecondsquareinch;
+ return new HeatFlux(value, HeatFluxUnit.BtuPerSecondSquareInch);
+ }
+ ///
+ /// Get HeatFlux from CaloriesPerSecondSquareCentimeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromCaloriesPerSecondSquareCentimeter(double caloriespersecondsquarecentimeter)
+ {
+ double value = (double) caloriespersecondsquarecentimeter;
+ return new HeatFlux(value, HeatFluxUnit.CaloriePerSecondSquareCentimeter);
+ }
+ ///
+ /// Get HeatFlux from CentiwattsPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromCentiwattsPerSquareMeter(double centiwattspersquaremeter)
+ {
+ double value = (double) centiwattspersquaremeter;
+ return new HeatFlux(value, HeatFluxUnit.CentiwattPerSquareMeter);
+ }
+ ///
+ /// Get HeatFlux from DeciwattsPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromDeciwattsPerSquareMeter(double deciwattspersquaremeter)
+ {
+ double value = (double) deciwattspersquaremeter;
+ return new HeatFlux(value, HeatFluxUnit.DeciwattPerSquareMeter);
+ }
+ ///
+ /// Get HeatFlux from KilocaloriesPerHourSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromKilocaloriesPerHourSquareMeter(double kilocaloriesperhoursquaremeter)
+ {
+ double value = (double) kilocaloriesperhoursquaremeter;
+ return new HeatFlux(value, HeatFluxUnit.KilocaloriePerHourSquareMeter);
+ }
+ ///
+ /// Get HeatFlux from KilocaloriesPerSecondSquareCentimeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromKilocaloriesPerSecondSquareCentimeter(double kilocaloriespersecondsquarecentimeter)
+ {
+ double value = (double) kilocaloriespersecondsquarecentimeter;
+ return new HeatFlux(value, HeatFluxUnit.KilocaloriePerSecondSquareCentimeter);
+ }
+ ///
+ /// Get HeatFlux from KilowattsPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromKilowattsPerSquareMeter(double kilowattspersquaremeter)
+ {
+ double value = (double) kilowattspersquaremeter;
+ return new HeatFlux(value, HeatFluxUnit.KilowattPerSquareMeter);
+ }
+ ///
+ /// Get HeatFlux from MicrowattsPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromMicrowattsPerSquareMeter(double microwattspersquaremeter)
+ {
+ double value = (double) microwattspersquaremeter;
+ return new HeatFlux(value, HeatFluxUnit.MicrowattPerSquareMeter);
+ }
+ ///
+ /// Get HeatFlux from MilliwattsPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromMilliwattsPerSquareMeter(double milliwattspersquaremeter)
+ {
+ double value = (double) milliwattspersquaremeter;
+ return new HeatFlux(value, HeatFluxUnit.MilliwattPerSquareMeter);
+ }
+ ///
+ /// Get HeatFlux from NanowattsPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromNanowattsPerSquareMeter(double nanowattspersquaremeter)
+ {
+ double value = (double) nanowattspersquaremeter;
+ return new HeatFlux(value, HeatFluxUnit.NanowattPerSquareMeter);
+ }
+ ///
+ /// Get HeatFlux from WattsPerSquareFoot.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromWattsPerSquareFoot(double wattspersquarefoot)
+ {
+ double value = (double) wattspersquarefoot;
+ return new HeatFlux(value, HeatFluxUnit.WattPerSquareFoot);
+ }
+ ///
+ /// Get HeatFlux from WattsPerSquareInch.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromWattsPerSquareInch(double wattspersquareinch)
+ {
+ double value = (double) wattspersquareinch;
+ return new HeatFlux(value, HeatFluxUnit.WattPerSquareInch);
+ }
+ ///
+ /// Get HeatFlux from WattsPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatFlux FromWattsPerSquareMeter(double wattspersquaremeter)
+ {
+ double value = (double) wattspersquaremeter;
+ return new HeatFlux(value, HeatFluxUnit.WattPerSquareMeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// HeatFlux unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static HeatFlux From(double value, HeatFluxUnit fromUnit)
+ {
+ return new HeatFlux((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 HeatFlux Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static HeatFlux Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out HeatFlux result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out HeatFlux result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static HeatFluxUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static HeatFluxUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out HeatFluxUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out HeatFluxUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is HeatFlux)) throw new ArgumentException("Expected type HeatFlux.", nameof(obj));
+
+ return CompareTo((HeatFlux)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(HeatFlux other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another HeatFlux within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(HeatFlux other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current HeatFlux.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(HeatFluxUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this HeatFlux to another HeatFlux with the unit representation .
+ ///
+ /// A HeatFlux with the specified unit.
+ public HeatFlux ToUnit(HeatFluxUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new HeatFlux(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case HeatFluxUnit.BtuPerHourSquareFoot: return _value*3.15459075;
+ case HeatFluxUnit.BtuPerMinuteSquareFoot: return _value*1.89275445e2;
+ case HeatFluxUnit.BtuPerSecondSquareFoot: return _value*1.13565267e4;
+ case HeatFluxUnit.BtuPerSecondSquareInch: return _value*1.63533984e6;
+ case HeatFluxUnit.CaloriePerSecondSquareCentimeter: return _value*4.1868e4;
+ case HeatFluxUnit.CentiwattPerSquareMeter: return (_value) * 1e-2d;
+ case HeatFluxUnit.DeciwattPerSquareMeter: return (_value) * 1e-1d;
+ case HeatFluxUnit.KilocaloriePerHourSquareMeter: return _value*1.163;
+ case HeatFluxUnit.KilocaloriePerSecondSquareCentimeter: return (_value*4.1868e4) * 1e3d;
+ case HeatFluxUnit.KilowattPerSquareMeter: return (_value) * 1e3d;
+ case HeatFluxUnit.MicrowattPerSquareMeter: return (_value) * 1e-6d;
+ case HeatFluxUnit.MilliwattPerSquareMeter: return (_value) * 1e-3d;
+ case HeatFluxUnit.NanowattPerSquareMeter: return (_value) * 1e-9d;
+ case HeatFluxUnit.WattPerSquareFoot: return _value*1.07639e1;
+ case HeatFluxUnit.WattPerSquareInch: return _value*1.5500031e3;
+ case HeatFluxUnit.WattPerSquareMeter: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(HeatFluxUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case HeatFluxUnit.BtuPerHourSquareFoot: return baseUnitValue/3.15459075;
+ case HeatFluxUnit.BtuPerMinuteSquareFoot: return baseUnitValue/1.89275445e2;
+ case HeatFluxUnit.BtuPerSecondSquareFoot: return baseUnitValue/1.13565267e4;
+ case HeatFluxUnit.BtuPerSecondSquareInch: return baseUnitValue/1.63533984e6;
+ case HeatFluxUnit.CaloriePerSecondSquareCentimeter: return baseUnitValue/4.1868e4;
+ case HeatFluxUnit.CentiwattPerSquareMeter: return (baseUnitValue) / 1e-2d;
+ case HeatFluxUnit.DeciwattPerSquareMeter: return (baseUnitValue) / 1e-1d;
+ case HeatFluxUnit.KilocaloriePerHourSquareMeter: return baseUnitValue/1.163;
+ case HeatFluxUnit.KilocaloriePerSecondSquareCentimeter: return (baseUnitValue/4.1868e4) / 1e3d;
+ case HeatFluxUnit.KilowattPerSquareMeter: return (baseUnitValue) / 1e3d;
+ case HeatFluxUnit.MicrowattPerSquareMeter: return (baseUnitValue) / 1e-6d;
+ case HeatFluxUnit.MilliwattPerSquareMeter: return (baseUnitValue) / 1e-3d;
+ case HeatFluxUnit.NanowattPerSquareMeter: return (baseUnitValue) / 1e-9d;
+ case HeatFluxUnit.WattPerSquareFoot: return baseUnitValue/1.07639e1;
+ case HeatFluxUnit.WattPerSquareInch: return baseUnitValue/1.5500031e3;
+ case HeatFluxUnit.WattPerSquareMeter: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/HeatTransferCoefficient.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/HeatTransferCoefficient.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..49fa0395d2
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/HeatTransferCoefficient.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,587 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The heat transfer coefficient or film coefficient, or film effectiveness, in thermodynamics and in mechanics is the proportionality constant between the heat flux and the thermodynamic driving force for the flow of heat (i.e., the temperature difference, ΔT)
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class HeatTransferCoefficient : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly HeatTransferCoefficientUnit? _unit;
+
+ static HeatTransferCoefficient()
+ {
+ BaseDimensions = new BaseDimensions(0, 1, -3, 0, -1, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit WattPerSquareMeterKelvin.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public HeatTransferCoefficient()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private HeatTransferCoefficient(double numericValue, HeatTransferCoefficientUnit unit)
+ {
+ if(unit == HeatTransferCoefficientUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of HeatTransferCoefficient, which is WattPerSquareMeterKelvin. All conversions go via this value.
+ ///
+ public static HeatTransferCoefficientUnit BaseUnit => HeatTransferCoefficientUnit.WattPerSquareMeterKelvin;
+
+ ///
+ /// Represents the largest possible value of HeatTransferCoefficient
+ ///
+ public static HeatTransferCoefficient MaxValue => new HeatTransferCoefficient(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of HeatTransferCoefficient
+ ///
+ public static HeatTransferCoefficient MinValue => new HeatTransferCoefficient(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.HeatTransferCoefficient;
+
+ ///
+ /// All units of measurement for the HeatTransferCoefficient quantity.
+ ///
+ public static HeatTransferCoefficientUnit[] Units { get; } = Enum.GetValues(typeof(HeatTransferCoefficientUnit)).Cast().Except(new HeatTransferCoefficientUnit[]{ HeatTransferCoefficientUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit WattPerSquareMeterKelvin.
+ ///
+ public static HeatTransferCoefficient Zero => new HeatTransferCoefficient(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public HeatTransferCoefficientUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => HeatTransferCoefficient.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => HeatTransferCoefficient.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get HeatTransferCoefficient in WattsPerSquareMeterCelsius.
+ ///
+ public double WattsPerSquareMeterCelsius => As(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius);
+
+ ///
+ /// Get HeatTransferCoefficient in WattsPerSquareMeterKelvin.
+ ///
+ public double WattsPerSquareMeterKelvin => As(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(HeatTransferCoefficientUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(HeatTransferCoefficientUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get HeatTransferCoefficient from WattsPerSquareMeterCelsius.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatTransferCoefficient FromWattsPerSquareMeterCelsius(double wattspersquaremetercelsius)
+ {
+ double value = (double) wattspersquaremetercelsius;
+ return new HeatTransferCoefficient(value, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius);
+ }
+ ///
+ /// Get HeatTransferCoefficient from WattsPerSquareMeterKelvin.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static HeatTransferCoefficient FromWattsPerSquareMeterKelvin(double wattspersquaremeterkelvin)
+ {
+ double value = (double) wattspersquaremeterkelvin;
+ return new HeatTransferCoefficient(value, HeatTransferCoefficientUnit.WattPerSquareMeterKelvin);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// HeatTransferCoefficient unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static HeatTransferCoefficient From(double value, HeatTransferCoefficientUnit fromUnit)
+ {
+ return new HeatTransferCoefficient((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 HeatTransferCoefficient Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static HeatTransferCoefficient Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out HeatTransferCoefficient result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out HeatTransferCoefficient result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static HeatTransferCoefficientUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static HeatTransferCoefficientUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out HeatTransferCoefficientUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out HeatTransferCoefficientUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is HeatTransferCoefficient)) throw new ArgumentException("Expected type HeatTransferCoefficient.", nameof(obj));
+
+ return CompareTo((HeatTransferCoefficient)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(HeatTransferCoefficient other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another HeatTransferCoefficient within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(HeatTransferCoefficient other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current HeatTransferCoefficient.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(HeatTransferCoefficientUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this HeatTransferCoefficient to another HeatTransferCoefficient with the unit representation .
+ ///
+ /// A HeatTransferCoefficient with the specified unit.
+ public HeatTransferCoefficient ToUnit(HeatTransferCoefficientUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new HeatTransferCoefficient(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case HeatTransferCoefficientUnit.WattPerSquareMeterCelsius: return _value;
+ case HeatTransferCoefficientUnit.WattPerSquareMeterKelvin: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(HeatTransferCoefficientUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case HeatTransferCoefficientUnit.WattPerSquareMeterCelsius: return baseUnitValue;
+ case HeatTransferCoefficientUnit.WattPerSquareMeterKelvin: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Illuminance.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Illuminance.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..87cc96ecbd
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Illuminance.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,624 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In photometry, illuminance is the total luminous flux incident on a surface, per unit area.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Illuminance
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Illuminance : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly IlluminanceUnit? _unit;
+
+ static Illuminance()
+ {
+ BaseDimensions = new BaseDimensions(-2, 0, 0, 0, 0, 0, 1);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Lux.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Illuminance()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Illuminance(double numericValue, IlluminanceUnit unit)
+ {
+ if(unit == IlluminanceUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Illuminance, which is Lux. All conversions go via this value.
+ ///
+ public static IlluminanceUnit BaseUnit => IlluminanceUnit.Lux;
+
+ ///
+ /// Represents the largest possible value of Illuminance
+ ///
+ public static Illuminance MaxValue => new Illuminance(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Illuminance
+ ///
+ public static Illuminance MinValue => new Illuminance(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Illuminance;
+
+ ///
+ /// All units of measurement for the Illuminance quantity.
+ ///
+ public static IlluminanceUnit[] Units { get; } = Enum.GetValues(typeof(IlluminanceUnit)).Cast().Except(new IlluminanceUnit[]{ IlluminanceUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Lux.
+ ///
+ public static Illuminance Zero => new Illuminance(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public IlluminanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Illuminance.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Illuminance.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Illuminance in Kilolux.
+ ///
+ public double Kilolux => As(IlluminanceUnit.Kilolux);
+
+ ///
+ /// Get Illuminance in Lux.
+ ///
+ public double Lux => As(IlluminanceUnit.Lux);
+
+ ///
+ /// Get Illuminance in Megalux.
+ ///
+ public double Megalux => As(IlluminanceUnit.Megalux);
+
+ ///
+ /// Get Illuminance in Millilux.
+ ///
+ public double Millilux => As(IlluminanceUnit.Millilux);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(IlluminanceUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(IlluminanceUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Illuminance from Kilolux.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Illuminance FromKilolux(double kilolux)
+ {
+ double value = (double) kilolux;
+ return new Illuminance(value, IlluminanceUnit.Kilolux);
+ }
+ ///
+ /// Get Illuminance from Lux.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Illuminance FromLux(double lux)
+ {
+ double value = (double) lux;
+ return new Illuminance(value, IlluminanceUnit.Lux);
+ }
+ ///
+ /// Get Illuminance from Megalux.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Illuminance FromMegalux(double megalux)
+ {
+ double value = (double) megalux;
+ return new Illuminance(value, IlluminanceUnit.Megalux);
+ }
+ ///
+ /// Get Illuminance from Millilux.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Illuminance FromMillilux(double millilux)
+ {
+ double value = (double) millilux;
+ return new Illuminance(value, IlluminanceUnit.Millilux);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Illuminance unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Illuminance From(double value, IlluminanceUnit fromUnit)
+ {
+ return new Illuminance((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 Illuminance Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Illuminance Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Illuminance result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Illuminance result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static IlluminanceUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static IlluminanceUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out IlluminanceUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out IlluminanceUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Illuminance)) throw new ArgumentException("Expected type Illuminance.", nameof(obj));
+
+ return CompareTo((Illuminance)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Illuminance other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Illuminance within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Illuminance other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Illuminance.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(IlluminanceUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Illuminance to another Illuminance with the unit representation .
+ ///
+ /// A Illuminance with the specified unit.
+ public Illuminance ToUnit(IlluminanceUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Illuminance(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case IlluminanceUnit.Kilolux: return (_value) * 1e3d;
+ case IlluminanceUnit.Lux: return _value;
+ case IlluminanceUnit.Megalux: return (_value) * 1e6d;
+ case IlluminanceUnit.Millilux: return (_value) * 1e-3d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(IlluminanceUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case IlluminanceUnit.Kilolux: return (baseUnitValue) / 1e3d;
+ case IlluminanceUnit.Lux: return baseUnitValue;
+ case IlluminanceUnit.Megalux: return (baseUnitValue) / 1e6d;
+ case IlluminanceUnit.Millilux: return (baseUnitValue) / 1e-3d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Irradiance.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Irradiance.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..87bee65bf0
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Irradiance.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,587 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Irradiance is the intensity of ultraviolet (UV) or visible light incident on a surface.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Irradiance : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly IrradianceUnit? _unit;
+
+ static Irradiance()
+ {
+ BaseDimensions = new BaseDimensions(0, 1, -3, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit WattPerSquareMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Irradiance()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Irradiance(double numericValue, IrradianceUnit unit)
+ {
+ if(unit == IrradianceUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Irradiance, which is WattPerSquareMeter. All conversions go via this value.
+ ///
+ public static IrradianceUnit BaseUnit => IrradianceUnit.WattPerSquareMeter;
+
+ ///
+ /// Represents the largest possible value of Irradiance
+ ///
+ public static Irradiance MaxValue => new Irradiance(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Irradiance
+ ///
+ public static Irradiance MinValue => new Irradiance(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Irradiance;
+
+ ///
+ /// All units of measurement for the Irradiance quantity.
+ ///
+ public static IrradianceUnit[] Units { get; } = Enum.GetValues(typeof(IrradianceUnit)).Cast().Except(new IrradianceUnit[]{ IrradianceUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit WattPerSquareMeter.
+ ///
+ public static Irradiance Zero => new Irradiance(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public IrradianceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Irradiance.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Irradiance.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Irradiance in KilowattsPerSquareMeter.
+ ///
+ public double KilowattsPerSquareMeter => As(IrradianceUnit.KilowattPerSquareMeter);
+
+ ///
+ /// Get Irradiance in WattsPerSquareMeter.
+ ///
+ public double WattsPerSquareMeter => As(IrradianceUnit.WattPerSquareMeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(IrradianceUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(IrradianceUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Irradiance from KilowattsPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Irradiance FromKilowattsPerSquareMeter(double kilowattspersquaremeter)
+ {
+ double value = (double) kilowattspersquaremeter;
+ return new Irradiance(value, IrradianceUnit.KilowattPerSquareMeter);
+ }
+ ///
+ /// Get Irradiance from WattsPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Irradiance FromWattsPerSquareMeter(double wattspersquaremeter)
+ {
+ double value = (double) wattspersquaremeter;
+ return new Irradiance(value, IrradianceUnit.WattPerSquareMeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Irradiance unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Irradiance From(double value, IrradianceUnit fromUnit)
+ {
+ return new Irradiance((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 Irradiance Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Irradiance Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Irradiance result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Irradiance result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static IrradianceUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static IrradianceUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out IrradianceUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out IrradianceUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Irradiance)) throw new ArgumentException("Expected type Irradiance.", nameof(obj));
+
+ return CompareTo((Irradiance)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Irradiance other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Irradiance within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Irradiance other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Irradiance.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(IrradianceUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Irradiance to another Irradiance with the unit representation .
+ ///
+ /// A Irradiance with the specified unit.
+ public Irradiance ToUnit(IrradianceUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Irradiance(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case IrradianceUnit.KilowattPerSquareMeter: return (_value) * 1e3d;
+ case IrradianceUnit.WattPerSquareMeter: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(IrradianceUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case IrradianceUnit.KilowattPerSquareMeter: return (baseUnitValue) / 1e3d;
+ case IrradianceUnit.WattPerSquareMeter: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Irradiation.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Irradiation.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..9478a879a7
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Irradiation.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,607 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Irradiation is the process by which an object is exposed to radiation. The exposure can originate from various sources, including natural sources.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Irradiation
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Irradiation : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly IrradiationUnit? _unit;
+
+ static Irradiation()
+ {
+ BaseDimensions = new BaseDimensions(0, 1, -2, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit JoulePerSquareMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Irradiation()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Irradiation(double numericValue, IrradiationUnit unit)
+ {
+ if(unit == IrradiationUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Irradiation, which is JoulePerSquareMeter. All conversions go via this value.
+ ///
+ public static IrradiationUnit BaseUnit => IrradiationUnit.JoulePerSquareMeter;
+
+ ///
+ /// Represents the largest possible value of Irradiation
+ ///
+ public static Irradiation MaxValue => new Irradiation(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Irradiation
+ ///
+ public static Irradiation MinValue => new Irradiation(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Irradiation;
+
+ ///
+ /// All units of measurement for the Irradiation quantity.
+ ///
+ public static IrradiationUnit[] Units { get; } = Enum.GetValues(typeof(IrradiationUnit)).Cast().Except(new IrradiationUnit[]{ IrradiationUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerSquareMeter.
+ ///
+ public static Irradiation Zero => new Irradiation(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public IrradiationUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Irradiation.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Irradiation.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Irradiation in JoulesPerSquareMeter.
+ ///
+ public double JoulesPerSquareMeter => As(IrradiationUnit.JoulePerSquareMeter);
+
+ ///
+ /// Get Irradiation in KilowattHoursPerSquareMeter.
+ ///
+ public double KilowattHoursPerSquareMeter => As(IrradiationUnit.KilowattHourPerSquareMeter);
+
+ ///
+ /// Get Irradiation in WattHoursPerSquareMeter.
+ ///
+ public double WattHoursPerSquareMeter => As(IrradiationUnit.WattHourPerSquareMeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(IrradiationUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(IrradiationUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Irradiation from JoulesPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Irradiation FromJoulesPerSquareMeter(double joulespersquaremeter)
+ {
+ double value = (double) joulespersquaremeter;
+ return new Irradiation(value, IrradiationUnit.JoulePerSquareMeter);
+ }
+ ///
+ /// Get Irradiation from KilowattHoursPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Irradiation FromKilowattHoursPerSquareMeter(double kilowatthourspersquaremeter)
+ {
+ double value = (double) kilowatthourspersquaremeter;
+ return new Irradiation(value, IrradiationUnit.KilowattHourPerSquareMeter);
+ }
+ ///
+ /// Get Irradiation from WattHoursPerSquareMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Irradiation FromWattHoursPerSquareMeter(double watthourspersquaremeter)
+ {
+ double value = (double) watthourspersquaremeter;
+ return new Irradiation(value, IrradiationUnit.WattHourPerSquareMeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Irradiation unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Irradiation From(double value, IrradiationUnit fromUnit)
+ {
+ return new Irradiation((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 Irradiation Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Irradiation Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Irradiation result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Irradiation result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static IrradiationUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static IrradiationUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out IrradiationUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out IrradiationUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Irradiation)) throw new ArgumentException("Expected type Irradiation.", nameof(obj));
+
+ return CompareTo((Irradiation)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Irradiation other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Irradiation within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Irradiation other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Irradiation.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(IrradiationUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Irradiation to another Irradiation with the unit representation .
+ ///
+ /// A Irradiation with the specified unit.
+ public Irradiation ToUnit(IrradiationUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Irradiation(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case IrradiationUnit.JoulePerSquareMeter: return _value;
+ case IrradiationUnit.KilowattHourPerSquareMeter: return (_value*3600d) * 1e3d;
+ case IrradiationUnit.WattHourPerSquareMeter: return _value*3600d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(IrradiationUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case IrradiationUnit.JoulePerSquareMeter: return baseUnitValue;
+ case IrradiationUnit.KilowattHourPerSquareMeter: return (baseUnitValue/3600d) / 1e3d;
+ case IrradiationUnit.WattHourPerSquareMeter: return baseUnitValue/3600d;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/KinematicViscosity.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/KinematicViscosity.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..cfc7afe804
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/KinematicViscosity.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,692 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The viscosity of a fluid is a measure of its resistance to gradual deformation by shear stress or tensile stress.
+ ///
+ ///
+ /// http://en.wikipedia.org/wiki/Viscosity
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class KinematicViscosity : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly KinematicViscosityUnit? _unit;
+
+ static KinematicViscosity()
+ {
+ BaseDimensions = new BaseDimensions(2, 0, -1, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit SquareMeterPerSecond.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public KinematicViscosity()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private KinematicViscosity(double numericValue, KinematicViscosityUnit unit)
+ {
+ if(unit == KinematicViscosityUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of KinematicViscosity, which is SquareMeterPerSecond. All conversions go via this value.
+ ///
+ public static KinematicViscosityUnit BaseUnit => KinematicViscosityUnit.SquareMeterPerSecond;
+
+ ///
+ /// Represents the largest possible value of KinematicViscosity
+ ///
+ public static KinematicViscosity MaxValue => new KinematicViscosity(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of KinematicViscosity
+ ///
+ public static KinematicViscosity MinValue => new KinematicViscosity(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.KinematicViscosity;
+
+ ///
+ /// All units of measurement for the KinematicViscosity quantity.
+ ///
+ public static KinematicViscosityUnit[] Units { get; } = Enum.GetValues(typeof(KinematicViscosityUnit)).Cast().Except(new KinematicViscosityUnit[]{ KinematicViscosityUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit SquareMeterPerSecond.
+ ///
+ public static KinematicViscosity Zero => new KinematicViscosity(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public KinematicViscosityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => KinematicViscosity.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => KinematicViscosity.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get KinematicViscosity in Centistokes.
+ ///
+ public double Centistokes => As(KinematicViscosityUnit.Centistokes);
+
+ ///
+ /// Get KinematicViscosity in Decistokes.
+ ///
+ public double Decistokes => As(KinematicViscosityUnit.Decistokes);
+
+ ///
+ /// Get KinematicViscosity in Kilostokes.
+ ///
+ public double Kilostokes => As(KinematicViscosityUnit.Kilostokes);
+
+ ///
+ /// Get KinematicViscosity in Microstokes.
+ ///
+ public double Microstokes => As(KinematicViscosityUnit.Microstokes);
+
+ ///
+ /// Get KinematicViscosity in Millistokes.
+ ///
+ public double Millistokes => As(KinematicViscosityUnit.Millistokes);
+
+ ///
+ /// Get KinematicViscosity in Nanostokes.
+ ///
+ public double Nanostokes => As(KinematicViscosityUnit.Nanostokes);
+
+ ///
+ /// Get KinematicViscosity in SquareMetersPerSecond.
+ ///
+ public double SquareMetersPerSecond => As(KinematicViscosityUnit.SquareMeterPerSecond);
+
+ ///
+ /// Get KinematicViscosity in Stokes.
+ ///
+ public double Stokes => As(KinematicViscosityUnit.Stokes);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(KinematicViscosityUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(KinematicViscosityUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get KinematicViscosity from Centistokes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static KinematicViscosity FromCentistokes(double centistokes)
+ {
+ double value = (double) centistokes;
+ return new KinematicViscosity(value, KinematicViscosityUnit.Centistokes);
+ }
+ ///
+ /// Get KinematicViscosity from Decistokes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static KinematicViscosity FromDecistokes(double decistokes)
+ {
+ double value = (double) decistokes;
+ return new KinematicViscosity(value, KinematicViscosityUnit.Decistokes);
+ }
+ ///
+ /// Get KinematicViscosity from Kilostokes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static KinematicViscosity FromKilostokes(double kilostokes)
+ {
+ double value = (double) kilostokes;
+ return new KinematicViscosity(value, KinematicViscosityUnit.Kilostokes);
+ }
+ ///
+ /// Get KinematicViscosity from Microstokes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static KinematicViscosity FromMicrostokes(double microstokes)
+ {
+ double value = (double) microstokes;
+ return new KinematicViscosity(value, KinematicViscosityUnit.Microstokes);
+ }
+ ///
+ /// Get KinematicViscosity from Millistokes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static KinematicViscosity FromMillistokes(double millistokes)
+ {
+ double value = (double) millistokes;
+ return new KinematicViscosity(value, KinematicViscosityUnit.Millistokes);
+ }
+ ///
+ /// Get KinematicViscosity from Nanostokes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static KinematicViscosity FromNanostokes(double nanostokes)
+ {
+ double value = (double) nanostokes;
+ return new KinematicViscosity(value, KinematicViscosityUnit.Nanostokes);
+ }
+ ///
+ /// Get KinematicViscosity from SquareMetersPerSecond.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static KinematicViscosity FromSquareMetersPerSecond(double squaremeterspersecond)
+ {
+ double value = (double) squaremeterspersecond;
+ return new KinematicViscosity(value, KinematicViscosityUnit.SquareMeterPerSecond);
+ }
+ ///
+ /// Get KinematicViscosity from Stokes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static KinematicViscosity FromStokes(double stokes)
+ {
+ double value = (double) stokes;
+ return new KinematicViscosity(value, KinematicViscosityUnit.Stokes);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// KinematicViscosity unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static KinematicViscosity From(double value, KinematicViscosityUnit fromUnit)
+ {
+ return new KinematicViscosity((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static KinematicViscosity Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out KinematicViscosity result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out KinematicViscosity result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static KinematicViscosityUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static KinematicViscosityUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out KinematicViscosityUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out KinematicViscosityUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is KinematicViscosity)) throw new ArgumentException("Expected type KinematicViscosity.", nameof(obj));
+
+ return CompareTo((KinematicViscosity)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(KinematicViscosity other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another KinematicViscosity within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(KinematicViscosity other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current KinematicViscosity.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(KinematicViscosityUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this KinematicViscosity to another KinematicViscosity with the unit representation .
+ ///
+ /// A KinematicViscosity with the specified unit.
+ public KinematicViscosity ToUnit(KinematicViscosityUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new KinematicViscosity(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case KinematicViscosityUnit.Centistokes: return (_value/1e4) * 1e-2d;
+ case KinematicViscosityUnit.Decistokes: return (_value/1e4) * 1e-1d;
+ case KinematicViscosityUnit.Kilostokes: return (_value/1e4) * 1e3d;
+ case KinematicViscosityUnit.Microstokes: return (_value/1e4) * 1e-6d;
+ case KinematicViscosityUnit.Millistokes: return (_value/1e4) * 1e-3d;
+ case KinematicViscosityUnit.Nanostokes: return (_value/1e4) * 1e-9d;
+ case KinematicViscosityUnit.SquareMeterPerSecond: return _value;
+ case KinematicViscosityUnit.Stokes: return _value/1e4;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(KinematicViscosityUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case KinematicViscosityUnit.Centistokes: return (baseUnitValue*1e4) / 1e-2d;
+ case KinematicViscosityUnit.Decistokes: return (baseUnitValue*1e4) / 1e-1d;
+ case KinematicViscosityUnit.Kilostokes: return (baseUnitValue*1e4) / 1e3d;
+ case KinematicViscosityUnit.Microstokes: return (baseUnitValue*1e4) / 1e-6d;
+ case KinematicViscosityUnit.Millistokes: return (baseUnitValue*1e4) / 1e-3d;
+ case KinematicViscosityUnit.Nanostokes: return (baseUnitValue*1e4) / 1e-9d;
+ case KinematicViscosityUnit.SquareMeterPerSecond: return baseUnitValue;
+ case KinematicViscosityUnit.Stokes: return baseUnitValue*1e4;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LapseRate.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LapseRate.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..f622b8d710
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LapseRate.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,570 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// Lapse rate is the rate at which Earth's atmospheric temperature decreases with an increase in altitude, or increases with the decrease in altitude.
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class LapseRate : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly LapseRateUnit? _unit;
+
+ static LapseRate()
+ {
+ BaseDimensions = new BaseDimensions(-1, 0, 0, 0, 1, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit DegreeCelsiusPerKilometer.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public LapseRate()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private LapseRate(double numericValue, LapseRateUnit unit)
+ {
+ if(unit == LapseRateUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of LapseRate, which is DegreeCelsiusPerKilometer. All conversions go via this value.
+ ///
+ public static LapseRateUnit BaseUnit => LapseRateUnit.DegreeCelsiusPerKilometer;
+
+ ///
+ /// Represents the largest possible value of LapseRate
+ ///
+ public static LapseRate MaxValue => new LapseRate(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of LapseRate
+ ///
+ public static LapseRate MinValue => new LapseRate(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.LapseRate;
+
+ ///
+ /// All units of measurement for the LapseRate quantity.
+ ///
+ public static LapseRateUnit[] Units { get; } = Enum.GetValues(typeof(LapseRateUnit)).Cast().Except(new LapseRateUnit[]{ LapseRateUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit DegreeCelsiusPerKilometer.
+ ///
+ public static LapseRate Zero => new LapseRate(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public LapseRateUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => LapseRate.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => LapseRate.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get LapseRate in DegreesCelciusPerKilometer.
+ ///
+ public double DegreesCelciusPerKilometer => As(LapseRateUnit.DegreeCelsiusPerKilometer);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(LapseRateUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(LapseRateUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get LapseRate from DegreesCelciusPerKilometer.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static LapseRate FromDegreesCelciusPerKilometer(double degreescelciusperkilometer)
+ {
+ double value = (double) degreescelciusperkilometer;
+ return new LapseRate(value, LapseRateUnit.DegreeCelsiusPerKilometer);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// LapseRate unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static LapseRate From(double value, LapseRateUnit fromUnit)
+ {
+ return new LapseRate((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 LapseRate Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static LapseRate Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out LapseRate result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out LapseRate result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static LapseRateUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static LapseRateUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out LapseRateUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out LapseRateUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is LapseRate)) throw new ArgumentException("Expected type LapseRate.", nameof(obj));
+
+ return CompareTo((LapseRate)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(LapseRate other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another LapseRate within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(LapseRate other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current LapseRate.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(LapseRateUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this LapseRate to another LapseRate with the unit representation .
+ ///
+ /// A LapseRate with the specified unit.
+ public LapseRate ToUnit(LapseRateUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new LapseRate(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case LapseRateUnit.DegreeCelsiusPerKilometer: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(LapseRateUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case LapseRateUnit.DegreeCelsiusPerKilometer: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LinearDensity.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LinearDensity.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..7cfa3a7f33
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LinearDensity.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,607 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// The Linear Density, or more precisely, the linear mass density, of a substance is its mass per unit length. The term linear density is most often used when describing the characteristics of one-dimensional objects, although linear density can also be used to describe the density of a three-dimensional quantity along one particular dimension.
+ ///
+ ///
+ /// http://en.wikipedia.org/wiki/Linear_density
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class LinearDensity : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly LinearDensityUnit? _unit;
+
+ static LinearDensity()
+ {
+ BaseDimensions = new BaseDimensions(-1, 1, 0, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit KilogramPerMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public LinearDensity()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private LinearDensity(double numericValue, LinearDensityUnit unit)
+ {
+ if(unit == LinearDensityUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of LinearDensity, which is KilogramPerMeter. All conversions go via this value.
+ ///
+ public static LinearDensityUnit BaseUnit => LinearDensityUnit.KilogramPerMeter;
+
+ ///
+ /// Represents the largest possible value of LinearDensity
+ ///
+ public static LinearDensity MaxValue => new LinearDensity(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of LinearDensity
+ ///
+ public static LinearDensity MinValue => new LinearDensity(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.LinearDensity;
+
+ ///
+ /// All units of measurement for the LinearDensity quantity.
+ ///
+ public static LinearDensityUnit[] Units { get; } = Enum.GetValues(typeof(LinearDensityUnit)).Cast().Except(new LinearDensityUnit[]{ LinearDensityUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerMeter.
+ ///
+ public static LinearDensity Zero => new LinearDensity(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public LinearDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => LinearDensity.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => LinearDensity.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get LinearDensity in GramsPerMeter.
+ ///
+ public double GramsPerMeter => As(LinearDensityUnit.GramPerMeter);
+
+ ///
+ /// Get LinearDensity in KilogramsPerMeter.
+ ///
+ public double KilogramsPerMeter => As(LinearDensityUnit.KilogramPerMeter);
+
+ ///
+ /// Get LinearDensity in PoundsPerFoot.
+ ///
+ public double PoundsPerFoot => As(LinearDensityUnit.PoundPerFoot);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(LinearDensityUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(LinearDensityUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get LinearDensity from GramsPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static LinearDensity FromGramsPerMeter(double gramspermeter)
+ {
+ double value = (double) gramspermeter;
+ return new LinearDensity(value, LinearDensityUnit.GramPerMeter);
+ }
+ ///
+ /// Get LinearDensity from KilogramsPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static LinearDensity FromKilogramsPerMeter(double kilogramspermeter)
+ {
+ double value = (double) kilogramspermeter;
+ return new LinearDensity(value, LinearDensityUnit.KilogramPerMeter);
+ }
+ ///
+ /// Get LinearDensity from PoundsPerFoot.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static LinearDensity FromPoundsPerFoot(double poundsperfoot)
+ {
+ double value = (double) poundsperfoot;
+ return new LinearDensity(value, LinearDensityUnit.PoundPerFoot);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// LinearDensity unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static LinearDensity From(double value, LinearDensityUnit fromUnit)
+ {
+ return new LinearDensity((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 LinearDensity Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static LinearDensity Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out LinearDensity result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out LinearDensity result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static LinearDensityUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static LinearDensityUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out LinearDensityUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out LinearDensityUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is LinearDensity)) throw new ArgumentException("Expected type LinearDensity.", nameof(obj));
+
+ return CompareTo((LinearDensity)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(LinearDensity other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another LinearDensity within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(LinearDensity other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current LinearDensity.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(LinearDensityUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this LinearDensity to another LinearDensity with the unit representation .
+ ///
+ /// A LinearDensity with the specified unit.
+ public LinearDensity ToUnit(LinearDensityUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new LinearDensity(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case LinearDensityUnit.GramPerMeter: return _value*1e-3;
+ case LinearDensityUnit.KilogramPerMeter: return (_value*1e-3) * 1e3d;
+ case LinearDensityUnit.PoundPerFoot: return _value*1.48816394;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(LinearDensityUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case LinearDensityUnit.GramPerMeter: return baseUnitValue/1e-3;
+ case LinearDensityUnit.KilogramPerMeter: return (baseUnitValue/1e-3) / 1e3d;
+ case LinearDensityUnit.PoundPerFoot: return baseUnitValue/1.48816394;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LuminousFlux.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LuminousFlux.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..7188f7cd59
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LuminousFlux.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In photometry, luminous flux or luminous power is the measure of the perceived power of light.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Luminous_flux
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class LuminousFlux : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly LuminousFluxUnit? _unit;
+
+ static LuminousFlux()
+ {
+ BaseDimensions = new BaseDimensions(0, 0, 0, 0, 0, 0, 1);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Lumen.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public LuminousFlux()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private LuminousFlux(double numericValue, LuminousFluxUnit unit)
+ {
+ if(unit == LuminousFluxUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of LuminousFlux, which is Lumen. All conversions go via this value.
+ ///
+ public static LuminousFluxUnit BaseUnit => LuminousFluxUnit.Lumen;
+
+ ///
+ /// Represents the largest possible value of LuminousFlux
+ ///
+ public static LuminousFlux MaxValue => new LuminousFlux(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of LuminousFlux
+ ///
+ public static LuminousFlux MinValue => new LuminousFlux(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.LuminousFlux;
+
+ ///
+ /// All units of measurement for the LuminousFlux quantity.
+ ///
+ public static LuminousFluxUnit[] Units { get; } = Enum.GetValues(typeof(LuminousFluxUnit)).Cast().Except(new LuminousFluxUnit[]{ LuminousFluxUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Lumen.
+ ///
+ public static LuminousFlux Zero => new LuminousFlux(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public LuminousFluxUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => LuminousFlux.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => LuminousFlux.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get LuminousFlux in Lumens.
+ ///
+ public double Lumens => As(LuminousFluxUnit.Lumen);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(LuminousFluxUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(LuminousFluxUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get LuminousFlux from Lumens.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static LuminousFlux FromLumens(double lumens)
+ {
+ double value = (double) lumens;
+ return new LuminousFlux(value, LuminousFluxUnit.Lumen);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// LuminousFlux unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static LuminousFlux From(double value, LuminousFluxUnit fromUnit)
+ {
+ return new LuminousFlux((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 LuminousFlux Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static LuminousFlux Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out LuminousFlux result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out LuminousFlux result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static LuminousFluxUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static LuminousFluxUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out LuminousFluxUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out LuminousFluxUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is LuminousFlux)) throw new ArgumentException("Expected type LuminousFlux.", nameof(obj));
+
+ return CompareTo((LuminousFlux)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(LuminousFlux other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another LuminousFlux within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(LuminousFlux other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current LuminousFlux.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(LuminousFluxUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this LuminousFlux to another LuminousFlux with the unit representation .
+ ///
+ /// A LuminousFlux with the specified unit.
+ public LuminousFlux ToUnit(LuminousFluxUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new LuminousFlux(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case LuminousFluxUnit.Lumen: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(LuminousFluxUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case LuminousFluxUnit.Lumen: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LuminousIntensity.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LuminousIntensity.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..0ae059bf84
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LuminousIntensity.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In photometry, luminous intensity is a measure of the wavelength-weighted power emitted by a light source in a particular direction per unit solid angle, based on the luminosity function, a standardized model of the sensitivity of the human eye.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Luminous_intensity
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class LuminousIntensity : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly LuminousIntensityUnit? _unit;
+
+ static LuminousIntensity()
+ {
+ BaseDimensions = new BaseDimensions(0, 0, 0, 0, 0, 0, 1);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Candela.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public LuminousIntensity()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private LuminousIntensity(double numericValue, LuminousIntensityUnit unit)
+ {
+ if(unit == LuminousIntensityUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of LuminousIntensity, which is Candela. All conversions go via this value.
+ ///
+ public static LuminousIntensityUnit BaseUnit => LuminousIntensityUnit.Candela;
+
+ ///
+ /// Represents the largest possible value of LuminousIntensity
+ ///
+ public static LuminousIntensity MaxValue => new LuminousIntensity(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of LuminousIntensity
+ ///
+ public static LuminousIntensity MinValue => new LuminousIntensity(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.LuminousIntensity;
+
+ ///
+ /// All units of measurement for the LuminousIntensity quantity.
+ ///
+ public static LuminousIntensityUnit[] Units { get; } = Enum.GetValues(typeof(LuminousIntensityUnit)).Cast().Except(new LuminousIntensityUnit[]{ LuminousIntensityUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Candela.
+ ///
+ public static LuminousIntensity Zero => new LuminousIntensity(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public LuminousIntensityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => LuminousIntensity.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => LuminousIntensity.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get LuminousIntensity in Candela.
+ ///
+ public double Candela => As(LuminousIntensityUnit.Candela);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(LuminousIntensityUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(LuminousIntensityUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get LuminousIntensity from Candela.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static LuminousIntensity FromCandela(double candela)
+ {
+ double value = (double) candela;
+ return new LuminousIntensity(value, LuminousIntensityUnit.Candela);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// LuminousIntensity unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static LuminousIntensity From(double value, LuminousIntensityUnit fromUnit)
+ {
+ return new LuminousIntensity((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 LuminousIntensity Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static LuminousIntensity Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out LuminousIntensity result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out LuminousIntensity result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static LuminousIntensityUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static LuminousIntensityUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out LuminousIntensityUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out LuminousIntensityUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is LuminousIntensity)) throw new ArgumentException("Expected type LuminousIntensity.", nameof(obj));
+
+ return CompareTo((LuminousIntensity)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(LuminousIntensity other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another LuminousIntensity within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(LuminousIntensity other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current LuminousIntensity.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(LuminousIntensityUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this LuminousIntensity to another LuminousIntensity with the unit representation .
+ ///
+ /// A LuminousIntensity with the specified unit.
+ public LuminousIntensity ToUnit(LuminousIntensityUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new LuminousIntensity(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case LuminousIntensityUnit.Candela: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(LuminousIntensityUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case LuminousIntensityUnit.Candela: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MagneticField.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MagneticField.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..543d738511
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MagneticField.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// A magnetic field is a force field that is created by moving electric charges (electric currents) and magnetic dipoles, and exerts a force on other nearby moving charges and magnetic dipoles.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Magnetic_field
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class MagneticField : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly MagneticFieldUnit? _unit;
+
+ static MagneticField()
+ {
+ BaseDimensions = new BaseDimensions(0, 1, -2, -1, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Tesla.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public MagneticField()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private MagneticField(double numericValue, MagneticFieldUnit unit)
+ {
+ if(unit == MagneticFieldUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of MagneticField, which is Tesla. All conversions go via this value.
+ ///
+ public static MagneticFieldUnit BaseUnit => MagneticFieldUnit.Tesla;
+
+ ///
+ /// Represents the largest possible value of MagneticField
+ ///
+ public static MagneticField MaxValue => new MagneticField(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of MagneticField
+ ///
+ public static MagneticField MinValue => new MagneticField(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.MagneticField;
+
+ ///
+ /// All units of measurement for the MagneticField quantity.
+ ///
+ public static MagneticFieldUnit[] Units { get; } = Enum.GetValues(typeof(MagneticFieldUnit)).Cast().Except(new MagneticFieldUnit[]{ MagneticFieldUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Tesla.
+ ///
+ public static MagneticField Zero => new MagneticField(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public MagneticFieldUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => MagneticField.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => MagneticField.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get MagneticField in Teslas.
+ ///
+ public double Teslas => As(MagneticFieldUnit.Tesla);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(MagneticFieldUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(MagneticFieldUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get MagneticField from Teslas.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static MagneticField FromTeslas(double teslas)
+ {
+ double value = (double) teslas;
+ return new MagneticField(value, MagneticFieldUnit.Tesla);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// MagneticField unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static MagneticField From(double value, MagneticFieldUnit fromUnit)
+ {
+ return new MagneticField((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 MagneticField Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static MagneticField Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out MagneticField result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out MagneticField result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static MagneticFieldUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static MagneticFieldUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out MagneticFieldUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out MagneticFieldUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is MagneticField)) throw new ArgumentException("Expected type MagneticField.", nameof(obj));
+
+ return CompareTo((MagneticField)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(MagneticField other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another MagneticField within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(MagneticField other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current MagneticField.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(MagneticFieldUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this MagneticField to another MagneticField with the unit representation .
+ ///
+ /// A MagneticField with the specified unit.
+ public MagneticField ToUnit(MagneticFieldUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new MagneticField(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case MagneticFieldUnit.Tesla: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(MagneticFieldUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case MagneticFieldUnit.Tesla: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MagneticFlux.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MagneticFlux.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..bc7a0ff539
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MagneticFlux.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In physics, specifically electromagnetism, the magnetic flux through a surface is the surface integral of the normal component of the magnetic field B passing through that surface.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Magnetic_flux
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class MagneticFlux : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly MagneticFluxUnit? _unit;
+
+ static MagneticFlux()
+ {
+ BaseDimensions = new BaseDimensions(2, 1, -2, -1, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Weber.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public MagneticFlux()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private MagneticFlux(double numericValue, MagneticFluxUnit unit)
+ {
+ if(unit == MagneticFluxUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of MagneticFlux, which is Weber. All conversions go via this value.
+ ///
+ public static MagneticFluxUnit BaseUnit => MagneticFluxUnit.Weber;
+
+ ///
+ /// Represents the largest possible value of MagneticFlux
+ ///
+ public static MagneticFlux MaxValue => new MagneticFlux(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of MagneticFlux
+ ///
+ public static MagneticFlux MinValue => new MagneticFlux(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.MagneticFlux;
+
+ ///
+ /// All units of measurement for the MagneticFlux quantity.
+ ///
+ public static MagneticFluxUnit[] Units { get; } = Enum.GetValues(typeof(MagneticFluxUnit)).Cast().Except(new MagneticFluxUnit[]{ MagneticFluxUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Weber.
+ ///
+ public static MagneticFlux Zero => new MagneticFlux(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public MagneticFluxUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => MagneticFlux.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => MagneticFlux.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get MagneticFlux in Webers.
+ ///
+ public double Webers => As(MagneticFluxUnit.Weber);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(MagneticFluxUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(MagneticFluxUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get MagneticFlux from Webers.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static MagneticFlux FromWebers(double webers)
+ {
+ double value = (double) webers;
+ return new MagneticFlux(value, MagneticFluxUnit.Weber);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// MagneticFlux unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static MagneticFlux From(double value, MagneticFluxUnit fromUnit)
+ {
+ return new MagneticFlux((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 MagneticFlux Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static MagneticFlux Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out MagneticFlux result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out MagneticFlux result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static MagneticFluxUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static MagneticFluxUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out MagneticFluxUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out MagneticFluxUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is MagneticFlux)) throw new ArgumentException("Expected type MagneticFlux.", nameof(obj));
+
+ return CompareTo((MagneticFlux)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(MagneticFlux other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another MagneticFlux within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(MagneticFlux other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current MagneticFlux.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(MagneticFluxUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this MagneticFlux to another MagneticFlux with the unit representation .
+ ///
+ /// A MagneticFlux with the specified unit.
+ public MagneticFlux ToUnit(MagneticFluxUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new MagneticFlux(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case MagneticFluxUnit.Weber: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(MagneticFluxUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case MagneticFluxUnit.Weber: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Magnetization.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Magnetization.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..ba3a41139d
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Magnetization.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,573 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In classical electromagnetism, magnetization is the vector field that expresses the density of permanent or induced magnetic dipole moments in a magnetic material.
+ ///
+ ///
+ /// https://en.wikipedia.org/wiki/Magnetization
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Magnetization : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly MagnetizationUnit? _unit;
+
+ static Magnetization()
+ {
+ BaseDimensions = new BaseDimensions(-1, 0, 0, 1, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit AmperePerMeter.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Magnetization()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Magnetization(double numericValue, MagnetizationUnit unit)
+ {
+ if(unit == MagnetizationUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Magnetization, which is AmperePerMeter. All conversions go via this value.
+ ///
+ public static MagnetizationUnit BaseUnit => MagnetizationUnit.AmperePerMeter;
+
+ ///
+ /// Represents the largest possible value of Magnetization
+ ///
+ public static Magnetization MaxValue => new Magnetization(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Magnetization
+ ///
+ public static Magnetization MinValue => new Magnetization(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Magnetization;
+
+ ///
+ /// All units of measurement for the Magnetization quantity.
+ ///
+ public static MagnetizationUnit[] Units { get; } = Enum.GetValues(typeof(MagnetizationUnit)).Cast().Except(new MagnetizationUnit[]{ MagnetizationUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit AmperePerMeter.
+ ///
+ public static Magnetization Zero => new Magnetization(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public MagnetizationUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Magnetization.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Magnetization.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Magnetization in AmperesPerMeter.
+ ///
+ public double AmperesPerMeter => As(MagnetizationUnit.AmperePerMeter);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(MagnetizationUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(MagnetizationUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Magnetization from AmperesPerMeter.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Magnetization FromAmperesPerMeter(double amperespermeter)
+ {
+ double value = (double) amperespermeter;
+ return new Magnetization(value, MagnetizationUnit.AmperePerMeter);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Magnetization unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Magnetization From(double value, MagnetizationUnit fromUnit)
+ {
+ return new Magnetization((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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 Magnetization Parse(string str)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Magnetization Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Magnetization result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Magnetization result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static MagnetizationUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static MagnetizationUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out MagnetizationUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out MagnetizationUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Magnetization)) throw new ArgumentException("Expected type Magnetization.", nameof(obj));
+
+ return CompareTo((Magnetization)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Magnetization other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///
+ ///
+ /// Compare equality to another Magnetization within the given absolute or relative tolerance.
+ ///
+ ///
+ /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a percentage of this quantity's value. will be converted into
+ /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of
+ /// this quantity's value to be considered equal.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Relative);
+ ///
+ ///
+ ///
+ ///
+ /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and
+ /// as a fixed number in this quantity's unit. will be converted into
+ /// this quantity's unit for comparison.
+ ///
+ /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm).
+ ///
+ /// var a = Length.FromMeters(2.0);
+ /// var b = Length.FromInches(50.0);
+ /// a.Equals(b, 0.01, ComparisonType.Absolute);
+ ///
+ ///
+ ///
+ ///
+ /// Note that it is advised against specifying zero difference, due to the nature
+ /// of floating point operations and using System.Double internally.
+ ///
+ ///
+ /// The other quantity to compare to.
+ /// The absolute or relative tolerance value. Must be greater than or equal to 0.
+ /// The comparison type: either relative or absolute.
+ /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance.
+ public bool Equals(Magnetization other, double tolerance, ComparisonType comparisonType)
+ {
+ if(tolerance < 0)
+ throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0.");
+
+ double thisValue = (double)this.Value;
+ double otherValueInThisUnits = other.As(this.Unit);
+
+ return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType);
+ }
+
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A hash code for the current Magnetization.
+ public override int GetHashCode()
+ {
+ return new { QuantityType, Value, Unit }.GetHashCode();
+ }
+
+ #endregion
+
+ #region Conversion Methods
+
+ ///
+ /// Convert to the unit representation .
+ ///
+ /// Value converted to the specified unit.
+ public double As(MagnetizationUnit unit)
+ {
+ if(Unit == unit)
+ return Convert.ToDouble(Value);
+
+ var converted = AsBaseNumericType(unit);
+ return Convert.ToDouble(converted);
+ }
+
+ ///
+ /// Converts this Magnetization to another Magnetization with the unit representation .
+ ///
+ /// A Magnetization with the specified unit.
+ public Magnetization ToUnit(MagnetizationUnit unit)
+ {
+ var convertedValue = AsBaseNumericType(unit);
+ return new Magnetization(convertedValue, unit);
+ }
+
+ ///
+ /// Converts the current value + unit to the base unit.
+ /// This is typically the first step in converting from one unit to another.
+ ///
+ /// The value in the base unit representation.
+ private double AsBaseUnit()
+ {
+ switch(Unit)
+ {
+ case MagnetizationUnit.AmperePerMeter: return _value;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to base units.");
+ }
+ }
+
+ private double AsBaseNumericType(MagnetizationUnit unit)
+ {
+ if(Unit == unit)
+ return _value;
+
+ var baseUnitValue = AsBaseUnit();
+
+ switch(unit)
+ {
+ case MagnetizationUnit.AmperePerMeter: return baseUnitValue;
+ default:
+ throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
+ }
+ }
+
+ #endregion
+
+ #region ToString Methods
+
+ ///
+ /// Get default string representation of value and unit.
+ ///
+ /// String representation.
+ public override string ToString()
+ {
+ return ToString(null);
+ }
+
+ ///
+ /// Get string representation of value and unit. Using two significant digits after radix.
+ ///
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName)
+ {
+ var provider = cultureName;
+ return ToString(provider, 2);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// The number of significant digits after the radix point.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString(string cultureName, int significantDigitsAfterRadix)
+ {
+ var provider = cultureName;
+ var value = Convert.ToDouble(Value);
+ var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix);
+ return ToString(provider, format);
+ }
+
+ ///
+ /// Get string representation of value and unit.
+ ///
+ /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively."
+ /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1.
+ /// String representation.
+ /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null.
+ public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args)
+ {
+ var provider = GetFormatProviderFromCultureName(cultureName);
+ if (format == null) throw new ArgumentNullException(nameof(format));
+ if (args == null) throw new ArgumentNullException(nameof(args));
+
+ provider = provider ?? GlobalConfiguration.DefaultCulture;
+
+ var value = Convert.ToDouble(Value);
+ var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args);
+ return string.Format(provider, format, formatArgs);
+ }
+
+ #endregion
+
+ private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName)
+ {
+ return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null;
+ }
+ }
+}
diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Mass.WindowsRuntimeComponent.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Mass.WindowsRuntimeComponent.g.cs
new file mode 100644
index 0000000000..30fb8adb4f
--- /dev/null
+++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Mass.WindowsRuntimeComponent.g.cs
@@ -0,0 +1,927 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by \generate-code.bat.
+//
+// Changes to this file will be lost when the code is regenerated.
+// The build server regenerates the code before each build and a pre-build
+// step will regenerate the code on each local build.
+//
+// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units.
+//
+// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities.
+// Add UnitDefinitions\MyQuantity.json and run GeneratUnits.bat to generate new units or quantities.
+//
+//
+//------------------------------------------------------------------------------
+
+// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).
+// https://github.com/angularsen/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 System.Globalization;
+using System.Linq;
+using JetBrains.Annotations;
+using UnitsNet.Units;
+using UnitsNet.InternalHelpers;
+
+// ReSharper disable once CheckNamespace
+
+namespace UnitsNet
+{
+ ///
+ /// In physics, mass (from Greek μᾶζα "barley cake, lump [of dough]") is a property of a physical system or body, giving rise to the phenomena of the body's resistance to being accelerated by a force and the strength of its mutual gravitational attraction with other bodies. Instruments such as mass balances or scales use those phenomena to measure mass. The SI unit of mass is the kilogram (kg).
+ ///
+ // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components
+ // Public structures can't have any members other than public fields, and those fields must be value types or strings.
+ // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic.
+ public sealed partial class Mass : IQuantity
+ {
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ private readonly double _value;
+
+ ///
+ /// The unit this quantity was constructed with.
+ ///
+ private readonly MassUnit? _unit;
+
+ static Mass()
+ {
+ BaseDimensions = new BaseDimensions(0, 1, 0, 0, 0, 0, 0);
+ }
+ ///
+ /// Creates the quantity with a value of 0 in the base unit Kilogram.
+ ///
+ ///
+ /// Windows Runtime Component requires a default constructor.
+ ///
+ public Mass()
+ {
+ _value = 0;
+ _unit = BaseUnit;
+ }
+
+ ///
+ /// Creates the quantity with the given numeric value and unit.
+ ///
+ /// The numeric value to contruct this quantity with.
+ /// The unit representation to contruct this quantity with.
+ /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.
+ /// If value is NaN or Infinity.
+ private Mass(double numericValue, MassUnit unit)
+ {
+ if(unit == MassUnit.Undefined)
+ throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
+
+ _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue));
+ _unit = unit;
+ }
+
+ #region Static Properties
+
+ ///
+ /// The of this quantity.
+ ///
+ public static BaseDimensions BaseDimensions { get; }
+
+ ///
+ /// The base unit of Mass, which is Kilogram. All conversions go via this value.
+ ///
+ public static MassUnit BaseUnit => MassUnit.Kilogram;
+
+ ///
+ /// Represents the largest possible value of Mass
+ ///
+ public static Mass MaxValue => new Mass(double.MaxValue, BaseUnit);
+
+ ///
+ /// Represents the smallest possible value of Mass
+ ///
+ public static Mass MinValue => new Mass(double.MinValue, BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public static QuantityType QuantityType => QuantityType.Mass;
+
+ ///
+ /// All units of measurement for the Mass quantity.
+ ///
+ public static MassUnit[] Units { get; } = Enum.GetValues(typeof(MassUnit)).Cast().Except(new MassUnit[]{ MassUnit.Undefined }).ToArray();
+
+ ///
+ /// Gets an instance of this quantity with a value of 0 in the base unit Kilogram.
+ ///
+ public static Mass Zero => new Mass(0, BaseUnit);
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// The numeric value this quantity was constructed with.
+ ///
+ public double Value => Convert.ToDouble(_value);
+
+ ///
+ /// The unit this quantity was constructed with -or- if default ctor was used.
+ ///
+ public MassUnit Unit => _unit.GetValueOrDefault(BaseUnit);
+
+ ///
+ /// The of this quantity.
+ ///
+ public QuantityType Type => Mass.QuantityType;
+
+ ///
+ /// The of this quantity.
+ ///
+ public BaseDimensions Dimensions => Mass.BaseDimensions;
+
+ #endregion
+
+ #region Conversion Properties
+
+ ///
+ /// Get Mass in Centigrams.
+ ///
+ public double Centigrams => As(MassUnit.Centigram);
+
+ ///
+ /// Get Mass in Decagrams.
+ ///
+ public double Decagrams => As(MassUnit.Decagram);
+
+ ///
+ /// Get Mass in Decigrams.
+ ///
+ public double Decigrams => As(MassUnit.Decigram);
+
+ ///
+ /// Get Mass in Grams.
+ ///
+ public double Grams => As(MassUnit.Gram);
+
+ ///
+ /// Get Mass in Hectograms.
+ ///
+ public double Hectograms => As(MassUnit.Hectogram);
+
+ ///
+ /// Get Mass in Kilograms.
+ ///
+ public double Kilograms => As(MassUnit.Kilogram);
+
+ ///
+ /// Get Mass in Kilopounds.
+ ///
+ public double Kilopounds => As(MassUnit.Kilopound);
+
+ ///
+ /// Get Mass in Kilotonnes.
+ ///
+ public double Kilotonnes => As(MassUnit.Kilotonne);
+
+ ///
+ /// Get Mass in LongHundredweight.
+ ///
+ public double LongHundredweight => As(MassUnit.LongHundredweight);
+
+ ///
+ /// Get Mass in LongTons.
+ ///
+ public double LongTons => As(MassUnit.LongTon);
+
+ ///
+ /// Get Mass in Megapounds.
+ ///
+ public double Megapounds => As(MassUnit.Megapound);
+
+ ///
+ /// Get Mass in Megatonnes.
+ ///
+ public double Megatonnes => As(MassUnit.Megatonne);
+
+ ///
+ /// Get Mass in Micrograms.
+ ///
+ public double Micrograms => As(MassUnit.Microgram);
+
+ ///
+ /// Get Mass in Milligrams.
+ ///
+ public double Milligrams => As(MassUnit.Milligram);
+
+ ///
+ /// Get Mass in Nanograms.
+ ///
+ public double Nanograms => As(MassUnit.Nanogram);
+
+ ///
+ /// Get Mass in Ounces.
+ ///
+ public double Ounces => As(MassUnit.Ounce);
+
+ ///
+ /// Get Mass in Pounds.
+ ///
+ public double Pounds => As(MassUnit.Pound);
+
+ ///
+ /// Get Mass in ShortHundredweight.
+ ///
+ public double ShortHundredweight => As(MassUnit.ShortHundredweight);
+
+ ///
+ /// Get Mass in ShortTons.
+ ///
+ public double ShortTons => As(MassUnit.ShortTon);
+
+ ///
+ /// Get Mass in Slugs.
+ ///
+ public double Slugs => As(MassUnit.Slug);
+
+ ///
+ /// Get Mass in Stone.
+ ///
+ public double Stone => As(MassUnit.Stone);
+
+ ///
+ /// Get Mass in Tonnes.
+ ///
+ public double Tonnes => As(MassUnit.Tonne);
+
+ #endregion
+
+ #region Static Methods
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ public static string GetAbbreviation(MassUnit unit)
+ {
+ return GetAbbreviation(unit, null);
+ }
+
+ ///
+ /// Get unit abbreviation string.
+ ///
+ /// Unit to get abbreviation for.
+ /// Unit abbreviation string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static string GetAbbreviation(MassUnit unit, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider);
+ }
+
+ #endregion
+
+ #region Static Factory Methods
+
+ ///
+ /// Get Mass from Centigrams.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromCentigrams(double centigrams)
+ {
+ double value = (double) centigrams;
+ return new Mass(value, MassUnit.Centigram);
+ }
+ ///
+ /// Get Mass from Decagrams.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromDecagrams(double decagrams)
+ {
+ double value = (double) decagrams;
+ return new Mass(value, MassUnit.Decagram);
+ }
+ ///
+ /// Get Mass from Decigrams.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromDecigrams(double decigrams)
+ {
+ double value = (double) decigrams;
+ return new Mass(value, MassUnit.Decigram);
+ }
+ ///
+ /// Get Mass from Grams.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromGrams(double grams)
+ {
+ double value = (double) grams;
+ return new Mass(value, MassUnit.Gram);
+ }
+ ///
+ /// Get Mass from Hectograms.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromHectograms(double hectograms)
+ {
+ double value = (double) hectograms;
+ return new Mass(value, MassUnit.Hectogram);
+ }
+ ///
+ /// Get Mass from Kilograms.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromKilograms(double kilograms)
+ {
+ double value = (double) kilograms;
+ return new Mass(value, MassUnit.Kilogram);
+ }
+ ///
+ /// Get Mass from Kilopounds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromKilopounds(double kilopounds)
+ {
+ double value = (double) kilopounds;
+ return new Mass(value, MassUnit.Kilopound);
+ }
+ ///
+ /// Get Mass from Kilotonnes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromKilotonnes(double kilotonnes)
+ {
+ double value = (double) kilotonnes;
+ return new Mass(value, MassUnit.Kilotonne);
+ }
+ ///
+ /// Get Mass from LongHundredweight.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromLongHundredweight(double longhundredweight)
+ {
+ double value = (double) longhundredweight;
+ return new Mass(value, MassUnit.LongHundredweight);
+ }
+ ///
+ /// Get Mass from LongTons.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromLongTons(double longtons)
+ {
+ double value = (double) longtons;
+ return new Mass(value, MassUnit.LongTon);
+ }
+ ///
+ /// Get Mass from Megapounds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromMegapounds(double megapounds)
+ {
+ double value = (double) megapounds;
+ return new Mass(value, MassUnit.Megapound);
+ }
+ ///
+ /// Get Mass from Megatonnes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromMegatonnes(double megatonnes)
+ {
+ double value = (double) megatonnes;
+ return new Mass(value, MassUnit.Megatonne);
+ }
+ ///
+ /// Get Mass from Micrograms.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromMicrograms(double micrograms)
+ {
+ double value = (double) micrograms;
+ return new Mass(value, MassUnit.Microgram);
+ }
+ ///
+ /// Get Mass from Milligrams.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromMilligrams(double milligrams)
+ {
+ double value = (double) milligrams;
+ return new Mass(value, MassUnit.Milligram);
+ }
+ ///
+ /// Get Mass from Nanograms.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromNanograms(double nanograms)
+ {
+ double value = (double) nanograms;
+ return new Mass(value, MassUnit.Nanogram);
+ }
+ ///
+ /// Get Mass from Ounces.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromOunces(double ounces)
+ {
+ double value = (double) ounces;
+ return new Mass(value, MassUnit.Ounce);
+ }
+ ///
+ /// Get Mass from Pounds.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromPounds(double pounds)
+ {
+ double value = (double) pounds;
+ return new Mass(value, MassUnit.Pound);
+ }
+ ///
+ /// Get Mass from ShortHundredweight.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromShortHundredweight(double shorthundredweight)
+ {
+ double value = (double) shorthundredweight;
+ return new Mass(value, MassUnit.ShortHundredweight);
+ }
+ ///
+ /// Get Mass from ShortTons.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromShortTons(double shorttons)
+ {
+ double value = (double) shorttons;
+ return new Mass(value, MassUnit.ShortTon);
+ }
+ ///
+ /// Get Mass from Slugs.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromSlugs(double slugs)
+ {
+ double value = (double) slugs;
+ return new Mass(value, MassUnit.Slug);
+ }
+ ///
+ /// Get Mass from Stone.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromStone(double stone)
+ {
+ double value = (double) stone;
+ return new Mass(value, MassUnit.Stone);
+ }
+ ///
+ /// Get Mass from Tonnes.
+ ///
+ /// If value is NaN or Infinity.
+ [Windows.Foundation.Metadata.DefaultOverload]
+ public static Mass FromTonnes(double tonnes)
+ {
+ double value = (double) tonnes;
+ return new Mass(value, MassUnit.Tonne);
+ }
+
+ ///
+ /// Dynamically convert from value and unit enum to .
+ ///
+ /// Value to convert from.
+ /// Unit to convert from.
+ /// Mass unit value.
+ // Fix name conflict with parameter "value"
+ [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
+ public static Mass From(double value, MassUnit fromUnit)
+ {
+ return new Mass((double)value, fromUnit);
+ }
+
+ #endregion
+
+ #region Static Parse Methods
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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)
+ {
+ return Parse(str, null);
+ }
+
+ ///
+ /// Parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ ///
+ /// Expected string to have one or two pairs of quantity and unit in the format
+ /// "<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 .
+ ///
+ ///
+ /// 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.
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static Mass Parse(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.Parse(
+ str,
+ provider,
+ From);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ public static bool TryParse([CanBeNull] string str, out Mass result)
+ {
+ return TryParse(str, null, out result);
+ }
+
+ ///
+ /// Try to parse a string with one or two quantities of the format "<quantity> <unit>".
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// Resulting unit quantity if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.Parse("5.5 m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Mass result)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return QuantityParser.Default.TryParse(
+ str,
+ provider,
+ From,
+ out result);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ public static MassUnit ParseUnit(string str)
+ {
+ return ParseUnit(str, null);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ ///
+ /// Length.ParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// The value of 'str' cannot be null.
+ /// Error parsing string.
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static MassUnit ParseUnit(string str, [CanBeNull] string cultureName)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.Parse(str, provider);
+ }
+
+ public static bool TryParseUnit(string str, out MassUnit unit)
+ {
+ return TryParseUnit(str, null, out unit);
+ }
+
+ ///
+ /// Parse a unit string.
+ ///
+ /// String to parse. Typically in the form: {number} {unit}
+ /// The parsed unit if successful.
+ /// True if successful, otherwise false.
+ ///
+ /// Length.TryParseUnit("m", new CultureInfo("en-US"));
+ ///
+ /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null.
+ public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out MassUnit unit)
+ {
+ IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);
+ return UnitParser.Default.TryParse(str, provider, out unit);
+ }
+
+ #endregion
+
+ #region Equality / IComparable
+
+ public int CompareTo(object obj)
+ {
+ if(obj is null) throw new ArgumentNullException(nameof(obj));
+ if(!(obj is Mass)) throw new ArgumentException("Expected type Mass.", nameof(obj));
+
+ return CompareTo((Mass)obj);
+ }
+
+ // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods
+ internal int CompareTo(Mass other)
+ {
+ return _value.CompareTo(other.AsBaseNumericType(this.Unit));
+ }
+
+ ///