diff --git a/Common/GeneratedCode/Quantities/Acceleration.Common.g.cs b/Common/GeneratedCode/Quantities/Acceleration.Common.g.cs
deleted file mode 100644
index 6d0a2a93e2..0000000000
--- a/Common/GeneratedCode/Quantities/Acceleration.Common.g.cs
+++ /dev/null
@@ -1,801 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Acceleration : IQuantity
-#else
- public partial struct Acceleration : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly AccelerationUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public AccelerationUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Acceleration()
- {
- BaseDimensions = new BaseDimensions(1, 0, -2, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Acceleration;
-
- ///
- /// The base unit of Acceleration, which is MeterPerSecondSquared. All conversions go via this value.
- ///
- public static AccelerationUnit BaseUnit => AccelerationUnit.MeterPerSecondSquared;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Acceleration quantity.
- ///
- public static AccelerationUnit[] Units { get; } = Enum.GetValues(typeof(AccelerationUnit)).Cast().Except(new AccelerationUnit[]{ AccelerationUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit MeterPerSecondSquared.
- ///
- public static Acceleration Zero => new Acceleration(0, BaseUnit);
-
- ///
- /// Get Acceleration from CentimetersPerSecondSquared.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromCentimetersPerSecondSquared(double centimeterspersecondsquared)
-#else
- public static Acceleration FromCentimetersPerSecondSquared(QuantityValue centimeterspersecondsquared)
-#endif
- {
- double value = (double) centimeterspersecondsquared;
- return new Acceleration(value, AccelerationUnit.CentimeterPerSecondSquared);
- }
-
- ///
- /// Get Acceleration from DecimetersPerSecondSquared.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromDecimetersPerSecondSquared(double decimeterspersecondsquared)
-#else
- public static Acceleration FromDecimetersPerSecondSquared(QuantityValue decimeterspersecondsquared)
-#endif
- {
- double value = (double) decimeterspersecondsquared;
- return new Acceleration(value, AccelerationUnit.DecimeterPerSecondSquared);
- }
-
- ///
- /// Get Acceleration from FeetPerSecondSquared.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromFeetPerSecondSquared(double feetpersecondsquared)
-#else
- public static Acceleration FromFeetPerSecondSquared(QuantityValue feetpersecondsquared)
-#endif
- {
- double value = (double) feetpersecondsquared;
- return new Acceleration(value, AccelerationUnit.FootPerSecondSquared);
- }
-
- ///
- /// Get Acceleration from InchesPerSecondSquared.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromInchesPerSecondSquared(double inchespersecondsquared)
-#else
- public static Acceleration FromInchesPerSecondSquared(QuantityValue inchespersecondsquared)
-#endif
- {
- double value = (double) inchespersecondsquared;
- return new Acceleration(value, AccelerationUnit.InchPerSecondSquared);
- }
-
- ///
- /// Get Acceleration from KilometersPerSecondSquared.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromKilometersPerSecondSquared(double kilometerspersecondsquared)
-#else
- public static Acceleration FromKilometersPerSecondSquared(QuantityValue kilometerspersecondsquared)
-#endif
- {
- double value = (double) kilometerspersecondsquared;
- return new Acceleration(value, AccelerationUnit.KilometerPerSecondSquared);
- }
-
- ///
- /// Get Acceleration from KnotsPerHour.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromKnotsPerHour(double knotsperhour)
-#else
- public static Acceleration FromKnotsPerHour(QuantityValue knotsperhour)
-#endif
- {
- double value = (double) knotsperhour;
- return new Acceleration(value, AccelerationUnit.KnotPerHour);
- }
-
- ///
- /// Get Acceleration from KnotsPerMinute.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromKnotsPerMinute(double knotsperminute)
-#else
- public static Acceleration FromKnotsPerMinute(QuantityValue knotsperminute)
-#endif
- {
- double value = (double) knotsperminute;
- return new Acceleration(value, AccelerationUnit.KnotPerMinute);
- }
-
- ///
- /// Get Acceleration from KnotsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromKnotsPerSecond(double knotspersecond)
-#else
- public static Acceleration FromKnotsPerSecond(QuantityValue knotspersecond)
-#endif
- {
- double value = (double) knotspersecond;
- return new Acceleration(value, AccelerationUnit.KnotPerSecond);
- }
-
- ///
- /// Get Acceleration from MetersPerSecondSquared.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromMetersPerSecondSquared(double meterspersecondsquared)
-#else
- public static Acceleration FromMetersPerSecondSquared(QuantityValue meterspersecondsquared)
-#endif
- {
- double value = (double) meterspersecondsquared;
- return new Acceleration(value, AccelerationUnit.MeterPerSecondSquared);
- }
-
- ///
- /// Get Acceleration from MicrometersPerSecondSquared.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromMicrometersPerSecondSquared(double micrometerspersecondsquared)
-#else
- public static Acceleration FromMicrometersPerSecondSquared(QuantityValue micrometerspersecondsquared)
-#endif
- {
- double value = (double) micrometerspersecondsquared;
- return new Acceleration(value, AccelerationUnit.MicrometerPerSecondSquared);
- }
-
- ///
- /// Get Acceleration from MillimetersPerSecondSquared.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromMillimetersPerSecondSquared(double millimeterspersecondsquared)
-#else
- public static Acceleration FromMillimetersPerSecondSquared(QuantityValue millimeterspersecondsquared)
-#endif
- {
- double value = (double) millimeterspersecondsquared;
- return new Acceleration(value, AccelerationUnit.MillimeterPerSecondSquared);
- }
-
- ///
- /// Get Acceleration from NanometersPerSecondSquared.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromNanometersPerSecondSquared(double nanometerspersecondsquared)
-#else
- public static Acceleration FromNanometersPerSecondSquared(QuantityValue nanometerspersecondsquared)
-#endif
- {
- double value = (double) nanometerspersecondsquared;
- return new Acceleration(value, AccelerationUnit.NanometerPerSecondSquared);
- }
-
- ///
- /// Get Acceleration from StandardGravity.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Acceleration FromStandardGravity(double standardgravity)
-#else
- public static Acceleration FromStandardGravity(QuantityValue standardgravity)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Acceleration From(double value, AccelerationUnit fromUnit)
-#else
- public static Acceleration From(QuantityValue value, AccelerationUnit fromUnit)
-#endif
- {
- return new Acceleration((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(AccelerationUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out AccelerationUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Acceleration ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Acceleration result)
- {
- result = default(Acceleration);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static AccelerationUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == AccelerationUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized AccelerationUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out AccelerationUnit unit)
- {
- unit = AccelerationUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == AccelerationUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(AccelerationUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Acceleration.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Acceleration.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/AmountOfSubstance.Common.g.cs b/Common/GeneratedCode/Quantities/AmountOfSubstance.Common.g.cs
deleted file mode 100644
index 9c4fb9a21c..0000000000
--- a/Common/GeneratedCode/Quantities/AmountOfSubstance.Common.g.cs
+++ /dev/null
@@ -1,823 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class AmountOfSubstance : IQuantity
-#else
- public partial struct AmountOfSubstance : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly AmountOfSubstanceUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public AmountOfSubstanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static AmountOfSubstance()
- {
- BaseDimensions = new BaseDimensions(0, 0, 0, 0, 0, 1, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.AmountOfSubstance;
-
- ///
- /// The base unit of AmountOfSubstance, which is Mole. All conversions go via this value.
- ///
- public static AmountOfSubstanceUnit BaseUnit => AmountOfSubstanceUnit.Mole;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the AmountOfSubstance quantity.
- ///
- public static AmountOfSubstanceUnit[] Units { get; } = Enum.GetValues(typeof(AmountOfSubstanceUnit)).Cast().Except(new AmountOfSubstanceUnit[]{ AmountOfSubstanceUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Mole.
- ///
- public static AmountOfSubstance Zero => new AmountOfSubstance(0, BaseUnit);
-
- ///
- /// Get AmountOfSubstance from Centimoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromCentimoles(double centimoles)
-#else
- public static AmountOfSubstance FromCentimoles(QuantityValue centimoles)
-#endif
- {
- double value = (double) centimoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.Centimole);
- }
-
- ///
- /// Get AmountOfSubstance from CentipoundMoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromCentipoundMoles(double centipoundmoles)
-#else
- public static AmountOfSubstance FromCentipoundMoles(QuantityValue centipoundmoles)
-#endif
- {
- double value = (double) centipoundmoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.CentipoundMole);
- }
-
- ///
- /// Get AmountOfSubstance from Decimoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromDecimoles(double decimoles)
-#else
- public static AmountOfSubstance FromDecimoles(QuantityValue decimoles)
-#endif
- {
- double value = (double) decimoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.Decimole);
- }
-
- ///
- /// Get AmountOfSubstance from DecipoundMoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromDecipoundMoles(double decipoundmoles)
-#else
- public static AmountOfSubstance FromDecipoundMoles(QuantityValue decipoundmoles)
-#endif
- {
- double value = (double) decipoundmoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.DecipoundMole);
- }
-
- ///
- /// Get AmountOfSubstance from Kilomoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromKilomoles(double kilomoles)
-#else
- public static AmountOfSubstance FromKilomoles(QuantityValue kilomoles)
-#endif
- {
- double value = (double) kilomoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.Kilomole);
- }
-
- ///
- /// Get AmountOfSubstance from KilopoundMoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromKilopoundMoles(double kilopoundmoles)
-#else
- public static AmountOfSubstance FromKilopoundMoles(QuantityValue kilopoundmoles)
-#endif
- {
- double value = (double) kilopoundmoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.KilopoundMole);
- }
-
- ///
- /// Get AmountOfSubstance from Micromoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromMicromoles(double micromoles)
-#else
- public static AmountOfSubstance FromMicromoles(QuantityValue micromoles)
-#endif
- {
- double value = (double) micromoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.Micromole);
- }
-
- ///
- /// Get AmountOfSubstance from MicropoundMoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromMicropoundMoles(double micropoundmoles)
-#else
- public static AmountOfSubstance FromMicropoundMoles(QuantityValue micropoundmoles)
-#endif
- {
- double value = (double) micropoundmoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.MicropoundMole);
- }
-
- ///
- /// Get AmountOfSubstance from Millimoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromMillimoles(double millimoles)
-#else
- public static AmountOfSubstance FromMillimoles(QuantityValue millimoles)
-#endif
- {
- double value = (double) millimoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.Millimole);
- }
-
- ///
- /// Get AmountOfSubstance from MillipoundMoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromMillipoundMoles(double millipoundmoles)
-#else
- public static AmountOfSubstance FromMillipoundMoles(QuantityValue millipoundmoles)
-#endif
- {
- double value = (double) millipoundmoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.MillipoundMole);
- }
-
- ///
- /// Get AmountOfSubstance from Moles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromMoles(double moles)
-#else
- public static AmountOfSubstance FromMoles(QuantityValue moles)
-#endif
- {
- double value = (double) moles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.Mole);
- }
-
- ///
- /// Get AmountOfSubstance from Nanomoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromNanomoles(double nanomoles)
-#else
- public static AmountOfSubstance FromNanomoles(QuantityValue nanomoles)
-#endif
- {
- double value = (double) nanomoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.Nanomole);
- }
-
- ///
- /// Get AmountOfSubstance from NanopoundMoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromNanopoundMoles(double nanopoundmoles)
-#else
- public static AmountOfSubstance FromNanopoundMoles(QuantityValue nanopoundmoles)
-#endif
- {
- double value = (double) nanopoundmoles;
- return new AmountOfSubstance(value, AmountOfSubstanceUnit.NanopoundMole);
- }
-
- ///
- /// Get AmountOfSubstance from PoundMoles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmountOfSubstance FromPoundMoles(double poundmoles)
-#else
- public static AmountOfSubstance FromPoundMoles(QuantityValue poundmoles)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static AmountOfSubstance From(double value, AmountOfSubstanceUnit fromUnit)
-#else
- public static AmountOfSubstance From(QuantityValue value, AmountOfSubstanceUnit fromUnit)
-#endif
- {
- return new AmountOfSubstance((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(AmountOfSubstanceUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out AmountOfSubstanceUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static AmountOfSubstance ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out AmountOfSubstance result)
- {
- result = default(AmountOfSubstance);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static AmountOfSubstanceUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == AmountOfSubstanceUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized AmountOfSubstanceUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out AmountOfSubstanceUnit unit)
- {
- unit = AmountOfSubstanceUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == AmountOfSubstanceUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(AmountOfSubstanceUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => AmountOfSubstance.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => AmountOfSubstance.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/AmplitudeRatio.Common.g.cs b/Common/GeneratedCode/Quantities/AmplitudeRatio.Common.g.cs
deleted file mode 100644
index c1fe46ff67..0000000000
--- a/Common/GeneratedCode/Quantities/AmplitudeRatio.Common.g.cs
+++ /dev/null
@@ -1,602 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// The strength of a signal expressed in decibels (dB) relative to one volt RMS.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class AmplitudeRatio : IQuantity
-#else
- public partial struct AmplitudeRatio : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly AmplitudeRatioUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public AmplitudeRatioUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static AmplitudeRatio()
- {
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.AmplitudeRatio;
-
- ///
- /// The base unit of AmplitudeRatio, which is DecibelVolt. All conversions go via this value.
- ///
- public static AmplitudeRatioUnit BaseUnit => AmplitudeRatioUnit.DecibelVolt;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the AmplitudeRatio quantity.
- ///
- public static AmplitudeRatioUnit[] Units { get; } = Enum.GetValues(typeof(AmplitudeRatioUnit)).Cast().Except(new AmplitudeRatioUnit[]{ AmplitudeRatioUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit DecibelVolt.
- ///
- public static AmplitudeRatio Zero => new AmplitudeRatio(0, BaseUnit);
-
- ///
- /// Get AmplitudeRatio from DecibelMicrovolts.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmplitudeRatio FromDecibelMicrovolts(double decibelmicrovolts)
-#else
- public static AmplitudeRatio FromDecibelMicrovolts(QuantityValue decibelmicrovolts)
-#endif
- {
- double value = (double) decibelmicrovolts;
- return new AmplitudeRatio(value, AmplitudeRatioUnit.DecibelMicrovolt);
- }
-
- ///
- /// Get AmplitudeRatio from DecibelMillivolts.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmplitudeRatio FromDecibelMillivolts(double decibelmillivolts)
-#else
- public static AmplitudeRatio FromDecibelMillivolts(QuantityValue decibelmillivolts)
-#endif
- {
- double value = (double) decibelmillivolts;
- return new AmplitudeRatio(value, AmplitudeRatioUnit.DecibelMillivolt);
- }
-
- ///
- /// Get AmplitudeRatio from DecibelsUnloaded.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmplitudeRatio FromDecibelsUnloaded(double decibelsunloaded)
-#else
- public static AmplitudeRatio FromDecibelsUnloaded(QuantityValue decibelsunloaded)
-#endif
- {
- double value = (double) decibelsunloaded;
- return new AmplitudeRatio(value, AmplitudeRatioUnit.DecibelUnloaded);
- }
-
- ///
- /// Get AmplitudeRatio from DecibelVolts.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AmplitudeRatio FromDecibelVolts(double decibelvolts)
-#else
- public static AmplitudeRatio FromDecibelVolts(QuantityValue decibelvolts)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static AmplitudeRatio From(double value, AmplitudeRatioUnit fromUnit)
-#else
- public static AmplitudeRatio From(QuantityValue value, AmplitudeRatioUnit fromUnit)
-#endif
- {
- return new AmplitudeRatio((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(AmplitudeRatioUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out AmplitudeRatioUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static AmplitudeRatio ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out AmplitudeRatio result)
- {
- result = default(AmplitudeRatio);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static AmplitudeRatioUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == AmplitudeRatioUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized AmplitudeRatioUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out AmplitudeRatioUnit unit)
- {
- unit = AmplitudeRatioUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == AmplitudeRatioUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(AmplitudeRatioUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => AmplitudeRatio.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => AmplitudeRatio.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Angle.Common.g.cs b/Common/GeneratedCode/Quantities/Angle.Common.g.cs
deleted file mode 100644
index 83cdf163dd..0000000000
--- a/Common/GeneratedCode/Quantities/Angle.Common.g.cs
+++ /dev/null
@@ -1,822 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Angle : IQuantity
-#else
- public partial struct Angle : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly AngleUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public AngleUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Angle()
- {
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Angle;
-
- ///
- /// The base unit of Angle, which is Degree. All conversions go via this value.
- ///
- public static AngleUnit BaseUnit => AngleUnit.Degree;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Angle quantity.
- ///
- public static AngleUnit[] Units { get; } = Enum.GetValues(typeof(AngleUnit)).Cast().Except(new AngleUnit[]{ AngleUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Degree.
- ///
- public static Angle Zero => new Angle(0, BaseUnit);
-
- ///
- /// Get Angle from Arcminutes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromArcminutes(double arcminutes)
-#else
- public static Angle FromArcminutes(QuantityValue arcminutes)
-#endif
- {
- double value = (double) arcminutes;
- return new Angle(value, AngleUnit.Arcminute);
- }
-
- ///
- /// Get Angle from Arcseconds.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromArcseconds(double arcseconds)
-#else
- public static Angle FromArcseconds(QuantityValue arcseconds)
-#endif
- {
- double value = (double) arcseconds;
- return new Angle(value, AngleUnit.Arcsecond);
- }
-
- ///
- /// Get Angle from Centiradians.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromCentiradians(double centiradians)
-#else
- public static Angle FromCentiradians(QuantityValue centiradians)
-#endif
- {
- double value = (double) centiradians;
- return new Angle(value, AngleUnit.Centiradian);
- }
-
- ///
- /// Get Angle from Deciradians.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromDeciradians(double deciradians)
-#else
- public static Angle FromDeciradians(QuantityValue deciradians)
-#endif
- {
- double value = (double) deciradians;
- return new Angle(value, AngleUnit.Deciradian);
- }
-
- ///
- /// Get Angle from Degrees.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromDegrees(double degrees)
-#else
- public static Angle FromDegrees(QuantityValue degrees)
-#endif
- {
- double value = (double) degrees;
- return new Angle(value, AngleUnit.Degree);
- }
-
- ///
- /// Get Angle from Gradians.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromGradians(double gradians)
-#else
- public static Angle FromGradians(QuantityValue gradians)
-#endif
- {
- double value = (double) gradians;
- return new Angle(value, AngleUnit.Gradian);
- }
-
- ///
- /// Get Angle from Microdegrees.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromMicrodegrees(double microdegrees)
-#else
- public static Angle FromMicrodegrees(QuantityValue microdegrees)
-#endif
- {
- double value = (double) microdegrees;
- return new Angle(value, AngleUnit.Microdegree);
- }
-
- ///
- /// Get Angle from Microradians.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromMicroradians(double microradians)
-#else
- public static Angle FromMicroradians(QuantityValue microradians)
-#endif
- {
- double value = (double) microradians;
- return new Angle(value, AngleUnit.Microradian);
- }
-
- ///
- /// Get Angle from Millidegrees.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromMillidegrees(double millidegrees)
-#else
- public static Angle FromMillidegrees(QuantityValue millidegrees)
-#endif
- {
- double value = (double) millidegrees;
- return new Angle(value, AngleUnit.Millidegree);
- }
-
- ///
- /// Get Angle from Milliradians.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromMilliradians(double milliradians)
-#else
- public static Angle FromMilliradians(QuantityValue milliradians)
-#endif
- {
- double value = (double) milliradians;
- return new Angle(value, AngleUnit.Milliradian);
- }
-
- ///
- /// Get Angle from Nanodegrees.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromNanodegrees(double nanodegrees)
-#else
- public static Angle FromNanodegrees(QuantityValue nanodegrees)
-#endif
- {
- double value = (double) nanodegrees;
- return new Angle(value, AngleUnit.Nanodegree);
- }
-
- ///
- /// Get Angle from Nanoradians.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromNanoradians(double nanoradians)
-#else
- public static Angle FromNanoradians(QuantityValue nanoradians)
-#endif
- {
- double value = (double) nanoradians;
- return new Angle(value, AngleUnit.Nanoradian);
- }
-
- ///
- /// Get Angle from Radians.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromRadians(double radians)
-#else
- public static Angle FromRadians(QuantityValue radians)
-#endif
- {
- double value = (double) radians;
- return new Angle(value, AngleUnit.Radian);
- }
-
- ///
- /// Get Angle from Revolutions.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Angle FromRevolutions(double revolutions)
-#else
- public static Angle FromRevolutions(QuantityValue revolutions)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Angle From(double value, AngleUnit fromUnit)
-#else
- public static Angle From(QuantityValue value, AngleUnit fromUnit)
-#endif
- {
- return new Angle((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(AngleUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out AngleUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Angle ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Angle result)
- {
- result = default(Angle);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static AngleUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == AngleUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized AngleUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out AngleUnit unit)
- {
- unit = AngleUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == AngleUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(AngleUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Angle.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Angle.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ApparentEnergy.Common.g.cs b/Common/GeneratedCode/Quantities/ApparentEnergy.Common.g.cs
deleted file mode 100644
index 0ecc9b3128..0000000000
--- a/Common/GeneratedCode/Quantities/ApparentEnergy.Common.g.cs
+++ /dev/null
@@ -1,581 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ApparentEnergy : IQuantity
-#else
- public partial struct ApparentEnergy : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ApparentEnergyUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ApparentEnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ApparentEnergy()
- {
- BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ApparentEnergy;
-
- ///
- /// The base unit of ApparentEnergy, which is VoltampereHour. All conversions go via this value.
- ///
- public static ApparentEnergyUnit BaseUnit => ApparentEnergyUnit.VoltampereHour;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ApparentEnergy quantity.
- ///
- public static ApparentEnergyUnit[] Units { get; } = Enum.GetValues(typeof(ApparentEnergyUnit)).Cast().Except(new ApparentEnergyUnit[]{ ApparentEnergyUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit VoltampereHour.
- ///
- public static ApparentEnergy Zero => new ApparentEnergy(0, BaseUnit);
-
- ///
- /// Get ApparentEnergy from KilovoltampereHours.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ApparentEnergy FromKilovoltampereHours(double kilovoltamperehours)
-#else
- public static ApparentEnergy FromKilovoltampereHours(QuantityValue kilovoltamperehours)
-#endif
- {
- double value = (double) kilovoltamperehours;
- return new ApparentEnergy(value, ApparentEnergyUnit.KilovoltampereHour);
- }
-
- ///
- /// Get ApparentEnergy from MegavoltampereHours.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ApparentEnergy FromMegavoltampereHours(double megavoltamperehours)
-#else
- public static ApparentEnergy FromMegavoltampereHours(QuantityValue megavoltamperehours)
-#endif
- {
- double value = (double) megavoltamperehours;
- return new ApparentEnergy(value, ApparentEnergyUnit.MegavoltampereHour);
- }
-
- ///
- /// Get ApparentEnergy from VoltampereHours.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ApparentEnergy FromVoltampereHours(double voltamperehours)
-#else
- public static ApparentEnergy FromVoltampereHours(QuantityValue voltamperehours)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ApparentEnergy From(double value, ApparentEnergyUnit fromUnit)
-#else
- public static ApparentEnergy From(QuantityValue value, ApparentEnergyUnit fromUnit)
-#endif
- {
- return new ApparentEnergy((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ApparentEnergyUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ApparentEnergyUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ApparentEnergy ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ApparentEnergy result)
- {
- result = default(ApparentEnergy);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ApparentEnergyUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ApparentEnergyUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ApparentEnergyUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ApparentEnergyUnit unit)
- {
- unit = ApparentEnergyUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ApparentEnergyUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ApparentEnergyUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ApparentEnergy.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ApparentEnergy.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ApparentPower.Common.g.cs b/Common/GeneratedCode/Quantities/ApparentPower.Common.g.cs
deleted file mode 100644
index 9df3c1f890..0000000000
--- a/Common/GeneratedCode/Quantities/ApparentPower.Common.g.cs
+++ /dev/null
@@ -1,603 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ApparentPower : IQuantity
-#else
- public partial struct ApparentPower : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ApparentPowerUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ApparentPowerUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ApparentPower()
- {
- BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ApparentPower;
-
- ///
- /// The base unit of ApparentPower, which is Voltampere. All conversions go via this value.
- ///
- public static ApparentPowerUnit BaseUnit => ApparentPowerUnit.Voltampere;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ApparentPower quantity.
- ///
- public static ApparentPowerUnit[] Units { get; } = Enum.GetValues(typeof(ApparentPowerUnit)).Cast().Except(new ApparentPowerUnit[]{ ApparentPowerUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Voltampere.
- ///
- public static ApparentPower Zero => new ApparentPower(0, BaseUnit);
-
- ///
- /// Get ApparentPower from Gigavoltamperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ApparentPower FromGigavoltamperes(double gigavoltamperes)
-#else
- public static ApparentPower FromGigavoltamperes(QuantityValue gigavoltamperes)
-#endif
- {
- double value = (double) gigavoltamperes;
- return new ApparentPower(value, ApparentPowerUnit.Gigavoltampere);
- }
-
- ///
- /// Get ApparentPower from Kilovoltamperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ApparentPower FromKilovoltamperes(double kilovoltamperes)
-#else
- public static ApparentPower FromKilovoltamperes(QuantityValue kilovoltamperes)
-#endif
- {
- double value = (double) kilovoltamperes;
- return new ApparentPower(value, ApparentPowerUnit.Kilovoltampere);
- }
-
- ///
- /// Get ApparentPower from Megavoltamperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ApparentPower FromMegavoltamperes(double megavoltamperes)
-#else
- public static ApparentPower FromMegavoltamperes(QuantityValue megavoltamperes)
-#endif
- {
- double value = (double) megavoltamperes;
- return new ApparentPower(value, ApparentPowerUnit.Megavoltampere);
- }
-
- ///
- /// Get ApparentPower from Voltamperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ApparentPower FromVoltamperes(double voltamperes)
-#else
- public static ApparentPower FromVoltamperes(QuantityValue voltamperes)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ApparentPower From(double value, ApparentPowerUnit fromUnit)
-#else
- public static ApparentPower From(QuantityValue value, ApparentPowerUnit fromUnit)
-#endif
- {
- return new ApparentPower((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ApparentPowerUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ApparentPowerUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ApparentPower ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ApparentPower result)
- {
- result = default(ApparentPower);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ApparentPowerUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ApparentPowerUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ApparentPowerUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ApparentPowerUnit unit)
- {
- unit = ApparentPowerUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ApparentPowerUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ApparentPowerUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ApparentPower.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ApparentPower.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Area.Common.g.cs b/Common/GeneratedCode/Quantities/Area.Common.g.cs
deleted file mode 100644
index c58c270ae2..0000000000
--- a/Common/GeneratedCode/Quantities/Area.Common.g.cs
+++ /dev/null
@@ -1,801 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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).
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Area : IQuantity
-#else
- public partial struct Area : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly AreaUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public AreaUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Area()
- {
- BaseDimensions = new BaseDimensions(2, 0, 0, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Area;
-
- ///
- /// The base unit of Area, which is SquareMeter. All conversions go via this value.
- ///
- public static AreaUnit BaseUnit => AreaUnit.SquareMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Area quantity.
- ///
- public static AreaUnit[] Units { get; } = Enum.GetValues(typeof(AreaUnit)).Cast().Except(new AreaUnit[]{ AreaUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit SquareMeter.
- ///
- public static Area Zero => new Area(0, BaseUnit);
-
- ///
- /// Get Area from Acres.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromAcres(double acres)
-#else
- public static Area FromAcres(QuantityValue acres)
-#endif
- {
- double value = (double) acres;
- return new Area(value, AreaUnit.Acre);
- }
-
- ///
- /// Get Area from Hectares.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromHectares(double hectares)
-#else
- public static Area FromHectares(QuantityValue hectares)
-#endif
- {
- double value = (double) hectares;
- return new Area(value, AreaUnit.Hectare);
- }
-
- ///
- /// Get Area from SquareCentimeters.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromSquareCentimeters(double squarecentimeters)
-#else
- public static Area FromSquareCentimeters(QuantityValue squarecentimeters)
-#endif
- {
- double value = (double) squarecentimeters;
- return new Area(value, AreaUnit.SquareCentimeter);
- }
-
- ///
- /// Get Area from SquareDecimeters.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromSquareDecimeters(double squaredecimeters)
-#else
- public static Area FromSquareDecimeters(QuantityValue squaredecimeters)
-#endif
- {
- double value = (double) squaredecimeters;
- return new Area(value, AreaUnit.SquareDecimeter);
- }
-
- ///
- /// Get Area from SquareFeet.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromSquareFeet(double squarefeet)
-#else
- public static Area FromSquareFeet(QuantityValue squarefeet)
-#endif
- {
- double value = (double) squarefeet;
- return new Area(value, AreaUnit.SquareFoot);
- }
-
- ///
- /// Get Area from SquareInches.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromSquareInches(double squareinches)
-#else
- public static Area FromSquareInches(QuantityValue squareinches)
-#endif
- {
- double value = (double) squareinches;
- return new Area(value, AreaUnit.SquareInch);
- }
-
- ///
- /// Get Area from SquareKilometers.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromSquareKilometers(double squarekilometers)
-#else
- public static Area FromSquareKilometers(QuantityValue squarekilometers)
-#endif
- {
- double value = (double) squarekilometers;
- return new Area(value, AreaUnit.SquareKilometer);
- }
-
- ///
- /// Get Area from SquareMeters.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromSquareMeters(double squaremeters)
-#else
- public static Area FromSquareMeters(QuantityValue squaremeters)
-#endif
- {
- double value = (double) squaremeters;
- return new Area(value, AreaUnit.SquareMeter);
- }
-
- ///
- /// Get Area from SquareMicrometers.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromSquareMicrometers(double squaremicrometers)
-#else
- public static Area FromSquareMicrometers(QuantityValue squaremicrometers)
-#endif
- {
- double value = (double) squaremicrometers;
- return new Area(value, AreaUnit.SquareMicrometer);
- }
-
- ///
- /// Get Area from SquareMiles.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromSquareMiles(double squaremiles)
-#else
- public static Area FromSquareMiles(QuantityValue squaremiles)
-#endif
- {
- double value = (double) squaremiles;
- return new Area(value, AreaUnit.SquareMile);
- }
-
- ///
- /// Get Area from SquareMillimeters.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromSquareMillimeters(double squaremillimeters)
-#else
- public static Area FromSquareMillimeters(QuantityValue squaremillimeters)
-#endif
- {
- double value = (double) squaremillimeters;
- return new Area(value, AreaUnit.SquareMillimeter);
- }
-
- ///
- /// Get Area from SquareYards.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromSquareYards(double squareyards)
-#else
- public static Area FromSquareYards(QuantityValue squareyards)
-#endif
- {
- double value = (double) squareyards;
- return new Area(value, AreaUnit.SquareYard);
- }
-
- ///
- /// Get Area from UsSurveySquareFeet.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Area FromUsSurveySquareFeet(double ussurveysquarefeet)
-#else
- public static Area FromUsSurveySquareFeet(QuantityValue ussurveysquarefeet)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Area From(double value, AreaUnit fromUnit)
-#else
- public static Area From(QuantityValue value, AreaUnit fromUnit)
-#endif
- {
- return new Area((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(AreaUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out AreaUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Area ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Area result)
- {
- result = default(Area);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static AreaUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == AreaUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized AreaUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out AreaUnit unit)
- {
- unit = AreaUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == AreaUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(AreaUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Area.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Area.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/AreaDensity.Common.g.cs b/Common/GeneratedCode/Quantities/AreaDensity.Common.g.cs
deleted file mode 100644
index 2499aca212..0000000000
--- a/Common/GeneratedCode/Quantities/AreaDensity.Common.g.cs
+++ /dev/null
@@ -1,537 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// The area density of a two-dimensional object is calculated as the mass per unit area.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class AreaDensity : IQuantity
-#else
- public partial struct AreaDensity : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly AreaDensityUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public AreaDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static AreaDensity()
- {
- BaseDimensions = new BaseDimensions(-2, 1, 0, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.AreaDensity;
-
- ///
- /// The base unit of AreaDensity, which is KilogramPerSquareMeter. All conversions go via this value.
- ///
- public static AreaDensityUnit BaseUnit => AreaDensityUnit.KilogramPerSquareMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the AreaDensity quantity.
- ///
- public static AreaDensityUnit[] Units { get; } = Enum.GetValues(typeof(AreaDensityUnit)).Cast().Except(new AreaDensityUnit[]{ AreaDensityUnit.Undefined }).ToArray();
-
- ///
- /// Get AreaDensity in KilogramsPerSquareMeter.
- ///
- public double KilogramsPerSquareMeter => As(AreaDensityUnit.KilogramPerSquareMeter);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerSquareMeter.
- ///
- public static AreaDensity Zero => new AreaDensity(0, BaseUnit);
-
- ///
- /// Get AreaDensity from KilogramsPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AreaDensity FromKilogramsPerSquareMeter(double kilogramspersquaremeter)
-#else
- public static AreaDensity FromKilogramsPerSquareMeter(QuantityValue kilogramspersquaremeter)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static AreaDensity From(double value, AreaDensityUnit fromUnit)
-#else
- public static AreaDensity From(QuantityValue value, AreaDensityUnit fromUnit)
-#endif
- {
- return new AreaDensity((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(AreaDensityUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out AreaDensityUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static AreaDensity ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out AreaDensity result)
- {
- result = default(AreaDensity);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static AreaDensityUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == AreaDensityUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized AreaDensityUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out AreaDensityUnit unit)
- {
- unit = AreaDensityUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == AreaDensityUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(AreaDensityUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => AreaDensity.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => AreaDensity.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/AreaMomentOfInertia.Common.g.cs b/Common/GeneratedCode/Quantities/AreaMomentOfInertia.Common.g.cs
deleted file mode 100644
index 0b60cdd202..0000000000
--- a/Common/GeneratedCode/Quantities/AreaMomentOfInertia.Common.g.cs
+++ /dev/null
@@ -1,647 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// A geometric property of an area that reflects how its points are distributed with regard to an axis.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class AreaMomentOfInertia : IQuantity
-#else
- public partial struct AreaMomentOfInertia : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly AreaMomentOfInertiaUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public AreaMomentOfInertiaUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static AreaMomentOfInertia()
- {
- BaseDimensions = new BaseDimensions(4, 0, 0, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.AreaMomentOfInertia;
-
- ///
- /// The base unit of AreaMomentOfInertia, which is MeterToTheFourth. All conversions go via this value.
- ///
- public static AreaMomentOfInertiaUnit BaseUnit => AreaMomentOfInertiaUnit.MeterToTheFourth;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the AreaMomentOfInertia quantity.
- ///
- public static AreaMomentOfInertiaUnit[] Units { get; } = Enum.GetValues(typeof(AreaMomentOfInertiaUnit)).Cast().Except(new AreaMomentOfInertiaUnit[]{ AreaMomentOfInertiaUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit MeterToTheFourth.
- ///
- public static AreaMomentOfInertia Zero => new AreaMomentOfInertia(0, BaseUnit);
-
- ///
- /// Get AreaMomentOfInertia from CentimetersToTheFourth.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AreaMomentOfInertia FromCentimetersToTheFourth(double centimeterstothefourth)
-#else
- public static AreaMomentOfInertia FromCentimetersToTheFourth(QuantityValue centimeterstothefourth)
-#endif
- {
- double value = (double) centimeterstothefourth;
- return new AreaMomentOfInertia(value, AreaMomentOfInertiaUnit.CentimeterToTheFourth);
- }
-
- ///
- /// Get AreaMomentOfInertia from DecimetersToTheFourth.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AreaMomentOfInertia FromDecimetersToTheFourth(double decimeterstothefourth)
-#else
- public static AreaMomentOfInertia FromDecimetersToTheFourth(QuantityValue decimeterstothefourth)
-#endif
- {
- double value = (double) decimeterstothefourth;
- return new AreaMomentOfInertia(value, AreaMomentOfInertiaUnit.DecimeterToTheFourth);
- }
-
- ///
- /// Get AreaMomentOfInertia from FeetToTheFourth.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AreaMomentOfInertia FromFeetToTheFourth(double feettothefourth)
-#else
- public static AreaMomentOfInertia FromFeetToTheFourth(QuantityValue feettothefourth)
-#endif
- {
- double value = (double) feettothefourth;
- return new AreaMomentOfInertia(value, AreaMomentOfInertiaUnit.FootToTheFourth);
- }
-
- ///
- /// Get AreaMomentOfInertia from InchesToTheFourth.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AreaMomentOfInertia FromInchesToTheFourth(double inchestothefourth)
-#else
- public static AreaMomentOfInertia FromInchesToTheFourth(QuantityValue inchestothefourth)
-#endif
- {
- double value = (double) inchestothefourth;
- return new AreaMomentOfInertia(value, AreaMomentOfInertiaUnit.InchToTheFourth);
- }
-
- ///
- /// Get AreaMomentOfInertia from MetersToTheFourth.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AreaMomentOfInertia FromMetersToTheFourth(double meterstothefourth)
-#else
- public static AreaMomentOfInertia FromMetersToTheFourth(QuantityValue meterstothefourth)
-#endif
- {
- double value = (double) meterstothefourth;
- return new AreaMomentOfInertia(value, AreaMomentOfInertiaUnit.MeterToTheFourth);
- }
-
- ///
- /// Get AreaMomentOfInertia from MillimetersToTheFourth.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static AreaMomentOfInertia FromMillimetersToTheFourth(double millimeterstothefourth)
-#else
- public static AreaMomentOfInertia FromMillimetersToTheFourth(QuantityValue millimeterstothefourth)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static AreaMomentOfInertia From(double value, AreaMomentOfInertiaUnit fromUnit)
-#else
- public static AreaMomentOfInertia From(QuantityValue value, AreaMomentOfInertiaUnit fromUnit)
-#endif
- {
- return new AreaMomentOfInertia((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(AreaMomentOfInertiaUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out AreaMomentOfInertiaUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static AreaMomentOfInertia ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out AreaMomentOfInertia result)
- {
- result = default(AreaMomentOfInertia);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static AreaMomentOfInertiaUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == AreaMomentOfInertiaUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized AreaMomentOfInertiaUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out AreaMomentOfInertiaUnit unit)
- {
- unit = AreaMomentOfInertiaUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == AreaMomentOfInertiaUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(AreaMomentOfInertiaUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => AreaMomentOfInertia.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => AreaMomentOfInertia.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/BitRate.Common.g.cs b/Common/GeneratedCode/Quantities/BitRate.Common.g.cs
deleted file mode 100644
index 1ad1293a07..0000000000
--- a/Common/GeneratedCode/Quantities/BitRate.Common.g.cs
+++ /dev/null
@@ -1,1086 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class BitRate : IQuantity
-#else
- public partial struct BitRate : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly decimal _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly BitRateUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public BitRateUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static BitRate()
- {
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.BitRate;
-
- ///
- /// The base unit of BitRate, which is BitPerSecond. All conversions go via this value.
- ///
- public static BitRateUnit BaseUnit => BitRateUnit.BitPerSecond;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the BitRate quantity.
- ///
- public static BitRateUnit[] Units { get; } = Enum.GetValues(typeof(BitRateUnit)).Cast().Except(new BitRateUnit[]{ BitRateUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit BitPerSecond.
- ///
- public static BitRate Zero => new BitRate(0, BaseUnit);
-
- ///
- /// Get BitRate from BitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromBitsPerSecond(double bitspersecond)
-#else
- public static BitRate FromBitsPerSecond(QuantityValue bitspersecond)
-#endif
- {
- decimal value = (decimal) bitspersecond;
- return new BitRate(value, BitRateUnit.BitPerSecond);
- }
-
- ///
- /// Get BitRate from BytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromBytesPerSecond(double bytespersecond)
-#else
- public static BitRate FromBytesPerSecond(QuantityValue bytespersecond)
-#endif
- {
- decimal value = (decimal) bytespersecond;
- return new BitRate(value, BitRateUnit.BytePerSecond);
- }
-
- ///
- /// Get BitRate from ExabitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromExabitsPerSecond(double exabitspersecond)
-#else
- public static BitRate FromExabitsPerSecond(QuantityValue exabitspersecond)
-#endif
- {
- decimal value = (decimal) exabitspersecond;
- return new BitRate(value, BitRateUnit.ExabitPerSecond);
- }
-
- ///
- /// Get BitRate from ExabytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromExabytesPerSecond(double exabytespersecond)
-#else
- public static BitRate FromExabytesPerSecond(QuantityValue exabytespersecond)
-#endif
- {
- decimal value = (decimal) exabytespersecond;
- return new BitRate(value, BitRateUnit.ExabytePerSecond);
- }
-
- ///
- /// Get BitRate from ExbibitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromExbibitsPerSecond(double exbibitspersecond)
-#else
- public static BitRate FromExbibitsPerSecond(QuantityValue exbibitspersecond)
-#endif
- {
- decimal value = (decimal) exbibitspersecond;
- return new BitRate(value, BitRateUnit.ExbibitPerSecond);
- }
-
- ///
- /// Get BitRate from ExbibytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromExbibytesPerSecond(double exbibytespersecond)
-#else
- public static BitRate FromExbibytesPerSecond(QuantityValue exbibytespersecond)
-#endif
- {
- decimal value = (decimal) exbibytespersecond;
- return new BitRate(value, BitRateUnit.ExbibytePerSecond);
- }
-
- ///
- /// Get BitRate from GibibitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromGibibitsPerSecond(double gibibitspersecond)
-#else
- public static BitRate FromGibibitsPerSecond(QuantityValue gibibitspersecond)
-#endif
- {
- decimal value = (decimal) gibibitspersecond;
- return new BitRate(value, BitRateUnit.GibibitPerSecond);
- }
-
- ///
- /// Get BitRate from GibibytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromGibibytesPerSecond(double gibibytespersecond)
-#else
- public static BitRate FromGibibytesPerSecond(QuantityValue gibibytespersecond)
-#endif
- {
- decimal value = (decimal) gibibytespersecond;
- return new BitRate(value, BitRateUnit.GibibytePerSecond);
- }
-
- ///
- /// Get BitRate from GigabitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromGigabitsPerSecond(double gigabitspersecond)
-#else
- public static BitRate FromGigabitsPerSecond(QuantityValue gigabitspersecond)
-#endif
- {
- decimal value = (decimal) gigabitspersecond;
- return new BitRate(value, BitRateUnit.GigabitPerSecond);
- }
-
- ///
- /// Get BitRate from GigabytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromGigabytesPerSecond(double gigabytespersecond)
-#else
- public static BitRate FromGigabytesPerSecond(QuantityValue gigabytespersecond)
-#endif
- {
- decimal value = (decimal) gigabytespersecond;
- return new BitRate(value, BitRateUnit.GigabytePerSecond);
- }
-
- ///
- /// Get BitRate from KibibitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromKibibitsPerSecond(double kibibitspersecond)
-#else
- public static BitRate FromKibibitsPerSecond(QuantityValue kibibitspersecond)
-#endif
- {
- decimal value = (decimal) kibibitspersecond;
- return new BitRate(value, BitRateUnit.KibibitPerSecond);
- }
-
- ///
- /// Get BitRate from KibibytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromKibibytesPerSecond(double kibibytespersecond)
-#else
- public static BitRate FromKibibytesPerSecond(QuantityValue kibibytespersecond)
-#endif
- {
- decimal value = (decimal) kibibytespersecond;
- return new BitRate(value, BitRateUnit.KibibytePerSecond);
- }
-
- ///
- /// Get BitRate from KilobitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromKilobitsPerSecond(double kilobitspersecond)
-#else
- public static BitRate FromKilobitsPerSecond(QuantityValue kilobitspersecond)
-#endif
- {
- decimal value = (decimal) kilobitspersecond;
- return new BitRate(value, BitRateUnit.KilobitPerSecond);
- }
-
- ///
- /// Get BitRate from KilobytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromKilobytesPerSecond(double kilobytespersecond)
-#else
- public static BitRate FromKilobytesPerSecond(QuantityValue kilobytespersecond)
-#endif
- {
- decimal value = (decimal) kilobytespersecond;
- return new BitRate(value, BitRateUnit.KilobytePerSecond);
- }
-
- ///
- /// Get BitRate from MebibitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromMebibitsPerSecond(double mebibitspersecond)
-#else
- public static BitRate FromMebibitsPerSecond(QuantityValue mebibitspersecond)
-#endif
- {
- decimal value = (decimal) mebibitspersecond;
- return new BitRate(value, BitRateUnit.MebibitPerSecond);
- }
-
- ///
- /// Get BitRate from MebibytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromMebibytesPerSecond(double mebibytespersecond)
-#else
- public static BitRate FromMebibytesPerSecond(QuantityValue mebibytespersecond)
-#endif
- {
- decimal value = (decimal) mebibytespersecond;
- return new BitRate(value, BitRateUnit.MebibytePerSecond);
- }
-
- ///
- /// Get BitRate from MegabitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromMegabitsPerSecond(double megabitspersecond)
-#else
- public static BitRate FromMegabitsPerSecond(QuantityValue megabitspersecond)
-#endif
- {
- decimal value = (decimal) megabitspersecond;
- return new BitRate(value, BitRateUnit.MegabitPerSecond);
- }
-
- ///
- /// Get BitRate from MegabytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromMegabytesPerSecond(double megabytespersecond)
-#else
- public static BitRate FromMegabytesPerSecond(QuantityValue megabytespersecond)
-#endif
- {
- decimal value = (decimal) megabytespersecond;
- return new BitRate(value, BitRateUnit.MegabytePerSecond);
- }
-
- ///
- /// Get BitRate from PebibitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromPebibitsPerSecond(double pebibitspersecond)
-#else
- public static BitRate FromPebibitsPerSecond(QuantityValue pebibitspersecond)
-#endif
- {
- decimal value = (decimal) pebibitspersecond;
- return new BitRate(value, BitRateUnit.PebibitPerSecond);
- }
-
- ///
- /// Get BitRate from PebibytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromPebibytesPerSecond(double pebibytespersecond)
-#else
- public static BitRate FromPebibytesPerSecond(QuantityValue pebibytespersecond)
-#endif
- {
- decimal value = (decimal) pebibytespersecond;
- return new BitRate(value, BitRateUnit.PebibytePerSecond);
- }
-
- ///
- /// Get BitRate from PetabitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromPetabitsPerSecond(double petabitspersecond)
-#else
- public static BitRate FromPetabitsPerSecond(QuantityValue petabitspersecond)
-#endif
- {
- decimal value = (decimal) petabitspersecond;
- return new BitRate(value, BitRateUnit.PetabitPerSecond);
- }
-
- ///
- /// Get BitRate from PetabytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromPetabytesPerSecond(double petabytespersecond)
-#else
- public static BitRate FromPetabytesPerSecond(QuantityValue petabytespersecond)
-#endif
- {
- decimal value = (decimal) petabytespersecond;
- return new BitRate(value, BitRateUnit.PetabytePerSecond);
- }
-
- ///
- /// Get BitRate from TebibitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromTebibitsPerSecond(double tebibitspersecond)
-#else
- public static BitRate FromTebibitsPerSecond(QuantityValue tebibitspersecond)
-#endif
- {
- decimal value = (decimal) tebibitspersecond;
- return new BitRate(value, BitRateUnit.TebibitPerSecond);
- }
-
- ///
- /// Get BitRate from TebibytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromTebibytesPerSecond(double tebibytespersecond)
-#else
- public static BitRate FromTebibytesPerSecond(QuantityValue tebibytespersecond)
-#endif
- {
- decimal value = (decimal) tebibytespersecond;
- return new BitRate(value, BitRateUnit.TebibytePerSecond);
- }
-
- ///
- /// Get BitRate from TerabitsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromTerabitsPerSecond(double terabitspersecond)
-#else
- public static BitRate FromTerabitsPerSecond(QuantityValue terabitspersecond)
-#endif
- {
- decimal value = (decimal) terabitspersecond;
- return new BitRate(value, BitRateUnit.TerabitPerSecond);
- }
-
- ///
- /// Get BitRate from TerabytesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BitRate FromTerabytesPerSecond(double terabytespersecond)
-#else
- public static BitRate FromTerabytesPerSecond(QuantityValue terabytespersecond)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static BitRate From(double value, BitRateUnit fromUnit)
-#else
- public static BitRate From(QuantityValue value, BitRateUnit fromUnit)
-#endif
- {
- return new BitRate((decimal)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(BitRateUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out BitRateUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static BitRate ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out BitRate result)
- {
- result = default(BitRate);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static BitRateUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == BitRateUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized BitRateUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out BitRateUnit unit)
- {
- unit = BitRateUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == BitRateUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(BitRateUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => BitRate.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => BitRate.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.Common.g.cs b/Common/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.Common.g.cs
deleted file mode 100644
index 0608d7e48d..0000000000
--- a/Common/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.Common.g.cs
+++ /dev/null
@@ -1,581 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class BrakeSpecificFuelConsumption : IQuantity
-#else
- public partial struct BrakeSpecificFuelConsumption : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly BrakeSpecificFuelConsumptionUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public BrakeSpecificFuelConsumptionUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static BrakeSpecificFuelConsumption()
- {
- BaseDimensions = new BaseDimensions(-2, 0, 2, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.BrakeSpecificFuelConsumption;
-
- ///
- /// The base unit of BrakeSpecificFuelConsumption, which is KilogramPerJoule. All conversions go via this value.
- ///
- public static BrakeSpecificFuelConsumptionUnit BaseUnit => BrakeSpecificFuelConsumptionUnit.KilogramPerJoule;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the BrakeSpecificFuelConsumption quantity.
- ///
- public static BrakeSpecificFuelConsumptionUnit[] Units { get; } = Enum.GetValues(typeof(BrakeSpecificFuelConsumptionUnit)).Cast().Except(new BrakeSpecificFuelConsumptionUnit[]{ BrakeSpecificFuelConsumptionUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerJoule.
- ///
- public static BrakeSpecificFuelConsumption Zero => new BrakeSpecificFuelConsumption(0, BaseUnit);
-
- ///
- /// Get BrakeSpecificFuelConsumption from GramsPerKiloWattHour.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BrakeSpecificFuelConsumption FromGramsPerKiloWattHour(double gramsperkilowatthour)
-#else
- public static BrakeSpecificFuelConsumption FromGramsPerKiloWattHour(QuantityValue gramsperkilowatthour)
-#endif
- {
- double value = (double) gramsperkilowatthour;
- return new BrakeSpecificFuelConsumption(value, BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour);
- }
-
- ///
- /// Get BrakeSpecificFuelConsumption from KilogramsPerJoule.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BrakeSpecificFuelConsumption FromKilogramsPerJoule(double kilogramsperjoule)
-#else
- public static BrakeSpecificFuelConsumption FromKilogramsPerJoule(QuantityValue kilogramsperjoule)
-#endif
- {
- double value = (double) kilogramsperjoule;
- return new BrakeSpecificFuelConsumption(value, BrakeSpecificFuelConsumptionUnit.KilogramPerJoule);
- }
-
- ///
- /// Get BrakeSpecificFuelConsumption from PoundsPerMechanicalHorsepowerHour.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static BrakeSpecificFuelConsumption FromPoundsPerMechanicalHorsepowerHour(double poundspermechanicalhorsepowerhour)
-#else
- public static BrakeSpecificFuelConsumption FromPoundsPerMechanicalHorsepowerHour(QuantityValue poundspermechanicalhorsepowerhour)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static BrakeSpecificFuelConsumption From(double value, BrakeSpecificFuelConsumptionUnit fromUnit)
-#else
- public static BrakeSpecificFuelConsumption From(QuantityValue value, BrakeSpecificFuelConsumptionUnit fromUnit)
-#endif
- {
- return new BrakeSpecificFuelConsumption((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(BrakeSpecificFuelConsumptionUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out BrakeSpecificFuelConsumptionUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static BrakeSpecificFuelConsumption ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out BrakeSpecificFuelConsumption result)
- {
- result = default(BrakeSpecificFuelConsumption);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static BrakeSpecificFuelConsumptionUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == BrakeSpecificFuelConsumptionUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized BrakeSpecificFuelConsumptionUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out BrakeSpecificFuelConsumptionUnit unit)
- {
- unit = BrakeSpecificFuelConsumptionUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == BrakeSpecificFuelConsumptionUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(BrakeSpecificFuelConsumptionUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => BrakeSpecificFuelConsumption.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => BrakeSpecificFuelConsumption.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Capacitance.Common.g.cs b/Common/GeneratedCode/Quantities/Capacitance.Common.g.cs
deleted file mode 100644
index 1fde587a73..0000000000
--- a/Common/GeneratedCode/Quantities/Capacitance.Common.g.cs
+++ /dev/null
@@ -1,537 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// Capacitance is the ability of a body to store an electric charge.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Capacitance : IQuantity
-#else
- public partial struct Capacitance : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly CapacitanceUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public CapacitanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Capacitance()
- {
- BaseDimensions = new BaseDimensions(-2, -1, 4, 2, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Capacitance;
-
- ///
- /// The base unit of Capacitance, which is Farad. All conversions go via this value.
- ///
- public static CapacitanceUnit BaseUnit => CapacitanceUnit.Farad;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Capacitance quantity.
- ///
- public static CapacitanceUnit[] Units { get; } = Enum.GetValues(typeof(CapacitanceUnit)).Cast().Except(new CapacitanceUnit[]{ CapacitanceUnit.Undefined }).ToArray();
-
- ///
- /// Get Capacitance in Farads.
- ///
- public double Farads => As(CapacitanceUnit.Farad);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Farad.
- ///
- public static Capacitance Zero => new Capacitance(0, BaseUnit);
-
- ///
- /// Get Capacitance from Farads.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Capacitance FromFarads(double farads)
-#else
- public static Capacitance FromFarads(QuantityValue farads)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Capacitance From(double value, CapacitanceUnit fromUnit)
-#else
- public static Capacitance From(QuantityValue value, CapacitanceUnit fromUnit)
-#endif
- {
- return new Capacitance((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(CapacitanceUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out CapacitanceUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Capacitance ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Capacitance result)
- {
- result = default(Capacitance);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static CapacitanceUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == CapacitanceUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized CapacitanceUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out CapacitanceUnit unit)
- {
- unit = CapacitanceUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == CapacitanceUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(CapacitanceUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Capacitance.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Capacitance.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Density.Common.g.cs b/Common/GeneratedCode/Quantities/Density.Common.g.cs
deleted file mode 100644
index dc2aee8589..0000000000
--- a/Common/GeneratedCode/Quantities/Density.Common.g.cs
+++ /dev/null
@@ -1,1351 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// The density, or more precisely, the volumetric mass density, of a substance is its mass per unit volume.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Density : IQuantity
-#else
- public partial struct Density : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly DensityUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public DensityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Density()
- {
- BaseDimensions = new BaseDimensions(-3, 1, 0, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Density;
-
- ///
- /// The base unit of Density, which is KilogramPerCubicMeter. All conversions go via this value.
- ///
- public static DensityUnit BaseUnit => DensityUnit.KilogramPerCubicMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Density quantity.
- ///
- public static DensityUnit[] Units { get; } = Enum.GetValues(typeof(DensityUnit)).Cast().Except(new DensityUnit[]{ DensityUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerCubicMeter.
- ///
- public static Density Zero => new Density(0, BaseUnit);
-
- ///
- /// Get Density from CentigramsPerDeciLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromCentigramsPerDeciLiter(double centigramsperdeciliter)
-#else
- public static Density FromCentigramsPerDeciLiter(QuantityValue centigramsperdeciliter)
-#endif
- {
- double value = (double) centigramsperdeciliter;
- return new Density(value, DensityUnit.CentigramPerDeciliter);
- }
-
- ///
- /// Get Density from CentigramsPerLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromCentigramsPerLiter(double centigramsperliter)
-#else
- public static Density FromCentigramsPerLiter(QuantityValue centigramsperliter)
-#endif
- {
- double value = (double) centigramsperliter;
- return new Density(value, DensityUnit.CentigramPerLiter);
- }
-
- ///
- /// Get Density from CentigramsPerMilliliter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromCentigramsPerMilliliter(double centigramspermilliliter)
-#else
- public static Density FromCentigramsPerMilliliter(QuantityValue centigramspermilliliter)
-#endif
- {
- double value = (double) centigramspermilliliter;
- return new Density(value, DensityUnit.CentigramPerMilliliter);
- }
-
- ///
- /// Get Density from DecigramsPerDeciLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromDecigramsPerDeciLiter(double decigramsperdeciliter)
-#else
- public static Density FromDecigramsPerDeciLiter(QuantityValue decigramsperdeciliter)
-#endif
- {
- double value = (double) decigramsperdeciliter;
- return new Density(value, DensityUnit.DecigramPerDeciliter);
- }
-
- ///
- /// Get Density from DecigramsPerLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromDecigramsPerLiter(double decigramsperliter)
-#else
- public static Density FromDecigramsPerLiter(QuantityValue decigramsperliter)
-#endif
- {
- double value = (double) decigramsperliter;
- return new Density(value, DensityUnit.DecigramPerLiter);
- }
-
- ///
- /// Get Density from DecigramsPerMilliliter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromDecigramsPerMilliliter(double decigramspermilliliter)
-#else
- public static Density FromDecigramsPerMilliliter(QuantityValue decigramspermilliliter)
-#endif
- {
- double value = (double) decigramspermilliliter;
- return new Density(value, DensityUnit.DecigramPerMilliliter);
- }
-
- ///
- /// Get Density from GramsPerCubicCentimeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromGramsPerCubicCentimeter(double gramspercubiccentimeter)
-#else
- public static Density FromGramsPerCubicCentimeter(QuantityValue gramspercubiccentimeter)
-#endif
- {
- double value = (double) gramspercubiccentimeter;
- return new Density(value, DensityUnit.GramPerCubicCentimeter);
- }
-
- ///
- /// Get Density from GramsPerCubicMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromGramsPerCubicMeter(double gramspercubicmeter)
-#else
- public static Density FromGramsPerCubicMeter(QuantityValue gramspercubicmeter)
-#endif
- {
- double value = (double) gramspercubicmeter;
- return new Density(value, DensityUnit.GramPerCubicMeter);
- }
-
- ///
- /// Get Density from GramsPerCubicMillimeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromGramsPerCubicMillimeter(double gramspercubicmillimeter)
-#else
- public static Density FromGramsPerCubicMillimeter(QuantityValue gramspercubicmillimeter)
-#endif
- {
- double value = (double) gramspercubicmillimeter;
- return new Density(value, DensityUnit.GramPerCubicMillimeter);
- }
-
- ///
- /// Get Density from GramsPerDeciLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromGramsPerDeciLiter(double gramsperdeciliter)
-#else
- public static Density FromGramsPerDeciLiter(QuantityValue gramsperdeciliter)
-#endif
- {
- double value = (double) gramsperdeciliter;
- return new Density(value, DensityUnit.GramPerDeciliter);
- }
-
- ///
- /// Get Density from GramsPerLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromGramsPerLiter(double gramsperliter)
-#else
- public static Density FromGramsPerLiter(QuantityValue gramsperliter)
-#endif
- {
- double value = (double) gramsperliter;
- return new Density(value, DensityUnit.GramPerLiter);
- }
-
- ///
- /// Get Density from GramsPerMilliliter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromGramsPerMilliliter(double gramspermilliliter)
-#else
- public static Density FromGramsPerMilliliter(QuantityValue gramspermilliliter)
-#endif
- {
- double value = (double) gramspermilliliter;
- return new Density(value, DensityUnit.GramPerMilliliter);
- }
-
- ///
- /// Get Density from KilogramsPerCubicCentimeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromKilogramsPerCubicCentimeter(double kilogramspercubiccentimeter)
-#else
- public static Density FromKilogramsPerCubicCentimeter(QuantityValue kilogramspercubiccentimeter)
-#endif
- {
- double value = (double) kilogramspercubiccentimeter;
- return new Density(value, DensityUnit.KilogramPerCubicCentimeter);
- }
-
- ///
- /// Get Density from KilogramsPerCubicMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromKilogramsPerCubicMeter(double kilogramspercubicmeter)
-#else
- public static Density FromKilogramsPerCubicMeter(QuantityValue kilogramspercubicmeter)
-#endif
- {
- double value = (double) kilogramspercubicmeter;
- return new Density(value, DensityUnit.KilogramPerCubicMeter);
- }
-
- ///
- /// Get Density from KilogramsPerCubicMillimeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromKilogramsPerCubicMillimeter(double kilogramspercubicmillimeter)
-#else
- public static Density FromKilogramsPerCubicMillimeter(QuantityValue kilogramspercubicmillimeter)
-#endif
- {
- double value = (double) kilogramspercubicmillimeter;
- return new Density(value, DensityUnit.KilogramPerCubicMillimeter);
- }
-
- ///
- /// Get Density from KilopoundsPerCubicFoot.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromKilopoundsPerCubicFoot(double kilopoundspercubicfoot)
-#else
- public static Density FromKilopoundsPerCubicFoot(QuantityValue kilopoundspercubicfoot)
-#endif
- {
- double value = (double) kilopoundspercubicfoot;
- return new Density(value, DensityUnit.KilopoundPerCubicFoot);
- }
-
- ///
- /// Get Density from KilopoundsPerCubicInch.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromKilopoundsPerCubicInch(double kilopoundspercubicinch)
-#else
- public static Density FromKilopoundsPerCubicInch(QuantityValue kilopoundspercubicinch)
-#endif
- {
- double value = (double) kilopoundspercubicinch;
- return new Density(value, DensityUnit.KilopoundPerCubicInch);
- }
-
- ///
- /// Get Density from MicrogramsPerDeciLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromMicrogramsPerDeciLiter(double microgramsperdeciliter)
-#else
- public static Density FromMicrogramsPerDeciLiter(QuantityValue microgramsperdeciliter)
-#endif
- {
- double value = (double) microgramsperdeciliter;
- return new Density(value, DensityUnit.MicrogramPerDeciliter);
- }
-
- ///
- /// Get Density from MicrogramsPerLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromMicrogramsPerLiter(double microgramsperliter)
-#else
- public static Density FromMicrogramsPerLiter(QuantityValue microgramsperliter)
-#endif
- {
- double value = (double) microgramsperliter;
- return new Density(value, DensityUnit.MicrogramPerLiter);
- }
-
- ///
- /// Get Density from MicrogramsPerMilliliter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromMicrogramsPerMilliliter(double microgramspermilliliter)
-#else
- public static Density FromMicrogramsPerMilliliter(QuantityValue microgramspermilliliter)
-#endif
- {
- double value = (double) microgramspermilliliter;
- return new Density(value, DensityUnit.MicrogramPerMilliliter);
- }
-
- ///
- /// Get Density from MilligramsPerCubicMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromMilligramsPerCubicMeter(double milligramspercubicmeter)
-#else
- public static Density FromMilligramsPerCubicMeter(QuantityValue milligramspercubicmeter)
-#endif
- {
- double value = (double) milligramspercubicmeter;
- return new Density(value, DensityUnit.MilligramPerCubicMeter);
- }
-
- ///
- /// Get Density from MilligramsPerDeciLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromMilligramsPerDeciLiter(double milligramsperdeciliter)
-#else
- public static Density FromMilligramsPerDeciLiter(QuantityValue milligramsperdeciliter)
-#endif
- {
- double value = (double) milligramsperdeciliter;
- return new Density(value, DensityUnit.MilligramPerDeciliter);
- }
-
- ///
- /// Get Density from MilligramsPerLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromMilligramsPerLiter(double milligramsperliter)
-#else
- public static Density FromMilligramsPerLiter(QuantityValue milligramsperliter)
-#endif
- {
- double value = (double) milligramsperliter;
- return new Density(value, DensityUnit.MilligramPerLiter);
- }
-
- ///
- /// Get Density from MilligramsPerMilliliter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromMilligramsPerMilliliter(double milligramspermilliliter)
-#else
- public static Density FromMilligramsPerMilliliter(QuantityValue milligramspermilliliter)
-#endif
- {
- double value = (double) milligramspermilliliter;
- return new Density(value, DensityUnit.MilligramPerMilliliter);
- }
-
- ///
- /// Get Density from NanogramsPerDeciLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromNanogramsPerDeciLiter(double nanogramsperdeciliter)
-#else
- public static Density FromNanogramsPerDeciLiter(QuantityValue nanogramsperdeciliter)
-#endif
- {
- double value = (double) nanogramsperdeciliter;
- return new Density(value, DensityUnit.NanogramPerDeciliter);
- }
-
- ///
- /// Get Density from NanogramsPerLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromNanogramsPerLiter(double nanogramsperliter)
-#else
- public static Density FromNanogramsPerLiter(QuantityValue nanogramsperliter)
-#endif
- {
- double value = (double) nanogramsperliter;
- return new Density(value, DensityUnit.NanogramPerLiter);
- }
-
- ///
- /// Get Density from NanogramsPerMilliliter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromNanogramsPerMilliliter(double nanogramspermilliliter)
-#else
- public static Density FromNanogramsPerMilliliter(QuantityValue nanogramspermilliliter)
-#endif
- {
- double value = (double) nanogramspermilliliter;
- return new Density(value, DensityUnit.NanogramPerMilliliter);
- }
-
- ///
- /// Get Density from PicogramsPerDeciLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromPicogramsPerDeciLiter(double picogramsperdeciliter)
-#else
- public static Density FromPicogramsPerDeciLiter(QuantityValue picogramsperdeciliter)
-#endif
- {
- double value = (double) picogramsperdeciliter;
- return new Density(value, DensityUnit.PicogramPerDeciliter);
- }
-
- ///
- /// Get Density from PicogramsPerLiter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromPicogramsPerLiter(double picogramsperliter)
-#else
- public static Density FromPicogramsPerLiter(QuantityValue picogramsperliter)
-#endif
- {
- double value = (double) picogramsperliter;
- return new Density(value, DensityUnit.PicogramPerLiter);
- }
-
- ///
- /// Get Density from PicogramsPerMilliliter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromPicogramsPerMilliliter(double picogramspermilliliter)
-#else
- public static Density FromPicogramsPerMilliliter(QuantityValue picogramspermilliliter)
-#endif
- {
- double value = (double) picogramspermilliliter;
- return new Density(value, DensityUnit.PicogramPerMilliliter);
- }
-
- ///
- /// Get Density from PoundsPerCubicFoot.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromPoundsPerCubicFoot(double poundspercubicfoot)
-#else
- public static Density FromPoundsPerCubicFoot(QuantityValue poundspercubicfoot)
-#endif
- {
- double value = (double) poundspercubicfoot;
- return new Density(value, DensityUnit.PoundPerCubicFoot);
- }
-
- ///
- /// Get Density from PoundsPerCubicInch.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromPoundsPerCubicInch(double poundspercubicinch)
-#else
- public static Density FromPoundsPerCubicInch(QuantityValue poundspercubicinch)
-#endif
- {
- double value = (double) poundspercubicinch;
- return new Density(value, DensityUnit.PoundPerCubicInch);
- }
-
- ///
- /// Get Density from PoundsPerImperialGallon.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromPoundsPerImperialGallon(double poundsperimperialgallon)
-#else
- public static Density FromPoundsPerImperialGallon(QuantityValue poundsperimperialgallon)
-#endif
- {
- double value = (double) poundsperimperialgallon;
- return new Density(value, DensityUnit.PoundPerImperialGallon);
- }
-
- ///
- /// Get Density from PoundsPerUSGallon.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromPoundsPerUSGallon(double poundsperusgallon)
-#else
- public static Density FromPoundsPerUSGallon(QuantityValue poundsperusgallon)
-#endif
- {
- double value = (double) poundsperusgallon;
- return new Density(value, DensityUnit.PoundPerUSGallon);
- }
-
- ///
- /// Get Density from SlugsPerCubicFoot.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromSlugsPerCubicFoot(double slugspercubicfoot)
-#else
- public static Density FromSlugsPerCubicFoot(QuantityValue slugspercubicfoot)
-#endif
- {
- double value = (double) slugspercubicfoot;
- return new Density(value, DensityUnit.SlugPerCubicFoot);
- }
-
- ///
- /// Get Density from TonnesPerCubicCentimeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromTonnesPerCubicCentimeter(double tonnespercubiccentimeter)
-#else
- public static Density FromTonnesPerCubicCentimeter(QuantityValue tonnespercubiccentimeter)
-#endif
- {
- double value = (double) tonnespercubiccentimeter;
- return new Density(value, DensityUnit.TonnePerCubicCentimeter);
- }
-
- ///
- /// Get Density from TonnesPerCubicMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromTonnesPerCubicMeter(double tonnespercubicmeter)
-#else
- public static Density FromTonnesPerCubicMeter(QuantityValue tonnespercubicmeter)
-#endif
- {
- double value = (double) tonnespercubicmeter;
- return new Density(value, DensityUnit.TonnePerCubicMeter);
- }
-
- ///
- /// Get Density from TonnesPerCubicMillimeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Density FromTonnesPerCubicMillimeter(double tonnespercubicmillimeter)
-#else
- public static Density FromTonnesPerCubicMillimeter(QuantityValue tonnespercubicmillimeter)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Density From(double value, DensityUnit fromUnit)
-#else
- public static Density From(QuantityValue value, DensityUnit fromUnit)
-#endif
- {
- return new Density((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(DensityUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out DensityUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Density ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Density result)
- {
- result = default(Density);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static DensityUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == DensityUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized DensityUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out DensityUnit unit)
- {
- unit = DensityUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == DensityUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(DensityUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Density.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Density.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Duration.Common.g.cs b/Common/GeneratedCode/Quantities/Duration.Common.g.cs
deleted file mode 100644
index 73439f778c..0000000000
--- a/Common/GeneratedCode/Quantities/Duration.Common.g.cs
+++ /dev/null
@@ -1,735 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Duration : IQuantity
-#else
- public partial struct Duration : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly DurationUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public DurationUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Duration()
- {
- BaseDimensions = new BaseDimensions(0, 0, 1, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Duration;
-
- ///
- /// The base unit of Duration, which is Second. All conversions go via this value.
- ///
- public static DurationUnit BaseUnit => DurationUnit.Second;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Duration quantity.
- ///
- public static DurationUnit[] Units { get; } = Enum.GetValues(typeof(DurationUnit)).Cast().Except(new DurationUnit[]{ DurationUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Second.
- ///
- public static Duration Zero => new Duration(0, BaseUnit);
-
- ///
- /// Get Duration from Days.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Duration FromDays(double days)
-#else
- public static Duration FromDays(QuantityValue days)
-#endif
- {
- double value = (double) days;
- return new Duration(value, DurationUnit.Day);
- }
-
- ///
- /// Get Duration from Hours.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Duration FromHours(double hours)
-#else
- public static Duration FromHours(QuantityValue hours)
-#endif
- {
- double value = (double) hours;
- return new Duration(value, DurationUnit.Hour);
- }
-
- ///
- /// Get Duration from Microseconds.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Duration FromMicroseconds(double microseconds)
-#else
- public static Duration FromMicroseconds(QuantityValue microseconds)
-#endif
- {
- double value = (double) microseconds;
- return new Duration(value, DurationUnit.Microsecond);
- }
-
- ///
- /// Get Duration from Milliseconds.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Duration FromMilliseconds(double milliseconds)
-#else
- public static Duration FromMilliseconds(QuantityValue milliseconds)
-#endif
- {
- double value = (double) milliseconds;
- return new Duration(value, DurationUnit.Millisecond);
- }
-
- ///
- /// Get Duration from Minutes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Duration FromMinutes(double minutes)
-#else
- public static Duration FromMinutes(QuantityValue minutes)
-#endif
- {
- double value = (double) minutes;
- return new Duration(value, DurationUnit.Minute);
- }
-
- ///
- /// Get Duration from Months30.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Duration FromMonths30(double months30)
-#else
- public static Duration FromMonths30(QuantityValue months30)
-#endif
- {
- double value = (double) months30;
- return new Duration(value, DurationUnit.Month30);
- }
-
- ///
- /// Get Duration from Nanoseconds.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Duration FromNanoseconds(double nanoseconds)
-#else
- public static Duration FromNanoseconds(QuantityValue nanoseconds)
-#endif
- {
- double value = (double) nanoseconds;
- return new Duration(value, DurationUnit.Nanosecond);
- }
-
- ///
- /// Get Duration from Seconds.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Duration FromSeconds(double seconds)
-#else
- public static Duration FromSeconds(QuantityValue seconds)
-#endif
- {
- double value = (double) seconds;
- return new Duration(value, DurationUnit.Second);
- }
-
- ///
- /// Get Duration from Weeks.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Duration FromWeeks(double weeks)
-#else
- public static Duration FromWeeks(QuantityValue weeks)
-#endif
- {
- double value = (double) weeks;
- return new Duration(value, DurationUnit.Week);
- }
-
- ///
- /// Get Duration from Years365.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Duration FromYears365(double years365)
-#else
- public static Duration FromYears365(QuantityValue years365)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Duration From(double value, DurationUnit fromUnit)
-#else
- public static Duration From(QuantityValue value, DurationUnit fromUnit)
-#endif
- {
- return new Duration((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(DurationUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out DurationUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Duration ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Duration result)
- {
- result = default(Duration);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static DurationUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == DurationUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized DurationUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out DurationUnit unit)
- {
- unit = DurationUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == DurationUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(DurationUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Duration.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Duration.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/DynamicViscosity.Common.g.cs b/Common/GeneratedCode/Quantities/DynamicViscosity.Common.g.cs
deleted file mode 100644
index 23979f9711..0000000000
--- a/Common/GeneratedCode/Quantities/DynamicViscosity.Common.g.cs
+++ /dev/null
@@ -1,647 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class DynamicViscosity : IQuantity
-#else
- public partial struct DynamicViscosity : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly DynamicViscosityUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public DynamicViscosityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static DynamicViscosity()
- {
- BaseDimensions = new BaseDimensions(-1, 1, -1, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.DynamicViscosity;
-
- ///
- /// The base unit of DynamicViscosity, which is NewtonSecondPerMeterSquared. All conversions go via this value.
- ///
- public static DynamicViscosityUnit BaseUnit => DynamicViscosityUnit.NewtonSecondPerMeterSquared;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the DynamicViscosity quantity.
- ///
- public static DynamicViscosityUnit[] Units { get; } = Enum.GetValues(typeof(DynamicViscosityUnit)).Cast().Except(new DynamicViscosityUnit[]{ DynamicViscosityUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit NewtonSecondPerMeterSquared.
- ///
- public static DynamicViscosity Zero => new DynamicViscosity(0, BaseUnit);
-
- ///
- /// Get DynamicViscosity from Centipoise.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static DynamicViscosity FromCentipoise(double centipoise)
-#else
- public static DynamicViscosity FromCentipoise(QuantityValue centipoise)
-#endif
- {
- double value = (double) centipoise;
- return new DynamicViscosity(value, DynamicViscosityUnit.Centipoise);
- }
-
- ///
- /// Get DynamicViscosity from MicropascalSeconds.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static DynamicViscosity FromMicropascalSeconds(double micropascalseconds)
-#else
- public static DynamicViscosity FromMicropascalSeconds(QuantityValue micropascalseconds)
-#endif
- {
- double value = (double) micropascalseconds;
- return new DynamicViscosity(value, DynamicViscosityUnit.MicropascalSecond);
- }
-
- ///
- /// Get DynamicViscosity from MillipascalSeconds.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static DynamicViscosity FromMillipascalSeconds(double millipascalseconds)
-#else
- public static DynamicViscosity FromMillipascalSeconds(QuantityValue millipascalseconds)
-#endif
- {
- double value = (double) millipascalseconds;
- return new DynamicViscosity(value, DynamicViscosityUnit.MillipascalSecond);
- }
-
- ///
- /// Get DynamicViscosity from NewtonSecondsPerMeterSquared.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static DynamicViscosity FromNewtonSecondsPerMeterSquared(double newtonsecondspermetersquared)
-#else
- public static DynamicViscosity FromNewtonSecondsPerMeterSquared(QuantityValue newtonsecondspermetersquared)
-#endif
- {
- double value = (double) newtonsecondspermetersquared;
- return new DynamicViscosity(value, DynamicViscosityUnit.NewtonSecondPerMeterSquared);
- }
-
- ///
- /// Get DynamicViscosity from PascalSeconds.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static DynamicViscosity FromPascalSeconds(double pascalseconds)
-#else
- public static DynamicViscosity FromPascalSeconds(QuantityValue pascalseconds)
-#endif
- {
- double value = (double) pascalseconds;
- return new DynamicViscosity(value, DynamicViscosityUnit.PascalSecond);
- }
-
- ///
- /// Get DynamicViscosity from Poise.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static DynamicViscosity FromPoise(double poise)
-#else
- public static DynamicViscosity FromPoise(QuantityValue poise)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static DynamicViscosity From(double value, DynamicViscosityUnit fromUnit)
-#else
- public static DynamicViscosity From(QuantityValue value, DynamicViscosityUnit fromUnit)
-#endif
- {
- return new DynamicViscosity((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(DynamicViscosityUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out DynamicViscosityUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static DynamicViscosity ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out DynamicViscosity result)
- {
- result = default(DynamicViscosity);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static DynamicViscosityUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == DynamicViscosityUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized DynamicViscosityUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out DynamicViscosityUnit unit)
- {
- unit = DynamicViscosityUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == DynamicViscosityUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(DynamicViscosityUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => DynamicViscosity.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => DynamicViscosity.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricAdmittance.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricAdmittance.Common.g.cs
deleted file mode 100644
index 63a672f664..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricAdmittance.Common.g.cs
+++ /dev/null
@@ -1,603 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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).
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricAdmittance : IQuantity
-#else
- public partial struct ElectricAdmittance : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricAdmittanceUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricAdmittanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricAdmittance()
- {
- BaseDimensions = new BaseDimensions(-2, -1, 3, 2, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricAdmittance;
-
- ///
- /// The base unit of ElectricAdmittance, which is Siemens. All conversions go via this value.
- ///
- public static ElectricAdmittanceUnit BaseUnit => ElectricAdmittanceUnit.Siemens;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricAdmittance quantity.
- ///
- public static ElectricAdmittanceUnit[] Units { get; } = Enum.GetValues(typeof(ElectricAdmittanceUnit)).Cast().Except(new ElectricAdmittanceUnit[]{ ElectricAdmittanceUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Siemens.
- ///
- public static ElectricAdmittance Zero => new ElectricAdmittance(0, BaseUnit);
-
- ///
- /// Get ElectricAdmittance from Microsiemens.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricAdmittance FromMicrosiemens(double microsiemens)
-#else
- public static ElectricAdmittance FromMicrosiemens(QuantityValue microsiemens)
-#endif
- {
- double value = (double) microsiemens;
- return new ElectricAdmittance(value, ElectricAdmittanceUnit.Microsiemens);
- }
-
- ///
- /// Get ElectricAdmittance from Millisiemens.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricAdmittance FromMillisiemens(double millisiemens)
-#else
- public static ElectricAdmittance FromMillisiemens(QuantityValue millisiemens)
-#endif
- {
- double value = (double) millisiemens;
- return new ElectricAdmittance(value, ElectricAdmittanceUnit.Millisiemens);
- }
-
- ///
- /// Get ElectricAdmittance from Nanosiemens.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricAdmittance FromNanosiemens(double nanosiemens)
-#else
- public static ElectricAdmittance FromNanosiemens(QuantityValue nanosiemens)
-#endif
- {
- double value = (double) nanosiemens;
- return new ElectricAdmittance(value, ElectricAdmittanceUnit.Nanosiemens);
- }
-
- ///
- /// Get ElectricAdmittance from Siemens.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricAdmittance FromSiemens(double siemens)
-#else
- public static ElectricAdmittance FromSiemens(QuantityValue siemens)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricAdmittance From(double value, ElectricAdmittanceUnit fromUnit)
-#else
- public static ElectricAdmittance From(QuantityValue value, ElectricAdmittanceUnit fromUnit)
-#endif
- {
- return new ElectricAdmittance((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricAdmittanceUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricAdmittanceUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricAdmittance ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricAdmittance result)
- {
- result = default(ElectricAdmittance);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricAdmittanceUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricAdmittanceUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricAdmittanceUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricAdmittanceUnit unit)
- {
- unit = ElectricAdmittanceUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricAdmittanceUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricAdmittanceUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricAdmittance.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricAdmittance.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricCharge.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricCharge.Common.g.cs
deleted file mode 100644
index 5dbfebef04..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricCharge.Common.g.cs
+++ /dev/null
@@ -1,537 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricCharge : IQuantity
-#else
- public partial struct ElectricCharge : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricChargeUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricChargeUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricCharge()
- {
- BaseDimensions = new BaseDimensions(0, 0, 1, 1, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricCharge;
-
- ///
- /// The base unit of ElectricCharge, which is Coulomb. All conversions go via this value.
- ///
- public static ElectricChargeUnit BaseUnit => ElectricChargeUnit.Coulomb;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricCharge quantity.
- ///
- public static ElectricChargeUnit[] Units { get; } = Enum.GetValues(typeof(ElectricChargeUnit)).Cast().Except(new ElectricChargeUnit[]{ ElectricChargeUnit.Undefined }).ToArray();
-
- ///
- /// Get ElectricCharge in Coulombs.
- ///
- public double Coulombs => As(ElectricChargeUnit.Coulomb);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Coulomb.
- ///
- public static ElectricCharge Zero => new ElectricCharge(0, BaseUnit);
-
- ///
- /// Get ElectricCharge from Coulombs.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricCharge FromCoulombs(double coulombs)
-#else
- public static ElectricCharge FromCoulombs(QuantityValue coulombs)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricCharge From(double value, ElectricChargeUnit fromUnit)
-#else
- public static ElectricCharge From(QuantityValue value, ElectricChargeUnit fromUnit)
-#endif
- {
- return new ElectricCharge((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricChargeUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricChargeUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricCharge ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricCharge result)
- {
- result = default(ElectricCharge);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricChargeUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricChargeUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricChargeUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricChargeUnit unit)
- {
- unit = ElectricChargeUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricChargeUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricChargeUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricCharge.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricCharge.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricChargeDensity.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricChargeDensity.Common.g.cs
deleted file mode 100644
index 6cb2bad778..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricChargeDensity.Common.g.cs
+++ /dev/null
@@ -1,537 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricChargeDensity : IQuantity
-#else
- public partial struct ElectricChargeDensity : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricChargeDensityUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricChargeDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricChargeDensity()
- {
- BaseDimensions = new BaseDimensions(-3, 0, 1, 1, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricChargeDensity;
-
- ///
- /// The base unit of ElectricChargeDensity, which is CoulombPerCubicMeter. All conversions go via this value.
- ///
- public static ElectricChargeDensityUnit BaseUnit => ElectricChargeDensityUnit.CoulombPerCubicMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricChargeDensity quantity.
- ///
- public static ElectricChargeDensityUnit[] Units { get; } = Enum.GetValues(typeof(ElectricChargeDensityUnit)).Cast().Except(new ElectricChargeDensityUnit[]{ ElectricChargeDensityUnit.Undefined }).ToArray();
-
- ///
- /// Get ElectricChargeDensity in CoulombsPerCubicMeter.
- ///
- public double CoulombsPerCubicMeter => As(ElectricChargeDensityUnit.CoulombPerCubicMeter);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit CoulombPerCubicMeter.
- ///
- public static ElectricChargeDensity Zero => new ElectricChargeDensity(0, BaseUnit);
-
- ///
- /// Get ElectricChargeDensity from CoulombsPerCubicMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricChargeDensity FromCoulombsPerCubicMeter(double coulombspercubicmeter)
-#else
- public static ElectricChargeDensity FromCoulombsPerCubicMeter(QuantityValue coulombspercubicmeter)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricChargeDensity From(double value, ElectricChargeDensityUnit fromUnit)
-#else
- public static ElectricChargeDensity From(QuantityValue value, ElectricChargeDensityUnit fromUnit)
-#endif
- {
- return new ElectricChargeDensity((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricChargeDensityUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricChargeDensityUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricChargeDensity ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricChargeDensity result)
- {
- result = default(ElectricChargeDensity);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricChargeDensityUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricChargeDensityUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricChargeDensityUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricChargeDensityUnit unit)
- {
- unit = ElectricChargeDensityUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricChargeDensityUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricChargeDensityUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricChargeDensity.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricChargeDensity.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricConductance.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricConductance.Common.g.cs
deleted file mode 100644
index 56d39d998a..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricConductance.Common.g.cs
+++ /dev/null
@@ -1,581 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricConductance : IQuantity
-#else
- public partial struct ElectricConductance : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricConductanceUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricConductanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricConductance()
- {
- BaseDimensions = new BaseDimensions(-2, -1, 3, 2, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricConductance;
-
- ///
- /// The base unit of ElectricConductance, which is Siemens. All conversions go via this value.
- ///
- public static ElectricConductanceUnit BaseUnit => ElectricConductanceUnit.Siemens;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricConductance quantity.
- ///
- public static ElectricConductanceUnit[] Units { get; } = Enum.GetValues(typeof(ElectricConductanceUnit)).Cast().Except(new ElectricConductanceUnit[]{ ElectricConductanceUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Siemens.
- ///
- public static ElectricConductance Zero => new ElectricConductance(0, BaseUnit);
-
- ///
- /// Get ElectricConductance from Microsiemens.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricConductance FromMicrosiemens(double microsiemens)
-#else
- public static ElectricConductance FromMicrosiemens(QuantityValue microsiemens)
-#endif
- {
- double value = (double) microsiemens;
- return new ElectricConductance(value, ElectricConductanceUnit.Microsiemens);
- }
-
- ///
- /// Get ElectricConductance from Millisiemens.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricConductance FromMillisiemens(double millisiemens)
-#else
- public static ElectricConductance FromMillisiemens(QuantityValue millisiemens)
-#endif
- {
- double value = (double) millisiemens;
- return new ElectricConductance(value, ElectricConductanceUnit.Millisiemens);
- }
-
- ///
- /// Get ElectricConductance from Siemens.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricConductance FromSiemens(double siemens)
-#else
- public static ElectricConductance FromSiemens(QuantityValue siemens)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricConductance From(double value, ElectricConductanceUnit fromUnit)
-#else
- public static ElectricConductance From(QuantityValue value, ElectricConductanceUnit fromUnit)
-#endif
- {
- return new ElectricConductance((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricConductanceUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricConductanceUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricConductance ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricConductance result)
- {
- result = default(ElectricConductance);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricConductanceUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricConductanceUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricConductanceUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricConductanceUnit unit)
- {
- unit = ElectricConductanceUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricConductanceUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricConductanceUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricConductance.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricConductance.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricConductivity.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricConductivity.Common.g.cs
deleted file mode 100644
index b1079413da..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricConductivity.Common.g.cs
+++ /dev/null
@@ -1,537 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricConductivity : IQuantity
-#else
- public partial struct ElectricConductivity : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricConductivityUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricConductivityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricConductivity()
- {
- BaseDimensions = new BaseDimensions(-3, -1, 3, 2, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricConductivity;
-
- ///
- /// The base unit of ElectricConductivity, which is SiemensPerMeter. All conversions go via this value.
- ///
- public static ElectricConductivityUnit BaseUnit => ElectricConductivityUnit.SiemensPerMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricConductivity quantity.
- ///
- public static ElectricConductivityUnit[] Units { get; } = Enum.GetValues(typeof(ElectricConductivityUnit)).Cast().Except(new ElectricConductivityUnit[]{ ElectricConductivityUnit.Undefined }).ToArray();
-
- ///
- /// Get ElectricConductivity in SiemensPerMeter.
- ///
- public double SiemensPerMeter => As(ElectricConductivityUnit.SiemensPerMeter);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit SiemensPerMeter.
- ///
- public static ElectricConductivity Zero => new ElectricConductivity(0, BaseUnit);
-
- ///
- /// Get ElectricConductivity from SiemensPerMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricConductivity FromSiemensPerMeter(double siemenspermeter)
-#else
- public static ElectricConductivity FromSiemensPerMeter(QuantityValue siemenspermeter)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricConductivity From(double value, ElectricConductivityUnit fromUnit)
-#else
- public static ElectricConductivity From(QuantityValue value, ElectricConductivityUnit fromUnit)
-#endif
- {
- return new ElectricConductivity((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricConductivityUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricConductivityUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricConductivity ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricConductivity result)
- {
- result = default(ElectricConductivity);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricConductivityUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricConductivityUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricConductivityUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricConductivityUnit unit)
- {
- unit = ElectricConductivityUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricConductivityUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricConductivityUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricConductivity.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricConductivity.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricCurrent.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricCurrent.Common.g.cs
deleted file mode 100644
index c05dd17d91..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricCurrent.Common.g.cs
+++ /dev/null
@@ -1,691 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricCurrent : IQuantity
-#else
- public partial struct ElectricCurrent : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricCurrentUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricCurrentUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricCurrent()
- {
- BaseDimensions = new BaseDimensions(0, 0, 0, 1, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricCurrent;
-
- ///
- /// The base unit of ElectricCurrent, which is Ampere. All conversions go via this value.
- ///
- public static ElectricCurrentUnit BaseUnit => ElectricCurrentUnit.Ampere;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricCurrent quantity.
- ///
- public static ElectricCurrentUnit[] Units { get; } = Enum.GetValues(typeof(ElectricCurrentUnit)).Cast().Except(new ElectricCurrentUnit[]{ ElectricCurrentUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Ampere.
- ///
- public static ElectricCurrent Zero => new ElectricCurrent(0, BaseUnit);
-
- ///
- /// Get ElectricCurrent from Amperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricCurrent FromAmperes(double amperes)
-#else
- public static ElectricCurrent FromAmperes(QuantityValue amperes)
-#endif
- {
- double value = (double) amperes;
- return new ElectricCurrent(value, ElectricCurrentUnit.Ampere);
- }
-
- ///
- /// Get ElectricCurrent from Centiamperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricCurrent FromCentiamperes(double centiamperes)
-#else
- public static ElectricCurrent FromCentiamperes(QuantityValue centiamperes)
-#endif
- {
- double value = (double) centiamperes;
- return new ElectricCurrent(value, ElectricCurrentUnit.Centiampere);
- }
-
- ///
- /// Get ElectricCurrent from Kiloamperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricCurrent FromKiloamperes(double kiloamperes)
-#else
- public static ElectricCurrent FromKiloamperes(QuantityValue kiloamperes)
-#endif
- {
- double value = (double) kiloamperes;
- return new ElectricCurrent(value, ElectricCurrentUnit.Kiloampere);
- }
-
- ///
- /// Get ElectricCurrent from Megaamperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricCurrent FromMegaamperes(double megaamperes)
-#else
- public static ElectricCurrent FromMegaamperes(QuantityValue megaamperes)
-#endif
- {
- double value = (double) megaamperes;
- return new ElectricCurrent(value, ElectricCurrentUnit.Megaampere);
- }
-
- ///
- /// Get ElectricCurrent from Microamperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricCurrent FromMicroamperes(double microamperes)
-#else
- public static ElectricCurrent FromMicroamperes(QuantityValue microamperes)
-#endif
- {
- double value = (double) microamperes;
- return new ElectricCurrent(value, ElectricCurrentUnit.Microampere);
- }
-
- ///
- /// Get ElectricCurrent from Milliamperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricCurrent FromMilliamperes(double milliamperes)
-#else
- public static ElectricCurrent FromMilliamperes(QuantityValue milliamperes)
-#endif
- {
- double value = (double) milliamperes;
- return new ElectricCurrent(value, ElectricCurrentUnit.Milliampere);
- }
-
- ///
- /// Get ElectricCurrent from Nanoamperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricCurrent FromNanoamperes(double nanoamperes)
-#else
- public static ElectricCurrent FromNanoamperes(QuantityValue nanoamperes)
-#endif
- {
- double value = (double) nanoamperes;
- return new ElectricCurrent(value, ElectricCurrentUnit.Nanoampere);
- }
-
- ///
- /// Get ElectricCurrent from Picoamperes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricCurrent FromPicoamperes(double picoamperes)
-#else
- public static ElectricCurrent FromPicoamperes(QuantityValue picoamperes)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricCurrent From(double value, ElectricCurrentUnit fromUnit)
-#else
- public static ElectricCurrent From(QuantityValue value, ElectricCurrentUnit fromUnit)
-#endif
- {
- return new ElectricCurrent((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricCurrentUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricCurrentUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricCurrent ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricCurrent result)
- {
- result = default(ElectricCurrent);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricCurrentUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricCurrentUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricCurrentUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricCurrentUnit unit)
- {
- unit = ElectricCurrentUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricCurrentUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricCurrentUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricCurrent.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricCurrent.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricCurrentDensity.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricCurrentDensity.Common.g.cs
deleted file mode 100644
index 2bb80eac60..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricCurrentDensity.Common.g.cs
+++ /dev/null
@@ -1,537 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// In electromagnetism, current density is the electric current per unit area of cross section.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricCurrentDensity : IQuantity
-#else
- public partial struct ElectricCurrentDensity : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricCurrentDensityUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricCurrentDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricCurrentDensity()
- {
- BaseDimensions = new BaseDimensions(-2, 0, 0, 1, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricCurrentDensity;
-
- ///
- /// The base unit of ElectricCurrentDensity, which is AmperePerSquareMeter. All conversions go via this value.
- ///
- public static ElectricCurrentDensityUnit BaseUnit => ElectricCurrentDensityUnit.AmperePerSquareMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricCurrentDensity quantity.
- ///
- public static ElectricCurrentDensityUnit[] Units { get; } = Enum.GetValues(typeof(ElectricCurrentDensityUnit)).Cast().Except(new ElectricCurrentDensityUnit[]{ ElectricCurrentDensityUnit.Undefined }).ToArray();
-
- ///
- /// Get ElectricCurrentDensity in AmperesPerSquareMeter.
- ///
- public double AmperesPerSquareMeter => As(ElectricCurrentDensityUnit.AmperePerSquareMeter);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit AmperePerSquareMeter.
- ///
- public static ElectricCurrentDensity Zero => new ElectricCurrentDensity(0, BaseUnit);
-
- ///
- /// Get ElectricCurrentDensity from AmperesPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricCurrentDensity FromAmperesPerSquareMeter(double amperespersquaremeter)
-#else
- public static ElectricCurrentDensity FromAmperesPerSquareMeter(QuantityValue amperespersquaremeter)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricCurrentDensity From(double value, ElectricCurrentDensityUnit fromUnit)
-#else
- public static ElectricCurrentDensity From(QuantityValue value, ElectricCurrentDensityUnit fromUnit)
-#endif
- {
- return new ElectricCurrentDensity((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricCurrentDensityUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricCurrentDensityUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricCurrentDensity ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricCurrentDensity result)
- {
- result = default(ElectricCurrentDensity);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricCurrentDensityUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricCurrentDensityUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricCurrentDensityUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricCurrentDensityUnit unit)
- {
- unit = ElectricCurrentDensityUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricCurrentDensityUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricCurrentDensityUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricCurrentDensity.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricCurrentDensity.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricCurrentGradient.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricCurrentGradient.Common.g.cs
deleted file mode 100644
index 625f5f3f12..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricCurrentGradient.Common.g.cs
+++ /dev/null
@@ -1,537 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// In electromagnetism, the current gradient describes how the current changes in time.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricCurrentGradient : IQuantity
-#else
- public partial struct ElectricCurrentGradient : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricCurrentGradientUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricCurrentGradientUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricCurrentGradient()
- {
- BaseDimensions = new BaseDimensions(0, 0, -1, 1, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricCurrentGradient;
-
- ///
- /// The base unit of ElectricCurrentGradient, which is AmperePerSecond. All conversions go via this value.
- ///
- public static ElectricCurrentGradientUnit BaseUnit => ElectricCurrentGradientUnit.AmperePerSecond;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricCurrentGradient quantity.
- ///
- public static ElectricCurrentGradientUnit[] Units { get; } = Enum.GetValues(typeof(ElectricCurrentGradientUnit)).Cast().Except(new ElectricCurrentGradientUnit[]{ ElectricCurrentGradientUnit.Undefined }).ToArray();
-
- ///
- /// Get ElectricCurrentGradient in AmperesPerSecond.
- ///
- public double AmperesPerSecond => As(ElectricCurrentGradientUnit.AmperePerSecond);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit AmperePerSecond.
- ///
- public static ElectricCurrentGradient Zero => new ElectricCurrentGradient(0, BaseUnit);
-
- ///
- /// Get ElectricCurrentGradient from AmperesPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricCurrentGradient FromAmperesPerSecond(double amperespersecond)
-#else
- public static ElectricCurrentGradient FromAmperesPerSecond(QuantityValue amperespersecond)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricCurrentGradient From(double value, ElectricCurrentGradientUnit fromUnit)
-#else
- public static ElectricCurrentGradient From(QuantityValue value, ElectricCurrentGradientUnit fromUnit)
-#endif
- {
- return new ElectricCurrentGradient((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricCurrentGradientUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricCurrentGradientUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricCurrentGradient ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricCurrentGradient result)
- {
- result = default(ElectricCurrentGradient);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricCurrentGradientUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricCurrentGradientUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricCurrentGradientUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricCurrentGradientUnit unit)
- {
- unit = ElectricCurrentGradientUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricCurrentGradientUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricCurrentGradientUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricCurrentGradient.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricCurrentGradient.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricField.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricField.Common.g.cs
deleted file mode 100644
index 58e01b2c4b..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricField.Common.g.cs
+++ /dev/null
@@ -1,537 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// An electric field is a force field that surrounds electric charges that attracts or repels other electric charges.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricField : IQuantity
-#else
- public partial struct ElectricField : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricFieldUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricFieldUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricField()
- {
- BaseDimensions = new BaseDimensions(1, 1, -3, -1, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricField;
-
- ///
- /// The base unit of ElectricField, which is VoltPerMeter. All conversions go via this value.
- ///
- public static ElectricFieldUnit BaseUnit => ElectricFieldUnit.VoltPerMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricField quantity.
- ///
- public static ElectricFieldUnit[] Units { get; } = Enum.GetValues(typeof(ElectricFieldUnit)).Cast().Except(new ElectricFieldUnit[]{ ElectricFieldUnit.Undefined }).ToArray();
-
- ///
- /// Get ElectricField in VoltsPerMeter.
- ///
- public double VoltsPerMeter => As(ElectricFieldUnit.VoltPerMeter);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit VoltPerMeter.
- ///
- public static ElectricField Zero => new ElectricField(0, BaseUnit);
-
- ///
- /// Get ElectricField from VoltsPerMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricField FromVoltsPerMeter(double voltspermeter)
-#else
- public static ElectricField FromVoltsPerMeter(QuantityValue voltspermeter)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricField From(double value, ElectricFieldUnit fromUnit)
-#else
- public static ElectricField From(QuantityValue value, ElectricFieldUnit fromUnit)
-#endif
- {
- return new ElectricField((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricFieldUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricFieldUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricField ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricField result)
- {
- result = default(ElectricField);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricFieldUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricFieldUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricFieldUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricFieldUnit unit)
- {
- unit = ElectricFieldUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricFieldUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricFieldUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricField.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricField.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricInductance.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricInductance.Common.g.cs
deleted file mode 100644
index 2e5b239d35..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricInductance.Common.g.cs
+++ /dev/null
@@ -1,537 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// Inductance is a property of an electrical conductor which opposes a change in current.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricInductance : IQuantity
-#else
- public partial struct ElectricInductance : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricInductanceUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricInductanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricInductance()
- {
- BaseDimensions = new BaseDimensions(2, 1, -2, -2, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricInductance;
-
- ///
- /// The base unit of ElectricInductance, which is Henry. All conversions go via this value.
- ///
- public static ElectricInductanceUnit BaseUnit => ElectricInductanceUnit.Henry;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricInductance quantity.
- ///
- public static ElectricInductanceUnit[] Units { get; } = Enum.GetValues(typeof(ElectricInductanceUnit)).Cast().Except(new ElectricInductanceUnit[]{ ElectricInductanceUnit.Undefined }).ToArray();
-
- ///
- /// Get ElectricInductance in Henries.
- ///
- public double Henries => As(ElectricInductanceUnit.Henry);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Henry.
- ///
- public static ElectricInductance Zero => new ElectricInductance(0, BaseUnit);
-
- ///
- /// Get ElectricInductance from Henries.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricInductance FromHenries(double henries)
-#else
- public static ElectricInductance FromHenries(QuantityValue henries)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricInductance From(double value, ElectricInductanceUnit fromUnit)
-#else
- public static ElectricInductance From(QuantityValue value, ElectricInductanceUnit fromUnit)
-#endif
- {
- return new ElectricInductance((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricInductanceUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricInductanceUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricInductance ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricInductance result)
- {
- result = default(ElectricInductance);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricInductanceUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricInductanceUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricInductanceUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricInductanceUnit unit)
- {
- unit = ElectricInductanceUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricInductanceUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricInductanceUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricInductance.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricInductance.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricPotential.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricPotential.Common.g.cs
deleted file mode 100644
index 36d1bc9933..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricPotential.Common.g.cs
+++ /dev/null
@@ -1,625 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricPotential : IQuantity
-#else
- public partial struct ElectricPotential : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricPotentialUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricPotentialUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricPotential()
- {
- BaseDimensions = new BaseDimensions(2, 1, -3, -1, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricPotential;
-
- ///
- /// The base unit of ElectricPotential, which is Volt. All conversions go via this value.
- ///
- public static ElectricPotentialUnit BaseUnit => ElectricPotentialUnit.Volt;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricPotential quantity.
- ///
- public static ElectricPotentialUnit[] Units { get; } = Enum.GetValues(typeof(ElectricPotentialUnit)).Cast().Except(new ElectricPotentialUnit[]{ ElectricPotentialUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Volt.
- ///
- public static ElectricPotential Zero => new ElectricPotential(0, BaseUnit);
-
- ///
- /// Get ElectricPotential from Kilovolts.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotential FromKilovolts(double kilovolts)
-#else
- public static ElectricPotential FromKilovolts(QuantityValue kilovolts)
-#endif
- {
- double value = (double) kilovolts;
- return new ElectricPotential(value, ElectricPotentialUnit.Kilovolt);
- }
-
- ///
- /// Get ElectricPotential from Megavolts.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotential FromMegavolts(double megavolts)
-#else
- public static ElectricPotential FromMegavolts(QuantityValue megavolts)
-#endif
- {
- double value = (double) megavolts;
- return new ElectricPotential(value, ElectricPotentialUnit.Megavolt);
- }
-
- ///
- /// Get ElectricPotential from Microvolts.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotential FromMicrovolts(double microvolts)
-#else
- public static ElectricPotential FromMicrovolts(QuantityValue microvolts)
-#endif
- {
- double value = (double) microvolts;
- return new ElectricPotential(value, ElectricPotentialUnit.Microvolt);
- }
-
- ///
- /// Get ElectricPotential from Millivolts.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotential FromMillivolts(double millivolts)
-#else
- public static ElectricPotential FromMillivolts(QuantityValue millivolts)
-#endif
- {
- double value = (double) millivolts;
- return new ElectricPotential(value, ElectricPotentialUnit.Millivolt);
- }
-
- ///
- /// Get ElectricPotential from Volts.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotential FromVolts(double volts)
-#else
- public static ElectricPotential FromVolts(QuantityValue volts)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricPotential From(double value, ElectricPotentialUnit fromUnit)
-#else
- public static ElectricPotential From(QuantityValue value, ElectricPotentialUnit fromUnit)
-#endif
- {
- return new ElectricPotential((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricPotentialUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricPotentialUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricPotential ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricPotential result)
- {
- result = default(ElectricPotential);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricPotentialUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricPotentialUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricPotentialUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricPotentialUnit unit)
- {
- unit = ElectricPotentialUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricPotentialUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricPotentialUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricPotential.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricPotential.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricPotentialAc.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricPotentialAc.Common.g.cs
deleted file mode 100644
index 25aece9384..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricPotentialAc.Common.g.cs
+++ /dev/null
@@ -1,624 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// The Electric Potential of a system known to use Alternating Current.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricPotentialAc : IQuantity
-#else
- public partial struct ElectricPotentialAc : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricPotentialAcUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricPotentialAcUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricPotentialAc()
- {
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricPotentialAc;
-
- ///
- /// The base unit of ElectricPotentialAc, which is VoltAc. All conversions go via this value.
- ///
- public static ElectricPotentialAcUnit BaseUnit => ElectricPotentialAcUnit.VoltAc;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricPotentialAc quantity.
- ///
- public static ElectricPotentialAcUnit[] Units { get; } = Enum.GetValues(typeof(ElectricPotentialAcUnit)).Cast().Except(new ElectricPotentialAcUnit[]{ ElectricPotentialAcUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit VoltAc.
- ///
- public static ElectricPotentialAc Zero => new ElectricPotentialAc(0, BaseUnit);
-
- ///
- /// Get ElectricPotentialAc from KilovoltsAc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotentialAc FromKilovoltsAc(double kilovoltsac)
-#else
- public static ElectricPotentialAc FromKilovoltsAc(QuantityValue kilovoltsac)
-#endif
- {
- double value = (double) kilovoltsac;
- return new ElectricPotentialAc(value, ElectricPotentialAcUnit.KilovoltAc);
- }
-
- ///
- /// Get ElectricPotentialAc from MegavoltsAc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotentialAc FromMegavoltsAc(double megavoltsac)
-#else
- public static ElectricPotentialAc FromMegavoltsAc(QuantityValue megavoltsac)
-#endif
- {
- double value = (double) megavoltsac;
- return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MegavoltAc);
- }
-
- ///
- /// Get ElectricPotentialAc from MicrovoltsAc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotentialAc FromMicrovoltsAc(double microvoltsac)
-#else
- public static ElectricPotentialAc FromMicrovoltsAc(QuantityValue microvoltsac)
-#endif
- {
- double value = (double) microvoltsac;
- return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MicrovoltAc);
- }
-
- ///
- /// Get ElectricPotentialAc from MillivoltsAc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotentialAc FromMillivoltsAc(double millivoltsac)
-#else
- public static ElectricPotentialAc FromMillivoltsAc(QuantityValue millivoltsac)
-#endif
- {
- double value = (double) millivoltsac;
- return new ElectricPotentialAc(value, ElectricPotentialAcUnit.MillivoltAc);
- }
-
- ///
- /// Get ElectricPotentialAc from VoltsAc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotentialAc FromVoltsAc(double voltsac)
-#else
- public static ElectricPotentialAc FromVoltsAc(QuantityValue voltsac)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricPotentialAc From(double value, ElectricPotentialAcUnit fromUnit)
-#else
- public static ElectricPotentialAc From(QuantityValue value, ElectricPotentialAcUnit fromUnit)
-#endif
- {
- return new ElectricPotentialAc((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricPotentialAcUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricPotentialAcUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricPotentialAc ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricPotentialAc result)
- {
- result = default(ElectricPotentialAc);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricPotentialAcUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricPotentialAcUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricPotentialAcUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricPotentialAcUnit unit)
- {
- unit = ElectricPotentialAcUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricPotentialAcUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricPotentialAcUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricPotentialAc.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricPotentialAc.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricPotentialDc.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricPotentialDc.Common.g.cs
deleted file mode 100644
index 1d2005ec42..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricPotentialDc.Common.g.cs
+++ /dev/null
@@ -1,624 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// The Electric Potential of a system known to use Direct Current.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricPotentialDc : IQuantity
-#else
- public partial struct ElectricPotentialDc : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricPotentialDcUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricPotentialDcUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricPotentialDc()
- {
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricPotentialDc;
-
- ///
- /// The base unit of ElectricPotentialDc, which is VoltDc. All conversions go via this value.
- ///
- public static ElectricPotentialDcUnit BaseUnit => ElectricPotentialDcUnit.VoltDc;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricPotentialDc quantity.
- ///
- public static ElectricPotentialDcUnit[] Units { get; } = Enum.GetValues(typeof(ElectricPotentialDcUnit)).Cast().Except(new ElectricPotentialDcUnit[]{ ElectricPotentialDcUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit VoltDc.
- ///
- public static ElectricPotentialDc Zero => new ElectricPotentialDc(0, BaseUnit);
-
- ///
- /// Get ElectricPotentialDc from KilovoltsDc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotentialDc FromKilovoltsDc(double kilovoltsdc)
-#else
- public static ElectricPotentialDc FromKilovoltsDc(QuantityValue kilovoltsdc)
-#endif
- {
- double value = (double) kilovoltsdc;
- return new ElectricPotentialDc(value, ElectricPotentialDcUnit.KilovoltDc);
- }
-
- ///
- /// Get ElectricPotentialDc from MegavoltsDc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotentialDc FromMegavoltsDc(double megavoltsdc)
-#else
- public static ElectricPotentialDc FromMegavoltsDc(QuantityValue megavoltsdc)
-#endif
- {
- double value = (double) megavoltsdc;
- return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MegavoltDc);
- }
-
- ///
- /// Get ElectricPotentialDc from MicrovoltsDc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotentialDc FromMicrovoltsDc(double microvoltsdc)
-#else
- public static ElectricPotentialDc FromMicrovoltsDc(QuantityValue microvoltsdc)
-#endif
- {
- double value = (double) microvoltsdc;
- return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MicrovoltDc);
- }
-
- ///
- /// Get ElectricPotentialDc from MillivoltsDc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotentialDc FromMillivoltsDc(double millivoltsdc)
-#else
- public static ElectricPotentialDc FromMillivoltsDc(QuantityValue millivoltsdc)
-#endif
- {
- double value = (double) millivoltsdc;
- return new ElectricPotentialDc(value, ElectricPotentialDcUnit.MillivoltDc);
- }
-
- ///
- /// Get ElectricPotentialDc from VoltsDc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricPotentialDc FromVoltsDc(double voltsdc)
-#else
- public static ElectricPotentialDc FromVoltsDc(QuantityValue voltsdc)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricPotentialDc From(double value, ElectricPotentialDcUnit fromUnit)
-#else
- public static ElectricPotentialDc From(QuantityValue value, ElectricPotentialDcUnit fromUnit)
-#endif
- {
- return new ElectricPotentialDc((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricPotentialDcUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricPotentialDcUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricPotentialDc ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricPotentialDc result)
- {
- result = default(ElectricPotentialDc);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricPotentialDcUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricPotentialDcUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricPotentialDcUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricPotentialDcUnit unit)
- {
- unit = ElectricPotentialDcUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricPotentialDcUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricPotentialDcUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricPotentialDc.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricPotentialDc.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricResistance.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricResistance.Common.g.cs
deleted file mode 100644
index 45f27e3218..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricResistance.Common.g.cs
+++ /dev/null
@@ -1,603 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricResistance : IQuantity
-#else
- public partial struct ElectricResistance : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricResistanceUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricResistanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricResistance()
- {
- BaseDimensions = new BaseDimensions(2, 1, -3, -2, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricResistance;
-
- ///
- /// The base unit of ElectricResistance, which is Ohm. All conversions go via this value.
- ///
- public static ElectricResistanceUnit BaseUnit => ElectricResistanceUnit.Ohm;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricResistance quantity.
- ///
- public static ElectricResistanceUnit[] Units { get; } = Enum.GetValues(typeof(ElectricResistanceUnit)).Cast().Except(new ElectricResistanceUnit[]{ ElectricResistanceUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Ohm.
- ///
- public static ElectricResistance Zero => new ElectricResistance(0, BaseUnit);
-
- ///
- /// Get ElectricResistance from Kiloohms.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricResistance FromKiloohms(double kiloohms)
-#else
- public static ElectricResistance FromKiloohms(QuantityValue kiloohms)
-#endif
- {
- double value = (double) kiloohms;
- return new ElectricResistance(value, ElectricResistanceUnit.Kiloohm);
- }
-
- ///
- /// Get ElectricResistance from Megaohms.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricResistance FromMegaohms(double megaohms)
-#else
- public static ElectricResistance FromMegaohms(QuantityValue megaohms)
-#endif
- {
- double value = (double) megaohms;
- return new ElectricResistance(value, ElectricResistanceUnit.Megaohm);
- }
-
- ///
- /// Get ElectricResistance from Milliohms.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricResistance FromMilliohms(double milliohms)
-#else
- public static ElectricResistance FromMilliohms(QuantityValue milliohms)
-#endif
- {
- double value = (double) milliohms;
- return new ElectricResistance(value, ElectricResistanceUnit.Milliohm);
- }
-
- ///
- /// Get ElectricResistance from Ohms.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricResistance FromOhms(double ohms)
-#else
- public static ElectricResistance FromOhms(QuantityValue ohms)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricResistance From(double value, ElectricResistanceUnit fromUnit)
-#else
- public static ElectricResistance From(QuantityValue value, ElectricResistanceUnit fromUnit)
-#endif
- {
- return new ElectricResistance((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricResistanceUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricResistanceUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricResistance ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricResistance result)
- {
- result = default(ElectricResistance);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricResistanceUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricResistanceUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricResistanceUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricResistanceUnit unit)
- {
- unit = ElectricResistanceUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricResistanceUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricResistanceUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricResistance.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricResistance.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ElectricResistivity.Common.g.cs b/Common/GeneratedCode/Quantities/ElectricResistivity.Common.g.cs
deleted file mode 100644
index bc1a12ad0c..0000000000
--- a/Common/GeneratedCode/Quantities/ElectricResistivity.Common.g.cs
+++ /dev/null
@@ -1,603 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ElectricResistivity : IQuantity
-#else
- public partial struct ElectricResistivity : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ElectricResistivityUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ElectricResistivityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ElectricResistivity()
- {
- BaseDimensions = new BaseDimensions(3, 1, -3, -2, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ElectricResistivity;
-
- ///
- /// The base unit of ElectricResistivity, which is OhmMeter. All conversions go via this value.
- ///
- public static ElectricResistivityUnit BaseUnit => ElectricResistivityUnit.OhmMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ElectricResistivity quantity.
- ///
- public static ElectricResistivityUnit[] Units { get; } = Enum.GetValues(typeof(ElectricResistivityUnit)).Cast().Except(new ElectricResistivityUnit[]{ ElectricResistivityUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit OhmMeter.
- ///
- public static ElectricResistivity Zero => new ElectricResistivity(0, BaseUnit);
-
- ///
- /// Get ElectricResistivity from MicroohmMeters.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricResistivity FromMicroohmMeters(double microohmmeters)
-#else
- public static ElectricResistivity FromMicroohmMeters(QuantityValue microohmmeters)
-#endif
- {
- double value = (double) microohmmeters;
- return new ElectricResistivity(value, ElectricResistivityUnit.MicroohmMeter);
- }
-
- ///
- /// Get ElectricResistivity from MilliohmMeters.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricResistivity FromMilliohmMeters(double milliohmmeters)
-#else
- public static ElectricResistivity FromMilliohmMeters(QuantityValue milliohmmeters)
-#endif
- {
- double value = (double) milliohmmeters;
- return new ElectricResistivity(value, ElectricResistivityUnit.MilliohmMeter);
- }
-
- ///
- /// Get ElectricResistivity from NanoohmMeters.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricResistivity FromNanoohmMeters(double nanoohmmeters)
-#else
- public static ElectricResistivity FromNanoohmMeters(QuantityValue nanoohmmeters)
-#endif
- {
- double value = (double) nanoohmmeters;
- return new ElectricResistivity(value, ElectricResistivityUnit.NanoohmMeter);
- }
-
- ///
- /// Get ElectricResistivity from OhmMeters.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ElectricResistivity FromOhmMeters(double ohmmeters)
-#else
- public static ElectricResistivity FromOhmMeters(QuantityValue ohmmeters)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ElectricResistivity From(double value, ElectricResistivityUnit fromUnit)
-#else
- public static ElectricResistivity From(QuantityValue value, ElectricResistivityUnit fromUnit)
-#endif
- {
- return new ElectricResistivity((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ElectricResistivityUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ElectricResistivityUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ElectricResistivity ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ElectricResistivity result)
- {
- result = default(ElectricResistivity);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ElectricResistivityUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ElectricResistivityUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ElectricResistivityUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ElectricResistivityUnit unit)
- {
- unit = ElectricResistivityUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ElectricResistivityUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ElectricResistivityUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ElectricResistivity.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ElectricResistivity.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Energy.Common.g.cs b/Common/GeneratedCode/Quantities/Energy.Common.g.cs
deleted file mode 100644
index 679d4ecf0e..0000000000
--- a/Common/GeneratedCode/Quantities/Energy.Common.g.cs
+++ /dev/null
@@ -1,999 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Energy : IQuantity
-#else
- public partial struct Energy : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly EnergyUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public EnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Energy()
- {
- BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Energy;
-
- ///
- /// The base unit of Energy, which is Joule. All conversions go via this value.
- ///
- public static EnergyUnit BaseUnit => EnergyUnit.Joule;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Energy quantity.
- ///
- public static EnergyUnit[] Units { get; } = Enum.GetValues(typeof(EnergyUnit)).Cast().Except(new EnergyUnit[]{ EnergyUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Joule.
- ///
- public static Energy Zero => new Energy(0, BaseUnit);
-
- ///
- /// Get Energy from BritishThermalUnits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromBritishThermalUnits(double britishthermalunits)
-#else
- public static Energy FromBritishThermalUnits(QuantityValue britishthermalunits)
-#endif
- {
- double value = (double) britishthermalunits;
- return new Energy(value, EnergyUnit.BritishThermalUnit);
- }
-
- ///
- /// Get Energy from Calories.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromCalories(double calories)
-#else
- public static Energy FromCalories(QuantityValue calories)
-#endif
- {
- double value = (double) calories;
- return new Energy(value, EnergyUnit.Calorie);
- }
-
- ///
- /// Get Energy from DecathermsEc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromDecathermsEc(double decathermsec)
-#else
- public static Energy FromDecathermsEc(QuantityValue decathermsec)
-#endif
- {
- double value = (double) decathermsec;
- return new Energy(value, EnergyUnit.DecathermEc);
- }
-
- ///
- /// Get Energy from DecathermsImperial.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromDecathermsImperial(double decathermsimperial)
-#else
- public static Energy FromDecathermsImperial(QuantityValue decathermsimperial)
-#endif
- {
- double value = (double) decathermsimperial;
- return new Energy(value, EnergyUnit.DecathermImperial);
- }
-
- ///
- /// Get Energy from DecathermsUs.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromDecathermsUs(double decathermsus)
-#else
- public static Energy FromDecathermsUs(QuantityValue decathermsus)
-#endif
- {
- double value = (double) decathermsus;
- return new Energy(value, EnergyUnit.DecathermUs);
- }
-
- ///
- /// Get Energy from ElectronVolts.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromElectronVolts(double electronvolts)
-#else
- public static Energy FromElectronVolts(QuantityValue electronvolts)
-#endif
- {
- double value = (double) electronvolts;
- return new Energy(value, EnergyUnit.ElectronVolt);
- }
-
- ///
- /// Get Energy from Ergs.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromErgs(double ergs)
-#else
- public static Energy FromErgs(QuantityValue ergs)
-#endif
- {
- double value = (double) ergs;
- return new Energy(value, EnergyUnit.Erg);
- }
-
- ///
- /// Get Energy from FootPounds.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromFootPounds(double footpounds)
-#else
- public static Energy FromFootPounds(QuantityValue footpounds)
-#endif
- {
- double value = (double) footpounds;
- return new Energy(value, EnergyUnit.FootPound);
- }
-
- ///
- /// Get Energy from GigabritishThermalUnits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromGigabritishThermalUnits(double gigabritishthermalunits)
-#else
- public static Energy FromGigabritishThermalUnits(QuantityValue gigabritishthermalunits)
-#endif
- {
- double value = (double) gigabritishthermalunits;
- return new Energy(value, EnergyUnit.GigabritishThermalUnit);
- }
-
- ///
- /// Get Energy from GigawattHours.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromGigawattHours(double gigawatthours)
-#else
- public static Energy FromGigawattHours(QuantityValue gigawatthours)
-#endif
- {
- double value = (double) gigawatthours;
- return new Energy(value, EnergyUnit.GigawattHour);
- }
-
- ///
- /// Get Energy from Joules.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromJoules(double joules)
-#else
- public static Energy FromJoules(QuantityValue joules)
-#endif
- {
- double value = (double) joules;
- return new Energy(value, EnergyUnit.Joule);
- }
-
- ///
- /// Get Energy from KilobritishThermalUnits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromKilobritishThermalUnits(double kilobritishthermalunits)
-#else
- public static Energy FromKilobritishThermalUnits(QuantityValue kilobritishthermalunits)
-#endif
- {
- double value = (double) kilobritishthermalunits;
- return new Energy(value, EnergyUnit.KilobritishThermalUnit);
- }
-
- ///
- /// Get Energy from Kilocalories.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromKilocalories(double kilocalories)
-#else
- public static Energy FromKilocalories(QuantityValue kilocalories)
-#endif
- {
- double value = (double) kilocalories;
- return new Energy(value, EnergyUnit.Kilocalorie);
- }
-
- ///
- /// Get Energy from Kilojoules.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromKilojoules(double kilojoules)
-#else
- public static Energy FromKilojoules(QuantityValue kilojoules)
-#endif
- {
- double value = (double) kilojoules;
- return new Energy(value, EnergyUnit.Kilojoule);
- }
-
- ///
- /// Get Energy from KilowattHours.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromKilowattHours(double kilowatthours)
-#else
- public static Energy FromKilowattHours(QuantityValue kilowatthours)
-#endif
- {
- double value = (double) kilowatthours;
- return new Energy(value, EnergyUnit.KilowattHour);
- }
-
- ///
- /// Get Energy from MegabritishThermalUnits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromMegabritishThermalUnits(double megabritishthermalunits)
-#else
- public static Energy FromMegabritishThermalUnits(QuantityValue megabritishthermalunits)
-#endif
- {
- double value = (double) megabritishthermalunits;
- return new Energy(value, EnergyUnit.MegabritishThermalUnit);
- }
-
- ///
- /// Get Energy from Megajoules.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromMegajoules(double megajoules)
-#else
- public static Energy FromMegajoules(QuantityValue megajoules)
-#endif
- {
- double value = (double) megajoules;
- return new Energy(value, EnergyUnit.Megajoule);
- }
-
- ///
- /// Get Energy from MegawattHours.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromMegawattHours(double megawatthours)
-#else
- public static Energy FromMegawattHours(QuantityValue megawatthours)
-#endif
- {
- double value = (double) megawatthours;
- return new Energy(value, EnergyUnit.MegawattHour);
- }
-
- ///
- /// Get Energy from ThermsEc.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromThermsEc(double thermsec)
-#else
- public static Energy FromThermsEc(QuantityValue thermsec)
-#endif
- {
- double value = (double) thermsec;
- return new Energy(value, EnergyUnit.ThermEc);
- }
-
- ///
- /// Get Energy from ThermsImperial.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromThermsImperial(double thermsimperial)
-#else
- public static Energy FromThermsImperial(QuantityValue thermsimperial)
-#endif
- {
- double value = (double) thermsimperial;
- return new Energy(value, EnergyUnit.ThermImperial);
- }
-
- ///
- /// Get Energy from ThermsUs.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromThermsUs(double thermsus)
-#else
- public static Energy FromThermsUs(QuantityValue thermsus)
-#endif
- {
- double value = (double) thermsus;
- return new Energy(value, EnergyUnit.ThermUs);
- }
-
- ///
- /// Get Energy from WattHours.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Energy FromWattHours(double watthours)
-#else
- public static Energy FromWattHours(QuantityValue watthours)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Energy From(double value, EnergyUnit fromUnit)
-#else
- public static Energy From(QuantityValue value, EnergyUnit fromUnit)
-#endif
- {
- return new Energy((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(EnergyUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out EnergyUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Energy ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Energy result)
- {
- result = default(Energy);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static EnergyUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == EnergyUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized EnergyUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out EnergyUnit unit)
- {
- unit = EnergyUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == EnergyUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(EnergyUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Energy.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Energy.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Entropy.Common.g.cs b/Common/GeneratedCode/Quantities/Entropy.Common.g.cs
deleted file mode 100644
index d2b8047b4a..0000000000
--- a/Common/GeneratedCode/Quantities/Entropy.Common.g.cs
+++ /dev/null
@@ -1,669 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Entropy : IQuantity
-#else
- public partial struct Entropy : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly EntropyUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public EntropyUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Entropy()
- {
- BaseDimensions = new BaseDimensions(2, 1, -2, 0, -1, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Entropy;
-
- ///
- /// The base unit of Entropy, which is JoulePerKelvin. All conversions go via this value.
- ///
- public static EntropyUnit BaseUnit => EntropyUnit.JoulePerKelvin;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Entropy quantity.
- ///
- public static EntropyUnit[] Units { get; } = Enum.GetValues(typeof(EntropyUnit)).Cast().Except(new EntropyUnit[]{ EntropyUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerKelvin.
- ///
- public static Entropy Zero => new Entropy(0, BaseUnit);
-
- ///
- /// Get Entropy from CaloriesPerKelvin.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Entropy FromCaloriesPerKelvin(double caloriesperkelvin)
-#else
- public static Entropy FromCaloriesPerKelvin(QuantityValue caloriesperkelvin)
-#endif
- {
- double value = (double) caloriesperkelvin;
- return new Entropy(value, EntropyUnit.CaloriePerKelvin);
- }
-
- ///
- /// Get Entropy from JoulesPerDegreeCelsius.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Entropy FromJoulesPerDegreeCelsius(double joulesperdegreecelsius)
-#else
- public static Entropy FromJoulesPerDegreeCelsius(QuantityValue joulesperdegreecelsius)
-#endif
- {
- double value = (double) joulesperdegreecelsius;
- return new Entropy(value, EntropyUnit.JoulePerDegreeCelsius);
- }
-
- ///
- /// Get Entropy from JoulesPerKelvin.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Entropy FromJoulesPerKelvin(double joulesperkelvin)
-#else
- public static Entropy FromJoulesPerKelvin(QuantityValue joulesperkelvin)
-#endif
- {
- double value = (double) joulesperkelvin;
- return new Entropy(value, EntropyUnit.JoulePerKelvin);
- }
-
- ///
- /// Get Entropy from KilocaloriesPerKelvin.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Entropy FromKilocaloriesPerKelvin(double kilocaloriesperkelvin)
-#else
- public static Entropy FromKilocaloriesPerKelvin(QuantityValue kilocaloriesperkelvin)
-#endif
- {
- double value = (double) kilocaloriesperkelvin;
- return new Entropy(value, EntropyUnit.KilocaloriePerKelvin);
- }
-
- ///
- /// Get Entropy from KilojoulesPerDegreeCelsius.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Entropy FromKilojoulesPerDegreeCelsius(double kilojoulesperdegreecelsius)
-#else
- public static Entropy FromKilojoulesPerDegreeCelsius(QuantityValue kilojoulesperdegreecelsius)
-#endif
- {
- double value = (double) kilojoulesperdegreecelsius;
- return new Entropy(value, EntropyUnit.KilojoulePerDegreeCelsius);
- }
-
- ///
- /// Get Entropy from KilojoulesPerKelvin.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Entropy FromKilojoulesPerKelvin(double kilojoulesperkelvin)
-#else
- public static Entropy FromKilojoulesPerKelvin(QuantityValue kilojoulesperkelvin)
-#endif
- {
- double value = (double) kilojoulesperkelvin;
- return new Entropy(value, EntropyUnit.KilojoulePerKelvin);
- }
-
- ///
- /// Get Entropy from MegajoulesPerKelvin.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Entropy FromMegajoulesPerKelvin(double megajoulesperkelvin)
-#else
- public static Entropy FromMegajoulesPerKelvin(QuantityValue megajoulesperkelvin)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Entropy From(double value, EntropyUnit fromUnit)
-#else
- public static Entropy From(QuantityValue value, EntropyUnit fromUnit)
-#endif
- {
- return new Entropy((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(EntropyUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out EntropyUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Entropy ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Entropy result)
- {
- result = default(Entropy);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static EntropyUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == EntropyUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized EntropyUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out EntropyUnit unit)
- {
- unit = EntropyUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == EntropyUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(EntropyUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Entropy.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Entropy.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Force.Common.g.cs b/Common/GeneratedCode/Quantities/Force.Common.g.cs
deleted file mode 100644
index 527bd45208..0000000000
--- a/Common/GeneratedCode/Quantities/Force.Common.g.cs
+++ /dev/null
@@ -1,735 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Force : IQuantity
-#else
- public partial struct Force : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ForceUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ForceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Force()
- {
- BaseDimensions = new BaseDimensions(1, 1, -2, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Force;
-
- ///
- /// The base unit of Force, which is Newton. All conversions go via this value.
- ///
- public static ForceUnit BaseUnit => ForceUnit.Newton;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Force quantity.
- ///
- public static ForceUnit[] Units { get; } = Enum.GetValues(typeof(ForceUnit)).Cast().Except(new ForceUnit[]{ ForceUnit.Undefined }).ToArray();
-
- ///
- /// 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 Newtons.
- ///
- public double Newtons => As(ForceUnit.Newton);
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Newton.
- ///
- public static Force Zero => new Force(0, BaseUnit);
-
- ///
- /// Get Force from Decanewtons.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Force FromDecanewtons(double decanewtons)
-#else
- public static Force FromDecanewtons(QuantityValue decanewtons)
-#endif
- {
- double value = (double) decanewtons;
- return new Force(value, ForceUnit.Decanewton);
- }
-
- ///
- /// Get Force from Dyne.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Force FromDyne(double dyne)
-#else
- public static Force FromDyne(QuantityValue dyne)
-#endif
- {
- double value = (double) dyne;
- return new Force(value, ForceUnit.Dyn);
- }
-
- ///
- /// Get Force from KilogramsForce.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Force FromKilogramsForce(double kilogramsforce)
-#else
- public static Force FromKilogramsForce(QuantityValue kilogramsforce)
-#endif
- {
- double value = (double) kilogramsforce;
- return new Force(value, ForceUnit.KilogramForce);
- }
-
- ///
- /// Get Force from Kilonewtons.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Force FromKilonewtons(double kilonewtons)
-#else
- public static Force FromKilonewtons(QuantityValue kilonewtons)
-#endif
- {
- double value = (double) kilonewtons;
- return new Force(value, ForceUnit.Kilonewton);
- }
-
- ///
- /// Get Force from KiloPonds.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Force FromKiloPonds(double kiloponds)
-#else
- public static Force FromKiloPonds(QuantityValue kiloponds)
-#endif
- {
- double value = (double) kiloponds;
- return new Force(value, ForceUnit.KiloPond);
- }
-
- ///
- /// Get Force from Meganewtons.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Force FromMeganewtons(double meganewtons)
-#else
- public static Force FromMeganewtons(QuantityValue meganewtons)
-#endif
- {
- double value = (double) meganewtons;
- return new Force(value, ForceUnit.Meganewton);
- }
-
- ///
- /// Get Force from Newtons.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Force FromNewtons(double newtons)
-#else
- public static Force FromNewtons(QuantityValue newtons)
-#endif
- {
- double value = (double) newtons;
- return new Force(value, ForceUnit.Newton);
- }
-
- ///
- /// Get Force from Poundals.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Force FromPoundals(double poundals)
-#else
- public static Force FromPoundals(QuantityValue poundals)
-#endif
- {
- double value = (double) poundals;
- return new Force(value, ForceUnit.Poundal);
- }
-
- ///
- /// Get Force from PoundsForce.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Force FromPoundsForce(double poundsforce)
-#else
- public static Force FromPoundsForce(QuantityValue poundsforce)
-#endif
- {
- double value = (double) poundsforce;
- return new Force(value, ForceUnit.PoundForce);
- }
-
- ///
- /// Get Force from TonnesForce.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Force FromTonnesForce(double tonnesforce)
-#else
- public static Force FromTonnesForce(QuantityValue tonnesforce)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Force From(double value, ForceUnit fromUnit)
-#else
- public static Force From(QuantityValue value, ForceUnit fromUnit)
-#endif
- {
- return new Force((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ForceUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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.Newton: return _value;
- 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.Newton: return baseUnitValue;
- 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ForceUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Force ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Force result)
- {
- result = default(Force);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ForceUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ForceUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ForceUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ForceUnit unit)
- {
- unit = ForceUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ForceUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ForceUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Force.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Force.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ForceChangeRate.Common.g.cs b/Common/GeneratedCode/Quantities/ForceChangeRate.Common.g.cs
deleted file mode 100644
index 9c1f7f2341..0000000000
--- a/Common/GeneratedCode/Quantities/ForceChangeRate.Common.g.cs
+++ /dev/null
@@ -1,757 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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).
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ForceChangeRate : IQuantity
-#else
- public partial struct ForceChangeRate : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ForceChangeRateUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ForceChangeRateUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ForceChangeRate()
- {
- BaseDimensions = new BaseDimensions(1, 1, -3, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ForceChangeRate;
-
- ///
- /// The base unit of ForceChangeRate, which is NewtonPerSecond. All conversions go via this value.
- ///
- public static ForceChangeRateUnit BaseUnit => ForceChangeRateUnit.NewtonPerSecond;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ForceChangeRate quantity.
- ///
- public static ForceChangeRateUnit[] Units { get; } = Enum.GetValues(typeof(ForceChangeRateUnit)).Cast().Except(new ForceChangeRateUnit[]{ ForceChangeRateUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit NewtonPerSecond.
- ///
- public static ForceChangeRate Zero => new ForceChangeRate(0, BaseUnit);
-
- ///
- /// Get ForceChangeRate from CentinewtonsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForceChangeRate FromCentinewtonsPerSecond(double centinewtonspersecond)
-#else
- public static ForceChangeRate FromCentinewtonsPerSecond(QuantityValue centinewtonspersecond)
-#endif
- {
- double value = (double) centinewtonspersecond;
- return new ForceChangeRate(value, ForceChangeRateUnit.CentinewtonPerSecond);
- }
-
- ///
- /// Get ForceChangeRate from DecanewtonsPerMinute.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForceChangeRate FromDecanewtonsPerMinute(double decanewtonsperminute)
-#else
- public static ForceChangeRate FromDecanewtonsPerMinute(QuantityValue decanewtonsperminute)
-#endif
- {
- double value = (double) decanewtonsperminute;
- return new ForceChangeRate(value, ForceChangeRateUnit.DecanewtonPerMinute);
- }
-
- ///
- /// Get ForceChangeRate from DecanewtonsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForceChangeRate FromDecanewtonsPerSecond(double decanewtonspersecond)
-#else
- public static ForceChangeRate FromDecanewtonsPerSecond(QuantityValue decanewtonspersecond)
-#endif
- {
- double value = (double) decanewtonspersecond;
- return new ForceChangeRate(value, ForceChangeRateUnit.DecanewtonPerSecond);
- }
-
- ///
- /// Get ForceChangeRate from DecinewtonsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForceChangeRate FromDecinewtonsPerSecond(double decinewtonspersecond)
-#else
- public static ForceChangeRate FromDecinewtonsPerSecond(QuantityValue decinewtonspersecond)
-#endif
- {
- double value = (double) decinewtonspersecond;
- return new ForceChangeRate(value, ForceChangeRateUnit.DecinewtonPerSecond);
- }
-
- ///
- /// Get ForceChangeRate from KilonewtonsPerMinute.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForceChangeRate FromKilonewtonsPerMinute(double kilonewtonsperminute)
-#else
- public static ForceChangeRate FromKilonewtonsPerMinute(QuantityValue kilonewtonsperminute)
-#endif
- {
- double value = (double) kilonewtonsperminute;
- return new ForceChangeRate(value, ForceChangeRateUnit.KilonewtonPerMinute);
- }
-
- ///
- /// Get ForceChangeRate from KilonewtonsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForceChangeRate FromKilonewtonsPerSecond(double kilonewtonspersecond)
-#else
- public static ForceChangeRate FromKilonewtonsPerSecond(QuantityValue kilonewtonspersecond)
-#endif
- {
- double value = (double) kilonewtonspersecond;
- return new ForceChangeRate(value, ForceChangeRateUnit.KilonewtonPerSecond);
- }
-
- ///
- /// Get ForceChangeRate from MicronewtonsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForceChangeRate FromMicronewtonsPerSecond(double micronewtonspersecond)
-#else
- public static ForceChangeRate FromMicronewtonsPerSecond(QuantityValue micronewtonspersecond)
-#endif
- {
- double value = (double) micronewtonspersecond;
- return new ForceChangeRate(value, ForceChangeRateUnit.MicronewtonPerSecond);
- }
-
- ///
- /// Get ForceChangeRate from MillinewtonsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForceChangeRate FromMillinewtonsPerSecond(double millinewtonspersecond)
-#else
- public static ForceChangeRate FromMillinewtonsPerSecond(QuantityValue millinewtonspersecond)
-#endif
- {
- double value = (double) millinewtonspersecond;
- return new ForceChangeRate(value, ForceChangeRateUnit.MillinewtonPerSecond);
- }
-
- ///
- /// Get ForceChangeRate from NanonewtonsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForceChangeRate FromNanonewtonsPerSecond(double nanonewtonspersecond)
-#else
- public static ForceChangeRate FromNanonewtonsPerSecond(QuantityValue nanonewtonspersecond)
-#endif
- {
- double value = (double) nanonewtonspersecond;
- return new ForceChangeRate(value, ForceChangeRateUnit.NanonewtonPerSecond);
- }
-
- ///
- /// Get ForceChangeRate from NewtonsPerMinute.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForceChangeRate FromNewtonsPerMinute(double newtonsperminute)
-#else
- public static ForceChangeRate FromNewtonsPerMinute(QuantityValue newtonsperminute)
-#endif
- {
- double value = (double) newtonsperminute;
- return new ForceChangeRate(value, ForceChangeRateUnit.NewtonPerMinute);
- }
-
- ///
- /// Get ForceChangeRate from NewtonsPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForceChangeRate FromNewtonsPerSecond(double newtonspersecond)
-#else
- public static ForceChangeRate FromNewtonsPerSecond(QuantityValue newtonspersecond)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ForceChangeRate From(double value, ForceChangeRateUnit fromUnit)
-#else
- public static ForceChangeRate From(QuantityValue value, ForceChangeRateUnit fromUnit)
-#endif
- {
- return new ForceChangeRate((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ForceChangeRateUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ForceChangeRateUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ForceChangeRate ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ForceChangeRate result)
- {
- result = default(ForceChangeRate);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ForceChangeRateUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ForceChangeRateUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ForceChangeRateUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ForceChangeRateUnit unit)
- {
- unit = ForceChangeRateUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ForceChangeRateUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ForceChangeRateUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ForceChangeRate.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ForceChangeRate.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/ForcePerLength.Common.g.cs b/Common/GeneratedCode/Quantities/ForcePerLength.Common.g.cs
deleted file mode 100644
index a4099b4aa0..0000000000
--- a/Common/GeneratedCode/Quantities/ForcePerLength.Common.g.cs
+++ /dev/null
@@ -1,713 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// The magnitude of force per unit length.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class ForcePerLength : IQuantity
-#else
- public partial struct ForcePerLength : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly ForcePerLengthUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public ForcePerLengthUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static ForcePerLength()
- {
- BaseDimensions = new BaseDimensions(0, 1, -2, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.ForcePerLength;
-
- ///
- /// The base unit of ForcePerLength, which is NewtonPerMeter. All conversions go via this value.
- ///
- public static ForcePerLengthUnit BaseUnit => ForcePerLengthUnit.NewtonPerMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the ForcePerLength quantity.
- ///
- public static ForcePerLengthUnit[] Units { get; } = Enum.GetValues(typeof(ForcePerLengthUnit)).Cast().Except(new ForcePerLengthUnit[]{ ForcePerLengthUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit NewtonPerMeter.
- ///
- public static ForcePerLength Zero => new ForcePerLength(0, BaseUnit);
-
- ///
- /// Get ForcePerLength from CentinewtonsPerMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForcePerLength FromCentinewtonsPerMeter(double centinewtonspermeter)
-#else
- public static ForcePerLength FromCentinewtonsPerMeter(QuantityValue centinewtonspermeter)
-#endif
- {
- double value = (double) centinewtonspermeter;
- return new ForcePerLength(value, ForcePerLengthUnit.CentinewtonPerMeter);
- }
-
- ///
- /// Get ForcePerLength from DecinewtonsPerMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForcePerLength FromDecinewtonsPerMeter(double decinewtonspermeter)
-#else
- public static ForcePerLength FromDecinewtonsPerMeter(QuantityValue decinewtonspermeter)
-#endif
- {
- double value = (double) decinewtonspermeter;
- return new ForcePerLength(value, ForcePerLengthUnit.DecinewtonPerMeter);
- }
-
- ///
- /// Get ForcePerLength from KilogramsForcePerMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForcePerLength FromKilogramsForcePerMeter(double kilogramsforcepermeter)
-#else
- public static ForcePerLength FromKilogramsForcePerMeter(QuantityValue kilogramsforcepermeter)
-#endif
- {
- double value = (double) kilogramsforcepermeter;
- return new ForcePerLength(value, ForcePerLengthUnit.KilogramForcePerMeter);
- }
-
- ///
- /// Get ForcePerLength from KilonewtonsPerMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForcePerLength FromKilonewtonsPerMeter(double kilonewtonspermeter)
-#else
- public static ForcePerLength FromKilonewtonsPerMeter(QuantityValue kilonewtonspermeter)
-#endif
- {
- double value = (double) kilonewtonspermeter;
- return new ForcePerLength(value, ForcePerLengthUnit.KilonewtonPerMeter);
- }
-
- ///
- /// Get ForcePerLength from MeganewtonsPerMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForcePerLength FromMeganewtonsPerMeter(double meganewtonspermeter)
-#else
- public static ForcePerLength FromMeganewtonsPerMeter(QuantityValue meganewtonspermeter)
-#endif
- {
- double value = (double) meganewtonspermeter;
- return new ForcePerLength(value, ForcePerLengthUnit.MeganewtonPerMeter);
- }
-
- ///
- /// Get ForcePerLength from MicronewtonsPerMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForcePerLength FromMicronewtonsPerMeter(double micronewtonspermeter)
-#else
- public static ForcePerLength FromMicronewtonsPerMeter(QuantityValue micronewtonspermeter)
-#endif
- {
- double value = (double) micronewtonspermeter;
- return new ForcePerLength(value, ForcePerLengthUnit.MicronewtonPerMeter);
- }
-
- ///
- /// Get ForcePerLength from MillinewtonsPerMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForcePerLength FromMillinewtonsPerMeter(double millinewtonspermeter)
-#else
- public static ForcePerLength FromMillinewtonsPerMeter(QuantityValue millinewtonspermeter)
-#endif
- {
- double value = (double) millinewtonspermeter;
- return new ForcePerLength(value, ForcePerLengthUnit.MillinewtonPerMeter);
- }
-
- ///
- /// Get ForcePerLength from NanonewtonsPerMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForcePerLength FromNanonewtonsPerMeter(double nanonewtonspermeter)
-#else
- public static ForcePerLength FromNanonewtonsPerMeter(QuantityValue nanonewtonspermeter)
-#endif
- {
- double value = (double) nanonewtonspermeter;
- return new ForcePerLength(value, ForcePerLengthUnit.NanonewtonPerMeter);
- }
-
- ///
- /// Get ForcePerLength from NewtonsPerMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static ForcePerLength FromNewtonsPerMeter(double newtonspermeter)
-#else
- public static ForcePerLength FromNewtonsPerMeter(QuantityValue newtonspermeter)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static ForcePerLength From(double value, ForcePerLengthUnit fromUnit)
-#else
- public static ForcePerLength From(QuantityValue value, ForcePerLengthUnit fromUnit)
-#endif
- {
- return new ForcePerLength((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(ForcePerLengthUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out ForcePerLengthUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static ForcePerLength ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out ForcePerLength result)
- {
- result = default(ForcePerLength);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static ForcePerLengthUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == ForcePerLengthUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized ForcePerLengthUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out ForcePerLengthUnit unit)
- {
- unit = ForcePerLengthUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == ForcePerLengthUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(ForcePerLengthUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => ForcePerLength.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => ForcePerLength.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Frequency.Common.g.cs b/Common/GeneratedCode/Quantities/Frequency.Common.g.cs
deleted file mode 100644
index b9f4b25715..0000000000
--- a/Common/GeneratedCode/Quantities/Frequency.Common.g.cs
+++ /dev/null
@@ -1,691 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// The number of occurrences of a repeating event per unit time.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Frequency : IQuantity
-#else
- public partial struct Frequency : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly FrequencyUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public FrequencyUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Frequency()
- {
- BaseDimensions = new BaseDimensions(0, 0, -1, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Frequency;
-
- ///
- /// The base unit of Frequency, which is Hertz. All conversions go via this value.
- ///
- public static FrequencyUnit BaseUnit => FrequencyUnit.Hertz;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Frequency quantity.
- ///
- public static FrequencyUnit[] Units { get; } = Enum.GetValues(typeof(FrequencyUnit)).Cast().Except(new FrequencyUnit[]{ FrequencyUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Hertz.
- ///
- public static Frequency Zero => new Frequency(0, BaseUnit);
-
- ///
- /// Get Frequency from CyclesPerHour.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Frequency FromCyclesPerHour(double cyclesperhour)
-#else
- public static Frequency FromCyclesPerHour(QuantityValue cyclesperhour)
-#endif
- {
- double value = (double) cyclesperhour;
- return new Frequency(value, FrequencyUnit.CyclePerHour);
- }
-
- ///
- /// Get Frequency from CyclesPerMinute.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Frequency FromCyclesPerMinute(double cyclesperminute)
-#else
- public static Frequency FromCyclesPerMinute(QuantityValue cyclesperminute)
-#endif
- {
- double value = (double) cyclesperminute;
- return new Frequency(value, FrequencyUnit.CyclePerMinute);
- }
-
- ///
- /// Get Frequency from Gigahertz.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Frequency FromGigahertz(double gigahertz)
-#else
- public static Frequency FromGigahertz(QuantityValue gigahertz)
-#endif
- {
- double value = (double) gigahertz;
- return new Frequency(value, FrequencyUnit.Gigahertz);
- }
-
- ///
- /// Get Frequency from Hertz.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Frequency FromHertz(double hertz)
-#else
- public static Frequency FromHertz(QuantityValue hertz)
-#endif
- {
- double value = (double) hertz;
- return new Frequency(value, FrequencyUnit.Hertz);
- }
-
- ///
- /// Get Frequency from Kilohertz.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Frequency FromKilohertz(double kilohertz)
-#else
- public static Frequency FromKilohertz(QuantityValue kilohertz)
-#endif
- {
- double value = (double) kilohertz;
- return new Frequency(value, FrequencyUnit.Kilohertz);
- }
-
- ///
- /// Get Frequency from Megahertz.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Frequency FromMegahertz(double megahertz)
-#else
- public static Frequency FromMegahertz(QuantityValue megahertz)
-#endif
- {
- double value = (double) megahertz;
- return new Frequency(value, FrequencyUnit.Megahertz);
- }
-
- ///
- /// Get Frequency from RadiansPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Frequency FromRadiansPerSecond(double radianspersecond)
-#else
- public static Frequency FromRadiansPerSecond(QuantityValue radianspersecond)
-#endif
- {
- double value = (double) radianspersecond;
- return new Frequency(value, FrequencyUnit.RadianPerSecond);
- }
-
- ///
- /// Get Frequency from Terahertz.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Frequency FromTerahertz(double terahertz)
-#else
- public static Frequency FromTerahertz(QuantityValue terahertz)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Frequency From(double value, FrequencyUnit fromUnit)
-#else
- public static Frequency From(QuantityValue value, FrequencyUnit fromUnit)
-#endif
- {
- return new Frequency((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(FrequencyUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out FrequencyUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Frequency ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Frequency result)
- {
- result = default(Frequency);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static FrequencyUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == FrequencyUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized FrequencyUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out FrequencyUnit unit)
- {
- unit = FrequencyUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == FrequencyUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(FrequencyUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Frequency.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Frequency.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/HeatFlux.Common.g.cs b/Common/GeneratedCode/Quantities/HeatFlux.Common.g.cs
deleted file mode 100644
index 4c5dc74008..0000000000
--- a/Common/GeneratedCode/Quantities/HeatFlux.Common.g.cs
+++ /dev/null
@@ -1,867 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// Heat flux is the flow of energy per unit of area per unit of time
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class HeatFlux : IQuantity
-#else
- public partial struct HeatFlux : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly HeatFluxUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public HeatFluxUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static HeatFlux()
- {
- BaseDimensions = new BaseDimensions(0, 1, -3, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.HeatFlux;
-
- ///
- /// The base unit of HeatFlux, which is WattPerSquareMeter. All conversions go via this value.
- ///
- public static HeatFluxUnit BaseUnit => HeatFluxUnit.WattPerSquareMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the HeatFlux quantity.
- ///
- public static HeatFluxUnit[] Units { get; } = Enum.GetValues(typeof(HeatFluxUnit)).Cast().Except(new HeatFluxUnit[]{ HeatFluxUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit WattPerSquareMeter.
- ///
- public static HeatFlux Zero => new HeatFlux(0, BaseUnit);
-
- ///
- /// Get HeatFlux from BtusPerHourSquareFoot.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromBtusPerHourSquareFoot(double btusperhoursquarefoot)
-#else
- public static HeatFlux FromBtusPerHourSquareFoot(QuantityValue btusperhoursquarefoot)
-#endif
- {
- double value = (double) btusperhoursquarefoot;
- return new HeatFlux(value, HeatFluxUnit.BtuPerHourSquareFoot);
- }
-
- ///
- /// Get HeatFlux from BtusPerMinuteSquareFoot.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromBtusPerMinuteSquareFoot(double btusperminutesquarefoot)
-#else
- public static HeatFlux FromBtusPerMinuteSquareFoot(QuantityValue btusperminutesquarefoot)
-#endif
- {
- double value = (double) btusperminutesquarefoot;
- return new HeatFlux(value, HeatFluxUnit.BtuPerMinuteSquareFoot);
- }
-
- ///
- /// Get HeatFlux from BtusPerSecondSquareFoot.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromBtusPerSecondSquareFoot(double btuspersecondsquarefoot)
-#else
- public static HeatFlux FromBtusPerSecondSquareFoot(QuantityValue btuspersecondsquarefoot)
-#endif
- {
- double value = (double) btuspersecondsquarefoot;
- return new HeatFlux(value, HeatFluxUnit.BtuPerSecondSquareFoot);
- }
-
- ///
- /// Get HeatFlux from BtusPerSecondSquareInch.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromBtusPerSecondSquareInch(double btuspersecondsquareinch)
-#else
- public static HeatFlux FromBtusPerSecondSquareInch(QuantityValue btuspersecondsquareinch)
-#endif
- {
- double value = (double) btuspersecondsquareinch;
- return new HeatFlux(value, HeatFluxUnit.BtuPerSecondSquareInch);
- }
-
- ///
- /// Get HeatFlux from CaloriesPerSecondSquareCentimeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromCaloriesPerSecondSquareCentimeter(double caloriespersecondsquarecentimeter)
-#else
- public static HeatFlux FromCaloriesPerSecondSquareCentimeter(QuantityValue caloriespersecondsquarecentimeter)
-#endif
- {
- double value = (double) caloriespersecondsquarecentimeter;
- return new HeatFlux(value, HeatFluxUnit.CaloriePerSecondSquareCentimeter);
- }
-
- ///
- /// Get HeatFlux from CentiwattsPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromCentiwattsPerSquareMeter(double centiwattspersquaremeter)
-#else
- public static HeatFlux FromCentiwattsPerSquareMeter(QuantityValue centiwattspersquaremeter)
-#endif
- {
- double value = (double) centiwattspersquaremeter;
- return new HeatFlux(value, HeatFluxUnit.CentiwattPerSquareMeter);
- }
-
- ///
- /// Get HeatFlux from DeciwattsPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromDeciwattsPerSquareMeter(double deciwattspersquaremeter)
-#else
- public static HeatFlux FromDeciwattsPerSquareMeter(QuantityValue deciwattspersquaremeter)
-#endif
- {
- double value = (double) deciwattspersquaremeter;
- return new HeatFlux(value, HeatFluxUnit.DeciwattPerSquareMeter);
- }
-
- ///
- /// Get HeatFlux from KilocaloriesPerHourSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromKilocaloriesPerHourSquareMeter(double kilocaloriesperhoursquaremeter)
-#else
- public static HeatFlux FromKilocaloriesPerHourSquareMeter(QuantityValue kilocaloriesperhoursquaremeter)
-#endif
- {
- double value = (double) kilocaloriesperhoursquaremeter;
- return new HeatFlux(value, HeatFluxUnit.KilocaloriePerHourSquareMeter);
- }
-
- ///
- /// Get HeatFlux from KilocaloriesPerSecondSquareCentimeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromKilocaloriesPerSecondSquareCentimeter(double kilocaloriespersecondsquarecentimeter)
-#else
- public static HeatFlux FromKilocaloriesPerSecondSquareCentimeter(QuantityValue kilocaloriespersecondsquarecentimeter)
-#endif
- {
- double value = (double) kilocaloriespersecondsquarecentimeter;
- return new HeatFlux(value, HeatFluxUnit.KilocaloriePerSecondSquareCentimeter);
- }
-
- ///
- /// Get HeatFlux from KilowattsPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromKilowattsPerSquareMeter(double kilowattspersquaremeter)
-#else
- public static HeatFlux FromKilowattsPerSquareMeter(QuantityValue kilowattspersquaremeter)
-#endif
- {
- double value = (double) kilowattspersquaremeter;
- return new HeatFlux(value, HeatFluxUnit.KilowattPerSquareMeter);
- }
-
- ///
- /// Get HeatFlux from MicrowattsPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromMicrowattsPerSquareMeter(double microwattspersquaremeter)
-#else
- public static HeatFlux FromMicrowattsPerSquareMeter(QuantityValue microwattspersquaremeter)
-#endif
- {
- double value = (double) microwattspersquaremeter;
- return new HeatFlux(value, HeatFluxUnit.MicrowattPerSquareMeter);
- }
-
- ///
- /// Get HeatFlux from MilliwattsPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromMilliwattsPerSquareMeter(double milliwattspersquaremeter)
-#else
- public static HeatFlux FromMilliwattsPerSquareMeter(QuantityValue milliwattspersquaremeter)
-#endif
- {
- double value = (double) milliwattspersquaremeter;
- return new HeatFlux(value, HeatFluxUnit.MilliwattPerSquareMeter);
- }
-
- ///
- /// Get HeatFlux from NanowattsPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromNanowattsPerSquareMeter(double nanowattspersquaremeter)
-#else
- public static HeatFlux FromNanowattsPerSquareMeter(QuantityValue nanowattspersquaremeter)
-#endif
- {
- double value = (double) nanowattspersquaremeter;
- return new HeatFlux(value, HeatFluxUnit.NanowattPerSquareMeter);
- }
-
- ///
- /// Get HeatFlux from WattsPerSquareFoot.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromWattsPerSquareFoot(double wattspersquarefoot)
-#else
- public static HeatFlux FromWattsPerSquareFoot(QuantityValue wattspersquarefoot)
-#endif
- {
- double value = (double) wattspersquarefoot;
- return new HeatFlux(value, HeatFluxUnit.WattPerSquareFoot);
- }
-
- ///
- /// Get HeatFlux from WattsPerSquareInch.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromWattsPerSquareInch(double wattspersquareinch)
-#else
- public static HeatFlux FromWattsPerSquareInch(QuantityValue wattspersquareinch)
-#endif
- {
- double value = (double) wattspersquareinch;
- return new HeatFlux(value, HeatFluxUnit.WattPerSquareInch);
- }
-
- ///
- /// Get HeatFlux from WattsPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatFlux FromWattsPerSquareMeter(double wattspersquaremeter)
-#else
- public static HeatFlux FromWattsPerSquareMeter(QuantityValue wattspersquaremeter)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static HeatFlux From(double value, HeatFluxUnit fromUnit)
-#else
- public static HeatFlux From(QuantityValue value, HeatFluxUnit fromUnit)
-#endif
- {
- return new HeatFlux((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(HeatFluxUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out HeatFluxUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static HeatFlux ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out HeatFlux result)
- {
- result = default(HeatFlux);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static HeatFluxUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == HeatFluxUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized HeatFluxUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out HeatFluxUnit unit)
- {
- unit = HeatFluxUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == HeatFluxUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(HeatFluxUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => HeatFlux.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => HeatFlux.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/HeatTransferCoefficient.Common.g.cs b/Common/GeneratedCode/Quantities/HeatTransferCoefficient.Common.g.cs
deleted file mode 100644
index c3e53a657e..0000000000
--- a/Common/GeneratedCode/Quantities/HeatTransferCoefficient.Common.g.cs
+++ /dev/null
@@ -1,559 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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)
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class HeatTransferCoefficient : IQuantity
-#else
- public partial struct HeatTransferCoefficient : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly HeatTransferCoefficientUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public HeatTransferCoefficientUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static HeatTransferCoefficient()
- {
- BaseDimensions = new BaseDimensions(0, 1, -3, 0, -1, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.HeatTransferCoefficient;
-
- ///
- /// The base unit of HeatTransferCoefficient, which is WattPerSquareMeterKelvin. All conversions go via this value.
- ///
- public static HeatTransferCoefficientUnit BaseUnit => HeatTransferCoefficientUnit.WattPerSquareMeterKelvin;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the HeatTransferCoefficient quantity.
- ///
- public static HeatTransferCoefficientUnit[] Units { get; } = Enum.GetValues(typeof(HeatTransferCoefficientUnit)).Cast().Except(new HeatTransferCoefficientUnit[]{ HeatTransferCoefficientUnit.Undefined }).ToArray();
-
- ///
- /// Get HeatTransferCoefficient in WattsPerSquareMeterCelsius.
- ///
- public double WattsPerSquareMeterCelsius => As(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius);
-
- ///
- /// Get HeatTransferCoefficient in WattsPerSquareMeterKelvin.
- ///
- public double WattsPerSquareMeterKelvin => As(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit WattPerSquareMeterKelvin.
- ///
- public static HeatTransferCoefficient Zero => new HeatTransferCoefficient(0, BaseUnit);
-
- ///
- /// Get HeatTransferCoefficient from WattsPerSquareMeterCelsius.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatTransferCoefficient FromWattsPerSquareMeterCelsius(double wattspersquaremetercelsius)
-#else
- public static HeatTransferCoefficient FromWattsPerSquareMeterCelsius(QuantityValue wattspersquaremetercelsius)
-#endif
- {
- double value = (double) wattspersquaremetercelsius;
- return new HeatTransferCoefficient(value, HeatTransferCoefficientUnit.WattPerSquareMeterCelsius);
- }
-
- ///
- /// Get HeatTransferCoefficient from WattsPerSquareMeterKelvin.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static HeatTransferCoefficient FromWattsPerSquareMeterKelvin(double wattspersquaremeterkelvin)
-#else
- public static HeatTransferCoefficient FromWattsPerSquareMeterKelvin(QuantityValue wattspersquaremeterkelvin)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static HeatTransferCoefficient From(double value, HeatTransferCoefficientUnit fromUnit)
-#else
- public static HeatTransferCoefficient From(QuantityValue value, HeatTransferCoefficientUnit fromUnit)
-#endif
- {
- return new HeatTransferCoefficient((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(HeatTransferCoefficientUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out HeatTransferCoefficientUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static HeatTransferCoefficient ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out HeatTransferCoefficient result)
- {
- result = default(HeatTransferCoefficient);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static HeatTransferCoefficientUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == HeatTransferCoefficientUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized HeatTransferCoefficientUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out HeatTransferCoefficientUnit unit)
- {
- unit = HeatTransferCoefficientUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == HeatTransferCoefficientUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(HeatTransferCoefficientUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => HeatTransferCoefficient.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => HeatTransferCoefficient.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Illuminance.Common.g.cs b/Common/GeneratedCode/Quantities/Illuminance.Common.g.cs
deleted file mode 100644
index 461747c421..0000000000
--- a/Common/GeneratedCode/Quantities/Illuminance.Common.g.cs
+++ /dev/null
@@ -1,603 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// In photometry, illuminance is the total luminous flux incident on a surface, per unit area.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Illuminance : IQuantity
-#else
- public partial struct Illuminance : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly IlluminanceUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public IlluminanceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Illuminance()
- {
- BaseDimensions = new BaseDimensions(-2, 0, 0, 0, 0, 0, 1);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Illuminance;
-
- ///
- /// The base unit of Illuminance, which is Lux. All conversions go via this value.
- ///
- public static IlluminanceUnit BaseUnit => IlluminanceUnit.Lux;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Illuminance quantity.
- ///
- public static IlluminanceUnit[] Units { get; } = Enum.GetValues(typeof(IlluminanceUnit)).Cast().Except(new IlluminanceUnit[]{ IlluminanceUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Lux.
- ///
- public static Illuminance Zero => new Illuminance(0, BaseUnit);
-
- ///
- /// Get Illuminance from Kilolux.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Illuminance FromKilolux(double kilolux)
-#else
- public static Illuminance FromKilolux(QuantityValue kilolux)
-#endif
- {
- double value = (double) kilolux;
- return new Illuminance(value, IlluminanceUnit.Kilolux);
- }
-
- ///
- /// Get Illuminance from Lux.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Illuminance FromLux(double lux)
-#else
- public static Illuminance FromLux(QuantityValue lux)
-#endif
- {
- double value = (double) lux;
- return new Illuminance(value, IlluminanceUnit.Lux);
- }
-
- ///
- /// Get Illuminance from Megalux.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Illuminance FromMegalux(double megalux)
-#else
- public static Illuminance FromMegalux(QuantityValue megalux)
-#endif
- {
- double value = (double) megalux;
- return new Illuminance(value, IlluminanceUnit.Megalux);
- }
-
- ///
- /// Get Illuminance from Millilux.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Illuminance FromMillilux(double millilux)
-#else
- public static Illuminance FromMillilux(QuantityValue millilux)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Illuminance From(double value, IlluminanceUnit fromUnit)
-#else
- public static Illuminance From(QuantityValue value, IlluminanceUnit fromUnit)
-#endif
- {
- return new Illuminance((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(IlluminanceUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out IlluminanceUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Illuminance ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Illuminance result)
- {
- result = default(Illuminance);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static IlluminanceUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == IlluminanceUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized IlluminanceUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out IlluminanceUnit unit)
- {
- unit = IlluminanceUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == IlluminanceUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(IlluminanceUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Illuminance.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Illuminance.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Information.Common.g.cs b/Common/GeneratedCode/Quantities/Information.Common.g.cs
deleted file mode 100644
index 4dc7772045..0000000000
--- a/Common/GeneratedCode/Quantities/Information.Common.g.cs
+++ /dev/null
@@ -1,1086 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// In computing and telecommunications, a unit of information is the capacity of some standard data storage system or communication channel, used to measure the capacities of other systems and channels. In information theory, units of information are also used to measure the information contents or entropy of random variables.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Information : IQuantity
-#else
- public partial struct Information : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly decimal _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly InformationUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public InformationUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Information()
- {
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- Information(decimal numericValue, InformationUnit unit)
- {
- if(unit == InformationUnit.Undefined)
- throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
-
- _value = numericValue;
- _unit = unit;
- }
-
- #region Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Information;
-
- ///
- /// The base unit of Information, which is Bit. All conversions go via this value.
- ///
- public static InformationUnit BaseUnit => InformationUnit.Bit;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Information quantity.
- ///
- public static InformationUnit[] Units { get; } = Enum.GetValues(typeof(InformationUnit)).Cast().Except(new InformationUnit[]{ InformationUnit.Undefined }).ToArray();
-
- ///
- /// Get Information in Bits.
- ///
- public double Bits => As(InformationUnit.Bit);
-
- ///
- /// Get Information in Bytes.
- ///
- public double Bytes => As(InformationUnit.Byte);
-
- ///
- /// Get Information in Exabits.
- ///
- public double Exabits => As(InformationUnit.Exabit);
-
- ///
- /// Get Information in Exabytes.
- ///
- public double Exabytes => As(InformationUnit.Exabyte);
-
- ///
- /// Get Information in Exbibits.
- ///
- public double Exbibits => As(InformationUnit.Exbibit);
-
- ///
- /// Get Information in Exbibytes.
- ///
- public double Exbibytes => As(InformationUnit.Exbibyte);
-
- ///
- /// Get Information in Gibibits.
- ///
- public double Gibibits => As(InformationUnit.Gibibit);
-
- ///
- /// Get Information in Gibibytes.
- ///
- public double Gibibytes => As(InformationUnit.Gibibyte);
-
- ///
- /// Get Information in Gigabits.
- ///
- public double Gigabits => As(InformationUnit.Gigabit);
-
- ///
- /// Get Information in Gigabytes.
- ///
- public double Gigabytes => As(InformationUnit.Gigabyte);
-
- ///
- /// Get Information in Kibibits.
- ///
- public double Kibibits => As(InformationUnit.Kibibit);
-
- ///
- /// Get Information in Kibibytes.
- ///
- public double Kibibytes => As(InformationUnit.Kibibyte);
-
- ///
- /// Get Information in Kilobits.
- ///
- public double Kilobits => As(InformationUnit.Kilobit);
-
- ///
- /// Get Information in Kilobytes.
- ///
- public double Kilobytes => As(InformationUnit.Kilobyte);
-
- ///
- /// Get Information in Mebibits.
- ///
- public double Mebibits => As(InformationUnit.Mebibit);
-
- ///
- /// Get Information in Mebibytes.
- ///
- public double Mebibytes => As(InformationUnit.Mebibyte);
-
- ///
- /// Get Information in Megabits.
- ///
- public double Megabits => As(InformationUnit.Megabit);
-
- ///
- /// Get Information in Megabytes.
- ///
- public double Megabytes => As(InformationUnit.Megabyte);
-
- ///
- /// Get Information in Pebibits.
- ///
- public double Pebibits => As(InformationUnit.Pebibit);
-
- ///
- /// Get Information in Pebibytes.
- ///
- public double Pebibytes => As(InformationUnit.Pebibyte);
-
- ///
- /// Get Information in Petabits.
- ///
- public double Petabits => As(InformationUnit.Petabit);
-
- ///
- /// Get Information in Petabytes.
- ///
- public double Petabytes => As(InformationUnit.Petabyte);
-
- ///
- /// Get Information in Tebibits.
- ///
- public double Tebibits => As(InformationUnit.Tebibit);
-
- ///
- /// Get Information in Tebibytes.
- ///
- public double Tebibytes => As(InformationUnit.Tebibyte);
-
- ///
- /// Get Information in Terabits.
- ///
- public double Terabits => As(InformationUnit.Terabit);
-
- ///
- /// Get Information in Terabytes.
- ///
- public double Terabytes => As(InformationUnit.Terabyte);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit Bit.
- ///
- public static Information Zero => new Information(0, BaseUnit);
-
- ///
- /// Get Information from Bits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromBits(double bits)
-#else
- public static Information FromBits(QuantityValue bits)
-#endif
- {
- decimal value = (decimal) bits;
- return new Information(value, InformationUnit.Bit);
- }
-
- ///
- /// Get Information from Bytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromBytes(double bytes)
-#else
- public static Information FromBytes(QuantityValue bytes)
-#endif
- {
- decimal value = (decimal) bytes;
- return new Information(value, InformationUnit.Byte);
- }
-
- ///
- /// Get Information from Exabits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromExabits(double exabits)
-#else
- public static Information FromExabits(QuantityValue exabits)
-#endif
- {
- decimal value = (decimal) exabits;
- return new Information(value, InformationUnit.Exabit);
- }
-
- ///
- /// Get Information from Exabytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromExabytes(double exabytes)
-#else
- public static Information FromExabytes(QuantityValue exabytes)
-#endif
- {
- decimal value = (decimal) exabytes;
- return new Information(value, InformationUnit.Exabyte);
- }
-
- ///
- /// Get Information from Exbibits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromExbibits(double exbibits)
-#else
- public static Information FromExbibits(QuantityValue exbibits)
-#endif
- {
- decimal value = (decimal) exbibits;
- return new Information(value, InformationUnit.Exbibit);
- }
-
- ///
- /// Get Information from Exbibytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromExbibytes(double exbibytes)
-#else
- public static Information FromExbibytes(QuantityValue exbibytes)
-#endif
- {
- decimal value = (decimal) exbibytes;
- return new Information(value, InformationUnit.Exbibyte);
- }
-
- ///
- /// Get Information from Gibibits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromGibibits(double gibibits)
-#else
- public static Information FromGibibits(QuantityValue gibibits)
-#endif
- {
- decimal value = (decimal) gibibits;
- return new Information(value, InformationUnit.Gibibit);
- }
-
- ///
- /// Get Information from Gibibytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromGibibytes(double gibibytes)
-#else
- public static Information FromGibibytes(QuantityValue gibibytes)
-#endif
- {
- decimal value = (decimal) gibibytes;
- return new Information(value, InformationUnit.Gibibyte);
- }
-
- ///
- /// Get Information from Gigabits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromGigabits(double gigabits)
-#else
- public static Information FromGigabits(QuantityValue gigabits)
-#endif
- {
- decimal value = (decimal) gigabits;
- return new Information(value, InformationUnit.Gigabit);
- }
-
- ///
- /// Get Information from Gigabytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromGigabytes(double gigabytes)
-#else
- public static Information FromGigabytes(QuantityValue gigabytes)
-#endif
- {
- decimal value = (decimal) gigabytes;
- return new Information(value, InformationUnit.Gigabyte);
- }
-
- ///
- /// Get Information from Kibibits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromKibibits(double kibibits)
-#else
- public static Information FromKibibits(QuantityValue kibibits)
-#endif
- {
- decimal value = (decimal) kibibits;
- return new Information(value, InformationUnit.Kibibit);
- }
-
- ///
- /// Get Information from Kibibytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromKibibytes(double kibibytes)
-#else
- public static Information FromKibibytes(QuantityValue kibibytes)
-#endif
- {
- decimal value = (decimal) kibibytes;
- return new Information(value, InformationUnit.Kibibyte);
- }
-
- ///
- /// Get Information from Kilobits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromKilobits(double kilobits)
-#else
- public static Information FromKilobits(QuantityValue kilobits)
-#endif
- {
- decimal value = (decimal) kilobits;
- return new Information(value, InformationUnit.Kilobit);
- }
-
- ///
- /// Get Information from Kilobytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromKilobytes(double kilobytes)
-#else
- public static Information FromKilobytes(QuantityValue kilobytes)
-#endif
- {
- decimal value = (decimal) kilobytes;
- return new Information(value, InformationUnit.Kilobyte);
- }
-
- ///
- /// Get Information from Mebibits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromMebibits(double mebibits)
-#else
- public static Information FromMebibits(QuantityValue mebibits)
-#endif
- {
- decimal value = (decimal) mebibits;
- return new Information(value, InformationUnit.Mebibit);
- }
-
- ///
- /// Get Information from Mebibytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromMebibytes(double mebibytes)
-#else
- public static Information FromMebibytes(QuantityValue mebibytes)
-#endif
- {
- decimal value = (decimal) mebibytes;
- return new Information(value, InformationUnit.Mebibyte);
- }
-
- ///
- /// Get Information from Megabits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromMegabits(double megabits)
-#else
- public static Information FromMegabits(QuantityValue megabits)
-#endif
- {
- decimal value = (decimal) megabits;
- return new Information(value, InformationUnit.Megabit);
- }
-
- ///
- /// Get Information from Megabytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromMegabytes(double megabytes)
-#else
- public static Information FromMegabytes(QuantityValue megabytes)
-#endif
- {
- decimal value = (decimal) megabytes;
- return new Information(value, InformationUnit.Megabyte);
- }
-
- ///
- /// Get Information from Pebibits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromPebibits(double pebibits)
-#else
- public static Information FromPebibits(QuantityValue pebibits)
-#endif
- {
- decimal value = (decimal) pebibits;
- return new Information(value, InformationUnit.Pebibit);
- }
-
- ///
- /// Get Information from Pebibytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromPebibytes(double pebibytes)
-#else
- public static Information FromPebibytes(QuantityValue pebibytes)
-#endif
- {
- decimal value = (decimal) pebibytes;
- return new Information(value, InformationUnit.Pebibyte);
- }
-
- ///
- /// Get Information from Petabits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromPetabits(double petabits)
-#else
- public static Information FromPetabits(QuantityValue petabits)
-#endif
- {
- decimal value = (decimal) petabits;
- return new Information(value, InformationUnit.Petabit);
- }
-
- ///
- /// Get Information from Petabytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromPetabytes(double petabytes)
-#else
- public static Information FromPetabytes(QuantityValue petabytes)
-#endif
- {
- decimal value = (decimal) petabytes;
- return new Information(value, InformationUnit.Petabyte);
- }
-
- ///
- /// Get Information from Tebibits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromTebibits(double tebibits)
-#else
- public static Information FromTebibits(QuantityValue tebibits)
-#endif
- {
- decimal value = (decimal) tebibits;
- return new Information(value, InformationUnit.Tebibit);
- }
-
- ///
- /// Get Information from Tebibytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromTebibytes(double tebibytes)
-#else
- public static Information FromTebibytes(QuantityValue tebibytes)
-#endif
- {
- decimal value = (decimal) tebibytes;
- return new Information(value, InformationUnit.Tebibyte);
- }
-
- ///
- /// Get Information from Terabits.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromTerabits(double terabits)
-#else
- public static Information FromTerabits(QuantityValue terabits)
-#endif
- {
- decimal value = (decimal) terabits;
- return new Information(value, InformationUnit.Terabit);
- }
-
- ///
- /// Get Information from Terabytes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Information FromTerabytes(double terabytes)
-#else
- public static Information FromTerabytes(QuantityValue terabytes)
-#endif
- {
- decimal value = (decimal) terabytes;
- return new Information(value, InformationUnit.Terabyte);
- }
-
-
- ///
- /// Dynamically convert from value and unit enum to .
- ///
- /// Value to convert from.
- /// Unit to convert from.
- /// Information unit value.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Information From(double value, InformationUnit fromUnit)
-#else
- public static Information From(QuantityValue value, InformationUnit fromUnit)
-#endif
- {
- return new Information((decimal)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(InformationUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #endregion
-
- #region Equality / IComparable
-
- public int CompareTo(object obj)
- {
- if(obj is null) throw new ArgumentNullException(nameof(obj));
- if(!(obj is Information)) throw new ArgumentException("Expected type Information.", nameof(obj));
-
- return CompareTo((Information)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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- int CompareTo(Information other)
- {
- return _value.CompareTo(other.AsBaseNumericType(this.Unit));
- }
-
- ///
- ///
- /// Compare equality to another Information 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(Information 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 Information.
- public override int GetHashCode()
- {
- return new { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// Convert to the unit representation .
- ///
- /// Value converted to the specified unit.
- public double As(InformationUnit unit)
- {
- if(Unit == unit)
- return Convert.ToDouble(Value);
-
- var converted = AsBaseNumericType(unit);
- return Convert.ToDouble(converted);
- }
-
- ///
- /// Converts this Information to another Information with the unit representation .
- ///
- /// A Information with the specified unit.
- public Information ToUnit(InformationUnit unit)
- {
- var convertedValue = AsBaseNumericType(unit);
- return new Information(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 InformationUnit.Bit: return _value;
- case InformationUnit.Byte: return _value*8m;
- case InformationUnit.Exabit: return (_value) * 1e18m;
- case InformationUnit.Exabyte: return (_value*8m) * 1e18m;
- case InformationUnit.Exbibit: return (_value) * (1024m * 1024 * 1024 * 1024 * 1024 * 1024);
- case InformationUnit.Exbibyte: return (_value*8m) * (1024m * 1024 * 1024 * 1024 * 1024 * 1024);
- case InformationUnit.Gibibit: return (_value) * (1024m * 1024 * 1024);
- case InformationUnit.Gibibyte: return (_value*8m) * (1024m * 1024 * 1024);
- case InformationUnit.Gigabit: return (_value) * 1e9m;
- case InformationUnit.Gigabyte: return (_value*8m) * 1e9m;
- case InformationUnit.Kibibit: return (_value) * 1024m;
- case InformationUnit.Kibibyte: return (_value*8m) * 1024m;
- case InformationUnit.Kilobit: return (_value) * 1e3m;
- case InformationUnit.Kilobyte: return (_value*8m) * 1e3m;
- case InformationUnit.Mebibit: return (_value) * (1024m * 1024);
- case InformationUnit.Mebibyte: return (_value*8m) * (1024m * 1024);
- case InformationUnit.Megabit: return (_value) * 1e6m;
- case InformationUnit.Megabyte: return (_value*8m) * 1e6m;
- case InformationUnit.Pebibit: return (_value) * (1024m * 1024 * 1024 * 1024 * 1024);
- case InformationUnit.Pebibyte: return (_value*8m) * (1024m * 1024 * 1024 * 1024 * 1024);
- case InformationUnit.Petabit: return (_value) * 1e15m;
- case InformationUnit.Petabyte: return (_value*8m) * 1e15m;
- case InformationUnit.Tebibit: return (_value) * (1024m * 1024 * 1024 * 1024);
- case InformationUnit.Tebibyte: return (_value*8m) * (1024m * 1024 * 1024 * 1024);
- case InformationUnit.Terabit: return (_value) * 1e12m;
- case InformationUnit.Terabyte: return (_value*8m) * 1e12m;
- default:
- throw new NotImplementedException($"Can not convert {Unit} to base units.");
- }
- }
-
- private decimal AsBaseNumericType(InformationUnit unit)
- {
- if(Unit == unit)
- return _value;
-
- var baseUnitValue = AsBaseUnit();
-
- switch(unit)
- {
- case InformationUnit.Bit: return baseUnitValue;
- case InformationUnit.Byte: return baseUnitValue/8m;
- case InformationUnit.Exabit: return (baseUnitValue) / 1e18m;
- case InformationUnit.Exabyte: return (baseUnitValue/8m) / 1e18m;
- case InformationUnit.Exbibit: return (baseUnitValue) / (1024m * 1024 * 1024 * 1024 * 1024 * 1024);
- case InformationUnit.Exbibyte: return (baseUnitValue/8m) / (1024m * 1024 * 1024 * 1024 * 1024 * 1024);
- case InformationUnit.Gibibit: return (baseUnitValue) / (1024m * 1024 * 1024);
- case InformationUnit.Gibibyte: return (baseUnitValue/8m) / (1024m * 1024 * 1024);
- case InformationUnit.Gigabit: return (baseUnitValue) / 1e9m;
- case InformationUnit.Gigabyte: return (baseUnitValue/8m) / 1e9m;
- case InformationUnit.Kibibit: return (baseUnitValue) / 1024m;
- case InformationUnit.Kibibyte: return (baseUnitValue/8m) / 1024m;
- case InformationUnit.Kilobit: return (baseUnitValue) / 1e3m;
- case InformationUnit.Kilobyte: return (baseUnitValue/8m) / 1e3m;
- case InformationUnit.Mebibit: return (baseUnitValue) / (1024m * 1024);
- case InformationUnit.Mebibyte: return (baseUnitValue/8m) / (1024m * 1024);
- case InformationUnit.Megabit: return (baseUnitValue) / 1e6m;
- case InformationUnit.Megabyte: return (baseUnitValue/8m) / 1e6m;
- case InformationUnit.Pebibit: return (baseUnitValue) / (1024m * 1024 * 1024 * 1024 * 1024);
- case InformationUnit.Pebibyte: return (baseUnitValue/8m) / (1024m * 1024 * 1024 * 1024 * 1024);
- case InformationUnit.Petabit: return (baseUnitValue) / 1e15m;
- case InformationUnit.Petabyte: return (baseUnitValue/8m) / 1e15m;
- case InformationUnit.Tebibit: return (baseUnitValue) / (1024m * 1024 * 1024 * 1024);
- case InformationUnit.Tebibyte: return (baseUnitValue/8m) / (1024m * 1024 * 1024 * 1024);
- case InformationUnit.Terabit: return (baseUnitValue) / 1e12m;
- case InformationUnit.Terabyte: return (baseUnitValue/8m) / 1e12m;
- default:
- throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
- }
- }
-
- #endregion
-
- #region Parsing
-
- ///
- /// 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 Information Parse(string str)
- {
- return ParseInternal(str, null);
- }
-
- ///
- /// 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 Information result)
- {
- return TryParseInternal(str, null, 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 InformationUnit ParseUnit(string str)
- {
- return ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out InformationUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Information ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Information result)
- {
- result = default(Information);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static InformationUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == InformationUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized InformationUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out InformationUnit unit)
- {
- unit = InformationUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == InformationUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(InformationUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// Represents the largest possible value of Information
- ///
- public static Information MaxValue => new Information(decimal.MaxValue, BaseUnit);
-
- ///
- /// Represents the smallest possible value of Information
- ///
- public static Information MinValue => new Information(decimal.MinValue, BaseUnit);
-
- ///
- /// The of this quantity.
- ///
- public QuantityType Type => Information.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Information.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Irradiance.Common.g.cs b/Common/GeneratedCode/Quantities/Irradiance.Common.g.cs
deleted file mode 100644
index 9cf07001d2..0000000000
--- a/Common/GeneratedCode/Quantities/Irradiance.Common.g.cs
+++ /dev/null
@@ -1,559 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// ReSharper disable once CheckNamespace
-
-namespace UnitsNet
-{
- ///
- /// Irradiance is the intensity of ultraviolet (UV) or visible light incident on a surface.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Irradiance : IQuantity
-#else
- public partial struct Irradiance : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly IrradianceUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public IrradianceUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Irradiance()
- {
- BaseDimensions = new BaseDimensions(0, 1, -3, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Irradiance;
-
- ///
- /// The base unit of Irradiance, which is WattPerSquareMeter. All conversions go via this value.
- ///
- public static IrradianceUnit BaseUnit => IrradianceUnit.WattPerSquareMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Irradiance quantity.
- ///
- public static IrradianceUnit[] Units { get; } = Enum.GetValues(typeof(IrradianceUnit)).Cast().Except(new IrradianceUnit[]{ IrradianceUnit.Undefined }).ToArray();
-
- ///
- /// Get Irradiance in KilowattsPerSquareMeter.
- ///
- public double KilowattsPerSquareMeter => As(IrradianceUnit.KilowattPerSquareMeter);
-
- ///
- /// Get Irradiance in WattsPerSquareMeter.
- ///
- public double WattsPerSquareMeter => As(IrradianceUnit.WattPerSquareMeter);
-
- #endregion
-
- #region Static
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit WattPerSquareMeter.
- ///
- public static Irradiance Zero => new Irradiance(0, BaseUnit);
-
- ///
- /// Get Irradiance from KilowattsPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Irradiance FromKilowattsPerSquareMeter(double kilowattspersquaremeter)
-#else
- public static Irradiance FromKilowattsPerSquareMeter(QuantityValue kilowattspersquaremeter)
-#endif
- {
- double value = (double) kilowattspersquaremeter;
- return new Irradiance(value, IrradianceUnit.KilowattPerSquareMeter);
- }
-
- ///
- /// Get Irradiance from WattsPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Irradiance FromWattsPerSquareMeter(double wattspersquaremeter)
-#else
- public static Irradiance FromWattsPerSquareMeter(QuantityValue wattspersquaremeter)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Irradiance From(double value, IrradianceUnit fromUnit)
-#else
- public static Irradiance From(QuantityValue value, IrradianceUnit fromUnit)
-#endif
- {
- return new Irradiance((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(IrradianceUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out IrradianceUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Irradiance ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Irradiance result)
- {
- result = default(Irradiance);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static IrradianceUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == IrradianceUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized IrradianceUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out IrradianceUnit unit)
- {
- unit = IrradianceUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == IrradianceUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(IrradianceUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Irradiance.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Irradiance.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/Irradiation.Common.g.cs b/Common/GeneratedCode/Quantities/Irradiation.Common.g.cs
deleted file mode 100644
index f200105b05..0000000000
--- a/Common/GeneratedCode/Quantities/Irradiation.Common.g.cs
+++ /dev/null
@@ -1,581 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class Irradiation : IQuantity
-#else
- public partial struct Irradiation : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly IrradiationUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public IrradiationUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static Irradiation()
- {
- BaseDimensions = new BaseDimensions(0, 1, -2, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.Irradiation;
-
- ///
- /// The base unit of Irradiation, which is JoulePerSquareMeter. All conversions go via this value.
- ///
- public static IrradiationUnit BaseUnit => IrradiationUnit.JoulePerSquareMeter;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the Irradiation quantity.
- ///
- public static IrradiationUnit[] Units { get; } = Enum.GetValues(typeof(IrradiationUnit)).Cast().Except(new IrradiationUnit[]{ IrradiationUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerSquareMeter.
- ///
- public static Irradiation Zero => new Irradiation(0, BaseUnit);
-
- ///
- /// Get Irradiation from JoulesPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Irradiation FromJoulesPerSquareMeter(double joulespersquaremeter)
-#else
- public static Irradiation FromJoulesPerSquareMeter(QuantityValue joulespersquaremeter)
-#endif
- {
- double value = (double) joulespersquaremeter;
- return new Irradiation(value, IrradiationUnit.JoulePerSquareMeter);
- }
-
- ///
- /// Get Irradiation from KilowattHoursPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Irradiation FromKilowattHoursPerSquareMeter(double kilowatthourspersquaremeter)
-#else
- public static Irradiation FromKilowattHoursPerSquareMeter(QuantityValue kilowatthourspersquaremeter)
-#endif
- {
- double value = (double) kilowatthourspersquaremeter;
- return new Irradiation(value, IrradiationUnit.KilowattHourPerSquareMeter);
- }
-
- ///
- /// Get Irradiation from WattHoursPerSquareMeter.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static Irradiation FromWattHoursPerSquareMeter(double watthourspersquaremeter)
-#else
- public static Irradiation FromWattHoursPerSquareMeter(QuantityValue watthourspersquaremeter)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static Irradiation From(double value, IrradiationUnit fromUnit)
-#else
- public static Irradiation From(QuantityValue value, IrradiationUnit fromUnit)
-#endif
- {
- return new Irradiation((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(IrradiationUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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 { Value, Unit }.GetHashCode();
- }
-
- #endregion
-
- #region Conversion
-
- ///
- /// 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 Parsing
-
- ///
- /// 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 ParseInternal(str, null);
- }
-
- ///
- /// 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 TryParseInternal(str, null, 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 ParseUnitInternal(str, null);
- }
-
- public static bool TryParseUnit(string str, out IrradiationUnit unit)
- {
- return TryParseUnitInternal(str, null, out unit);
- }
-
- ///
- /// Parse a string with one or two quantities of the format "<quantity> <unit>".
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// 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.
- ///
- private static Irradiation ParseInternal(string str, [CanBeNull] IFormatProvider provider)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.Parse(str, provider, ParseUnitInternal, 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}
- /// Format to use when parsing number and unit. Defaults to .
- /// Resulting unit quantity if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.Parse("5.5 m", new CultureInfo("en-US"));
- ///
- private static bool TryParseInternal([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Irradiation result)
- {
- result = default(Irradiation);
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- provider = provider ?? GlobalConfiguration.DefaultCulture;
-
- return QuantityParser.Default.TryParse(str, provider, TryParseUnitInternal, From, out result);
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- /// The value of 'str' cannot be null.
- /// Error parsing string.
- private static IrradiationUnit ParseUnitInternal(string str, IFormatProvider provider = null)
- {
- if (str == null) throw new ArgumentNullException(nameof(str));
-
- var unit = UnitParser.Default.Parse(str, provider);
-
- if (unit == IrradiationUnit.Undefined)
- {
- var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized IrradiationUnit.");
- newEx.Data["input"] = str;
- newEx.Data["provider"] = provider?.ToString() ?? "(null)";
- throw newEx;
- }
-
- return unit;
- }
-
- ///
- /// Parse a unit string.
- ///
- /// String to parse. Typically in the form: {number} {unit}
- /// Format to use when parsing number and unit. Defaults to .
- /// The parsed unit if successful.
- /// True if successful, otherwise false.
- ///
- /// Length.ParseUnit("m", new CultureInfo("en-US"));
- ///
- private static bool TryParseUnitInternal(string str, IFormatProvider provider, out IrradiationUnit unit)
- {
- unit = IrradiationUnit.Undefined;
-
- if(string.IsNullOrWhiteSpace(str))
- return false;
-
- if(!UnitParser.Default.TryParse(str, provider, out unit))
- return false;
-
- if(unit == IrradiationUnit.Undefined)
- return false;
-
- return true;
- }
-
- #endregion
-
- ///
- /// Get default string representation of value and unit.
- ///
- /// String representation.
- public override string ToString()
- {
- return ToString(Unit);
- }
-
- ///
- /// Get string representation of value and unit. Using current UI culture and two significant digits after radix.
- ///
- /// Unit representation to use.
- /// String representation.
- public string ToString(IrradiationUnit unit)
- {
- return ToString(unit, null, 2);
- }
-
- ///
- /// 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 QuantityType Type => Irradiation.QuantityType;
-
- ///
- /// The of this quantity.
- ///
- public BaseDimensions Dimensions => Irradiation.BaseDimensions;
- }
-}
diff --git a/Common/GeneratedCode/Quantities/KinematicViscosity.Common.g.cs b/Common/GeneratedCode/Quantities/KinematicViscosity.Common.g.cs
deleted file mode 100644
index 1c52767722..0000000000
--- a/Common/GeneratedCode/Quantities/KinematicViscosity.Common.g.cs
+++ /dev/null
@@ -1,691 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.Linq;
-using JetBrains.Annotations;
-using UnitsNet.InternalHelpers;
-using UnitsNet.Units;
-
-// 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.
- ///
- // ReSharper disable once PartialTypeWithSinglePart
-
- // 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.
-#if WINDOWS_UWP
- public sealed partial class KinematicViscosity : IQuantity
-#else
- public partial struct KinematicViscosity : IQuantity, IComparable, IComparable
-#endif
- {
- ///
- /// The numeric value this quantity was constructed with.
- ///
- private readonly double _value;
-
- ///
- /// The unit this quantity was constructed with.
- ///
- private readonly KinematicViscosityUnit? _unit;
-
- ///
- /// The unit this quantity was constructed with -or- if default ctor was used.
- ///
- public KinematicViscosityUnit Unit => _unit.GetValueOrDefault(BaseUnit);
-
- static KinematicViscosity()
- {
- BaseDimensions = new BaseDimensions(2, 0, -1, 0, 0, 0, 0);
- }
-
- ///
- /// 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.
-#if WINDOWS_UWP
- private
-#else
- public
-#endif
- 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 Properties
-
- ///
- /// The of this quantity.
- ///
- public static QuantityType QuantityType => QuantityType.KinematicViscosity;
-
- ///
- /// The base unit of KinematicViscosity, which is SquareMeterPerSecond. All conversions go via this value.
- ///
- public static KinematicViscosityUnit BaseUnit => KinematicViscosityUnit.SquareMeterPerSecond;
-
- ///
- /// The of this quantity.
- ///
- public static BaseDimensions BaseDimensions
- {
- get;
- }
-
- ///
- /// All units of measurement for the KinematicViscosity quantity.
- ///
- public static KinematicViscosityUnit[] Units { get; } = Enum.GetValues(typeof(KinematicViscosityUnit)).Cast().Except(new KinematicViscosityUnit[]{ KinematicViscosityUnit.Undefined }).ToArray();
-
- ///
- /// 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
-
- ///
- /// Gets an instance of this quantity with a value of 0 in the base unit SquareMeterPerSecond.
- ///
- public static KinematicViscosity Zero => new KinematicViscosity(0, BaseUnit);
-
- ///
- /// Get KinematicViscosity from Centistokes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static KinematicViscosity FromCentistokes(double centistokes)
-#else
- public static KinematicViscosity FromCentistokes(QuantityValue centistokes)
-#endif
- {
- double value = (double) centistokes;
- return new KinematicViscosity(value, KinematicViscosityUnit.Centistokes);
- }
-
- ///
- /// Get KinematicViscosity from Decistokes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static KinematicViscosity FromDecistokes(double decistokes)
-#else
- public static KinematicViscosity FromDecistokes(QuantityValue decistokes)
-#endif
- {
- double value = (double) decistokes;
- return new KinematicViscosity(value, KinematicViscosityUnit.Decistokes);
- }
-
- ///
- /// Get KinematicViscosity from Kilostokes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static KinematicViscosity FromKilostokes(double kilostokes)
-#else
- public static KinematicViscosity FromKilostokes(QuantityValue kilostokes)
-#endif
- {
- double value = (double) kilostokes;
- return new KinematicViscosity(value, KinematicViscosityUnit.Kilostokes);
- }
-
- ///
- /// Get KinematicViscosity from Microstokes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static KinematicViscosity FromMicrostokes(double microstokes)
-#else
- public static KinematicViscosity FromMicrostokes(QuantityValue microstokes)
-#endif
- {
- double value = (double) microstokes;
- return new KinematicViscosity(value, KinematicViscosityUnit.Microstokes);
- }
-
- ///
- /// Get KinematicViscosity from Millistokes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static KinematicViscosity FromMillistokes(double millistokes)
-#else
- public static KinematicViscosity FromMillistokes(QuantityValue millistokes)
-#endif
- {
- double value = (double) millistokes;
- return new KinematicViscosity(value, KinematicViscosityUnit.Millistokes);
- }
-
- ///
- /// Get KinematicViscosity from Nanostokes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static KinematicViscosity FromNanostokes(double nanostokes)
-#else
- public static KinematicViscosity FromNanostokes(QuantityValue nanostokes)
-#endif
- {
- double value = (double) nanostokes;
- return new KinematicViscosity(value, KinematicViscosityUnit.Nanostokes);
- }
-
- ///
- /// Get KinematicViscosity from SquareMetersPerSecond.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static KinematicViscosity FromSquareMetersPerSecond(double squaremeterspersecond)
-#else
- public static KinematicViscosity FromSquareMetersPerSecond(QuantityValue squaremeterspersecond)
-#endif
- {
- double value = (double) squaremeterspersecond;
- return new KinematicViscosity(value, KinematicViscosityUnit.SquareMeterPerSecond);
- }
-
- ///
- /// Get KinematicViscosity from Stokes.
- ///
- /// If value is NaN or Infinity.
-#if WINDOWS_UWP
- [Windows.Foundation.Metadata.DefaultOverload]
- public static KinematicViscosity FromStokes(double stokes)
-#else
- public static KinematicViscosity FromStokes(QuantityValue stokes)
-#endif
- {
- 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.
-#if WINDOWS_UWP
- // Fix name conflict with parameter "value"
- [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")]
- public static KinematicViscosity From(double value, KinematicViscosityUnit fromUnit)
-#else
- public static KinematicViscosity From(QuantityValue value, KinematicViscosityUnit fromUnit)
-#endif
- {
- return new KinematicViscosity((double)value, fromUnit);
- }
-
- ///
- /// Get unit abbreviation string.
- ///
- /// Unit to get abbreviation for.
- /// Unit abbreviation string.
- [UsedImplicitly]
- public static string GetAbbreviation(KinematicViscosityUnit unit)
- {
- return GetAbbreviation(unit, null);
- }
-
- #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
-#if WINDOWS_UWP
- internal
-#else
- public
-#endif
- 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).
- ///