diff --git a/.gitignore b/.gitignore index 2e6ebec7d0..729a9f42b0 100644 --- a/.gitignore +++ b/.gitignore @@ -259,3 +259,6 @@ Artifacts # Build server tooling /secure-file /.tools/ + +# Mac files +**/.DS_Store \ No newline at end of file diff --git a/Common/UnitDefinitions/EnergyEfficiency.json b/Common/UnitDefinitions/EnergyEfficiency.json new file mode 100644 index 0000000000..0e2f3f8664 --- /dev/null +++ b/Common/UnitDefinitions/EnergyEfficiency.json @@ -0,0 +1,42 @@ +{ + "Name": "EnergyEfficiency", + "BaseUnit": "WattHourPerKilometer", + "XmlDocSummary": "", + "BaseDimensions": { + "Wh/km": 1 + }, + "Units": [ + { + "SingularName": "WattHourPerKilometer", + "PluralName": "WattHoursPerKilometer", + "BaseUnits": { + "Wh/km": "WattHourPerKilometer" + }, + "FromUnitToBaseFunc": "{x}", + "FromBaseToUnitFunc": "{x}", + "Prefixes": ["Kilo" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "Wh/km" ] + } + ] + }, + { + "SingularName": "WattHourPerMeter", + "PluralName": "WattHoursPerMeter", + "BaseUnits": { + "Wh/m": "WattHourPerMeter" + }, + "FromUnitToBaseFunc": "{x} * 1e3", + "FromBaseToUnitFunc": "{x} / 1e3", + "Prefixes": ["Kilo"], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "Wh/m" ] + } + ] + } + ] +} diff --git a/Common/UnitEnumValues.g.json b/Common/UnitEnumValues.g.json index e58a8e2198..bb2bab3486 100644 --- a/Common/UnitEnumValues.g.json +++ b/Common/UnitEnumValues.g.json @@ -1862,5 +1862,25 @@ "Sievert": 9, "Kilosievert": 3, "Megasievert": 6 + }, + "EnergyEfficiency": { + "FemtowattHourPerKilometer": 7, + "FemtowattHourPerMeter": 9, + "GigawattHourPerKilometer": 10, + "GigawattHourPerMeter": 2, + "KilowattHourPerKilometer": 5, + "KilowattHourPerMeter": 3, + "MegawattHourPerKilometer": 1, + "MegawattHourPerMeter": 6, + "MicrowattHourPerKilometer": 4, + "MicrowattHourPerMeter": 8, + "MilliwattHourPerKilometer": 12, + "MilliwattHourPerMeter": 15, + "NanowattHourPerKilometer": 11, + "NanowattHourPerMeter": 16, + "PicowattHourPerKilometer": 14, + "PicowattHourPerMeter": 19, + "WattHourPerKilometer": 13, + "WattHourPerMeter": 20 } } diff --git a/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/EnergyEfficiency.nfproj b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/EnergyEfficiency.nfproj new file mode 100644 index 0000000000..5d33ce3268 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/EnergyEfficiency.nfproj @@ -0,0 +1,42 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {31f3d11e-76d2-1914-ebad-28e0cb77326b} + Library + Properties + 512 + UnitsNet + UnitsNet.EnergyEfficiency + v1.0 + bin\$(Configuration)\$(AssemblyName).xml + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll + True + True + + + + + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/UnitsNet.NanoFramework.EnergyEfficiency.nuspec b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/UnitsNet.NanoFramework.EnergyEfficiency.nuspec new file mode 100644 index 0000000000..d7a09bc51b --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/UnitsNet.NanoFramework.EnergyEfficiency.nuspec @@ -0,0 +1,26 @@ + + + + UnitsNet.nanoFramework.EnergyEfficiency + 5.57.0 + Units.NET EnergyEfficiency - nanoFramework + Andreas Gullberg Larsen,nanoframework + UnitsNet + MIT-0 + https://github.com/angularsen/UnitsNet + false + Adds EnergyEfficiency 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 energyefficiency unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable + + + + + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/packages.config b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/packages.config new file mode 100644 index 0000000000..313a8dccdf --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/EnergyEfficiency/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs new file mode 100644 index 0000000000..2756af7483 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Quantities/EnergyEfficiency.g.cs @@ -0,0 +1,198 @@ +//------------------------------------------------------------------------------ +// +// 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 +{ + /// + /// + /// + /// + public struct EnergyEfficiency + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly EnergyEfficiencyUnit _unit; + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + /// + public EnergyEfficiencyUnit 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 EnergyEfficiency(double value, EnergyEfficiencyUnit unit) + { + _value = value; + _unit = unit; + } + + /// + /// The base unit of EnergyEfficiency, which is Second. All conversions go via this value. + /// + public static EnergyEfficiencyUnit BaseUnit { get; } = EnergyEfficiencyUnit.WattHourPerKilometer; + + /// + /// Represents the largest possible value of EnergyEfficiency. + /// + public static EnergyEfficiency MaxValue { get; } = new EnergyEfficiency(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of EnergyEfficiency. + /// + public static EnergyEfficiency MinValue { get; } = new EnergyEfficiency(double.MinValue, BaseUnit); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Second. + /// + public static EnergyEfficiency Zero { get; } = new EnergyEfficiency(0, BaseUnit); + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double KilowattHoursPerKilometer => As(EnergyEfficiencyUnit.KilowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double KilowattHoursPerMeter => As(EnergyEfficiencyUnit.KilowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double WattHoursPerKilometer => As(EnergyEfficiencyUnit.WattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double WattHoursPerMeter => As(EnergyEfficiencyUnit.WattHourPerMeter); + + #endregion + + #region Static Factory Methods + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromKilowattHoursPerKilometer(double kilowatthoursperkilometer) => new EnergyEfficiency(kilowatthoursperkilometer, EnergyEfficiencyUnit.KilowattHourPerKilometer); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromKilowattHoursPerMeter(double kilowatthourspermeter) => new EnergyEfficiency(kilowatthourspermeter, EnergyEfficiencyUnit.KilowattHourPerMeter); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromWattHoursPerKilometer(double watthoursperkilometer) => new EnergyEfficiency(watthoursperkilometer, EnergyEfficiencyUnit.WattHourPerKilometer); + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromWattHoursPerMeter(double watthourspermeter) => new EnergyEfficiency(watthourspermeter, EnergyEfficiencyUnit.WattHourPerMeter); + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// EnergyEfficiency unit value. + public static EnergyEfficiency From(double value, EnergyEfficiencyUnit fromUnit) + { + return new EnergyEfficiency(value, fromUnit); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(EnergyEfficiencyUnit unit) => GetValueAs(unit); + + /// + /// Converts this EnergyEfficiency to another EnergyEfficiency with the unit representation . + /// + /// A EnergyEfficiency with the specified unit. + public EnergyEfficiency ToUnit(EnergyEfficiencyUnit unit) + { + var convertedValue = GetValueAs(unit); + return new EnergyEfficiency(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 + { + EnergyEfficiencyUnit.KilowattHourPerKilometer => (_value) * 1e3d, + EnergyEfficiencyUnit.KilowattHourPerMeter => (_value * 1e3) * 1e3d, + EnergyEfficiencyUnit.WattHourPerKilometer => _value, + EnergyEfficiencyUnit.WattHourPerMeter => _value * 1e3, + _ => throw new NotImplementedException($"Can not convert {Unit} to base units.") + }; + } + + private double GetValueAs(EnergyEfficiencyUnit unit) + { + if (Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + return unit switch + { + EnergyEfficiencyUnit.KilowattHourPerKilometer => (baseUnitValue) / 1e3d, + EnergyEfficiencyUnit.KilowattHourPerMeter => (baseUnitValue / 1e3) / 1e3d, + EnergyEfficiencyUnit.WattHourPerKilometer => baseUnitValue, + EnergyEfficiencyUnit.WattHourPerMeter => baseUnitValue / 1e3, + _ => throw new NotImplementedException($"Can not convert {Unit} to {unit}.") + }; + } + + #endregion + } +} + diff --git a/UnitsNet.NanoFramework/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs b/UnitsNet.NanoFramework/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs new file mode 100644 index 0000000000..0fc1eafbc4 --- /dev/null +++ b/UnitsNet.NanoFramework/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// 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 EnergyEfficiencyUnit + { + KilowattHourPerKilometer = 5, + KilowattHourPerMeter = 3, + WattHourPerKilometer = 13, + WattHourPerMeter = 20, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln index d64098f57d..1f1969a38e 100644 --- a/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln +++ b/UnitsNet.NanoFramework/GeneratedCode/UnitsNet.nanoFramework.sln @@ -76,6 +76,8 @@ Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Energy", "Energy\Energy.nfp EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "EnergyDensity", "EnergyDensity\EnergyDensity.nfproj", "{c5025916-5039-97c2-b450-af1420f5fb08}" EndProject +Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "EnergyEfficiency", "EnergyEfficiency\EnergyEfficiency.nfproj", "{31f3d11e-76d2-1914-ebad-28e0cb77326b}" +EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Entropy", "Entropy\Entropy.nfproj", "{816884bb-a5f6-5c07-967b-bb8f21d724b7}" EndProject Project("{d608a2b1-6ead-4383-a205-ad1ce69d9ef7}") = "Force", "Force\Force.nfproj", "{5517dacf-b1ff-6515-e5b6-b5081f92f407}" @@ -478,6 +480,12 @@ Global {c5025916-5039-97c2-b450-af1420f5fb08}.Release|Any CPU.ActiveCfg = Release|Any CPU {c5025916-5039-97c2-b450-af1420f5fb08}.Release|Any CPU.Build.0 = Release|Any CPU {c5025916-5039-97c2-b450-af1420f5fb08}.Release|Any CPU.Deploy.0 = Release|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Debug|Any CPU.Build.0 = Debug|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Debug|Any CPU.Deploy.0 = Debug|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Release|Any CPU.ActiveCfg = Release|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Release|Any CPU.Build.0 = Release|Any CPU +{31f3d11e-76d2-1914-ebad-28e0cb77326b}.Release|Any CPU.Deploy.0 = Release|Any CPU {816884bb-a5f6-5c07-967b-bb8f21d724b7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {816884bb-a5f6-5c07-967b-bb8f21d724b7}.Debug|Any CPU.Build.0 = Debug|Any CPU {816884bb-a5f6-5c07-967b-bb8f21d724b7}.Debug|Any CPU.Deploy.0 = Debug|Any CPU diff --git a/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToEnergyEfficiencyExtensionsTest.g.cs b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToEnergyEfficiencyExtensionsTest.g.cs new file mode 100644 index 0000000000..3ee8b30f71 --- /dev/null +++ b/UnitsNet.NumberExtensions.Tests/GeneratedCode/NumberToEnergyEfficiencyExtensionsTest.g.cs @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToEnergyEfficiency; +using Xunit; + +namespace UnitsNet.Tests +{ + public class NumberToEnergyEfficiencyExtensionsTests + { + [Fact] + public void NumberToKilowattHoursPerKilometerTest() => + Assert.Equal(EnergyEfficiency.FromKilowattHoursPerKilometer(2), 2.KilowattHoursPerKilometer()); + + [Fact] + public void NumberToKilowattHoursPerMeterTest() => + Assert.Equal(EnergyEfficiency.FromKilowattHoursPerMeter(2), 2.KilowattHoursPerMeter()); + + [Fact] + public void NumberToWattHoursPerKilometerTest() => + Assert.Equal(EnergyEfficiency.FromWattHoursPerKilometer(2), 2.WattHoursPerKilometer()); + + [Fact] + public void NumberToWattHoursPerMeterTest() => + Assert.Equal(EnergyEfficiency.FromWattHoursPerMeter(2), 2.WattHoursPerMeter()); + + } +} diff --git a/UnitsNet.NumberExtensions/GeneratedCode/NumberToEnergyEfficiencyExtensions.g.cs b/UnitsNet.NumberExtensions/GeneratedCode/NumberToEnergyEfficiencyExtensions.g.cs new file mode 100644 index 0000000000..4aae2e4406 --- /dev/null +++ b/UnitsNet.NumberExtensions/GeneratedCode/NumberToEnergyEfficiencyExtensions.g.cs @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// 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.NumberToEnergyEfficiency +{ + /// + /// A number to EnergyEfficiency Extensions + /// + public static class NumberToEnergyEfficiencyExtensions + { + /// + public static EnergyEfficiency KilowattHoursPerKilometer(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromKilowattHoursPerKilometer(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency KilowattHoursPerMeter(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromKilowattHoursPerMeter(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency WattHoursPerKilometer(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromWattHoursPerKilometer(Convert.ToDouble(value)); + + /// + public static EnergyEfficiency WattHoursPerMeter(this T value) + where T : notnull +#if NET7_0_OR_GREATER + , INumber +#endif + => EnergyEfficiency.FromWattHoursPerMeter(Convert.ToDouble(value)); + + } +} diff --git a/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs b/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs new file mode 100644 index 0000000000..d04045833c --- /dev/null +++ b/UnitsNet.Tests/CustomCode/EnergyEfficiencyTests.cs @@ -0,0 +1,32 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; + +namespace UnitsNet.Tests.CustomCode +{ + public class EnergyEfficiencyTests : EnergyEfficiencyTestsBase + { + protected override bool SupportsSIUnitSystem => false; + protected override double KilowattHoursPerKilometerInOneWattHourPerKilometer => 1e-3; + protected override double KilowattHoursPerMeterInOneWattHourPerKilometer => 1e-6; + protected override double WattHoursPerKilometerInOneWattHourPerKilometer => 1; + protected override double WattHoursPerMeterInOneWattHourPerKilometer => 1e-3; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs index 7dc41682e2..aa6405a08f 100644 --- a/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs +++ b/UnitsNet.Tests/GeneratedCode/IQuantityTests.g.cs @@ -71,6 +71,7 @@ void Assertion(int expectedValue, Enum expectedUnit, IQuantity quantity) Assertion(3, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, Quantity.From(3, ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)); Assertion(3, EnergyUnit.WattHour, Quantity.From(3, EnergyUnit.WattHour)); Assertion(3, EnergyDensityUnit.WattHourPerCubicMeter, Quantity.From(3, EnergyDensityUnit.WattHourPerCubicMeter)); + Assertion(3, EnergyEfficiencyUnit.WattHourPerMeter, Quantity.From(3, EnergyEfficiencyUnit.WattHourPerMeter)); Assertion(3, EntropyUnit.MegajoulePerKelvin, Quantity.From(3, EntropyUnit.MegajoulePerKelvin)); Assertion(3, ForceUnit.TonneForce, Quantity.From(3, ForceUnit.TonneForce)); Assertion(3, ForceChangeRateUnit.PoundForcePerSecond, Quantity.From(3, ForceChangeRateUnit.PoundForcePerSecond)); @@ -202,6 +203,7 @@ public void QuantityInfo_IsSameAsStaticInfoProperty() Assertion(ElectricSurfaceChargeDensity.Info, ElectricSurfaceChargeDensity.Zero); Assertion(Energy.Info, Energy.Zero); Assertion(EnergyDensity.Info, EnergyDensity.Zero); + Assertion(EnergyEfficiency.Info, EnergyEfficiency.Zero); Assertion(Entropy.Info, Entropy.Zero); Assertion(Force.Info, Force.Zero); Assertion(ForceChangeRate.Info, ForceChangeRate.Zero); @@ -333,6 +335,7 @@ public void Dimensions_IsSameAsStaticBaseDimensions() Assertion(ElectricSurfaceChargeDensity.BaseDimensions, ElectricSurfaceChargeDensity.Zero); Assertion(Energy.BaseDimensions, Energy.Zero); Assertion(EnergyDensity.BaseDimensions, EnergyDensity.Zero); + Assertion(EnergyEfficiency.BaseDimensions, EnergyEfficiency.Zero); Assertion(Entropy.BaseDimensions, Entropy.Zero); Assertion(Force.BaseDimensions, Force.Zero); Assertion(ForceChangeRate.BaseDimensions, ForceChangeRate.Zero); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyEfficiencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyEfficiencyTestsBase.g.cs new file mode 100644 index 0000000000..187a2f12f9 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyEfficiencyTestsBase.g.cs @@ -0,0 +1,744 @@ +//------------------------------------------------------------------------------ +// +// 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 EnergyEfficiency. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class EnergyEfficiencyTestsBase : QuantityTestsBase + { + protected abstract double KilowattHoursPerKilometerInOneWattHourPerKilometer { get; } + protected abstract double KilowattHoursPerMeterInOneWattHourPerKilometer { get; } + protected abstract double WattHoursPerKilometerInOneWattHourPerKilometer { get; } + protected abstract double WattHoursPerMeterInOneWattHourPerKilometer { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double KilowattHoursPerKilometerTolerance { get { return 1e-5; } } + protected virtual double KilowattHoursPerMeterTolerance { get { return 1e-5; } } + protected virtual double WattHoursPerKilometerTolerance { get { return 1e-5; } } + protected virtual double WattHoursPerMeterTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + protected (double UnitsInBaseUnit, double Tolerence) GetConversionFactor(EnergyEfficiencyUnit unit) + { + return unit switch + { + EnergyEfficiencyUnit.KilowattHourPerKilometer => (KilowattHoursPerKilometerInOneWattHourPerKilometer, KilowattHoursPerKilometerTolerance), + EnergyEfficiencyUnit.KilowattHourPerMeter => (KilowattHoursPerMeterInOneWattHourPerKilometer, KilowattHoursPerMeterTolerance), + EnergyEfficiencyUnit.WattHourPerKilometer => (WattHoursPerKilometerInOneWattHourPerKilometer, WattHoursPerKilometerTolerance), + EnergyEfficiencyUnit.WattHourPerMeter => (WattHoursPerMeterInOneWattHourPerKilometer, WattHoursPerMeterTolerance), + _ => throw new NotSupportedException() + }; + } + + public static IEnumerable UnitTypes = new List + { + new object[] { EnergyEfficiencyUnit.KilowattHourPerKilometer }, + new object[] { EnergyEfficiencyUnit.KilowattHourPerMeter }, + new object[] { EnergyEfficiencyUnit.WattHourPerKilometer }, + new object[] { EnergyEfficiencyUnit.WattHourPerMeter }, + }; + + [Fact] + public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() + { + var quantity = new EnergyEfficiency(); + Assert.Equal(0, quantity.Value); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, quantity.Unit); + } + + [Fact] + public void Ctor_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => new EnergyEfficiency(double.PositiveInfinity, EnergyEfficiencyUnit.WattHourPerKilometer)); + Assert.Throws(() => new EnergyEfficiency(double.NegativeInfinity, EnergyEfficiencyUnit.WattHourPerKilometer)); + } + + [Fact] + public void Ctor_WithNaNValue_ThrowsArgumentException() + { + Assert.Throws(() => new EnergyEfficiency(double.NaN, EnergyEfficiencyUnit.WattHourPerKilometer)); + } + + [Fact] + public void Ctor_NullAsUnitSystem_ThrowsArgumentNullException() + { + Assert.Throws(() => new EnergyEfficiency(value: 1, unitSystem: null)); + } + + [Fact] + public void Ctor_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + Func TestCode = () => new EnergyEfficiency(value: 1, unitSystem: UnitSystem.SI); + if (SupportsSIUnitSystem) + { + var quantity = (EnergyEfficiency) TestCode(); + Assert.Equal(1, quantity.Value); + } + else + { + Assert.Throws(TestCode); + } + } + + [Fact] + public void EnergyEfficiency_QuantityInfo_ReturnsQuantityInfoDescribingQuantity() + { + var quantity = new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerKilometer); + + QuantityInfo quantityInfo = quantity.QuantityInfo; + + Assert.Equal(EnergyEfficiency.Zero, quantityInfo.Zero); + Assert.Equal("EnergyEfficiency", quantityInfo.Name); + + var units = EnumUtils.GetEnumValues().OrderBy(x => x.ToString()).ToArray(); + var unitNames = units.Select(x => x.ToString()); + } + + [Fact] + public void WattHourPerKilometerToEnergyEfficiencyUnits() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + AssertEx.EqualTolerance(KilowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(KilowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.KilowattHoursPerMeter, KilowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(WattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(WattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.WattHoursPerMeter, WattHoursPerMeterTolerance); + } + + [Fact] + public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit() + { + var quantity00 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.KilowattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity00.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, quantity00.Unit); + + var quantity01 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.KilowattHourPerMeter); + AssertEx.EqualTolerance(1, quantity01.KilowattHoursPerMeter, KilowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, quantity01.Unit); + + var quantity02 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.WattHourPerKilometer); + AssertEx.EqualTolerance(1, quantity02.WattHoursPerKilometer, WattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, quantity02.Unit); + + var quantity03 = EnergyEfficiency.From(1, EnergyEfficiencyUnit.WattHourPerMeter); + AssertEx.EqualTolerance(1, quantity03.WattHoursPerMeter, WattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, quantity03.Unit); + + } + + [Fact] + public void FromWattHoursPerKilometer_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => EnergyEfficiency.FromWattHoursPerKilometer(double.PositiveInfinity)); + Assert.Throws(() => EnergyEfficiency.FromWattHoursPerKilometer(double.NegativeInfinity)); + } + + [Fact] + public void FromWattHoursPerKilometer_WithNanValue_ThrowsArgumentException() + { + Assert.Throws(() => EnergyEfficiency.FromWattHoursPerKilometer(double.NaN)); + } + + [Fact] + public void As() + { + var watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + AssertEx.EqualTolerance(KilowattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.KilowattHourPerKilometer), KilowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(KilowattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.KilowattHourPerMeter), KilowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(WattHoursPerKilometerInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.WattHourPerKilometer), WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(WattHoursPerMeterInOneWattHourPerKilometer, watthourperkilometer.As(EnergyEfficiencyUnit.WattHourPerMeter), WattHoursPerMeterTolerance); + } + + [Fact] + public void As_SIUnitSystem_ThrowsArgumentExceptionIfNotSupported() + { + var quantity = new EnergyEfficiency(value: 1, unit: EnergyEfficiency.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 = EnergyEfficiency.Parse("1 kWh/km", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 kWh/m", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.KilowattHoursPerMeter, KilowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 Wh/km", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.WattHoursPerKilometer, WattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = EnergyEfficiency.Parse("1 Wh/m", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.WattHoursPerMeter, WattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParse() + { + { + Assert.True(EnergyEfficiency.TryParse("1 kWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilowattHoursPerKilometer, KilowattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 kWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.KilowattHoursPerMeter, KilowattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 Wh/km", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.WattHoursPerKilometer, WattHoursPerKilometerTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, parsed.Unit); + } + + { + Assert.True(EnergyEfficiency.TryParse("1 Wh/m", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.WattHoursPerMeter, WattHoursPerMeterTolerance); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, parsed.Unit); + } + + } + + [Fact] + public void ParseUnit() + { + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("kWh/km", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("kWh/m", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("Wh/km", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsedUnit = EnergyEfficiency.ParseUnit("Wh/m", CultureInfo.GetCultureInfo("en-US")); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, parsedUnit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + } + + [Fact] + public void TryParseUnit() + { + { + Assert.True(EnergyEfficiency.TryParseUnit("kWh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerKilometer, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("kWh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.KilowattHourPerMeter, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("Wh/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerKilometer, parsedUnit); + } + + { + Assert.True(EnergyEfficiency.TryParseUnit("Wh/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); + Assert.Equal(EnergyEfficiencyUnit.WattHourPerMeter, parsedUnit); + } + + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit(EnergyEfficiencyUnit unit) + { + var inBaseUnits = EnergyEfficiency.From(1.0, EnergyEfficiency.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(EnergyEfficiencyUnit unit) + { + var quantity = EnergyEfficiency.From(3.0, unit); + var toUnitWithSameUnit = quantity.ToUnit(unit); + Assert.Equal(quantity, toUnitWithSameUnit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public void ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit(EnergyEfficiencyUnit 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 = EnergyEfficiency.Units.First(u => u != EnergyEfficiency.BaseUnit); + + var quantity = EnergyEfficiency.From(3.0, fromUnit); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Theory] + [MemberData(nameof(UnitTypes))] + public virtual void ToUnit_FromDefaultQuantity_ReturnsQuantityWithGivenUnit(EnergyEfficiencyUnit unit) + { + var quantity = default(EnergyEfficiency); + var converted = quantity.ToUnit(unit); + Assert.Equal(converted.Unit, unit); + } + + [Fact] + public void ConversionRoundTrip() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromKilowattHoursPerKilometer(watthourperkilometer.KilowattHoursPerKilometer).WattHoursPerKilometer, KilowattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromKilowattHoursPerMeter(watthourperkilometer.KilowattHoursPerMeter).WattHoursPerKilometer, KilowattHoursPerMeterTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromWattHoursPerKilometer(watthourperkilometer.WattHoursPerKilometer).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(1, EnergyEfficiency.FromWattHoursPerMeter(watthourperkilometer.WattHoursPerMeter).WattHoursPerKilometer, WattHoursPerMeterTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + EnergyEfficiency v = EnergyEfficiency.FromWattHoursPerKilometer(1); + AssertEx.EqualTolerance(-1, -v.WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(2, (EnergyEfficiency.FromWattHoursPerKilometer(3)-v).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(2, (v + v).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(10, (v*10).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(10, (10*v).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(2, (EnergyEfficiency.FromWattHoursPerKilometer(10)/5).WattHoursPerKilometer, WattHoursPerKilometerTolerance); + AssertEx.EqualTolerance(2, EnergyEfficiency.FromWattHoursPerKilometer(10)/EnergyEfficiency.FromWattHoursPerKilometer(5), WattHoursPerKilometerTolerance); + } + + [Fact] + public void ComparisonOperators() + { + EnergyEfficiency oneWattHourPerKilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + EnergyEfficiency twoWattHoursPerKilometer = EnergyEfficiency.FromWattHoursPerKilometer(2); + + Assert.True(oneWattHourPerKilometer < twoWattHoursPerKilometer); + Assert.True(oneWattHourPerKilometer <= twoWattHoursPerKilometer); + Assert.True(twoWattHoursPerKilometer > oneWattHourPerKilometer); + Assert.True(twoWattHoursPerKilometer >= oneWattHourPerKilometer); + + Assert.False(oneWattHourPerKilometer > twoWattHoursPerKilometer); + Assert.False(oneWattHourPerKilometer >= twoWattHoursPerKilometer); + Assert.False(twoWattHoursPerKilometer < oneWattHourPerKilometer); + Assert.False(twoWattHoursPerKilometer <= oneWattHourPerKilometer); + } + + [Fact] + public void CompareToIsImplemented() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.Equal(0, watthourperkilometer.CompareTo(watthourperkilometer)); + Assert.True(watthourperkilometer.CompareTo(EnergyEfficiency.Zero) > 0); + Assert.True(EnergyEfficiency.Zero.CompareTo(watthourperkilometer) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.Throws(() => watthourperkilometer.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.Throws(() => watthourperkilometer.CompareTo(null)); + } + + [Theory] + [InlineData(1, EnergyEfficiencyUnit.WattHourPerKilometer, 1, EnergyEfficiencyUnit.WattHourPerKilometer, true)] // Same value and unit. + [InlineData(1, EnergyEfficiencyUnit.WattHourPerKilometer, 2, EnergyEfficiencyUnit.WattHourPerKilometer, false)] // Different value. + [InlineData(2, EnergyEfficiencyUnit.WattHourPerKilometer, 1, EnergyEfficiencyUnit.KilowattHourPerKilometer, false)] // Different value and unit. + [InlineData(1, EnergyEfficiencyUnit.WattHourPerKilometer, 1, EnergyEfficiencyUnit.KilowattHourPerKilometer, false)] // Different unit. + public void Equals_ReturnsTrue_IfValueAndUnitAreEqual(double valueA, EnergyEfficiencyUnit unitA, double valueB, EnergyEfficiencyUnit unitB, bool expectEqual) + { + var a = new EnergyEfficiency(valueA, unitA); + var b = new EnergyEfficiency(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 = EnergyEfficiency.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 = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.True(v.Equals(EnergyEfficiency.FromWattHoursPerKilometer(1), WattHoursPerKilometerTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(EnergyEfficiency.Zero, WattHoursPerKilometerTolerance, ComparisonType.Relative)); + Assert.True(EnergyEfficiency.FromWattHoursPerKilometer(100).Equals(EnergyEfficiency.FromWattHoursPerKilometer(120), (double)0.3m, ComparisonType.Relative)); + Assert.False(EnergyEfficiency.FromWattHoursPerKilometer(100).Equals(EnergyEfficiency.FromWattHoursPerKilometer(120), (double)0.1m, ComparisonType.Relative)); + } + + [Fact] + public void Equals_NegativeRelativeTolerance_ThrowsArgumentOutOfRangeException() + { + var v = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.Throws(() => v.Equals(EnergyEfficiency.FromWattHoursPerKilometer(1), -1, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.False(watthourperkilometer.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + EnergyEfficiency watthourperkilometer = EnergyEfficiency.FromWattHoursPerKilometer(1); + Assert.False(watthourperkilometer.Equals(null)); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(EnergyEfficiencyUnit)).Cast(); + foreach (var unit in units) + { + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(EnergyEfficiency.BaseDimensions is null); + } + + [Fact] + public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() + { + var prevCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); + try { + Assert.Equal("1 kWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerKilometer).ToString()); + Assert.Equal("1 kWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerMeter).ToString()); + Assert.Equal("1 Wh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerKilometer).ToString()); + Assert.Equal("1 Wh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerMeter).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 kWh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerKilometer).ToString(swedishCulture)); + Assert.Equal("1 kWh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.KilowattHourPerMeter).ToString(swedishCulture)); + Assert.Equal("1 Wh/km", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerKilometer).ToString(swedishCulture)); + Assert.Equal("1 Wh/m", new EnergyEfficiency(1, EnergyEfficiencyUnit.WattHourPerMeter).ToString(swedishCulture)); + } + + [Fact] + public void ToString_SFormat_FormatsNumberWithGivenDigitsAfterRadixForCurrentCulture() + { + var oldCulture = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s1")); + Assert.Equal("0.12 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s2")); + Assert.Equal("0.123 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s3")); + Assert.Equal("0.1235 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s4")); + } + finally + { + CultureInfo.CurrentCulture = oldCulture; + } + } + + [Fact] + public void ToString_SFormatAndCulture_FormatsNumberWithGivenDigitsAfterRadixForGivenCulture() + { + var culture = CultureInfo.InvariantCulture; + Assert.Equal("0.1 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s1", culture)); + Assert.Equal("0.12 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s2", culture)); + Assert.Equal("0.123 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s3", culture)); + Assert.Equal("0.1235 Wh/km", new EnergyEfficiency(0.123456, EnergyEfficiencyUnit.WattHourPerKilometer).ToString("s4", culture)); + } + + [Theory] + [InlineData(null)] + [InlineData("en-US")] + public void ToString_NullFormat_DefaultsToGeneralFormat(string cultureName) + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(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 = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(quantity.ToString(format, CultureInfo.CurrentCulture), quantity.ToString(format, null)); + } + + [Fact] + public void Convert_ToBool_ThrowsInvalidCastException() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Throws(() => Convert.ToBoolean(quantity)); + } + + [Fact] + public void Convert_ToByte_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((byte)quantity.Value, Convert.ToByte(quantity)); + } + + [Fact] + public void Convert_ToChar_ThrowsInvalidCastException() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Throws(() => Convert.ToChar(quantity)); + } + + [Fact] + public void Convert_ToDateTime_ThrowsInvalidCastException() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Throws(() => Convert.ToDateTime(quantity)); + } + + [Fact] + public void Convert_ToDecimal_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((decimal)quantity.Value, Convert.ToDecimal(quantity)); + } + + [Fact] + public void Convert_ToDouble_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((double)quantity.Value, Convert.ToDouble(quantity)); + } + + [Fact] + public void Convert_ToInt16_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((short)quantity.Value, Convert.ToInt16(quantity)); + } + + [Fact] + public void Convert_ToInt32_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((int)quantity.Value, Convert.ToInt32(quantity)); + } + + [Fact] + public void Convert_ToInt64_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((long)quantity.Value, Convert.ToInt64(quantity)); + } + + [Fact] + public void Convert_ToSByte_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((sbyte)quantity.Value, Convert.ToSByte(quantity)); + } + + [Fact] + public void Convert_ToSingle_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); + } + + [Fact] + public void Convert_ToString_EqualsToString() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); + } + + [Fact] + public void Convert_ToUInt16_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((ushort)quantity.Value, Convert.ToUInt16(quantity)); + } + + [Fact] + public void Convert_ToUInt32_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((uint)quantity.Value, Convert.ToUInt32(quantity)); + } + + [Fact] + public void Convert_ToUInt64_EqualsValueAsSameType() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); + } + + [Fact] + public void Convert_ChangeType_SelfType_EqualsSelf() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(EnergyEfficiency))); + } + + [Fact] + public void Convert_ChangeType_UnitType_EqualsUnit() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(EnergyEfficiencyUnit))); + } + + [Fact] + public void Convert_ChangeType_QuantityInfo_EqualsQuantityInfo() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(EnergyEfficiency.Info, Convert.ChangeType(quantity, typeof(QuantityInfo))); + } + + [Fact] + public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(EnergyEfficiency.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); + } + + [Fact] + public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Throws(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); + } + + [Fact] + public void GetHashCode_Equals() + { + var quantity = EnergyEfficiency.FromWattHoursPerKilometer(1.0); + Assert.Equal(new {EnergyEfficiency.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 = EnergyEfficiency.FromWattHoursPerKilometer(value); + Assert.Equal(EnergyEfficiency.FromWattHoursPerKilometer(-value), -quantity); + } + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs b/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs new file mode 100644 index 0000000000..9200a5d7e9 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/EnergyEfficiency.g.cs @@ -0,0 +1,992 @@ +//------------------------------------------------------------------------------ +// +// 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; +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 +{ + /// + /// + /// + /// + [DataContract] + [DebuggerTypeProxy(typeof(QuantityDisplay))] + public readonly partial struct EnergyEfficiency : + IArithmeticQuantity, + IComparable, + IComparable, + IConvertible, + IEquatable, + IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + [DataMember(Name = "Value", Order = 1)] + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + [DataMember(Name = "Unit", Order = 2)] + private readonly EnergyEfficiencyUnit? _unit; + + static EnergyEfficiency() + { + BaseDimensions = BaseDimensions.Dimensionless; + BaseUnit = EnergyEfficiencyUnit.WattHourPerKilometer; + Units = Enum.GetValues(typeof(EnergyEfficiencyUnit)).Cast().ToArray(); + Zero = new EnergyEfficiency(0, BaseUnit); + Info = new QuantityInfo("EnergyEfficiency", + new UnitInfo[] + { + new UnitInfo(EnergyEfficiencyUnit.KilowattHourPerKilometer, "KilowattHoursPerKilometer", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.KilowattHourPerMeter, "KilowattHoursPerMeter", BaseUnits.Undefined, "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.WattHourPerKilometer, "WattHoursPerKilometer", new BaseUnits(), "EnergyEfficiency"), + new UnitInfo(EnergyEfficiencyUnit.WattHourPerMeter, "WattHoursPerMeter", new BaseUnits(), "EnergyEfficiency"), + }, + 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 EnergyEfficiency(double value, EnergyEfficiencyUnit 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 EnergyEfficiency(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 EnergyEfficiency, which is WattHourPerKilometer. All conversions go via this value. + /// + public static EnergyEfficiencyUnit BaseUnit { get; } + + /// + /// All units of measurement for the EnergyEfficiency quantity. + /// + public static EnergyEfficiencyUnit[] Units { get; } + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit WattHourPerKilometer. + /// + public static EnergyEfficiency Zero { get; } + + /// + public static EnergyEfficiency 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 EnergyEfficiencyUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => EnergyEfficiency.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Gets a value of this quantity converted into + /// + public double KilowattHoursPerKilometer => As(EnergyEfficiencyUnit.KilowattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double KilowattHoursPerMeter => As(EnergyEfficiencyUnit.KilowattHourPerMeter); + + /// + /// Gets a value of this quantity converted into + /// + public double WattHoursPerKilometer => As(EnergyEfficiencyUnit.WattHourPerKilometer); + + /// + /// Gets a value of this quantity converted into + /// + public double WattHoursPerMeter => As(EnergyEfficiencyUnit.WattHourPerMeter); + + #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: EnergyEfficiencyUnit -> BaseUnit + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.KilowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.KilowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerKilometer)); + + // Register in unit converter: BaseUnit <-> BaseUnit + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer, quantity => quantity); + + // Register in unit converter: BaseUnit -> EnergyEfficiencyUnit + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerKilometer, quantity => quantity.ToUnit(EnergyEfficiencyUnit.KilowattHourPerKilometer)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.KilowattHourPerMeter)); + unitConverter.SetConversionFunction(EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerMeter, quantity => quantity.ToUnit(EnergyEfficiencyUnit.WattHourPerMeter)); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(EnergyEfficiencyUnit 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(EnergyEfficiencyUnit 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 EnergyEfficiency FromKilowattHoursPerKilometer(QuantityValue kilowatthoursperkilometer) + { + double value = (double) kilowatthoursperkilometer; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.KilowattHourPerKilometer); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromKilowattHoursPerMeter(QuantityValue kilowatthourspermeter) + { + double value = (double) kilowatthourspermeter; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.KilowattHourPerMeter); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromWattHoursPerKilometer(QuantityValue watthoursperkilometer) + { + double value = (double) watthoursperkilometer; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.WattHourPerKilometer); + } + + /// + /// Creates a from . + /// + /// If value is NaN or Infinity. + public static EnergyEfficiency FromWattHoursPerMeter(QuantityValue watthourspermeter) + { + double value = (double) watthourspermeter; + return new EnergyEfficiency(value, EnergyEfficiencyUnit.WattHourPerMeter); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// EnergyEfficiency unit value. + public static EnergyEfficiency From(QuantityValue value, EnergyEfficiencyUnit fromUnit) + { + return new EnergyEfficiency((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 EnergyEfficiency 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 EnergyEfficiency 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 EnergyEfficiency 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 EnergyEfficiency 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 EnergyEfficiencyUnit 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 EnergyEfficiencyUnit ParseUnit(string str, IFormatProvider? provider) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out EnergyEfficiencyUnit 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 EnergyEfficiencyUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static EnergyEfficiency operator -(EnergyEfficiency right) + { + return new EnergyEfficiency(-right.Value, right.Unit); + } + + /// Get from adding two . + public static EnergyEfficiency operator +(EnergyEfficiency left, EnergyEfficiency right) + { + return new EnergyEfficiency(left.Value + right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from subtracting two . + public static EnergyEfficiency operator -(EnergyEfficiency left, EnergyEfficiency right) + { + return new EnergyEfficiency(left.Value - right.ToUnit(left.Unit).Value, left.Unit); + } + + /// Get from multiplying value and . + public static EnergyEfficiency operator *(double left, EnergyEfficiency right) + { + return new EnergyEfficiency(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static EnergyEfficiency operator *(EnergyEfficiency left, double right) + { + return new EnergyEfficiency(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static EnergyEfficiency operator /(EnergyEfficiency left, double right) + { + return new EnergyEfficiency(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(EnergyEfficiency left, EnergyEfficiency right) + { + return left.WattHoursPerKilometer / right.WattHoursPerKilometer; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(EnergyEfficiency left, EnergyEfficiency right) + { + return left.Value <= right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than or equal to. + public static bool operator >=(EnergyEfficiency left, EnergyEfficiency right) + { + return left.Value >= right.ToUnit(left.Unit).Value; + } + + /// Returns true if less than. + public static bool operator <(EnergyEfficiency left, EnergyEfficiency right) + { + return left.Value < right.ToUnit(left.Unit).Value; + } + + /// Returns true if greater than. + public static bool operator >(EnergyEfficiency left, EnergyEfficiency 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(EnergyEfficiency other, EnergyEfficiency 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 ==(EnergyEfficiency left, EnergyEfficiency 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(EnergyEfficiency other, EnergyEfficiency 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 !=(EnergyEfficiency left, EnergyEfficiency right) + { + return !(left == right); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(EnergyEfficiency other, EnergyEfficiency 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 EnergyEfficiency otherQuantity)) + return false; + + return Equals(otherQuantity); + } + + /// + /// Indicates strict equality of two quantities, where both and are exactly equal. + [Obsolete("Use Equals(EnergyEfficiency other, EnergyEfficiency 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(EnergyEfficiency 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 EnergyEfficiency otherQuantity)) throw new ArgumentException("Expected type EnergyEfficiency.", 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(EnergyEfficiency other) + { + return _value.CompareTo(other.ToUnit(this.Unit).Value); + } + + /// + /// + /// Compare equality to another EnergyEfficiency 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(EnergyEfficiency other, EnergyEfficiency 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(EnergyEfficiency 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); + } + + /// + public bool Equals(IQuantity? other, IQuantity tolerance) + { + return other is EnergyEfficiency otherTyped + && (tolerance is EnergyEfficiency toleranceTyped + ? true + : throw new ArgumentException($"Tolerance quantity ({tolerance.QuantityInfo.Name}) did not match the other quantities of type 'EnergyEfficiency'.", nameof(tolerance))) + && Equals(otherTyped, toleranceTyped); + } + + /// + public bool Equals(EnergyEfficiency other, EnergyEfficiency 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 EnergyEfficiency. + 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(EnergyEfficiencyUnit 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 EnergyEfficiencyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyEfficiencyUnit)} is supported.", nameof(unit)); + + return (double)As(typedUnit); + } + + /// + double IValueQuantity.As(Enum unit) + { + if (!(unit is EnergyEfficiencyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyEfficiencyUnit)} is supported.", nameof(unit)); + + return As(typedUnit); + } + + /// + /// Converts this EnergyEfficiency to another EnergyEfficiency with the unit representation . + /// + /// The unit to convert to. + /// A EnergyEfficiency with the specified unit. + public EnergyEfficiency ToUnit(EnergyEfficiencyUnit 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 EnergyEfficiency with the specified unit. + public EnergyEfficiency ToUnit(EnergyEfficiencyUnit 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(EnergyEfficiency), Unit, typeof(EnergyEfficiency), unit), out var conversionFunction)) + { + // See if the unit converter has an extensibility conversion registered. + return (EnergyEfficiency)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(EnergyEfficiencyUnit unit, [NotNullWhen(true)] out EnergyEfficiency? converted) + { + if (Unit == unit) + { + converted = this; + return true; + } + + EnergyEfficiency? convertedOrNull = (Unit, unit) switch + { + // EnergyEfficiencyUnit -> BaseUnit + (EnergyEfficiencyUnit.KilowattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value) * 1e3d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.KilowattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency((_value * 1e3) * 1e3d, EnergyEfficiencyUnit.WattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerMeter, EnergyEfficiencyUnit.WattHourPerKilometer) => new EnergyEfficiency(_value * 1e3, EnergyEfficiencyUnit.WattHourPerKilometer), + + // BaseUnit -> EnergyEfficiencyUnit + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerKilometer) => new EnergyEfficiency((_value) / 1e3d, EnergyEfficiencyUnit.KilowattHourPerKilometer), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.KilowattHourPerMeter) => new EnergyEfficiency((_value / 1e3) / 1e3d, EnergyEfficiencyUnit.KilowattHourPerMeter), + (EnergyEfficiencyUnit.WattHourPerKilometer, EnergyEfficiencyUnit.WattHourPerMeter) => new EnergyEfficiency(_value / 1e3, EnergyEfficiencyUnit.WattHourPerMeter), + + _ => null + }; + + if (convertedOrNull is null) + { + converted = default; + return false; + } + + converted = convertedOrNull.Value; + return true; + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if (!(unit is EnergyEfficiencyUnit typedUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyEfficiencyUnit)} is supported.", nameof(unit)); + + return ToUnit(typedUnit, DefaultConversionFunctions); + } + + /// + public EnergyEfficiency 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(EnergyEfficiencyUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + IValueQuantity IValueQuantity.ToUnit(Enum unit) + { + if (unit is not EnergyEfficiencyUnit typedUnit) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(EnergyEfficiencyUnit)} 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(EnergyEfficiency)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider? provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(EnergyEfficiency)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider? provider) + { + throw new InvalidCastException($"Converting {typeof(EnergyEfficiency)} 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(EnergyEfficiency)) + return this; + else if (conversionType == typeof(EnergyEfficiencyUnit)) + return Unit; + else if (conversionType == typeof(QuantityInfo)) + return EnergyEfficiency.Info; + else if (conversionType == typeof(BaseDimensions)) + return EnergyEfficiency.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(EnergyEfficiency)} 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 9432eb50b6..568098df47 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -75,6 +75,7 @@ public partial class Quantity { "ElectricSurfaceChargeDensity", ElectricSurfaceChargeDensity.Info }, { "Energy", Energy.Info }, { "EnergyDensity", EnergyDensity.Info }, + { "EnergyEfficiency", EnergyEfficiency.Info }, { "Entropy", Entropy.Info }, { "Force", Force.Info }, { "ForceChangeRate", ForceChangeRate.Info }, @@ -211,6 +212,7 @@ public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, QuantityValu "ElectricSurfaceChargeDensity" => ElectricSurfaceChargeDensity.From(value, ElectricSurfaceChargeDensity.BaseUnit), "Energy" => Energy.From(value, Energy.BaseUnit), "EnergyDensity" => EnergyDensity.From(value, EnergyDensity.BaseUnit), + "EnergyEfficiency" => EnergyEfficiency.From(value, EnergyEfficiency.BaseUnit), "Entropy" => Entropy.From(value, Entropy.BaseUnit), "Force" => Force.From(value, Force.BaseUnit), "ForceChangeRate" => ForceChangeRate.From(value, ForceChangeRate.BaseUnit), @@ -350,6 +352,7 @@ public static bool TryFrom(QuantityValue value, Enum? unit, [NotNullWhen(true)] ElectricSurfaceChargeDensityUnit electricSurfaceChargeDensityUnit => ElectricSurfaceChargeDensity.From(value, electricSurfaceChargeDensityUnit), EnergyUnit energyUnit => Energy.From(value, energyUnit), EnergyDensityUnit energyDensityUnit => EnergyDensity.From(value, energyDensityUnit), + EnergyEfficiencyUnit energyEfficiencyUnit => EnergyEfficiency.From(value, energyEfficiencyUnit), EntropyUnit entropyUnit => Entropy.From(value, entropyUnit), ForceUnit forceUnit => Force.From(value, forceUnit), ForceChangeRateUnit forceChangeRateUnit => ForceChangeRate.From(value, forceChangeRateUnit), @@ -499,6 +502,7 @@ public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, Type _ when quantityType == typeof(ElectricSurfaceChargeDensity) => parser.TryParse(quantityString, formatProvider, ElectricSurfaceChargeDensity.From, out quantity), Type _ when quantityType == typeof(Energy) => parser.TryParse(quantityString, formatProvider, Energy.From, out quantity), Type _ when quantityType == typeof(EnergyDensity) => parser.TryParse(quantityString, formatProvider, EnergyDensity.From, out quantity), + Type _ when quantityType == typeof(EnergyEfficiency) => parser.TryParse(quantityString, formatProvider, EnergyEfficiency.From, out quantity), Type _ when quantityType == typeof(Entropy) => parser.TryParse(quantityString, formatProvider, Entropy.From, out quantity), Type _ when quantityType == typeof(Force) => parser.TryParse(quantityString, formatProvider, Force.From, out quantity), Type _ when quantityType == typeof(ForceChangeRate) => parser.TryParse(quantityString, formatProvider, ForceChangeRate.From, out quantity), @@ -629,6 +633,7 @@ internal static IEnumerable GetQuantityTypes() yield return typeof(ElectricSurfaceChargeDensity); yield return typeof(Energy); yield return typeof(EnergyDensity); + yield return typeof(EnergyEfficiency); yield return typeof(Entropy); yield return typeof(Force); yield return typeof(ForceChangeRate); diff --git a/UnitsNet/GeneratedCode/Resources/EnergyEfficiency.restext b/UnitsNet/GeneratedCode/Resources/EnergyEfficiency.restext new file mode 100644 index 0000000000..a4a86243a4 --- /dev/null +++ b/UnitsNet/GeneratedCode/Resources/EnergyEfficiency.restext @@ -0,0 +1,4 @@ +KilowattHoursPerKilometer=kWh/km +KilowattHoursPerMeter=kWh/m +WattHoursPerKilometer=Wh/km +WattHoursPerMeter=Wh/m diff --git a/UnitsNet/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs b/UnitsNet/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs new file mode 100644 index 0000000000..0fc1eafbc4 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/EnergyEfficiencyUnit.g.cs @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// +// 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 EnergyEfficiencyUnit + { + KilowattHourPerKilometer = 5, + KilowattHourPerMeter = 3, + WattHourPerKilometer = 13, + WattHourPerMeter = 20, + } + + #pragma warning restore 1591 +}