diff --git a/Common/UnitDefinitions/Compressibility.json b/Common/UnitDefinitions/Compressibility.json new file mode 100644 index 0000000000..7c22f0092f --- /dev/null +++ b/Common/UnitDefinitions/Compressibility.json @@ -0,0 +1,101 @@ +{ + "Name": "Compressibility", + "BaseUnit": "InversePascal", + "XmlDoc": "Compressibility is the measure of the relative volume change of a fluid or solid in response to pressure changes.", + "BaseDimensions": { + "L": 1, + "M": -1, + "T": 2 + }, + "Units": [ + { + "SingularName": "InversePascal", + "PluralName": "InversePascals", + "BaseUnits": { + "L": "Meter", + "M": "Kilogram", + "T": "Second" + }, + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "Pa⁻¹", "1/Pa" ] + } + ] + }, + { + "SingularName": "InverseKilopascal", + "PluralName": "InverseKilopascals", + "FromUnitToBaseFunc": "{x} * 1e3", + "FromBaseToUnitFunc": "{x} / 1e3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "kPa⁻¹", "1/kPa" ] + } + ] + }, + { + "SingularName": "InverseMegapascal", + "PluralName": "InverseMegapascals", + "FromUnitToBaseFunc": "{x} * 1e6", + "FromBaseToUnitFunc": "{x} / 1e6", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "kPa⁻¹", "1/kPa" ] + } + ] + }, + { + "SingularName": "InverseAtmosphere", + "PluralName": "InverseAtmospheres", + "FromUnitToBaseFunc": "{x} * 101325", + "FromBaseToUnitFunc": "{x} / 101325", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "atm⁻¹", "1/atm" ] + } + ] + }, + { + "SingularName": "InverseMillibar", + "PluralName": "InverseMillibars", + "FromUnitToBaseFunc": "{x} * 100", + "FromBaseToUnitFunc": "{x} / 100", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "mbar⁻¹", "1/mbar" ] + } + ] + }, + { + "SingularName": "InverseBar", + "PluralName": "InverseBars", + "FromUnitToBaseFunc": "{x} * 1e5", + "FromBaseToUnitFunc": "{x} / 1e5", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "bar⁻¹", "1/bar" ] + } + ] + }, + { + "SingularName": "InversePoundForcePerSquareInch", + "PluralName": "InversePoundsForcePerSquareInch", + "FromUnitToBaseFunc": "{x} * 6.894757293168361e3", + "FromBaseToUnitFunc": "{x} / 6.894757293168361e3", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "psi⁻¹", "1/psi" ] + } + ] + } + ] +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/Compressibility/Compressibility.nfproj b/UnitsNet.NanoFramework/GeneratedCode/Compressibility/Compressibility.nfproj new file mode 100644 index 0000000000..dd14cd1436 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Compressibility/Compressibility.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildToolsPath)..\..\..\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {daf647be-be87-88b9-ee92-dece21fe0dff} + Library + Properties + 512 + UnitsNet + UnitsNet.Compressibility + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.12.0-preview.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Compressibility/UnitsNet.NanoFramework.Compressibility.nuspec b/UnitsNet.NanoFramework/GeneratedCode/Compressibility/UnitsNet.NanoFramework.Compressibility.nuspec new file mode 100644 index 0000000000..52ba59088d --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Compressibility/UnitsNet.NanoFramework.Compressibility.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.Compressibility + 4.121.0 + Units.NET Compressibility - nanoFramework + Andreas Gullberg Larsen,nanoFramework project contributors + UnitsNet + MIT + https://github.com/angularsen/UnitsNet + false + Adds Compressibility units for Units.NET on .NET nanoFramework. For .NET or .NET Core, use UnitsNet instead. + https://raw.githubusercontent.com/angularsen/UnitsNet/ce85185429be345d77eb2ce09c99d59cc9ab8aed/Docs/Images/logo-32.png + + + Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). + en-US + nanoframework unit units measurement si metric imperial abbreviation abbreviations convert conversion parse c# .net immutable uwp uap winrt win10 windows runtime component compressibility + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Compressibility/packages.config b/UnitsNet.NanoFramework/GeneratedCode/Compressibility/packages.config new file mode 100644 index 0000000000..0f8741e8f7 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Compressibility/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/Compressibility.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Compressibility.g.cs new file mode 100644 index 0000000000..e92522ef3f --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/Compressibility.g.cs @@ -0,0 +1,237 @@ +//------------------------------------------------------------------------------ +// +// 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 generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using UnitsNet.Units; + +namespace UnitsNet +{ + /// + /// + /// Compressibility is the measure of the relative volume change of a fluid or solid in response to pressure changes. + /// + public struct Compressibility + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly CompressibilityUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public CompressibilityUnit Unit => _unit; + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to construct this quantity with. + /// The unit representation to construct this quantity with. + /// If value is NaN or Infinity. + public Compressibility(double value, CompressibilityUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of Duration, which is Second. All conversions go via this value. + /// + public static CompressibilityUnit BaseUnit { get; } = CompressibilityUnit.InversePascal; + + /// + /// Represents the largest possible value of Duration + /// + public static Compressibility MaxValue { get; } = new Compressibility(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of Duration + /// + public static Compressibility MinValue { get; } = new Compressibility(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static Compressibility Zero { get; } = new Compressibility(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double InverseAtmospheres => As(CompressibilityUnit.InverseAtmosphere); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseBars => As(CompressibilityUnit.InverseBar); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseKilopascals => As(CompressibilityUnit.InverseKilopascal); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseMegapascals => As(CompressibilityUnit.InverseMegapascal); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseMillibars => As(CompressibilityUnit.InverseMillibar); + + /// + /// Gets a value of this quantity converted into + /// + public double InversePascals => As(CompressibilityUnit.InversePascal); + + /// + /// Gets a value of this quantity converted into + /// + public double InversePoundsForcePerSquareInch => As(CompressibilityUnit.InversePoundForcePerSquareInch); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInverseAtmospheres(double inverseatmospheres) => new Compressibility(inverseatmospheres, CompressibilityUnit.InverseAtmosphere); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInverseBars(double inversebars) => new Compressibility(inversebars, CompressibilityUnit.InverseBar); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInverseKilopascals(double inversekilopascals) => new Compressibility(inversekilopascals, CompressibilityUnit.InverseKilopascal); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInverseMegapascals(double inversemegapascals) => new Compressibility(inversemegapascals, CompressibilityUnit.InverseMegapascal); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInverseMillibars(double inversemillibars) => new Compressibility(inversemillibars, CompressibilityUnit.InverseMillibar); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInversePascals(double inversepascals) => new Compressibility(inversepascals, CompressibilityUnit.InversePascal); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInversePoundsForcePerSquareInch(double inversepoundsforcepersquareinch) => new Compressibility(inversepoundsforcepersquareinch, CompressibilityUnit.InversePoundForcePerSquareInch); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Compressibility unit value. + public static Compressibility From(double value, CompressibilityUnit fromUnit) + { + return new Compressibility(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(CompressibilityUnit unit) => GetValueAs(unit); + + /// + /// Converts this Duration to another Duration with the unit representation . + /// + /// A Duration with the specified unit. + public Compressibility ToUnit(CompressibilityUnit unit) + { + var convertedValue = GetValueAs(unit); + return new Compressibility(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 GetValueInBaseUnit() + { + return Unit switch + { + CompressibilityUnit.InverseAtmosphere => _value * 101325, + CompressibilityUnit.InverseBar => _value * 1e5, + CompressibilityUnit.InverseKilopascal => _value * 1e3, + CompressibilityUnit.InverseMegapascal => _value * 1e6, + CompressibilityUnit.InverseMillibar => _value * 100, + CompressibilityUnit.InversePascal => _value, + CompressibilityUnit.InversePoundForcePerSquareInch => _value * 6.894757293168361e3, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(CompressibilityUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + CompressibilityUnit.InverseAtmosphere => baseUnitValue / 101325, + CompressibilityUnit.InverseBar => baseUnitValue / 1e5, + CompressibilityUnit.InverseKilopascal => baseUnitValue / 1e3, + CompressibilityUnit.InverseMegapascal => baseUnitValue / 1e6, + CompressibilityUnit.InverseMillibar => baseUnitValue / 100, + CompressibilityUnit.InversePascal => baseUnitValue, + CompressibilityUnit.InversePoundForcePerSquareInch => baseUnitValue / 6.894757293168361e3, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/CompressibilityUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/CompressibilityUnit.g.cs new file mode 100644 index 0000000000..5b3e4f4514 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/CompressibilityUnit.g.cs @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +// +// 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 generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum CompressibilityUnit + { + Undefined = 0, + InverseAtmosphere, + InverseBar, + InverseKilopascal, + InverseMegapascal, + InverseMillibar, + InversePascal, + InversePoundForcePerSquareInch, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln index 2aae3bf429..1fc7ade9ba 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln +++ b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln @@ -28,6 +28,8 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Capacitance", "Capacitance\ EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "CoefficientOfThermalExpansion", "CoefficientOfThermalExpansion\CoefficientOfThermalExpansion.nfproj", "{a9514ce6-d4e7-88ca-051e-e9e53610c519}" EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Compressibility", "Compressibility\Compressibility.nfproj", "{daf647be-be87-88b9-ee92-dece21fe0dff}" +EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Density", "Density\Density.nfproj", "{d683a277-5892-aec2-985d-c2343725d0af}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Duration", "Duration\Duration.nfproj", "{3c2ac54f-554c-518b-7c46-3b22d86d0e3b}" @@ -310,6 +312,12 @@ Global {a9514ce6-d4e7-88ca-051e-e9e53610c519}.Release|Any CPU.ActiveCfg = Release|Any CPU {a9514ce6-d4e7-88ca-051e-e9e53610c519}.Release|Any CPU.Build.0 = Release|Any CPU {a9514ce6-d4e7-88ca-051e-e9e53610c519}.Release|Any CPU.Deploy.0 = Release|Any CPU +{daf647be-be87-88b9-ee92-dece21fe0dff}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{daf647be-be87-88b9-ee92-dece21fe0dff}.Debug|Any CPU.Build.0 = Debug|Any CPU +{daf647be-be87-88b9-ee92-dece21fe0dff}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{daf647be-be87-88b9-ee92-dece21fe0dff}.Release|Any CPU.ActiveCfg = Release|Any CPU +{daf647be-be87-88b9-ee92-dece21fe0dff}.Release|Any CPU.Build.0 = Release|Any CPU +{daf647be-be87-88b9-ee92-dece21fe0dff}.Release|Any CPU.Deploy.0 = Release|Any CPU {d683a277-5892-aec2-985d-c2343725d0af}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {d683a277-5892-aec2-985d-c2343725d0af}.Debug|Any CPU.Build.0 = Debug|Any CPU {d683a277-5892-aec2-985d-c2343725d0af}.Debug|Any CPU.Deploy.0 = Debug|Any CPU diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToCompressibilityExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToCompressibilityExtensionsTest.g.cs new file mode 100644 index 0000000000..da846bbb69 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToCompressibilityExtensionsTest.g.cs @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// 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 generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using UnitsNet.NumberExtensions.NumberToCompressibility; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToCompressibilityExtensionsTests + { + [Fact] + public void NumberToInverseAtmospheresTest() => + Assert.Equal(Compressibility.FromInverseAtmospheres(2), 2.InverseAtmospheres()); + + [Fact] + public void NumberToInverseBarsTest() => + Assert.Equal(Compressibility.FromInverseBars(2), 2.InverseBars()); + + [Fact] + public void NumberToInverseKilopascalsTest() => + Assert.Equal(Compressibility.FromInverseKilopascals(2), 2.InverseKilopascals()); + + [Fact] + public void NumberToInverseMegapascalsTest() => + Assert.Equal(Compressibility.FromInverseMegapascals(2), 2.InverseMegapascals()); + + [Fact] + public void NumberToInverseMillibarsTest() => + Assert.Equal(Compressibility.FromInverseMillibars(2), 2.InverseMillibars()); + + [Fact] + public void NumberToInversePascalsTest() => + Assert.Equal(Compressibility.FromInversePascals(2), 2.InversePascals()); + + [Fact] + public void NumberToInversePoundsForcePerSquareInchTest() => + Assert.Equal(Compressibility.FromInversePoundsForcePerSquareInch(2), 2.InversePoundsForcePerSquareInch()); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToCompressibilityExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToCompressibilityExtensions.g.cs new file mode 100644 index 0000000000..40f8b04061 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToCompressibilityExtensions.g.cs @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// 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 generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; + +#nullable enable + +namespace UnitsNet.NumberExtensions.NumberToCompressibility +{ + /// + /// A number to Compressibility Extensions + /// + public static class NumberToCompressibilityExtensions + { + /// + public static Compressibility InverseAtmospheres(this T value) => + Compressibility.FromInverseAtmospheres(Convert.ToDouble(value)); + + /// + public static Compressibility InverseBars(this T value) => + Compressibility.FromInverseBars(Convert.ToDouble(value)); + + /// + public static Compressibility InverseKilopascals(this T value) => + Compressibility.FromInverseKilopascals(Convert.ToDouble(value)); + + /// + public static Compressibility InverseMegapascals(this T value) => + Compressibility.FromInverseMegapascals(Convert.ToDouble(value)); + + /// + public static Compressibility InverseMillibars(this T value) => + Compressibility.FromInverseMillibars(Convert.ToDouble(value)); + + /// + public static Compressibility InversePascals(this T value) => + Compressibility.FromInversePascals(Convert.ToDouble(value)); + + /// + public static Compressibility InversePoundsForcePerSquareInch(this T value) => + Compressibility.FromInversePoundsForcePerSquareInch(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.Tests/CustomCode/CompressibilityTests.cs b/UnitsNet.Tests/CustomCode/CompressibilityTests.cs new file mode 100644 index 0000000000..689efed670 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/CompressibilityTests.cs @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// +// 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 generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; + +namespace UnitsNet.Tests.CustomCode +{ + public class CompressibilityTests : CompressibilityTestsBase + { + // Override properties in base class here + + protected override double InversePascalsInOneInversePascal => 1; + protected override double InverseMillibarsInOneInversePascal => 1e-2; + protected override double InverseKilopascalsInOneInversePascal => 1e-3; + protected override double InverseMegapascalsInOneInversePascal => 1e-6; + protected override double InverseBarsInOneInversePascal => 1e-5; + protected override double InversePoundsForcePerSquareInchInOneInversePascal => 1.450377377302092151542e-4; + protected override double InverseAtmospheresInOneInversePascal => 9.86923266716013e-6; + + protected override bool SupportsSIUnitSystem => true; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index 636742bff9..61311e9e3b 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -47,6 +47,7 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, Quantity.From(3, BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)); Assertion(3, CapacitanceUnit.Picofarad, Quantity.From(3, CapacitanceUnit.Picofarad)); Assertion(3, CoefficientOfThermalExpansionUnit.InverseKelvin, Quantity.From(3, CoefficientOfThermalExpansionUnit.InverseKelvin)); + Assertion(3, CompressibilityUnit.InversePoundForcePerSquareInch, Quantity.From(3, CompressibilityUnit.InversePoundForcePerSquareInch)); Assertion(3, DensityUnit.TonnePerCubicMillimeter, Quantity.From(3, DensityUnit.TonnePerCubicMillimeter)); Assertion(3, DurationUnit.Year365, Quantity.From(3, DurationUnit.Year365)); Assertion(3, DynamicViscosityUnit.Reyn, Quantity.From(3, DynamicViscosityUnit.Reyn)); @@ -166,6 +167,7 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(BrakeSpecificFuelConsumption.Info, BrakeSpecificFuelConsumption.Zero); Assertion(Capacitance.Info, Capacitance.Zero); Assertion(CoefficientOfThermalExpansion.Info, CoefficientOfThermalExpansion.Zero); + Assertion(Compressibility.Info, Compressibility.Zero); Assertion(Density.Info, Density.Zero); Assertion(Duration.Info, Duration.Zero); Assertion(DynamicViscosity.Info, DynamicViscosity.Zero); @@ -285,6 +287,7 @@ public void Type_EqualsStaticQuantityTypeProperty() Assertion(BrakeSpecificFuelConsumption.QuantityType, BrakeSpecificFuelConsumption.Zero); Assertion(Capacitance.QuantityType, Capacitance.Zero); Assertion(CoefficientOfThermalExpansion.QuantityType, CoefficientOfThermalExpansion.Zero); + Assertion(Compressibility.QuantityType, Compressibility.Zero); Assertion(Density.QuantityType, Density.Zero); Assertion(Duration.QuantityType, Duration.Zero); Assertion(DynamicViscosity.QuantityType, DynamicViscosity.Zero); @@ -404,6 +407,7 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(BrakeSpecificFuelConsumption.BaseDimensions, BrakeSpecificFuelConsumption.Zero); Assertion(Capacitance.BaseDimensions, Capacitance.Zero); Assertion(CoefficientOfThermalExpansion.BaseDimensions, CoefficientOfThermalExpansion.Zero); + Assertion(Compressibility.BaseDimensions, Compressibility.Zero); Assertion(Density.BaseDimensions, Density.Zero); Assertion(Duration.BaseDimensions, Duration.Zero); Assertion(DynamicViscosity.BaseDimensions, DynamicViscosity.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs new file mode 100644 index 0000000000..d707793ecc --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs @@ -0,0 +1,691 @@ +//------------------------------------------------------------------------------ +// +// 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 generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of Compressibility. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class CompressibilityTestsBase : QuantityTestsBase + { + protected abstract double InverseAtmospheresInOneInversePascal { get; } + protected abstract double InverseBarsInOneInversePascal { get; } + protected abstract double InverseKilopascalsInOneInversePascal { get; } + protected abstract double InverseMegapascalsInOneInversePascal { get; } + protected abstract double InverseMillibarsInOneInversePascal { get; } + protected abstract double InversePascalsInOneInversePascal { get; } + protected abstract double InversePoundsForcePerSquareInchInOneInversePascal { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double InverseAtmospheresTolerance { get { return 1e-5; } } + protected virtual double InverseBarsTolerance { get { return 1e-5; } } + protected virtual double InverseKilopascalsTolerance { get { return 1e-5; } } + protected virtual double InverseMegapascalsTolerance { get { return 1e-5; } } + protected virtual double InverseMillibarsTolerance { get { return 1e-5; } } + protected virtual double InversePascalsTolerance { get { return 1e-5; } } + protected virtual double InversePoundsForcePerSquareInchTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(CompressibilityUnit unit) + { + return unit switch + { + CompressibilityUnit.InverseAtmosphere => (InverseAtmospheresInOneInversePascal, InverseAtmospheresTolerance), + CompressibilityUnit.InverseBar => (InverseBarsInOneInversePascal, InverseBarsTolerance), + CompressibilityUnit.InverseKilopascal => (InverseKilopascalsInOneInversePascal, InverseKilopascalsTolerance), + CompressibilityUnit.InverseMegapascal => (InverseMegapascalsInOneInversePascal, InverseMegapascalsTolerance), + CompressibilityUnit.InverseMillibar => (InverseMillibarsInOneInversePascal, InverseMillibarsTolerance), + CompressibilityUnit.InversePascal => (InversePascalsInOneInversePascal, InversePascalsTolerance), + CompressibilityUnit.InversePoundForcePerSquareInch => (InversePoundsForcePerSquareInchInOneInversePascal, InversePoundsForcePerSquareInchTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { CompressibilityUnit.InverseAtmosphere }, + new object[] { CompressibilityUnit.InverseBar }, + new object[] { CompressibilityUnit.InverseKilopascal }, + new object[] { CompressibilityUnit.InverseMegapascal }, + new object[] { CompressibilityUnit.InverseMillibar }, + new object[] { CompressibilityUnit.InversePascal }, + new object[] { CompressibilityUnit.InversePoundForcePerSquareInch }, + }; + + [Fact] + public void Ctor_WithUndefinedUnit_ThrowsArgumentException() + { + Assert.Throws(() => new Compressibility((double)0.0, CompressibilityUnit.Undefined)); + } + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new Compressibility(); + Assert.Equal(0, quantity.Value); + Assert.Equal(CompressibilityUnit.InversePascal, quantity.Unit); + } + + + [Fact] + public void Ctor_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => new Compressibility(double.PositiveInfinity, CompressibilityUnit.InversePascal)); + Assert.Throws(() => new Compressibility(double.NegativeInfinity, CompressibilityUnit.InversePascal)); + } + + [Fact] + public void Ctor_WithNaNValue_ThrowsArgumentException() + { + Assert.Throws(() => new Compressibility(double.NaN, CompressibilityUnit.InversePascal)); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new Compressibility(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new Compressibility(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (Compressibility) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void Compressibility_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new Compressibility(1, CompressibilityUnit.InversePascal); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(Compressibility.Zero, quantityInfo.Zero); + Assert.Equal("Compressibility", quantityInfo.Name); + Assert.Equal(QuantityType.Compressibility, quantityInfo.QuantityType); + + var units = EnumUtils.GetEnumValues().Except(new[] {CompressibilityUnit.Undefined}).ToArray(); + var unitNames = units.Select(x => x.ToString()); + + // Obsolete members + Assert.Equal(units, quantityInfo.Units); + Assert.Equal(unitNames, quantityInfo.UnitNames); + } + + [Fact] + public void InversePascalToCompressibilityUnits() + { + Compressibility inversepascal = Compressibility.FromInversePascals(1); + AssertEx.EqualTolerance(InverseAtmospheresInOneInversePascal, inversepascal.InverseAtmospheres, InverseAtmospheresTolerance); + AssertEx.EqualTolerance(InverseBarsInOneInversePascal, inversepascal.InverseBars, InverseBarsTolerance); + AssertEx.EqualTolerance(InverseKilopascalsInOneInversePascal, inversepascal.InverseKilopascals, InverseKilopascalsTolerance); + AssertEx.EqualTolerance(InverseMegapascalsInOneInversePascal, inversepascal.InverseMegapascals, InverseMegapascalsTolerance); + AssertEx.EqualTolerance(InverseMillibarsInOneInversePascal, inversepascal.InverseMillibars, InverseMillibarsTolerance); + AssertEx.EqualTolerance(InversePascalsInOneInversePascal, inversepascal.InversePascals, InversePascalsTolerance); + AssertEx.EqualTolerance(InversePoundsForcePerSquareInchInOneInversePascal, inversepascal.InversePoundsForcePerSquareInch, InversePoundsForcePerSquareInchTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + var quantity00 = Compressibility.From(1, CompressibilityUnit.InverseAtmosphere); + AssertEx.EqualTolerance(1, quantity00.InverseAtmospheres, InverseAtmospheresTolerance); + Assert.Equal(CompressibilityUnit.InverseAtmosphere, quantity00.Unit); + + var quantity01 = Compressibility.From(1, CompressibilityUnit.InverseBar); + AssertEx.EqualTolerance(1, quantity01.InverseBars, InverseBarsTolerance); + Assert.Equal(CompressibilityUnit.InverseBar, quantity01.Unit); + + var quantity02 = Compressibility.From(1, CompressibilityUnit.InverseKilopascal); + AssertEx.EqualTolerance(1, quantity02.InverseKilopascals, InverseKilopascalsTolerance); + Assert.Equal(CompressibilityUnit.InverseKilopascal, quantity02.Unit); + + var quantity03 = Compressibility.From(1, CompressibilityUnit.InverseMegapascal); + AssertEx.EqualTolerance(1, quantity03.InverseMegapascals, InverseMegapascalsTolerance); + Assert.Equal(CompressibilityUnit.InverseMegapascal, quantity03.Unit); + + var quantity04 = Compressibility.From(1, CompressibilityUnit.InverseMillibar); + AssertEx.EqualTolerance(1, quantity04.InverseMillibars, InverseMillibarsTolerance); + Assert.Equal(CompressibilityUnit.InverseMillibar, quantity04.Unit); + + var quantity05 = Compressibility.From(1, CompressibilityUnit.InversePascal); + AssertEx.EqualTolerance(1, quantity05.InversePascals, InversePascalsTolerance); + Assert.Equal(CompressibilityUnit.InversePascal, quantity05.Unit); + + var quantity06 = Compressibility.From(1, CompressibilityUnit.InversePoundForcePerSquareInch); + AssertEx.EqualTolerance(1, quantity06.InversePoundsForcePerSquareInch, InversePoundsForcePerSquareInchTolerance); + Assert.Equal(CompressibilityUnit.InversePoundForcePerSquareInch, quantity06.Unit); + + } + + [Fact] + public void FromInversePascals_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => Compressibility.FromInversePascals(double.PositiveInfinity)); + Assert.Throws(() => Compressibility.FromInversePascals(double.NegativeInfinity)); + } + + [Fact] + public void FromInversePascals_WithNanValue_ThrowsArgumentException() + { + Assert.Throws(() => Compressibility.FromInversePascals(double.NaN)); + } + + [Fact] + public void As() + { + var inversepascal = Compressibility.FromInversePascals(1); + AssertEx.EqualTolerance(InverseAtmospheresInOneInversePascal, inversepascal.As(CompressibilityUnit.InverseAtmosphere), InverseAtmospheresTolerance); + AssertEx.EqualTolerance(InverseBarsInOneInversePascal, inversepascal.As(CompressibilityUnit.InverseBar), InverseBarsTolerance); + AssertEx.EqualTolerance(InverseKilopascalsInOneInversePascal, inversepascal.As(CompressibilityUnit.InverseKilopascal), InverseKilopascalsTolerance); + AssertEx.EqualTolerance(InverseMegapascalsInOneInversePascal, inversepascal.As(CompressibilityUnit.InverseMegapascal), InverseMegapascalsTolerance); + AssertEx.EqualTolerance(InverseMillibarsInOneInversePascal, inversepascal.As(CompressibilityUnit.InverseMillibar), InverseMillibarsTolerance); + AssertEx.EqualTolerance(InversePascalsInOneInversePascal, inversepascal.As(CompressibilityUnit.InversePascal), InversePascalsTolerance); + AssertEx.EqualTolerance(InversePoundsForcePerSquareInchInOneInversePascal, inversepascal.As(CompressibilityUnit.InversePoundForcePerSquareInch), InversePoundsForcePerSquareInchTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new Compressibility(value: 1, unit: Compressibility.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = (double) AsWithSIUnitSystem(); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(CompressibilityUnit unit) + { + var inBaseUnits = Compressibility.From(1.0, Compressibility.BaseUnit); + var converted = inBaseUnits.ToUnit(unit); + + var conversionFactor = GetConversionFactor(unit); + AssertEx.EqualTolerance(conversionFactor.UnitsInBaseUnit, (double)converted.Value, conversionFactor.Tolerence); + Assert.Equal(unit, converted.Unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_WithSameUnits_AreEqual(CompressibilityUnit unit) + { + var quantity = Compressibility.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(CompressibilityUnit unit) + { + // See if there is a unit available that is not the base unit. + var fromUnit = Compressibility.Units.FirstOrDefault(u => u != Compressibility.BaseUnit && u != CompressibilityUnit.Undefined); + + // If there is only one unit for the quantity, we must use the base unit. + if (fromUnit == CompressibilityUnit.Undefined) + fromUnit = Compressibility.BaseUnit; + + var quantity = Compressibility.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + Compressibility inversepascal = Compressibility.FromInversePascals(1); + AssertEx.EqualTolerance(1, Compressibility.FromInverseAtmospheres(inversepascal.InverseAtmospheres).InversePascals, InverseAtmospheresTolerance); + AssertEx.EqualTolerance(1, Compressibility.FromInverseBars(inversepascal.InverseBars).InversePascals, InverseBarsTolerance); + AssertEx.EqualTolerance(1, Compressibility.FromInverseKilopascals(inversepascal.InverseKilopascals).InversePascals, InverseKilopascalsTolerance); + AssertEx.EqualTolerance(1, Compressibility.FromInverseMegapascals(inversepascal.InverseMegapascals).InversePascals, InverseMegapascalsTolerance); + AssertEx.EqualTolerance(1, Compressibility.FromInverseMillibars(inversepascal.InverseMillibars).InversePascals, InverseMillibarsTolerance); + AssertEx.EqualTolerance(1, Compressibility.FromInversePascals(inversepascal.InversePascals).InversePascals, InversePascalsTolerance); + AssertEx.EqualTolerance(1, Compressibility.FromInversePoundsForcePerSquareInch(inversepascal.InversePoundsForcePerSquareInch).InversePascals, InversePoundsForcePerSquareInchTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + Compressibility v = Compressibility.FromInversePascals(1); + AssertEx.EqualTolerance(-1, -v.InversePascals, InversePascalsTolerance); + AssertEx.EqualTolerance(2, (Compressibility.FromInversePascals(3)-v).InversePascals, InversePascalsTolerance); + AssertEx.EqualTolerance(2, (v + v).InversePascals, InversePascalsTolerance); + AssertEx.EqualTolerance(10, (v*10).InversePascals, InversePascalsTolerance); + AssertEx.EqualTolerance(10, (10*v).InversePascals, InversePascalsTolerance); + AssertEx.EqualTolerance(2, (Compressibility.FromInversePascals(10)/5).InversePascals, InversePascalsTolerance); + AssertEx.EqualTolerance(2, Compressibility.FromInversePascals(10)/Compressibility.FromInversePascals(5), InversePascalsTolerance); + } + + [Fact] + public void ComparisonOperators() + { + Compressibility oneInversePascal = Compressibility.FromInversePascals(1); + Compressibility twoInversePascals = Compressibility.FromInversePascals(2); + + Assert.True(oneInversePascal < twoInversePascals); + Assert.True(oneInversePascal <= twoInversePascals); + Assert.True(twoInversePascals > oneInversePascal); + Assert.True(twoInversePascals >= oneInversePascal); + + Assert.False(oneInversePascal > twoInversePascals); + Assert.False(oneInversePascal >= twoInversePascals); + Assert.False(twoInversePascals < oneInversePascal); + Assert.False(twoInversePascals <= oneInversePascal); + } + + [Fact] + public void CompareToIsImplemented() + { + Compressibility inversepascal = Compressibility.FromInversePascals(1); + Assert.Equal(0, inversepascal.CompareTo(inversepascal)); + Assert.True(inversepascal.CompareTo(Compressibility.Zero) > 0); + Assert.True(Compressibility.Zero.CompareTo(inversepascal) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + Compressibility inversepascal = Compressibility.FromInversePascals(1); + Assert.Throws(() => inversepascal.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + Compressibility inversepascal = Compressibility.FromInversePascals(1); + Assert.Throws(() => inversepascal.CompareTo(null)); + } + + [Fact] + public void EqualityOperators() + { + var a = Compressibility.FromInversePascals(1); + var b = Compressibility.FromInversePascals(2); + +#pragma warning disable CS8073 +// ReSharper disable EqualExpressionComparison + + Assert.True(a == a); + Assert.False(a != a); + + Assert.True(a != b); + Assert.False(a == b); + + Assert.False(a == null); + Assert.False(null == a); + +// ReSharper restore EqualExpressionComparison +#pragma warning restore CS8073 + } + + [Fact] + public void Equals_SameType_IsImplemented() + { + var a = Compressibility.FromInversePascals(1); + var b = Compressibility.FromInversePascals(2); + + Assert.True(a.Equals(a)); + Assert.False(a.Equals(b)); + } + + [Fact] + public void Equals_QuantityAsObject_IsImplemented() + { + object a = Compressibility.FromInversePascals(1); + object b = Compressibility.FromInversePascals(2); + + Assert.True(a.Equals(a)); + Assert.False(a.Equals(b)); + Assert.False(a.Equals((object)null)); + } + + [Fact] + public void Equals_RelativeTolerance_IsImplemented() + { + var v = Compressibility.FromInversePascals(1); + Assert.True(v.Equals(Compressibility.FromInversePascals(1), InversePascalsTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(Compressibility.Zero, InversePascalsTolerance, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = Compressibility.FromInversePascals(1); + Assert.Throws(() => v.Equals(Compressibility.FromInversePascals(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + Compressibility inversepascal = Compressibility.FromInversePascals(1); + Assert.False(inversepascal.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + Compressibility inversepascal = Compressibility.FromInversePascals(1); + Assert.False(inversepascal.Equals(null)); + } + + [Fact] + public void UnitsDoesNotContainUndefined() + { + Assert.DoesNotContain(CompressibilityUnit.Undefined, Compressibility.Units); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(CompressibilityUnit)).Cast(); + foreach(var unit in units) + { + if (unit == CompressibilityUnit.Undefined) + continue; + + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(Compressibility.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentUICulture; + Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 atm⁻¹", new Compressibility(1, CompressibilityUnit.InverseAtmosphere).ToString()); + Assert.Equal("1 bar⁻¹", new Compressibility(1, CompressibilityUnit.InverseBar).ToString()); + Assert.Equal("1 kPa⁻¹", new Compressibility(1, CompressibilityUnit.InverseKilopascal).ToString()); + Assert.Equal("1 kPa⁻¹", new Compressibility(1, CompressibilityUnit.InverseMegapascal).ToString()); + Assert.Equal("1 mbar⁻¹", new Compressibility(1, CompressibilityUnit.InverseMillibar).ToString()); + Assert.Equal("1 Pa⁻¹", new Compressibility(1, CompressibilityUnit.InversePascal).ToString()); + Assert.Equal("1 psi⁻¹", new Compressibility(1, CompressibilityUnit.InversePoundForcePerSquareInch).ToString()); + } + finally + { + Thread.CurrentThread.CurrentUICulture = prevCulture; + } + } + + [Fact] + public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCultureSinceThereAreNoMappings() + { + // Chose this culture, because we don't currently have any abbreviations mapped for that culture and we expect the en-US to be used as fallback. + var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); + + Assert.Equal("1 atm⁻¹", new Compressibility(1, CompressibilityUnit.InverseAtmosphere).ToString(swedishCulture)); + Assert.Equal("1 bar⁻¹", new Compressibility(1, CompressibilityUnit.InverseBar).ToString(swedishCulture)); + Assert.Equal("1 kPa⁻¹", new Compressibility(1, CompressibilityUnit.InverseKilopascal).ToString(swedishCulture)); + Assert.Equal("1 kPa⁻¹", new Compressibility(1, CompressibilityUnit.InverseMegapascal).ToString(swedishCulture)); + Assert.Equal("1 mbar⁻¹", new Compressibility(1, CompressibilityUnit.InverseMillibar).ToString(swedishCulture)); + Assert.Equal("1 Pa⁻¹", new Compressibility(1, CompressibilityUnit.InversePascal).ToString(swedishCulture)); + Assert.Equal("1 psi⁻¹", new Compressibility(1, CompressibilityUnit.InversePoundForcePerSquareInch).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentUICulture; + try + { + CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 Pa⁻¹", new Compressibility(0.123456, CompressibilityUnit.InversePascal).ToString("s1")); + Assert.Equal("0.12 Pa⁻¹", new Compressibility(0.123456, CompressibilityUnit.InversePascal).ToString("s2")); + Assert.Equal("0.123 Pa⁻¹", new Compressibility(0.123456, CompressibilityUnit.InversePascal).ToString("s3")); + Assert.Equal("0.1235 Pa⁻¹", new Compressibility(0.123456, CompressibilityUnit.InversePascal).ToString("s4")); + } + finally + { + CultureInfo.CurrentUICulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 Pa⁻¹", new Compressibility(0.123456, CompressibilityUnit.InversePascal).ToString("s1", culture)); + Assert.Equal("0.12 Pa⁻¹", new Compressibility(0.123456, CompressibilityUnit.InversePascal).ToString("s2", culture)); + Assert.Equal("0.123 Pa⁻¹", new Compressibility(0.123456, CompressibilityUnit.InversePascal).ToString("s3", culture)); + Assert.Equal("0.1235 Pa⁻¹", new Compressibility(0.123456, CompressibilityUnit.InversePascal).ToString("s4", culture)); + } + + + [Fact] + public void ToString_NullFormat_ThrowsArgumentNullException() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Throws(() => quantity.ToString(null, null, null)); + } + + [Fact] + public void ToString_NullArgs_ThrowsArgumentNullException() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Throws(() => quantity.ToString(null, "g", null)); + } + + [Fact] + public void ToString_NullProvider_EqualsCurrentUICulture() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal(quantity.ToString(CultureInfo.CurrentUICulture, "g"), quantity.ToString(null, "g")); + } + + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(Compressibility))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(CompressibilityUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityType_EqualsQuantityType() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal(QuantityType.Compressibility, Convert.ChangeType(quantity, typeof(QuantityType))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal(Compressibility.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal(Compressibility.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = Compressibility.FromInversePascals(1.0); + Assert.Equal(new {Compressibility.Info.Name, quantity.Value, quantity.Unit}.GetHashCode(), quantity.GetHashCode()); + } + + [Theory] + [InlineData(1.0)] + [InlineData(-1.0)] + public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) + { + var quantity = Compressibility.FromInversePascals(value); + Assert.Equal(Compressibility.FromInversePascals(-value), -quantity); + } + } +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Compressibility.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Compressibility.g.cs new file mode 100644 index 0000000000..6362bd4a39 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Compressibility.g.cs @@ -0,0 +1,707 @@ +//------------------------------------------------------------------------------ +// +// 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 generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; +using UnitsNet.InternalHelpers; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// Compressibility is the measure of the relative volume change of a fluid or solid in response to pressure changes. + /// + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. + public sealed partial class Compressibility : IQuantity + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly CompressibilityUnit? _unit; + + static Compressibility() + { + BaseDimensions = new BaseDimensions(1, -1, 2, 0, 0, 0, 0); + BaseUnit = CompressibilityUnit.InversePascal; + MaxValue = new Compressibility(double.MaxValue, BaseUnit); + MinValue = new Compressibility(double.MinValue, BaseUnit); + QuantityType = QuantityType.Compressibility; + Units = Enum.GetValues(typeof(CompressibilityUnit)).Cast().Except(new CompressibilityUnit[]{ CompressibilityUnit.Undefined }).ToArray(); + Zero = new Compressibility(0, BaseUnit); + Info = new QuantityInfo(QuantityType.Compressibility, Units.Cast().ToArray(), BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with a value of 0 in the base unit InversePascal. + /// + /// + /// Windows Runtime Component requires a default constructor. + /// + public Compressibility() + { + _value = 0; + _unit = BaseUnit; + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to construct this quantity with. + /// The unit representation to construct this quantity with. + /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component. + /// If value is NaN or Infinity. + private Compressibility(double value, CompressibilityUnit unit) + { + if (unit == CompressibilityUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(value, nameof(value)); + _unit = unit; + } + + #region Static Properties + + /// + /// Information about the quantity type, such as unit values and names. + /// + internal static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of Compressibility, which is InversePascal. All conversions go via this value. + /// + public static CompressibilityUnit BaseUnit { get; } + + /// + /// Represents the largest possible value of Compressibility + /// + public static Compressibility MaxValue { get; } + + /// + /// Represents the smallest possible value of Compressibility + /// + public static Compressibility MinValue { get; } + + /// + /// The of this quantity. + /// + [Obsolete("QuantityType will be removed in the future. Use the Info property instead.")] + public static QuantityType QuantityType { get; } + + /// + /// All units of measurement for the Compressibility quantity. + /// + public static CompressibilityUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit InversePascal. + /// + public static Compressibility Zero { get; } + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => Convert.ToDouble(_value); + + /// + object IQuantity.Unit => Unit; + + /// + /// The unit this quantity was constructed with -or- if default ctor was used. + /// + public CompressibilityUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + internal QuantityInfo QuantityInfo => Info; + + /// + /// The of this quantity. + /// + [Obsolete("QuantityType will be removed in the future. Use the Info property instead.")] + public QuantityType Type => Compressibility.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => Compressibility.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double InverseAtmospheres => As(CompressibilityUnit.InverseAtmosphere); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseBars => As(CompressibilityUnit.InverseBar); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseKilopascals => As(CompressibilityUnit.InverseKilopascal); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseMegapascals => As(CompressibilityUnit.InverseMegapascal); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseMillibars => As(CompressibilityUnit.InverseMillibar); + + /// + /// Gets a value of this quantity converted into + /// + public double InversePascals => As(CompressibilityUnit.InversePascal); + + /// + /// Gets a value of this quantity converted into + /// + public double InversePoundsForcePerSquareInch => As(CompressibilityUnit.InversePoundForcePerSquareInch); + + #endregion + + #region Static Methods + + internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbreviationsCache) + { + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InverseAtmosphere, new CultureInfo("en-US"), false, true, new string[]{"atm⁻¹", "1/atm"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InverseBar, new CultureInfo("en-US"), false, true, new string[]{"bar⁻¹", "1/bar"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InverseKilopascal, new CultureInfo("en-US"), false, true, new string[]{"kPa⁻¹", "1/kPa"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InverseMegapascal, new CultureInfo("en-US"), false, true, new string[]{"kPa⁻¹", "1/kPa"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InverseMillibar, new CultureInfo("en-US"), false, true, new string[]{"mbar⁻¹", "1/mbar"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InversePascal, new CultureInfo("en-US"), false, true, new string[]{"Pa⁻¹", "1/Pa"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InversePoundForcePerSquareInch, new CultureInfo("en-US"), false, true, new string[]{"psi⁻¹", "1/psi"}); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(CompressibilityUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static string GetAbbreviation(CompressibilityUnit unit, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Compressibility FromInverseAtmospheres(double inverseatmospheres) + { + double value = (double) inverseatmospheres; + return new Compressibility(value, CompressibilityUnit.InverseAtmosphere); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Compressibility FromInverseBars(double inversebars) + { + double value = (double) inversebars; + return new Compressibility(value, CompressibilityUnit.InverseBar); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Compressibility FromInverseKilopascals(double inversekilopascals) + { + double value = (double) inversekilopascals; + return new Compressibility(value, CompressibilityUnit.InverseKilopascal); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Compressibility FromInverseMegapascals(double inversemegapascals) + { + double value = (double) inversemegapascals; + return new Compressibility(value, CompressibilityUnit.InverseMegapascal); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Compressibility FromInverseMillibars(double inversemillibars) + { + double value = (double) inversemillibars; + return new Compressibility(value, CompressibilityUnit.InverseMillibar); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Compressibility FromInversePascals(double inversepascals) + { + double value = (double) inversepascals; + return new Compressibility(value, CompressibilityUnit.InversePascal); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Compressibility FromInversePoundsForcePerSquareInch(double inversepoundsforcepersquareinch) + { + double value = (double) inversepoundsforcepersquareinch; + return new Compressibility(value, CompressibilityUnit.InversePoundForcePerSquareInch); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Compressibility unit value. + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static Compressibility From(double value, CompressibilityUnit fromUnit) + { + return new Compressibility((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static Compressibility Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static Compressibility Parse(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out Compressibility result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Compressibility result) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static CompressibilityUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static CompressibilityUnit ParseUnit(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.Parse(str, provider); + } + + public static bool TryParseUnit(string str, out CompressibilityUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out CompressibilityUnit unit) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj is null) throw new ArgumentNullException(nameof(obj)); + if (!(obj is Compressibility objCompressibility)) throw new ArgumentException("Expected type Compressibility.", nameof(obj)); + + return CompareTo(objCompressibility); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods + internal int CompareTo(Compressibility other) + { + return _value.CompareTo(other.AsBaseNumericType(this.Unit)); + } + + [Windows.Foundation.Metadata.DefaultOverload] + public override bool Equals(object obj) + { + if (obj is null || !(obj is Compressibility objCompressibility)) + return false; + + return Equals(objCompressibility); + } + + public bool Equals(Compressibility other) + { + return _value.Equals(other.AsBaseNumericType(this.Unit)); + } + + /// + /// + /// Compare equality to another Compressibility 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(Compressibility 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 Compressibility. + public override int GetHashCode() + { + return new { Info.Name, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + double IQuantity.As(object unit) => As((CompressibilityUnit)unit); + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(CompressibilityUnit unit) + { + if (Unit == unit) + return Convert.ToDouble(Value); + + var converted = AsBaseNumericType(unit); + return Convert.ToDouble(converted); + } + + /// + /// Converts this Compressibility to another Compressibility with the unit representation . + /// + /// A Compressibility with the specified unit. + public Compressibility ToUnit(CompressibilityUnit unit) + { + var convertedValue = AsBaseNumericType(unit); + return new Compressibility(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 CompressibilityUnit.InverseAtmosphere: return _value * 101325; + case CompressibilityUnit.InverseBar: return _value * 1e5; + case CompressibilityUnit.InverseKilopascal: return _value * 1e3; + case CompressibilityUnit.InverseMegapascal: return _value * 1e6; + case CompressibilityUnit.InverseMillibar: return _value * 100; + case CompressibilityUnit.InversePascal: return _value; + case CompressibilityUnit.InversePoundForcePerSquareInch: return _value * 6.894757293168361e3; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double AsBaseNumericType(CompressibilityUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = AsBaseUnit(); + + switch(unit) + { + case CompressibilityUnit.InverseAtmosphere: return baseUnitValue / 101325; + case CompressibilityUnit.InverseBar: return baseUnitValue / 1e5; + case CompressibilityUnit.InverseKilopascal: return baseUnitValue / 1e3; + case CompressibilityUnit.InverseMegapascal: return baseUnitValue / 1e6; + case CompressibilityUnit.InverseMillibar: return baseUnitValue / 100; + case CompressibilityUnit.InversePascal: return baseUnitValue; + case CompressibilityUnit.InversePoundForcePerSquareInch: return baseUnitValue / 6.894757293168361e3; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Get default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(null); + } + + /// + /// Get string representation of value and unit. Using two significant digits after radix. + /// + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName) + { + var provider = cultureName; + return ToString(provider, 2); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString(string cultureName, int significantDigitsAfterRadix) + { + var provider = cultureName; + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implicitly included as arguments 0 and 1. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args) + { + var provider = GetFormatProviderFromCultureName(cultureName); + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? GlobalConfiguration.DefaultCulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + #endregion + + private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName) + { + return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null; + } + } +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs index c4bd62c635..7f8c95d0fb 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs @@ -80,6 +80,9 @@ internal static bool TryFrom(double value, Enum unit, out IQuantity quantity) case CoefficientOfThermalExpansionUnit coefficientOfThermalExpansionUnit: quantity = CoefficientOfThermalExpansion.From(value, coefficientOfThermalExpansionUnit); return true; + case CompressibilityUnit compressibilityUnit: + quantity = Compressibility.From(value, compressibilityUnit); + return true; case DensityUnit densityUnit: quantity = Density.From(value, densityUnit); return true; @@ -466,6 +469,9 @@ internal static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type q if (quantityType == typeof(CoefficientOfThermalExpansion)) return parser.TryParse(quantityString, formatProvider, CoefficientOfThermalExpansion.From, out quantity); + if (quantityType == typeof(Compressibility)) + return parser.TryParse(quantityString, formatProvider, Compressibility.From, out quantity); + if (quantityType == typeof(Density)) return parser.TryParse(quantityString, formatProvider, Density.From, out quantity); @@ -782,6 +788,7 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(BrakeSpecificFuelConsumption); yield return typeof(Capacitance); yield return typeof(CoefficientOfThermalExpansion); + yield return typeof(Compressibility); yield return typeof(Density); yield return typeof(Duration); yield return typeof(DynamicViscosity); diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs index 0da8ff7922..c99f5e619c 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs @@ -46,6 +46,7 @@ public enum QuantityType BrakeSpecificFuelConsumption, Capacitance, CoefficientOfThermalExpansion, + Compressibility, Density, Duration, DynamicViscosity, diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/CompressibilityUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/CompressibilityUnit.g.cs new file mode 100644 index 0000000000..5b3e4f4514 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/CompressibilityUnit.g.cs @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +// +// 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 generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum CompressibilityUnit + { + Undefined = 0, + InverseAtmosphere, + InverseBar, + InverseKilopascal, + InverseMegapascal, + InverseMillibar, + InversePascal, + InversePoundForcePerSquareInch, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs new file mode 100644 index 0000000000..681bf11347 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs @@ -0,0 +1,1005 @@ +//------------------------------------------------------------------------------ +// +// 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 generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Globalization; +using System.Linq; +using System.Runtime.Serialization; +using JetBrains.Annotations; +using UnitsNet.InternalHelpers; +using UnitsNet.Units; + +#nullable enable + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// Compressibility is the measure of the relative volume change of a fluid or solid in response to pressure changes. + /// + [DataContract] + public partial struct Compressibility : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + [DataMember(Name = "Value", Order = 0)] + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + [DataMember(Name = "Unit", Order = 1)] + private readonly CompressibilityUnit? _unit; + + static Compressibility() + { + BaseDimensions = new BaseDimensions(1, -1, 2, 0, 0, 0, 0); + BaseUnit = CompressibilityUnit.InversePascal; + MaxValue = new Compressibility(double.MaxValue, BaseUnit); + MinValue = new Compressibility(double.MinValue, BaseUnit); + QuantityType = QuantityType.Compressibility; + Units = Enum.GetValues(typeof(CompressibilityUnit)).Cast().Except(new CompressibilityUnit[]{ CompressibilityUnit.Undefined }).ToArray(); + Zero = new Compressibility(0, BaseUnit); + Info = new QuantityInfo("Compressibility", + new UnitInfo[] + { + new UnitInfo(CompressibilityUnit.InverseAtmosphere, "InverseAtmospheres", BaseUnits.Undefined), + new UnitInfo(CompressibilityUnit.InverseBar, "InverseBars", BaseUnits.Undefined), + new UnitInfo(CompressibilityUnit.InverseKilopascal, "InverseKilopascals", BaseUnits.Undefined), + new UnitInfo(CompressibilityUnit.InverseMegapascal, "InverseMegapascals", BaseUnits.Undefined), + new UnitInfo(CompressibilityUnit.InverseMillibar, "InverseMillibars", BaseUnits.Undefined), + new UnitInfo(CompressibilityUnit.InversePascal, "InversePascals", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)), + new UnitInfo(CompressibilityUnit.InversePoundForcePerSquareInch, "InversePoundsForcePerSquareInch", BaseUnits.Undefined), + }, + BaseUnit, Zero, BaseDimensions, QuantityType.Compressibility); + + DefaultConversionFunctions = new UnitConverter(); + RegisterDefaultConversions(DefaultConversionFunctions); + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to construct this quantity with. + /// The unit representation to construct this quantity with. + /// If value is NaN or Infinity. + public Compressibility(double value, CompressibilityUnit unit) + { + if (unit == CompressibilityUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(value, nameof(value)); + _unit = unit; + } + + /// + /// Creates an instance of the quantity with the given numeric value in units compatible with the given . + /// If multiple compatible units were found, the first match is used. + /// + /// The numeric value to construct this quantity with. + /// The unit system to create the quantity with. + /// The given is null. + /// No unit was found for the given . + public Compressibility(double value, UnitSystem unitSystem) + { + if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + var firstUnitInfo = unitInfos.FirstOrDefault(); + + _value = Guard.EnsureValidNumber(value, nameof(value)); + _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + } + + #region Static Properties + + /// + /// The containing the default generated conversion functions for instances. + /// + public static UnitConverter DefaultConversionFunctions { get; } + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of Compressibility, which is InversePascal. All conversions go via this value. + /// + public static CompressibilityUnit BaseUnit { get; } + + /// + /// Represents the largest possible value of Compressibility + /// + [Obsolete("MaxValue and MinValue will be removed. Choose your own value or use nullability for unbounded lower/upper range checks. See discussion in https://github.com/angularsen/UnitsNet/issues/848.")] + public static Compressibility MaxValue { get; } + + /// + /// Represents the smallest possible value of Compressibility + /// + [Obsolete("MaxValue and MinValue will be removed. Choose your own value or use nullability for unbounded lower/upper range checks. See discussion in https://github.com/angularsen/UnitsNet/issues/848.")] + public static Compressibility MinValue { get; } + + /// + /// The of this quantity. + /// + [Obsolete("QuantityType will be removed in the future. Use the Info property instead.")] + public static QuantityType QuantityType { get; } + + /// + /// All units of measurement for the Compressibility quantity. + /// + public static CompressibilityUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit InversePascal. + /// + public static Compressibility Zero { get; } + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + Enum IQuantity.Unit => Unit; + + /// + public CompressibilityUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + [Obsolete("QuantityType will be removed in the future. Use the Info property instead.")] + public QuantityType Type => QuantityType.Compressibility; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => Compressibility.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double InverseAtmospheres => As(CompressibilityUnit.InverseAtmosphere); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseBars => As(CompressibilityUnit.InverseBar); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseKilopascals => As(CompressibilityUnit.InverseKilopascal); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseMegapascals => As(CompressibilityUnit.InverseMegapascal); + + /// + /// Gets a value of this quantity converted into + /// + public double InverseMillibars => As(CompressibilityUnit.InverseMillibar); + + /// + /// Gets a value of this quantity converted into + /// + public double InversePascals => As(CompressibilityUnit.InversePascal); + + /// + /// Gets a value of this quantity converted into + /// + public double InversePoundsForcePerSquareInch => As(CompressibilityUnit.InversePoundForcePerSquareInch); + + #endregion + + #region Static Methods + + /// + /// Registers the default conversion functions in the given instance. + /// + /// The to register the default conversion functions in. + internal static void RegisterDefaultConversions(UnitConverter unitConverter) + { + // Register in unit converter: BaseUnit -> CompressibilityUnit + unitConverter.SetConversionFunction(CompressibilityUnit.InversePascal, CompressibilityUnit.InverseAtmosphere, quantity => new Compressibility(quantity.Value / 101325, CompressibilityUnit.InverseAtmosphere)); + unitConverter.SetConversionFunction(CompressibilityUnit.InversePascal, CompressibilityUnit.InverseBar, quantity => new Compressibility(quantity.Value / 1e5, CompressibilityUnit.InverseBar)); + unitConverter.SetConversionFunction(CompressibilityUnit.InversePascal, CompressibilityUnit.InverseKilopascal, quantity => new Compressibility(quantity.Value / 1e3, CompressibilityUnit.InverseKilopascal)); + unitConverter.SetConversionFunction(CompressibilityUnit.InversePascal, CompressibilityUnit.InverseMegapascal, quantity => new Compressibility(quantity.Value / 1e6, CompressibilityUnit.InverseMegapascal)); + unitConverter.SetConversionFunction(CompressibilityUnit.InversePascal, CompressibilityUnit.InverseMillibar, quantity => new Compressibility(quantity.Value / 100, CompressibilityUnit.InverseMillibar)); + unitConverter.SetConversionFunction(CompressibilityUnit.InversePascal, CompressibilityUnit.InversePoundForcePerSquareInch, quantity => new Compressibility(quantity.Value / 6.894757293168361e3, CompressibilityUnit.InversePoundForcePerSquareInch)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(CompressibilityUnit.InversePascal, CompressibilityUnit.InversePascal, quantity => quantity); + + // Register in unit converter: CompressibilityUnit -> BaseUnit + unitConverter.SetConversionFunction(CompressibilityUnit.InverseAtmosphere, CompressibilityUnit.InversePascal, quantity => new Compressibility(quantity.Value * 101325, CompressibilityUnit.InversePascal)); + unitConverter.SetConversionFunction(CompressibilityUnit.InverseBar, CompressibilityUnit.InversePascal, quantity => new Compressibility(quantity.Value * 1e5, CompressibilityUnit.InversePascal)); + unitConverter.SetConversionFunction(CompressibilityUnit.InverseKilopascal, CompressibilityUnit.InversePascal, quantity => new Compressibility(quantity.Value * 1e3, CompressibilityUnit.InversePascal)); + unitConverter.SetConversionFunction(CompressibilityUnit.InverseMegapascal, CompressibilityUnit.InversePascal, quantity => new Compressibility(quantity.Value * 1e6, CompressibilityUnit.InversePascal)); + unitConverter.SetConversionFunction(CompressibilityUnit.InverseMillibar, CompressibilityUnit.InversePascal, quantity => new Compressibility(quantity.Value * 100, CompressibilityUnit.InversePascal)); + unitConverter.SetConversionFunction(CompressibilityUnit.InversePoundForcePerSquareInch, CompressibilityUnit.InversePascal, quantity => new Compressibility(quantity.Value * 6.894757293168361e3, CompressibilityUnit.InversePascal)); + } + + internal static void MapGeneratedLocalizations(UnitAbbreviationsCache unitAbbreviationsCache) + { + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InverseAtmosphere, new CultureInfo("en-US"), false, true, new string[]{"atm⁻¹", "1/atm"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InverseBar, new CultureInfo("en-US"), false, true, new string[]{"bar⁻¹", "1/bar"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InverseKilopascal, new CultureInfo("en-US"), false, true, new string[]{"kPa⁻¹", "1/kPa"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InverseMegapascal, new CultureInfo("en-US"), false, true, new string[]{"kPa⁻¹", "1/kPa"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InverseMillibar, new CultureInfo("en-US"), false, true, new string[]{"mbar⁻¹", "1/mbar"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InversePascal, new CultureInfo("en-US"), false, true, new string[]{"Pa⁻¹", "1/Pa"}); + unitAbbreviationsCache.PerformAbbreviationMapping(CompressibilityUnit.InversePoundForcePerSquareInch, new CultureInfo("en-US"), false, true, new string[]{"psi⁻¹", "1/psi"}); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(CompressibilityUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Format to use for localization. Defaults to if null. + public static string GetAbbreviation(CompressibilityUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInverseAtmospheres(QuantityValue inverseatmospheres) + { + double value = (double) inverseatmospheres; + return new Compressibility(value, CompressibilityUnit.InverseAtmosphere); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInverseBars(QuantityValue inversebars) + { + double value = (double) inversebars; + return new Compressibility(value, CompressibilityUnit.InverseBar); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInverseKilopascals(QuantityValue inversekilopascals) + { + double value = (double) inversekilopascals; + return new Compressibility(value, CompressibilityUnit.InverseKilopascal); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInverseMegapascals(QuantityValue inversemegapascals) + { + double value = (double) inversemegapascals; + return new Compressibility(value, CompressibilityUnit.InverseMegapascal); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInverseMillibars(QuantityValue inversemillibars) + { + double value = (double) inversemillibars; + return new Compressibility(value, CompressibilityUnit.InverseMillibar); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInversePascals(QuantityValue inversepascals) + { + double value = (double) inversepascals; + return new Compressibility(value, CompressibilityUnit.InversePascal); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static Compressibility FromInversePoundsForcePerSquareInch(QuantityValue inversepoundsforcepersquareinch) + { + double value = (double) inversepoundsforcepersquareinch; + return new Compressibility(value, CompressibilityUnit.InversePoundForcePerSquareInch); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Compressibility unit value. + public static Compressibility From(QuantityValue value, CompressibilityUnit fromUnit) + { + return new Compressibility((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static Compressibility Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static Compressibility Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse(string? str, out Compressibility result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParse(string? str, IFormatProvider? provider, out Compressibility result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static CompressibilityUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// Format to use when parsing number and unit. Defaults to if null. + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static CompressibilityUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out CompressibilityUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, IFormatProvider? provider, out CompressibilityUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static Compressibility operator -(Compressibility right) + { + return new Compressibility(-right.Value, right.Unit); + } + + /// Get from adding two . + public static Compressibility operator +(Compressibility left, Compressibility right) + { + return new Compressibility(left.Value + right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from subtracting two . + public static Compressibility operator -(Compressibility left, Compressibility right) + { + return new Compressibility(left.Value - right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from multiplying value and . + public static Compressibility operator *(double left, Compressibility right) + { + return new Compressibility(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static Compressibility operator *(Compressibility left, double right) + { + return new Compressibility(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static Compressibility operator /(Compressibility left, double right) + { + return new Compressibility(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(Compressibility left, Compressibility right) + { + return left.InversePascals / right.InversePascals; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(Compressibility left, Compressibility right) + { + return left.Value <= right.GetValueAs(left.Unit); + } + + /// Returns true if greater than or equal to. + public static bool operator >=(Compressibility left, Compressibility right) + { + return left.Value >= right.GetValueAs(left.Unit); + } + + /// Returns true if less than. + public static bool operator <(Compressibility left, Compressibility right) + { + return left.Value < right.GetValueAs(left.Unit); + } + + /// Returns true if greater than. + public static bool operator >(Compressibility left, Compressibility right) + { + return left.Value > right.GetValueAs(left.Unit); + } + + /// Returns true if exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator ==(Compressibility left, Compressibility right) + { + return left.Equals(right); + } + + /// Returns true if not exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator !=(Compressibility left, Compressibility right) + { + return !(left == right); + } + + /// + public int CompareTo(object obj) + { + if (obj is null) throw new ArgumentNullException(nameof(obj)); + if (!(obj is Compressibility objCompressibility)) throw new ArgumentException("Expected type Compressibility.", nameof(obj)); + + return CompareTo(objCompressibility); + } + + /// + public int CompareTo(Compressibility other) + { + return _value.CompareTo(other.GetValueAs(this.Unit)); + } + + /// + /// Consider using for safely comparing floating point values. + public override bool Equals(object obj) + { + if (obj is null || !(obj is Compressibility objCompressibility)) + return false; + + return Equals(objCompressibility); + } + + /// + /// Consider using for safely comparing floating point values. + public bool Equals(Compressibility other) + { + return _value.Equals(other.GetValueAs(this.Unit)); + } + + /// + /// + /// Compare equality to another Compressibility 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(Compressibility 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 Compressibility. + public override int GetHashCode() + { + return new { Info.Name, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(CompressibilityUnit unit) + { + if (Unit == unit) + return Convert.ToDouble(Value); + + var converted = GetValueAs(unit); + return Convert.ToDouble(converted); + } + + /// + public double As(UnitSystem unitSystem) + { + if (unitSystem is null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if (firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return As(firstUnitInfo.Value); + } + + /// + double IQuantity.As(Enum unit) + { + if (!(unit is CompressibilityUnit unitAsCompressibilityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CompressibilityUnit)} is supported.", nameof(unit)); + + return As(unitAsCompressibilityUnit); + } + + /// + /// Converts this Compressibility to another Compressibility with the unit representation . + /// + /// The unit to convert to. + /// A Compressibility with the specified unit. + public Compressibility ToUnit(CompressibilityUnit unit) + { + return ToUnit(unit, DefaultConversionFunctions); + } + + /// + /// Converts this Compressibility to another Compressibility using the given with the unit representation . + /// + /// The unit to convert to. + /// The to use for the conversion. + /// A Compressibility with the specified unit. + public Compressibility ToUnit(CompressibilityUnit unit, UnitConverter unitConverter) + { + if (Unit == unit) + { + // Already in requested units. + return this; + } + else if (unitConverter.TryGetConversionFunction((typeof(Compressibility), Unit, typeof(Compressibility), unit), out var conversionFunction)) + { + // Direct conversion to requested unit found. Return the converted quantity. + var converted = conversionFunction(this); + return (Compressibility)converted; + } + else if (Unit != BaseUnit) + { + // Direct conversion to requested unit NOT found. Convert to BaseUnit, and then from BaseUnit to requested unit. + var inBaseUnits = ToUnit(BaseUnit); + return inBaseUnits.ToUnit(unit); + } + else + { + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is CompressibilityUnit unitAsCompressibilityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(CompressibilityUnit)} is supported.", nameof(unit)); + + return ToUnit(unitAsCompressibilityUnit, DefaultConversionFunctions); + } + + /// + public Compressibility ToUnit(UnitSystem unitSystem) + { + if (unitSystem is null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if (firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return ToUnit(firstUnitInfo.Value); + } + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + IQuantity IQuantity.ToUnit(CompressibilityUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + private double GetValueAs(CompressibilityUnit unit) + { + var converted = ToUnit(unit); + return (double)converted.Value; + } + + #endregion + + #region ToString Methods + + /// + /// Gets the default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString("g"); + } + + /// + /// Gets the default string representation of value and unit using the given format provider. + /// + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + public string ToString(IFormatProvider? provider) + { + return ToString("g", provider); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] + public string ToString(IFormatProvider? provider, int significantDigitsAfterRadix) + { + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implicitly included as arguments 0 and 1. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] + public string ToString(IFormatProvider? provider, [NotNull] string format, [NotNull] params object[] args) + { + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? CultureInfo.CurrentUICulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using . + /// + /// The format string. + /// The string representation. + public string ToString(string format) + { + return ToString(format, CultureInfo.CurrentUICulture); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. + /// + /// The format string. + /// Format to use for localization and number formatting. Defaults to if null. + /// The string representation. + public string ToString(string format, IFormatProvider? provider) + { + return QuantityFormatter.Format(this, format, provider); + } + + #endregion + + #region IConvertible Methods + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(Compressibility)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(Compressibility)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(Compressibility)} to DateTime is not supported."); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + return Convert.ToDecimal(_value); + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + return Convert.ToDouble(_value); + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return Convert.ToInt16(_value); + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return Convert.ToInt32(_value); + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return Convert.ToInt64(_value); + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + return Convert.ToSByte(_value); + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + return Convert.ToSingle(_value); + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString("g", provider); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + if (conversionType == typeof(Compressibility)) + return this; + else if (conversionType == typeof(CompressibilityUnit)) + return Unit; + else if (conversionType == typeof(QuantityType)) + return Compressibility.QuantityType; + else if (conversionType == typeof(QuantityInfo)) + return Compressibility.Info; + else if (conversionType == typeof(BaseDimensions)) + return Compressibility.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(Compressibility)} to {conversionType} is not supported."); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + return Convert.ToUInt16(_value); + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + return Convert.ToUInt32(_value); + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + return Convert.ToUInt64(_value); + } + + #endregion + } +} diff --git a/UnitsNet/GeneratedCode/Quantity.g.cs b/UnitsNet/GeneratedCode/Quantity.g.cs index 4e06eecf12..fcd95a6af1 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -51,6 +51,7 @@ public static partial class Quantity { "BrakeSpecificFuelConsumption", BrakeSpecificFuelConsumption.Info }, { "Capacitance", Capacitance.Info }, { "CoefficientOfThermalExpansion", CoefficientOfThermalExpansion.Info }, + { "Compressibility", Compressibility.Info }, { "Density", Density.Info }, { "Duration", Duration.Info }, { "DynamicViscosity", DynamicViscosity.Info }, @@ -176,6 +177,7 @@ public static IQuantity FromQuantityType(QuantityType quantityType, QuantityValu QuantityType.BrakeSpecificFuelConsumption => BrakeSpecificFuelConsumption.From(value, BrakeSpecificFuelConsumption.BaseUnit), QuantityType.Capacitance => Capacitance.From(value, Capacitance.BaseUnit), QuantityType.CoefficientOfThermalExpansion => CoefficientOfThermalExpansion.From(value, CoefficientOfThermalExpansion.BaseUnit), + QuantityType.Compressibility => Compressibility.From(value, Compressibility.BaseUnit), QuantityType.Density => Density.From(value, Density.BaseUnit), QuantityType.Duration => Duration.From(value, Duration.BaseUnit), QuantityType.DynamicViscosity => DynamicViscosity.From(value, DynamicViscosity.BaseUnit), @@ -302,6 +304,7 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, QuantityValu "BrakeSpecificFuelConsumption" => BrakeSpecificFuelConsumption.From(value, BrakeSpecificFuelConsumption.BaseUnit), "Capacitance" => Capacitance.From(value, Capacitance.BaseUnit), "CoefficientOfThermalExpansion" => CoefficientOfThermalExpansion.From(value, CoefficientOfThermalExpansion.BaseUnit), + "Compressibility" => Compressibility.From(value, Compressibility.BaseUnit), "Density" => Density.From(value, Density.BaseUnit), "Duration" => Duration.From(value, Duration.BaseUnit), "DynamicViscosity" => DynamicViscosity.From(value, DynamicViscosity.BaseUnit), @@ -455,6 +458,9 @@ public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity? quanti case CoefficientOfThermalExpansionUnit coefficientOfThermalExpansionUnit: quantity = CoefficientOfThermalExpansion.From(value, coefficientOfThermalExpansionUnit); return true; + case CompressibilityUnit compressibilityUnit: + quantity = Compressibility.From(value, compressibilityUnit); + return true; case DensityUnit densityUnit: quantity = Density.From(value, densityUnit); return true; @@ -792,6 +798,7 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, Type _ when quantityType == typeof(BrakeSpecificFuelConsumption) => parser.TryParse(quantityString, formatProvider, BrakeSpecificFuelConsumption.From, out quantity), Type _ when quantityType == typeof(Capacitance) => parser.TryParse(quantityString, formatProvider, Capacitance.From, out quantity), Type _ when quantityType == typeof(CoefficientOfThermalExpansion) => parser.TryParse(quantityString, formatProvider, CoefficientOfThermalExpansion.From, out quantity), + Type _ when quantityType == typeof(Compressibility) => parser.TryParse(quantityString, formatProvider, Compressibility.From, out quantity), Type _ when quantityType == typeof(Density) => parser.TryParse(quantityString, formatProvider, Density.From, out quantity), Type _ when quantityType == typeof(Duration) => parser.TryParse(quantityString, formatProvider, Duration.From, out quantity), Type _ when quantityType == typeof(DynamicViscosity) => parser.TryParse(quantityString, formatProvider, DynamicViscosity.From, out quantity), @@ -910,6 +917,7 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(BrakeSpecificFuelConsumption); yield return typeof(Capacitance); yield return typeof(CoefficientOfThermalExpansion); + yield return typeof(Compressibility); yield return typeof(Density); yield return typeof(Duration); yield return typeof(DynamicViscosity); diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs index 522fe664ca..d804d3eb3e 100644 --- a/UnitsNet/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet/GeneratedCode/QuantityType.g.cs @@ -48,6 +48,7 @@ public enum QuantityType BrakeSpecificFuelConsumption, Capacitance, CoefficientOfThermalExpansion, + Compressibility, Density, Duration, DynamicViscosity, diff --git a/UnitsNet/GeneratedCode/Units/CompressibilityUnit.g.cs b/UnitsNet/GeneratedCode/Units/CompressibilityUnit.g.cs new file mode 100644 index 0000000000..5b3e4f4514 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/CompressibilityUnit.g.cs @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +// +// 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 generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum CompressibilityUnit + { + Undefined = 0, + InverseAtmosphere, + InverseBar, + InverseKilopascal, + InverseMegapascal, + InverseMillibar, + InversePascal, + InversePoundForcePerSquareInch, + } + + #pragma warning restore 1591 +}