From c3b90fe2a5417892333be46a72014d9bc45561b2 Mon Sep 17 00:00:00 2001 From: trb5016 Date: Thu, 5 Mar 2020 13:42:58 -0500 Subject: [PATCH 1/6] Add quantity LinearPowerDensity --- .../UnitDefinitions/LinearPowerDensity.json | 78 + ...berToLinearPowerDensityExtensionsTest.g.cs | 128 ++ .../NumberToLinearPowerDensityExtensions.g.cs | 130 ++ .../CustomCode/LinearPowerDensityTests.cs | 56 + .../GeneratedCode/IQuantityTests.g.cs | 4 + .../LinearPowerDensityTestsBase.g.cs | 695 +++++++++ .../Quantities/LinearPowerDensity.g.cs | 991 +++++++++++++ .../GeneratedCode/Quantity.g.cs | 6 + .../GeneratedCode/QuantityType.g.cs | 1 + .../GeneratedCode/UnitAbbreviationsCache.g.cs | 25 + .../Units/LinearPowerDensityUnit.g.cs | 57 + .../Quantities/LinearPowerDensity.g.cs | 1261 +++++++++++++++++ UnitsNet/GeneratedCode/Quantity.g.cs | 7 + UnitsNet/GeneratedCode/QuantityType.g.cs | 1 + .../GeneratedCode/UnitAbbreviationsCache.g.cs | 25 + UnitsNet/GeneratedCode/UnitConverter.g.cs | 49 + .../Units/LinearPowerDensityUnit.g.cs | 57 + 17 files changed, 3571 insertions(+) create mode 100644 Common/UnitDefinitions/LinearPowerDensity.json create mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToLinearPowerDensityExtensionsTest.g.cs create mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToLinearPowerDensityExtensions.g.cs create mode 100644 UnitsNet.Tests/CustomCode/LinearPowerDensityTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LinearPowerDensity.g.cs create mode 100644 UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LinearPowerDensityUnit.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/LinearPowerDensityUnit.g.cs diff --git a/Common/UnitDefinitions/LinearPowerDensity.json b/Common/UnitDefinitions/LinearPowerDensity.json new file mode 100644 index 0000000000..6e11a3640b --- /dev/null +++ b/Common/UnitDefinitions/LinearPowerDensity.json @@ -0,0 +1,78 @@ +{ + "Name": "LinearPowerDensity", + "BaseUnit": "WattPerMeter", + "XmlDoc": "The Linear Power Density of a substance is its power per unit length. The term linear density is most often used when describing the characteristics of one-dimensional objects, although linear density can also be used to describe the density of a three-dimensional quantity along one particular dimension.", + "XmlDocRemarks": "http://en.wikipedia.org/wiki/Linear_density", + "BaseDimensions": { + "M": 1, + "L": 1, + "T": -3 + }, + "Units": [ + { + "SingularName": "WattPerMeter", + "PluralName": "WattsPerMeter", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "W/m" ] + } + ] + }, + { + "SingularName": "WattPerCentimeter", + "PluralName": "WattsPerCentimeter", + "FromUnitToBaseFunc": "x*1e2", + "FromBaseToUnitFunc": "x/1e2", + "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "W/cm" ] + } + ] + }, + { + "SingularName": "WattPerMillimeter", + "PluralName": "WattsPerMillimeter", + "FromUnitToBaseFunc": "x*1e3", + "FromBaseToUnitFunc": "x/1e3", + "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "W/mm" ] + } + ] + }, + { + "SingularName": "WattPerInch", + "PluralName": "WattsPerInch", + "FromUnitToBaseFunc": "x*39.37007874", + "FromBaseToUnitFunc": "x/39.37007874", + "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "W/in" ] + } + ] + }, + { + "SingularName": "WattPerFoot", + "PluralName": "WattsPerFoot", + "FromUnitToBaseFunc": "x*3.280839895", + "FromBaseToUnitFunc": "x/3.280839895", + "Prefixes": [ "Milli", "Kilo", "Mega", "Giga" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "W/ft" ] + } + ] + } + ] +} \ No newline at end of file diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToLinearPowerDensityExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToLinearPowerDensityExtensionsTest.g.cs new file mode 100644 index 0000000000..deb623e4dd --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToLinearPowerDensityExtensionsTest.g.cs @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToLinearPowerDensity; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToLinearPowerDensityExtensionsTests + { + [Fact] + public void NumberToGigawattsPerCentimeterTest() => + Assert.Equal(LinearPowerDensity.FromGigawattsPerCentimeter(2), 2.GigawattsPerCentimeter()); + + [Fact] + public void NumberToGigawattsPerFootTest() => + Assert.Equal(LinearPowerDensity.FromGigawattsPerFoot(2), 2.GigawattsPerFoot()); + + [Fact] + public void NumberToGigawattsPerInchTest() => + Assert.Equal(LinearPowerDensity.FromGigawattsPerInch(2), 2.GigawattsPerInch()); + + [Fact] + public void NumberToGigawattsPerMeterTest() => + Assert.Equal(LinearPowerDensity.FromGigawattsPerMeter(2), 2.GigawattsPerMeter()); + + [Fact] + public void NumberToGigawattsPerMillimeterTest() => + Assert.Equal(LinearPowerDensity.FromGigawattsPerMillimeter(2), 2.GigawattsPerMillimeter()); + + [Fact] + public void NumberToKilowattsPerCentimeterTest() => + Assert.Equal(LinearPowerDensity.FromKilowattsPerCentimeter(2), 2.KilowattsPerCentimeter()); + + [Fact] + public void NumberToKilowattsPerFootTest() => + Assert.Equal(LinearPowerDensity.FromKilowattsPerFoot(2), 2.KilowattsPerFoot()); + + [Fact] + public void NumberToKilowattsPerInchTest() => + Assert.Equal(LinearPowerDensity.FromKilowattsPerInch(2), 2.KilowattsPerInch()); + + [Fact] + public void NumberToKilowattsPerMeterTest() => + Assert.Equal(LinearPowerDensity.FromKilowattsPerMeter(2), 2.KilowattsPerMeter()); + + [Fact] + public void NumberToKilowattsPerMillimeterTest() => + Assert.Equal(LinearPowerDensity.FromKilowattsPerMillimeter(2), 2.KilowattsPerMillimeter()); + + [Fact] + public void NumberToMegawattsPerCentimeterTest() => + Assert.Equal(LinearPowerDensity.FromMegawattsPerCentimeter(2), 2.MegawattsPerCentimeter()); + + [Fact] + public void NumberToMegawattsPerFootTest() => + Assert.Equal(LinearPowerDensity.FromMegawattsPerFoot(2), 2.MegawattsPerFoot()); + + [Fact] + public void NumberToMegawattsPerInchTest() => + Assert.Equal(LinearPowerDensity.FromMegawattsPerInch(2), 2.MegawattsPerInch()); + + [Fact] + public void NumberToMegawattsPerMeterTest() => + Assert.Equal(LinearPowerDensity.FromMegawattsPerMeter(2), 2.MegawattsPerMeter()); + + [Fact] + public void NumberToMegawattsPerMillimeterTest() => + Assert.Equal(LinearPowerDensity.FromMegawattsPerMillimeter(2), 2.MegawattsPerMillimeter()); + + [Fact] + public void NumberToMilliwattsPerCentimeterTest() => + Assert.Equal(LinearPowerDensity.FromMilliwattsPerCentimeter(2), 2.MilliwattsPerCentimeter()); + + [Fact] + public void NumberToMilliwattsPerFootTest() => + Assert.Equal(LinearPowerDensity.FromMilliwattsPerFoot(2), 2.MilliwattsPerFoot()); + + [Fact] + public void NumberToMilliwattsPerInchTest() => + Assert.Equal(LinearPowerDensity.FromMilliwattsPerInch(2), 2.MilliwattsPerInch()); + + [Fact] + public void NumberToMilliwattsPerMeterTest() => + Assert.Equal(LinearPowerDensity.FromMilliwattsPerMeter(2), 2.MilliwattsPerMeter()); + + [Fact] + public void NumberToMilliwattsPerMillimeterTest() => + Assert.Equal(LinearPowerDensity.FromMilliwattsPerMillimeter(2), 2.MilliwattsPerMillimeter()); + + [Fact] + public void NumberToWattsPerCentimeterTest() => + Assert.Equal(LinearPowerDensity.FromWattsPerCentimeter(2), 2.WattsPerCentimeter()); + + [Fact] + public void NumberToWattsPerFootTest() => + Assert.Equal(LinearPowerDensity.FromWattsPerFoot(2), 2.WattsPerFoot()); + + [Fact] + public void NumberToWattsPerInchTest() => + Assert.Equal(LinearPowerDensity.FromWattsPerInch(2), 2.WattsPerInch()); + + [Fact] + public void NumberToWattsPerMeterTest() => + Assert.Equal(LinearPowerDensity.FromWattsPerMeter(2), 2.WattsPerMeter()); + + [Fact] + public void NumberToWattsPerMillimeterTest() => + Assert.Equal(LinearPowerDensity.FromWattsPerMillimeter(2), 2.WattsPerMillimeter()); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToLinearPowerDensityExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToLinearPowerDensityExtensions.g.cs new file mode 100644 index 0000000000..a41a12af63 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToLinearPowerDensityExtensions.g.cs @@ -0,0 +1,130 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberExtensions.NumberToLinearPowerDensity +{ + /// + /// A number to LinearPowerDensity Extensions + /// + public static class NumberToLinearPowerDensityExtensions + { + /// + public static LinearPowerDensity GigawattsPerCentimeter(this T value) => + LinearPowerDensity.FromGigawattsPerCentimeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity GigawattsPerFoot(this T value) => + LinearPowerDensity.FromGigawattsPerFoot(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity GigawattsPerInch(this T value) => + LinearPowerDensity.FromGigawattsPerInch(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity GigawattsPerMeter(this T value) => + LinearPowerDensity.FromGigawattsPerMeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity GigawattsPerMillimeter(this T value) => + LinearPowerDensity.FromGigawattsPerMillimeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity KilowattsPerCentimeter(this T value) => + LinearPowerDensity.FromKilowattsPerCentimeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity KilowattsPerFoot(this T value) => + LinearPowerDensity.FromKilowattsPerFoot(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity KilowattsPerInch(this T value) => + LinearPowerDensity.FromKilowattsPerInch(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity KilowattsPerMeter(this T value) => + LinearPowerDensity.FromKilowattsPerMeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity KilowattsPerMillimeter(this T value) => + LinearPowerDensity.FromKilowattsPerMillimeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity MegawattsPerCentimeter(this T value) => + LinearPowerDensity.FromMegawattsPerCentimeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity MegawattsPerFoot(this T value) => + LinearPowerDensity.FromMegawattsPerFoot(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity MegawattsPerInch(this T value) => + LinearPowerDensity.FromMegawattsPerInch(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity MegawattsPerMeter(this T value) => + LinearPowerDensity.FromMegawattsPerMeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity MegawattsPerMillimeter(this T value) => + LinearPowerDensity.FromMegawattsPerMillimeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity MilliwattsPerCentimeter(this T value) => + LinearPowerDensity.FromMilliwattsPerCentimeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity MilliwattsPerFoot(this T value) => + LinearPowerDensity.FromMilliwattsPerFoot(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity MilliwattsPerInch(this T value) => + LinearPowerDensity.FromMilliwattsPerInch(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity MilliwattsPerMeter(this T value) => + LinearPowerDensity.FromMilliwattsPerMeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity MilliwattsPerMillimeter(this T value) => + LinearPowerDensity.FromMilliwattsPerMillimeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity WattsPerCentimeter(this T value) => + LinearPowerDensity.FromWattsPerCentimeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity WattsPerFoot(this T value) => + LinearPowerDensity.FromWattsPerFoot(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity WattsPerInch(this T value) => + LinearPowerDensity.FromWattsPerInch(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity WattsPerMeter(this T value) => + LinearPowerDensity.FromWattsPerMeter(Convert.ToDouble(value)); + + /// + public static LinearPowerDensity WattsPerMillimeter(this T value) => + LinearPowerDensity.FromWattsPerMillimeter(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.Tests/CustomCode/LinearPowerDensityTests.cs b/UnitsNet.Tests/CustomCode/LinearPowerDensityTests.cs new file mode 100644 index 0000000000..c45766cbfa --- /dev/null +++ b/UnitsNet.Tests/CustomCode/LinearPowerDensityTests.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 System; + +namespace UnitsNet.Tests.CustomCode +{ + public class LinearPowerDensityTests : LinearPowerDensityTestsBase + { + protected override double GigawattsPerCentimeterInOneWattPerMeter => 1e-11; + protected override double GigawattsPerFootInOneWattPerMeter => 3.0480e-10; + protected override double GigawattsPerInchInOneWattPerMeter => 2.5400e-11; + protected override double GigawattsPerMeterInOneWattPerMeter => 1e-9; + protected override double GigawattsPerMillimeterInOneWattPerMeter => 1e-12; + + protected override double MegawattsPerCentimeterInOneWattPerMeter => 1e-8; + protected override double MegawattsPerFootInOneWattPerMeter => 3.0480e-7; + protected override double MegawattsPerInchInOneWattPerMeter => 2.5400e-8; + protected override double MegawattsPerMeterInOneWattPerMeter => 1e-6; + protected override double MegawattsPerMillimeterInOneWattPerMeter => 1e-9; + + protected override double KilowattsPerCentimeterInOneWattPerMeter => 1e-5; + protected override double KilowattsPerFootInOneWattPerMeter => 3.0480e-4; + protected override double KilowattsPerInchInOneWattPerMeter => 2.5400e-5; + protected override double KilowattsPerMeterInOneWattPerMeter => 1e-3; + protected override double KilowattsPerMillimeterInOneWattPerMeter => 1e-6; + + protected override double WattsPerCentimeterInOneWattPerMeter => 1e-2; + protected override double WattsPerFootInOneWattPerMeter => 3.0480e-1; + protected override double WattsPerInchInOneWattPerMeter => 2.5400e-2; + protected override double WattsPerMeterInOneWattPerMeter => 1; + protected override double WattsPerMillimeterInOneWattPerMeter => 1e-3; + + protected override double MilliwattsPerCentimeterInOneWattPerMeter => 1e1; + protected override double MilliwattsPerFootInOneWattPerMeter => 3.0480e2; + protected override double MilliwattsPerInchInOneWattPerMeter => 2.5400e1; + protected override double MilliwattsPerMeterInOneWattPerMeter => 1e3; + protected override double MilliwattsPerMillimeterInOneWattPerMeter => 1; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index 9d58a715be..2944626e9b 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -85,6 +85,7 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, LengthUnit.Yard, Quantity.From(3, LengthUnit.Yard)); Assertion(3, LevelUnit.Neper, Quantity.From(3, LevelUnit.Neper)); Assertion(3, LinearDensityUnit.PoundPerInch, Quantity.From(3, LinearDensityUnit.PoundPerInch)); + Assertion(3, LinearPowerDensityUnit.WattPerMillimeter, Quantity.From(3, LinearPowerDensityUnit.WattPerMillimeter)); Assertion(3, LuminosityUnit.Watt, Quantity.From(3, LuminosityUnit.Watt)); Assertion(3, LuminousFluxUnit.Lumen, Quantity.From(3, LuminousFluxUnit.Lumen)); Assertion(3, LuminousIntensityUnit.Candela, Quantity.From(3, LuminousIntensityUnit.Candela)); @@ -192,6 +193,7 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(Length.Info, Length.Zero); Assertion(Level.Info, Level.Zero); Assertion(LinearDensity.Info, LinearDensity.Zero); + Assertion(LinearPowerDensity.Info, LinearPowerDensity.Zero); Assertion(Luminosity.Info, Luminosity.Zero); Assertion(LuminousFlux.Info, LuminousFlux.Zero); Assertion(LuminousIntensity.Info, LuminousIntensity.Zero); @@ -299,6 +301,7 @@ public void Type_EqualsStaticQuantityTypeProperty() Assertion(Length.QuantityType, Length.Zero); Assertion(Level.QuantityType, Level.Zero); Assertion(LinearDensity.QuantityType, LinearDensity.Zero); + Assertion(LinearPowerDensity.QuantityType, LinearPowerDensity.Zero); Assertion(Luminosity.QuantityType, Luminosity.Zero); Assertion(LuminousFlux.QuantityType, LuminousFlux.Zero); Assertion(LuminousIntensity.QuantityType, LuminousIntensity.Zero); @@ -406,6 +409,7 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(Length.BaseDimensions, Length.Zero); Assertion(Level.BaseDimensions, Level.Zero); Assertion(LinearDensity.BaseDimensions, LinearDensity.Zero); + Assertion(LinearPowerDensity.BaseDimensions, LinearPowerDensity.Zero); Assertion(Luminosity.BaseDimensions, Luminosity.Zero); Assertion(LuminousFlux.BaseDimensions, LuminousFlux.Zero); Assertion(LuminousIntensity.BaseDimensions, LuminousIntensity.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs new file mode 100644 index 0000000000..dd54935429 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs @@ -0,0 +1,695 @@ +//------------------------------------------------------------------------------ +// +// 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.Threading; +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 LinearPowerDensity. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class LinearPowerDensityTestsBase + { + protected abstract double GigawattsPerCentimeterInOneWattPerMeter { get; } + protected abstract double GigawattsPerFootInOneWattPerMeter { get; } + protected abstract double GigawattsPerInchInOneWattPerMeter { get; } + protected abstract double GigawattsPerMeterInOneWattPerMeter { get; } + protected abstract double GigawattsPerMillimeterInOneWattPerMeter { get; } + protected abstract double KilowattsPerCentimeterInOneWattPerMeter { get; } + protected abstract double KilowattsPerFootInOneWattPerMeter { get; } + protected abstract double KilowattsPerInchInOneWattPerMeter { get; } + protected abstract double KilowattsPerMeterInOneWattPerMeter { get; } + protected abstract double KilowattsPerMillimeterInOneWattPerMeter { get; } + protected abstract double MegawattsPerCentimeterInOneWattPerMeter { get; } + protected abstract double MegawattsPerFootInOneWattPerMeter { get; } + protected abstract double MegawattsPerInchInOneWattPerMeter { get; } + protected abstract double MegawattsPerMeterInOneWattPerMeter { get; } + protected abstract double MegawattsPerMillimeterInOneWattPerMeter { get; } + protected abstract double MilliwattsPerCentimeterInOneWattPerMeter { get; } + protected abstract double MilliwattsPerFootInOneWattPerMeter { get; } + protected abstract double MilliwattsPerInchInOneWattPerMeter { get; } + protected abstract double MilliwattsPerMeterInOneWattPerMeter { get; } + protected abstract double MilliwattsPerMillimeterInOneWattPerMeter { get; } + protected abstract double WattsPerCentimeterInOneWattPerMeter { get; } + protected abstract double WattsPerFootInOneWattPerMeter { get; } + protected abstract double WattsPerInchInOneWattPerMeter { get; } + protected abstract double WattsPerMeterInOneWattPerMeter { get; } + protected abstract double WattsPerMillimeterInOneWattPerMeter { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double GigawattsPerCentimeterTolerance { get { return 1e-5; } } + protected virtual double GigawattsPerFootTolerance { get { return 1e-5; } } + protected virtual double GigawattsPerInchTolerance { get { return 1e-5; } } + protected virtual double GigawattsPerMeterTolerance { get { return 1e-5; } } + protected virtual double GigawattsPerMillimeterTolerance { get { return 1e-5; } } + protected virtual double KilowattsPerCentimeterTolerance { get { return 1e-5; } } + protected virtual double KilowattsPerFootTolerance { get { return 1e-5; } } + protected virtual double KilowattsPerInchTolerance { get { return 1e-5; } } + protected virtual double KilowattsPerMeterTolerance { get { return 1e-5; } } + protected virtual double KilowattsPerMillimeterTolerance { get { return 1e-5; } } + protected virtual double MegawattsPerCentimeterTolerance { get { return 1e-5; } } + protected virtual double MegawattsPerFootTolerance { get { return 1e-5; } } + protected virtual double MegawattsPerInchTolerance { get { return 1e-5; } } + protected virtual double MegawattsPerMeterTolerance { get { return 1e-5; } } + protected virtual double MegawattsPerMillimeterTolerance { get { return 1e-5; } } + protected virtual double MilliwattsPerCentimeterTolerance { get { return 1e-5; } } + protected virtual double MilliwattsPerFootTolerance { get { return 1e-5; } } + protected virtual double MilliwattsPerInchTolerance { get { return 1e-5; } } + protected virtual double MilliwattsPerMeterTolerance { get { return 1e-5; } } + protected virtual double MilliwattsPerMillimeterTolerance { get { return 1e-5; } } + protected virtual double WattsPerCentimeterTolerance { get { return 1e-5; } } + protected virtual double WattsPerFootTolerance { get { return 1e-5; } } + protected virtual double WattsPerInchTolerance { get { return 1e-5; } } + protected virtual double WattsPerMeterTolerance { get { return 1e-5; } } + protected virtual double WattsPerMillimeterTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void Ctor_WithUndefinedUnit_ThrowsArgumentException() + { + Assert.Throws(() => new LinearPowerDensity((double)0.0, LinearPowerDensityUnit.Undefined)); + } + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new LinearPowerDensity(); + Assert.Equal(0, quantity.Value); + Assert.Equal(LinearPowerDensityUnit.WattPerMeter, quantity.Unit); + } + + + [Fact] + public void Ctor_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => new LinearPowerDensity(double.PositiveInfinity, LinearPowerDensityUnit.WattPerMeter)); + Assert.Throws(() => new LinearPowerDensity(double.NegativeInfinity, LinearPowerDensityUnit.WattPerMeter)); + } + + [Fact] + public void Ctor_WithNaNValue_ThrowsArgumentException() + { + Assert.Throws(() => new LinearPowerDensity(double.NaN, LinearPowerDensityUnit.WattPerMeter)); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new LinearPowerDensity(value: 1.0, unitSystem: null)); + } + + [Fact] + public void LinearPowerDensity_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new LinearPowerDensity(1, LinearPowerDensityUnit.WattPerMeter); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(LinearPowerDensity.Zero, quantityInfo.Zero); + Assert.Equal("LinearPowerDensity", quantityInfo.Name); + Assert.Equal(QuantityType.LinearPowerDensity, quantityInfo.QuantityType); + + var units = EnumUtils.GetEnumValues().Except(new[] {LinearPowerDensityUnit.Undefined}).ToArray(); + var unitNames = units.Select(x => x.ToString()); + + // Obsolete members +#pragma warning disable 618 + Assert.Equal(units, quantityInfo.Units); + Assert.Equal(unitNames, quantityInfo.UnitNames); +#pragma warning restore 618 + } + + [Fact] + public void WattPerMeterToLinearPowerDensityUnits() + { + LinearPowerDensity wattpermeter = LinearPowerDensity.FromWattsPerMeter(1); + AssertEx.EqualTolerance(GigawattsPerCentimeterInOneWattPerMeter, wattpermeter.GigawattsPerCentimeter, GigawattsPerCentimeterTolerance); + AssertEx.EqualTolerance(GigawattsPerFootInOneWattPerMeter, wattpermeter.GigawattsPerFoot, GigawattsPerFootTolerance); + AssertEx.EqualTolerance(GigawattsPerInchInOneWattPerMeter, wattpermeter.GigawattsPerInch, GigawattsPerInchTolerance); + AssertEx.EqualTolerance(GigawattsPerMeterInOneWattPerMeter, wattpermeter.GigawattsPerMeter, GigawattsPerMeterTolerance); + AssertEx.EqualTolerance(GigawattsPerMillimeterInOneWattPerMeter, wattpermeter.GigawattsPerMillimeter, GigawattsPerMillimeterTolerance); + AssertEx.EqualTolerance(KilowattsPerCentimeterInOneWattPerMeter, wattpermeter.KilowattsPerCentimeter, KilowattsPerCentimeterTolerance); + AssertEx.EqualTolerance(KilowattsPerFootInOneWattPerMeter, wattpermeter.KilowattsPerFoot, KilowattsPerFootTolerance); + AssertEx.EqualTolerance(KilowattsPerInchInOneWattPerMeter, wattpermeter.KilowattsPerInch, KilowattsPerInchTolerance); + AssertEx.EqualTolerance(KilowattsPerMeterInOneWattPerMeter, wattpermeter.KilowattsPerMeter, KilowattsPerMeterTolerance); + AssertEx.EqualTolerance(KilowattsPerMillimeterInOneWattPerMeter, wattpermeter.KilowattsPerMillimeter, KilowattsPerMillimeterTolerance); + AssertEx.EqualTolerance(MegawattsPerCentimeterInOneWattPerMeter, wattpermeter.MegawattsPerCentimeter, MegawattsPerCentimeterTolerance); + AssertEx.EqualTolerance(MegawattsPerFootInOneWattPerMeter, wattpermeter.MegawattsPerFoot, MegawattsPerFootTolerance); + AssertEx.EqualTolerance(MegawattsPerInchInOneWattPerMeter, wattpermeter.MegawattsPerInch, MegawattsPerInchTolerance); + AssertEx.EqualTolerance(MegawattsPerMeterInOneWattPerMeter, wattpermeter.MegawattsPerMeter, MegawattsPerMeterTolerance); + AssertEx.EqualTolerance(MegawattsPerMillimeterInOneWattPerMeter, wattpermeter.MegawattsPerMillimeter, MegawattsPerMillimeterTolerance); + AssertEx.EqualTolerance(MilliwattsPerCentimeterInOneWattPerMeter, wattpermeter.MilliwattsPerCentimeter, MilliwattsPerCentimeterTolerance); + AssertEx.EqualTolerance(MilliwattsPerFootInOneWattPerMeter, wattpermeter.MilliwattsPerFoot, MilliwattsPerFootTolerance); + AssertEx.EqualTolerance(MilliwattsPerInchInOneWattPerMeter, wattpermeter.MilliwattsPerInch, MilliwattsPerInchTolerance); + AssertEx.EqualTolerance(MilliwattsPerMeterInOneWattPerMeter, wattpermeter.MilliwattsPerMeter, MilliwattsPerMeterTolerance); + AssertEx.EqualTolerance(MilliwattsPerMillimeterInOneWattPerMeter, wattpermeter.MilliwattsPerMillimeter, MilliwattsPerMillimeterTolerance); + AssertEx.EqualTolerance(WattsPerCentimeterInOneWattPerMeter, wattpermeter.WattsPerCentimeter, WattsPerCentimeterTolerance); + AssertEx.EqualTolerance(WattsPerFootInOneWattPerMeter, wattpermeter.WattsPerFoot, WattsPerFootTolerance); + AssertEx.EqualTolerance(WattsPerInchInOneWattPerMeter, wattpermeter.WattsPerInch, WattsPerInchTolerance); + AssertEx.EqualTolerance(WattsPerMeterInOneWattPerMeter, wattpermeter.WattsPerMeter, WattsPerMeterTolerance); + AssertEx.EqualTolerance(WattsPerMillimeterInOneWattPerMeter, wattpermeter.WattsPerMillimeter, WattsPerMillimeterTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + var quantity00 = LinearPowerDensity.From(1, LinearPowerDensityUnit.GigawattPerCentimeter); + AssertEx.EqualTolerance(1, quantity00.GigawattsPerCentimeter, GigawattsPerCentimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.GigawattPerCentimeter, quantity00.Unit); + + var quantity01 = LinearPowerDensity.From(1, LinearPowerDensityUnit.GigawattPerFoot); + AssertEx.EqualTolerance(1, quantity01.GigawattsPerFoot, GigawattsPerFootTolerance); + Assert.Equal(LinearPowerDensityUnit.GigawattPerFoot, quantity01.Unit); + + var quantity02 = LinearPowerDensity.From(1, LinearPowerDensityUnit.GigawattPerInch); + AssertEx.EqualTolerance(1, quantity02.GigawattsPerInch, GigawattsPerInchTolerance); + Assert.Equal(LinearPowerDensityUnit.GigawattPerInch, quantity02.Unit); + + var quantity03 = LinearPowerDensity.From(1, LinearPowerDensityUnit.GigawattPerMeter); + AssertEx.EqualTolerance(1, quantity03.GigawattsPerMeter, GigawattsPerMeterTolerance); + Assert.Equal(LinearPowerDensityUnit.GigawattPerMeter, quantity03.Unit); + + var quantity04 = LinearPowerDensity.From(1, LinearPowerDensityUnit.GigawattPerMillimeter); + AssertEx.EqualTolerance(1, quantity04.GigawattsPerMillimeter, GigawattsPerMillimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.GigawattPerMillimeter, quantity04.Unit); + + var quantity05 = LinearPowerDensity.From(1, LinearPowerDensityUnit.KilowattPerCentimeter); + AssertEx.EqualTolerance(1, quantity05.KilowattsPerCentimeter, KilowattsPerCentimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.KilowattPerCentimeter, quantity05.Unit); + + var quantity06 = LinearPowerDensity.From(1, LinearPowerDensityUnit.KilowattPerFoot); + AssertEx.EqualTolerance(1, quantity06.KilowattsPerFoot, KilowattsPerFootTolerance); + Assert.Equal(LinearPowerDensityUnit.KilowattPerFoot, quantity06.Unit); + + var quantity07 = LinearPowerDensity.From(1, LinearPowerDensityUnit.KilowattPerInch); + AssertEx.EqualTolerance(1, quantity07.KilowattsPerInch, KilowattsPerInchTolerance); + Assert.Equal(LinearPowerDensityUnit.KilowattPerInch, quantity07.Unit); + + var quantity08 = LinearPowerDensity.From(1, LinearPowerDensityUnit.KilowattPerMeter); + AssertEx.EqualTolerance(1, quantity08.KilowattsPerMeter, KilowattsPerMeterTolerance); + Assert.Equal(LinearPowerDensityUnit.KilowattPerMeter, quantity08.Unit); + + var quantity09 = LinearPowerDensity.From(1, LinearPowerDensityUnit.KilowattPerMillimeter); + AssertEx.EqualTolerance(1, quantity09.KilowattsPerMillimeter, KilowattsPerMillimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.KilowattPerMillimeter, quantity09.Unit); + + var quantity10 = LinearPowerDensity.From(1, LinearPowerDensityUnit.MegawattPerCentimeter); + AssertEx.EqualTolerance(1, quantity10.MegawattsPerCentimeter, MegawattsPerCentimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MegawattPerCentimeter, quantity10.Unit); + + var quantity11 = LinearPowerDensity.From(1, LinearPowerDensityUnit.MegawattPerFoot); + AssertEx.EqualTolerance(1, quantity11.MegawattsPerFoot, MegawattsPerFootTolerance); + Assert.Equal(LinearPowerDensityUnit.MegawattPerFoot, quantity11.Unit); + + var quantity12 = LinearPowerDensity.From(1, LinearPowerDensityUnit.MegawattPerInch); + AssertEx.EqualTolerance(1, quantity12.MegawattsPerInch, MegawattsPerInchTolerance); + Assert.Equal(LinearPowerDensityUnit.MegawattPerInch, quantity12.Unit); + + var quantity13 = LinearPowerDensity.From(1, LinearPowerDensityUnit.MegawattPerMeter); + AssertEx.EqualTolerance(1, quantity13.MegawattsPerMeter, MegawattsPerMeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MegawattPerMeter, quantity13.Unit); + + var quantity14 = LinearPowerDensity.From(1, LinearPowerDensityUnit.MegawattPerMillimeter); + AssertEx.EqualTolerance(1, quantity14.MegawattsPerMillimeter, MegawattsPerMillimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MegawattPerMillimeter, quantity14.Unit); + + var quantity15 = LinearPowerDensity.From(1, LinearPowerDensityUnit.MilliwattPerCentimeter); + AssertEx.EqualTolerance(1, quantity15.MilliwattsPerCentimeter, MilliwattsPerCentimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MilliwattPerCentimeter, quantity15.Unit); + + var quantity16 = LinearPowerDensity.From(1, LinearPowerDensityUnit.MilliwattPerFoot); + AssertEx.EqualTolerance(1, quantity16.MilliwattsPerFoot, MilliwattsPerFootTolerance); + Assert.Equal(LinearPowerDensityUnit.MilliwattPerFoot, quantity16.Unit); + + var quantity17 = LinearPowerDensity.From(1, LinearPowerDensityUnit.MilliwattPerInch); + AssertEx.EqualTolerance(1, quantity17.MilliwattsPerInch, MilliwattsPerInchTolerance); + Assert.Equal(LinearPowerDensityUnit.MilliwattPerInch, quantity17.Unit); + + var quantity18 = LinearPowerDensity.From(1, LinearPowerDensityUnit.MilliwattPerMeter); + AssertEx.EqualTolerance(1, quantity18.MilliwattsPerMeter, MilliwattsPerMeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MilliwattPerMeter, quantity18.Unit); + + var quantity19 = LinearPowerDensity.From(1, LinearPowerDensityUnit.MilliwattPerMillimeter); + AssertEx.EqualTolerance(1, quantity19.MilliwattsPerMillimeter, MilliwattsPerMillimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MilliwattPerMillimeter, quantity19.Unit); + + var quantity20 = LinearPowerDensity.From(1, LinearPowerDensityUnit.WattPerCentimeter); + AssertEx.EqualTolerance(1, quantity20.WattsPerCentimeter, WattsPerCentimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.WattPerCentimeter, quantity20.Unit); + + var quantity21 = LinearPowerDensity.From(1, LinearPowerDensityUnit.WattPerFoot); + AssertEx.EqualTolerance(1, quantity21.WattsPerFoot, WattsPerFootTolerance); + Assert.Equal(LinearPowerDensityUnit.WattPerFoot, quantity21.Unit); + + var quantity22 = LinearPowerDensity.From(1, LinearPowerDensityUnit.WattPerInch); + AssertEx.EqualTolerance(1, quantity22.WattsPerInch, WattsPerInchTolerance); + Assert.Equal(LinearPowerDensityUnit.WattPerInch, quantity22.Unit); + + var quantity23 = LinearPowerDensity.From(1, LinearPowerDensityUnit.WattPerMeter); + AssertEx.EqualTolerance(1, quantity23.WattsPerMeter, WattsPerMeterTolerance); + Assert.Equal(LinearPowerDensityUnit.WattPerMeter, quantity23.Unit); + + var quantity24 = LinearPowerDensity.From(1, LinearPowerDensityUnit.WattPerMillimeter); + AssertEx.EqualTolerance(1, quantity24.WattsPerMillimeter, WattsPerMillimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.WattPerMillimeter, quantity24.Unit); + + } + + [Fact] + public void FromWattsPerMeter_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => LinearPowerDensity.FromWattsPerMeter(double.PositiveInfinity)); + Assert.Throws(() => LinearPowerDensity.FromWattsPerMeter(double.NegativeInfinity)); + } + + [Fact] + public void FromWattsPerMeter_WithNanValue_ThrowsArgumentException() + { + Assert.Throws(() => LinearPowerDensity.FromWattsPerMeter(double.NaN)); + } + + [Fact] + public void As() + { + var wattpermeter = LinearPowerDensity.FromWattsPerMeter(1); + AssertEx.EqualTolerance(GigawattsPerCentimeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.GigawattPerCentimeter), GigawattsPerCentimeterTolerance); + AssertEx.EqualTolerance(GigawattsPerFootInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.GigawattPerFoot), GigawattsPerFootTolerance); + AssertEx.EqualTolerance(GigawattsPerInchInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.GigawattPerInch), GigawattsPerInchTolerance); + AssertEx.EqualTolerance(GigawattsPerMeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.GigawattPerMeter), GigawattsPerMeterTolerance); + AssertEx.EqualTolerance(GigawattsPerMillimeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.GigawattPerMillimeter), GigawattsPerMillimeterTolerance); + AssertEx.EqualTolerance(KilowattsPerCentimeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.KilowattPerCentimeter), KilowattsPerCentimeterTolerance); + AssertEx.EqualTolerance(KilowattsPerFootInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.KilowattPerFoot), KilowattsPerFootTolerance); + AssertEx.EqualTolerance(KilowattsPerInchInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.KilowattPerInch), KilowattsPerInchTolerance); + AssertEx.EqualTolerance(KilowattsPerMeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.KilowattPerMeter), KilowattsPerMeterTolerance); + AssertEx.EqualTolerance(KilowattsPerMillimeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.KilowattPerMillimeter), KilowattsPerMillimeterTolerance); + AssertEx.EqualTolerance(MegawattsPerCentimeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.MegawattPerCentimeter), MegawattsPerCentimeterTolerance); + AssertEx.EqualTolerance(MegawattsPerFootInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.MegawattPerFoot), MegawattsPerFootTolerance); + AssertEx.EqualTolerance(MegawattsPerInchInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.MegawattPerInch), MegawattsPerInchTolerance); + AssertEx.EqualTolerance(MegawattsPerMeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.MegawattPerMeter), MegawattsPerMeterTolerance); + AssertEx.EqualTolerance(MegawattsPerMillimeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.MegawattPerMillimeter), MegawattsPerMillimeterTolerance); + AssertEx.EqualTolerance(MilliwattsPerCentimeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.MilliwattPerCentimeter), MilliwattsPerCentimeterTolerance); + AssertEx.EqualTolerance(MilliwattsPerFootInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.MilliwattPerFoot), MilliwattsPerFootTolerance); + AssertEx.EqualTolerance(MilliwattsPerInchInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.MilliwattPerInch), MilliwattsPerInchTolerance); + AssertEx.EqualTolerance(MilliwattsPerMeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.MilliwattPerMeter), MilliwattsPerMeterTolerance); + AssertEx.EqualTolerance(MilliwattsPerMillimeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.MilliwattPerMillimeter), MilliwattsPerMillimeterTolerance); + AssertEx.EqualTolerance(WattsPerCentimeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.WattPerCentimeter), WattsPerCentimeterTolerance); + AssertEx.EqualTolerance(WattsPerFootInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.WattPerFoot), WattsPerFootTolerance); + AssertEx.EqualTolerance(WattsPerInchInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.WattPerInch), WattsPerInchTolerance); + AssertEx.EqualTolerance(WattsPerMeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.WattPerMeter), WattsPerMeterTolerance); + AssertEx.EqualTolerance(WattsPerMillimeterInOneWattPerMeter, wattpermeter.As(LinearPowerDensityUnit.WattPerMillimeter), WattsPerMillimeterTolerance); + } + + [Fact] + public void ToUnit() + { + var wattpermeter = LinearPowerDensity.FromWattsPerMeter(1); + + var gigawattpercentimeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.GigawattPerCentimeter); + AssertEx.EqualTolerance(GigawattsPerCentimeterInOneWattPerMeter, (double)gigawattpercentimeterQuantity.Value, GigawattsPerCentimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.GigawattPerCentimeter, gigawattpercentimeterQuantity.Unit); + + var gigawattperfootQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.GigawattPerFoot); + AssertEx.EqualTolerance(GigawattsPerFootInOneWattPerMeter, (double)gigawattperfootQuantity.Value, GigawattsPerFootTolerance); + Assert.Equal(LinearPowerDensityUnit.GigawattPerFoot, gigawattperfootQuantity.Unit); + + var gigawattperinchQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.GigawattPerInch); + AssertEx.EqualTolerance(GigawattsPerInchInOneWattPerMeter, (double)gigawattperinchQuantity.Value, GigawattsPerInchTolerance); + Assert.Equal(LinearPowerDensityUnit.GigawattPerInch, gigawattperinchQuantity.Unit); + + var gigawattpermeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.GigawattPerMeter); + AssertEx.EqualTolerance(GigawattsPerMeterInOneWattPerMeter, (double)gigawattpermeterQuantity.Value, GigawattsPerMeterTolerance); + Assert.Equal(LinearPowerDensityUnit.GigawattPerMeter, gigawattpermeterQuantity.Unit); + + var gigawattpermillimeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.GigawattPerMillimeter); + AssertEx.EqualTolerance(GigawattsPerMillimeterInOneWattPerMeter, (double)gigawattpermillimeterQuantity.Value, GigawattsPerMillimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.GigawattPerMillimeter, gigawattpermillimeterQuantity.Unit); + + var kilowattpercentimeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.KilowattPerCentimeter); + AssertEx.EqualTolerance(KilowattsPerCentimeterInOneWattPerMeter, (double)kilowattpercentimeterQuantity.Value, KilowattsPerCentimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.KilowattPerCentimeter, kilowattpercentimeterQuantity.Unit); + + var kilowattperfootQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.KilowattPerFoot); + AssertEx.EqualTolerance(KilowattsPerFootInOneWattPerMeter, (double)kilowattperfootQuantity.Value, KilowattsPerFootTolerance); + Assert.Equal(LinearPowerDensityUnit.KilowattPerFoot, kilowattperfootQuantity.Unit); + + var kilowattperinchQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.KilowattPerInch); + AssertEx.EqualTolerance(KilowattsPerInchInOneWattPerMeter, (double)kilowattperinchQuantity.Value, KilowattsPerInchTolerance); + Assert.Equal(LinearPowerDensityUnit.KilowattPerInch, kilowattperinchQuantity.Unit); + + var kilowattpermeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.KilowattPerMeter); + AssertEx.EqualTolerance(KilowattsPerMeterInOneWattPerMeter, (double)kilowattpermeterQuantity.Value, KilowattsPerMeterTolerance); + Assert.Equal(LinearPowerDensityUnit.KilowattPerMeter, kilowattpermeterQuantity.Unit); + + var kilowattpermillimeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.KilowattPerMillimeter); + AssertEx.EqualTolerance(KilowattsPerMillimeterInOneWattPerMeter, (double)kilowattpermillimeterQuantity.Value, KilowattsPerMillimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.KilowattPerMillimeter, kilowattpermillimeterQuantity.Unit); + + var megawattpercentimeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.MegawattPerCentimeter); + AssertEx.EqualTolerance(MegawattsPerCentimeterInOneWattPerMeter, (double)megawattpercentimeterQuantity.Value, MegawattsPerCentimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MegawattPerCentimeter, megawattpercentimeterQuantity.Unit); + + var megawattperfootQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.MegawattPerFoot); + AssertEx.EqualTolerance(MegawattsPerFootInOneWattPerMeter, (double)megawattperfootQuantity.Value, MegawattsPerFootTolerance); + Assert.Equal(LinearPowerDensityUnit.MegawattPerFoot, megawattperfootQuantity.Unit); + + var megawattperinchQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.MegawattPerInch); + AssertEx.EqualTolerance(MegawattsPerInchInOneWattPerMeter, (double)megawattperinchQuantity.Value, MegawattsPerInchTolerance); + Assert.Equal(LinearPowerDensityUnit.MegawattPerInch, megawattperinchQuantity.Unit); + + var megawattpermeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.MegawattPerMeter); + AssertEx.EqualTolerance(MegawattsPerMeterInOneWattPerMeter, (double)megawattpermeterQuantity.Value, MegawattsPerMeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MegawattPerMeter, megawattpermeterQuantity.Unit); + + var megawattpermillimeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.MegawattPerMillimeter); + AssertEx.EqualTolerance(MegawattsPerMillimeterInOneWattPerMeter, (double)megawattpermillimeterQuantity.Value, MegawattsPerMillimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MegawattPerMillimeter, megawattpermillimeterQuantity.Unit); + + var milliwattpercentimeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.MilliwattPerCentimeter); + AssertEx.EqualTolerance(MilliwattsPerCentimeterInOneWattPerMeter, (double)milliwattpercentimeterQuantity.Value, MilliwattsPerCentimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MilliwattPerCentimeter, milliwattpercentimeterQuantity.Unit); + + var milliwattperfootQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.MilliwattPerFoot); + AssertEx.EqualTolerance(MilliwattsPerFootInOneWattPerMeter, (double)milliwattperfootQuantity.Value, MilliwattsPerFootTolerance); + Assert.Equal(LinearPowerDensityUnit.MilliwattPerFoot, milliwattperfootQuantity.Unit); + + var milliwattperinchQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.MilliwattPerInch); + AssertEx.EqualTolerance(MilliwattsPerInchInOneWattPerMeter, (double)milliwattperinchQuantity.Value, MilliwattsPerInchTolerance); + Assert.Equal(LinearPowerDensityUnit.MilliwattPerInch, milliwattperinchQuantity.Unit); + + var milliwattpermeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.MilliwattPerMeter); + AssertEx.EqualTolerance(MilliwattsPerMeterInOneWattPerMeter, (double)milliwattpermeterQuantity.Value, MilliwattsPerMeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MilliwattPerMeter, milliwattpermeterQuantity.Unit); + + var milliwattpermillimeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.MilliwattPerMillimeter); + AssertEx.EqualTolerance(MilliwattsPerMillimeterInOneWattPerMeter, (double)milliwattpermillimeterQuantity.Value, MilliwattsPerMillimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.MilliwattPerMillimeter, milliwattpermillimeterQuantity.Unit); + + var wattpercentimeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.WattPerCentimeter); + AssertEx.EqualTolerance(WattsPerCentimeterInOneWattPerMeter, (double)wattpercentimeterQuantity.Value, WattsPerCentimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.WattPerCentimeter, wattpercentimeterQuantity.Unit); + + var wattperfootQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.WattPerFoot); + AssertEx.EqualTolerance(WattsPerFootInOneWattPerMeter, (double)wattperfootQuantity.Value, WattsPerFootTolerance); + Assert.Equal(LinearPowerDensityUnit.WattPerFoot, wattperfootQuantity.Unit); + + var wattperinchQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.WattPerInch); + AssertEx.EqualTolerance(WattsPerInchInOneWattPerMeter, (double)wattperinchQuantity.Value, WattsPerInchTolerance); + Assert.Equal(LinearPowerDensityUnit.WattPerInch, wattperinchQuantity.Unit); + + var wattpermeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.WattPerMeter); + AssertEx.EqualTolerance(WattsPerMeterInOneWattPerMeter, (double)wattpermeterQuantity.Value, WattsPerMeterTolerance); + Assert.Equal(LinearPowerDensityUnit.WattPerMeter, wattpermeterQuantity.Unit); + + var wattpermillimeterQuantity = wattpermeter.ToUnit(LinearPowerDensityUnit.WattPerMillimeter); + AssertEx.EqualTolerance(WattsPerMillimeterInOneWattPerMeter, (double)wattpermillimeterQuantity.Value, WattsPerMillimeterTolerance); + Assert.Equal(LinearPowerDensityUnit.WattPerMillimeter, wattpermillimeterQuantity.Unit); + } + + [Fact] + public void ConversionRoundTrip() + { + LinearPowerDensity wattpermeter = LinearPowerDensity.FromWattsPerMeter(1); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromGigawattsPerCentimeter(wattpermeter.GigawattsPerCentimeter).WattsPerMeter, GigawattsPerCentimeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromGigawattsPerFoot(wattpermeter.GigawattsPerFoot).WattsPerMeter, GigawattsPerFootTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromGigawattsPerInch(wattpermeter.GigawattsPerInch).WattsPerMeter, GigawattsPerInchTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromGigawattsPerMeter(wattpermeter.GigawattsPerMeter).WattsPerMeter, GigawattsPerMeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromGigawattsPerMillimeter(wattpermeter.GigawattsPerMillimeter).WattsPerMeter, GigawattsPerMillimeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromKilowattsPerCentimeter(wattpermeter.KilowattsPerCentimeter).WattsPerMeter, KilowattsPerCentimeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromKilowattsPerFoot(wattpermeter.KilowattsPerFoot).WattsPerMeter, KilowattsPerFootTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromKilowattsPerInch(wattpermeter.KilowattsPerInch).WattsPerMeter, KilowattsPerInchTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromKilowattsPerMeter(wattpermeter.KilowattsPerMeter).WattsPerMeter, KilowattsPerMeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromKilowattsPerMillimeter(wattpermeter.KilowattsPerMillimeter).WattsPerMeter, KilowattsPerMillimeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromMegawattsPerCentimeter(wattpermeter.MegawattsPerCentimeter).WattsPerMeter, MegawattsPerCentimeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromMegawattsPerFoot(wattpermeter.MegawattsPerFoot).WattsPerMeter, MegawattsPerFootTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromMegawattsPerInch(wattpermeter.MegawattsPerInch).WattsPerMeter, MegawattsPerInchTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromMegawattsPerMeter(wattpermeter.MegawattsPerMeter).WattsPerMeter, MegawattsPerMeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromMegawattsPerMillimeter(wattpermeter.MegawattsPerMillimeter).WattsPerMeter, MegawattsPerMillimeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromMilliwattsPerCentimeter(wattpermeter.MilliwattsPerCentimeter).WattsPerMeter, MilliwattsPerCentimeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromMilliwattsPerFoot(wattpermeter.MilliwattsPerFoot).WattsPerMeter, MilliwattsPerFootTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromMilliwattsPerInch(wattpermeter.MilliwattsPerInch).WattsPerMeter, MilliwattsPerInchTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromMilliwattsPerMeter(wattpermeter.MilliwattsPerMeter).WattsPerMeter, MilliwattsPerMeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromMilliwattsPerMillimeter(wattpermeter.MilliwattsPerMillimeter).WattsPerMeter, MilliwattsPerMillimeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromWattsPerCentimeter(wattpermeter.WattsPerCentimeter).WattsPerMeter, WattsPerCentimeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromWattsPerFoot(wattpermeter.WattsPerFoot).WattsPerMeter, WattsPerFootTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromWattsPerInch(wattpermeter.WattsPerInch).WattsPerMeter, WattsPerInchTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromWattsPerMeter(wattpermeter.WattsPerMeter).WattsPerMeter, WattsPerMeterTolerance); + AssertEx.EqualTolerance(1, LinearPowerDensity.FromWattsPerMillimeter(wattpermeter.WattsPerMillimeter).WattsPerMeter, WattsPerMillimeterTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + LinearPowerDensity v = LinearPowerDensity.FromWattsPerMeter(1); + AssertEx.EqualTolerance(-1, -v.WattsPerMeter, WattsPerMeterTolerance); + AssertEx.EqualTolerance(2, (LinearPowerDensity.FromWattsPerMeter(3)-v).WattsPerMeter, WattsPerMeterTolerance); + AssertEx.EqualTolerance(2, (v + v).WattsPerMeter, WattsPerMeterTolerance); + AssertEx.EqualTolerance(10, (v*10).WattsPerMeter, WattsPerMeterTolerance); + AssertEx.EqualTolerance(10, (10*v).WattsPerMeter, WattsPerMeterTolerance); + AssertEx.EqualTolerance(2, (LinearPowerDensity.FromWattsPerMeter(10)/5).WattsPerMeter, WattsPerMeterTolerance); + AssertEx.EqualTolerance(2, LinearPowerDensity.FromWattsPerMeter(10)/LinearPowerDensity.FromWattsPerMeter(5), WattsPerMeterTolerance); + } + + [Fact] + public void ComparisonOperators() + { + LinearPowerDensity oneWattPerMeter = LinearPowerDensity.FromWattsPerMeter(1); + LinearPowerDensity twoWattsPerMeter = LinearPowerDensity.FromWattsPerMeter(2); + + Assert.True(oneWattPerMeter < twoWattsPerMeter); + Assert.True(oneWattPerMeter <= twoWattsPerMeter); + Assert.True(twoWattsPerMeter > oneWattPerMeter); + Assert.True(twoWattsPerMeter >= oneWattPerMeter); + + Assert.False(oneWattPerMeter > twoWattsPerMeter); + Assert.False(oneWattPerMeter >= twoWattsPerMeter); + Assert.False(twoWattsPerMeter < oneWattPerMeter); + Assert.False(twoWattsPerMeter <= oneWattPerMeter); + } + + [Fact] + public void CompareToIsImplemented() + { + LinearPowerDensity wattpermeter = LinearPowerDensity.FromWattsPerMeter(1); + Assert.Equal(0, wattpermeter.CompareTo(wattpermeter)); + Assert.True(wattpermeter.CompareTo(LinearPowerDensity.Zero) > 0); + Assert.True(LinearPowerDensity.Zero.CompareTo(wattpermeter) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + LinearPowerDensity wattpermeter = LinearPowerDensity.FromWattsPerMeter(1); + Assert.Throws(() => wattpermeter.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + LinearPowerDensity wattpermeter = LinearPowerDensity.FromWattsPerMeter(1); + Assert.Throws(() => wattpermeter.CompareTo(null)); + } + + [Fact] + public void EqualityOperators() + { + var a = LinearPowerDensity.FromWattsPerMeter(1); + var b = LinearPowerDensity.FromWattsPerMeter(2); + + // 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 + } + + [Fact] + public void EqualsIsImplemented() + { + var a = LinearPowerDensity.FromWattsPerMeter(1); + var b = LinearPowerDensity.FromWattsPerMeter(2); + + Assert.True(a.Equals(a)); + Assert.False(a.Equals(b)); + Assert.False(a.Equals(null)); + } + + [Fact] + public void EqualsRelativeToleranceIsImplemented() + { + var v = LinearPowerDensity.FromWattsPerMeter(1); + Assert.True(v.Equals(LinearPowerDensity.FromWattsPerMeter(1), WattsPerMeterTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(LinearPowerDensity.Zero, WattsPerMeterTolerance, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + LinearPowerDensity wattpermeter = LinearPowerDensity.FromWattsPerMeter(1); + Assert.False(wattpermeter.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + LinearPowerDensity wattpermeter = LinearPowerDensity.FromWattsPerMeter(1); + Assert.False(wattpermeter.Equals(null)); + } + + [Fact] + public void UnitsDoesNotContainUndefined() + { + Assert.DoesNotContain(LinearPowerDensityUnit.Undefined, LinearPowerDensity.Units); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(LinearPowerDensityUnit)).Cast(); + foreach(var unit in units) + { + if(unit == LinearPowerDensityUnit.Undefined) + continue; + + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(LinearPowerDensity.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentUICulture; + Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 GW/cm", new LinearPowerDensity(1, LinearPowerDensityUnit.GigawattPerCentimeter).ToString()); + Assert.Equal("1 GW/ft", new LinearPowerDensity(1, LinearPowerDensityUnit.GigawattPerFoot).ToString()); + Assert.Equal("1 GW/in", new LinearPowerDensity(1, LinearPowerDensityUnit.GigawattPerInch).ToString()); + Assert.Equal("1 GW/m", new LinearPowerDensity(1, LinearPowerDensityUnit.GigawattPerMeter).ToString()); + Assert.Equal("1 GW/mm", new LinearPowerDensity(1, LinearPowerDensityUnit.GigawattPerMillimeter).ToString()); + Assert.Equal("1 kW/cm", new LinearPowerDensity(1, LinearPowerDensityUnit.KilowattPerCentimeter).ToString()); + Assert.Equal("1 kW/ft", new LinearPowerDensity(1, LinearPowerDensityUnit.KilowattPerFoot).ToString()); + Assert.Equal("1 kW/in", new LinearPowerDensity(1, LinearPowerDensityUnit.KilowattPerInch).ToString()); + Assert.Equal("1 kW/m", new LinearPowerDensity(1, LinearPowerDensityUnit.KilowattPerMeter).ToString()); + Assert.Equal("1 kW/mm", new LinearPowerDensity(1, LinearPowerDensityUnit.KilowattPerMillimeter).ToString()); + Assert.Equal("1 MW/cm", new LinearPowerDensity(1, LinearPowerDensityUnit.MegawattPerCentimeter).ToString()); + Assert.Equal("1 MW/ft", new LinearPowerDensity(1, LinearPowerDensityUnit.MegawattPerFoot).ToString()); + Assert.Equal("1 MW/in", new LinearPowerDensity(1, LinearPowerDensityUnit.MegawattPerInch).ToString()); + Assert.Equal("1 MW/m", new LinearPowerDensity(1, LinearPowerDensityUnit.MegawattPerMeter).ToString()); + Assert.Equal("1 MW/mm", new LinearPowerDensity(1, LinearPowerDensityUnit.MegawattPerMillimeter).ToString()); + Assert.Equal("1 mW/cm", new LinearPowerDensity(1, LinearPowerDensityUnit.MilliwattPerCentimeter).ToString()); + Assert.Equal("1 mW/ft", new LinearPowerDensity(1, LinearPowerDensityUnit.MilliwattPerFoot).ToString()); + Assert.Equal("1 mW/in", new LinearPowerDensity(1, LinearPowerDensityUnit.MilliwattPerInch).ToString()); + Assert.Equal("1 mW/m", new LinearPowerDensity(1, LinearPowerDensityUnit.MilliwattPerMeter).ToString()); + Assert.Equal("1 mW/mm", new LinearPowerDensity(1, LinearPowerDensityUnit.MilliwattPerMillimeter).ToString()); + Assert.Equal("1 W/cm", new LinearPowerDensity(1, LinearPowerDensityUnit.WattPerCentimeter).ToString()); + Assert.Equal("1 W/ft", new LinearPowerDensity(1, LinearPowerDensityUnit.WattPerFoot).ToString()); + Assert.Equal("1 W/in", new LinearPowerDensity(1, LinearPowerDensityUnit.WattPerInch).ToString()); + Assert.Equal("1 W/m", new LinearPowerDensity(1, LinearPowerDensityUnit.WattPerMeter).ToString()); + Assert.Equal("1 W/mm", new LinearPowerDensity(1, LinearPowerDensityUnit.WattPerMillimeter).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 GW/cm", new LinearPowerDensity(1, LinearPowerDensityUnit.GigawattPerCentimeter).ToString(swedishCulture)); + Assert.Equal("1 GW/ft", new LinearPowerDensity(1, LinearPowerDensityUnit.GigawattPerFoot).ToString(swedishCulture)); + Assert.Equal("1 GW/in", new LinearPowerDensity(1, LinearPowerDensityUnit.GigawattPerInch).ToString(swedishCulture)); + Assert.Equal("1 GW/m", new LinearPowerDensity(1, LinearPowerDensityUnit.GigawattPerMeter).ToString(swedishCulture)); + Assert.Equal("1 GW/mm", new LinearPowerDensity(1, LinearPowerDensityUnit.GigawattPerMillimeter).ToString(swedishCulture)); + Assert.Equal("1 kW/cm", new LinearPowerDensity(1, LinearPowerDensityUnit.KilowattPerCentimeter).ToString(swedishCulture)); + Assert.Equal("1 kW/ft", new LinearPowerDensity(1, LinearPowerDensityUnit.KilowattPerFoot).ToString(swedishCulture)); + Assert.Equal("1 kW/in", new LinearPowerDensity(1, LinearPowerDensityUnit.KilowattPerInch).ToString(swedishCulture)); + Assert.Equal("1 kW/m", new LinearPowerDensity(1, LinearPowerDensityUnit.KilowattPerMeter).ToString(swedishCulture)); + Assert.Equal("1 kW/mm", new LinearPowerDensity(1, LinearPowerDensityUnit.KilowattPerMillimeter).ToString(swedishCulture)); + Assert.Equal("1 MW/cm", new LinearPowerDensity(1, LinearPowerDensityUnit.MegawattPerCentimeter).ToString(swedishCulture)); + Assert.Equal("1 MW/ft", new LinearPowerDensity(1, LinearPowerDensityUnit.MegawattPerFoot).ToString(swedishCulture)); + Assert.Equal("1 MW/in", new LinearPowerDensity(1, LinearPowerDensityUnit.MegawattPerInch).ToString(swedishCulture)); + Assert.Equal("1 MW/m", new LinearPowerDensity(1, LinearPowerDensityUnit.MegawattPerMeter).ToString(swedishCulture)); + Assert.Equal("1 MW/mm", new LinearPowerDensity(1, LinearPowerDensityUnit.MegawattPerMillimeter).ToString(swedishCulture)); + Assert.Equal("1 mW/cm", new LinearPowerDensity(1, LinearPowerDensityUnit.MilliwattPerCentimeter).ToString(swedishCulture)); + Assert.Equal("1 mW/ft", new LinearPowerDensity(1, LinearPowerDensityUnit.MilliwattPerFoot).ToString(swedishCulture)); + Assert.Equal("1 mW/in", new LinearPowerDensity(1, LinearPowerDensityUnit.MilliwattPerInch).ToString(swedishCulture)); + Assert.Equal("1 mW/m", new LinearPowerDensity(1, LinearPowerDensityUnit.MilliwattPerMeter).ToString(swedishCulture)); + Assert.Equal("1 mW/mm", new LinearPowerDensity(1, LinearPowerDensityUnit.MilliwattPerMillimeter).ToString(swedishCulture)); + Assert.Equal("1 W/cm", new LinearPowerDensity(1, LinearPowerDensityUnit.WattPerCentimeter).ToString(swedishCulture)); + Assert.Equal("1 W/ft", new LinearPowerDensity(1, LinearPowerDensityUnit.WattPerFoot).ToString(swedishCulture)); + Assert.Equal("1 W/in", new LinearPowerDensity(1, LinearPowerDensityUnit.WattPerInch).ToString(swedishCulture)); + Assert.Equal("1 W/m", new LinearPowerDensity(1, LinearPowerDensityUnit.WattPerMeter).ToString(swedishCulture)); + Assert.Equal("1 W/mm", new LinearPowerDensity(1, LinearPowerDensityUnit.WattPerMillimeter).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentUICulture; + try + { + CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 W/m", new LinearPowerDensity(0.123456, LinearPowerDensityUnit.WattPerMeter).ToString("s1")); + Assert.Equal("0.12 W/m", new LinearPowerDensity(0.123456, LinearPowerDensityUnit.WattPerMeter).ToString("s2")); + Assert.Equal("0.123 W/m", new LinearPowerDensity(0.123456, LinearPowerDensityUnit.WattPerMeter).ToString("s3")); + Assert.Equal("0.1235 W/m", new LinearPowerDensity(0.123456, LinearPowerDensityUnit.WattPerMeter).ToString("s4")); + } + finally + { + CultureInfo.CurrentUICulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 W/m", new LinearPowerDensity(0.123456, LinearPowerDensityUnit.WattPerMeter).ToString("s1", culture)); + Assert.Equal("0.12 W/m", new LinearPowerDensity(0.123456, LinearPowerDensityUnit.WattPerMeter).ToString("s2", culture)); + Assert.Equal("0.123 W/m", new LinearPowerDensity(0.123456, LinearPowerDensityUnit.WattPerMeter).ToString("s3", culture)); + Assert.Equal("0.1235 W/m", new LinearPowerDensity(0.123456, LinearPowerDensityUnit.WattPerMeter).ToString("s4", culture)); + } + } +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LinearPowerDensity.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LinearPowerDensity.g.cs new file mode 100644 index 0000000000..6f361343a0 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/LinearPowerDensity.g.cs @@ -0,0 +1,991 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// The Linear Power Density of a substance is its power per unit length. The term linear density is most often used when describing the characteristics of one-dimensional objects, although linear density can also be used to describe the density of a three-dimensional quantity along one particular dimension. + /// + /// + /// http://en.wikipedia.org/wiki/Linear_density + /// + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. + public sealed partial class LinearPowerDensity : IQuantity + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly LinearPowerDensityUnit? _unit; + + static LinearPowerDensity() + { + BaseDimensions = new BaseDimensions(1, 1, -3, 0, 0, 0, 0); + Info = new QuantityInfo(QuantityType.LinearPowerDensity, Units.Cast().ToArray(), BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with a value of 0 in the base unit WattPerMeter. + /// + /// + /// Windows Runtime Component requires a default constructor. + /// + public LinearPowerDensity() + { + _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 LinearPowerDensity(double value, LinearPowerDensityUnit unit) + { + if(unit == LinearPowerDensityUnit.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 LinearPowerDensity, which is WattPerMeter. All conversions go via this value. + /// + public static LinearPowerDensityUnit BaseUnit { get; } = LinearPowerDensityUnit.WattPerMeter; + + /// + /// Represents the largest possible value of LinearPowerDensity + /// + public static LinearPowerDensity MaxValue { get; } = new LinearPowerDensity(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of LinearPowerDensity + /// + public static LinearPowerDensity MinValue { get; } = new LinearPowerDensity(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.LinearPowerDensity; + + /// + /// All units of measurement for the LinearPowerDensity quantity. + /// + public static LinearPowerDensityUnit[] Units { get; } = Enum.GetValues(typeof(LinearPowerDensityUnit)).Cast().Except(new LinearPowerDensityUnit[]{ LinearPowerDensityUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit WattPerMeter. + /// + public static LinearPowerDensity Zero { get; } = new LinearPowerDensity(0, BaseUnit); + + #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 LinearPowerDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + internal QuantityInfo QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => LinearPowerDensity.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => LinearPowerDensity.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get LinearPowerDensity in GigawattsPerCentimeter. + /// + public double GigawattsPerCentimeter => As(LinearPowerDensityUnit.GigawattPerCentimeter); + + /// + /// Get LinearPowerDensity in GigawattsPerFoot. + /// + public double GigawattsPerFoot => As(LinearPowerDensityUnit.GigawattPerFoot); + + /// + /// Get LinearPowerDensity in GigawattsPerInch. + /// + public double GigawattsPerInch => As(LinearPowerDensityUnit.GigawattPerInch); + + /// + /// Get LinearPowerDensity in GigawattsPerMeter. + /// + public double GigawattsPerMeter => As(LinearPowerDensityUnit.GigawattPerMeter); + + /// + /// Get LinearPowerDensity in GigawattsPerMillimeter. + /// + public double GigawattsPerMillimeter => As(LinearPowerDensityUnit.GigawattPerMillimeter); + + /// + /// Get LinearPowerDensity in KilowattsPerCentimeter. + /// + public double KilowattsPerCentimeter => As(LinearPowerDensityUnit.KilowattPerCentimeter); + + /// + /// Get LinearPowerDensity in KilowattsPerFoot. + /// + public double KilowattsPerFoot => As(LinearPowerDensityUnit.KilowattPerFoot); + + /// + /// Get LinearPowerDensity in KilowattsPerInch. + /// + public double KilowattsPerInch => As(LinearPowerDensityUnit.KilowattPerInch); + + /// + /// Get LinearPowerDensity in KilowattsPerMeter. + /// + public double KilowattsPerMeter => As(LinearPowerDensityUnit.KilowattPerMeter); + + /// + /// Get LinearPowerDensity in KilowattsPerMillimeter. + /// + public double KilowattsPerMillimeter => As(LinearPowerDensityUnit.KilowattPerMillimeter); + + /// + /// Get LinearPowerDensity in MegawattsPerCentimeter. + /// + public double MegawattsPerCentimeter => As(LinearPowerDensityUnit.MegawattPerCentimeter); + + /// + /// Get LinearPowerDensity in MegawattsPerFoot. + /// + public double MegawattsPerFoot => As(LinearPowerDensityUnit.MegawattPerFoot); + + /// + /// Get LinearPowerDensity in MegawattsPerInch. + /// + public double MegawattsPerInch => As(LinearPowerDensityUnit.MegawattPerInch); + + /// + /// Get LinearPowerDensity in MegawattsPerMeter. + /// + public double MegawattsPerMeter => As(LinearPowerDensityUnit.MegawattPerMeter); + + /// + /// Get LinearPowerDensity in MegawattsPerMillimeter. + /// + public double MegawattsPerMillimeter => As(LinearPowerDensityUnit.MegawattPerMillimeter); + + /// + /// Get LinearPowerDensity in MilliwattsPerCentimeter. + /// + public double MilliwattsPerCentimeter => As(LinearPowerDensityUnit.MilliwattPerCentimeter); + + /// + /// Get LinearPowerDensity in MilliwattsPerFoot. + /// + public double MilliwattsPerFoot => As(LinearPowerDensityUnit.MilliwattPerFoot); + + /// + /// Get LinearPowerDensity in MilliwattsPerInch. + /// + public double MilliwattsPerInch => As(LinearPowerDensityUnit.MilliwattPerInch); + + /// + /// Get LinearPowerDensity in MilliwattsPerMeter. + /// + public double MilliwattsPerMeter => As(LinearPowerDensityUnit.MilliwattPerMeter); + + /// + /// Get LinearPowerDensity in MilliwattsPerMillimeter. + /// + public double MilliwattsPerMillimeter => As(LinearPowerDensityUnit.MilliwattPerMillimeter); + + /// + /// Get LinearPowerDensity in WattsPerCentimeter. + /// + public double WattsPerCentimeter => As(LinearPowerDensityUnit.WattPerCentimeter); + + /// + /// Get LinearPowerDensity in WattsPerFoot. + /// + public double WattsPerFoot => As(LinearPowerDensityUnit.WattPerFoot); + + /// + /// Get LinearPowerDensity in WattsPerInch. + /// + public double WattsPerInch => As(LinearPowerDensityUnit.WattPerInch); + + /// + /// Get LinearPowerDensity in WattsPerMeter. + /// + public double WattsPerMeter => As(LinearPowerDensityUnit.WattPerMeter); + + /// + /// Get LinearPowerDensity in WattsPerMillimeter. + /// + public double WattsPerMillimeter => As(LinearPowerDensityUnit.WattPerMillimeter); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(LinearPowerDensityUnit 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(LinearPowerDensityUnit unit, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get LinearPowerDensity from GigawattsPerCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromGigawattsPerCentimeter(double gigawattspercentimeter) + { + double value = (double) gigawattspercentimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.GigawattPerCentimeter); + } + /// + /// Get LinearPowerDensity from GigawattsPerFoot. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromGigawattsPerFoot(double gigawattsperfoot) + { + double value = (double) gigawattsperfoot; + return new LinearPowerDensity(value, LinearPowerDensityUnit.GigawattPerFoot); + } + /// + /// Get LinearPowerDensity from GigawattsPerInch. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromGigawattsPerInch(double gigawattsperinch) + { + double value = (double) gigawattsperinch; + return new LinearPowerDensity(value, LinearPowerDensityUnit.GigawattPerInch); + } + /// + /// Get LinearPowerDensity from GigawattsPerMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromGigawattsPerMeter(double gigawattspermeter) + { + double value = (double) gigawattspermeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.GigawattPerMeter); + } + /// + /// Get LinearPowerDensity from GigawattsPerMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromGigawattsPerMillimeter(double gigawattspermillimeter) + { + double value = (double) gigawattspermillimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.GigawattPerMillimeter); + } + /// + /// Get LinearPowerDensity from KilowattsPerCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromKilowattsPerCentimeter(double kilowattspercentimeter) + { + double value = (double) kilowattspercentimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.KilowattPerCentimeter); + } + /// + /// Get LinearPowerDensity from KilowattsPerFoot. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromKilowattsPerFoot(double kilowattsperfoot) + { + double value = (double) kilowattsperfoot; + return new LinearPowerDensity(value, LinearPowerDensityUnit.KilowattPerFoot); + } + /// + /// Get LinearPowerDensity from KilowattsPerInch. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromKilowattsPerInch(double kilowattsperinch) + { + double value = (double) kilowattsperinch; + return new LinearPowerDensity(value, LinearPowerDensityUnit.KilowattPerInch); + } + /// + /// Get LinearPowerDensity from KilowattsPerMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromKilowattsPerMeter(double kilowattspermeter) + { + double value = (double) kilowattspermeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.KilowattPerMeter); + } + /// + /// Get LinearPowerDensity from KilowattsPerMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromKilowattsPerMillimeter(double kilowattspermillimeter) + { + double value = (double) kilowattspermillimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.KilowattPerMillimeter); + } + /// + /// Get LinearPowerDensity from MegawattsPerCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromMegawattsPerCentimeter(double megawattspercentimeter) + { + double value = (double) megawattspercentimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MegawattPerCentimeter); + } + /// + /// Get LinearPowerDensity from MegawattsPerFoot. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromMegawattsPerFoot(double megawattsperfoot) + { + double value = (double) megawattsperfoot; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MegawattPerFoot); + } + /// + /// Get LinearPowerDensity from MegawattsPerInch. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromMegawattsPerInch(double megawattsperinch) + { + double value = (double) megawattsperinch; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MegawattPerInch); + } + /// + /// Get LinearPowerDensity from MegawattsPerMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromMegawattsPerMeter(double megawattspermeter) + { + double value = (double) megawattspermeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MegawattPerMeter); + } + /// + /// Get LinearPowerDensity from MegawattsPerMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromMegawattsPerMillimeter(double megawattspermillimeter) + { + double value = (double) megawattspermillimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MegawattPerMillimeter); + } + /// + /// Get LinearPowerDensity from MilliwattsPerCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromMilliwattsPerCentimeter(double milliwattspercentimeter) + { + double value = (double) milliwattspercentimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MilliwattPerCentimeter); + } + /// + /// Get LinearPowerDensity from MilliwattsPerFoot. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromMilliwattsPerFoot(double milliwattsperfoot) + { + double value = (double) milliwattsperfoot; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MilliwattPerFoot); + } + /// + /// Get LinearPowerDensity from MilliwattsPerInch. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromMilliwattsPerInch(double milliwattsperinch) + { + double value = (double) milliwattsperinch; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MilliwattPerInch); + } + /// + /// Get LinearPowerDensity from MilliwattsPerMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromMilliwattsPerMeter(double milliwattspermeter) + { + double value = (double) milliwattspermeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MilliwattPerMeter); + } + /// + /// Get LinearPowerDensity from MilliwattsPerMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromMilliwattsPerMillimeter(double milliwattspermillimeter) + { + double value = (double) milliwattspermillimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MilliwattPerMillimeter); + } + /// + /// Get LinearPowerDensity from WattsPerCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromWattsPerCentimeter(double wattspercentimeter) + { + double value = (double) wattspercentimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.WattPerCentimeter); + } + /// + /// Get LinearPowerDensity from WattsPerFoot. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromWattsPerFoot(double wattsperfoot) + { + double value = (double) wattsperfoot; + return new LinearPowerDensity(value, LinearPowerDensityUnit.WattPerFoot); + } + /// + /// Get LinearPowerDensity from WattsPerInch. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromWattsPerInch(double wattsperinch) + { + double value = (double) wattsperinch; + return new LinearPowerDensity(value, LinearPowerDensityUnit.WattPerInch); + } + /// + /// Get LinearPowerDensity from WattsPerMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromWattsPerMeter(double wattspermeter) + { + double value = (double) wattspermeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.WattPerMeter); + } + /// + /// Get LinearPowerDensity from WattsPerMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static LinearPowerDensity FromWattsPerMillimeter(double wattspermillimeter) + { + double value = (double) wattspermillimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.WattPerMillimeter); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// LinearPowerDensity unit value. + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static LinearPowerDensity From(double value, LinearPowerDensityUnit fromUnit) + { + return new LinearPowerDensity((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 LinearPowerDensity 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 LinearPowerDensity 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 LinearPowerDensity 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 LinearPowerDensity 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 LinearPowerDensityUnit 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 LinearPowerDensityUnit ParseUnit(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.Parse(str, provider); + } + + public static bool TryParseUnit(string str, out LinearPowerDensityUnit 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 LinearPowerDensityUnit 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 LinearPowerDensity objLinearPowerDensity)) throw new ArgumentException("Expected type LinearPowerDensity.", nameof(obj)); + + return CompareTo(objLinearPowerDensity); + } + + // 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(LinearPowerDensity other) + { + return _value.CompareTo(other.AsBaseNumericType(this.Unit)); + } + + [Windows.Foundation.Metadata.DefaultOverload] + public override bool Equals(object obj) + { + if(obj is null || !(obj is LinearPowerDensity objLinearPowerDensity)) + return false; + + return Equals(objLinearPowerDensity); + } + + public bool Equals(LinearPowerDensity other) + { + return _value.Equals(other.AsBaseNumericType(this.Unit)); + } + + /// + /// + /// Compare equality to another LinearPowerDensity 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(LinearPowerDensity 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 LinearPowerDensity. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + double IQuantity.As(object unit) => As((LinearPowerDensityUnit)unit); + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(LinearPowerDensityUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = AsBaseNumericType(unit); + return Convert.ToDouble(converted); + } + + /// + /// Converts this LinearPowerDensity to another LinearPowerDensity with the unit representation . + /// + /// A LinearPowerDensity with the specified unit. + public LinearPowerDensity ToUnit(LinearPowerDensityUnit unit) + { + var convertedValue = AsBaseNumericType(unit); + return new LinearPowerDensity(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 LinearPowerDensityUnit.GigawattPerCentimeter: return (_value*1e2) * 1e9d; + case LinearPowerDensityUnit.GigawattPerFoot: return (_value*3.280839895) * 1e9d; + case LinearPowerDensityUnit.GigawattPerInch: return (_value*39.37007874) * 1e9d; + case LinearPowerDensityUnit.GigawattPerMeter: return (_value) * 1e9d; + case LinearPowerDensityUnit.GigawattPerMillimeter: return (_value*1e3) * 1e9d; + case LinearPowerDensityUnit.KilowattPerCentimeter: return (_value*1e2) * 1e3d; + case LinearPowerDensityUnit.KilowattPerFoot: return (_value*3.280839895) * 1e3d; + case LinearPowerDensityUnit.KilowattPerInch: return (_value*39.37007874) * 1e3d; + case LinearPowerDensityUnit.KilowattPerMeter: return (_value) * 1e3d; + case LinearPowerDensityUnit.KilowattPerMillimeter: return (_value*1e3) * 1e3d; + case LinearPowerDensityUnit.MegawattPerCentimeter: return (_value*1e2) * 1e6d; + case LinearPowerDensityUnit.MegawattPerFoot: return (_value*3.280839895) * 1e6d; + case LinearPowerDensityUnit.MegawattPerInch: return (_value*39.37007874) * 1e6d; + case LinearPowerDensityUnit.MegawattPerMeter: return (_value) * 1e6d; + case LinearPowerDensityUnit.MegawattPerMillimeter: return (_value*1e3) * 1e6d; + case LinearPowerDensityUnit.MilliwattPerCentimeter: return (_value*1e2) * 1e-3d; + case LinearPowerDensityUnit.MilliwattPerFoot: return (_value*3.280839895) * 1e-3d; + case LinearPowerDensityUnit.MilliwattPerInch: return (_value*39.37007874) * 1e-3d; + case LinearPowerDensityUnit.MilliwattPerMeter: return (_value) * 1e-3d; + case LinearPowerDensityUnit.MilliwattPerMillimeter: return (_value*1e3) * 1e-3d; + case LinearPowerDensityUnit.WattPerCentimeter: return _value*1e2; + case LinearPowerDensityUnit.WattPerFoot: return _value*3.280839895; + case LinearPowerDensityUnit.WattPerInch: return _value*39.37007874; + case LinearPowerDensityUnit.WattPerMeter: return _value; + case LinearPowerDensityUnit.WattPerMillimeter: return _value*1e3; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double AsBaseNumericType(LinearPowerDensityUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = AsBaseUnit(); + + switch(unit) + { + case LinearPowerDensityUnit.GigawattPerCentimeter: return (baseUnitValue/1e2) / 1e9d; + case LinearPowerDensityUnit.GigawattPerFoot: return (baseUnitValue/3.280839895) / 1e9d; + case LinearPowerDensityUnit.GigawattPerInch: return (baseUnitValue/39.37007874) / 1e9d; + case LinearPowerDensityUnit.GigawattPerMeter: return (baseUnitValue) / 1e9d; + case LinearPowerDensityUnit.GigawattPerMillimeter: return (baseUnitValue/1e3) / 1e9d; + case LinearPowerDensityUnit.KilowattPerCentimeter: return (baseUnitValue/1e2) / 1e3d; + case LinearPowerDensityUnit.KilowattPerFoot: return (baseUnitValue/3.280839895) / 1e3d; + case LinearPowerDensityUnit.KilowattPerInch: return (baseUnitValue/39.37007874) / 1e3d; + case LinearPowerDensityUnit.KilowattPerMeter: return (baseUnitValue) / 1e3d; + case LinearPowerDensityUnit.KilowattPerMillimeter: return (baseUnitValue/1e3) / 1e3d; + case LinearPowerDensityUnit.MegawattPerCentimeter: return (baseUnitValue/1e2) / 1e6d; + case LinearPowerDensityUnit.MegawattPerFoot: return (baseUnitValue/3.280839895) / 1e6d; + case LinearPowerDensityUnit.MegawattPerInch: return (baseUnitValue/39.37007874) / 1e6d; + case LinearPowerDensityUnit.MegawattPerMeter: return (baseUnitValue) / 1e6d; + case LinearPowerDensityUnit.MegawattPerMillimeter: return (baseUnitValue/1e3) / 1e6d; + case LinearPowerDensityUnit.MilliwattPerCentimeter: return (baseUnitValue/1e2) / 1e-3d; + case LinearPowerDensityUnit.MilliwattPerFoot: return (baseUnitValue/3.280839895) / 1e-3d; + case LinearPowerDensityUnit.MilliwattPerInch: return (baseUnitValue/39.37007874) / 1e-3d; + case LinearPowerDensityUnit.MilliwattPerMeter: return (baseUnitValue) / 1e-3d; + case LinearPowerDensityUnit.MilliwattPerMillimeter: return (baseUnitValue/1e3) / 1e-3d; + case LinearPowerDensityUnit.WattPerCentimeter: return baseUnitValue/1e2; + case LinearPowerDensityUnit.WattPerFoot: return baseUnitValue/3.280839895; + case LinearPowerDensityUnit.WattPerInch: return baseUnitValue/39.37007874; + case LinearPowerDensityUnit.WattPerMeter: return baseUnitValue; + case LinearPowerDensityUnit.WattPerMillimeter: return baseUnitValue/1e3; + 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 1b3d5f547e..b436f897ed 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs @@ -194,6 +194,9 @@ internal static bool TryFrom(double value, Enum unit, out IQuantity quantity) case LinearDensityUnit linearDensityUnit: quantity = LinearDensity.From(value, linearDensityUnit); return true; + case LinearPowerDensityUnit linearPowerDensityUnit: + quantity = LinearPowerDensity.From(value, linearPowerDensityUnit); + return true; case LuminosityUnit luminosityUnit: quantity = Luminosity.From(value, luminosityUnit); return true; @@ -544,6 +547,9 @@ internal static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type q if (quantityType == typeof(LinearDensity)) return parser.TryParse(quantityString, formatProvider, LinearDensity.From, out quantity); + if (quantityType == typeof(LinearPowerDensity)) + return parser.TryParse(quantityString, formatProvider, LinearPowerDensity.From, out quantity); + if (quantityType == typeof(Luminosity)) return parser.TryParse(quantityString, formatProvider, Luminosity.From, out quantity); diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs index a6e4cec3e9..ecdb0c8b69 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs @@ -80,6 +80,7 @@ public enum QuantityType Length, Level, LinearDensity, + LinearPowerDensity, Luminosity, LuminousFlux, LuminousIntensity, diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs index 222b7d750d..f32b2d23c9 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -615,6 +615,31 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.MilligramPerMillimeter, new string[]{"mg/mm"}), ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.PoundPerFoot, new string[]{"lb/ft"}), ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.PoundPerInch, new string[]{"lb/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.GigawattPerCentimeter, new string[]{"GW/cm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.GigawattPerFoot, new string[]{"GW/ft"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.GigawattPerInch, new string[]{"GW/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.GigawattPerMeter, new string[]{"GW/m"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.GigawattPerMillimeter, new string[]{"GW/mm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.KilowattPerCentimeter, new string[]{"kW/cm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.KilowattPerFoot, new string[]{"kW/ft"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.KilowattPerInch, new string[]{"kW/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.KilowattPerMeter, new string[]{"kW/m"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.KilowattPerMillimeter, new string[]{"kW/mm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MegawattPerCentimeter, new string[]{"MW/cm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MegawattPerFoot, new string[]{"MW/ft"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MegawattPerInch, new string[]{"MW/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MegawattPerMeter, new string[]{"MW/m"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MegawattPerMillimeter, new string[]{"MW/mm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MilliwattPerCentimeter, new string[]{"mW/cm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MilliwattPerFoot, new string[]{"mW/ft"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MilliwattPerInch, new string[]{"mW/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MilliwattPerMeter, new string[]{"mW/m"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MilliwattPerMillimeter, new string[]{"mW/mm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.WattPerCentimeter, new string[]{"W/cm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.WattPerFoot, new string[]{"W/ft"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.WattPerInch, new string[]{"W/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.WattPerMeter, new string[]{"W/m"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.WattPerMillimeter, new string[]{"W/mm"}), ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Decawatt, new string[]{"daW"}), ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Deciwatt, new string[]{"dW"}), ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Femtowatt, new string[]{"fW"}), diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LinearPowerDensityUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LinearPowerDensityUnit.g.cs new file mode 100644 index 0000000000..8395416543 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LinearPowerDensityUnit.g.cs @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// 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 LinearPowerDensityUnit + { + Undefined = 0, + GigawattPerCentimeter, + GigawattPerFoot, + GigawattPerInch, + GigawattPerMeter, + GigawattPerMillimeter, + KilowattPerCentimeter, + KilowattPerFoot, + KilowattPerInch, + KilowattPerMeter, + KilowattPerMillimeter, + MegawattPerCentimeter, + MegawattPerFoot, + MegawattPerInch, + MegawattPerMeter, + MegawattPerMillimeter, + MilliwattPerCentimeter, + MilliwattPerFoot, + MilliwattPerInch, + MilliwattPerMeter, + MilliwattPerMillimeter, + WattPerCentimeter, + WattPerFoot, + WattPerInch, + WattPerMeter, + WattPerMillimeter, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs new file mode 100644 index 0000000000..a5de965729 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs @@ -0,0 +1,1261 @@ +//------------------------------------------------------------------------------ +// +// 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.InternalHelpers; +using UnitsNet.Units; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// The Linear Power Density of a substance is its power per unit length. The term linear density is most often used when describing the characteristics of one-dimensional objects, although linear density can also be used to describe the density of a three-dimensional quantity along one particular dimension. + /// + /// + /// http://en.wikipedia.org/wiki/Linear_density + /// + public partial struct LinearPowerDensity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly LinearPowerDensityUnit? _unit; + + static LinearPowerDensity() + { + BaseDimensions = new BaseDimensions(1, 1, -3, 0, 0, 0, 0); + + Info = new QuantityInfo(QuantityType.LinearPowerDensity, + new UnitInfo[] { + new UnitInfo(LinearPowerDensityUnit.GigawattPerCentimeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.GigawattPerFoot, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.GigawattPerInch, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.GigawattPerMeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.GigawattPerMillimeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.KilowattPerCentimeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.KilowattPerFoot, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.KilowattPerInch, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.KilowattPerMeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.KilowattPerMillimeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.MegawattPerCentimeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.MegawattPerFoot, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.MegawattPerInch, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.MegawattPerMeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.MegawattPerMillimeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.MilliwattPerCentimeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.MilliwattPerFoot, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.MilliwattPerInch, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.MilliwattPerMeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.MilliwattPerMillimeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.WattPerCentimeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.WattPerFoot, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.WattPerInch, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.WattPerMeter, BaseUnits.Undefined), + new UnitInfo(LinearPowerDensityUnit.WattPerMillimeter, BaseUnits.Undefined), + }, + BaseUnit, Zero, BaseDimensions); + } + + /// + /// 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 LinearPowerDensity(double value, LinearPowerDensityUnit unit) + { + if(unit == LinearPowerDensityUnit.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 LinearPowerDensity(double value, UnitSystem unitSystem) + { + if(unitSystem == 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 + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of LinearPowerDensity, which is WattPerMeter. All conversions go via this value. + /// + public static LinearPowerDensityUnit BaseUnit { get; } = LinearPowerDensityUnit.WattPerMeter; + + /// + /// Represents the largest possible value of LinearPowerDensity + /// + public static LinearPowerDensity MaxValue { get; } = new LinearPowerDensity(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of LinearPowerDensity + /// + public static LinearPowerDensity MinValue { get; } = new LinearPowerDensity(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.LinearPowerDensity; + + /// + /// All units of measurement for the LinearPowerDensity quantity. + /// + public static LinearPowerDensityUnit[] Units { get; } = Enum.GetValues(typeof(LinearPowerDensityUnit)).Cast().Except(new LinearPowerDensityUnit[]{ LinearPowerDensityUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit WattPerMeter. + /// + public static LinearPowerDensity Zero { get; } = new LinearPowerDensity(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + Enum IQuantity.Unit => Unit; + + /// + public LinearPowerDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => LinearPowerDensity.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => LinearPowerDensity.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get LinearPowerDensity in GigawattsPerCentimeter. + /// + public double GigawattsPerCentimeter => As(LinearPowerDensityUnit.GigawattPerCentimeter); + + /// + /// Get LinearPowerDensity in GigawattsPerFoot. + /// + public double GigawattsPerFoot => As(LinearPowerDensityUnit.GigawattPerFoot); + + /// + /// Get LinearPowerDensity in GigawattsPerInch. + /// + public double GigawattsPerInch => As(LinearPowerDensityUnit.GigawattPerInch); + + /// + /// Get LinearPowerDensity in GigawattsPerMeter. + /// + public double GigawattsPerMeter => As(LinearPowerDensityUnit.GigawattPerMeter); + + /// + /// Get LinearPowerDensity in GigawattsPerMillimeter. + /// + public double GigawattsPerMillimeter => As(LinearPowerDensityUnit.GigawattPerMillimeter); + + /// + /// Get LinearPowerDensity in KilowattsPerCentimeter. + /// + public double KilowattsPerCentimeter => As(LinearPowerDensityUnit.KilowattPerCentimeter); + + /// + /// Get LinearPowerDensity in KilowattsPerFoot. + /// + public double KilowattsPerFoot => As(LinearPowerDensityUnit.KilowattPerFoot); + + /// + /// Get LinearPowerDensity in KilowattsPerInch. + /// + public double KilowattsPerInch => As(LinearPowerDensityUnit.KilowattPerInch); + + /// + /// Get LinearPowerDensity in KilowattsPerMeter. + /// + public double KilowattsPerMeter => As(LinearPowerDensityUnit.KilowattPerMeter); + + /// + /// Get LinearPowerDensity in KilowattsPerMillimeter. + /// + public double KilowattsPerMillimeter => As(LinearPowerDensityUnit.KilowattPerMillimeter); + + /// + /// Get LinearPowerDensity in MegawattsPerCentimeter. + /// + public double MegawattsPerCentimeter => As(LinearPowerDensityUnit.MegawattPerCentimeter); + + /// + /// Get LinearPowerDensity in MegawattsPerFoot. + /// + public double MegawattsPerFoot => As(LinearPowerDensityUnit.MegawattPerFoot); + + /// + /// Get LinearPowerDensity in MegawattsPerInch. + /// + public double MegawattsPerInch => As(LinearPowerDensityUnit.MegawattPerInch); + + /// + /// Get LinearPowerDensity in MegawattsPerMeter. + /// + public double MegawattsPerMeter => As(LinearPowerDensityUnit.MegawattPerMeter); + + /// + /// Get LinearPowerDensity in MegawattsPerMillimeter. + /// + public double MegawattsPerMillimeter => As(LinearPowerDensityUnit.MegawattPerMillimeter); + + /// + /// Get LinearPowerDensity in MilliwattsPerCentimeter. + /// + public double MilliwattsPerCentimeter => As(LinearPowerDensityUnit.MilliwattPerCentimeter); + + /// + /// Get LinearPowerDensity in MilliwattsPerFoot. + /// + public double MilliwattsPerFoot => As(LinearPowerDensityUnit.MilliwattPerFoot); + + /// + /// Get LinearPowerDensity in MilliwattsPerInch. + /// + public double MilliwattsPerInch => As(LinearPowerDensityUnit.MilliwattPerInch); + + /// + /// Get LinearPowerDensity in MilliwattsPerMeter. + /// + public double MilliwattsPerMeter => As(LinearPowerDensityUnit.MilliwattPerMeter); + + /// + /// Get LinearPowerDensity in MilliwattsPerMillimeter. + /// + public double MilliwattsPerMillimeter => As(LinearPowerDensityUnit.MilliwattPerMillimeter); + + /// + /// Get LinearPowerDensity in WattsPerCentimeter. + /// + public double WattsPerCentimeter => As(LinearPowerDensityUnit.WattPerCentimeter); + + /// + /// Get LinearPowerDensity in WattsPerFoot. + /// + public double WattsPerFoot => As(LinearPowerDensityUnit.WattPerFoot); + + /// + /// Get LinearPowerDensity in WattsPerInch. + /// + public double WattsPerInch => As(LinearPowerDensityUnit.WattPerInch); + + /// + /// Get LinearPowerDensity in WattsPerMeter. + /// + public double WattsPerMeter => As(LinearPowerDensityUnit.WattPerMeter); + + /// + /// Get LinearPowerDensity in WattsPerMillimeter. + /// + public double WattsPerMillimeter => As(LinearPowerDensityUnit.WattPerMillimeter); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(LinearPowerDensityUnit 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(LinearPowerDensityUnit unit, [CanBeNull] IFormatProvider provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get LinearPowerDensity from GigawattsPerCentimeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromGigawattsPerCentimeter(QuantityValue gigawattspercentimeter) + { + double value = (double) gigawattspercentimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.GigawattPerCentimeter); + } + /// + /// Get LinearPowerDensity from GigawattsPerFoot. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromGigawattsPerFoot(QuantityValue gigawattsperfoot) + { + double value = (double) gigawattsperfoot; + return new LinearPowerDensity(value, LinearPowerDensityUnit.GigawattPerFoot); + } + /// + /// Get LinearPowerDensity from GigawattsPerInch. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromGigawattsPerInch(QuantityValue gigawattsperinch) + { + double value = (double) gigawattsperinch; + return new LinearPowerDensity(value, LinearPowerDensityUnit.GigawattPerInch); + } + /// + /// Get LinearPowerDensity from GigawattsPerMeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromGigawattsPerMeter(QuantityValue gigawattspermeter) + { + double value = (double) gigawattspermeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.GigawattPerMeter); + } + /// + /// Get LinearPowerDensity from GigawattsPerMillimeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromGigawattsPerMillimeter(QuantityValue gigawattspermillimeter) + { + double value = (double) gigawattspermillimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.GigawattPerMillimeter); + } + /// + /// Get LinearPowerDensity from KilowattsPerCentimeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromKilowattsPerCentimeter(QuantityValue kilowattspercentimeter) + { + double value = (double) kilowattspercentimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.KilowattPerCentimeter); + } + /// + /// Get LinearPowerDensity from KilowattsPerFoot. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromKilowattsPerFoot(QuantityValue kilowattsperfoot) + { + double value = (double) kilowattsperfoot; + return new LinearPowerDensity(value, LinearPowerDensityUnit.KilowattPerFoot); + } + /// + /// Get LinearPowerDensity from KilowattsPerInch. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromKilowattsPerInch(QuantityValue kilowattsperinch) + { + double value = (double) kilowattsperinch; + return new LinearPowerDensity(value, LinearPowerDensityUnit.KilowattPerInch); + } + /// + /// Get LinearPowerDensity from KilowattsPerMeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromKilowattsPerMeter(QuantityValue kilowattspermeter) + { + double value = (double) kilowattspermeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.KilowattPerMeter); + } + /// + /// Get LinearPowerDensity from KilowattsPerMillimeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromKilowattsPerMillimeter(QuantityValue kilowattspermillimeter) + { + double value = (double) kilowattspermillimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.KilowattPerMillimeter); + } + /// + /// Get LinearPowerDensity from MegawattsPerCentimeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromMegawattsPerCentimeter(QuantityValue megawattspercentimeter) + { + double value = (double) megawattspercentimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MegawattPerCentimeter); + } + /// + /// Get LinearPowerDensity from MegawattsPerFoot. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromMegawattsPerFoot(QuantityValue megawattsperfoot) + { + double value = (double) megawattsperfoot; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MegawattPerFoot); + } + /// + /// Get LinearPowerDensity from MegawattsPerInch. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromMegawattsPerInch(QuantityValue megawattsperinch) + { + double value = (double) megawattsperinch; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MegawattPerInch); + } + /// + /// Get LinearPowerDensity from MegawattsPerMeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromMegawattsPerMeter(QuantityValue megawattspermeter) + { + double value = (double) megawattspermeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MegawattPerMeter); + } + /// + /// Get LinearPowerDensity from MegawattsPerMillimeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromMegawattsPerMillimeter(QuantityValue megawattspermillimeter) + { + double value = (double) megawattspermillimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MegawattPerMillimeter); + } + /// + /// Get LinearPowerDensity from MilliwattsPerCentimeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromMilliwattsPerCentimeter(QuantityValue milliwattspercentimeter) + { + double value = (double) milliwattspercentimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MilliwattPerCentimeter); + } + /// + /// Get LinearPowerDensity from MilliwattsPerFoot. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromMilliwattsPerFoot(QuantityValue milliwattsperfoot) + { + double value = (double) milliwattsperfoot; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MilliwattPerFoot); + } + /// + /// Get LinearPowerDensity from MilliwattsPerInch. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromMilliwattsPerInch(QuantityValue milliwattsperinch) + { + double value = (double) milliwattsperinch; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MilliwattPerInch); + } + /// + /// Get LinearPowerDensity from MilliwattsPerMeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromMilliwattsPerMeter(QuantityValue milliwattspermeter) + { + double value = (double) milliwattspermeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MilliwattPerMeter); + } + /// + /// Get LinearPowerDensity from MilliwattsPerMillimeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromMilliwattsPerMillimeter(QuantityValue milliwattspermillimeter) + { + double value = (double) milliwattspermillimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.MilliwattPerMillimeter); + } + /// + /// Get LinearPowerDensity from WattsPerCentimeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromWattsPerCentimeter(QuantityValue wattspercentimeter) + { + double value = (double) wattspercentimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.WattPerCentimeter); + } + /// + /// Get LinearPowerDensity from WattsPerFoot. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromWattsPerFoot(QuantityValue wattsperfoot) + { + double value = (double) wattsperfoot; + return new LinearPowerDensity(value, LinearPowerDensityUnit.WattPerFoot); + } + /// + /// Get LinearPowerDensity from WattsPerInch. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromWattsPerInch(QuantityValue wattsperinch) + { + double value = (double) wattsperinch; + return new LinearPowerDensity(value, LinearPowerDensityUnit.WattPerInch); + } + /// + /// Get LinearPowerDensity from WattsPerMeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromWattsPerMeter(QuantityValue wattspermeter) + { + double value = (double) wattspermeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.WattPerMeter); + } + /// + /// Get LinearPowerDensity from WattsPerMillimeter. + /// + /// If value is NaN or Infinity. + public static LinearPowerDensity FromWattsPerMillimeter(QuantityValue wattspermillimeter) + { + double value = (double) wattspermillimeter; + return new LinearPowerDensity(value, LinearPowerDensityUnit.WattPerMillimeter); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// LinearPowerDensity unit value. + public static LinearPowerDensity From(QuantityValue value, LinearPowerDensityUnit fromUnit) + { + return new LinearPowerDensity((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 LinearPowerDensity 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 LinearPowerDensity Parse(string str, [CanBeNull] 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([CanBeNull] string str, out LinearPowerDensity 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([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out LinearPowerDensity 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 LinearPowerDensityUnit 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 LinearPowerDensityUnit ParseUnit(string str, [CanBeNull] IFormatProvider provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out LinearPowerDensityUnit 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 LinearPowerDensityUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static LinearPowerDensity operator -(LinearPowerDensity right) + { + return new LinearPowerDensity(-right.Value, right.Unit); + } + + /// Get from adding two . + public static LinearPowerDensity operator +(LinearPowerDensity left, LinearPowerDensity right) + { + return new LinearPowerDensity(left.Value + right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from subtracting two . + public static LinearPowerDensity operator -(LinearPowerDensity left, LinearPowerDensity right) + { + return new LinearPowerDensity(left.Value - right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from multiplying value and . + public static LinearPowerDensity operator *(double left, LinearPowerDensity right) + { + return new LinearPowerDensity(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static LinearPowerDensity operator *(LinearPowerDensity left, double right) + { + return new LinearPowerDensity(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static LinearPowerDensity operator /(LinearPowerDensity left, double right) + { + return new LinearPowerDensity(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(LinearPowerDensity left, LinearPowerDensity right) + { + return left.WattsPerMeter / right.WattsPerMeter; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(LinearPowerDensity left, LinearPowerDensity right) + { + return left.Value <= right.GetValueAs(left.Unit); + } + + /// Returns true if greater than or equal to. + public static bool operator >=(LinearPowerDensity left, LinearPowerDensity right) + { + return left.Value >= right.GetValueAs(left.Unit); + } + + /// Returns true if less than. + public static bool operator <(LinearPowerDensity left, LinearPowerDensity right) + { + return left.Value < right.GetValueAs(left.Unit); + } + + /// Returns true if greater than. + public static bool operator >(LinearPowerDensity left, LinearPowerDensity 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 ==(LinearPowerDensity left, LinearPowerDensity right) + { + return left.Equals(right); + } + + /// Returns true if not exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator !=(LinearPowerDensity left, LinearPowerDensity right) + { + return !(left == right); + } + + /// + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is LinearPowerDensity objLinearPowerDensity)) throw new ArgumentException("Expected type LinearPowerDensity.", nameof(obj)); + + return CompareTo(objLinearPowerDensity); + } + + /// + public int CompareTo(LinearPowerDensity 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 LinearPowerDensity objLinearPowerDensity)) + return false; + + return Equals(objLinearPowerDensity); + } + + /// + /// Consider using for safely comparing floating point values. + public bool Equals(LinearPowerDensity other) + { + return _value.Equals(other.GetValueAs(this.Unit)); + } + + /// + /// + /// Compare equality to another LinearPowerDensity 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(LinearPowerDensity 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 LinearPowerDensity. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(LinearPowerDensityUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = GetValueAs(unit); + return Convert.ToDouble(converted); + } + + /// + public double As(UnitSystem unitSystem) + { + if(unitSystem == 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 LinearPowerDensityUnit unitAsLinearPowerDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearPowerDensityUnit)} is supported.", nameof(unit)); + + return As(unitAsLinearPowerDensityUnit); + } + + /// + /// Converts this LinearPowerDensity to another LinearPowerDensity with the unit representation . + /// + /// A LinearPowerDensity with the specified unit. + public LinearPowerDensity ToUnit(LinearPowerDensityUnit unit) + { + var convertedValue = GetValueAs(unit); + return new LinearPowerDensity(convertedValue, unit); + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is LinearPowerDensityUnit unitAsLinearPowerDensityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LinearPowerDensityUnit)} is supported.", nameof(unit)); + + return ToUnit(unitAsLinearPowerDensityUnit); + } + + /// + public LinearPowerDensity ToUnit(UnitSystem unitSystem) + { + if(unitSystem == 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(LinearPowerDensityUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + /// 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() + { + switch(Unit) + { + case LinearPowerDensityUnit.GigawattPerCentimeter: return (_value*1e2) * 1e9d; + case LinearPowerDensityUnit.GigawattPerFoot: return (_value*3.280839895) * 1e9d; + case LinearPowerDensityUnit.GigawattPerInch: return (_value*39.37007874) * 1e9d; + case LinearPowerDensityUnit.GigawattPerMeter: return (_value) * 1e9d; + case LinearPowerDensityUnit.GigawattPerMillimeter: return (_value*1e3) * 1e9d; + case LinearPowerDensityUnit.KilowattPerCentimeter: return (_value*1e2) * 1e3d; + case LinearPowerDensityUnit.KilowattPerFoot: return (_value*3.280839895) * 1e3d; + case LinearPowerDensityUnit.KilowattPerInch: return (_value*39.37007874) * 1e3d; + case LinearPowerDensityUnit.KilowattPerMeter: return (_value) * 1e3d; + case LinearPowerDensityUnit.KilowattPerMillimeter: return (_value*1e3) * 1e3d; + case LinearPowerDensityUnit.MegawattPerCentimeter: return (_value*1e2) * 1e6d; + case LinearPowerDensityUnit.MegawattPerFoot: return (_value*3.280839895) * 1e6d; + case LinearPowerDensityUnit.MegawattPerInch: return (_value*39.37007874) * 1e6d; + case LinearPowerDensityUnit.MegawattPerMeter: return (_value) * 1e6d; + case LinearPowerDensityUnit.MegawattPerMillimeter: return (_value*1e3) * 1e6d; + case LinearPowerDensityUnit.MilliwattPerCentimeter: return (_value*1e2) * 1e-3d; + case LinearPowerDensityUnit.MilliwattPerFoot: return (_value*3.280839895) * 1e-3d; + case LinearPowerDensityUnit.MilliwattPerInch: return (_value*39.37007874) * 1e-3d; + case LinearPowerDensityUnit.MilliwattPerMeter: return (_value) * 1e-3d; + case LinearPowerDensityUnit.MilliwattPerMillimeter: return (_value*1e3) * 1e-3d; + case LinearPowerDensityUnit.WattPerCentimeter: return _value*1e2; + case LinearPowerDensityUnit.WattPerFoot: return _value*3.280839895; + case LinearPowerDensityUnit.WattPerInch: return _value*39.37007874; + case LinearPowerDensityUnit.WattPerMeter: return _value; + case LinearPowerDensityUnit.WattPerMillimeter: return _value*1e3; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + /// + /// 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. + internal LinearPowerDensity ToBaseUnit() + { + var baseUnitValue = GetValueInBaseUnit(); + return new LinearPowerDensity(baseUnitValue, BaseUnit); + } + + private double GetValueAs(LinearPowerDensityUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + switch(unit) + { + case LinearPowerDensityUnit.GigawattPerCentimeter: return (baseUnitValue/1e2) / 1e9d; + case LinearPowerDensityUnit.GigawattPerFoot: return (baseUnitValue/3.280839895) / 1e9d; + case LinearPowerDensityUnit.GigawattPerInch: return (baseUnitValue/39.37007874) / 1e9d; + case LinearPowerDensityUnit.GigawattPerMeter: return (baseUnitValue) / 1e9d; + case LinearPowerDensityUnit.GigawattPerMillimeter: return (baseUnitValue/1e3) / 1e9d; + case LinearPowerDensityUnit.KilowattPerCentimeter: return (baseUnitValue/1e2) / 1e3d; + case LinearPowerDensityUnit.KilowattPerFoot: return (baseUnitValue/3.280839895) / 1e3d; + case LinearPowerDensityUnit.KilowattPerInch: return (baseUnitValue/39.37007874) / 1e3d; + case LinearPowerDensityUnit.KilowattPerMeter: return (baseUnitValue) / 1e3d; + case LinearPowerDensityUnit.KilowattPerMillimeter: return (baseUnitValue/1e3) / 1e3d; + case LinearPowerDensityUnit.MegawattPerCentimeter: return (baseUnitValue/1e2) / 1e6d; + case LinearPowerDensityUnit.MegawattPerFoot: return (baseUnitValue/3.280839895) / 1e6d; + case LinearPowerDensityUnit.MegawattPerInch: return (baseUnitValue/39.37007874) / 1e6d; + case LinearPowerDensityUnit.MegawattPerMeter: return (baseUnitValue) / 1e6d; + case LinearPowerDensityUnit.MegawattPerMillimeter: return (baseUnitValue/1e3) / 1e6d; + case LinearPowerDensityUnit.MilliwattPerCentimeter: return (baseUnitValue/1e2) / 1e-3d; + case LinearPowerDensityUnit.MilliwattPerFoot: return (baseUnitValue/3.280839895) / 1e-3d; + case LinearPowerDensityUnit.MilliwattPerInch: return (baseUnitValue/39.37007874) / 1e-3d; + case LinearPowerDensityUnit.MilliwattPerMeter: return (baseUnitValue) / 1e-3d; + case LinearPowerDensityUnit.MilliwattPerMillimeter: return (baseUnitValue/1e3) / 1e-3d; + case LinearPowerDensityUnit.WattPerCentimeter: return baseUnitValue/1e2; + case LinearPowerDensityUnit.WattPerFoot: return baseUnitValue/3.280839895; + case LinearPowerDensityUnit.WattPerInch: return baseUnitValue/39.37007874; + case LinearPowerDensityUnit.WattPerMeter: return baseUnitValue; + case LinearPowerDensityUnit.WattPerMillimeter: return baseUnitValue/1e3; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #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([CanBeNull] 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([CanBeNull] 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([CanBeNull] 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 formatProvider) + { + return QuantityFormatter.Format(this, format, formatProvider); + } + + #endregion + + #region IConvertible Methods + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(LinearPowerDensity)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(LinearPowerDensity)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(LinearPowerDensity)} 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(LinearPowerDensity)) + return this; + else if(conversionType == typeof(LinearPowerDensityUnit)) + return Unit; + else if(conversionType == typeof(QuantityType)) + return LinearPowerDensity.QuantityType; + else if(conversionType == typeof(BaseDimensions)) + return LinearPowerDensity.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(LinearPowerDensity)} 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 f1d8016b23..4675003c8c 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -142,6 +142,8 @@ public static IQuantity FromQuantityType(QuantityType quantityType, QuantityValu return Level.From(value, Level.BaseUnit); case QuantityType.LinearDensity: return LinearDensity.From(value, LinearDensity.BaseUnit); + case QuantityType.LinearPowerDensity: + return LinearPowerDensity.From(value, LinearPowerDensity.BaseUnit); case QuantityType.Luminosity: return Luminosity.From(value, Luminosity.BaseUnit); case QuantityType.LuminousFlux: @@ -409,6 +411,9 @@ public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity quantit case LinearDensityUnit linearDensityUnit: quantity = LinearDensity.From(value, linearDensityUnit); return true; + case LinearPowerDensityUnit linearPowerDensityUnit: + quantity = LinearPowerDensity.From(value, linearPowerDensityUnit); + return true; case LuminosityUnit luminosityUnit: quantity = Luminosity.From(value, luminosityUnit); return true; @@ -685,6 +690,8 @@ public static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type qua return parser.TryParse(quantityString, formatProvider, Level.From, out quantity); case Type _ when quantityType == typeof(LinearDensity): return parser.TryParse(quantityString, formatProvider, LinearDensity.From, out quantity); + case Type _ when quantityType == typeof(LinearPowerDensity): + return parser.TryParse(quantityString, formatProvider, LinearPowerDensity.From, out quantity); case Type _ when quantityType == typeof(Luminosity): return parser.TryParse(quantityString, formatProvider, Luminosity.From, out quantity); case Type _ when quantityType == typeof(LuminousFlux): diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs index b3f1f342fe..40ea6c9d6f 100644 --- a/UnitsNet/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet/GeneratedCode/QuantityType.g.cs @@ -82,6 +82,7 @@ public enum QuantityType Length, Level, LinearDensity, + LinearPowerDensity, Luminosity, LuminousFlux, LuminousIntensity, diff --git a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs index cacb3b68c9..7cc6b1771f 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -615,6 +615,31 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.MilligramPerMillimeter, new string[]{"mg/mm"}), ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.PoundPerFoot, new string[]{"lb/ft"}), ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.PoundPerInch, new string[]{"lb/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.GigawattPerCentimeter, new string[]{"GW/cm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.GigawattPerFoot, new string[]{"GW/ft"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.GigawattPerInch, new string[]{"GW/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.GigawattPerMeter, new string[]{"GW/m"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.GigawattPerMillimeter, new string[]{"GW/mm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.KilowattPerCentimeter, new string[]{"kW/cm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.KilowattPerFoot, new string[]{"kW/ft"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.KilowattPerInch, new string[]{"kW/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.KilowattPerMeter, new string[]{"kW/m"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.KilowattPerMillimeter, new string[]{"kW/mm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MegawattPerCentimeter, new string[]{"MW/cm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MegawattPerFoot, new string[]{"MW/ft"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MegawattPerInch, new string[]{"MW/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MegawattPerMeter, new string[]{"MW/m"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MegawattPerMillimeter, new string[]{"MW/mm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MilliwattPerCentimeter, new string[]{"mW/cm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MilliwattPerFoot, new string[]{"mW/ft"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MilliwattPerInch, new string[]{"mW/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MilliwattPerMeter, new string[]{"mW/m"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.MilliwattPerMillimeter, new string[]{"mW/mm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.WattPerCentimeter, new string[]{"W/cm"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.WattPerFoot, new string[]{"W/ft"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.WattPerInch, new string[]{"W/in"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.WattPerMeter, new string[]{"W/m"}), + ("en-US", typeof(LinearPowerDensityUnit), (int)LinearPowerDensityUnit.WattPerMillimeter, new string[]{"W/mm"}), ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Decawatt, new string[]{"daW"}), ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Deciwatt, new string[]{"dW"}), ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Femtowatt, new string[]{"fW"}), diff --git a/UnitsNet/GeneratedCode/UnitConverter.g.cs b/UnitsNet/GeneratedCode/UnitConverter.g.cs index 0e25bab244..de470f8dba 100644 --- a/UnitsNet/GeneratedCode/UnitConverter.g.cs +++ b/UnitsNet/GeneratedCode/UnitConverter.g.cs @@ -955,6 +955,55 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(LinearDensityUnit.PoundPerFoot, LinearDensity.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(LinearDensity.BaseUnit, LinearDensityUnit.PoundPerInch, q => q.ToUnit(LinearDensityUnit.PoundPerInch)); unitConverter.SetConversionFunction(LinearDensityUnit.PoundPerInch, LinearDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.GigawattPerCentimeter, q => q.ToUnit(LinearPowerDensityUnit.GigawattPerCentimeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.GigawattPerCentimeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.GigawattPerFoot, q => q.ToUnit(LinearPowerDensityUnit.GigawattPerFoot)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.GigawattPerFoot, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.GigawattPerInch, q => q.ToUnit(LinearPowerDensityUnit.GigawattPerInch)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.GigawattPerInch, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.GigawattPerMeter, q => q.ToUnit(LinearPowerDensityUnit.GigawattPerMeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.GigawattPerMeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.GigawattPerMillimeter, q => q.ToUnit(LinearPowerDensityUnit.GigawattPerMillimeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.GigawattPerMillimeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.KilowattPerCentimeter, q => q.ToUnit(LinearPowerDensityUnit.KilowattPerCentimeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.KilowattPerCentimeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.KilowattPerFoot, q => q.ToUnit(LinearPowerDensityUnit.KilowattPerFoot)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.KilowattPerFoot, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.KilowattPerInch, q => q.ToUnit(LinearPowerDensityUnit.KilowattPerInch)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.KilowattPerInch, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.KilowattPerMeter, q => q.ToUnit(LinearPowerDensityUnit.KilowattPerMeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.KilowattPerMeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.KilowattPerMillimeter, q => q.ToUnit(LinearPowerDensityUnit.KilowattPerMillimeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.KilowattPerMillimeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.MegawattPerCentimeter, q => q.ToUnit(LinearPowerDensityUnit.MegawattPerCentimeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.MegawattPerCentimeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.MegawattPerFoot, q => q.ToUnit(LinearPowerDensityUnit.MegawattPerFoot)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.MegawattPerFoot, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.MegawattPerInch, q => q.ToUnit(LinearPowerDensityUnit.MegawattPerInch)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.MegawattPerInch, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.MegawattPerMeter, q => q.ToUnit(LinearPowerDensityUnit.MegawattPerMeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.MegawattPerMeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.MegawattPerMillimeter, q => q.ToUnit(LinearPowerDensityUnit.MegawattPerMillimeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.MegawattPerMillimeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.MilliwattPerCentimeter, q => q.ToUnit(LinearPowerDensityUnit.MilliwattPerCentimeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.MilliwattPerCentimeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.MilliwattPerFoot, q => q.ToUnit(LinearPowerDensityUnit.MilliwattPerFoot)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.MilliwattPerFoot, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.MilliwattPerInch, q => q.ToUnit(LinearPowerDensityUnit.MilliwattPerInch)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.MilliwattPerInch, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.MilliwattPerMeter, q => q.ToUnit(LinearPowerDensityUnit.MilliwattPerMeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.MilliwattPerMeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.MilliwattPerMillimeter, q => q.ToUnit(LinearPowerDensityUnit.MilliwattPerMillimeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.MilliwattPerMillimeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.WattPerCentimeter, q => q.ToUnit(LinearPowerDensityUnit.WattPerCentimeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.WattPerCentimeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.WattPerFoot, q => q.ToUnit(LinearPowerDensityUnit.WattPerFoot)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.WattPerFoot, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.WattPerInch, q => q.ToUnit(LinearPowerDensityUnit.WattPerInch)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.WattPerInch, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensity.BaseUnit, q => q); + unitConverter.SetConversionFunction(LinearPowerDensity.BaseUnit, LinearPowerDensityUnit.WattPerMillimeter, q => q.ToUnit(LinearPowerDensityUnit.WattPerMillimeter)); + unitConverter.SetConversionFunction(LinearPowerDensityUnit.WattPerMillimeter, LinearPowerDensity.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Decawatt, q => q.ToUnit(LuminosityUnit.Decawatt)); unitConverter.SetConversionFunction(LuminosityUnit.Decawatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Deciwatt, q => q.ToUnit(LuminosityUnit.Deciwatt)); diff --git a/UnitsNet/GeneratedCode/Units/LinearPowerDensityUnit.g.cs b/UnitsNet/GeneratedCode/Units/LinearPowerDensityUnit.g.cs new file mode 100644 index 0000000000..8395416543 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/LinearPowerDensityUnit.g.cs @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// 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 LinearPowerDensityUnit + { + Undefined = 0, + GigawattPerCentimeter, + GigawattPerFoot, + GigawattPerInch, + GigawattPerMeter, + GigawattPerMillimeter, + KilowattPerCentimeter, + KilowattPerFoot, + KilowattPerInch, + KilowattPerMeter, + KilowattPerMillimeter, + MegawattPerCentimeter, + MegawattPerFoot, + MegawattPerInch, + MegawattPerMeter, + MegawattPerMillimeter, + MilliwattPerCentimeter, + MilliwattPerFoot, + MilliwattPerInch, + MilliwattPerMeter, + MilliwattPerMillimeter, + WattPerCentimeter, + WattPerFoot, + WattPerInch, + WattPerMeter, + WattPerMillimeter, + } + + #pragma warning restore 1591 +} From a9078946f0abfb576a017100ac0797faf28bad8d Mon Sep 17 00:00:00 2001 From: Travis Bement Date: Sun, 29 Mar 2020 15:06:43 -0400 Subject: [PATCH 2/6] Add combinations of Area, Density, and LinearDensity operators --- UnitsNet.Tests/CustomCode/AreaTests.cs | 7 +++++++ UnitsNet.Tests/CustomCode/DensityTests.cs | 7 +++++++ .../CustomCode/LinearDensityTests.cs | 16 +++++++++++++- UnitsNet/CustomCode/Quantities/Area.extra.cs | 6 ++++++ .../CustomCode/Quantities/Density.extra.cs | 6 ++++++ .../Quantities/LinearDensity.extra.cs | 21 +++++++++++++++++++ 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 UnitsNet/CustomCode/Quantities/LinearDensity.extra.cs diff --git a/UnitsNet.Tests/CustomCode/AreaTests.cs b/UnitsNet.Tests/CustomCode/AreaTests.cs index d637cd18a9..5edc60edba 100644 --- a/UnitsNet.Tests/CustomCode/AreaTests.cs +++ b/UnitsNet.Tests/CustomCode/AreaTests.cs @@ -51,6 +51,13 @@ public void AreaTimesMassFluxEqualsMassFlow() Assert.Equal(massFlow, MassFlow.FromKilogramsPerSecond(40)); } + [Fact] + public void AreaTimesDensityEqualsLinearDensity() + { + LinearDensity linearDensity = Area.FromSquareCentimeters(2) * Density.FromGramsPerCubicCentimeter(10); + Assert.Equal(LinearDensity.FromGramsPerCentimeter(20), linearDensity); + } + [Theory] [InlineData(0, 0)] [InlineData(0.5, 0.19634954084936208)] diff --git a/UnitsNet.Tests/CustomCode/DensityTests.cs b/UnitsNet.Tests/CustomCode/DensityTests.cs index 6d70e059c2..a2a1cc467d 100644 --- a/UnitsNet.Tests/CustomCode/DensityTests.cs +++ b/UnitsNet.Tests/CustomCode/DensityTests.cs @@ -121,5 +121,12 @@ public void DensityTimesAccelerationEqualsSpecificWeight() SpecificWeight specificWeight = Density.FromKilogramsPerCubicMeter(10) * Acceleration.FromMetersPerSecondSquared(2); Assert.Equal(SpecificWeight.FromNewtonsPerCubicMeter(20), specificWeight); } + + [Fact] + public void DensityTimesAreaEqualsLinearDensity() + { + LinearDensity linearDensity = Density.FromGramsPerCubicCentimeter(10) * Area.FromSquareCentimeters(2); + Assert.Equal(LinearDensity.FromGramsPerCentimeter(20), linearDensity); + } } } diff --git a/UnitsNet.Tests/CustomCode/LinearDensityTests.cs b/UnitsNet.Tests/CustomCode/LinearDensityTests.cs index 65bfdcec5c..2acc6e4f96 100644 --- a/UnitsNet.Tests/CustomCode/LinearDensityTests.cs +++ b/UnitsNet.Tests/CustomCode/LinearDensityTests.cs @@ -22,6 +22,7 @@ using System; +using Xunit; namespace UnitsNet.Tests.CustomCode { @@ -47,6 +48,19 @@ public class LinearDensityTests : LinearDensityTestsBase protected override double PoundsPerInchInOneKilogramPerMeter => 5.599741459E-02; protected override double PoundsPerFootInOneKilogramPerMeter => 6.71968975e-1; - + + [Fact] + public void LinearDensityDividedByAreaEqualsDensity() + { + Density density = LinearDensity.FromGramsPerCentimeter(10) / Area.FromSquareCentimeters(2); + Assert.Equal(Density.FromGramsPerCubicCentimeter(5), density); + } + + [Fact] + public void LinearDensityDividedByDensityEqualsArea() + { + Area area = LinearDensity.FromGramsPerCentimeter(10) / Density.FromGramsPerCubicCentimeter(2); + Assert.Equal(Area.FromSquareCentimeters(5), area); + } } } diff --git a/UnitsNet/CustomCode/Quantities/Area.extra.cs b/UnitsNet/CustomCode/Quantities/Area.extra.cs index a4c005015c..e207909f68 100644 --- a/UnitsNet/CustomCode/Quantities/Area.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Area.extra.cs @@ -41,5 +41,11 @@ public static Area FromCircleRadius(Length radius) { return VolumeFlow.FromCubicMetersPerSecond(area.SquareMeters * speed.MetersPerSecond); } + + /// Get from times . + public static LinearDensity operator *(Area area, Density density) + { + return LinearDensity.FromGramsPerCentimeter(area.SquareCentimeters * density.GramsPerCubicCentimeter); + } } } diff --git a/UnitsNet/CustomCode/Quantities/Density.extra.cs b/UnitsNet/CustomCode/Quantities/Density.extra.cs index e569cefac5..7e6dd55308 100644 --- a/UnitsNet/CustomCode/Quantities/Density.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Density.extra.cs @@ -70,5 +70,11 @@ public static Density FromMolarity(Molarity molarity, Mass molecularWeight) { return new Molarity(density.KilogramsPerCubicMeter / molecularWeight.Kilograms, MolarityUnit.MolesPerCubicMeter); } + + /// Get from times . + public static LinearDensity operator *(Density density, Area area) + { + return LinearDensity.FromGramsPerCentimeter(density.GramsPerCubicCentimeter * area.SquareCentimeters); + } } } diff --git a/UnitsNet/CustomCode/Quantities/LinearDensity.extra.cs b/UnitsNet/CustomCode/Quantities/LinearDensity.extra.cs new file mode 100644 index 0000000000..ad845b9e7c --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/LinearDensity.extra.cs @@ -0,0 +1,21 @@ +// 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. + +namespace UnitsNet +{ + public partial struct LinearDensity + { + + /// Get from times . + public static Density operator /(LinearDensity linearDensity, Area area) + { + return Density.FromGramsPerCubicCentimeter(linearDensity.GramsPerCentimeter / area.SquareCentimeters); + } + + /// Get from times . + public static Area operator /(LinearDensity linearDensity, Density density) + { + return Area.FromSquareCentimeters(linearDensity.GramsPerCentimeter / density.GramsPerCubicCentimeter); + } + } +} From c9d71d1dfba5c2612ad2543bf94dd6ce4e89a45f Mon Sep 17 00:00:00 2001 From: Travis Bement Date: Sun, 29 Mar 2020 17:21:46 -0400 Subject: [PATCH 3/6] Changed operator overloads for Area, Density, and LinearDensity to SI base units --- UnitsNet/CustomCode/Quantities/Area.extra.cs | 2 +- UnitsNet/CustomCode/Quantities/Density.extra.cs | 2 +- UnitsNet/CustomCode/Quantities/LinearDensity.extra.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/UnitsNet/CustomCode/Quantities/Area.extra.cs b/UnitsNet/CustomCode/Quantities/Area.extra.cs index e207909f68..5a89d29521 100644 --- a/UnitsNet/CustomCode/Quantities/Area.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Area.extra.cs @@ -45,7 +45,7 @@ public static Area FromCircleRadius(Length radius) /// Get from times . public static LinearDensity operator *(Area area, Density density) { - return LinearDensity.FromGramsPerCentimeter(area.SquareCentimeters * density.GramsPerCubicCentimeter); + return LinearDensity.FromKilogramsPerMeter(area.SquareMeters * density.KilogramsPerCubicMeter); } } } diff --git a/UnitsNet/CustomCode/Quantities/Density.extra.cs b/UnitsNet/CustomCode/Quantities/Density.extra.cs index 7e6dd55308..d20459ed7b 100644 --- a/UnitsNet/CustomCode/Quantities/Density.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Density.extra.cs @@ -74,7 +74,7 @@ public static Density FromMolarity(Molarity molarity, Mass molecularWeight) /// Get from times . public static LinearDensity operator *(Density density, Area area) { - return LinearDensity.FromGramsPerCentimeter(density.GramsPerCubicCentimeter * area.SquareCentimeters); + return LinearDensity.FromKilogramsPerMeter(density.KilogramsPerCubicMeter * area.SquareMeters); } } } diff --git a/UnitsNet/CustomCode/Quantities/LinearDensity.extra.cs b/UnitsNet/CustomCode/Quantities/LinearDensity.extra.cs index ad845b9e7c..06cc602b45 100644 --- a/UnitsNet/CustomCode/Quantities/LinearDensity.extra.cs +++ b/UnitsNet/CustomCode/Quantities/LinearDensity.extra.cs @@ -9,13 +9,13 @@ public partial struct LinearDensity /// Get from times . public static Density operator /(LinearDensity linearDensity, Area area) { - return Density.FromGramsPerCubicCentimeter(linearDensity.GramsPerCentimeter / area.SquareCentimeters); + return Density.FromKilogramsPerCubicMeter(linearDensity.KilogramsPerMeter / area.SquareMeters); } /// Get from times . public static Area operator /(LinearDensity linearDensity, Density density) { - return Area.FromSquareCentimeters(linearDensity.GramsPerCentimeter / density.GramsPerCubicCentimeter); + return Area.FromSquareMeters(linearDensity.KilogramsPerMeter / density.KilogramsPerCubicMeter); } } } From 09701551ad2361a0c81694ae9c7ef4392219cf2b Mon Sep 17 00:00:00 2001 From: Travis Bement Date: Fri, 8 May 2020 21:37:57 -0400 Subject: [PATCH 4/6] Add serialization support for multi-dimensional arrays --- .../UnitsNetJsonConverterTests.cs | 33 +++++++++ .../UnitsNetJsonDeserializationTests.cs | 51 +++++++++++--- .../UnitsNetJsonSerializationTests.cs | 33 +++++++++ .../UnitsNetJsonConverter.cs | 70 +++++++++++++++++-- 4 files changed, 171 insertions(+), 16 deletions(-) diff --git a/UnitsNet.Serialization.JsonNet.CompatibilityTests/UnitsNetJsonConverterTests.cs b/UnitsNet.Serialization.JsonNet.CompatibilityTests/UnitsNetJsonConverterTests.cs index 0a62526b9c..3a71fbc5fe 100644 --- a/UnitsNet.Serialization.JsonNet.CompatibilityTests/UnitsNetJsonConverterTests.cs +++ b/UnitsNet.Serialization.JsonNet.CompatibilityTests/UnitsNetJsonConverterTests.cs @@ -351,6 +351,39 @@ public void ArrayOfUnits_ExpectCorrectlyDeserialized() Assert.Equal(expected, result); } + [Fact(Skip = "Not supported in older versions of serialization")] + public void MultiDimArrayOfUnits_ExpectCorrectlyDeserialized() + { + Frequency[,] expected = { { Frequency.FromHertz(10), Frequency.FromHertz(10) }, { Frequency.FromHertz(10), Frequency.FromHertz(10) } }; + + string json = "[\n" + + " [\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " },\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " }\n" + + " ],\n" + + " [\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " },\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " }\n" + + " ]\n" + + "]"; + + Frequency[,] result = DeserializeObject(json); + + Assert.Equal(expected, result); + } + [Fact(Skip = "Not supported in older versions of serialization")] public void EmptyArray_ExpectCorrectlyDeserialized() { diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetJsonDeserializationTests.cs b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetJsonDeserializationTests.cs index 539da9100a..610f45c976 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetJsonDeserializationTests.cs +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetJsonDeserializationTests.cs @@ -188,21 +188,54 @@ public void ArrayOfUnits_ExpectCorrectlyDeserialized() Frequency[] expected = { Frequency.FromHertz(10), Frequency.FromHertz(10) }; var json = "[\n" + - " {\n" + - " \"Unit\": \"FrequencyUnit.Hertz\",\n" + - " \"Value\": 10.0\n" + - " },\n" + - " {\n" + - " \"Unit\": \"FrequencyUnit.Hertz\",\n" + - " \"Value\": 10.0\n" + - " }\n" + - "]"; + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " },\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " }\n" + + "]"; var result = DeserializeObject(json); Assert.Equal(expected, result); } + [Fact] + public void MultiDimArrayOfUnits_ExpectCorrectlyDeserialized() + { + Frequency[,] expected = { { Frequency.FromHertz(10), Frequency.FromHertz(10) }, { Frequency.FromHertz(10), Frequency.FromHertz(10) } }; + + var json = "[\n" + + " [\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " },\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " }\n" + + " ],\n" + + " [\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " },\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " }\n" + + " ]\n" + + "]"; + + var result = DeserializeObject(json); + + Assert.Equal(expected, result); + } + [Fact] public void EmptyArray_ExpectCorrectlyDeserialized() { diff --git a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetJsonSerializationTests.cs b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetJsonSerializationTests.cs index 7747a9bc9f..537b7d3c92 100644 --- a/UnitsNet.Serialization.JsonNet.Tests/UnitsNetJsonSerializationTests.cs +++ b/UnitsNet.Serialization.JsonNet.Tests/UnitsNetJsonSerializationTests.cs @@ -119,6 +119,39 @@ public void ArrayValue_ExpectJsonArray() Assert.Equal(expectedJson, json); } + [Fact] + public void MultiDimArrayValue_ExpectJsonArray() + { + Frequency[,] testObj = { { Frequency.FromHertz(10), Frequency.FromHertz(10) }, { Frequency.FromHertz(10), Frequency.FromHertz(10) } }; + + string expectedJson = "[\n" + + " [\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " },\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " }\n" + + " ],\n" + + " [\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " },\n" + + " {\n" + + " \"Unit\": \"FrequencyUnit.Hertz\",\n" + + " \"Value\": 10.0\n" + + " }\n" + + " ]\n" + + "]"; + + string json = SerializeObject(testObj); + + Assert.Equal(expectedJson, json); + } + [Fact] public void EmptyArrayValue_ExpectJsonArray() { diff --git a/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs b/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs index 217b76ea9e..512958cee6 100644 --- a/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs +++ b/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs @@ -44,15 +44,15 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist object obj = TryDeserializeIComparable(reader, serializer); if (obj is Array values) { - // Create array with the requested type, such as `Length[]` or `Frequency[]` - var arrayOfQuantities = Array.CreateInstance(objectType.GetElementType(), values.Length); + + // Create array with the requested type, such as `Length[]` or `Frequency[]` or multi-dimensional arrays like `Length[,]` or `Frequency[,,]` + var arrayOfQuantities = Array.CreateInstance(objectType.GetElementType(), LastIndex(values)); // Fill array with parsed quantities - var i = 0; - foreach (ValueUnit valueUnit in values) + var ind = FirstIndex(values); + while (ind != null) { - IQuantity quantity = ParseValueUnit(valueUnit); - arrayOfQuantities.SetValue(quantity, i++); + arrayOfQuantities.SetValue(values.GetValue(ind), ind); } return arrayOfQuantities; @@ -148,7 +148,16 @@ public override void WriteJson(JsonWriter writer, object obj, JsonSerializer ser } else if (obj is Array values) { - var results = values.Cast().Select(ToValueUnit); + + var results = Array.CreateInstance(typeof(ValueUnit), LastIndex(values)); + var ind = FirstIndex(values); + + while (ind != null) + { + results.SetValue((IQuantity)values.GetValue(ind), ind); + ind = NextIndex(results, ind); + } + serializer.Serialize(writer, results); } else if (obj is IQuantity quantity) @@ -231,5 +240,52 @@ protected virtual bool CanConvertNullable(Type objectType) } #endregion + + #region "MultiDimensional Array Helpers" + + private static Array ConvertArrayElements(Array array) + { + var ret = Array.CreateInstance(typeof(TResult), LastIndex(array)); + var ind = FirstIndex(array); + + while (ind != null) + { + ret.SetValue((TResult)array.GetValue(ind), ind); + ind = NextIndex(array, ind); + } + return ret; + } + + private static int[] FirstIndex(Array array) + { + return Enumerable.Range(0, array.Rank).Select(x => array.GetLowerBound(x)).ToArray(); + } + + private static int[] LastIndex(Array array) + { + return Enumerable.Range(0, array.Rank).Select(x => array.GetUpperBound(x) + 1).ToArray(); + } + + private static int[] NextIndex(Array array, int[] index) + { + for (var i = 0; i < index.Length; i++) + { + index[i] += 1; + + if (index[i] <= array.GetUpperBound(i)) + { + return index; + } + else + { + index[i] = array.GetLowerBound(i); + } + } + return null; + } + + #endregion + + } } From f48deed427c9f81d55149397e2c40db3c7a7f426 Mon Sep 17 00:00:00 2001 From: Travis Bement Date: Sun, 10 May 2020 20:46:09 -0400 Subject: [PATCH 5/6] Addressed comments from PR 782 --- .../Internal/MultiDimensionalArrayHelpers.cs | 89 +++++++++++++++++++ .../UnitsNetJsonConverter.cs | 61 ++----------- 2 files changed, 97 insertions(+), 53 deletions(-) create mode 100644 UnitsNet.Serialization.JsonNet/Internal/MultiDimensionalArrayHelpers.cs diff --git a/UnitsNet.Serialization.JsonNet/Internal/MultiDimensionalArrayHelpers.cs b/UnitsNet.Serialization.JsonNet/Internal/MultiDimensionalArrayHelpers.cs new file mode 100644 index 0000000000..5a675067c7 --- /dev/null +++ b/UnitsNet.Serialization.JsonNet/Internal/MultiDimensionalArrayHelpers.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UnitsNet.Serialization.JsonNet.Internal +{ + + /// + /// Helper class for working with and manipulating multi-dimension arrays based on their generic index. + /// + internal static class MultiDimensionalArrayHelpers + { + + /// + /// Returns a new array of same Rank and Length as but with each element converted to + /// + /// + /// + /// + public static Array ConvertArrayElements(Array array) + { + var ret = Array.CreateInstance(typeof(TResult), LastIndex(array)); + var ind = FirstIndex(array); + + while (ind != null) + { + ret.SetValue((TResult)array.GetValue(ind), ind); + ind = NextIndex(array, ind); + } + return ret; + } + + /// + /// Returns the index for the 'first' element in a multidimensional array. + /// + /// 'First' is defined as the for each rank of the + /// + /// E.g., for a zero-based 5x5x5 array this method would return [0, 0, 0]. + /// + /// + /// 1D integer array specifying the location of the first element in the multidimensional array + public static int[] FirstIndex(Array array) + { + return Enumerable.Range(0, array.Rank).Select(x => array.GetLowerBound(x)).ToArray(); + } + + /// + /// Returns the index for the 'last' element in a multidimensional array. + /// + /// 'Last' is defined as the for each rank of the + /// + /// E.g., for a zero-based 5x5x5 array this method would return [4, 4, 4]. + /// + /// + /// 1D integer array specifying the location of the last element in the multidimensional array + public static int[] LastIndex(Array array) + { + return Enumerable.Range(0, array.Rank).Select(x => array.GetUpperBound(x) + 1).ToArray(); + } + + /// + /// Returns the 'next' index after the specified multidimensional + /// + /// The 'next' index is determined by first looping through all elements in the first dimension of the array, then moving on to the next dimension and repeating + /// + /// + /// + /// Returns the index location of the next element in after as a 1D array of integers. If there is no next index, returns null + public static int[] NextIndex(Array array, int[] index) + { + for (var i = 0; i < index.Length; i++) + { + index[i] += 1; + + if (index[i] <= array.GetUpperBound(i)) + { + return index; + } + else + { + index[i] = array.GetLowerBound(i); + } + } + return null; + } + + } +} diff --git a/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs b/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs index 512958cee6..2782da5ed8 100644 --- a/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs +++ b/UnitsNet.Serialization.JsonNet/UnitsNetJsonConverter.cs @@ -6,6 +6,7 @@ using JetBrains.Annotations; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using UnitsNet.Serialization.JsonNet.Internal; namespace UnitsNet.Serialization.JsonNet { @@ -46,13 +47,13 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { // Create array with the requested type, such as `Length[]` or `Frequency[]` or multi-dimensional arrays like `Length[,]` or `Frequency[,,]` - var arrayOfQuantities = Array.CreateInstance(objectType.GetElementType(), LastIndex(values)); + var arrayOfQuantities = Array.CreateInstance(objectType.GetElementType(), MultiDimensionalArrayHelpers.LastIndex(values)); // Fill array with parsed quantities - var ind = FirstIndex(values); - while (ind != null) + int[] index = MultiDimensionalArrayHelpers.FirstIndex(values); + while (index != null) { - arrayOfQuantities.SetValue(values.GetValue(ind), ind); + arrayOfQuantities.SetValue(values.GetValue(index), index); } return arrayOfQuantities; @@ -149,13 +150,13 @@ public override void WriteJson(JsonWriter writer, object obj, JsonSerializer ser else if (obj is Array values) { - var results = Array.CreateInstance(typeof(ValueUnit), LastIndex(values)); - var ind = FirstIndex(values); + var results = Array.CreateInstance(typeof(ValueUnit), MultiDimensionalArrayHelpers.LastIndex(values)); + var ind = MultiDimensionalArrayHelpers.FirstIndex(values); while (ind != null) { results.SetValue((IQuantity)values.GetValue(ind), ind); - ind = NextIndex(results, ind); + ind = MultiDimensionalArrayHelpers.NextIndex(results, ind); } serializer.Serialize(writer, results); @@ -241,51 +242,5 @@ protected virtual bool CanConvertNullable(Type objectType) #endregion - #region "MultiDimensional Array Helpers" - - private static Array ConvertArrayElements(Array array) - { - var ret = Array.CreateInstance(typeof(TResult), LastIndex(array)); - var ind = FirstIndex(array); - - while (ind != null) - { - ret.SetValue((TResult)array.GetValue(ind), ind); - ind = NextIndex(array, ind); - } - return ret; - } - - private static int[] FirstIndex(Array array) - { - return Enumerable.Range(0, array.Rank).Select(x => array.GetLowerBound(x)).ToArray(); - } - - private static int[] LastIndex(Array array) - { - return Enumerable.Range(0, array.Rank).Select(x => array.GetUpperBound(x) + 1).ToArray(); - } - - private static int[] NextIndex(Array array, int[] index) - { - for (var i = 0; i < index.Length; i++) - { - index[i] += 1; - - if (index[i] <= array.GetUpperBound(i)) - { - return index; - } - else - { - index[i] = array.GetLowerBound(i); - } - } - return null; - } - - #endregion - - } } From f23dbf1cae67b8678188a7bb7b19e7e71a9e4686 Mon Sep 17 00:00:00 2001 From: Travis Bement Date: Wed, 13 May 2020 13:30:46 -0400 Subject: [PATCH 6/6] Add MassFlux Units combinations for kilograms and centimeter/millimeters --- Common/UnitDefinitions/MassFlux.json | 65 +++++++ .../NumberToMassFluxExtensionsTest.g.cs | 40 +++++ .../NumberToMassFluxExtensions.g.cs | 40 +++++ UnitsNet.Tests/CustomCode/MassFluxTests.cs | 13 ++ .../GeneratedCode/IQuantityTests.g.cs | 2 +- .../TestsBase/MassFluxTestsBase.g.cs | 162 ++++++++++++++++- .../GeneratedCode/Quantities/MassFlux.g.cs | 170 ++++++++++++++++++ .../GeneratedCode/UnitAbbreviationsCache.g.cs | 10 ++ .../GeneratedCode/Units/MassFluxUnit.g.cs | 10 ++ .../GeneratedCode/Quantities/MassFlux.g.cs | 170 ++++++++++++++++++ .../GeneratedCode/UnitAbbreviationsCache.g.cs | 10 ++ UnitsNet/GeneratedCode/UnitConverter.g.cs | 20 +++ .../GeneratedCode/Units/MassFluxUnit.g.cs | 10 ++ 13 files changed, 715 insertions(+), 7 deletions(-) diff --git a/Common/UnitDefinitions/MassFlux.json b/Common/UnitDefinitions/MassFlux.json index 91e2aafb44..45492311a3 100644 --- a/Common/UnitDefinitions/MassFlux.json +++ b/Common/UnitDefinitions/MassFlux.json @@ -20,6 +20,71 @@ "Abbreviations": [ "g·s⁻¹·m⁻²" ] } ] + }, + { + "SingularName": "GramPerSecondPerSquareCentimeter", + "PluralName": "GramsPerSecondPerSquareCentimeter", + "FromUnitToBaseFunc": "x/1e-1", + "FromBaseToUnitFunc": "x*1e-1", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g·s⁻¹·cm⁻²" ] + } + ] + }, + { + "SingularName": "GramPerSecondPerSquareMillimeter", + "PluralName": "GramsPerSecondPerSquareMillimeter", + "FromUnitToBaseFunc": "x/1e-3", + "FromBaseToUnitFunc": "x*1e-3", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g·s⁻¹·mm⁻²" ] + } + ] + }, + { + "SingularName": "GramPerHourPerSquareMeter", + "PluralName": "GramsPerHourPerSquareMeter", + "FromUnitToBaseFunc": "x/3.6e6", + "FromBaseToUnitFunc": "x*3.6e6", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g·h⁻¹·m⁻²" ] + } + ] + }, + { + "SingularName": "GramPerHourPerSquareCentimeter", + "PluralName": "GramsPerHourPerSquareCentimeter", + "FromUnitToBaseFunc": "x/3.6e2", + "FromBaseToUnitFunc": "x*3.6e2", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g·h⁻¹·cm⁻²" ] + } + ] + }, + { + "SingularName": "GramPerHourPerSquareMillimeter", + "PluralName": "GramsPerHourPerSquareMillimeter", + "FromUnitToBaseFunc": "x/3.6e0", + "FromBaseToUnitFunc": "x*3.6e0", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g·h⁻¹·mm⁻²" ] + } + ] } ] } diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMassFluxExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMassFluxExtensionsTest.g.cs index e87a915ee0..cab140f603 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMassFluxExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToMassFluxExtensionsTest.g.cs @@ -24,13 +24,53 @@ namespace UnitsNet.Tests { public class NumberToMassFluxExtensionsTests { + [Fact] + public void NumberToGramsPerHourPerSquareCentimeterTest() => + Assert.Equal(MassFlux.FromGramsPerHourPerSquareCentimeter(2), 2.GramsPerHourPerSquareCentimeter()); + + [Fact] + public void NumberToGramsPerHourPerSquareMeterTest() => + Assert.Equal(MassFlux.FromGramsPerHourPerSquareMeter(2), 2.GramsPerHourPerSquareMeter()); + + [Fact] + public void NumberToGramsPerHourPerSquareMillimeterTest() => + Assert.Equal(MassFlux.FromGramsPerHourPerSquareMillimeter(2), 2.GramsPerHourPerSquareMillimeter()); + + [Fact] + public void NumberToGramsPerSecondPerSquareCentimeterTest() => + Assert.Equal(MassFlux.FromGramsPerSecondPerSquareCentimeter(2), 2.GramsPerSecondPerSquareCentimeter()); + [Fact] public void NumberToGramsPerSecondPerSquareMeterTest() => Assert.Equal(MassFlux.FromGramsPerSecondPerSquareMeter(2), 2.GramsPerSecondPerSquareMeter()); + [Fact] + public void NumberToGramsPerSecondPerSquareMillimeterTest() => + Assert.Equal(MassFlux.FromGramsPerSecondPerSquareMillimeter(2), 2.GramsPerSecondPerSquareMillimeter()); + + [Fact] + public void NumberToKilogramsPerHourPerSquareCentimeterTest() => + Assert.Equal(MassFlux.FromKilogramsPerHourPerSquareCentimeter(2), 2.KilogramsPerHourPerSquareCentimeter()); + + [Fact] + public void NumberToKilogramsPerHourPerSquareMeterTest() => + Assert.Equal(MassFlux.FromKilogramsPerHourPerSquareMeter(2), 2.KilogramsPerHourPerSquareMeter()); + + [Fact] + public void NumberToKilogramsPerHourPerSquareMillimeterTest() => + Assert.Equal(MassFlux.FromKilogramsPerHourPerSquareMillimeter(2), 2.KilogramsPerHourPerSquareMillimeter()); + + [Fact] + public void NumberToKilogramsPerSecondPerSquareCentimeterTest() => + Assert.Equal(MassFlux.FromKilogramsPerSecondPerSquareCentimeter(2), 2.KilogramsPerSecondPerSquareCentimeter()); + [Fact] public void NumberToKilogramsPerSecondPerSquareMeterTest() => Assert.Equal(MassFlux.FromKilogramsPerSecondPerSquareMeter(2), 2.KilogramsPerSecondPerSquareMeter()); + [Fact] + public void NumberToKilogramsPerSecondPerSquareMillimeterTest() => + Assert.Equal(MassFlux.FromKilogramsPerSecondPerSquareMillimeter(2), 2.KilogramsPerSecondPerSquareMillimeter()); + } } diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToMassFluxExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToMassFluxExtensions.g.cs index 73d36eb37b..f98ff6dfaf 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToMassFluxExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToMassFluxExtensions.g.cs @@ -26,13 +26,53 @@ namespace UnitsNet.NumberExtensions.NumberToMassFlux /// public static class NumberToMassFluxExtensions { + /// + public static MassFlux GramsPerHourPerSquareCentimeter(this T value) => + MassFlux.FromGramsPerHourPerSquareCentimeter(Convert.ToDouble(value)); + + /// + public static MassFlux GramsPerHourPerSquareMeter(this T value) => + MassFlux.FromGramsPerHourPerSquareMeter(Convert.ToDouble(value)); + + /// + public static MassFlux GramsPerHourPerSquareMillimeter(this T value) => + MassFlux.FromGramsPerHourPerSquareMillimeter(Convert.ToDouble(value)); + + /// + public static MassFlux GramsPerSecondPerSquareCentimeter(this T value) => + MassFlux.FromGramsPerSecondPerSquareCentimeter(Convert.ToDouble(value)); + /// public static MassFlux GramsPerSecondPerSquareMeter(this T value) => MassFlux.FromGramsPerSecondPerSquareMeter(Convert.ToDouble(value)); + /// + public static MassFlux GramsPerSecondPerSquareMillimeter(this T value) => + MassFlux.FromGramsPerSecondPerSquareMillimeter(Convert.ToDouble(value)); + + /// + public static MassFlux KilogramsPerHourPerSquareCentimeter(this T value) => + MassFlux.FromKilogramsPerHourPerSquareCentimeter(Convert.ToDouble(value)); + + /// + public static MassFlux KilogramsPerHourPerSquareMeter(this T value) => + MassFlux.FromKilogramsPerHourPerSquareMeter(Convert.ToDouble(value)); + + /// + public static MassFlux KilogramsPerHourPerSquareMillimeter(this T value) => + MassFlux.FromKilogramsPerHourPerSquareMillimeter(Convert.ToDouble(value)); + + /// + public static MassFlux KilogramsPerSecondPerSquareCentimeter(this T value) => + MassFlux.FromKilogramsPerSecondPerSquareCentimeter(Convert.ToDouble(value)); + /// public static MassFlux KilogramsPerSecondPerSquareMeter(this T value) => MassFlux.FromKilogramsPerSecondPerSquareMeter(Convert.ToDouble(value)); + /// + public static MassFlux KilogramsPerSecondPerSquareMillimeter(this T value) => + MassFlux.FromKilogramsPerSecondPerSquareMillimeter(Convert.ToDouble(value)); + } } diff --git a/UnitsNet.Tests/CustomCode/MassFluxTests.cs b/UnitsNet.Tests/CustomCode/MassFluxTests.cs index e2dfa88e2f..148ed1af37 100644 --- a/UnitsNet.Tests/CustomCode/MassFluxTests.cs +++ b/UnitsNet.Tests/CustomCode/MassFluxTests.cs @@ -27,8 +27,21 @@ namespace UnitsNet.Tests.CustomCode public class MassFluxTests : MassFluxTestsBase { protected override double GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter => 1E3; + protected override double GramsPerSecondPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter => 1E-1; + protected override double GramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter => 1E-3; + + protected override double GramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter => 3.6E6; + protected override double GramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter => 3.6E2; + protected override double GramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter => 3.6E0; protected override double KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter => 1; + protected override double KilogramsPerSecondPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter => 1E-4; + protected override double KilogramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter => 1E-6; + + protected override double KilogramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter => 3.6E3; + protected override double KilogramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter => 3.6E-1; + protected override double KilogramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter => 3.6E-3; + [Fact] public void MassFluxDividedBySpeedEqualsDensity() diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index e1450bd0ea..2ddf119b00 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -95,7 +95,7 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, MassUnit.Tonne, Quantity.From(3, MassUnit.Tonne)); Assertion(3, MassConcentrationUnit.TonnePerCubicMillimeter, Quantity.From(3, MassConcentrationUnit.TonnePerCubicMillimeter)); Assertion(3, MassFlowUnit.TonnePerHour, Quantity.From(3, MassFlowUnit.TonnePerHour)); - Assertion(3, MassFluxUnit.KilogramPerSecondPerSquareMeter, Quantity.From(3, MassFluxUnit.KilogramPerSecondPerSquareMeter)); + Assertion(3, MassFluxUnit.KilogramPerSecondPerSquareMillimeter, Quantity.From(3, MassFluxUnit.KilogramPerSecondPerSquareMillimeter)); Assertion(3, MassFractionUnit.Percent, Quantity.From(3, MassFractionUnit.Percent)); Assertion(3, MassMomentOfInertiaUnit.TonneSquareMilimeter, Quantity.From(3, MassMomentOfInertiaUnit.TonneSquareMilimeter)); Assertion(3, MolarEnergyUnit.MegajoulePerMole, Quantity.From(3, MolarEnergyUnit.MegajoulePerMole)); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs index 3022df7cce..0a669c1bbe 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs @@ -36,12 +36,32 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class MassFluxTestsBase { + protected abstract double GramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter { get; } + protected abstract double GramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter { get; } + protected abstract double GramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter { get; } + protected abstract double GramsPerSecondPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter { get; } protected abstract double GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter { get; } + protected abstract double GramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter { get; } + protected abstract double KilogramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter { get; } + protected abstract double KilogramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter { get; } + protected abstract double KilogramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter { get; } + protected abstract double KilogramsPerSecondPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter { get; } protected abstract double KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter { get; } + protected abstract double KilogramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter { get; } // ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double GramsPerHourPerSquareCentimeterTolerance { get { return 1e-5; } } + protected virtual double GramsPerHourPerSquareMeterTolerance { get { return 1e-5; } } + protected virtual double GramsPerHourPerSquareMillimeterTolerance { get { return 1e-5; } } + protected virtual double GramsPerSecondPerSquareCentimeterTolerance { get { return 1e-5; } } protected virtual double GramsPerSecondPerSquareMeterTolerance { get { return 1e-5; } } + protected virtual double GramsPerSecondPerSquareMillimeterTolerance { get { return 1e-5; } } + protected virtual double KilogramsPerHourPerSquareCentimeterTolerance { get { return 1e-5; } } + protected virtual double KilogramsPerHourPerSquareMeterTolerance { get { return 1e-5; } } + protected virtual double KilogramsPerHourPerSquareMillimeterTolerance { get { return 1e-5; } } + protected virtual double KilogramsPerSecondPerSquareCentimeterTolerance { get { return 1e-5; } } protected virtual double KilogramsPerSecondPerSquareMeterTolerance { get { return 1e-5; } } + protected virtual double KilogramsPerSecondPerSquareMillimeterTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global [Fact] @@ -103,20 +123,70 @@ public void MassFlux_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() public void KilogramPerSecondPerSquareMeterToMassFluxUnits() { MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + AssertEx.EqualTolerance(GramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.GramsPerHourPerSquareCentimeter, GramsPerHourPerSquareCentimeterTolerance); + AssertEx.EqualTolerance(GramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.GramsPerHourPerSquareMeter, GramsPerHourPerSquareMeterTolerance); + AssertEx.EqualTolerance(GramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.GramsPerHourPerSquareMillimeter, GramsPerHourPerSquareMillimeterTolerance); + AssertEx.EqualTolerance(GramsPerSecondPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.GramsPerSecondPerSquareCentimeter, GramsPerSecondPerSquareCentimeterTolerance); AssertEx.EqualTolerance(GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.GramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(GramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.GramsPerSecondPerSquareMillimeter, GramsPerSecondPerSquareMillimeterTolerance); + AssertEx.EqualTolerance(KilogramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.KilogramsPerHourPerSquareCentimeter, KilogramsPerHourPerSquareCentimeterTolerance); + AssertEx.EqualTolerance(KilogramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.KilogramsPerHourPerSquareMeter, KilogramsPerHourPerSquareMeterTolerance); + AssertEx.EqualTolerance(KilogramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.KilogramsPerHourPerSquareMillimeter, KilogramsPerHourPerSquareMillimeterTolerance); + AssertEx.EqualTolerance(KilogramsPerSecondPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.KilogramsPerSecondPerSquareCentimeter, KilogramsPerSecondPerSquareCentimeterTolerance); AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.KilogramsPerSecondPerSquareMillimeter, KilogramsPerSecondPerSquareMillimeterTolerance); } [Fact] public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() { - var quantity00 = MassFlux.From(1, MassFluxUnit.GramPerSecondPerSquareMeter); - AssertEx.EqualTolerance(1, quantity00.GramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMeter, quantity00.Unit); + var quantity00 = MassFlux.From(1, MassFluxUnit.GramPerHourPerSquareCentimeter); + AssertEx.EqualTolerance(1, quantity00.GramsPerHourPerSquareCentimeter, GramsPerHourPerSquareCentimeterTolerance); + Assert.Equal(MassFluxUnit.GramPerHourPerSquareCentimeter, quantity00.Unit); - var quantity01 = MassFlux.From(1, MassFluxUnit.KilogramPerSecondPerSquareMeter); - AssertEx.EqualTolerance(1, quantity01.KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMeter, quantity01.Unit); + var quantity01 = MassFlux.From(1, MassFluxUnit.GramPerHourPerSquareMeter); + AssertEx.EqualTolerance(1, quantity01.GramsPerHourPerSquareMeter, GramsPerHourPerSquareMeterTolerance); + Assert.Equal(MassFluxUnit.GramPerHourPerSquareMeter, quantity01.Unit); + + var quantity02 = MassFlux.From(1, MassFluxUnit.GramPerHourPerSquareMillimeter); + AssertEx.EqualTolerance(1, quantity02.GramsPerHourPerSquareMillimeter, GramsPerHourPerSquareMillimeterTolerance); + Assert.Equal(MassFluxUnit.GramPerHourPerSquareMillimeter, quantity02.Unit); + + var quantity03 = MassFlux.From(1, MassFluxUnit.GramPerSecondPerSquareCentimeter); + AssertEx.EqualTolerance(1, quantity03.GramsPerSecondPerSquareCentimeter, GramsPerSecondPerSquareCentimeterTolerance); + Assert.Equal(MassFluxUnit.GramPerSecondPerSquareCentimeter, quantity03.Unit); + + var quantity04 = MassFlux.From(1, MassFluxUnit.GramPerSecondPerSquareMeter); + AssertEx.EqualTolerance(1, quantity04.GramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); + Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMeter, quantity04.Unit); + + var quantity05 = MassFlux.From(1, MassFluxUnit.GramPerSecondPerSquareMillimeter); + AssertEx.EqualTolerance(1, quantity05.GramsPerSecondPerSquareMillimeter, GramsPerSecondPerSquareMillimeterTolerance); + Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMillimeter, quantity05.Unit); + + var quantity06 = MassFlux.From(1, MassFluxUnit.KilogramPerHourPerSquareCentimeter); + AssertEx.EqualTolerance(1, quantity06.KilogramsPerHourPerSquareCentimeter, KilogramsPerHourPerSquareCentimeterTolerance); + Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareCentimeter, quantity06.Unit); + + var quantity07 = MassFlux.From(1, MassFluxUnit.KilogramPerHourPerSquareMeter); + AssertEx.EqualTolerance(1, quantity07.KilogramsPerHourPerSquareMeter, KilogramsPerHourPerSquareMeterTolerance); + Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMeter, quantity07.Unit); + + var quantity08 = MassFlux.From(1, MassFluxUnit.KilogramPerHourPerSquareMillimeter); + AssertEx.EqualTolerance(1, quantity08.KilogramsPerHourPerSquareMillimeter, KilogramsPerHourPerSquareMillimeterTolerance); + Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMillimeter, quantity08.Unit); + + var quantity09 = MassFlux.From(1, MassFluxUnit.KilogramPerSecondPerSquareCentimeter); + AssertEx.EqualTolerance(1, quantity09.KilogramsPerSecondPerSquareCentimeter, KilogramsPerSecondPerSquareCentimeterTolerance); + Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareCentimeter, quantity09.Unit); + + var quantity10 = MassFlux.From(1, MassFluxUnit.KilogramPerSecondPerSquareMeter); + AssertEx.EqualTolerance(1, quantity10.KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMeter, quantity10.Unit); + + var quantity11 = MassFlux.From(1, MassFluxUnit.KilogramPerSecondPerSquareMillimeter); + AssertEx.EqualTolerance(1, quantity11.KilogramsPerSecondPerSquareMillimeter, KilogramsPerSecondPerSquareMillimeterTolerance); + Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMillimeter, quantity11.Unit); } @@ -137,8 +207,18 @@ public void FromKilogramsPerSecondPerSquareMeter_WithNanValue_ThrowsArgumentExce public void As() { var kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + AssertEx.EqualTolerance(GramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.GramPerHourPerSquareCentimeter), GramsPerHourPerSquareCentimeterTolerance); + AssertEx.EqualTolerance(GramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.GramPerHourPerSquareMeter), GramsPerHourPerSquareMeterTolerance); + AssertEx.EqualTolerance(GramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.GramPerHourPerSquareMillimeter), GramsPerHourPerSquareMillimeterTolerance); + AssertEx.EqualTolerance(GramsPerSecondPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.GramPerSecondPerSquareCentimeter), GramsPerSecondPerSquareCentimeterTolerance); AssertEx.EqualTolerance(GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.GramPerSecondPerSquareMeter), GramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(GramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.GramPerSecondPerSquareMillimeter), GramsPerSecondPerSquareMillimeterTolerance); + AssertEx.EqualTolerance(KilogramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.KilogramPerHourPerSquareCentimeter), KilogramsPerHourPerSquareCentimeterTolerance); + AssertEx.EqualTolerance(KilogramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.KilogramPerHourPerSquareMeter), KilogramsPerHourPerSquareMeterTolerance); + AssertEx.EqualTolerance(KilogramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.KilogramPerHourPerSquareMillimeter), KilogramsPerHourPerSquareMillimeterTolerance); + AssertEx.EqualTolerance(KilogramsPerSecondPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.KilogramPerSecondPerSquareCentimeter), KilogramsPerSecondPerSquareCentimeterTolerance); AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.KilogramPerSecondPerSquareMeter), KilogramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.KilogramPerSecondPerSquareMillimeter), KilogramsPerSecondPerSquareMillimeterTolerance); } [Fact] @@ -146,21 +226,71 @@ public void ToUnit() { var kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + var gramperhourpersquarecentimeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.GramPerHourPerSquareCentimeter); + AssertEx.EqualTolerance(GramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, (double)gramperhourpersquarecentimeterQuantity.Value, GramsPerHourPerSquareCentimeterTolerance); + Assert.Equal(MassFluxUnit.GramPerHourPerSquareCentimeter, gramperhourpersquarecentimeterQuantity.Unit); + + var gramperhourpersquaremeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.GramPerHourPerSquareMeter); + AssertEx.EqualTolerance(GramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter, (double)gramperhourpersquaremeterQuantity.Value, GramsPerHourPerSquareMeterTolerance); + Assert.Equal(MassFluxUnit.GramPerHourPerSquareMeter, gramperhourpersquaremeterQuantity.Unit); + + var gramperhourpersquaremillimeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.GramPerHourPerSquareMillimeter); + AssertEx.EqualTolerance(GramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, (double)gramperhourpersquaremillimeterQuantity.Value, GramsPerHourPerSquareMillimeterTolerance); + Assert.Equal(MassFluxUnit.GramPerHourPerSquareMillimeter, gramperhourpersquaremillimeterQuantity.Unit); + + var grampersecondpersquarecentimeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.GramPerSecondPerSquareCentimeter); + AssertEx.EqualTolerance(GramsPerSecondPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, (double)grampersecondpersquarecentimeterQuantity.Value, GramsPerSecondPerSquareCentimeterTolerance); + Assert.Equal(MassFluxUnit.GramPerSecondPerSquareCentimeter, grampersecondpersquarecentimeterQuantity.Unit); + var grampersecondpersquaremeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.GramPerSecondPerSquareMeter); AssertEx.EqualTolerance(GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, (double)grampersecondpersquaremeterQuantity.Value, GramsPerSecondPerSquareMeterTolerance); Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMeter, grampersecondpersquaremeterQuantity.Unit); + var grampersecondpersquaremillimeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.GramPerSecondPerSquareMillimeter); + AssertEx.EqualTolerance(GramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, (double)grampersecondpersquaremillimeterQuantity.Value, GramsPerSecondPerSquareMillimeterTolerance); + Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMillimeter, grampersecondpersquaremillimeterQuantity.Unit); + + var kilogramperhourpersquarecentimeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.KilogramPerHourPerSquareCentimeter); + AssertEx.EqualTolerance(KilogramsPerHourPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, (double)kilogramperhourpersquarecentimeterQuantity.Value, KilogramsPerHourPerSquareCentimeterTolerance); + Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareCentimeter, kilogramperhourpersquarecentimeterQuantity.Unit); + + var kilogramperhourpersquaremeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.KilogramPerHourPerSquareMeter); + AssertEx.EqualTolerance(KilogramsPerHourPerSquareMeterInOneKilogramPerSecondPerSquareMeter, (double)kilogramperhourpersquaremeterQuantity.Value, KilogramsPerHourPerSquareMeterTolerance); + Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMeter, kilogramperhourpersquaremeterQuantity.Unit); + + var kilogramperhourpersquaremillimeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.KilogramPerHourPerSquareMillimeter); + AssertEx.EqualTolerance(KilogramsPerHourPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, (double)kilogramperhourpersquaremillimeterQuantity.Value, KilogramsPerHourPerSquareMillimeterTolerance); + Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMillimeter, kilogramperhourpersquaremillimeterQuantity.Unit); + + var kilogrampersecondpersquarecentimeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.KilogramPerSecondPerSquareCentimeter); + AssertEx.EqualTolerance(KilogramsPerSecondPerSquareCentimeterInOneKilogramPerSecondPerSquareMeter, (double)kilogrampersecondpersquarecentimeterQuantity.Value, KilogramsPerSecondPerSquareCentimeterTolerance); + Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareCentimeter, kilogrampersecondpersquarecentimeterQuantity.Unit); + var kilogrampersecondpersquaremeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.KilogramPerSecondPerSquareMeter); AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, (double)kilogrampersecondpersquaremeterQuantity.Value, KilogramsPerSecondPerSquareMeterTolerance); Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeterQuantity.Unit); + + var kilogrampersecondpersquaremillimeterQuantity = kilogrampersecondpersquaremeter.ToUnit(MassFluxUnit.KilogramPerSecondPerSquareMillimeter); + AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMillimeterInOneKilogramPerSecondPerSquareMeter, (double)kilogrampersecondpersquaremillimeterQuantity.Value, KilogramsPerSecondPerSquareMillimeterTolerance); + Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMillimeter, kilogrampersecondpersquaremillimeterQuantity.Unit); } [Fact] public void ConversionRoundTrip() { MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + AssertEx.EqualTolerance(1, MassFlux.FromGramsPerHourPerSquareCentimeter(kilogrampersecondpersquaremeter.GramsPerHourPerSquareCentimeter).KilogramsPerSecondPerSquareMeter, GramsPerHourPerSquareCentimeterTolerance); + AssertEx.EqualTolerance(1, MassFlux.FromGramsPerHourPerSquareMeter(kilogrampersecondpersquaremeter.GramsPerHourPerSquareMeter).KilogramsPerSecondPerSquareMeter, GramsPerHourPerSquareMeterTolerance); + AssertEx.EqualTolerance(1, MassFlux.FromGramsPerHourPerSquareMillimeter(kilogrampersecondpersquaremeter.GramsPerHourPerSquareMillimeter).KilogramsPerSecondPerSquareMeter, GramsPerHourPerSquareMillimeterTolerance); + AssertEx.EqualTolerance(1, MassFlux.FromGramsPerSecondPerSquareCentimeter(kilogrampersecondpersquaremeter.GramsPerSecondPerSquareCentimeter).KilogramsPerSecondPerSquareMeter, GramsPerSecondPerSquareCentimeterTolerance); AssertEx.EqualTolerance(1, MassFlux.FromGramsPerSecondPerSquareMeter(kilogrampersecondpersquaremeter.GramsPerSecondPerSquareMeter).KilogramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(1, MassFlux.FromGramsPerSecondPerSquareMillimeter(kilogrampersecondpersquaremeter.GramsPerSecondPerSquareMillimeter).KilogramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMillimeterTolerance); + AssertEx.EqualTolerance(1, MassFlux.FromKilogramsPerHourPerSquareCentimeter(kilogrampersecondpersquaremeter.KilogramsPerHourPerSquareCentimeter).KilogramsPerSecondPerSquareMeter, KilogramsPerHourPerSquareCentimeterTolerance); + AssertEx.EqualTolerance(1, MassFlux.FromKilogramsPerHourPerSquareMeter(kilogrampersecondpersquaremeter.KilogramsPerHourPerSquareMeter).KilogramsPerSecondPerSquareMeter, KilogramsPerHourPerSquareMeterTolerance); + AssertEx.EqualTolerance(1, MassFlux.FromKilogramsPerHourPerSquareMillimeter(kilogrampersecondpersquaremeter.KilogramsPerHourPerSquareMillimeter).KilogramsPerSecondPerSquareMeter, KilogramsPerHourPerSquareMillimeterTolerance); + AssertEx.EqualTolerance(1, MassFlux.FromKilogramsPerSecondPerSquareCentimeter(kilogrampersecondpersquaremeter.KilogramsPerSecondPerSquareCentimeter).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareCentimeterTolerance); AssertEx.EqualTolerance(1, MassFlux.FromKilogramsPerSecondPerSquareMeter(kilogrampersecondpersquaremeter.KilogramsPerSecondPerSquareMeter).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(1, MassFlux.FromKilogramsPerSecondPerSquareMillimeter(kilogrampersecondpersquaremeter.KilogramsPerSecondPerSquareMillimeter).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMillimeterTolerance); } [Fact] @@ -300,8 +430,18 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() var prevCulture = Thread.CurrentThread.CurrentUICulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); try { + Assert.Equal("1 g·h⁻¹·cm⁻²", new MassFlux(1, MassFluxUnit.GramPerHourPerSquareCentimeter).ToString()); + Assert.Equal("1 g·h⁻¹·m⁻²", new MassFlux(1, MassFluxUnit.GramPerHourPerSquareMeter).ToString()); + Assert.Equal("1 g·h⁻¹·mm⁻²", new MassFlux(1, MassFluxUnit.GramPerHourPerSquareMillimeter).ToString()); + Assert.Equal("1 g·s⁻¹·cm⁻²", new MassFlux(1, MassFluxUnit.GramPerSecondPerSquareCentimeter).ToString()); Assert.Equal("1 g·s⁻¹·m⁻²", new MassFlux(1, MassFluxUnit.GramPerSecondPerSquareMeter).ToString()); + Assert.Equal("1 g·s⁻¹·mm⁻²", new MassFlux(1, MassFluxUnit.GramPerSecondPerSquareMillimeter).ToString()); + Assert.Equal("1 kg·h⁻¹·cm⁻²", new MassFlux(1, MassFluxUnit.KilogramPerHourPerSquareCentimeter).ToString()); + Assert.Equal("1 kg·h⁻¹·m⁻²", new MassFlux(1, MassFluxUnit.KilogramPerHourPerSquareMeter).ToString()); + Assert.Equal("1 kg·h⁻¹·mm⁻²", new MassFlux(1, MassFluxUnit.KilogramPerHourPerSquareMillimeter).ToString()); + Assert.Equal("1 kg·s⁻¹·cm⁻²", new MassFlux(1, MassFluxUnit.KilogramPerSecondPerSquareCentimeter).ToString()); Assert.Equal("1 kg·s⁻¹·m⁻²", new MassFlux(1, MassFluxUnit.KilogramPerSecondPerSquareMeter).ToString()); + Assert.Equal("1 kg·s⁻¹·mm⁻²", new MassFlux(1, MassFluxUnit.KilogramPerSecondPerSquareMillimeter).ToString()); } finally { @@ -315,8 +455,18 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture // 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 g·h⁻¹·cm⁻²", new MassFlux(1, MassFluxUnit.GramPerHourPerSquareCentimeter).ToString(swedishCulture)); + Assert.Equal("1 g·h⁻¹·m⁻²", new MassFlux(1, MassFluxUnit.GramPerHourPerSquareMeter).ToString(swedishCulture)); + Assert.Equal("1 g·h⁻¹·mm⁻²", new MassFlux(1, MassFluxUnit.GramPerHourPerSquareMillimeter).ToString(swedishCulture)); + Assert.Equal("1 g·s⁻¹·cm⁻²", new MassFlux(1, MassFluxUnit.GramPerSecondPerSquareCentimeter).ToString(swedishCulture)); Assert.Equal("1 g·s⁻¹·m⁻²", new MassFlux(1, MassFluxUnit.GramPerSecondPerSquareMeter).ToString(swedishCulture)); + Assert.Equal("1 g·s⁻¹·mm⁻²", new MassFlux(1, MassFluxUnit.GramPerSecondPerSquareMillimeter).ToString(swedishCulture)); + Assert.Equal("1 kg·h⁻¹·cm⁻²", new MassFlux(1, MassFluxUnit.KilogramPerHourPerSquareCentimeter).ToString(swedishCulture)); + Assert.Equal("1 kg·h⁻¹·m⁻²", new MassFlux(1, MassFluxUnit.KilogramPerHourPerSquareMeter).ToString(swedishCulture)); + Assert.Equal("1 kg·h⁻¹·mm⁻²", new MassFlux(1, MassFluxUnit.KilogramPerHourPerSquareMillimeter).ToString(swedishCulture)); + Assert.Equal("1 kg·s⁻¹·cm⁻²", new MassFlux(1, MassFluxUnit.KilogramPerSecondPerSquareCentimeter).ToString(swedishCulture)); Assert.Equal("1 kg·s⁻¹·m⁻²", new MassFlux(1, MassFluxUnit.KilogramPerSecondPerSquareMeter).ToString(swedishCulture)); + Assert.Equal("1 kg·s⁻¹·mm⁻²", new MassFlux(1, MassFluxUnit.KilogramPerSecondPerSquareMillimeter).ToString(swedishCulture)); } [Fact] diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFlux.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFlux.g.cs index 96c5383064..048c017ae8 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFlux.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/MassFlux.g.cs @@ -155,16 +155,66 @@ private MassFlux(double value, MassFluxUnit unit) #region Conversion Properties + /// + /// Get MassFlux in GramsPerHourPerSquareCentimeter. + /// + public double GramsPerHourPerSquareCentimeter => As(MassFluxUnit.GramPerHourPerSquareCentimeter); + + /// + /// Get MassFlux in GramsPerHourPerSquareMeter. + /// + public double GramsPerHourPerSquareMeter => As(MassFluxUnit.GramPerHourPerSquareMeter); + + /// + /// Get MassFlux in GramsPerHourPerSquareMillimeter. + /// + public double GramsPerHourPerSquareMillimeter => As(MassFluxUnit.GramPerHourPerSquareMillimeter); + + /// + /// Get MassFlux in GramsPerSecondPerSquareCentimeter. + /// + public double GramsPerSecondPerSquareCentimeter => As(MassFluxUnit.GramPerSecondPerSquareCentimeter); + /// /// Get MassFlux in GramsPerSecondPerSquareMeter. /// public double GramsPerSecondPerSquareMeter => As(MassFluxUnit.GramPerSecondPerSquareMeter); + /// + /// Get MassFlux in GramsPerSecondPerSquareMillimeter. + /// + public double GramsPerSecondPerSquareMillimeter => As(MassFluxUnit.GramPerSecondPerSquareMillimeter); + + /// + /// Get MassFlux in KilogramsPerHourPerSquareCentimeter. + /// + public double KilogramsPerHourPerSquareCentimeter => As(MassFluxUnit.KilogramPerHourPerSquareCentimeter); + + /// + /// Get MassFlux in KilogramsPerHourPerSquareMeter. + /// + public double KilogramsPerHourPerSquareMeter => As(MassFluxUnit.KilogramPerHourPerSquareMeter); + + /// + /// Get MassFlux in KilogramsPerHourPerSquareMillimeter. + /// + public double KilogramsPerHourPerSquareMillimeter => As(MassFluxUnit.KilogramPerHourPerSquareMillimeter); + + /// + /// Get MassFlux in KilogramsPerSecondPerSquareCentimeter. + /// + public double KilogramsPerSecondPerSquareCentimeter => As(MassFluxUnit.KilogramPerSecondPerSquareCentimeter); + /// /// Get MassFlux in KilogramsPerSecondPerSquareMeter. /// public double KilogramsPerSecondPerSquareMeter => As(MassFluxUnit.KilogramPerSecondPerSquareMeter); + /// + /// Get MassFlux in KilogramsPerSecondPerSquareMillimeter. + /// + public double KilogramsPerSecondPerSquareMillimeter => As(MassFluxUnit.KilogramPerSecondPerSquareMillimeter); + #endregion #region Static Methods @@ -195,6 +245,46 @@ public static string GetAbbreviation(MassFluxUnit unit, [CanBeNull] string cultu #region Static Factory Methods + /// + /// Get MassFlux from GramsPerHourPerSquareCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromGramsPerHourPerSquareCentimeter(double gramsperhourpersquarecentimeter) + { + double value = (double) gramsperhourpersquarecentimeter; + return new MassFlux(value, MassFluxUnit.GramPerHourPerSquareCentimeter); + } + /// + /// Get MassFlux from GramsPerHourPerSquareMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromGramsPerHourPerSquareMeter(double gramsperhourpersquaremeter) + { + double value = (double) gramsperhourpersquaremeter; + return new MassFlux(value, MassFluxUnit.GramPerHourPerSquareMeter); + } + /// + /// Get MassFlux from GramsPerHourPerSquareMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromGramsPerHourPerSquareMillimeter(double gramsperhourpersquaremillimeter) + { + double value = (double) gramsperhourpersquaremillimeter; + return new MassFlux(value, MassFluxUnit.GramPerHourPerSquareMillimeter); + } + /// + /// Get MassFlux from GramsPerSecondPerSquareCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromGramsPerSecondPerSquareCentimeter(double gramspersecondpersquarecentimeter) + { + double value = (double) gramspersecondpersquarecentimeter; + return new MassFlux(value, MassFluxUnit.GramPerSecondPerSquareCentimeter); + } /// /// Get MassFlux from GramsPerSecondPerSquareMeter. /// @@ -206,6 +296,56 @@ public static MassFlux FromGramsPerSecondPerSquareMeter(double gramspersecondper return new MassFlux(value, MassFluxUnit.GramPerSecondPerSquareMeter); } /// + /// Get MassFlux from GramsPerSecondPerSquareMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromGramsPerSecondPerSquareMillimeter(double gramspersecondpersquaremillimeter) + { + double value = (double) gramspersecondpersquaremillimeter; + return new MassFlux(value, MassFluxUnit.GramPerSecondPerSquareMillimeter); + } + /// + /// Get MassFlux from KilogramsPerHourPerSquareCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromKilogramsPerHourPerSquareCentimeter(double kilogramsperhourpersquarecentimeter) + { + double value = (double) kilogramsperhourpersquarecentimeter; + return new MassFlux(value, MassFluxUnit.KilogramPerHourPerSquareCentimeter); + } + /// + /// Get MassFlux from KilogramsPerHourPerSquareMeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromKilogramsPerHourPerSquareMeter(double kilogramsperhourpersquaremeter) + { + double value = (double) kilogramsperhourpersquaremeter; + return new MassFlux(value, MassFluxUnit.KilogramPerHourPerSquareMeter); + } + /// + /// Get MassFlux from KilogramsPerHourPerSquareMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromKilogramsPerHourPerSquareMillimeter(double kilogramsperhourpersquaremillimeter) + { + double value = (double) kilogramsperhourpersquaremillimeter; + return new MassFlux(value, MassFluxUnit.KilogramPerHourPerSquareMillimeter); + } + /// + /// Get MassFlux from KilogramsPerSecondPerSquareCentimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromKilogramsPerSecondPerSquareCentimeter(double kilogramspersecondpersquarecentimeter) + { + double value = (double) kilogramspersecondpersquarecentimeter; + return new MassFlux(value, MassFluxUnit.KilogramPerSecondPerSquareCentimeter); + } + /// /// Get MassFlux from KilogramsPerSecondPerSquareMeter. /// /// If value is NaN or Infinity. @@ -215,6 +355,16 @@ public static MassFlux FromKilogramsPerSecondPerSquareMeter(double kilogramspers double value = (double) kilogramspersecondpersquaremeter; return new MassFlux(value, MassFluxUnit.KilogramPerSecondPerSquareMeter); } + /// + /// Get MassFlux from KilogramsPerSecondPerSquareMillimeter. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromKilogramsPerSecondPerSquareMillimeter(double kilogramspersecondpersquaremillimeter) + { + double value = (double) kilogramspersecondpersquaremillimeter; + return new MassFlux(value, MassFluxUnit.KilogramPerSecondPerSquareMillimeter); + } /// /// Dynamically convert from value and unit enum to . @@ -506,8 +656,18 @@ private double AsBaseUnit() { switch(Unit) { + case MassFluxUnit.GramPerHourPerSquareCentimeter: return _value/3.6e2; + case MassFluxUnit.GramPerHourPerSquareMeter: return _value/3.6e6; + case MassFluxUnit.GramPerHourPerSquareMillimeter: return _value/3.6e0; + case MassFluxUnit.GramPerSecondPerSquareCentimeter: return _value/1e-1; case MassFluxUnit.GramPerSecondPerSquareMeter: return _value/1e3; + case MassFluxUnit.GramPerSecondPerSquareMillimeter: return _value/1e-3; + case MassFluxUnit.KilogramPerHourPerSquareCentimeter: return (_value/3.6e2) * 1e3d; + case MassFluxUnit.KilogramPerHourPerSquareMeter: return (_value/3.6e6) * 1e3d; + case MassFluxUnit.KilogramPerHourPerSquareMillimeter: return (_value/3.6e0) * 1e3d; + case MassFluxUnit.KilogramPerSecondPerSquareCentimeter: return (_value/1e-1) * 1e3d; case MassFluxUnit.KilogramPerSecondPerSquareMeter: return (_value/1e3) * 1e3d; + case MassFluxUnit.KilogramPerSecondPerSquareMillimeter: return (_value/1e-3) * 1e3d; default: throw new NotImplementedException($"Can not convert {Unit} to base units."); } @@ -522,8 +682,18 @@ private double AsBaseNumericType(MassFluxUnit unit) switch(unit) { + case MassFluxUnit.GramPerHourPerSquareCentimeter: return baseUnitValue*3.6e2; + case MassFluxUnit.GramPerHourPerSquareMeter: return baseUnitValue*3.6e6; + case MassFluxUnit.GramPerHourPerSquareMillimeter: return baseUnitValue*3.6e0; + case MassFluxUnit.GramPerSecondPerSquareCentimeter: return baseUnitValue*1e-1; case MassFluxUnit.GramPerSecondPerSquareMeter: return baseUnitValue*1e3; + case MassFluxUnit.GramPerSecondPerSquareMillimeter: return baseUnitValue*1e-3; + case MassFluxUnit.KilogramPerHourPerSquareCentimeter: return (baseUnitValue*3.6e2) / 1e3d; + case MassFluxUnit.KilogramPerHourPerSquareMeter: return (baseUnitValue*3.6e6) / 1e3d; + case MassFluxUnit.KilogramPerHourPerSquareMillimeter: return (baseUnitValue*3.6e0) / 1e3d; + case MassFluxUnit.KilogramPerSecondPerSquareCentimeter: return (baseUnitValue*1e-1) / 1e3d; case MassFluxUnit.KilogramPerSecondPerSquareMeter: return (baseUnitValue*1e3) / 1e3d; + case MassFluxUnit.KilogramPerSecondPerSquareMillimeter: return (baseUnitValue*1e-3) / 1e3d; default: throw new NotImplementedException($"Can not convert {Unit} to {unit}."); } diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs index cbc975a5d7..b2f20ab258 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -809,8 +809,18 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.ShortTonPerHour, new string[]{"short tn/h"}), ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.TonnePerDay, new string[]{"t/d"}), ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.TonnePerHour, new string[]{"t/h"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerHourPerSquareCentimeter, new string[]{"g·h⁻¹·cm⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerHourPerSquareMeter, new string[]{"g·h⁻¹·m⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerHourPerSquareMillimeter, new string[]{"g·h⁻¹·mm⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerSecondPerSquareCentimeter, new string[]{"g·s⁻¹·cm⁻²"}), ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerSecondPerSquareMeter, new string[]{"g·s⁻¹·m⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerSecondPerSquareMillimeter, new string[]{"g·s⁻¹·mm⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerHourPerSquareCentimeter, new string[]{"kg·h⁻¹·cm⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerHourPerSquareMeter, new string[]{"kg·h⁻¹·m⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerHourPerSquareMillimeter, new string[]{"kg·h⁻¹·mm⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerSecondPerSquareCentimeter, new string[]{"kg·s⁻¹·cm⁻²"}), ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerSecondPerSquareMeter, new string[]{"kg·s⁻¹·m⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerSecondPerSquareMillimeter, new string[]{"kg·s⁻¹·mm⁻²"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerGram, new string[]{"cg/g"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerKilogram, new string[]{"cg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerGram, new string[]{"dag/g"}), diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFluxUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFluxUnit.g.cs index b8f38d2101..2ec7d5a857 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFluxUnit.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassFluxUnit.g.cs @@ -26,8 +26,18 @@ namespace UnitsNet.Units public enum MassFluxUnit { Undefined = 0, + GramPerHourPerSquareCentimeter, + GramPerHourPerSquareMeter, + GramPerHourPerSquareMillimeter, + GramPerSecondPerSquareCentimeter, GramPerSecondPerSquareMeter, + GramPerSecondPerSquareMillimeter, + KilogramPerHourPerSquareCentimeter, + KilogramPerHourPerSquareMeter, + KilogramPerHourPerSquareMillimeter, + KilogramPerSecondPerSquareCentimeter, KilogramPerSecondPerSquareMeter, + KilogramPerSecondPerSquareMillimeter, } #pragma warning restore 1591 diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs index 3b7bd4c264..23c7d68268 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs @@ -50,8 +50,18 @@ static MassFlux() Info = new QuantityInfo(QuantityType.MassFlux, new UnitInfo[] { + new UnitInfo(MassFluxUnit.GramPerHourPerSquareCentimeter, BaseUnits.Undefined), + new UnitInfo(MassFluxUnit.GramPerHourPerSquareMeter, BaseUnits.Undefined), + new UnitInfo(MassFluxUnit.GramPerHourPerSquareMillimeter, BaseUnits.Undefined), + new UnitInfo(MassFluxUnit.GramPerSecondPerSquareCentimeter, BaseUnits.Undefined), new UnitInfo(MassFluxUnit.GramPerSecondPerSquareMeter, BaseUnits.Undefined), + new UnitInfo(MassFluxUnit.GramPerSecondPerSquareMillimeter, BaseUnits.Undefined), + new UnitInfo(MassFluxUnit.KilogramPerHourPerSquareCentimeter, BaseUnits.Undefined), + new UnitInfo(MassFluxUnit.KilogramPerHourPerSquareMeter, BaseUnits.Undefined), + new UnitInfo(MassFluxUnit.KilogramPerHourPerSquareMillimeter, BaseUnits.Undefined), + new UnitInfo(MassFluxUnit.KilogramPerSecondPerSquareCentimeter, BaseUnits.Undefined), new UnitInfo(MassFluxUnit.KilogramPerSecondPerSquareMeter, BaseUnits.Undefined), + new UnitInfo(MassFluxUnit.KilogramPerSecondPerSquareMillimeter, BaseUnits.Undefined), }, BaseUnit, Zero, BaseDimensions); } @@ -164,16 +174,66 @@ public MassFlux(double value, UnitSystem unitSystem) #region Conversion Properties + /// + /// Get MassFlux in GramsPerHourPerSquareCentimeter. + /// + public double GramsPerHourPerSquareCentimeter => As(MassFluxUnit.GramPerHourPerSquareCentimeter); + + /// + /// Get MassFlux in GramsPerHourPerSquareMeter. + /// + public double GramsPerHourPerSquareMeter => As(MassFluxUnit.GramPerHourPerSquareMeter); + + /// + /// Get MassFlux in GramsPerHourPerSquareMillimeter. + /// + public double GramsPerHourPerSquareMillimeter => As(MassFluxUnit.GramPerHourPerSquareMillimeter); + + /// + /// Get MassFlux in GramsPerSecondPerSquareCentimeter. + /// + public double GramsPerSecondPerSquareCentimeter => As(MassFluxUnit.GramPerSecondPerSquareCentimeter); + /// /// Get MassFlux in GramsPerSecondPerSquareMeter. /// public double GramsPerSecondPerSquareMeter => As(MassFluxUnit.GramPerSecondPerSquareMeter); + /// + /// Get MassFlux in GramsPerSecondPerSquareMillimeter. + /// + public double GramsPerSecondPerSquareMillimeter => As(MassFluxUnit.GramPerSecondPerSquareMillimeter); + + /// + /// Get MassFlux in KilogramsPerHourPerSquareCentimeter. + /// + public double KilogramsPerHourPerSquareCentimeter => As(MassFluxUnit.KilogramPerHourPerSquareCentimeter); + + /// + /// Get MassFlux in KilogramsPerHourPerSquareMeter. + /// + public double KilogramsPerHourPerSquareMeter => As(MassFluxUnit.KilogramPerHourPerSquareMeter); + + /// + /// Get MassFlux in KilogramsPerHourPerSquareMillimeter. + /// + public double KilogramsPerHourPerSquareMillimeter => As(MassFluxUnit.KilogramPerHourPerSquareMillimeter); + + /// + /// Get MassFlux in KilogramsPerSecondPerSquareCentimeter. + /// + public double KilogramsPerSecondPerSquareCentimeter => As(MassFluxUnit.KilogramPerSecondPerSquareCentimeter); + /// /// Get MassFlux in KilogramsPerSecondPerSquareMeter. /// public double KilogramsPerSecondPerSquareMeter => As(MassFluxUnit.KilogramPerSecondPerSquareMeter); + /// + /// Get MassFlux in KilogramsPerSecondPerSquareMillimeter. + /// + public double KilogramsPerSecondPerSquareMillimeter => As(MassFluxUnit.KilogramPerSecondPerSquareMillimeter); + #endregion #region Static Methods @@ -203,6 +263,42 @@ public static string GetAbbreviation(MassFluxUnit unit, [CanBeNull] IFormatProvi #region Static Factory Methods + /// + /// Get MassFlux from GramsPerHourPerSquareCentimeter. + /// + /// If value is NaN or Infinity. + public static MassFlux FromGramsPerHourPerSquareCentimeter(QuantityValue gramsperhourpersquarecentimeter) + { + double value = (double) gramsperhourpersquarecentimeter; + return new MassFlux(value, MassFluxUnit.GramPerHourPerSquareCentimeter); + } + /// + /// Get MassFlux from GramsPerHourPerSquareMeter. + /// + /// If value is NaN or Infinity. + public static MassFlux FromGramsPerHourPerSquareMeter(QuantityValue gramsperhourpersquaremeter) + { + double value = (double) gramsperhourpersquaremeter; + return new MassFlux(value, MassFluxUnit.GramPerHourPerSquareMeter); + } + /// + /// Get MassFlux from GramsPerHourPerSquareMillimeter. + /// + /// If value is NaN or Infinity. + public static MassFlux FromGramsPerHourPerSquareMillimeter(QuantityValue gramsperhourpersquaremillimeter) + { + double value = (double) gramsperhourpersquaremillimeter; + return new MassFlux(value, MassFluxUnit.GramPerHourPerSquareMillimeter); + } + /// + /// Get MassFlux from GramsPerSecondPerSquareCentimeter. + /// + /// If value is NaN or Infinity. + public static MassFlux FromGramsPerSecondPerSquareCentimeter(QuantityValue gramspersecondpersquarecentimeter) + { + double value = (double) gramspersecondpersquarecentimeter; + return new MassFlux(value, MassFluxUnit.GramPerSecondPerSquareCentimeter); + } /// /// Get MassFlux from GramsPerSecondPerSquareMeter. /// @@ -213,6 +309,51 @@ public static MassFlux FromGramsPerSecondPerSquareMeter(QuantityValue gramsperse return new MassFlux(value, MassFluxUnit.GramPerSecondPerSquareMeter); } /// + /// Get MassFlux from GramsPerSecondPerSquareMillimeter. + /// + /// If value is NaN or Infinity. + public static MassFlux FromGramsPerSecondPerSquareMillimeter(QuantityValue gramspersecondpersquaremillimeter) + { + double value = (double) gramspersecondpersquaremillimeter; + return new MassFlux(value, MassFluxUnit.GramPerSecondPerSquareMillimeter); + } + /// + /// Get MassFlux from KilogramsPerHourPerSquareCentimeter. + /// + /// If value is NaN or Infinity. + public static MassFlux FromKilogramsPerHourPerSquareCentimeter(QuantityValue kilogramsperhourpersquarecentimeter) + { + double value = (double) kilogramsperhourpersquarecentimeter; + return new MassFlux(value, MassFluxUnit.KilogramPerHourPerSquareCentimeter); + } + /// + /// Get MassFlux from KilogramsPerHourPerSquareMeter. + /// + /// If value is NaN or Infinity. + public static MassFlux FromKilogramsPerHourPerSquareMeter(QuantityValue kilogramsperhourpersquaremeter) + { + double value = (double) kilogramsperhourpersquaremeter; + return new MassFlux(value, MassFluxUnit.KilogramPerHourPerSquareMeter); + } + /// + /// Get MassFlux from KilogramsPerHourPerSquareMillimeter. + /// + /// If value is NaN or Infinity. + public static MassFlux FromKilogramsPerHourPerSquareMillimeter(QuantityValue kilogramsperhourpersquaremillimeter) + { + double value = (double) kilogramsperhourpersquaremillimeter; + return new MassFlux(value, MassFluxUnit.KilogramPerHourPerSquareMillimeter); + } + /// + /// Get MassFlux from KilogramsPerSecondPerSquareCentimeter. + /// + /// If value is NaN or Infinity. + public static MassFlux FromKilogramsPerSecondPerSquareCentimeter(QuantityValue kilogramspersecondpersquarecentimeter) + { + double value = (double) kilogramspersecondpersquarecentimeter; + return new MassFlux(value, MassFluxUnit.KilogramPerSecondPerSquareCentimeter); + } + /// /// Get MassFlux from KilogramsPerSecondPerSquareMeter. /// /// If value is NaN or Infinity. @@ -221,6 +362,15 @@ public static MassFlux FromKilogramsPerSecondPerSquareMeter(QuantityValue kilogr double value = (double) kilogramspersecondpersquaremeter; return new MassFlux(value, MassFluxUnit.KilogramPerSecondPerSquareMeter); } + /// + /// Get MassFlux from KilogramsPerSecondPerSquareMillimeter. + /// + /// If value is NaN or Infinity. + public static MassFlux FromKilogramsPerSecondPerSquareMillimeter(QuantityValue kilogramspersecondpersquaremillimeter) + { + double value = (double) kilogramspersecondpersquaremillimeter; + return new MassFlux(value, MassFluxUnit.KilogramPerSecondPerSquareMillimeter); + } /// /// Dynamically convert from value and unit enum to . @@ -650,8 +800,18 @@ private double GetValueInBaseUnit() { switch(Unit) { + case MassFluxUnit.GramPerHourPerSquareCentimeter: return _value/3.6e2; + case MassFluxUnit.GramPerHourPerSquareMeter: return _value/3.6e6; + case MassFluxUnit.GramPerHourPerSquareMillimeter: return _value/3.6e0; + case MassFluxUnit.GramPerSecondPerSquareCentimeter: return _value/1e-1; case MassFluxUnit.GramPerSecondPerSquareMeter: return _value/1e3; + case MassFluxUnit.GramPerSecondPerSquareMillimeter: return _value/1e-3; + case MassFluxUnit.KilogramPerHourPerSquareCentimeter: return (_value/3.6e2) * 1e3d; + case MassFluxUnit.KilogramPerHourPerSquareMeter: return (_value/3.6e6) * 1e3d; + case MassFluxUnit.KilogramPerHourPerSquareMillimeter: return (_value/3.6e0) * 1e3d; + case MassFluxUnit.KilogramPerSecondPerSquareCentimeter: return (_value/1e-1) * 1e3d; case MassFluxUnit.KilogramPerSecondPerSquareMeter: return (_value/1e3) * 1e3d; + case MassFluxUnit.KilogramPerSecondPerSquareMillimeter: return (_value/1e-3) * 1e3d; default: throw new NotImplementedException($"Can not convert {Unit} to base units."); } @@ -677,8 +837,18 @@ private double GetValueAs(MassFluxUnit unit) switch(unit) { + case MassFluxUnit.GramPerHourPerSquareCentimeter: return baseUnitValue*3.6e2; + case MassFluxUnit.GramPerHourPerSquareMeter: return baseUnitValue*3.6e6; + case MassFluxUnit.GramPerHourPerSquareMillimeter: return baseUnitValue*3.6e0; + case MassFluxUnit.GramPerSecondPerSquareCentimeter: return baseUnitValue*1e-1; case MassFluxUnit.GramPerSecondPerSquareMeter: return baseUnitValue*1e3; + case MassFluxUnit.GramPerSecondPerSquareMillimeter: return baseUnitValue*1e-3; + case MassFluxUnit.KilogramPerHourPerSquareCentimeter: return (baseUnitValue*3.6e2) / 1e3d; + case MassFluxUnit.KilogramPerHourPerSquareMeter: return (baseUnitValue*3.6e6) / 1e3d; + case MassFluxUnit.KilogramPerHourPerSquareMillimeter: return (baseUnitValue*3.6e0) / 1e3d; + case MassFluxUnit.KilogramPerSecondPerSquareCentimeter: return (baseUnitValue*1e-1) / 1e3d; case MassFluxUnit.KilogramPerSecondPerSquareMeter: return (baseUnitValue*1e3) / 1e3d; + case MassFluxUnit.KilogramPerSecondPerSquareMillimeter: return (baseUnitValue*1e-3) / 1e3d; default: throw new NotImplementedException($"Can not convert {Unit} to {unit}."); } diff --git a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs index a6ede7f36e..776eebbf75 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -809,8 +809,18 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.ShortTonPerHour, new string[]{"short tn/h"}), ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.TonnePerDay, new string[]{"t/d"}), ("en-US", typeof(MassFlowUnit), (int)MassFlowUnit.TonnePerHour, new string[]{"t/h"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerHourPerSquareCentimeter, new string[]{"g·h⁻¹·cm⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerHourPerSquareMeter, new string[]{"g·h⁻¹·m⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerHourPerSquareMillimeter, new string[]{"g·h⁻¹·mm⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerSecondPerSquareCentimeter, new string[]{"g·s⁻¹·cm⁻²"}), ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerSecondPerSquareMeter, new string[]{"g·s⁻¹·m⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.GramPerSecondPerSquareMillimeter, new string[]{"g·s⁻¹·mm⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerHourPerSquareCentimeter, new string[]{"kg·h⁻¹·cm⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerHourPerSquareMeter, new string[]{"kg·h⁻¹·m⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerHourPerSquareMillimeter, new string[]{"kg·h⁻¹·mm⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerSecondPerSquareCentimeter, new string[]{"kg·s⁻¹·cm⁻²"}), ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerSecondPerSquareMeter, new string[]{"kg·s⁻¹·m⁻²"}), + ("en-US", typeof(MassFluxUnit), (int)MassFluxUnit.KilogramPerSecondPerSquareMillimeter, new string[]{"kg·s⁻¹·mm⁻²"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerGram, new string[]{"cg/g"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.CentigramPerKilogram, new string[]{"cg/kg"}), ("en-US", typeof(MassFractionUnit), (int)MassFractionUnit.DecagramPerGram, new string[]{"dag/g"}), diff --git a/UnitsNet/GeneratedCode/UnitConverter.g.cs b/UnitsNet/GeneratedCode/UnitConverter.g.cs index 62fe6a292e..6a850d2cb6 100644 --- a/UnitsNet/GeneratedCode/UnitConverter.g.cs +++ b/UnitsNet/GeneratedCode/UnitConverter.g.cs @@ -1253,9 +1253,29 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(MassFlowUnit.TonnePerDay, MassFlow.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(MassFlow.BaseUnit, MassFlowUnit.TonnePerHour, q => q.ToUnit(MassFlowUnit.TonnePerHour)); unitConverter.SetConversionFunction(MassFlowUnit.TonnePerHour, MassFlow.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFluxUnit.GramPerHourPerSquareCentimeter, q => q.ToUnit(MassFluxUnit.GramPerHourPerSquareCentimeter)); + unitConverter.SetConversionFunction(MassFluxUnit.GramPerHourPerSquareCentimeter, MassFlux.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFluxUnit.GramPerHourPerSquareMeter, q => q.ToUnit(MassFluxUnit.GramPerHourPerSquareMeter)); + unitConverter.SetConversionFunction(MassFluxUnit.GramPerHourPerSquareMeter, MassFlux.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFluxUnit.GramPerHourPerSquareMillimeter, q => q.ToUnit(MassFluxUnit.GramPerHourPerSquareMillimeter)); + unitConverter.SetConversionFunction(MassFluxUnit.GramPerHourPerSquareMillimeter, MassFlux.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFluxUnit.GramPerSecondPerSquareCentimeter, q => q.ToUnit(MassFluxUnit.GramPerSecondPerSquareCentimeter)); + unitConverter.SetConversionFunction(MassFluxUnit.GramPerSecondPerSquareCentimeter, MassFlux.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFluxUnit.GramPerSecondPerSquareMeter, q => q.ToUnit(MassFluxUnit.GramPerSecondPerSquareMeter)); unitConverter.SetConversionFunction(MassFluxUnit.GramPerSecondPerSquareMeter, MassFlux.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFluxUnit.GramPerSecondPerSquareMillimeter, q => q.ToUnit(MassFluxUnit.GramPerSecondPerSquareMillimeter)); + unitConverter.SetConversionFunction(MassFluxUnit.GramPerSecondPerSquareMillimeter, MassFlux.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFluxUnit.KilogramPerHourPerSquareCentimeter, q => q.ToUnit(MassFluxUnit.KilogramPerHourPerSquareCentimeter)); + unitConverter.SetConversionFunction(MassFluxUnit.KilogramPerHourPerSquareCentimeter, MassFlux.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFluxUnit.KilogramPerHourPerSquareMeter, q => q.ToUnit(MassFluxUnit.KilogramPerHourPerSquareMeter)); + unitConverter.SetConversionFunction(MassFluxUnit.KilogramPerHourPerSquareMeter, MassFlux.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFluxUnit.KilogramPerHourPerSquareMillimeter, q => q.ToUnit(MassFluxUnit.KilogramPerHourPerSquareMillimeter)); + unitConverter.SetConversionFunction(MassFluxUnit.KilogramPerHourPerSquareMillimeter, MassFlux.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFluxUnit.KilogramPerSecondPerSquareCentimeter, q => q.ToUnit(MassFluxUnit.KilogramPerSecondPerSquareCentimeter)); + unitConverter.SetConversionFunction(MassFluxUnit.KilogramPerSecondPerSquareCentimeter, MassFlux.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFlux.BaseUnit, q => q); + unitConverter.SetConversionFunction(MassFlux.BaseUnit, MassFluxUnit.KilogramPerSecondPerSquareMillimeter, q => q.ToUnit(MassFluxUnit.KilogramPerSecondPerSquareMillimeter)); + unitConverter.SetConversionFunction(MassFluxUnit.KilogramPerSecondPerSquareMillimeter, MassFlux.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(MassFraction.BaseUnit, MassFractionUnit.CentigramPerGram, q => q.ToUnit(MassFractionUnit.CentigramPerGram)); unitConverter.SetConversionFunction(MassFractionUnit.CentigramPerGram, MassFraction.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(MassFraction.BaseUnit, MassFractionUnit.CentigramPerKilogram, q => q.ToUnit(MassFractionUnit.CentigramPerKilogram)); diff --git a/UnitsNet/GeneratedCode/Units/MassFluxUnit.g.cs b/UnitsNet/GeneratedCode/Units/MassFluxUnit.g.cs index b8f38d2101..2ec7d5a857 100644 --- a/UnitsNet/GeneratedCode/Units/MassFluxUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/MassFluxUnit.g.cs @@ -26,8 +26,18 @@ namespace UnitsNet.Units public enum MassFluxUnit { Undefined = 0, + GramPerHourPerSquareCentimeter, + GramPerHourPerSquareMeter, + GramPerHourPerSquareMillimeter, + GramPerSecondPerSquareCentimeter, GramPerSecondPerSquareMeter, + GramPerSecondPerSquareMillimeter, + KilogramPerHourPerSquareCentimeter, + KilogramPerHourPerSquareMeter, + KilogramPerHourPerSquareMillimeter, + KilogramPerSecondPerSquareCentimeter, KilogramPerSecondPerSquareMeter, + KilogramPerSecondPerSquareMillimeter, } #pragma warning restore 1591