From 95d9ca70c99b87366245aa201b59dc47513e43bb Mon Sep 17 00:00:00 2001 From: Piotr Stenke Date: Tue, 2 Jan 2024 14:33:46 +0100 Subject: [PATCH 1/5] Add RadiationExposure.json --- Common/UnitDefinitions/RadiationExposure.json | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Common/UnitDefinitions/RadiationExposure.json diff --git a/Common/UnitDefinitions/RadiationExposure.json b/Common/UnitDefinitions/RadiationExposure.json new file mode 100644 index 0000000000..65f4521af2 --- /dev/null +++ b/Common/UnitDefinitions/RadiationExposure.json @@ -0,0 +1,48 @@ +{ + "Name": "RadiationExposure", + "BaseUnit": "CoulombPerKilogram", + "XmlDocSummary": "Radiation exposure is a measure of the ionization of air due to ionizing radiation from photons.", + "XmlDocsRemarks": "https://en.wikipedia.org/wiki/Radiation_exposure", + "BaseDimensions": { + "M": -1, + "T": 1, + "I": 1 + }, + "Units": [ + { + "SingularName": "CoulombPerKilogram", + "PluralName": "CoulombsPerKilogram", + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "BaseUnits": { + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, + "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "C/kg" ] + } + ] + }, + { + "SingularName": "Roentgen", + "PluralName": "Roentgens", + "FromUnitToBaseFunc": "{x} * 2.58e-4", + "FromBaseToUnitFunc": "{x} / 2.58e-4", + "BaseUnits": { + "M": "Kilogram", + "T": "Second", + "I": "Ampere" + }, + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "R" ] + } + ] + } + ] +} \ No newline at end of file From 812cb831dc703d1026fd6d22d1e3ee95f0728681 Mon Sep 17 00:00:00 2001 From: Piotr Stenke Date: Tue, 2 Jan 2024 14:54:35 +0100 Subject: [PATCH 2/5] Remove Kilo and Mega --- Common/UnitDefinitions/RadiationExposure.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/UnitDefinitions/RadiationExposure.json b/Common/UnitDefinitions/RadiationExposure.json index 65f4521af2..fe0304ace8 100644 --- a/Common/UnitDefinitions/RadiationExposure.json +++ b/Common/UnitDefinitions/RadiationExposure.json @@ -19,7 +19,7 @@ "T": "Second", "I": "Ampere" }, - "Prefixes": [ "Pico", "Nano", "Micro", "Milli", "Kilo", "Mega" ], + "Prefixes": [ "Pico", "Nano", "Micro", "Milli" ], "Localization": [ { "Culture": "en-US", From 83cce617a1fd98e7fedeed215e9c1d6bd1c6a60d Mon Sep 17 00:00:00 2001 From: Piotr Stenke Date: Tue, 2 Jan 2024 15:04:21 +0100 Subject: [PATCH 3/5] Run codegen --- Common/UnitEnumValues.g.json | 8 + .../Quantities/RadiationExposure.g.cs | 224 ++++ .../RadiationExposure.nfproj | 42 + ...Net.NanoFramework.RadiationExposure.nuspec | 26 + .../RadiationExposure/packages.config | 4 + .../Units/RadiationExposureUnit.g.cs | 37 + .../GeneratedCode/UnitsNet.nanoFramework.sln | 8 + ...mberToRadiationExposureExtensionsTest.g.cs | 52 + .../NumberToRadiationExposureExtensions.g.cs | 84 ++ .../CustomCode/RadiationExposureTests.cs | 18 + .../GeneratedCode/IQuantityTests.g.cs | 3 + .../TestsBase/RadiationExposureTestsBase.g.cs | 816 +++++++++++++ .../Quantities/RadiationExposure.g.cs | 1030 +++++++++++++++++ UnitsNet/GeneratedCode/Quantity.g.cs | 5 + .../Resources/RadiationExposure.restext | 6 + .../Units/RadiationExposureUnit.g.cs | 37 + 16 files changed, 2400 insertions(+) create mode 100644 UnitsNet.NanoFramework/GeneratedCode/Quantities/RadiationExposure.g.cs create mode 100644 UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/RadiationExposure.nfproj create mode 100644 UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/UnitsNet.NanoFramework.RadiationExposure.nuspec create mode 100644 UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/packages.config create mode 100644 UnitsNet.NanoFramework/GeneratedCode/Units/RadiationExposureUnit.g.cs create mode 100644 UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToRadiationExposureExtensionsTest.g.cs create mode 100644 UnitsNet.NumberExtensions/GeneratedCode/NumberToRadiationExposureExtensions.g.cs create mode 100644 UnitsNet.Tests/CustomCode/RadiationExposureTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs create mode 100644 UnitsNet/GeneratedCode/Resources/RadiationExposure.restext create mode 100644 UnitsNet/GeneratedCode/Units/RadiationExposureUnit.g.cs diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index 5bc81f4e52..a301670164 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -1825,5 +1825,13 @@ "Picobecquerel": 36, "Picocurie": 35, "Picorutherford": 25 + }, + "RadiationExposure": { + "CoulombPerKilogram": 10, + "MicrocoulombPerKilogram": 3, + "MillicoulombPerKilogram": 2, + "NanocoulombPerKilogram": 6, + "PicocoulombPerKilogram": 5, + "Roentgen": 4 } } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/RadiationExposure.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/RadiationExposure.g.cs new file mode 100644 index 0000000000..699b2fba55 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/RadiationExposure.g.cs @@ -0,0 +1,224 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using UnitsNet.Units; + +namespace UnitsNet +{ + /// + /// + /// Radiation exposure is a measure of the ionization of air due to ionizing radiation from photons. + /// + public struct RadiationExposure + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly RadiationExposureUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public RadiationExposureUnit Unit => _unit; + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to construct this quantity with. + /// The unit representation to construct this quantity with. + /// If value is NaN or Infinity. + public RadiationExposure(double value, RadiationExposureUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of Duration, which is Second. All conversions go via this value. + /// + public static RadiationExposureUnit BaseUnit { get; } = RadiationExposureUnit.CoulombPerKilogram; + + /// + /// Represents the largest possible value of Duration + /// + public static RadiationExposure MaxValue { get; } = new RadiationExposure(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of Duration + /// + public static RadiationExposure MinValue { get; } = new RadiationExposure(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static RadiationExposure Zero { get; } = new RadiationExposure(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double CoulombsPerKilogram => As(RadiationExposureUnit.CoulombPerKilogram); + + /// + /// Gets a value of this quantity converted into + /// + public double MicrocoulombsPerKilogram => As(RadiationExposureUnit.MicrocoulombPerKilogram); + + /// + /// Gets a value of this quantity converted into + /// + public double MillicoulombsPerKilogram => As(RadiationExposureUnit.MillicoulombPerKilogram); + + /// + /// Gets a value of this quantity converted into + /// + public double NanocoulombsPerKilogram => As(RadiationExposureUnit.NanocoulombPerKilogram); + + /// + /// Gets a value of this quantity converted into + /// + public double PicocoulombsPerKilogram => As(RadiationExposureUnit.PicocoulombPerKilogram); + + /// + /// Gets a value of this quantity converted into + /// + public double Roentgens => As(RadiationExposureUnit.Roentgen); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromCoulombsPerKilogram(double coulombsperkilogram) => new RadiationExposure(coulombsperkilogram, RadiationExposureUnit.CoulombPerKilogram); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromMicrocoulombsPerKilogram(double microcoulombsperkilogram) => new RadiationExposure(microcoulombsperkilogram, RadiationExposureUnit.MicrocoulombPerKilogram); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromMillicoulombsPerKilogram(double millicoulombsperkilogram) => new RadiationExposure(millicoulombsperkilogram, RadiationExposureUnit.MillicoulombPerKilogram); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromNanocoulombsPerKilogram(double nanocoulombsperkilogram) => new RadiationExposure(nanocoulombsperkilogram, RadiationExposureUnit.NanocoulombPerKilogram); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromPicocoulombsPerKilogram(double picocoulombsperkilogram) => new RadiationExposure(picocoulombsperkilogram, RadiationExposureUnit.PicocoulombPerKilogram); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromRoentgens(double roentgens) => new RadiationExposure(roentgens, RadiationExposureUnit.Roentgen); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// RadiationExposure unit value. + public static RadiationExposure From(double value, RadiationExposureUnit fromUnit) + { + return new RadiationExposure(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(RadiationExposureUnit unit) => GetValueAs(unit); + + /// + /// Converts this Duration to another Duration with the unit representation . + /// + /// A Duration with the specified unit. + public RadiationExposure ToUnit(RadiationExposureUnit unit) + { + var convertedValue = GetValueAs(unit); + return new RadiationExposure(convertedValue, unit); + } + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double GetValueInBaseUnit() + { + return Unit switch + { + RadiationExposureUnit.CoulombPerKilogram => _value, + RadiationExposureUnit.MicrocoulombPerKilogram => (_value) * 1e-6d, + RadiationExposureUnit.MillicoulombPerKilogram => (_value) * 1e-3d, + RadiationExposureUnit.NanocoulombPerKilogram => (_value) * 1e-9d, + RadiationExposureUnit.PicocoulombPerKilogram => (_value) * 1e-12d, + RadiationExposureUnit.Roentgen => _value * 2.58e-4, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(RadiationExposureUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + RadiationExposureUnit.CoulombPerKilogram => baseUnitValue, + RadiationExposureUnit.MicrocoulombPerKilogram => (baseUnitValue) / 1e-6d, + RadiationExposureUnit.MillicoulombPerKilogram => (baseUnitValue) / 1e-3d, + RadiationExposureUnit.NanocoulombPerKilogram => (baseUnitValue) / 1e-9d, + RadiationExposureUnit.PicocoulombPerKilogram => (baseUnitValue) / 1e-12d, + RadiationExposureUnit.Roentgen => baseUnitValue / 2.58e-4, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/RadiationExposure.nfproj b/UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/RadiationExposure.nfproj new file mode 100644 index 0000000000..f2b96d78df --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/RadiationExposure.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {69b383c7-828a-1857-cbe2-f11b9ba77320} + Library + Properties + 512 + UnitsNet + UnitsNet.RadiationExposure + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/UnitsNet.NanoFramework.RadiationExposure.nuspec b/UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/UnitsNet.NanoFramework.RadiationExposure.nuspec new file mode 100644 index 0000000000..470443e550 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/UnitsNet.NanoFramework.RadiationExposure.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.RadiationExposure + 5.41.0 + Units.NET RadiationExposure - nanoFramework + Andreas Gullberg Larsen,nanoframework + UnitsNet + MIT + https://github.com/angularsen/UnitsNet + false + Adds RadiationExposure units for Units.NET on .NET nanoFramework. For .NET or .NET Core, use UnitsNet instead. + https://raw.githubusercontent.com/angularsen/UnitsNet/ce85185429be345d77eb2ce09c99d59cc9ab8aed/Docs/Images/logo-32.png + + + Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). + en-US + nanoframework radiationexposure unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/packages.config b/UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/packages.config new file mode 100644 index 0000000000..313a8dccdf --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/RadiationExposure/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/RadiationExposureUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/RadiationExposureUnit.g.cs new file mode 100644 index 0000000000..75b4669f79 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/RadiationExposureUnit.g.cs @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// 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 RadiationExposureUnit + { + CoulombPerKilogram = 10, + MicrocoulombPerKilogram = 3, + MillicoulombPerKilogram = 2, + NanocoulombPerKilogram = 6, + PicocoulombPerKilogram = 5, + Roentgen = 4, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln index ce672dd107..4ae1dab440 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln +++ b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln @@ -170,6 +170,8 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Pressure", "Pressure\Pressu EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "PressureChangeRate", "PressureChangeRate\PressureChangeRate.nfproj", "{c9e4cfa9-c5d3-5e9d-243c-106ba4b6a447}" EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "RadiationExposure", "RadiationExposure\RadiationExposure.nfproj", "{69b383c7-828a-1857-cbe2-f11b9ba77320}" +EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Radioactivity", "Radioactivity\Radioactivity.nfproj", "{abf4b42f-e999-2a78-403f-fb09524f186a}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Ratio", "Ratio\Ratio.nfproj", "{b0be4813-d93e-7b06-d422-23ca28adf22a}" @@ -756,6 +758,12 @@ Global {c9e4cfa9-c5d3-5e9d-243c-106ba4b6a447}.Release|Any CPU.ActiveCfg = Release|Any CPU {c9e4cfa9-c5d3-5e9d-243c-106ba4b6a447}.Release|Any CPU.Build.0 = Release|Any CPU {c9e4cfa9-c5d3-5e9d-243c-106ba4b6a447}.Release|Any CPU.Deploy.0 = Release|Any CPU +{69b383c7-828a-1857-cbe2-f11b9ba77320}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{69b383c7-828a-1857-cbe2-f11b9ba77320}.Debug|Any CPU.Build.0 = Debug|Any CPU +{69b383c7-828a-1857-cbe2-f11b9ba77320}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{69b383c7-828a-1857-cbe2-f11b9ba77320}.Release|Any CPU.ActiveCfg = Release|Any CPU +{69b383c7-828a-1857-cbe2-f11b9ba77320}.Release|Any CPU.Build.0 = Release|Any CPU +{69b383c7-828a-1857-cbe2-f11b9ba77320}.Release|Any CPU.Deploy.0 = Release|Any CPU {abf4b42f-e999-2a78-403f-fb09524f186a}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {abf4b42f-e999-2a78-403f-fb09524f186a}.Debug|Any CPU.Build.0 = Debug|Any CPU {abf4b42f-e999-2a78-403f-fb09524f186a}.Debug|Any CPU.Deploy.0 = Debug|Any CPU diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToRadiationExposureExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToRadiationExposureExtensionsTest.g.cs new file mode 100644 index 0000000000..1d6989d721 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToRadiationExposureExtensionsTest.g.cs @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToRadiationExposure; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToRadiationExposureExtensionsTests + { + [Fact] + public void NumberToCoulombsPerKilogramTest() => + Assert.Equal(RadiationExposure.FromCoulombsPerKilogram(2), 2.CoulombsPerKilogram()); + + [Fact] + public void NumberToMicrocoulombsPerKilogramTest() => + Assert.Equal(RadiationExposure.FromMicrocoulombsPerKilogram(2), 2.MicrocoulombsPerKilogram()); + + [Fact] + public void NumberToMillicoulombsPerKilogramTest() => + Assert.Equal(RadiationExposure.FromMillicoulombsPerKilogram(2), 2.MillicoulombsPerKilogram()); + + [Fact] + public void NumberToNanocoulombsPerKilogramTest() => + Assert.Equal(RadiationExposure.FromNanocoulombsPerKilogram(2), 2.NanocoulombsPerKilogram()); + + [Fact] + public void NumberToPicocoulombsPerKilogramTest() => + Assert.Equal(RadiationExposure.FromPicocoulombsPerKilogram(2), 2.PicocoulombsPerKilogram()); + + [Fact] + public void NumberToRoentgensTest() => + Assert.Equal(RadiationExposure.FromRoentgens(2), 2.Roentgens()); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToRadiationExposureExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToRadiationExposureExtensions.g.cs new file mode 100644 index 0000000000..1e8a9610bf --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToRadiationExposureExtensions.g.cs @@ -0,0 +1,84 @@ +//------------------------------------------------------------------------------ +// +// 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; + +#if NET7_0_OR_GREATER +using System.Numerics; +#endif + +#nullable enable + +namespace UnitsNet.NumberExtensions.NumberToRadiationExposure +{ + /// + /// A number to RadiationExposure Extensions + /// + public static class NumberToRadiationExposureExtensions + { + /// + public static RadiationExposure CoulombsPerKilogram(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => RadiationExposure.FromCoulombsPerKilogram(Convert.ToDouble(value)); + + /// + public static RadiationExposure MicrocoulombsPerKilogram(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => RadiationExposure.FromMicrocoulombsPerKilogram(Convert.ToDouble(value)); + + /// + public static RadiationExposure MillicoulombsPerKilogram(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => RadiationExposure.FromMillicoulombsPerKilogram(Convert.ToDouble(value)); + + /// + public static RadiationExposure NanocoulombsPerKilogram(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => RadiationExposure.FromNanocoulombsPerKilogram(Convert.ToDouble(value)); + + /// + public static RadiationExposure PicocoulombsPerKilogram(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => RadiationExposure.FromPicocoulombsPerKilogram(Convert.ToDouble(value)); + + /// + public static RadiationExposure Roentgens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => RadiationExposure.FromRoentgens(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.Tests/CustomCode/RadiationExposureTests.cs b/UnitsNet.Tests/CustomCode/RadiationExposureTests.cs new file mode 100644 index 0000000000..d3bf3e52fb --- /dev/null +++ b/UnitsNet.Tests/CustomCode/RadiationExposureTests.cs @@ -0,0 +1,18 @@ +// 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 RadiationExposureTests : RadiationExposureTestsBase + { + protected override bool SupportsSIUnitSystem => true; + protected override double CoulombsPerKilogramInOneCoulombPerKilogram => 1; + protected override double MillicoulombsPerKilogramInOneCoulombPerKilogram => 1e+3; + protected override double MicrocoulombsPerKilogramInOneCoulombPerKilogram => 1e+6; + protected override double NanocoulombsPerKilogramInOneCoulombPerKilogram => 1e+9; + protected override double PicocoulombsPerKilogramInOneCoulombPerKilogram => 1e+12; + protected override double RoentgensInOneCoulombPerKilogram => 3875.9689922; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index 9e18cd461c..adfc1e4d48 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -118,6 +118,7 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, PowerRatioUnit.DecibelWatt, Quantity.From(3, PowerRatioUnit.DecibelWatt)); Assertion(3, PressureUnit.Torr, Quantity.From(3, PressureUnit.Torr)); Assertion(3, PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, Quantity.From(3, PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)); + Assertion(3, RadiationExposureUnit.Roentgen, Quantity.From(3, RadiationExposureUnit.Roentgen)); Assertion(3, RadioactivityUnit.Terarutherford, Quantity.From(3, RadioactivityUnit.Terarutherford)); Assertion(3, RatioUnit.Percent, Quantity.From(3, RatioUnit.Percent)); Assertion(3, RatioChangeRateUnit.PercentPerSecond, Quantity.From(3, RatioChangeRateUnit.PercentPerSecond)); @@ -247,6 +248,7 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(PowerRatio.Info, PowerRatio.Zero); Assertion(Pressure.Info, Pressure.Zero); Assertion(PressureChangeRate.Info, PressureChangeRate.Zero); + Assertion(RadiationExposure.Info, RadiationExposure.Zero); Assertion(Radioactivity.Info, Radioactivity.Zero); Assertion(Ratio.Info, Ratio.Zero); Assertion(RatioChangeRate.Info, RatioChangeRate.Zero); @@ -376,6 +378,7 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(PowerRatio.BaseDimensions, PowerRatio.Zero); Assertion(Pressure.BaseDimensions, Pressure.Zero); Assertion(PressureChangeRate.BaseDimensions, PressureChangeRate.Zero); + Assertion(RadiationExposure.BaseDimensions, RadiationExposure.Zero); Assertion(Radioactivity.BaseDimensions, Radioactivity.Zero); Assertion(Ratio.BaseDimensions, Ratio.Zero); Assertion(RatioChangeRate.BaseDimensions, RatioChangeRate.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs new file mode 100644 index 0000000000..34b1ab9a1c --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs @@ -0,0 +1,816 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using UnitsNet.Tests.TestsBase; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of RadiationExposure. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class RadiationExposureTestsBase : QuantityTestsBase + { + protected abstract double CoulombsPerKilogramInOneCoulombPerKilogram { get; } + protected abstract double MicrocoulombsPerKilogramInOneCoulombPerKilogram { get; } + protected abstract double MillicoulombsPerKilogramInOneCoulombPerKilogram { get; } + protected abstract double NanocoulombsPerKilogramInOneCoulombPerKilogram { get; } + protected abstract double PicocoulombsPerKilogramInOneCoulombPerKilogram { get; } + protected abstract double RoentgensInOneCoulombPerKilogram { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double CoulombsPerKilogramTolerance { get { return 1e-5; } } + protected virtual double MicrocoulombsPerKilogramTolerance { get { return 1e-5; } } + protected virtual double MillicoulombsPerKilogramTolerance { get { return 1e-5; } } + protected virtual double NanocoulombsPerKilogramTolerance { get { return 1e-5; } } + protected virtual double PicocoulombsPerKilogramTolerance { get { return 1e-5; } } + protected virtual double RoentgensTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(RadiationExposureUnit unit) + { + return unit switch + { + RadiationExposureUnit.CoulombPerKilogram => (CoulombsPerKilogramInOneCoulombPerKilogram, CoulombsPerKilogramTolerance), + RadiationExposureUnit.MicrocoulombPerKilogram => (MicrocoulombsPerKilogramInOneCoulombPerKilogram, MicrocoulombsPerKilogramTolerance), + RadiationExposureUnit.MillicoulombPerKilogram => (MillicoulombsPerKilogramInOneCoulombPerKilogram, MillicoulombsPerKilogramTolerance), + RadiationExposureUnit.NanocoulombPerKilogram => (NanocoulombsPerKilogramInOneCoulombPerKilogram, NanocoulombsPerKilogramTolerance), + RadiationExposureUnit.PicocoulombPerKilogram => (PicocoulombsPerKilogramInOneCoulombPerKilogram, PicocoulombsPerKilogramTolerance), + RadiationExposureUnit.Roentgen => (RoentgensInOneCoulombPerKilogram, RoentgensTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { RadiationExposureUnit.CoulombPerKilogram }, + new object[] { RadiationExposureUnit.MicrocoulombPerKilogram }, + new object[] { RadiationExposureUnit.MillicoulombPerKilogram }, + new object[] { RadiationExposureUnit.NanocoulombPerKilogram }, + new object[] { RadiationExposureUnit.PicocoulombPerKilogram }, + new object[] { RadiationExposureUnit.Roentgen }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new RadiationExposure(); + Assert.Equal(0, quantity.Value); + Assert.Equal(RadiationExposureUnit.CoulombPerKilogram, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => new RadiationExposure(double.PositiveInfinity, RadiationExposureUnit.CoulombPerKilogram)); + Assert.Throws(() => new RadiationExposure(double.NegativeInfinity, RadiationExposureUnit.CoulombPerKilogram)); + } + + [Fact] + public void Ctor_WithNaNValue_ThrowsArgumentException() + { + Assert.Throws(() => new RadiationExposure(double.NaN, RadiationExposureUnit.CoulombPerKilogram)); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new RadiationExposure(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new RadiationExposure(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (RadiationExposure) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void RadiationExposure_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new RadiationExposure(1, RadiationExposureUnit.CoulombPerKilogram); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(RadiationExposure.Zero, quantityInfo.Zero); + Assert.Equal("RadiationExposure", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void CoulombPerKilogramToRadiationExposureUnits() + { + RadiationExposure coulombperkilogram = RadiationExposure.FromCoulombsPerKilogram(1); + AssertEx.EqualTolerance(CoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.CoulombsPerKilogram, CoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(MicrocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.MicrocoulombsPerKilogram, MicrocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(MillicoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.MillicoulombsPerKilogram, MillicoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(NanocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.NanocoulombsPerKilogram, NanocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(PicocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.PicocoulombsPerKilogram, PicocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(RoentgensInOneCoulombPerKilogram, coulombperkilogram.Roentgens, RoentgensTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + var quantity00 = RadiationExposure.From(1, RadiationExposureUnit.CoulombPerKilogram); + AssertEx.EqualTolerance(1, quantity00.CoulombsPerKilogram, CoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.CoulombPerKilogram, quantity00.Unit); + + var quantity01 = RadiationExposure.From(1, RadiationExposureUnit.MicrocoulombPerKilogram); + AssertEx.EqualTolerance(1, quantity01.MicrocoulombsPerKilogram, MicrocoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, quantity01.Unit); + + var quantity02 = RadiationExposure.From(1, RadiationExposureUnit.MillicoulombPerKilogram); + AssertEx.EqualTolerance(1, quantity02.MillicoulombsPerKilogram, MillicoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, quantity02.Unit); + + var quantity03 = RadiationExposure.From(1, RadiationExposureUnit.NanocoulombPerKilogram); + AssertEx.EqualTolerance(1, quantity03.NanocoulombsPerKilogram, NanocoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, quantity03.Unit); + + var quantity04 = RadiationExposure.From(1, RadiationExposureUnit.PicocoulombPerKilogram); + AssertEx.EqualTolerance(1, quantity04.PicocoulombsPerKilogram, PicocoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.PicocoulombPerKilogram, quantity04.Unit); + + var quantity05 = RadiationExposure.From(1, RadiationExposureUnit.Roentgen); + AssertEx.EqualTolerance(1, quantity05.Roentgens, RoentgensTolerance); + Assert.Equal(RadiationExposureUnit.Roentgen, quantity05.Unit); + + } + + [Fact] + public void FromCoulombsPerKilogram_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => RadiationExposure.FromCoulombsPerKilogram(double.PositiveInfinity)); + Assert.Throws(() => RadiationExposure.FromCoulombsPerKilogram(double.NegativeInfinity)); + } + + [Fact] + public void FromCoulombsPerKilogram_WithNanValue_ThrowsArgumentException() + { + Assert.Throws(() => RadiationExposure.FromCoulombsPerKilogram(double.NaN)); + } + + [Fact] + public void As() + { + var coulombperkilogram = RadiationExposure.FromCoulombsPerKilogram(1); + AssertEx.EqualTolerance(CoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.CoulombPerKilogram), CoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(MicrocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.MicrocoulombPerKilogram), MicrocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(MillicoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.MillicoulombPerKilogram), MillicoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(NanocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.NanocoulombPerKilogram), NanocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(PicocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.PicocoulombPerKilogram), PicocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(RoentgensInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.Roentgen), RoentgensTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new RadiationExposure(value: 1, unit: RadiationExposure.BaseUnit); + Func AsWithSIUnitSystem = () => quantity.As(UnitSystem.SI); + + if (SupportsSIUnitSystem) + { + var value = Convert.ToDouble(AsWithSIUnitSystem()); + Assert.Equal(1, value); + } + else + { + Assert.Throws(AsWithSIUnitSystem); + } + } + + [Fact] + public void Parse() + { + try + { + var parsed = RadiationExposure.Parse("1 C/kg", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.CoulombsPerKilogram, CoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.CoulombPerKilogram, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = RadiationExposure.Parse("1 µC/kg", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MicrocoulombsPerKilogram, MicrocoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = RadiationExposure.Parse("1 mC/kg", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MillicoulombsPerKilogram, MillicoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = RadiationExposure.Parse("1 nC/kg", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.NanocoulombsPerKilogram, NanocoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = RadiationExposure.Parse("1 pC/kg", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.PicocoulombsPerKilogram, PicocoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.PicocoulombPerKilogram, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = RadiationExposure.Parse("1 R", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Roentgens, RoentgensTolerance); + Assert.Equal(RadiationExposureUnit.Roentgen, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(RadiationExposure.TryParse("1 C/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.CoulombsPerKilogram, CoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.CoulombPerKilogram, parsed.Unit); + } + + { + Assert.True(RadiationExposure.TryParse("1 µC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MicrocoulombsPerKilogram, MicrocoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsed.Unit); + } + + { + Assert.True(RadiationExposure.TryParse("1 mC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MillicoulombsPerKilogram, MillicoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsed.Unit); + } + + { + Assert.True(RadiationExposure.TryParse("1 nC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.NanocoulombsPerKilogram, NanocoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, parsed.Unit); + } + + { + Assert.True(RadiationExposure.TryParse("1 pC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.PicocoulombsPerKilogram, PicocoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.PicocoulombPerKilogram, parsed.Unit); + } + + { + Assert.True(RadiationExposure.TryParse("1 R", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Roentgens, RoentgensTolerance); + Assert.Equal(RadiationExposureUnit.Roentgen, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = RadiationExposure.ParseUnit("C/kg", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(RadiationExposureUnit.CoulombPerKilogram, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = RadiationExposure.ParseUnit("µC/kg", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = RadiationExposure.ParseUnit("mC/kg", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = RadiationExposure.ParseUnit("nC/kg", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = RadiationExposure.ParseUnit("pC/kg", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(RadiationExposureUnit.PicocoulombPerKilogram, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = RadiationExposure.ParseUnit("R", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(RadiationExposureUnit.Roentgen, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(RadiationExposure.TryParseUnit("C/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(RadiationExposureUnit.CoulombPerKilogram, parsedUnit); + } + + { + Assert.True(RadiationExposure.TryParseUnit("µC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsedUnit); + } + + { + Assert.True(RadiationExposure.TryParseUnit("mC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsedUnit); + } + + { + Assert.True(RadiationExposure.TryParseUnit("nC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, parsedUnit); + } + + { + Assert.True(RadiationExposure.TryParseUnit("pC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(RadiationExposureUnit.PicocoulombPerKilogram, parsedUnit); + } + + { + Assert.True(RadiationExposure.TryParseUnit("R", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(RadiationExposureUnit.Roentgen, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(RadiationExposureUnit unit) + { + var inBaseUnits = RadiationExposure.From(1.0, RadiationExposure.BaseUnit); + var converted = inBaseUnits.ToUnit(unit); + + var conversionFactor = GetConversionFactor(unit); + AssertEx.EqualTolerance(conversionFactor.UnitsInBaseUnit, converted.Value, conversionFactor.Tolerence); + Assert.Equal(unit, converted.Unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_WithSameUnits_AreEqual(RadiationExposureUnit unit) + { + var quantity = RadiationExposure.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(RadiationExposureUnit unit) + { + // See if there is a unit available that is not the base unit, fallback to base unit if it has only a single unit. + var fromUnit = RadiationExposure.Units.First(u => u != RadiationExposure.BaseUnit); + + var quantity = RadiationExposure.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(RadiationExposureUnit unit) + { + var quantity = default(RadiationExposure); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + RadiationExposure coulombperkilogram = RadiationExposure.FromCoulombsPerKilogram(1); + AssertEx.EqualTolerance(1, RadiationExposure.FromCoulombsPerKilogram(coulombperkilogram.CoulombsPerKilogram).CoulombsPerKilogram, CoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(1, RadiationExposure.FromMicrocoulombsPerKilogram(coulombperkilogram.MicrocoulombsPerKilogram).CoulombsPerKilogram, MicrocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(1, RadiationExposure.FromMillicoulombsPerKilogram(coulombperkilogram.MillicoulombsPerKilogram).CoulombsPerKilogram, MillicoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(1, RadiationExposure.FromNanocoulombsPerKilogram(coulombperkilogram.NanocoulombsPerKilogram).CoulombsPerKilogram, NanocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(1, RadiationExposure.FromPicocoulombsPerKilogram(coulombperkilogram.PicocoulombsPerKilogram).CoulombsPerKilogram, PicocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(1, RadiationExposure.FromRoentgens(coulombperkilogram.Roentgens).CoulombsPerKilogram, RoentgensTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + RadiationExposure v = RadiationExposure.FromCoulombsPerKilogram(1); + AssertEx.EqualTolerance(-1, -v.CoulombsPerKilogram, CoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(2, (RadiationExposure.FromCoulombsPerKilogram(3)-v).CoulombsPerKilogram, CoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(2, (v + v).CoulombsPerKilogram, CoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(10, (v*10).CoulombsPerKilogram, CoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(10, (10*v).CoulombsPerKilogram, CoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(2, (RadiationExposure.FromCoulombsPerKilogram(10)/5).CoulombsPerKilogram, CoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(2, RadiationExposure.FromCoulombsPerKilogram(10)/RadiationExposure.FromCoulombsPerKilogram(5), CoulombsPerKilogramTolerance); + } + + [Fact] + public void ComparisonOperators() + { + RadiationExposure oneCoulombPerKilogram = RadiationExposure.FromCoulombsPerKilogram(1); + RadiationExposure twoCoulombsPerKilogram = RadiationExposure.FromCoulombsPerKilogram(2); + + Assert.True(oneCoulombPerKilogram < twoCoulombsPerKilogram); + Assert.True(oneCoulombPerKilogram <= twoCoulombsPerKilogram); + Assert.True(twoCoulombsPerKilogram > oneCoulombPerKilogram); + Assert.True(twoCoulombsPerKilogram >= oneCoulombPerKilogram); + + Assert.False(oneCoulombPerKilogram > twoCoulombsPerKilogram); + Assert.False(oneCoulombPerKilogram >= twoCoulombsPerKilogram); + Assert.False(twoCoulombsPerKilogram < oneCoulombPerKilogram); + Assert.False(twoCoulombsPerKilogram <= oneCoulombPerKilogram); + } + + [Fact] + public void CompareToIsImplemented() + { + RadiationExposure coulombperkilogram = RadiationExposure.FromCoulombsPerKilogram(1); + Assert.Equal(0, coulombperkilogram.CompareTo(coulombperkilogram)); + Assert.True(coulombperkilogram.CompareTo(RadiationExposure.Zero) > 0); + Assert.True(RadiationExposure.Zero.CompareTo(coulombperkilogram) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + RadiationExposure coulombperkilogram = RadiationExposure.FromCoulombsPerKilogram(1); + Assert.Throws(() => coulombperkilogram.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + RadiationExposure coulombperkilogram = RadiationExposure.FromCoulombsPerKilogram(1); + Assert.Throws(() => coulombperkilogram.CompareTo(null)); + } + + [Theory] + [InlineData(1, RadiationExposureUnit.CoulombPerKilogram, 1, RadiationExposureUnit.CoulombPerKilogram, true)] // Same value and unit. + [InlineData(1, RadiationExposureUnit.CoulombPerKilogram, 2, RadiationExposureUnit.CoulombPerKilogram, false)] // Different value. + [InlineData(2, RadiationExposureUnit.CoulombPerKilogram, 1, RadiationExposureUnit.MicrocoulombPerKilogram, false)] // Different value and unit. + [InlineData(1, RadiationExposureUnit.CoulombPerKilogram, 1, RadiationExposureUnit.MicrocoulombPerKilogram, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, RadiationExposureUnit unitA, double valueB, RadiationExposureUnit unitB, bool expectEqual) + { + var a = new RadiationExposure(valueA, unitA); + var b = new RadiationExposure(valueB, unitB); + + // Operator overloads. + Assert.Equal(expectEqual, a == b); + Assert.Equal(expectEqual, b == a); + Assert.Equal(!expectEqual, a != b); + Assert.Equal(!expectEqual, b != a); + + // IEquatable + Assert.Equal(expectEqual, a.Equals(b)); + Assert.Equal(expectEqual, b.Equals(a)); + + // IEquatable + Assert.Equal(expectEqual, a.Equals((object)b)); + Assert.Equal(expectEqual, b.Equals((object)a)); + } + + [Fact] + public void Equals_Null_ReturnsFalse() + { + var a = RadiationExposure.Zero; + + Assert.False(a.Equals((object)null)); + + // "The result of the expression is always 'false'..." + #pragma warning disable CS8073 + Assert.False(a == null); + Assert.False(null == a); + Assert.True(a != null); + Assert.True(null != a); + #pragma warning restore CS8073 + } + + [Fact] + public void Equals_RelativeTolerance_IsImplemented() + { + var v = RadiationExposure.FromCoulombsPerKilogram(1); + Assert.True(v.Equals(RadiationExposure.FromCoulombsPerKilogram(1), CoulombsPerKilogramTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(RadiationExposure.Zero, CoulombsPerKilogramTolerance, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = RadiationExposure.FromCoulombsPerKilogram(1); + Assert.Throws(() => v.Equals(RadiationExposure.FromCoulombsPerKilogram(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + RadiationExposure coulombperkilogram = RadiationExposure.FromCoulombsPerKilogram(1); + Assert.False(coulombperkilogram.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + RadiationExposure coulombperkilogram = RadiationExposure.FromCoulombsPerKilogram(1); + Assert.False(coulombperkilogram.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(RadiationExposureUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(RadiationExposure.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 C/kg", new RadiationExposure(1, RadiationExposureUnit.CoulombPerKilogram).ToString()); + Assert.Equal("1 µC/kg", new RadiationExposure(1, RadiationExposureUnit.MicrocoulombPerKilogram).ToString()); + Assert.Equal("1 mC/kg", new RadiationExposure(1, RadiationExposureUnit.MillicoulombPerKilogram).ToString()); + Assert.Equal("1 nC/kg", new RadiationExposure(1, RadiationExposureUnit.NanocoulombPerKilogram).ToString()); + Assert.Equal("1 pC/kg", new RadiationExposure(1, RadiationExposureUnit.PicocoulombPerKilogram).ToString()); + Assert.Equal("1 R", new RadiationExposure(1, RadiationExposureUnit.Roentgen).ToString()); + } + finally + { + Thread.CurrentThread.CurrentCulture = 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 C/kg", new RadiationExposure(1, RadiationExposureUnit.CoulombPerKilogram).ToString(swedishCulture)); + Assert.Equal("1 µC/kg", new RadiationExposure(1, RadiationExposureUnit.MicrocoulombPerKilogram).ToString(swedishCulture)); + Assert.Equal("1 mC/kg", new RadiationExposure(1, RadiationExposureUnit.MillicoulombPerKilogram).ToString(swedishCulture)); + Assert.Equal("1 nC/kg", new RadiationExposure(1, RadiationExposureUnit.NanocoulombPerKilogram).ToString(swedishCulture)); + Assert.Equal("1 pC/kg", new RadiationExposure(1, RadiationExposureUnit.PicocoulombPerKilogram).ToString(swedishCulture)); + Assert.Equal("1 R", new RadiationExposure(1, RadiationExposureUnit.Roentgen).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 C/kg", new RadiationExposure(0.123456, RadiationExposureUnit.CoulombPerKilogram).ToString("s1")); + Assert.Equal("0.12 C/kg", new RadiationExposure(0.123456, RadiationExposureUnit.CoulombPerKilogram).ToString("s2")); + Assert.Equal("0.123 C/kg", new RadiationExposure(0.123456, RadiationExposureUnit.CoulombPerKilogram).ToString("s3")); + Assert.Equal("0.1235 C/kg", new RadiationExposure(0.123456, RadiationExposureUnit.CoulombPerKilogram).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 C/kg", new RadiationExposure(0.123456, RadiationExposureUnit.CoulombPerKilogram).ToString("s1", culture)); + Assert.Equal("0.12 C/kg", new RadiationExposure(0.123456, RadiationExposureUnit.CoulombPerKilogram).ToString("s2", culture)); + Assert.Equal("0.123 C/kg", new RadiationExposure(0.123456, RadiationExposureUnit.CoulombPerKilogram).ToString("s3", culture)); + Assert.Equal("0.1235 C/kg", new RadiationExposure(0.123456, RadiationExposureUnit.CoulombPerKilogram).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + CultureInfo formatProvider = cultureName == null + ? null + : CultureInfo.GetCultureInfo(cultureName); + + Assert.Equal(quantity.ToString("g", formatProvider), quantity.ToString(null, formatProvider)); + } + + [Theory] + [InlineData(null)] + [InlineData("g")] + public void ToString_NullProvider_EqualsCurrentCulture(string format) + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(RadiationExposure))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(RadiationExposureUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal(RadiationExposure.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal(RadiationExposure.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(1.0); + Assert.Equal(new {RadiationExposure.Info.Name, quantity.Value, quantity.Unit}.GetHashCode(), quantity.GetHashCode()); + } + + [Theory] + [InlineData(1.0)] + [InlineData(-1.0)] + public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) + { + var quantity = RadiationExposure.FromCoulombsPerKilogram(value); + Assert.Equal(RadiationExposure.FromCoulombsPerKilogram(-value), -quantity); + } + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs b/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs new file mode 100644 index 0000000000..b271cb63c2 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs @@ -0,0 +1,1030 @@ +//------------------------------------------------------------------------------ +// +// 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.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Linq; +using System.Runtime.Serialization; +using UnitsNet.InternalHelpers; +using UnitsNet.Units; + +#nullable enable + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// Radiation exposure is a measure of the ionization of air due to ionizing radiation from photons. + /// + [DataContract] + public readonly partial struct RadiationExposure : + IArithmeticQuantity, + IComparable, + IComparable, + IConvertible, + IEquatable, + IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + [DataMember(Name = "Value", Order = 0)] + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + [DataMember(Name = "Unit", Order = 1)] + private readonly RadiationExposureUnit? _unit; + + static RadiationExposure() + { + BaseDimensions = new BaseDimensions(0, -1, 1, 1, 0, 0, 0); + BaseUnit = RadiationExposureUnit.CoulombPerKilogram; + Units = Enum.GetValues(typeof(RadiationExposureUnit)).Cast().ToArray(); + Zero = new RadiationExposure(0, BaseUnit); + Info = new QuantityInfo("RadiationExposure", + new UnitInfo[] + { + new UnitInfo(RadiationExposureUnit.CoulombPerKilogram, "CoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "RadiationExposure"), + new UnitInfo(RadiationExposureUnit.MicrocoulombPerKilogram, "MicrocoulombsPerKilogram", BaseUnits.Undefined, "RadiationExposure"), + new UnitInfo(RadiationExposureUnit.MillicoulombPerKilogram, "MillicoulombsPerKilogram", BaseUnits.Undefined, "RadiationExposure"), + new UnitInfo(RadiationExposureUnit.NanocoulombPerKilogram, "NanocoulombsPerKilogram", BaseUnits.Undefined, "RadiationExposure"), + new UnitInfo(RadiationExposureUnit.PicocoulombPerKilogram, "PicocoulombsPerKilogram", BaseUnits.Undefined, "RadiationExposure"), + new UnitInfo(RadiationExposureUnit.Roentgen, "Roentgens", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "RadiationExposure"), + }, + BaseUnit, Zero, BaseDimensions); + + DefaultConversionFunctions = new UnitConverter(); + RegisterDefaultConversions(DefaultConversionFunctions); + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to construct this quantity with. + /// The unit representation to construct this quantity with. + /// If value is NaN or Infinity. + public RadiationExposure(double value, RadiationExposureUnit 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 RadiationExposure(double value, UnitSystem unitSystem) + { + if (unitSystem is null) throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + var firstUnitInfo = unitInfos.FirstOrDefault(); + + _value = Guard.EnsureValidNumber(value, nameof(value)); + _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + } + + #region Static Properties + + /// + /// The containing the default generated conversion functions for instances. + /// + public static UnitConverter DefaultConversionFunctions { get; } + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of RadiationExposure, which is CoulombPerKilogram. All conversions go via this value. + /// + public static RadiationExposureUnit BaseUnit { get; } + + /// + /// All units of measurement for the RadiationExposure quantity. + /// + public static RadiationExposureUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit CoulombPerKilogram. + /// + public static RadiationExposure Zero { get; } + + /// + public static RadiationExposure AdditiveIdentity => Zero; + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + QuantityValue IQuantity.Value => _value; + + Enum IQuantity.Unit => Unit; + + /// + public RadiationExposureUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => RadiationExposure.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double CoulombsPerKilogram => As(RadiationExposureUnit.CoulombPerKilogram); + + /// + /// Gets a value of this quantity converted into + /// + public double MicrocoulombsPerKilogram => As(RadiationExposureUnit.MicrocoulombPerKilogram); + + /// + /// Gets a value of this quantity converted into + /// + public double MillicoulombsPerKilogram => As(RadiationExposureUnit.MillicoulombPerKilogram); + + /// + /// Gets a value of this quantity converted into + /// + public double NanocoulombsPerKilogram => As(RadiationExposureUnit.NanocoulombPerKilogram); + + /// + /// Gets a value of this quantity converted into + /// + public double PicocoulombsPerKilogram => As(RadiationExposureUnit.PicocoulombPerKilogram); + + /// + /// Gets a value of this quantity converted into + /// + public double Roentgens => As(RadiationExposureUnit.Roentgen); + + #endregion + + #region Static Methods + + /// + /// Registers the default conversion functions in the given instance. + /// + /// The to register the default conversion functions in. + internal static void RegisterDefaultConversions(UnitConverter unitConverter) + { + // Register in unit converter: RadiationExposureUnit -> BaseUnit + unitConverter.SetConversionFunction(RadiationExposureUnit.MicrocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.MillicoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.NanocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.PicocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.Roentgen, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity); + + // Register in unit converter: BaseUnit -> RadiationExposureUnit + unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.MicrocoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.MicrocoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.MillicoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.MillicoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.NanocoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.NanocoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.PicocoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.PicocoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.Roentgen, quantity => quantity.ToUnit(RadiationExposureUnit.Roentgen)); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(RadiationExposureUnit 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(RadiationExposureUnit unit, IFormatProvider? provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromCoulombsPerKilogram(QuantityValue coulombsperkilogram) + { + double value = (double) coulombsperkilogram; + return new RadiationExposure(value, RadiationExposureUnit.CoulombPerKilogram); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromMicrocoulombsPerKilogram(QuantityValue microcoulombsperkilogram) + { + double value = (double) microcoulombsperkilogram; + return new RadiationExposure(value, RadiationExposureUnit.MicrocoulombPerKilogram); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromMillicoulombsPerKilogram(QuantityValue millicoulombsperkilogram) + { + double value = (double) millicoulombsperkilogram; + return new RadiationExposure(value, RadiationExposureUnit.MillicoulombPerKilogram); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromNanocoulombsPerKilogram(QuantityValue nanocoulombsperkilogram) + { + double value = (double) nanocoulombsperkilogram; + return new RadiationExposure(value, RadiationExposureUnit.NanocoulombPerKilogram); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromPicocoulombsPerKilogram(QuantityValue picocoulombsperkilogram) + { + double value = (double) picocoulombsperkilogram; + return new RadiationExposure(value, RadiationExposureUnit.PicocoulombPerKilogram); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromRoentgens(QuantityValue roentgens) + { + double value = (double) roentgens; + return new RadiationExposure(value, RadiationExposureUnit.Roentgen); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// RadiationExposure unit value. + public static RadiationExposure From(QuantityValue value, RadiationExposureUnit fromUnit) + { + return new RadiationExposure((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", CultureInfo.GetCultureInfo("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 RadiationExposure 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", CultureInfo.GetCultureInfo("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 RadiationExposure Parse(string str, IFormatProvider? provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", CultureInfo.GetCultureInfo("en-US")); + /// + public static bool TryParse(string? str, out RadiationExposure 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", CultureInfo.GetCultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParse(string? str, IFormatProvider? provider, out RadiationExposure 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", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static RadiationExposureUnit 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", CultureInfo.GetCultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static RadiationExposureUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out RadiationExposureUnit 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", CultureInfo.GetCultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, IFormatProvider? provider, out RadiationExposureUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static RadiationExposure operator -(RadiationExposure right) + { + return new RadiationExposure(-right.Value, right.Unit); + } + + /// Get from adding two . + public static RadiationExposure operator +(RadiationExposure left, RadiationExposure right) + { + return new RadiationExposure(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static RadiationExposure operator -(RadiationExposure left, RadiationExposure right) + { + return new RadiationExposure(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static RadiationExposure operator *(double left, RadiationExposure right) + { + return new RadiationExposure(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static RadiationExposure operator *(RadiationExposure left, double right) + { + return new RadiationExposure(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static RadiationExposure operator /(RadiationExposure left, double right) + { + return new RadiationExposure(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(RadiationExposure left, RadiationExposure right) + { + return left.CoulombsPerKilogram / right.CoulombsPerKilogram; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(RadiationExposure left, RadiationExposure right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(RadiationExposure left, RadiationExposure right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(RadiationExposure left, RadiationExposure right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(RadiationExposure left, RadiationExposure right) + { + return left.Value > right.ToUnit(left.Unit).Value; + } + + // We use obsolete attribute to communicate the preferred equality members to use. + // CS0809: Obsolete member 'memberA' overrides non-obsolete member 'memberB'. + #pragma warning disable CS0809 + + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RadiationExposure other, RadiationExposure tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] + public static bool operator ==(RadiationExposure left, RadiationExposure right) + { + return left.Equals(right); + } + + /// Indicates strict inequality of two quantities, where both and are exactly equal. + [Obsolete("For null checks, use `x is null` syntax to not invoke overloads. For equality checks, use Equals(RadiationExposure other, RadiationExposure tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] + public static bool operator !=(RadiationExposure left, RadiationExposure right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(RadiationExposure other, RadiationExposure tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] + public override bool Equals(object? obj) + { + if (obj is null || !(obj is RadiationExposure otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(RadiationExposure other, RadiationExposure tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] + public bool Equals(RadiationExposure other) + { + return new { Value, Unit }.Equals(new { other.Value, other.Unit }); + } + + #pragma warning restore CS0809 + + /// Compares the current with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// An object to compare with this instance. + /// + /// is not the same type as this instance. + /// + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// + public int CompareTo(object? obj) + { + if (obj is null) throw new ArgumentNullException(nameof(obj)); + if (!(obj is RadiationExposure otherQuantity)) throw new ArgumentException("Expected type RadiationExposure.", nameof(obj)); + + return CompareTo(otherQuantity); + } + + /// Compares the current with another and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other when converted to the same unit. + /// A quantity to compare with this instance. + /// A value that indicates the relative order of the quantities being compared. The return value has these meanings: + /// + /// Value Meaning + /// Less than zero This instance precedes in the sort order. + /// Zero This instance occurs in the same position in the sort order as . + /// Greater than zero This instance follows in the sort order. + /// + /// + public int CompareTo(RadiationExposure other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another RadiationExposure 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 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. + [Obsolete("Use Equals(RadiationExposure other, RadiationExposure tolerance) instead, to check equality across units and to specify the max tolerance for rounding errors due to floating-point arithmetic when converting between units.")] + public bool Equals(RadiationExposure other, double tolerance, ComparisonType comparisonType) + { + if (tolerance < 0) + throw new ArgumentOutOfRangeException(nameof(tolerance), "Tolerance must be greater than or equal to 0."); + + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance, + comparisonType: ComparisonType.Absolute); + } + + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is RadiationExposure otherTyped + && (tolerance is RadiationExposure toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'RadiationExposure'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(RadiationExposure other, RadiationExposure tolerance) + { + return UnitsNet.Comparison.Equals( + referenceValue: this.Value, + otherValue: other.As(this.Unit), + tolerance: tolerance.As(this.Unit), + comparisonType: ComparisonType.Absolute); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current RadiationExposure. + public override int GetHashCode() + { + return new { Info.Name, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(RadiationExposureUnit unit) + { + if (Unit == unit) + return Value; + + return ToUnit(unit).Value; + } + + /// + public double As(UnitSystem unitSystem) + { + if (unitSystem is null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if (firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return As(firstUnitInfo.Value); + } + + /// + double IQuantity.As(Enum unit) + { + if (!(unit is RadiationExposureUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationExposureUnit)} is supported.", nameof(unit)); + + return (double)As(typedUnit); + } + + /// + double IValueQuantity.As(Enum unit) + { + if (!(unit is RadiationExposureUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationExposureUnit)} is supported.", nameof(unit)); + + return As(typedUnit); + } + + /// + /// Converts this RadiationExposure to another RadiationExposure with the unit representation . + /// + /// The unit to convert to. + /// A RadiationExposure with the specified unit. + public RadiationExposure ToUnit(RadiationExposureUnit unit) + { + return ToUnit(unit, DefaultConversionFunctions); + } + + /// + /// Converts this to another using the given with the unit representation . + /// + /// The unit to convert to. + /// The to use for the conversion. + /// A RadiationExposure with the specified unit. + public RadiationExposure ToUnit(RadiationExposureUnit unit, UnitConverter unitConverter) + { + if (TryToUnit(unit, out var converted)) + { + // Try to convert using the auto-generated conversion methods. + return converted!.Value; + } + else if (unitConverter.TryGetConversionFunction((typeof(RadiationExposure), Unit, typeof(RadiationExposure), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (RadiationExposure)conversionFunction(this); + } + else if (Unit != BaseUnit) + { + // Conversion to requested unit NOT found. Try to convert to BaseUnit, and then from BaseUnit to requested unit. + var inBaseUnits = ToUnit(BaseUnit); + return inBaseUnits.ToUnit(unit); + } + else + { + // No possible conversion + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + /// + /// Attempts to convert this to another with the unit representation . + /// + /// The unit to convert to. + /// The converted in , if successful. + /// True if successful, otherwise false. + private bool TryToUnit(RadiationExposureUnit unit, [NotNullWhen(true)] out RadiationExposure? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + RadiationExposure? convertedOrNull = (Unit, unit) switch + { + // RadiationExposureUnit -> BaseUnit + (RadiationExposureUnit.MicrocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure((_value) * 1e-6d, RadiationExposureUnit.CoulombPerKilogram), + (RadiationExposureUnit.MillicoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure((_value) * 1e-3d, RadiationExposureUnit.CoulombPerKilogram), + (RadiationExposureUnit.NanocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure((_value) * 1e-9d, RadiationExposureUnit.CoulombPerKilogram), + (RadiationExposureUnit.PicocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure((_value) * 1e-12d, RadiationExposureUnit.CoulombPerKilogram), + (RadiationExposureUnit.Roentgen, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure(_value * 2.58e-4, RadiationExposureUnit.CoulombPerKilogram), + + // BaseUnit -> RadiationExposureUnit + (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.MicrocoulombPerKilogram) => new RadiationExposure((_value) / 1e-6d, RadiationExposureUnit.MicrocoulombPerKilogram), + (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.MillicoulombPerKilogram) => new RadiationExposure((_value) / 1e-3d, RadiationExposureUnit.MillicoulombPerKilogram), + (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.NanocoulombPerKilogram) => new RadiationExposure((_value) / 1e-9d, RadiationExposureUnit.NanocoulombPerKilogram), + (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.PicocoulombPerKilogram) => new RadiationExposure((_value) / 1e-12d, RadiationExposureUnit.PicocoulombPerKilogram), + (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.Roentgen) => new RadiationExposure(_value / 2.58e-4, RadiationExposureUnit.Roentgen), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is RadiationExposureUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationExposureUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public RadiationExposure ToUnit(UnitSystem unitSystem) + { + if (unitSystem is null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if (firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return ToUnit(firstUnitInfo.Value); + } + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + IQuantity IQuantity.ToUnit(RadiationExposureUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + IValueQuantity IValueQuantity.ToUnit(Enum unit) + { + if (unit is not RadiationExposureUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(RadiationExposureUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit); + } + + /// + IValueQuantity IValueQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + #endregion + + #region ToString Methods + + /// + /// Gets the default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString("g"); + } + + /// + /// Gets the default string representation of value and unit using the given format provider. + /// + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + public string ToString(IFormatProvider? provider) + { + return ToString("g", provider); + } + + /// + /// + /// 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.CurrentCulture); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. + /// + /// The format string. + /// Format to use for localization and number formatting. Defaults to if null. + /// The string representation. + public string ToString(string? format, IFormatProvider? provider) + { + return QuantityFormatter.Format(this, format, provider); + } + + #endregion + + #region IConvertible Methods + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + bool IConvertible.ToBoolean(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(RadiationExposure)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(RadiationExposure)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(RadiationExposure)} 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(RadiationExposure)) + return this; + else if (conversionType == typeof(RadiationExposureUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return RadiationExposure.Info; + else if (conversionType == typeof(BaseDimensions)) + return RadiationExposure.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(RadiationExposure)} 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 08cf42aeb4..3f09a75aa4 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -122,6 +122,7 @@ public partial class Quantity { "PowerRatio", PowerRatio.Info }, { "Pressure", Pressure.Info }, { "PressureChangeRate", PressureChangeRate.Info }, + { "RadiationExposure", RadiationExposure.Info }, { "Radioactivity", Radioactivity.Info }, { "Ratio", Ratio.Info }, { "RatioChangeRate", RatioChangeRate.Info }, @@ -256,6 +257,7 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, QuantityValu "PowerRatio" => PowerRatio.From(value, PowerRatio.BaseUnit), "Pressure" => Pressure.From(value, Pressure.BaseUnit), "PressureChangeRate" => PressureChangeRate.From(value, PressureChangeRate.BaseUnit), + "RadiationExposure" => RadiationExposure.From(value, RadiationExposure.BaseUnit), "Radioactivity" => Radioactivity.From(value, Radioactivity.BaseUnit), "Ratio" => Ratio.From(value, Ratio.BaseUnit), "RatioChangeRate" => RatioChangeRate.From(value, RatioChangeRate.BaseUnit), @@ -393,6 +395,7 @@ public static bool TryFrom(QuantityValue value, Enum? unit, [NotNullWhen(true)] PowerRatioUnit powerRatioUnit => PowerRatio.From(value, powerRatioUnit), PressureUnit pressureUnit => Pressure.From(value, pressureUnit), PressureChangeRateUnit pressureChangeRateUnit => PressureChangeRate.From(value, pressureChangeRateUnit), + RadiationExposureUnit radiationExposureUnit => RadiationExposure.From(value, radiationExposureUnit), RadioactivityUnit radioactivityUnit => Radioactivity.From(value, radioactivityUnit), RatioUnit ratioUnit => Ratio.From(value, ratioUnit), RatioChangeRateUnit ratioChangeRateUnit => RatioChangeRate.From(value, ratioChangeRateUnit), @@ -540,6 +543,7 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, Type _ when quantityType == typeof(PowerRatio) => parser.TryParse(quantityString, formatProvider, PowerRatio.From, out quantity), Type _ when quantityType == typeof(Pressure) => parser.TryParse(quantityString, formatProvider, Pressure.From, out quantity), Type _ when quantityType == typeof(PressureChangeRate) => parser.TryParse(quantityString, formatProvider, PressureChangeRate.From, out quantity), + Type _ when quantityType == typeof(RadiationExposure) => parser.TryParse(quantityString, formatProvider, RadiationExposure.From, out quantity), Type _ when quantityType == typeof(Radioactivity) => parser.TryParse(quantityString, formatProvider, Radioactivity.From, out quantity), Type _ when quantityType == typeof(Ratio) => parser.TryParse(quantityString, formatProvider, Ratio.From, out quantity), Type _ when quantityType == typeof(RatioChangeRate) => parser.TryParse(quantityString, formatProvider, RatioChangeRate.From, out quantity), @@ -668,6 +672,7 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(PowerRatio); yield return typeof(Pressure); yield return typeof(PressureChangeRate); + yield return typeof(RadiationExposure); yield return typeof(Radioactivity); yield return typeof(Ratio); yield return typeof(RatioChangeRate); diff --git a/UnitsNet/GeneratedCode/Resources/RadiationExposure.restext b/UnitsNet/GeneratedCode/Resources/RadiationExposure.restext new file mode 100644 index 0000000000..68f0eacb08 --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/RadiationExposure.restext @@ -0,0 +1,6 @@ +CoulombsPerKilogram=C/kg +MicrocoulombsPerKilogram=µC/kg +MillicoulombsPerKilogram=mC/kg +NanocoulombsPerKilogram=nC/kg +PicocoulombsPerKilogram=pC/kg +Roentgens=R diff --git a/UnitsNet/GeneratedCode/Units/RadiationExposureUnit.g.cs b/UnitsNet/GeneratedCode/Units/RadiationExposureUnit.g.cs new file mode 100644 index 0000000000..75b4669f79 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/RadiationExposureUnit.g.cs @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// 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 RadiationExposureUnit + { + CoulombPerKilogram = 10, + MicrocoulombPerKilogram = 3, + MillicoulombPerKilogram = 2, + NanocoulombPerKilogram = 6, + PicocoulombPerKilogram = 5, + Roentgen = 4, + } + + #pragma warning restore 1591 +} From c9c8b5988e2ea426f8c3312fd358ffe947d2a1ad Mon Sep 17 00:00:00 2001 From: Piotr Stenke Date: Tue, 2 Jan 2024 15:37:38 +0100 Subject: [PATCH 4/5] Add prefixes to Roentgen --- Common/UnitDefinitions/RadiationExposure.json | 1 + 1 file changed, 1 insertion(+) diff --git a/Common/UnitDefinitions/RadiationExposure.json b/Common/UnitDefinitions/RadiationExposure.json index fe0304ace8..6684939d72 100644 --- a/Common/UnitDefinitions/RadiationExposure.json +++ b/Common/UnitDefinitions/RadiationExposure.json @@ -32,6 +32,7 @@ "PluralName": "Roentgens", "FromUnitToBaseFunc": "{x} * 2.58e-4", "FromBaseToUnitFunc": "{x} / 2.58e-4", + "Prefixes": [ "Micro", "Milli" ], "BaseUnits": { "M": "Kilogram", "T": "Second", From e6cd503b38efbb966675fbaf0acb6cc22514d1b0 Mon Sep 17 00:00:00 2001 From: Piotr Stenke Date: Tue, 2 Jan 2024 15:43:21 +0100 Subject: [PATCH 5/5] Run codegen with new prefixes --- Common/UnitEnumValues.g.json | 4 +- .../Quantities/RadiationExposure.g.cs | 26 +++++ .../Units/RadiationExposureUnit.g.cs | 2 + ...mberToRadiationExposureExtensionsTest.g.cs | 8 ++ .../NumberToRadiationExposureExtensions.g.cs | 16 +++ .../CustomCode/RadiationExposureTests.cs | 2 + .../TestsBase/RadiationExposureTestsBase.g.cs | 98 ++++++++++++++++--- .../Quantities/RadiationExposure.g.cs | 40 ++++++++ .../Resources/RadiationExposure.restext | 2 + .../Units/RadiationExposureUnit.g.cs | 2 + 10 files changed, 187 insertions(+), 13 deletions(-) diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index a301670164..4d909db5bb 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -1832,6 +1832,8 @@ "MillicoulombPerKilogram": 2, "NanocoulombPerKilogram": 6, "PicocoulombPerKilogram": 5, - "Roentgen": 4 + "Roentgen": 4, + "Microroentgen": 12, + "Milliroentgen": 13 } } diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/RadiationExposure.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/RadiationExposure.g.cs index 699b2fba55..73ea4a7735 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Quantities/RadiationExposure.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/RadiationExposure.g.cs @@ -89,11 +89,21 @@ public RadiationExposure(double value, RadiationExposureUnit unit) /// public double MicrocoulombsPerKilogram => As(RadiationExposureUnit.MicrocoulombPerKilogram); + /// + /// Gets a value of this quantity converted into + /// + public double Microroentgens => As(RadiationExposureUnit.Microroentgen); + /// /// Gets a value of this quantity converted into /// public double MillicoulombsPerKilogram => As(RadiationExposureUnit.MillicoulombPerKilogram); + /// + /// Gets a value of this quantity converted into + /// + public double Milliroentgens => As(RadiationExposureUnit.Milliroentgen); + /// /// Gets a value of this quantity converted into /// @@ -125,12 +135,24 @@ public RadiationExposure(double value, RadiationExposureUnit unit) /// If value is NaN or Infinity. public static RadiationExposure FromMicrocoulombsPerKilogram(double microcoulombsperkilogram) => new RadiationExposure(microcoulombsperkilogram, RadiationExposureUnit.MicrocoulombPerKilogram); + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromMicroroentgens(double microroentgens) => new RadiationExposure(microroentgens, RadiationExposureUnit.Microroentgen); + /// /// Creates a from . /// /// If value is NaN or Infinity. public static RadiationExposure FromMillicoulombsPerKilogram(double millicoulombsperkilogram) => new RadiationExposure(millicoulombsperkilogram, RadiationExposureUnit.MillicoulombPerKilogram); + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromMilliroentgens(double milliroentgens) => new RadiationExposure(milliroentgens, RadiationExposureUnit.Milliroentgen); + /// /// Creates a from . /// @@ -191,7 +213,9 @@ private double GetValueInBaseUnit() { RadiationExposureUnit.CoulombPerKilogram => _value, RadiationExposureUnit.MicrocoulombPerKilogram => (_value) * 1e-6d, + RadiationExposureUnit.Microroentgen => (_value * 2.58e-4) * 1e-6d, RadiationExposureUnit.MillicoulombPerKilogram => (_value) * 1e-3d, + RadiationExposureUnit.Milliroentgen => (_value * 2.58e-4) * 1e-3d, RadiationExposureUnit.NanocoulombPerKilogram => (_value) * 1e-9d, RadiationExposureUnit.PicocoulombPerKilogram => (_value) * 1e-12d, RadiationExposureUnit.Roentgen => _value * 2.58e-4, @@ -210,7 +234,9 @@ private double GetValueAs(RadiationExposureUnit unit) { RadiationExposureUnit.CoulombPerKilogram => baseUnitValue, RadiationExposureUnit.MicrocoulombPerKilogram => (baseUnitValue) / 1e-6d, + RadiationExposureUnit.Microroentgen => (baseUnitValue / 2.58e-4) / 1e-6d, RadiationExposureUnit.MillicoulombPerKilogram => (baseUnitValue) / 1e-3d, + RadiationExposureUnit.Milliroentgen => (baseUnitValue / 2.58e-4) / 1e-3d, RadiationExposureUnit.NanocoulombPerKilogram => (baseUnitValue) / 1e-9d, RadiationExposureUnit.PicocoulombPerKilogram => (baseUnitValue) / 1e-12d, RadiationExposureUnit.Roentgen => baseUnitValue / 2.58e-4, diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/RadiationExposureUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/RadiationExposureUnit.g.cs index 75b4669f79..8e50cdd24f 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/Units/RadiationExposureUnit.g.cs +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/RadiationExposureUnit.g.cs @@ -27,7 +27,9 @@ public enum RadiationExposureUnit { CoulombPerKilogram = 10, MicrocoulombPerKilogram = 3, + Microroentgen = 12, MillicoulombPerKilogram = 2, + Milliroentgen = 13, NanocoulombPerKilogram = 6, PicocoulombPerKilogram = 5, Roentgen = 4, diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToRadiationExposureExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToRadiationExposureExtensionsTest.g.cs index 1d6989d721..e8906260d3 100644 --- a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToRadiationExposureExtensionsTest.g.cs +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToRadiationExposureExtensionsTest.g.cs @@ -32,10 +32,18 @@ public void NumberToCoulombsPerKilogramTest() => public void NumberToMicrocoulombsPerKilogramTest() => Assert.Equal(RadiationExposure.FromMicrocoulombsPerKilogram(2), 2.MicrocoulombsPerKilogram()); + [Fact] + public void NumberToMicroroentgensTest() => + Assert.Equal(RadiationExposure.FromMicroroentgens(2), 2.Microroentgens()); + [Fact] public void NumberToMillicoulombsPerKilogramTest() => Assert.Equal(RadiationExposure.FromMillicoulombsPerKilogram(2), 2.MillicoulombsPerKilogram()); + [Fact] + public void NumberToMilliroentgensTest() => + Assert.Equal(RadiationExposure.FromMilliroentgens(2), 2.Milliroentgens()); + [Fact] public void NumberToNanocoulombsPerKilogramTest() => Assert.Equal(RadiationExposure.FromNanocoulombsPerKilogram(2), 2.NanocoulombsPerKilogram()); diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToRadiationExposureExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToRadiationExposureExtensions.g.cs index 1e8a9610bf..d24f2b7f0a 100644 --- a/UnitsNet.NumberExtensions/GeneratedCode/NumberToRadiationExposureExtensions.g.cs +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToRadiationExposureExtensions.g.cs @@ -48,6 +48,14 @@ public static RadiationExposure MicrocoulombsPerKilogram(this T value) #endif => RadiationExposure.FromMicrocoulombsPerKilogram(Convert.ToDouble(value)); + /// + public static RadiationExposure Microroentgens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => RadiationExposure.FromMicroroentgens(Convert.ToDouble(value)); + /// public static RadiationExposure MillicoulombsPerKilogram(this T value) where T : notnull @@ -56,6 +64,14 @@ public static RadiationExposure MillicoulombsPerKilogram(this T value) #endif => RadiationExposure.FromMillicoulombsPerKilogram(Convert.ToDouble(value)); + /// + public static RadiationExposure Milliroentgens(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => RadiationExposure.FromMilliroentgens(Convert.ToDouble(value)); + /// public static RadiationExposure NanocoulombsPerKilogram(this T value) where T : notnull diff --git a/UnitsNet.Tests/CustomCode/RadiationExposureTests.cs b/UnitsNet.Tests/CustomCode/RadiationExposureTests.cs index d3bf3e52fb..19b52baf95 100644 --- a/UnitsNet.Tests/CustomCode/RadiationExposureTests.cs +++ b/UnitsNet.Tests/CustomCode/RadiationExposureTests.cs @@ -14,5 +14,7 @@ public class RadiationExposureTests : RadiationExposureTestsBase protected override double NanocoulombsPerKilogramInOneCoulombPerKilogram => 1e+9; protected override double PicocoulombsPerKilogramInOneCoulombPerKilogram => 1e+12; protected override double RoentgensInOneCoulombPerKilogram => 3875.9689922; + protected override double MilliroentgensInOneCoulombPerKilogram => 3875.9689922e+3; + protected override double MicroroentgensInOneCoulombPerKilogram => 3875.9689922e+6; } } diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs index 34b1ab9a1c..31f2bf9527 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs @@ -40,7 +40,9 @@ public abstract partial class RadiationExposureTestsBase : QuantityTestsBase { protected abstract double CoulombsPerKilogramInOneCoulombPerKilogram { get; } protected abstract double MicrocoulombsPerKilogramInOneCoulombPerKilogram { get; } + protected abstract double MicroroentgensInOneCoulombPerKilogram { get; } protected abstract double MillicoulombsPerKilogramInOneCoulombPerKilogram { get; } + protected abstract double MilliroentgensInOneCoulombPerKilogram { get; } protected abstract double NanocoulombsPerKilogramInOneCoulombPerKilogram { get; } protected abstract double PicocoulombsPerKilogramInOneCoulombPerKilogram { get; } protected abstract double RoentgensInOneCoulombPerKilogram { get; } @@ -48,7 +50,9 @@ public abstract partial class RadiationExposureTestsBase : QuantityTestsBase // ReSharper disable VirtualMemberNeverOverriden.Global protected virtual double CoulombsPerKilogramTolerance { get { return 1e-5; } } protected virtual double MicrocoulombsPerKilogramTolerance { get { return 1e-5; } } + protected virtual double MicroroentgensTolerance { get { return 1e-5; } } protected virtual double MillicoulombsPerKilogramTolerance { get { return 1e-5; } } + protected virtual double MilliroentgensTolerance { get { return 1e-5; } } protected virtual double NanocoulombsPerKilogramTolerance { get { return 1e-5; } } protected virtual double PicocoulombsPerKilogramTolerance { get { return 1e-5; } } protected virtual double RoentgensTolerance { get { return 1e-5; } } @@ -60,7 +64,9 @@ public abstract partial class RadiationExposureTestsBase : QuantityTestsBase { RadiationExposureUnit.CoulombPerKilogram => (CoulombsPerKilogramInOneCoulombPerKilogram, CoulombsPerKilogramTolerance), RadiationExposureUnit.MicrocoulombPerKilogram => (MicrocoulombsPerKilogramInOneCoulombPerKilogram, MicrocoulombsPerKilogramTolerance), + RadiationExposureUnit.Microroentgen => (MicroroentgensInOneCoulombPerKilogram, MicroroentgensTolerance), RadiationExposureUnit.MillicoulombPerKilogram => (MillicoulombsPerKilogramInOneCoulombPerKilogram, MillicoulombsPerKilogramTolerance), + RadiationExposureUnit.Milliroentgen => (MilliroentgensInOneCoulombPerKilogram, MilliroentgensTolerance), RadiationExposureUnit.NanocoulombPerKilogram => (NanocoulombsPerKilogramInOneCoulombPerKilogram, NanocoulombsPerKilogramTolerance), RadiationExposureUnit.PicocoulombPerKilogram => (PicocoulombsPerKilogramInOneCoulombPerKilogram, PicocoulombsPerKilogramTolerance), RadiationExposureUnit.Roentgen => (RoentgensInOneCoulombPerKilogram, RoentgensTolerance), @@ -72,7 +78,9 @@ public abstract partial class RadiationExposureTestsBase : QuantityTestsBase { new object[] { RadiationExposureUnit.CoulombPerKilogram }, new object[] { RadiationExposureUnit.MicrocoulombPerKilogram }, + new object[] { RadiationExposureUnit.Microroentgen }, new object[] { RadiationExposureUnit.MillicoulombPerKilogram }, + new object[] { RadiationExposureUnit.Milliroentgen }, new object[] { RadiationExposureUnit.NanocoulombPerKilogram }, new object[] { RadiationExposureUnit.PicocoulombPerKilogram }, new object[] { RadiationExposureUnit.Roentgen }, @@ -140,7 +148,9 @@ public void CoulombPerKilogramToRadiationExposureUnits() RadiationExposure coulombperkilogram = RadiationExposure.FromCoulombsPerKilogram(1); AssertEx.EqualTolerance(CoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.CoulombsPerKilogram, CoulombsPerKilogramTolerance); AssertEx.EqualTolerance(MicrocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.MicrocoulombsPerKilogram, MicrocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(MicroroentgensInOneCoulombPerKilogram, coulombperkilogram.Microroentgens, MicroroentgensTolerance); AssertEx.EqualTolerance(MillicoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.MillicoulombsPerKilogram, MillicoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(MilliroentgensInOneCoulombPerKilogram, coulombperkilogram.Milliroentgens, MilliroentgensTolerance); AssertEx.EqualTolerance(NanocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.NanocoulombsPerKilogram, NanocoulombsPerKilogramTolerance); AssertEx.EqualTolerance(PicocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.PicocoulombsPerKilogram, PicocoulombsPerKilogramTolerance); AssertEx.EqualTolerance(RoentgensInOneCoulombPerKilogram, coulombperkilogram.Roentgens, RoentgensTolerance); @@ -157,21 +167,29 @@ public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() AssertEx.EqualTolerance(1, quantity01.MicrocoulombsPerKilogram, MicrocoulombsPerKilogramTolerance); Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, quantity01.Unit); - var quantity02 = RadiationExposure.From(1, RadiationExposureUnit.MillicoulombPerKilogram); - AssertEx.EqualTolerance(1, quantity02.MillicoulombsPerKilogram, MillicoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, quantity02.Unit); + var quantity02 = RadiationExposure.From(1, RadiationExposureUnit.Microroentgen); + AssertEx.EqualTolerance(1, quantity02.Microroentgens, MicroroentgensTolerance); + Assert.Equal(RadiationExposureUnit.Microroentgen, quantity02.Unit); - var quantity03 = RadiationExposure.From(1, RadiationExposureUnit.NanocoulombPerKilogram); - AssertEx.EqualTolerance(1, quantity03.NanocoulombsPerKilogram, NanocoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, quantity03.Unit); + var quantity03 = RadiationExposure.From(1, RadiationExposureUnit.MillicoulombPerKilogram); + AssertEx.EqualTolerance(1, quantity03.MillicoulombsPerKilogram, MillicoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, quantity03.Unit); - var quantity04 = RadiationExposure.From(1, RadiationExposureUnit.PicocoulombPerKilogram); - AssertEx.EqualTolerance(1, quantity04.PicocoulombsPerKilogram, PicocoulombsPerKilogramTolerance); - Assert.Equal(RadiationExposureUnit.PicocoulombPerKilogram, quantity04.Unit); + var quantity04 = RadiationExposure.From(1, RadiationExposureUnit.Milliroentgen); + AssertEx.EqualTolerance(1, quantity04.Milliroentgens, MilliroentgensTolerance); + Assert.Equal(RadiationExposureUnit.Milliroentgen, quantity04.Unit); - var quantity05 = RadiationExposure.From(1, RadiationExposureUnit.Roentgen); - AssertEx.EqualTolerance(1, quantity05.Roentgens, RoentgensTolerance); - Assert.Equal(RadiationExposureUnit.Roentgen, quantity05.Unit); + var quantity05 = RadiationExposure.From(1, RadiationExposureUnit.NanocoulombPerKilogram); + AssertEx.EqualTolerance(1, quantity05.NanocoulombsPerKilogram, NanocoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, quantity05.Unit); + + var quantity06 = RadiationExposure.From(1, RadiationExposureUnit.PicocoulombPerKilogram); + AssertEx.EqualTolerance(1, quantity06.PicocoulombsPerKilogram, PicocoulombsPerKilogramTolerance); + Assert.Equal(RadiationExposureUnit.PicocoulombPerKilogram, quantity06.Unit); + + var quantity07 = RadiationExposure.From(1, RadiationExposureUnit.Roentgen); + AssertEx.EqualTolerance(1, quantity07.Roentgens, RoentgensTolerance); + Assert.Equal(RadiationExposureUnit.Roentgen, quantity07.Unit); } @@ -194,7 +212,9 @@ public void As() var coulombperkilogram = RadiationExposure.FromCoulombsPerKilogram(1); AssertEx.EqualTolerance(CoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.CoulombPerKilogram), CoulombsPerKilogramTolerance); AssertEx.EqualTolerance(MicrocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.MicrocoulombPerKilogram), MicrocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(MicroroentgensInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.Microroentgen), MicroroentgensTolerance); AssertEx.EqualTolerance(MillicoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.MillicoulombPerKilogram), MillicoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(MilliroentgensInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.Milliroentgen), MilliroentgensTolerance); AssertEx.EqualTolerance(NanocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.NanocoulombPerKilogram), NanocoulombsPerKilogramTolerance); AssertEx.EqualTolerance(PicocoulombsPerKilogramInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.PicocoulombPerKilogram), PicocoulombsPerKilogramTolerance); AssertEx.EqualTolerance(RoentgensInOneCoulombPerKilogram, coulombperkilogram.As(RadiationExposureUnit.Roentgen), RoentgensTolerance); @@ -234,6 +254,13 @@ public void Parse() Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = RadiationExposure.Parse("1 µR", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Microroentgens, MicroroentgensTolerance); + Assert.Equal(RadiationExposureUnit.Microroentgen, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = RadiationExposure.Parse("1 mC/kg", CultureInfo.GetCultureInfo("en-US")); @@ -241,6 +268,13 @@ public void Parse() Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = RadiationExposure.Parse("1 mR", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.Milliroentgens, MilliroentgensTolerance); + Assert.Equal(RadiationExposureUnit.Milliroentgen, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = RadiationExposure.Parse("1 nC/kg", CultureInfo.GetCultureInfo("en-US")); @@ -279,12 +313,24 @@ public void TryParse() Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsed.Unit); } + { + Assert.True(RadiationExposure.TryParse("1 µR", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Microroentgens, MicroroentgensTolerance); + Assert.Equal(RadiationExposureUnit.Microroentgen, parsed.Unit); + } + { Assert.True(RadiationExposure.TryParse("1 mC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.MillicoulombsPerKilogram, MillicoulombsPerKilogramTolerance); Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsed.Unit); } + { + Assert.True(RadiationExposure.TryParse("1 mR", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.Milliroentgens, MilliroentgensTolerance); + Assert.Equal(RadiationExposureUnit.Milliroentgen, parsed.Unit); + } + { Assert.True(RadiationExposure.TryParse("1 nC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.NanocoulombsPerKilogram, NanocoulombsPerKilogramTolerance); @@ -320,12 +366,24 @@ public void ParseUnit() Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = RadiationExposure.ParseUnit("µR", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(RadiationExposureUnit.Microroentgen, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = RadiationExposure.ParseUnit("mC/kg", CultureInfo.GetCultureInfo("en-US")); Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsedUnit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsedUnit = RadiationExposure.ParseUnit("mR", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(RadiationExposureUnit.Milliroentgen, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsedUnit = RadiationExposure.ParseUnit("nC/kg", CultureInfo.GetCultureInfo("en-US")); @@ -359,11 +417,21 @@ public void TryParseUnit() Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsedUnit); } + { + Assert.True(RadiationExposure.TryParseUnit("µR", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(RadiationExposureUnit.Microroentgen, parsedUnit); + } + { Assert.True(RadiationExposure.TryParseUnit("mC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsedUnit); } + { + Assert.True(RadiationExposure.TryParseUnit("mR", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(RadiationExposureUnit.Milliroentgen, parsedUnit); + } + { Assert.True(RadiationExposure.TryParseUnit("nC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, parsedUnit); @@ -429,7 +497,9 @@ public void ConversionRoundTrip() RadiationExposure coulombperkilogram = RadiationExposure.FromCoulombsPerKilogram(1); AssertEx.EqualTolerance(1, RadiationExposure.FromCoulombsPerKilogram(coulombperkilogram.CoulombsPerKilogram).CoulombsPerKilogram, CoulombsPerKilogramTolerance); AssertEx.EqualTolerance(1, RadiationExposure.FromMicrocoulombsPerKilogram(coulombperkilogram.MicrocoulombsPerKilogram).CoulombsPerKilogram, MicrocoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(1, RadiationExposure.FromMicroroentgens(coulombperkilogram.Microroentgens).CoulombsPerKilogram, MicroroentgensTolerance); AssertEx.EqualTolerance(1, RadiationExposure.FromMillicoulombsPerKilogram(coulombperkilogram.MillicoulombsPerKilogram).CoulombsPerKilogram, MillicoulombsPerKilogramTolerance); + AssertEx.EqualTolerance(1, RadiationExposure.FromMilliroentgens(coulombperkilogram.Milliroentgens).CoulombsPerKilogram, MilliroentgensTolerance); AssertEx.EqualTolerance(1, RadiationExposure.FromNanocoulombsPerKilogram(coulombperkilogram.NanocoulombsPerKilogram).CoulombsPerKilogram, NanocoulombsPerKilogramTolerance); AssertEx.EqualTolerance(1, RadiationExposure.FromPicocoulombsPerKilogram(coulombperkilogram.PicocoulombsPerKilogram).CoulombsPerKilogram, PicocoulombsPerKilogramTolerance); AssertEx.EqualTolerance(1, RadiationExposure.FromRoentgens(coulombperkilogram.Roentgens).CoulombsPerKilogram, RoentgensTolerance); @@ -582,7 +652,9 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() try { Assert.Equal("1 C/kg", new RadiationExposure(1, RadiationExposureUnit.CoulombPerKilogram).ToString()); Assert.Equal("1 µC/kg", new RadiationExposure(1, RadiationExposureUnit.MicrocoulombPerKilogram).ToString()); + Assert.Equal("1 µR", new RadiationExposure(1, RadiationExposureUnit.Microroentgen).ToString()); Assert.Equal("1 mC/kg", new RadiationExposure(1, RadiationExposureUnit.MillicoulombPerKilogram).ToString()); + Assert.Equal("1 mR", new RadiationExposure(1, RadiationExposureUnit.Milliroentgen).ToString()); Assert.Equal("1 nC/kg", new RadiationExposure(1, RadiationExposureUnit.NanocoulombPerKilogram).ToString()); Assert.Equal("1 pC/kg", new RadiationExposure(1, RadiationExposureUnit.PicocoulombPerKilogram).ToString()); Assert.Equal("1 R", new RadiationExposure(1, RadiationExposureUnit.Roentgen).ToString()); @@ -601,7 +673,9 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture Assert.Equal("1 C/kg", new RadiationExposure(1, RadiationExposureUnit.CoulombPerKilogram).ToString(swedishCulture)); Assert.Equal("1 µC/kg", new RadiationExposure(1, RadiationExposureUnit.MicrocoulombPerKilogram).ToString(swedishCulture)); + Assert.Equal("1 µR", new RadiationExposure(1, RadiationExposureUnit.Microroentgen).ToString(swedishCulture)); Assert.Equal("1 mC/kg", new RadiationExposure(1, RadiationExposureUnit.MillicoulombPerKilogram).ToString(swedishCulture)); + Assert.Equal("1 mR", new RadiationExposure(1, RadiationExposureUnit.Milliroentgen).ToString(swedishCulture)); Assert.Equal("1 nC/kg", new RadiationExposure(1, RadiationExposureUnit.NanocoulombPerKilogram).ToString(swedishCulture)); Assert.Equal("1 pC/kg", new RadiationExposure(1, RadiationExposureUnit.PicocoulombPerKilogram).ToString(swedishCulture)); Assert.Equal("1 R", new RadiationExposure(1, RadiationExposureUnit.Roentgen).ToString(swedishCulture)); diff --git a/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs b/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs index b271cb63c2..ef1853eca5 100644 --- a/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs @@ -67,7 +67,9 @@ static RadiationExposure() { new UnitInfo(RadiationExposureUnit.CoulombPerKilogram, "CoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "RadiationExposure"), new UnitInfo(RadiationExposureUnit.MicrocoulombPerKilogram, "MicrocoulombsPerKilogram", BaseUnits.Undefined, "RadiationExposure"), + new UnitInfo(RadiationExposureUnit.Microroentgen, "Microroentgens", BaseUnits.Undefined, "RadiationExposure"), new UnitInfo(RadiationExposureUnit.MillicoulombPerKilogram, "MillicoulombsPerKilogram", BaseUnits.Undefined, "RadiationExposure"), + new UnitInfo(RadiationExposureUnit.Milliroentgen, "Milliroentgens", BaseUnits.Undefined, "RadiationExposure"), new UnitInfo(RadiationExposureUnit.NanocoulombPerKilogram, "NanocoulombsPerKilogram", BaseUnits.Undefined, "RadiationExposure"), new UnitInfo(RadiationExposureUnit.PicocoulombPerKilogram, "PicocoulombsPerKilogram", BaseUnits.Undefined, "RadiationExposure"), new UnitInfo(RadiationExposureUnit.Roentgen, "Roentgens", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "RadiationExposure"), @@ -184,11 +186,21 @@ public RadiationExposure(double value, UnitSystem unitSystem) /// public double MicrocoulombsPerKilogram => As(RadiationExposureUnit.MicrocoulombPerKilogram); + /// + /// Gets a value of this quantity converted into + /// + public double Microroentgens => As(RadiationExposureUnit.Microroentgen); + /// /// Gets a value of this quantity converted into /// public double MillicoulombsPerKilogram => As(RadiationExposureUnit.MillicoulombPerKilogram); + /// + /// Gets a value of this quantity converted into + /// + public double Milliroentgens => As(RadiationExposureUnit.Milliroentgen); + /// /// Gets a value of this quantity converted into /// @@ -216,7 +228,9 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) { // Register in unit converter: RadiationExposureUnit -> BaseUnit unitConverter.SetConversionFunction(RadiationExposureUnit.MicrocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.Microroentgen, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); unitConverter.SetConversionFunction(RadiationExposureUnit.MillicoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.Milliroentgen, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); unitConverter.SetConversionFunction(RadiationExposureUnit.NanocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); unitConverter.SetConversionFunction(RadiationExposureUnit.PicocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); unitConverter.SetConversionFunction(RadiationExposureUnit.Roentgen, RadiationExposureUnit.CoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.CoulombPerKilogram)); @@ -226,7 +240,9 @@ internal static void RegisterDefaultConversions(UnitConverter unitConverter) // Register in unit converter: BaseUnit -> RadiationExposureUnit unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.MicrocoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.MicrocoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.Microroentgen, quantity => quantity.ToUnit(RadiationExposureUnit.Microroentgen)); unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.MillicoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.MillicoulombPerKilogram)); + unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.Milliroentgen, quantity => quantity.ToUnit(RadiationExposureUnit.Milliroentgen)); unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.NanocoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.NanocoulombPerKilogram)); unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.PicocoulombPerKilogram, quantity => quantity.ToUnit(RadiationExposureUnit.PicocoulombPerKilogram)); unitConverter.SetConversionFunction(RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.Roentgen, quantity => quantity.ToUnit(RadiationExposureUnit.Roentgen)); @@ -277,6 +293,16 @@ public static RadiationExposure FromMicrocoulombsPerKilogram(QuantityValue micro return new RadiationExposure(value, RadiationExposureUnit.MicrocoulombPerKilogram); } + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromMicroroentgens(QuantityValue microroentgens) + { + double value = (double) microroentgens; + return new RadiationExposure(value, RadiationExposureUnit.Microroentgen); + } + /// /// Creates a from . /// @@ -287,6 +313,16 @@ public static RadiationExposure FromMillicoulombsPerKilogram(QuantityValue milli return new RadiationExposure(value, RadiationExposureUnit.MillicoulombPerKilogram); } + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static RadiationExposure FromMilliroentgens(QuantityValue milliroentgens) + { + double value = (double) milliroentgens; + return new RadiationExposure(value, RadiationExposureUnit.Milliroentgen); + } + /// /// Creates a from . /// @@ -811,14 +847,18 @@ private bool TryToUnit(RadiationExposureUnit unit, [NotNullWhen(true)] out Radia { // RadiationExposureUnit -> BaseUnit (RadiationExposureUnit.MicrocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure((_value) * 1e-6d, RadiationExposureUnit.CoulombPerKilogram), + (RadiationExposureUnit.Microroentgen, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure((_value * 2.58e-4) * 1e-6d, RadiationExposureUnit.CoulombPerKilogram), (RadiationExposureUnit.MillicoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure((_value) * 1e-3d, RadiationExposureUnit.CoulombPerKilogram), + (RadiationExposureUnit.Milliroentgen, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure((_value * 2.58e-4) * 1e-3d, RadiationExposureUnit.CoulombPerKilogram), (RadiationExposureUnit.NanocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure((_value) * 1e-9d, RadiationExposureUnit.CoulombPerKilogram), (RadiationExposureUnit.PicocoulombPerKilogram, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure((_value) * 1e-12d, RadiationExposureUnit.CoulombPerKilogram), (RadiationExposureUnit.Roentgen, RadiationExposureUnit.CoulombPerKilogram) => new RadiationExposure(_value * 2.58e-4, RadiationExposureUnit.CoulombPerKilogram), // BaseUnit -> RadiationExposureUnit (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.MicrocoulombPerKilogram) => new RadiationExposure((_value) / 1e-6d, RadiationExposureUnit.MicrocoulombPerKilogram), + (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.Microroentgen) => new RadiationExposure((_value / 2.58e-4) / 1e-6d, RadiationExposureUnit.Microroentgen), (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.MillicoulombPerKilogram) => new RadiationExposure((_value) / 1e-3d, RadiationExposureUnit.MillicoulombPerKilogram), + (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.Milliroentgen) => new RadiationExposure((_value / 2.58e-4) / 1e-3d, RadiationExposureUnit.Milliroentgen), (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.NanocoulombPerKilogram) => new RadiationExposure((_value) / 1e-9d, RadiationExposureUnit.NanocoulombPerKilogram), (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.PicocoulombPerKilogram) => new RadiationExposure((_value) / 1e-12d, RadiationExposureUnit.PicocoulombPerKilogram), (RadiationExposureUnit.CoulombPerKilogram, RadiationExposureUnit.Roentgen) => new RadiationExposure(_value / 2.58e-4, RadiationExposureUnit.Roentgen), diff --git a/UnitsNet/GeneratedCode/Resources/RadiationExposure.restext b/UnitsNet/GeneratedCode/Resources/RadiationExposure.restext index 68f0eacb08..d7725ef20e 100644 --- a/UnitsNet/GeneratedCode/Resources/RadiationExposure.restext +++ b/UnitsNet/GeneratedCode/Resources/RadiationExposure.restext @@ -1,6 +1,8 @@ CoulombsPerKilogram=C/kg MicrocoulombsPerKilogram=µC/kg +Microroentgens=µR MillicoulombsPerKilogram=mC/kg +Milliroentgens=mR NanocoulombsPerKilogram=nC/kg PicocoulombsPerKilogram=pC/kg Roentgens=R diff --git a/UnitsNet/GeneratedCode/Units/RadiationExposureUnit.g.cs b/UnitsNet/GeneratedCode/Units/RadiationExposureUnit.g.cs index 75b4669f79..8e50cdd24f 100644 --- a/UnitsNet/GeneratedCode/Units/RadiationExposureUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/RadiationExposureUnit.g.cs @@ -27,7 +27,9 @@ public enum RadiationExposureUnit { CoulombPerKilogram = 10, MicrocoulombPerKilogram = 3, + Microroentgen = 12, MillicoulombPerKilogram = 2, + Milliroentgen = 13, NanocoulombPerKilogram = 6, PicocoulombPerKilogram = 5, Roentgen = 4,