From c28c5c4550464a275e49babe17ba870e88f3d11d Mon Sep 17 00:00:00 2001 From: Go Date: Tue, 9 Jan 2018 14:11:38 -0600 Subject: [PATCH 1/2] Add Mass Flux Add Mass Flux unit definition Also added operators with Mass Flux' relation to Density, Speed, Area, and Mass Flow. --- UnitsNet.Tests/CustomCode/AreaTests.cs | 7 + UnitsNet.Tests/CustomCode/DensityTests.cs | 7 + UnitsNet.Tests/CustomCode/MassFlowTests.cs | 14 + UnitsNet.Tests/CustomCode/MassFluxTests.cs | 73 ++ UnitsNet.Tests/CustomCode/SpeedTests.cs | 7 + .../GeneratedCode/MassFluxTestsBase.g.cs | 185 +++++ UnitsNet/CustomCode/Quantities/Area.extra.cs | 5 + .../CustomCode/Quantities/Density.extra.cs | 5 + .../CustomCode/Quantities/MassFlow.extra.cs | 10 + .../CustomCode/Quantities/MassFlux.extra.cs | 53 ++ UnitsNet/CustomCode/Quantities/Speed.extra.cs | 5 + .../Number/NumberToMassFluxExtensions.g.cs | 117 +++ .../GeneratedCode/Quantities/MassFlux.g.cs | 724 ++++++++++++++++++ UnitsNet/GeneratedCode/QuantityType.g.cs | 1 + .../GeneratedCode/UnitSystem.Default.g.cs | 14 + .../GeneratedCode/Units/MassFluxUnit.g.cs | 48 ++ UnitsNet/UnitDefinitions/MassFlux.json | 20 + 17 files changed, 1295 insertions(+) create mode 100644 UnitsNet.Tests/CustomCode/MassFluxTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/MassFluxTestsBase.g.cs create mode 100644 UnitsNet/CustomCode/Quantities/MassFlux.extra.cs create mode 100644 UnitsNet/GeneratedCode/Extensions/Number/NumberToMassFluxExtensions.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/MassFluxUnit.g.cs create mode 100644 UnitsNet/UnitDefinitions/MassFlux.json diff --git a/UnitsNet.Tests/CustomCode/AreaTests.cs b/UnitsNet.Tests/CustomCode/AreaTests.cs index e642ca98db..b53b11ecd3 100644 --- a/UnitsNet.Tests/CustomCode/AreaTests.cs +++ b/UnitsNet.Tests/CustomCode/AreaTests.cs @@ -56,5 +56,12 @@ public void AreaDividedByLengthEqualsLength() Length length = Area.FromSquareMeters(50)/Length.FromMeters(5); Assert.Equal(length, Length.FromMeters(10)); } + + [Fact] + public void AreaTimesMassFluxEqualsMassFlow() + { + MassFlow massFlow = Area.FromSquareMeters(20) * MassFlux.FromKilogramsPerSecondPerSquareMeter(2); + Assert.Equal(massFlow, MassFlow.FromKilogramsPerSecond(40)); + } } } diff --git a/UnitsNet.Tests/CustomCode/DensityTests.cs b/UnitsNet.Tests/CustomCode/DensityTests.cs index ebbbaec0a0..6e7bffa029 100644 --- a/UnitsNet.Tests/CustomCode/DensityTests.cs +++ b/UnitsNet.Tests/CustomCode/DensityTests.cs @@ -132,5 +132,12 @@ public void ExpectDensityConvertedToMolarityCorrectly() var molarity = density.ToMolarity(mw).MolesPerCubicMeter; AssertEx.EqualTolerance(1026.98355, molarity, KilogramsPerCubicMeterTolerance); } + + [Fact] + public void DensityTimesSpeedEqualsMassFlux() + { + MassFlux massFlux = Density.FromKilogramsPerCubicMeter(20) * Speed.FromMetersPerSecond(2); + Assert.Equal(massFlux, MassFlux.FromKilogramsPerSecondPerSquareMeter(40)); + } } } \ No newline at end of file diff --git a/UnitsNet.Tests/CustomCode/MassFlowTests.cs b/UnitsNet.Tests/CustomCode/MassFlowTests.cs index 769f9bce4b..aa67eb779d 100644 --- a/UnitsNet.Tests/CustomCode/MassFlowTests.cs +++ b/UnitsNet.Tests/CustomCode/MassFlowTests.cs @@ -102,5 +102,19 @@ public void MassFlowTimesSpecificEnergyEqualsPower() Power power = MassFlow.FromKilogramsPerSecond(20.0) * SpecificEnergy.FromJoulesPerKilogram(10.0); Assert.Equal(200, power.Watts); } + + [Fact] + public void MassFlowDividedByAreaEqualsMassFlux() + { + MassFlux massFlux = MassFlow.FromKilogramsPerSecond(20) / Area.FromSquareMeters(2); + Assert.Equal(10, massFlux.KilogramsPerSecondPerSquareMeter); + } + + [Fact] + public void MassFlowDividedByMassFluxEqualsArea() + { + Area area = MassFlow.FromKilogramsPerSecond(20) / MassFlux.FromKilogramsPerSecondPerSquareMeter(2); + Assert.Equal(10, area.SquareMeters); + } } } \ No newline at end of file diff --git a/UnitsNet.Tests/CustomCode/MassFluxTests.cs b/UnitsNet.Tests/CustomCode/MassFluxTests.cs new file mode 100644 index 0000000000..d666b13ae9 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/MassFluxTests.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated (once) by \generate-code.bat, but will not be +// regenerated when it already exists. The purpose of creating this file is to make +// it easier to remember to implement all the unit conversion test cases. +// +// Whenever a new unit is added to this quantity and \generate-code.bat is run, +// the base test class will get a new abstract property and cause a compile error +// in this derived class, reminding the developer to implement the test case +// for the new unit. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyUnit.extra.cs files to add code to generated quantities. +// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using Xunit; + +namespace UnitsNet.Tests.CustomCode +{ + public class MassFluxTests : MassFluxTestsBase + { + protected override double GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter => 1E3; + + protected override double KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter => 1; + + [Fact] + public void MassFluxDividedBySpeedEqualsDensity() + { + Density density = MassFlux.FromKilogramsPerSecondPerSquareMeter(20) / Speed.FromMetersPerSecond(2); + Assert.Equal(density, Density.FromKilogramsPerCubicMeter(10)); + } + + [Fact] + public void MassFluxDividedByDensityEqualsSpeed() + { + Speed speed = MassFlux.FromKilogramsPerSecondPerSquareMeter(20) / Density.FromKilogramsPerCubicMeter(2); + Assert.Equal(speed, Speed.FromMetersPerSecond(10)); + } + + [Fact] + public void MassFluxTimesAreaEqualsMassFlow() + { + MassFlow massFlow = MassFlux.FromKilogramsPerSecondPerSquareMeter(20) * Area.FromSquareMeters(2); + Assert.Equal(massFlow, MassFlow.FromKilogramsPerSecond(40)); + } + } +} diff --git a/UnitsNet.Tests/CustomCode/SpeedTests.cs b/UnitsNet.Tests/CustomCode/SpeedTests.cs index c4cdd74ef9..93a66be68b 100644 --- a/UnitsNet.Tests/CustomCode/SpeedTests.cs +++ b/UnitsNet.Tests/CustomCode/SpeedTests.cs @@ -160,5 +160,12 @@ public void SpeedTimesSpeedEqualsSpecificEnergy() SpecificEnergy length = Speed.FromMetersPerSecond(2) * Speed.FromMetersPerSecond(20); Assert.Equal(length, SpecificEnergy.FromJoulesPerKilogram(40)); } + + [Fact] + public void SpeedTimesDensityEqualsMassFlux() + { + MassFlux massFlux = Speed.FromMetersPerSecond(20) * Density.FromKilogramsPerCubicMeter(2); + Assert.Equal(massFlux, MassFlux.FromKilogramsPerSecondPerSquareMeter(40)); + } } } diff --git a/UnitsNet.Tests/GeneratedCode/MassFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MassFluxTestsBase.g.cs new file mode 100644 index 0000000000..74e78e0da0 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/MassFluxTestsBase.g.cs @@ -0,0 +1,185 @@ +//------------------------------------------------------------------------------ +// +// 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\MyUnit.extra.cs files to add code to generated quantities. +// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using 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 MassFlux. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class MassFluxTestsBase + { + protected abstract double GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter { get; } + protected abstract double KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double GramsPerSecondPerSquareMeterTolerance { get { return 1e-5; } } + protected virtual double KilogramsPerSecondPerSquareMeterTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void KilogramPerSecondPerSquareMeterToMassFluxUnits() + { + MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + AssertEx.EqualTolerance(GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.GramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + } + + [Fact] + public void FromValueAndUnit() + { + AssertEx.EqualTolerance(1, MassFlux.From(1, MassFluxUnit.GramPerSecondPerSquareMeter).GramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(1, MassFlux.From(1, MassFluxUnit.KilogramPerSecondPerSquareMeter).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + } + + [Fact] + public void As() + { + var kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + AssertEx.EqualTolerance(GramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.GramPerSecondPerSquareMeter), GramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(KilogramsPerSecondPerSquareMeterInOneKilogramPerSecondPerSquareMeter, kilogrampersecondpersquaremeter.As(MassFluxUnit.KilogramPerSecondPerSquareMeter), KilogramsPerSecondPerSquareMeterTolerance); + } + + [Fact] + public void ConversionRoundTrip() + { + MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + AssertEx.EqualTolerance(1, MassFlux.FromGramsPerSecondPerSquareMeter(kilogrampersecondpersquaremeter.GramsPerSecondPerSquareMeter).KilogramsPerSecondPerSquareMeter, GramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(1, MassFlux.FromKilogramsPerSecondPerSquareMeter(kilogrampersecondpersquaremeter.KilogramsPerSecondPerSquareMeter).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + MassFlux v = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + AssertEx.EqualTolerance(-1, -v.KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(2, (MassFlux.FromKilogramsPerSecondPerSquareMeter(3)-v).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(2, (v + v).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(10, (v*10).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(10, (10*v).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(2, (MassFlux.FromKilogramsPerSecondPerSquareMeter(10)/5).KilogramsPerSecondPerSquareMeter, KilogramsPerSecondPerSquareMeterTolerance); + AssertEx.EqualTolerance(2, MassFlux.FromKilogramsPerSecondPerSquareMeter(10)/MassFlux.FromKilogramsPerSecondPerSquareMeter(5), KilogramsPerSecondPerSquareMeterTolerance); + } + + [Fact] + public void ComparisonOperators() + { + MassFlux oneKilogramPerSecondPerSquareMeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + MassFlux twoKilogramsPerSecondPerSquareMeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(2); + + Assert.True(oneKilogramPerSecondPerSquareMeter < twoKilogramsPerSecondPerSquareMeter); + Assert.True(oneKilogramPerSecondPerSquareMeter <= twoKilogramsPerSecondPerSquareMeter); + Assert.True(twoKilogramsPerSecondPerSquareMeter > oneKilogramPerSecondPerSquareMeter); + Assert.True(twoKilogramsPerSecondPerSquareMeter >= oneKilogramPerSecondPerSquareMeter); + + Assert.False(oneKilogramPerSecondPerSquareMeter > twoKilogramsPerSecondPerSquareMeter); + Assert.False(oneKilogramPerSecondPerSquareMeter >= twoKilogramsPerSecondPerSquareMeter); + Assert.False(twoKilogramsPerSecondPerSquareMeter < oneKilogramPerSecondPerSquareMeter); + Assert.False(twoKilogramsPerSecondPerSquareMeter <= oneKilogramPerSecondPerSquareMeter); + } + + [Fact] + public void CompareToIsImplemented() + { + MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + Assert.Equal(0, kilogrampersecondpersquaremeter.CompareTo(kilogrampersecondpersquaremeter)); + Assert.True(kilogrampersecondpersquaremeter.CompareTo(MassFlux.Zero) > 0); + Assert.True(MassFlux.Zero.CompareTo(kilogrampersecondpersquaremeter) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + Assert.Throws(() => kilogrampersecondpersquaremeter.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + Assert.Throws(() => kilogrampersecondpersquaremeter.CompareTo(null)); + } + + + [Fact] + public void EqualityOperators() + { + MassFlux a = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + MassFlux b = MassFlux.FromKilogramsPerSecondPerSquareMeter(2); + +// ReSharper disable EqualExpressionComparison + Assert.True(a == a); + Assert.True(a != b); + + Assert.False(a == b); + Assert.False(a != a); +// ReSharper restore EqualExpressionComparison + } + + [Fact] + public void EqualsIsImplemented() + { + MassFlux v = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + Assert.True(v.Equals(MassFlux.FromKilogramsPerSecondPerSquareMeter(1), MassFlux.FromKilogramsPerSecondPerSquareMeter(KilogramsPerSecondPerSquareMeterTolerance))); + Assert.False(v.Equals(MassFlux.Zero, MassFlux.FromKilogramsPerSecondPerSquareMeter(KilogramsPerSecondPerSquareMeterTolerance))); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + Assert.False(kilogrampersecondpersquaremeter.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + MassFlux kilogrampersecondpersquaremeter = MassFlux.FromKilogramsPerSecondPerSquareMeter(1); + Assert.False(kilogrampersecondpersquaremeter.Equals(null)); + } + } +} diff --git a/UnitsNet/CustomCode/Quantities/Area.extra.cs b/UnitsNet/CustomCode/Quantities/Area.extra.cs index 0cbd5edeb6..018f2e1760 100644 --- a/UnitsNet/CustomCode/Quantities/Area.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Area.extra.cs @@ -36,6 +36,11 @@ public partial struct Area { return Length.FromMeters(area.SquareMeters / length.Meters); } + + public static MassFlow operator *(Area area, MassFlux massFlux) + { + return MassFlow.FromGramsPerSecond(area.SquareMeters * massFlux.GramsPerSecondPerSquareMeter); + } #endif } } \ No newline at end of file diff --git a/UnitsNet/CustomCode/Quantities/Density.extra.cs b/UnitsNet/CustomCode/Quantities/Density.extra.cs index 65bd353dc3..487e0d35b7 100644 --- a/UnitsNet/CustomCode/Quantities/Density.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Density.extra.cs @@ -61,6 +61,11 @@ public static Molarity ToMolarity(Density density, Mass molecularWeight) { return DynamicViscosity.FromNewtonSecondsPerMeterSquared(kinematicViscosity.SquareMetersPerSecond * density.KilogramsPerCubicMeter); } + + public static MassFlux operator *(Density density, Speed speed) + { + return MassFlux.FromKilogramsPerSecondPerSquareMeter(density.KilogramsPerCubicMeter * speed.MetersPerSecond); + } #endif } } \ No newline at end of file diff --git a/UnitsNet/CustomCode/Quantities/MassFlow.extra.cs b/UnitsNet/CustomCode/Quantities/MassFlow.extra.cs index 1c516ee8ce..80cfbac30c 100644 --- a/UnitsNet/CustomCode/Quantities/MassFlow.extra.cs +++ b/UnitsNet/CustomCode/Quantities/MassFlow.extra.cs @@ -70,6 +70,16 @@ public partial struct MassFlow { return Power.FromWatts(massFlow.KilogramsPerSecond * specificEnergy.JoulesPerKilogram); } + + public static MassFlux operator /(MassFlow massFlow, Area area) + { + return MassFlux.FromKilogramsPerSecondPerSquareMeter(massFlow.KilogramsPerSecond / area.SquareMeters); + } + + public static Area operator /(MassFlow massFlow, MassFlux massFlux) + { + return Area.FromSquareMeters(massFlow.KilogramsPerSecond / massFlux.KilogramsPerSecondPerSquareMeter); + } #endif } } \ No newline at end of file diff --git a/UnitsNet/CustomCode/Quantities/MassFlux.extra.cs b/UnitsNet/CustomCode/Quantities/MassFlux.extra.cs new file mode 100644 index 0000000000..97ac20384a --- /dev/null +++ b/UnitsNet/CustomCode/Quantities/MassFlux.extra.cs @@ -0,0 +1,53 @@ +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#if !WINDOWS_UWP +using System; + +#endif + +namespace UnitsNet +{ + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class MassFlux +#else + public partial struct MassFlux +#endif + { +#if !WINDOWS_UWP + public static Density operator /(MassFlux massFlux, Speed speed) + { + return Density.FromKilogramsPerCubicMeter(massFlux.KilogramsPerSecondPerSquareMeter / speed.MetersPerSecond); + } + public static Speed operator /(MassFlux massFlux, Density density) + { + return Speed.FromMetersPerSecond(massFlux.KilogramsPerSecondPerSquareMeter / density.KilogramsPerCubicMeter); + } + public static MassFlow operator *(MassFlux massFlux, Area area) + { + return MassFlow.FromGramsPerSecond(massFlux.GramsPerSecondPerSquareMeter * area.SquareMeters); + } +#endif + } +} diff --git a/UnitsNet/CustomCode/Quantities/Speed.extra.cs b/UnitsNet/CustomCode/Quantities/Speed.extra.cs index ad02c0b06d..fbd91571c1 100644 --- a/UnitsNet/CustomCode/Quantities/Speed.extra.cs +++ b/UnitsNet/CustomCode/Quantities/Speed.extra.cs @@ -76,6 +76,11 @@ public partial struct Speed { return SpecificEnergy.FromJoulesPerKilogram(left.MetersPerSecond * right.MetersPerSecond); } + + public static MassFlux operator *(Speed speed, Density density) + { + return MassFlux.FromKilogramsPerSecondPerSquareMeter(speed.MetersPerSecond * density.KilogramsPerCubicMeter); + } #endif } } \ No newline at end of file diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToMassFluxExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToMassFluxExtensions.g.cs new file mode 100644 index 0000000000..b5e1e630c9 --- /dev/null +++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToMassFluxExtensions.g.cs @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +// +// 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\MyUnit.extra.cs files to add code to generated quantities. +// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; + +// Windows Runtime Component does not support extension methods and method overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP +namespace UnitsNet.Extensions.NumberToMassFlux +{ + public static class NumberToMassFluxExtensions + { + #region GramPerSecondPerSquareMeter + + /// + public static MassFlux GramsPerSecondPerSquareMeter(this int value) => MassFlux.FromGramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux? GramsPerSecondPerSquareMeter(this int? value) => MassFlux.FromGramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux GramsPerSecondPerSquareMeter(this long value) => MassFlux.FromGramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux? GramsPerSecondPerSquareMeter(this long? value) => MassFlux.FromGramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux GramsPerSecondPerSquareMeter(this double value) => MassFlux.FromGramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux? GramsPerSecondPerSquareMeter(this double? value) => MassFlux.FromGramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux GramsPerSecondPerSquareMeter(this float value) => MassFlux.FromGramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux? GramsPerSecondPerSquareMeter(this float? value) => MassFlux.FromGramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux GramsPerSecondPerSquareMeter(this decimal value) => MassFlux.FromGramsPerSecondPerSquareMeter(Convert.ToDouble(value)); + + /// + public static MassFlux? GramsPerSecondPerSquareMeter(this decimal? value) => MassFlux.FromGramsPerSecondPerSquareMeter(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region KilogramPerSecondPerSquareMeter + + /// + public static MassFlux KilogramsPerSecondPerSquareMeter(this int value) => MassFlux.FromKilogramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux? KilogramsPerSecondPerSquareMeter(this int? value) => MassFlux.FromKilogramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux KilogramsPerSecondPerSquareMeter(this long value) => MassFlux.FromKilogramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux? KilogramsPerSecondPerSquareMeter(this long? value) => MassFlux.FromKilogramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux KilogramsPerSecondPerSquareMeter(this double value) => MassFlux.FromKilogramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux? KilogramsPerSecondPerSquareMeter(this double? value) => MassFlux.FromKilogramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux KilogramsPerSecondPerSquareMeter(this float value) => MassFlux.FromKilogramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux? KilogramsPerSecondPerSquareMeter(this float? value) => MassFlux.FromKilogramsPerSecondPerSquareMeter(value); + + /// + public static MassFlux KilogramsPerSecondPerSquareMeter(this decimal value) => MassFlux.FromKilogramsPerSecondPerSquareMeter(Convert.ToDouble(value)); + + /// + public static MassFlux? KilogramsPerSecondPerSquareMeter(this decimal? value) => MassFlux.FromKilogramsPerSecondPerSquareMeter(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + } +} +#endif diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs new file mode 100644 index 0000000000..3aba1ebeff --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs @@ -0,0 +1,724 @@ +//------------------------------------------------------------------------------ +// +// 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\MyUnit.extra.cs files to add code to generated quantities. +// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// Mass flux is the mass flow rate per unit area. + /// + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class MassFlux +#else + public partial struct MassFlux : IComparable, IComparable +#endif + { + /// + /// Base unit of MassFlux. + /// + private readonly double _kilogramsPerSecondPerSquareMeter; + + // Windows Runtime Component requires a default constructor +#if WINDOWS_UWP + public MassFlux() : this(0) + { + } +#endif + + public MassFlux(double kilogramspersecondpersquaremeter) + { + _kilogramsPerSecondPerSquareMeter = Convert.ToDouble(kilogramspersecondpersquaremeter); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods +#if WINDOWS_UWP + private +#else + public +#endif + MassFlux(long kilogramspersecondpersquaremeter) + { + _kilogramsPerSecondPerSquareMeter = Convert.ToDouble(kilogramspersecondpersquaremeter); + } + + // 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 + // Windows Runtime Component does not support decimal type +#if WINDOWS_UWP + private +#else + public +#endif + MassFlux(decimal kilogramspersecondpersquaremeter) + { + _kilogramsPerSecondPerSquareMeter = Convert.ToDouble(kilogramspersecondpersquaremeter); + } + + #region Properties + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType => QuantityType.MassFlux; + + /// + /// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value. + /// + public static MassFluxUnit BaseUnit + { + get { return MassFluxUnit.KilogramPerSecondPerSquareMeter; } + } + + /// + /// All units of measurement for the MassFlux quantity. + /// + public static MassFluxUnit[] Units { get; } = Enum.GetValues(typeof(MassFluxUnit)).Cast().ToArray(); + + /// + /// Get MassFlux in GramsPerSecondPerSquareMeter. + /// + public double GramsPerSecondPerSquareMeter + { + get { return _kilogramsPerSecondPerSquareMeter*1e3; } + } + + /// + /// Get MassFlux in KilogramsPerSecondPerSquareMeter. + /// + public double KilogramsPerSecondPerSquareMeter + { + get { return (_kilogramsPerSecondPerSquareMeter*1e3) / 1e3d; } + } + + #endregion + + #region Static + + public static MassFlux Zero + { + get { return new MassFlux(); } + } + + /// + /// Get MassFlux from GramsPerSecondPerSquareMeter. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromGramsPerSecondPerSquareMeter(double gramspersecondpersquaremeter) + { + double value = (double) gramspersecondpersquaremeter; + return new MassFlux(value/1e3); + } +#else + public static MassFlux FromGramsPerSecondPerSquareMeter(QuantityValue gramspersecondpersquaremeter) + { + double value = (double) gramspersecondpersquaremeter; + return new MassFlux((value/1e3)); + } +#endif + + /// + /// Get MassFlux from KilogramsPerSecondPerSquareMeter. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static MassFlux FromKilogramsPerSecondPerSquareMeter(double kilogramspersecondpersquaremeter) + { + double value = (double) kilogramspersecondpersquaremeter; + return new MassFlux((value/1e3) * 1e3d); + } +#else + public static MassFlux FromKilogramsPerSecondPerSquareMeter(QuantityValue kilogramspersecondpersquaremeter) + { + double value = (double) kilogramspersecondpersquaremeter; + return new MassFlux(((value/1e3) * 1e3d)); + } +#endif + + // Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + /// + /// Get nullable MassFlux from nullable GramsPerSecondPerSquareMeter. + /// + public static MassFlux? FromGramsPerSecondPerSquareMeter(QuantityValue? gramspersecondpersquaremeter) + { + if (gramspersecondpersquaremeter.HasValue) + { + return FromGramsPerSecondPerSquareMeter(gramspersecondpersquaremeter.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable MassFlux from nullable KilogramsPerSecondPerSquareMeter. + /// + public static MassFlux? FromKilogramsPerSecondPerSquareMeter(QuantityValue? kilogramspersecondpersquaremeter) + { + if (kilogramspersecondpersquaremeter.HasValue) + { + return FromKilogramsPerSecondPerSquareMeter(kilogramspersecondpersquaremeter.Value); + } + else + { + return null; + } + } + +#endif + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// MassFlux unit value. +#if WINDOWS_UWP + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static MassFlux From(double value, MassFluxUnit fromUnit) +#else + public static MassFlux From(QuantityValue value, MassFluxUnit fromUnit) +#endif + { + switch (fromUnit) + { + case MassFluxUnit.GramPerSecondPerSquareMeter: + return FromGramsPerSecondPerSquareMeter(value); + case MassFluxUnit.KilogramPerSecondPerSquareMeter: + return FromKilogramsPerSecondPerSquareMeter(value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + + // Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// MassFlux unit value. + public static MassFlux? From(QuantityValue? value, MassFluxUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case MassFluxUnit.GramPerSecondPerSquareMeter: + return FromGramsPerSecondPerSquareMeter(value.Value); + case MassFluxUnit.KilogramPerSecondPerSquareMeter: + return FromKilogramsPerSecondPerSquareMeter(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } +#endif + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + [UsedImplicitly] + public static string GetAbbreviation(MassFluxUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Culture to use for localization. Defaults to Thread.CurrentUICulture. + /// Unit abbreviation string. + [UsedImplicitly] + public static string GetAbbreviation(MassFluxUnit unit, [CanBeNull] Culture culture) + { + return UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit); + } + + #endregion + + #region Arithmetic Operators + + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static MassFlux operator -(MassFlux right) + { + return new MassFlux(-right._kilogramsPerSecondPerSquareMeter); + } + + public static MassFlux operator +(MassFlux left, MassFlux right) + { + return new MassFlux(left._kilogramsPerSecondPerSquareMeter + right._kilogramsPerSecondPerSquareMeter); + } + + public static MassFlux operator -(MassFlux left, MassFlux right) + { + return new MassFlux(left._kilogramsPerSecondPerSquareMeter - right._kilogramsPerSecondPerSquareMeter); + } + + public static MassFlux operator *(double left, MassFlux right) + { + return new MassFlux(left*right._kilogramsPerSecondPerSquareMeter); + } + + public static MassFlux operator *(MassFlux left, double right) + { + return new MassFlux(left._kilogramsPerSecondPerSquareMeter*(double)right); + } + + public static MassFlux operator /(MassFlux left, double right) + { + return new MassFlux(left._kilogramsPerSecondPerSquareMeter/(double)right); + } + + public static double operator /(MassFlux left, MassFlux right) + { + return Convert.ToDouble(left._kilogramsPerSecondPerSquareMeter/right._kilogramsPerSecondPerSquareMeter); + } +#endif + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is MassFlux)) throw new ArgumentException("Expected type MassFlux.", "obj"); + return CompareTo((MassFlux) obj); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods +#if WINDOWS_UWP + internal +#else + public +#endif + int CompareTo(MassFlux other) + { + return _kilogramsPerSecondPerSquareMeter.CompareTo(other._kilogramsPerSecondPerSquareMeter); + } + + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static bool operator <=(MassFlux left, MassFlux right) + { + return left._kilogramsPerSecondPerSquareMeter <= right._kilogramsPerSecondPerSquareMeter; + } + + public static bool operator >=(MassFlux left, MassFlux right) + { + return left._kilogramsPerSecondPerSquareMeter >= right._kilogramsPerSecondPerSquareMeter; + } + + public static bool operator <(MassFlux left, MassFlux right) + { + return left._kilogramsPerSecondPerSquareMeter < right._kilogramsPerSecondPerSquareMeter; + } + + public static bool operator >(MassFlux left, MassFlux right) + { + return left._kilogramsPerSecondPerSquareMeter > right._kilogramsPerSecondPerSquareMeter; + } + + [Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")] + public static bool operator ==(MassFlux left, MassFlux right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._kilogramsPerSecondPerSquareMeter == right._kilogramsPerSecondPerSquareMeter; + } + + [Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")] + public static bool operator !=(MassFlux left, MassFlux right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._kilogramsPerSecondPerSquareMeter != right._kilogramsPerSecondPerSquareMeter; + } +#endif + + [Obsolete("It is not safe to compare equality due to using System.Double as the internal representation. It is very easy to get slightly different values due to floating point operations. Instead use Equals(other, maxError) to provide the max allowed error.")] + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return _kilogramsPerSecondPerSquareMeter.Equals(((MassFlux) obj)._kilogramsPerSecondPerSquareMeter); + } + + /// + /// Compare equality to another MassFlux by specifying a max allowed difference. + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// Other quantity to compare to. + /// Max error allowed. + /// True if the difference between the two values is not greater than the specified max. + public bool Equals(MassFlux other, MassFlux maxError) + { + return Math.Abs(_kilogramsPerSecondPerSquareMeter - other._kilogramsPerSecondPerSquareMeter) <= maxError._kilogramsPerSecondPerSquareMeter; + } + + public override int GetHashCode() + { + return _kilogramsPerSecondPerSquareMeter.GetHashCode(); + } + + #endregion + + #region Conversion + + /// + /// Convert to the unit representation . + /// + /// Value in new unit if successful, exception otherwise. + /// If conversion was not successful. + public double As(MassFluxUnit unit) + { + switch (unit) + { + case MassFluxUnit.GramPerSecondPerSquareMeter: + return GramsPerSecondPerSquareMeter; + case MassFluxUnit.KilogramPerSecondPerSquareMeter: + return KilogramsPerSecondPerSquareMeter; + + default: + throw new NotImplementedException("unit: " + unit); + } + } + + #endregion + + #region Parsing + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static MassFlux 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} + /// Format to use when parsing number and unit. If it is null, it defaults to for parsing the number and for parsing the unit abbreviation by culture/language. + /// + /// 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 MassFlux Parse(string str, [CanBeNull] Culture culture) + { + if (str == null) throw new ArgumentNullException("str"); + + // Windows Runtime Component does not support CultureInfo type, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP + IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture); +#else + IFormatProvider formatProvider = culture; +#endif + return QuantityParser.Parse(str, formatProvider, + delegate(string value, string unit, IFormatProvider formatProvider2) + { + double parsedValue = double.Parse(value, formatProvider2); + MassFluxUnit parsedUnit = ParseUnit(unit, formatProvider2); + return From(parsedValue, parsedUnit); + }, (x, y) => FromKilogramsPerSecondPerSquareMeter(x.KilogramsPerSecondPerSquareMeter + y.KilogramsPerSecondPerSquareMeter)); + } + + /// + /// 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 MassFlux 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} + /// Format to use when parsing number and unit. If it is null, it defaults to for parsing the number and for parsing the unit abbreviation by culture/language. + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, [CanBeNull] Culture culture, out MassFlux result) + { + try + { + result = Parse(str, culture); + return true; + } + catch + { + result = default(MassFlux); + return false; + } + } + + /// + /// Parse a unit string. + /// + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static MassFluxUnit ParseUnit(string str) + { + return ParseUnit(str, (IFormatProvider)null); + } + + /// + /// Parse a unit string. + /// + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static MassFluxUnit ParseUnit(string str, [CanBeNull] string cultureName) + { + return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName)); + } + + /// + /// Parse a unit string. + /// + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods +#if WINDOWS_UWP + internal +#else + public +#endif + static MassFluxUnit ParseUnit(string str, IFormatProvider formatProvider = null) + { + if (str == null) throw new ArgumentNullException("str"); + + var unitSystem = UnitSystem.GetCached(formatProvider); + var unit = unitSystem.Parse(str.Trim()); + + if (unit == MassFluxUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized MassFluxUnit."); + newEx.Data["input"] = str; + newEx.Data["formatprovider"] = formatProvider?.ToString() ?? "(null)"; + throw newEx; + } + + return unit; + } + + #endregion + + /// + /// Set the default unit used by ToString(). Default is KilogramPerSecondPerSquareMeter + /// + public static MassFluxUnit ToStringDefaultUnit { get; set; } = MassFluxUnit.KilogramPerSecondPerSquareMeter; + + /// + /// Get default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(ToStringDefaultUnit); + } + + /// + /// Get string representation of value and unit. Using current UI culture and two significant digits after radix. + /// + /// Unit representation to use. + /// String representation. + public string ToString(MassFluxUnit unit) + { + return ToString(unit, null, 2); + } + + /// + /// Get string representation of value and unit. Using two significant digits after radix. + /// + /// Unit representation to use. + /// Culture to use for localization and number formatting. + /// String representation. + public string ToString(MassFluxUnit unit, [CanBeNull] Culture culture) + { + return ToString(unit, culture, 2); + } + + /// + /// Get string representation of value and unit. + /// + /// Unit representation to use. + /// Culture to use for localization and number formatting. + /// The number of significant digits after the radix point. + /// String representation. + [UsedImplicitly] + public string ToString(MassFluxUnit unit, [CanBeNull] Culture culture, int significantDigitsAfterRadix) + { + double value = As(unit); + string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(unit, culture, format); + } + + /// + /// Get string representation of value and unit. + /// + /// Culture to use for localization and number formatting. + /// Unit representation to use. + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + [UsedImplicitly] + public string ToString(MassFluxUnit unit, [CanBeNull] Culture culture, [NotNull] string format, + [NotNull] params object[] args) + { + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + // Windows Runtime Component does not support CultureInfo type, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP + IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture); +#else + IFormatProvider formatProvider = culture; +#endif + double value = As(unit); + object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args); + return string.Format(formatProvider, format, formatArgs); + } + + /// + /// Represents the largest possible value of MassFlux + /// + public static MassFlux MaxValue + { + get + { + return new MassFlux(double.MaxValue); + } + } + + /// + /// Represents the smallest possible value of MassFlux + /// + public static MassFlux MinValue + { + get + { + return new MassFlux(double.MinValue); + } + } + } +} diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs index 06688fd25d..dfadc36e65 100644 --- a/UnitsNet/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet/GeneratedCode/QuantityType.g.cs @@ -80,6 +80,7 @@ public enum QuantityType Level, Mass, MassFlow, + MassFlux, MassMomentOfInertia, MolarEnergy, MolarEntropy, diff --git a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs index 1a0537c3df..7052425ed7 100644 --- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs +++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs @@ -1893,6 +1893,20 @@ private static readonly ReadOnlyCollection DefaultLocalization new AbbreviationsForCulture("en-US", "t/d"), }), }), + new UnitLocalization(typeof (MassFluxUnit), + new[] + { + new CulturesForEnumValue((int) MassFluxUnit.GramPerSecondPerSquareMeter, + new[] + { + new AbbreviationsForCulture("en-US", "g/s-m²"), + }), + new CulturesForEnumValue((int) MassFluxUnit.KilogramPerSecondPerSquareMeter, + new[] + { + new AbbreviationsForCulture("en-US", "kg/s-m²"), + }), + }), new UnitLocalization(typeof (MassMomentOfInertiaUnit), new[] { diff --git a/UnitsNet/GeneratedCode/Units/MassFluxUnit.g.cs b/UnitsNet/GeneratedCode/Units/MassFluxUnit.g.cs new file mode 100644 index 0000000000..313329b350 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/MassFluxUnit.g.cs @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// +// 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\MyUnit.extra.cs files to add code to generated quantities. +// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + public enum MassFluxUnit + { + Undefined = 0, + GramPerSecondPerSquareMeter, + KilogramPerSecondPerSquareMeter, + } +} diff --git a/UnitsNet/UnitDefinitions/MassFlux.json b/UnitsNet/UnitDefinitions/MassFlux.json new file mode 100644 index 0000000000..ce5e6bd9fe --- /dev/null +++ b/UnitsNet/UnitDefinitions/MassFlux.json @@ -0,0 +1,20 @@ +{ + "Name": "MassFlux", + "BaseUnit": "KilogramPerSecondPerSquareMeter", + "XmlDoc": "Mass flux is the mass flow rate per unit area.", + "Units": [ + { + "SingularName": "GramPerSecondPerSquareMeter", + "PluralName": "GramsPerSecondPerSquareMeter", + "FromUnitToBaseFunc": "x/1e3", + "FromBaseToUnitFunc": "x*1e3", + "Prefixes": [ "Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "g/s-m²" ] + } + ] + } + ] +} \ No newline at end of file From 4bd292df7df70968d19e6dd69b59c81777b3e97c Mon Sep 17 00:00:00 2001 From: gojanpaolo Date: Fri, 12 Jan 2018 08:56:23 -0600 Subject: [PATCH 2/2] Changed abbrevation https://github.com/angularsen/UnitsNet/pull/362#pullrequestreview-88284869 --- UnitsNet/GeneratedCode/UnitSystem.Default.g.cs | 4 ++-- UnitsNet/UnitDefinitions/MassFlux.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs index 7052425ed7..9dcfebd248 100644 --- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs +++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs @@ -1899,12 +1899,12 @@ private static readonly ReadOnlyCollection DefaultLocalization new CulturesForEnumValue((int) MassFluxUnit.GramPerSecondPerSquareMeter, new[] { - new AbbreviationsForCulture("en-US", "g/s-m²"), + new AbbreviationsForCulture("en-US", "g·s⁻¹·m⁻²"), }), new CulturesForEnumValue((int) MassFluxUnit.KilogramPerSecondPerSquareMeter, new[] { - new AbbreviationsForCulture("en-US", "kg/s-m²"), + new AbbreviationsForCulture("en-US", "kg·s⁻¹·m⁻²"), }), }), new UnitLocalization(typeof (MassMomentOfInertiaUnit), diff --git a/UnitsNet/UnitDefinitions/MassFlux.json b/UnitsNet/UnitDefinitions/MassFlux.json index ce5e6bd9fe..345044e248 100644 --- a/UnitsNet/UnitDefinitions/MassFlux.json +++ b/UnitsNet/UnitDefinitions/MassFlux.json @@ -12,7 +12,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [ "g/s-m²" ] + "Abbreviations": [ "g·s⁻¹·m⁻²" ] } ] }