From 388dbe22b594807fc1a2651f5c0b5d159c1701d0 Mon Sep 17 00:00:00 2001 From: "coding@baxenergy.com" Date: Tue, 16 Jan 2018 17:54:42 +0100 Subject: [PATCH 1/3] Added physical quantity BitRate: Base: BitPerSecond (bit/s, bps) + Prefixes: "Kilo", "Mega", "Giga", "Tera", "Peta", "Exa", "Kibi", "Mebi", "Gibi", "Tebi", "Pebi", "Exbi" Additional: BytePerSecond (B/s) + Prefixes: "Kilo", "Mega", "Giga", "Tera", "Peta", "Exa", "Kibi", "Mebi", "Gibi", "Tebi", "Pebi", "Exbi" --- UnitsNet.Tests/CustomCode/BitRateTests.cs | 101 + .../GeneratedCode/BitRateTestsBase.g.cs | 329 +++ .../Number/NumberToBitRateExtensions.g.cs | 933 +++++++++ .../GeneratedCode/Quantities/BitRate.g.cs | 1849 +++++++++++++++++ UnitsNet/GeneratedCode/QuantityType.g.cs | 1 + .../GeneratedCode/UnitSystem.Default.g.cs | 134 ++ UnitsNet/GeneratedCode/Units/BitRateUnit.g.cs | 72 + UnitsNet/UnitDefinitions/BitRate.json | 35 + 8 files changed, 3454 insertions(+) create mode 100644 UnitsNet.Tests/CustomCode/BitRateTests.cs create mode 100644 UnitsNet.Tests/GeneratedCode/BitRateTestsBase.g.cs create mode 100644 UnitsNet/GeneratedCode/Extensions/Number/NumberToBitRateExtensions.g.cs create mode 100644 UnitsNet/GeneratedCode/Quantities/BitRate.g.cs create mode 100644 UnitsNet/GeneratedCode/Units/BitRateUnit.g.cs create mode 100644 UnitsNet/UnitDefinitions/BitRate.json diff --git a/UnitsNet.Tests/CustomCode/BitRateTests.cs b/UnitsNet.Tests/CustomCode/BitRateTests.cs new file mode 100644 index 0000000000..a4ac06ad57 --- /dev/null +++ b/UnitsNet.Tests/CustomCode/BitRateTests.cs @@ -0,0 +1,101 @@ +//------------------------------------------------------------------------------ +// +// This code was generated (once) by \generate-code.bat, but will not be +// regenerated when it already exists. The purpose of creating this file is to make +// it easier to remember to implement all the unit conversion test cases. +// +// Whenever a new unit is added to this quantity and \generate-code.bat is run, +// the base test class will get a new abstract property and cause a compile error +// in this derived class, reminding the developer to implement the test case +// for the new unit. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyUnit.extra.cs files to add code to generated quantities. +// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + + +using System; + +namespace UnitsNet.Tests.CustomCode +{ + public class BitRateTests : BitRateTestsBase + { + protected override double BitsPerSecondInOneBitPerSecond => 1d; + + protected override double BytesPerSecondInOneBitPerSecond => 0.125d; + + protected override double ExabitsPerSecondInOneBitPerSecond => 1e-18d; + + protected override double ExabytesPerSecondInOneBitPerSecond => 0.125d * 1e-18d; + + protected override double ExbibitsPerSecondInOneBitPerSecond => 1d / Math.Pow(1024, 6); + + protected override double ExbibytesPerSecondInOneBitPerSecond => 8d / Math.Pow(1024, 6); + + protected override double GibibitsPerSecondInOneBitPerSecond => 1d / Math.Pow(1024, 3); + + protected override double GibibytesPerSecondInOneBitPerSecond => 1d / 8 / Math.Pow(1024, 3); + + protected override double GigabitsPerSecondInOneBitPerSecond => 1e-9d; + + protected override double GigabytesPerSecondInOneBitPerSecond => 0.125d * 1e-9d; + + protected override double KibibitsPerSecondInOneBitPerSecond => 1d / 1024d; + + protected override double KibibytesPerSecondInOneBitPerSecond => 1d / 8 / 1024d; + + protected override double KilobitsPerSecondInOneBitPerSecond => 0.001d; + + protected override double KilobytesPerSecondInOneBitPerSecond => 0.000125d; + + protected override double MebibitsPerSecondInOneBitPerSecond => 1d / Math.Pow(1024, 2); + + protected override double MebibytesPerSecondInOneBitPerSecond => 1d / 8 / Math.Pow(1024, 2); + + protected override double MegabitsPerSecondInOneBitPerSecond => 1e-6d; + + protected override double MegabytesPerSecondInOneBitPerSecond => 0.125d * 1e-6d; + + protected override double PebibitsPerSecondInOneBitPerSecond => 1d / Math.Pow(1024, 5); + + protected override double PebibytesPerSecondInOneBitPerSecond => 1d / 8 / Math.Pow(1024, 5); + + protected override double PetabitsPerSecondInOneBitPerSecond => 1e-15d; + + protected override double PetabytesPerSecondInOneBitPerSecond => 0.125d * 1e-15d; + + protected override double TebibitsPerSecondInOneBitPerSecond => 1d / Math.Pow(1024, 4); + + protected override double TebibytesPerSecondInOneBitPerSecond => 1d / 8 / Math.Pow(1024, 4); + + protected override double TerabitsPerSecondInOneBitPerSecond => 1e-12d; + + protected override double TerabytesPerSecondInOneBitPerSecond => 0.125d * 1e-12d; + } +} diff --git a/UnitsNet.Tests/GeneratedCode/BitRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/BitRateTestsBase.g.cs new file mode 100644 index 0000000000..7a1631a82f --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/BitRateTestsBase.g.cs @@ -0,0 +1,329 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyUnit.extra.cs files to add code to generated quantities. +// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using UnitsNet.Units; +using Xunit; + +// Disable build warning CS1718: Comparison made to same variable; did you mean to compare something else? +#pragma warning disable 1718 + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Tests +{ + /// + /// Test of BitRate. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class BitRateTestsBase + { + protected abstract double BitsPerSecondInOneBitPerSecond { get; } + protected abstract double BytesPerSecondInOneBitPerSecond { get; } + protected abstract double ExabitsPerSecondInOneBitPerSecond { get; } + protected abstract double ExabytesPerSecondInOneBitPerSecond { get; } + protected abstract double ExbibitsPerSecondInOneBitPerSecond { get; } + protected abstract double ExbibytesPerSecondInOneBitPerSecond { get; } + protected abstract double GibibitsPerSecondInOneBitPerSecond { get; } + protected abstract double GibibytesPerSecondInOneBitPerSecond { get; } + protected abstract double GigabitsPerSecondInOneBitPerSecond { get; } + protected abstract double GigabytesPerSecondInOneBitPerSecond { get; } + protected abstract double KibibitsPerSecondInOneBitPerSecond { get; } + protected abstract double KibibytesPerSecondInOneBitPerSecond { get; } + protected abstract double KilobitsPerSecondInOneBitPerSecond { get; } + protected abstract double KilobytesPerSecondInOneBitPerSecond { get; } + protected abstract double MebibitsPerSecondInOneBitPerSecond { get; } + protected abstract double MebibytesPerSecondInOneBitPerSecond { get; } + protected abstract double MegabitsPerSecondInOneBitPerSecond { get; } + protected abstract double MegabytesPerSecondInOneBitPerSecond { get; } + protected abstract double PebibitsPerSecondInOneBitPerSecond { get; } + protected abstract double PebibytesPerSecondInOneBitPerSecond { get; } + protected abstract double PetabitsPerSecondInOneBitPerSecond { get; } + protected abstract double PetabytesPerSecondInOneBitPerSecond { get; } + protected abstract double TebibitsPerSecondInOneBitPerSecond { get; } + protected abstract double TebibytesPerSecondInOneBitPerSecond { get; } + protected abstract double TerabitsPerSecondInOneBitPerSecond { get; } + protected abstract double TerabytesPerSecondInOneBitPerSecond { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double BitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double BytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double ExabitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double ExabytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double ExbibitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double ExbibytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double GibibitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double GibibytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double GigabitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double GigabytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double KibibitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double KibibytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double KilobitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double KilobytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double MebibitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double MebibytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double MegabitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double MegabytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double PebibitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double PebibytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double PetabitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double PetabytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double TebibitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double TebibytesPerSecondTolerance { get { return 1e-5; } } + protected virtual double TerabitsPerSecondTolerance { get { return 1e-5; } } + protected virtual double TerabytesPerSecondTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void BitPerSecondToBitRateUnits() + { + BitRate bitpersecond = BitRate.FromBitsPerSecond(1); + AssertEx.EqualTolerance(BitsPerSecondInOneBitPerSecond, bitpersecond.BitsPerSecond, BitsPerSecondTolerance); + AssertEx.EqualTolerance(BytesPerSecondInOneBitPerSecond, bitpersecond.BytesPerSecond, BytesPerSecondTolerance); + AssertEx.EqualTolerance(ExabitsPerSecondInOneBitPerSecond, bitpersecond.ExabitsPerSecond, ExabitsPerSecondTolerance); + AssertEx.EqualTolerance(ExabytesPerSecondInOneBitPerSecond, bitpersecond.ExabytesPerSecond, ExabytesPerSecondTolerance); + AssertEx.EqualTolerance(ExbibitsPerSecondInOneBitPerSecond, bitpersecond.ExbibitsPerSecond, ExbibitsPerSecondTolerance); + AssertEx.EqualTolerance(ExbibytesPerSecondInOneBitPerSecond, bitpersecond.ExbibytesPerSecond, ExbibytesPerSecondTolerance); + AssertEx.EqualTolerance(GibibitsPerSecondInOneBitPerSecond, bitpersecond.GibibitsPerSecond, GibibitsPerSecondTolerance); + AssertEx.EqualTolerance(GibibytesPerSecondInOneBitPerSecond, bitpersecond.GibibytesPerSecond, GibibytesPerSecondTolerance); + AssertEx.EqualTolerance(GigabitsPerSecondInOneBitPerSecond, bitpersecond.GigabitsPerSecond, GigabitsPerSecondTolerance); + AssertEx.EqualTolerance(GigabytesPerSecondInOneBitPerSecond, bitpersecond.GigabytesPerSecond, GigabytesPerSecondTolerance); + AssertEx.EqualTolerance(KibibitsPerSecondInOneBitPerSecond, bitpersecond.KibibitsPerSecond, KibibitsPerSecondTolerance); + AssertEx.EqualTolerance(KibibytesPerSecondInOneBitPerSecond, bitpersecond.KibibytesPerSecond, KibibytesPerSecondTolerance); + AssertEx.EqualTolerance(KilobitsPerSecondInOneBitPerSecond, bitpersecond.KilobitsPerSecond, KilobitsPerSecondTolerance); + AssertEx.EqualTolerance(KilobytesPerSecondInOneBitPerSecond, bitpersecond.KilobytesPerSecond, KilobytesPerSecondTolerance); + AssertEx.EqualTolerance(MebibitsPerSecondInOneBitPerSecond, bitpersecond.MebibitsPerSecond, MebibitsPerSecondTolerance); + AssertEx.EqualTolerance(MebibytesPerSecondInOneBitPerSecond, bitpersecond.MebibytesPerSecond, MebibytesPerSecondTolerance); + AssertEx.EqualTolerance(MegabitsPerSecondInOneBitPerSecond, bitpersecond.MegabitsPerSecond, MegabitsPerSecondTolerance); + AssertEx.EqualTolerance(MegabytesPerSecondInOneBitPerSecond, bitpersecond.MegabytesPerSecond, MegabytesPerSecondTolerance); + AssertEx.EqualTolerance(PebibitsPerSecondInOneBitPerSecond, bitpersecond.PebibitsPerSecond, PebibitsPerSecondTolerance); + AssertEx.EqualTolerance(PebibytesPerSecondInOneBitPerSecond, bitpersecond.PebibytesPerSecond, PebibytesPerSecondTolerance); + AssertEx.EqualTolerance(PetabitsPerSecondInOneBitPerSecond, bitpersecond.PetabitsPerSecond, PetabitsPerSecondTolerance); + AssertEx.EqualTolerance(PetabytesPerSecondInOneBitPerSecond, bitpersecond.PetabytesPerSecond, PetabytesPerSecondTolerance); + AssertEx.EqualTolerance(TebibitsPerSecondInOneBitPerSecond, bitpersecond.TebibitsPerSecond, TebibitsPerSecondTolerance); + AssertEx.EqualTolerance(TebibytesPerSecondInOneBitPerSecond, bitpersecond.TebibytesPerSecond, TebibytesPerSecondTolerance); + AssertEx.EqualTolerance(TerabitsPerSecondInOneBitPerSecond, bitpersecond.TerabitsPerSecond, TerabitsPerSecondTolerance); + AssertEx.EqualTolerance(TerabytesPerSecondInOneBitPerSecond, bitpersecond.TerabytesPerSecond, TerabytesPerSecondTolerance); + } + + [Fact] + public void FromValueAndUnit() + { + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.BitPerSecond).BitsPerSecond, BitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.BytePerSecond).BytesPerSecond, BytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.ExabitPerSecond).ExabitsPerSecond, ExabitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.ExabytePerSecond).ExabytesPerSecond, ExabytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.ExbibitPerSecond).ExbibitsPerSecond, ExbibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.ExbibytePerSecond).ExbibytesPerSecond, ExbibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.GibibitPerSecond).GibibitsPerSecond, GibibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.GibibytePerSecond).GibibytesPerSecond, GibibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.GigabitPerSecond).GigabitsPerSecond, GigabitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.GigabytePerSecond).GigabytesPerSecond, GigabytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.KibibitPerSecond).KibibitsPerSecond, KibibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.KibibytePerSecond).KibibytesPerSecond, KibibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.KilobitPerSecond).KilobitsPerSecond, KilobitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.KilobytePerSecond).KilobytesPerSecond, KilobytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.MebibitPerSecond).MebibitsPerSecond, MebibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.MebibytePerSecond).MebibytesPerSecond, MebibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.MegabitPerSecond).MegabitsPerSecond, MegabitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.MegabytePerSecond).MegabytesPerSecond, MegabytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.PebibitPerSecond).PebibitsPerSecond, PebibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.PebibytePerSecond).PebibytesPerSecond, PebibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.PetabitPerSecond).PetabitsPerSecond, PetabitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.PetabytePerSecond).PetabytesPerSecond, PetabytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.TebibitPerSecond).TebibitsPerSecond, TebibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.TebibytePerSecond).TebibytesPerSecond, TebibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.TerabitPerSecond).TerabitsPerSecond, TerabitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.From(1, BitRateUnit.TerabytePerSecond).TerabytesPerSecond, TerabytesPerSecondTolerance); + } + + [Fact] + public void As() + { + var bitpersecond = BitRate.FromBitsPerSecond(1); + AssertEx.EqualTolerance(BitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.BitPerSecond), BitsPerSecondTolerance); + AssertEx.EqualTolerance(BytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.BytePerSecond), BytesPerSecondTolerance); + AssertEx.EqualTolerance(ExabitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.ExabitPerSecond), ExabitsPerSecondTolerance); + AssertEx.EqualTolerance(ExabytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.ExabytePerSecond), ExabytesPerSecondTolerance); + AssertEx.EqualTolerance(ExbibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.ExbibitPerSecond), ExbibitsPerSecondTolerance); + AssertEx.EqualTolerance(ExbibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.ExbibytePerSecond), ExbibytesPerSecondTolerance); + AssertEx.EqualTolerance(GibibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.GibibitPerSecond), GibibitsPerSecondTolerance); + AssertEx.EqualTolerance(GibibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.GibibytePerSecond), GibibytesPerSecondTolerance); + AssertEx.EqualTolerance(GigabitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.GigabitPerSecond), GigabitsPerSecondTolerance); + AssertEx.EqualTolerance(GigabytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.GigabytePerSecond), GigabytesPerSecondTolerance); + AssertEx.EqualTolerance(KibibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.KibibitPerSecond), KibibitsPerSecondTolerance); + AssertEx.EqualTolerance(KibibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.KibibytePerSecond), KibibytesPerSecondTolerance); + AssertEx.EqualTolerance(KilobitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.KilobitPerSecond), KilobitsPerSecondTolerance); + AssertEx.EqualTolerance(KilobytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.KilobytePerSecond), KilobytesPerSecondTolerance); + AssertEx.EqualTolerance(MebibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.MebibitPerSecond), MebibitsPerSecondTolerance); + AssertEx.EqualTolerance(MebibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.MebibytePerSecond), MebibytesPerSecondTolerance); + AssertEx.EqualTolerance(MegabitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.MegabitPerSecond), MegabitsPerSecondTolerance); + AssertEx.EqualTolerance(MegabytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.MegabytePerSecond), MegabytesPerSecondTolerance); + AssertEx.EqualTolerance(PebibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.PebibitPerSecond), PebibitsPerSecondTolerance); + AssertEx.EqualTolerance(PebibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.PebibytePerSecond), PebibytesPerSecondTolerance); + AssertEx.EqualTolerance(PetabitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.PetabitPerSecond), PetabitsPerSecondTolerance); + AssertEx.EqualTolerance(PetabytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.PetabytePerSecond), PetabytesPerSecondTolerance); + AssertEx.EqualTolerance(TebibitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.TebibitPerSecond), TebibitsPerSecondTolerance); + AssertEx.EqualTolerance(TebibytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.TebibytePerSecond), TebibytesPerSecondTolerance); + AssertEx.EqualTolerance(TerabitsPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.TerabitPerSecond), TerabitsPerSecondTolerance); + AssertEx.EqualTolerance(TerabytesPerSecondInOneBitPerSecond, bitpersecond.As(BitRateUnit.TerabytePerSecond), TerabytesPerSecondTolerance); + } + + [Fact] + public void ConversionRoundTrip() + { + BitRate bitpersecond = BitRate.FromBitsPerSecond(1); + AssertEx.EqualTolerance(1, BitRate.FromBitsPerSecond(bitpersecond.BitsPerSecond).BitsPerSecond, BitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromBytesPerSecond(bitpersecond.BytesPerSecond).BitsPerSecond, BytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromExabitsPerSecond(bitpersecond.ExabitsPerSecond).BitsPerSecond, ExabitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromExabytesPerSecond(bitpersecond.ExabytesPerSecond).BitsPerSecond, ExabytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromExbibitsPerSecond(bitpersecond.ExbibitsPerSecond).BitsPerSecond, ExbibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromExbibytesPerSecond(bitpersecond.ExbibytesPerSecond).BitsPerSecond, ExbibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromGibibitsPerSecond(bitpersecond.GibibitsPerSecond).BitsPerSecond, GibibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromGibibytesPerSecond(bitpersecond.GibibytesPerSecond).BitsPerSecond, GibibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromGigabitsPerSecond(bitpersecond.GigabitsPerSecond).BitsPerSecond, GigabitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromGigabytesPerSecond(bitpersecond.GigabytesPerSecond).BitsPerSecond, GigabytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromKibibitsPerSecond(bitpersecond.KibibitsPerSecond).BitsPerSecond, KibibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromKibibytesPerSecond(bitpersecond.KibibytesPerSecond).BitsPerSecond, KibibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromKilobitsPerSecond(bitpersecond.KilobitsPerSecond).BitsPerSecond, KilobitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromKilobytesPerSecond(bitpersecond.KilobytesPerSecond).BitsPerSecond, KilobytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromMebibitsPerSecond(bitpersecond.MebibitsPerSecond).BitsPerSecond, MebibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromMebibytesPerSecond(bitpersecond.MebibytesPerSecond).BitsPerSecond, MebibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromMegabitsPerSecond(bitpersecond.MegabitsPerSecond).BitsPerSecond, MegabitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromMegabytesPerSecond(bitpersecond.MegabytesPerSecond).BitsPerSecond, MegabytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromPebibitsPerSecond(bitpersecond.PebibitsPerSecond).BitsPerSecond, PebibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromPebibytesPerSecond(bitpersecond.PebibytesPerSecond).BitsPerSecond, PebibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromPetabitsPerSecond(bitpersecond.PetabitsPerSecond).BitsPerSecond, PetabitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromPetabytesPerSecond(bitpersecond.PetabytesPerSecond).BitsPerSecond, PetabytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromTebibitsPerSecond(bitpersecond.TebibitsPerSecond).BitsPerSecond, TebibitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromTebibytesPerSecond(bitpersecond.TebibytesPerSecond).BitsPerSecond, TebibytesPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromTerabitsPerSecond(bitpersecond.TerabitsPerSecond).BitsPerSecond, TerabitsPerSecondTolerance); + AssertEx.EqualTolerance(1, BitRate.FromTerabytesPerSecond(bitpersecond.TerabytesPerSecond).BitsPerSecond, TerabytesPerSecondTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + BitRate v = BitRate.FromBitsPerSecond(1); + AssertEx.EqualTolerance(-1, -v.BitsPerSecond, BitsPerSecondTolerance); + AssertEx.EqualTolerance(2, (BitRate.FromBitsPerSecond(3)-v).BitsPerSecond, BitsPerSecondTolerance); + AssertEx.EqualTolerance(2, (v + v).BitsPerSecond, BitsPerSecondTolerance); + AssertEx.EqualTolerance(10, (v*10).BitsPerSecond, BitsPerSecondTolerance); + AssertEx.EqualTolerance(10, (10*v).BitsPerSecond, BitsPerSecondTolerance); + AssertEx.EqualTolerance(2, (BitRate.FromBitsPerSecond(10)/5).BitsPerSecond, BitsPerSecondTolerance); + AssertEx.EqualTolerance(2, BitRate.FromBitsPerSecond(10)/BitRate.FromBitsPerSecond(5), BitsPerSecondTolerance); + } + + [Fact] + public void ComparisonOperators() + { + BitRate oneBitPerSecond = BitRate.FromBitsPerSecond(1); + BitRate twoBitsPerSecond = BitRate.FromBitsPerSecond(2); + + Assert.True(oneBitPerSecond < twoBitsPerSecond); + Assert.True(oneBitPerSecond <= twoBitsPerSecond); + Assert.True(twoBitsPerSecond > oneBitPerSecond); + Assert.True(twoBitsPerSecond >= oneBitPerSecond); + + Assert.False(oneBitPerSecond > twoBitsPerSecond); + Assert.False(oneBitPerSecond >= twoBitsPerSecond); + Assert.False(twoBitsPerSecond < oneBitPerSecond); + Assert.False(twoBitsPerSecond <= oneBitPerSecond); + } + + [Fact] + public void CompareToIsImplemented() + { + BitRate bitpersecond = BitRate.FromBitsPerSecond(1); + Assert.Equal(0, bitpersecond.CompareTo(bitpersecond)); + Assert.True(bitpersecond.CompareTo(BitRate.Zero) > 0); + Assert.True(BitRate.Zero.CompareTo(bitpersecond) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + BitRate bitpersecond = BitRate.FromBitsPerSecond(1); + Assert.Throws(() => bitpersecond.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + BitRate bitpersecond = BitRate.FromBitsPerSecond(1); + Assert.Throws(() => bitpersecond.CompareTo(null)); + } + + + [Fact] + public void EqualityOperators() + { + BitRate a = BitRate.FromBitsPerSecond(1); + BitRate b = BitRate.FromBitsPerSecond(2); + +// ReSharper disable EqualExpressionComparison + Assert.True(a == a); + Assert.True(a != b); + + Assert.False(a == b); + Assert.False(a != a); +// ReSharper restore EqualExpressionComparison + } + + [Fact] + public void EqualsIsImplemented() + { + BitRate v = BitRate.FromBitsPerSecond(1); + Assert.True(v.Equals(BitRate.FromBitsPerSecond(1), BitRate.FromBitsPerSecond(BitsPerSecondTolerance))); + Assert.False(v.Equals(BitRate.Zero, BitRate.FromBitsPerSecond(BitsPerSecondTolerance))); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + BitRate bitpersecond = BitRate.FromBitsPerSecond(1); + Assert.False(bitpersecond.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + BitRate bitpersecond = BitRate.FromBitsPerSecond(1); + Assert.False(bitpersecond.Equals(null)); + } + } +} diff --git a/UnitsNet/GeneratedCode/Extensions/Number/NumberToBitRateExtensions.g.cs b/UnitsNet/GeneratedCode/Extensions/Number/NumberToBitRateExtensions.g.cs new file mode 100644 index 0000000000..4150b55c4a --- /dev/null +++ b/UnitsNet/GeneratedCode/Extensions/Number/NumberToBitRateExtensions.g.cs @@ -0,0 +1,933 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyUnit.extra.cs files to add code to generated quantities. +// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; + +// Windows Runtime Component does not support extension methods and method overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP +namespace UnitsNet.Extensions.NumberToBitRate +{ + public static class NumberToBitRateExtensions + { + #region BitPerSecond + + /// + public static BitRate BitsPerSecond(this int value) => BitRate.FromBitsPerSecond(value); + + /// + public static BitRate? BitsPerSecond(this int? value) => BitRate.FromBitsPerSecond(value); + + /// + public static BitRate BitsPerSecond(this long value) => BitRate.FromBitsPerSecond(value); + + /// + public static BitRate? BitsPerSecond(this long? value) => BitRate.FromBitsPerSecond(value); + + /// + public static BitRate BitsPerSecond(this double value) => BitRate.FromBitsPerSecond(value); + + /// + public static BitRate? BitsPerSecond(this double? value) => BitRate.FromBitsPerSecond(value); + + /// + public static BitRate BitsPerSecond(this float value) => BitRate.FromBitsPerSecond(value); + + /// + public static BitRate? BitsPerSecond(this float? value) => BitRate.FromBitsPerSecond(value); + + /// + public static BitRate BitsPerSecond(this decimal value) => BitRate.FromBitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? BitsPerSecond(this decimal? value) => BitRate.FromBitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region BytePerSecond + + /// + public static BitRate BytesPerSecond(this int value) => BitRate.FromBytesPerSecond(value); + + /// + public static BitRate? BytesPerSecond(this int? value) => BitRate.FromBytesPerSecond(value); + + /// + public static BitRate BytesPerSecond(this long value) => BitRate.FromBytesPerSecond(value); + + /// + public static BitRate? BytesPerSecond(this long? value) => BitRate.FromBytesPerSecond(value); + + /// + public static BitRate BytesPerSecond(this double value) => BitRate.FromBytesPerSecond(value); + + /// + public static BitRate? BytesPerSecond(this double? value) => BitRate.FromBytesPerSecond(value); + + /// + public static BitRate BytesPerSecond(this float value) => BitRate.FromBytesPerSecond(value); + + /// + public static BitRate? BytesPerSecond(this float? value) => BitRate.FromBytesPerSecond(value); + + /// + public static BitRate BytesPerSecond(this decimal value) => BitRate.FromBytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? BytesPerSecond(this decimal? value) => BitRate.FromBytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region ExabitPerSecond + + /// + public static BitRate ExabitsPerSecond(this int value) => BitRate.FromExabitsPerSecond(value); + + /// + public static BitRate? ExabitsPerSecond(this int? value) => BitRate.FromExabitsPerSecond(value); + + /// + public static BitRate ExabitsPerSecond(this long value) => BitRate.FromExabitsPerSecond(value); + + /// + public static BitRate? ExabitsPerSecond(this long? value) => BitRate.FromExabitsPerSecond(value); + + /// + public static BitRate ExabitsPerSecond(this double value) => BitRate.FromExabitsPerSecond(value); + + /// + public static BitRate? ExabitsPerSecond(this double? value) => BitRate.FromExabitsPerSecond(value); + + /// + public static BitRate ExabitsPerSecond(this float value) => BitRate.FromExabitsPerSecond(value); + + /// + public static BitRate? ExabitsPerSecond(this float? value) => BitRate.FromExabitsPerSecond(value); + + /// + public static BitRate ExabitsPerSecond(this decimal value) => BitRate.FromExabitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? ExabitsPerSecond(this decimal? value) => BitRate.FromExabitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region ExabytePerSecond + + /// + public static BitRate ExabytesPerSecond(this int value) => BitRate.FromExabytesPerSecond(value); + + /// + public static BitRate? ExabytesPerSecond(this int? value) => BitRate.FromExabytesPerSecond(value); + + /// + public static BitRate ExabytesPerSecond(this long value) => BitRate.FromExabytesPerSecond(value); + + /// + public static BitRate? ExabytesPerSecond(this long? value) => BitRate.FromExabytesPerSecond(value); + + /// + public static BitRate ExabytesPerSecond(this double value) => BitRate.FromExabytesPerSecond(value); + + /// + public static BitRate? ExabytesPerSecond(this double? value) => BitRate.FromExabytesPerSecond(value); + + /// + public static BitRate ExabytesPerSecond(this float value) => BitRate.FromExabytesPerSecond(value); + + /// + public static BitRate? ExabytesPerSecond(this float? value) => BitRate.FromExabytesPerSecond(value); + + /// + public static BitRate ExabytesPerSecond(this decimal value) => BitRate.FromExabytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? ExabytesPerSecond(this decimal? value) => BitRate.FromExabytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region ExbibitPerSecond + + /// + public static BitRate ExbibitsPerSecond(this int value) => BitRate.FromExbibitsPerSecond(value); + + /// + public static BitRate? ExbibitsPerSecond(this int? value) => BitRate.FromExbibitsPerSecond(value); + + /// + public static BitRate ExbibitsPerSecond(this long value) => BitRate.FromExbibitsPerSecond(value); + + /// + public static BitRate? ExbibitsPerSecond(this long? value) => BitRate.FromExbibitsPerSecond(value); + + /// + public static BitRate ExbibitsPerSecond(this double value) => BitRate.FromExbibitsPerSecond(value); + + /// + public static BitRate? ExbibitsPerSecond(this double? value) => BitRate.FromExbibitsPerSecond(value); + + /// + public static BitRate ExbibitsPerSecond(this float value) => BitRate.FromExbibitsPerSecond(value); + + /// + public static BitRate? ExbibitsPerSecond(this float? value) => BitRate.FromExbibitsPerSecond(value); + + /// + public static BitRate ExbibitsPerSecond(this decimal value) => BitRate.FromExbibitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? ExbibitsPerSecond(this decimal? value) => BitRate.FromExbibitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region ExbibytePerSecond + + /// + public static BitRate ExbibytesPerSecond(this int value) => BitRate.FromExbibytesPerSecond(value); + + /// + public static BitRate? ExbibytesPerSecond(this int? value) => BitRate.FromExbibytesPerSecond(value); + + /// + public static BitRate ExbibytesPerSecond(this long value) => BitRate.FromExbibytesPerSecond(value); + + /// + public static BitRate? ExbibytesPerSecond(this long? value) => BitRate.FromExbibytesPerSecond(value); + + /// + public static BitRate ExbibytesPerSecond(this double value) => BitRate.FromExbibytesPerSecond(value); + + /// + public static BitRate? ExbibytesPerSecond(this double? value) => BitRate.FromExbibytesPerSecond(value); + + /// + public static BitRate ExbibytesPerSecond(this float value) => BitRate.FromExbibytesPerSecond(value); + + /// + public static BitRate? ExbibytesPerSecond(this float? value) => BitRate.FromExbibytesPerSecond(value); + + /// + public static BitRate ExbibytesPerSecond(this decimal value) => BitRate.FromExbibytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? ExbibytesPerSecond(this decimal? value) => BitRate.FromExbibytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region GibibitPerSecond + + /// + public static BitRate GibibitsPerSecond(this int value) => BitRate.FromGibibitsPerSecond(value); + + /// + public static BitRate? GibibitsPerSecond(this int? value) => BitRate.FromGibibitsPerSecond(value); + + /// + public static BitRate GibibitsPerSecond(this long value) => BitRate.FromGibibitsPerSecond(value); + + /// + public static BitRate? GibibitsPerSecond(this long? value) => BitRate.FromGibibitsPerSecond(value); + + /// + public static BitRate GibibitsPerSecond(this double value) => BitRate.FromGibibitsPerSecond(value); + + /// + public static BitRate? GibibitsPerSecond(this double? value) => BitRate.FromGibibitsPerSecond(value); + + /// + public static BitRate GibibitsPerSecond(this float value) => BitRate.FromGibibitsPerSecond(value); + + /// + public static BitRate? GibibitsPerSecond(this float? value) => BitRate.FromGibibitsPerSecond(value); + + /// + public static BitRate GibibitsPerSecond(this decimal value) => BitRate.FromGibibitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? GibibitsPerSecond(this decimal? value) => BitRate.FromGibibitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region GibibytePerSecond + + /// + public static BitRate GibibytesPerSecond(this int value) => BitRate.FromGibibytesPerSecond(value); + + /// + public static BitRate? GibibytesPerSecond(this int? value) => BitRate.FromGibibytesPerSecond(value); + + /// + public static BitRate GibibytesPerSecond(this long value) => BitRate.FromGibibytesPerSecond(value); + + /// + public static BitRate? GibibytesPerSecond(this long? value) => BitRate.FromGibibytesPerSecond(value); + + /// + public static BitRate GibibytesPerSecond(this double value) => BitRate.FromGibibytesPerSecond(value); + + /// + public static BitRate? GibibytesPerSecond(this double? value) => BitRate.FromGibibytesPerSecond(value); + + /// + public static BitRate GibibytesPerSecond(this float value) => BitRate.FromGibibytesPerSecond(value); + + /// + public static BitRate? GibibytesPerSecond(this float? value) => BitRate.FromGibibytesPerSecond(value); + + /// + public static BitRate GibibytesPerSecond(this decimal value) => BitRate.FromGibibytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? GibibytesPerSecond(this decimal? value) => BitRate.FromGibibytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region GigabitPerSecond + + /// + public static BitRate GigabitsPerSecond(this int value) => BitRate.FromGigabitsPerSecond(value); + + /// + public static BitRate? GigabitsPerSecond(this int? value) => BitRate.FromGigabitsPerSecond(value); + + /// + public static BitRate GigabitsPerSecond(this long value) => BitRate.FromGigabitsPerSecond(value); + + /// + public static BitRate? GigabitsPerSecond(this long? value) => BitRate.FromGigabitsPerSecond(value); + + /// + public static BitRate GigabitsPerSecond(this double value) => BitRate.FromGigabitsPerSecond(value); + + /// + public static BitRate? GigabitsPerSecond(this double? value) => BitRate.FromGigabitsPerSecond(value); + + /// + public static BitRate GigabitsPerSecond(this float value) => BitRate.FromGigabitsPerSecond(value); + + /// + public static BitRate? GigabitsPerSecond(this float? value) => BitRate.FromGigabitsPerSecond(value); + + /// + public static BitRate GigabitsPerSecond(this decimal value) => BitRate.FromGigabitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? GigabitsPerSecond(this decimal? value) => BitRate.FromGigabitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region GigabytePerSecond + + /// + public static BitRate GigabytesPerSecond(this int value) => BitRate.FromGigabytesPerSecond(value); + + /// + public static BitRate? GigabytesPerSecond(this int? value) => BitRate.FromGigabytesPerSecond(value); + + /// + public static BitRate GigabytesPerSecond(this long value) => BitRate.FromGigabytesPerSecond(value); + + /// + public static BitRate? GigabytesPerSecond(this long? value) => BitRate.FromGigabytesPerSecond(value); + + /// + public static BitRate GigabytesPerSecond(this double value) => BitRate.FromGigabytesPerSecond(value); + + /// + public static BitRate? GigabytesPerSecond(this double? value) => BitRate.FromGigabytesPerSecond(value); + + /// + public static BitRate GigabytesPerSecond(this float value) => BitRate.FromGigabytesPerSecond(value); + + /// + public static BitRate? GigabytesPerSecond(this float? value) => BitRate.FromGigabytesPerSecond(value); + + /// + public static BitRate GigabytesPerSecond(this decimal value) => BitRate.FromGigabytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? GigabytesPerSecond(this decimal? value) => BitRate.FromGigabytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region KibibitPerSecond + + /// + public static BitRate KibibitsPerSecond(this int value) => BitRate.FromKibibitsPerSecond(value); + + /// + public static BitRate? KibibitsPerSecond(this int? value) => BitRate.FromKibibitsPerSecond(value); + + /// + public static BitRate KibibitsPerSecond(this long value) => BitRate.FromKibibitsPerSecond(value); + + /// + public static BitRate? KibibitsPerSecond(this long? value) => BitRate.FromKibibitsPerSecond(value); + + /// + public static BitRate KibibitsPerSecond(this double value) => BitRate.FromKibibitsPerSecond(value); + + /// + public static BitRate? KibibitsPerSecond(this double? value) => BitRate.FromKibibitsPerSecond(value); + + /// + public static BitRate KibibitsPerSecond(this float value) => BitRate.FromKibibitsPerSecond(value); + + /// + public static BitRate? KibibitsPerSecond(this float? value) => BitRate.FromKibibitsPerSecond(value); + + /// + public static BitRate KibibitsPerSecond(this decimal value) => BitRate.FromKibibitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? KibibitsPerSecond(this decimal? value) => BitRate.FromKibibitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region KibibytePerSecond + + /// + public static BitRate KibibytesPerSecond(this int value) => BitRate.FromKibibytesPerSecond(value); + + /// + public static BitRate? KibibytesPerSecond(this int? value) => BitRate.FromKibibytesPerSecond(value); + + /// + public static BitRate KibibytesPerSecond(this long value) => BitRate.FromKibibytesPerSecond(value); + + /// + public static BitRate? KibibytesPerSecond(this long? value) => BitRate.FromKibibytesPerSecond(value); + + /// + public static BitRate KibibytesPerSecond(this double value) => BitRate.FromKibibytesPerSecond(value); + + /// + public static BitRate? KibibytesPerSecond(this double? value) => BitRate.FromKibibytesPerSecond(value); + + /// + public static BitRate KibibytesPerSecond(this float value) => BitRate.FromKibibytesPerSecond(value); + + /// + public static BitRate? KibibytesPerSecond(this float? value) => BitRate.FromKibibytesPerSecond(value); + + /// + public static BitRate KibibytesPerSecond(this decimal value) => BitRate.FromKibibytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? KibibytesPerSecond(this decimal? value) => BitRate.FromKibibytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region KilobitPerSecond + + /// + public static BitRate KilobitsPerSecond(this int value) => BitRate.FromKilobitsPerSecond(value); + + /// + public static BitRate? KilobitsPerSecond(this int? value) => BitRate.FromKilobitsPerSecond(value); + + /// + public static BitRate KilobitsPerSecond(this long value) => BitRate.FromKilobitsPerSecond(value); + + /// + public static BitRate? KilobitsPerSecond(this long? value) => BitRate.FromKilobitsPerSecond(value); + + /// + public static BitRate KilobitsPerSecond(this double value) => BitRate.FromKilobitsPerSecond(value); + + /// + public static BitRate? KilobitsPerSecond(this double? value) => BitRate.FromKilobitsPerSecond(value); + + /// + public static BitRate KilobitsPerSecond(this float value) => BitRate.FromKilobitsPerSecond(value); + + /// + public static BitRate? KilobitsPerSecond(this float? value) => BitRate.FromKilobitsPerSecond(value); + + /// + public static BitRate KilobitsPerSecond(this decimal value) => BitRate.FromKilobitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? KilobitsPerSecond(this decimal? value) => BitRate.FromKilobitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region KilobytePerSecond + + /// + public static BitRate KilobytesPerSecond(this int value) => BitRate.FromKilobytesPerSecond(value); + + /// + public static BitRate? KilobytesPerSecond(this int? value) => BitRate.FromKilobytesPerSecond(value); + + /// + public static BitRate KilobytesPerSecond(this long value) => BitRate.FromKilobytesPerSecond(value); + + /// + public static BitRate? KilobytesPerSecond(this long? value) => BitRate.FromKilobytesPerSecond(value); + + /// + public static BitRate KilobytesPerSecond(this double value) => BitRate.FromKilobytesPerSecond(value); + + /// + public static BitRate? KilobytesPerSecond(this double? value) => BitRate.FromKilobytesPerSecond(value); + + /// + public static BitRate KilobytesPerSecond(this float value) => BitRate.FromKilobytesPerSecond(value); + + /// + public static BitRate? KilobytesPerSecond(this float? value) => BitRate.FromKilobytesPerSecond(value); + + /// + public static BitRate KilobytesPerSecond(this decimal value) => BitRate.FromKilobytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? KilobytesPerSecond(this decimal? value) => BitRate.FromKilobytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region MebibitPerSecond + + /// + public static BitRate MebibitsPerSecond(this int value) => BitRate.FromMebibitsPerSecond(value); + + /// + public static BitRate? MebibitsPerSecond(this int? value) => BitRate.FromMebibitsPerSecond(value); + + /// + public static BitRate MebibitsPerSecond(this long value) => BitRate.FromMebibitsPerSecond(value); + + /// + public static BitRate? MebibitsPerSecond(this long? value) => BitRate.FromMebibitsPerSecond(value); + + /// + public static BitRate MebibitsPerSecond(this double value) => BitRate.FromMebibitsPerSecond(value); + + /// + public static BitRate? MebibitsPerSecond(this double? value) => BitRate.FromMebibitsPerSecond(value); + + /// + public static BitRate MebibitsPerSecond(this float value) => BitRate.FromMebibitsPerSecond(value); + + /// + public static BitRate? MebibitsPerSecond(this float? value) => BitRate.FromMebibitsPerSecond(value); + + /// + public static BitRate MebibitsPerSecond(this decimal value) => BitRate.FromMebibitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? MebibitsPerSecond(this decimal? value) => BitRate.FromMebibitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region MebibytePerSecond + + /// + public static BitRate MebibytesPerSecond(this int value) => BitRate.FromMebibytesPerSecond(value); + + /// + public static BitRate? MebibytesPerSecond(this int? value) => BitRate.FromMebibytesPerSecond(value); + + /// + public static BitRate MebibytesPerSecond(this long value) => BitRate.FromMebibytesPerSecond(value); + + /// + public static BitRate? MebibytesPerSecond(this long? value) => BitRate.FromMebibytesPerSecond(value); + + /// + public static BitRate MebibytesPerSecond(this double value) => BitRate.FromMebibytesPerSecond(value); + + /// + public static BitRate? MebibytesPerSecond(this double? value) => BitRate.FromMebibytesPerSecond(value); + + /// + public static BitRate MebibytesPerSecond(this float value) => BitRate.FromMebibytesPerSecond(value); + + /// + public static BitRate? MebibytesPerSecond(this float? value) => BitRate.FromMebibytesPerSecond(value); + + /// + public static BitRate MebibytesPerSecond(this decimal value) => BitRate.FromMebibytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? MebibytesPerSecond(this decimal? value) => BitRate.FromMebibytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region MegabitPerSecond + + /// + public static BitRate MegabitsPerSecond(this int value) => BitRate.FromMegabitsPerSecond(value); + + /// + public static BitRate? MegabitsPerSecond(this int? value) => BitRate.FromMegabitsPerSecond(value); + + /// + public static BitRate MegabitsPerSecond(this long value) => BitRate.FromMegabitsPerSecond(value); + + /// + public static BitRate? MegabitsPerSecond(this long? value) => BitRate.FromMegabitsPerSecond(value); + + /// + public static BitRate MegabitsPerSecond(this double value) => BitRate.FromMegabitsPerSecond(value); + + /// + public static BitRate? MegabitsPerSecond(this double? value) => BitRate.FromMegabitsPerSecond(value); + + /// + public static BitRate MegabitsPerSecond(this float value) => BitRate.FromMegabitsPerSecond(value); + + /// + public static BitRate? MegabitsPerSecond(this float? value) => BitRate.FromMegabitsPerSecond(value); + + /// + public static BitRate MegabitsPerSecond(this decimal value) => BitRate.FromMegabitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? MegabitsPerSecond(this decimal? value) => BitRate.FromMegabitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region MegabytePerSecond + + /// + public static BitRate MegabytesPerSecond(this int value) => BitRate.FromMegabytesPerSecond(value); + + /// + public static BitRate? MegabytesPerSecond(this int? value) => BitRate.FromMegabytesPerSecond(value); + + /// + public static BitRate MegabytesPerSecond(this long value) => BitRate.FromMegabytesPerSecond(value); + + /// + public static BitRate? MegabytesPerSecond(this long? value) => BitRate.FromMegabytesPerSecond(value); + + /// + public static BitRate MegabytesPerSecond(this double value) => BitRate.FromMegabytesPerSecond(value); + + /// + public static BitRate? MegabytesPerSecond(this double? value) => BitRate.FromMegabytesPerSecond(value); + + /// + public static BitRate MegabytesPerSecond(this float value) => BitRate.FromMegabytesPerSecond(value); + + /// + public static BitRate? MegabytesPerSecond(this float? value) => BitRate.FromMegabytesPerSecond(value); + + /// + public static BitRate MegabytesPerSecond(this decimal value) => BitRate.FromMegabytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? MegabytesPerSecond(this decimal? value) => BitRate.FromMegabytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region PebibitPerSecond + + /// + public static BitRate PebibitsPerSecond(this int value) => BitRate.FromPebibitsPerSecond(value); + + /// + public static BitRate? PebibitsPerSecond(this int? value) => BitRate.FromPebibitsPerSecond(value); + + /// + public static BitRate PebibitsPerSecond(this long value) => BitRate.FromPebibitsPerSecond(value); + + /// + public static BitRate? PebibitsPerSecond(this long? value) => BitRate.FromPebibitsPerSecond(value); + + /// + public static BitRate PebibitsPerSecond(this double value) => BitRate.FromPebibitsPerSecond(value); + + /// + public static BitRate? PebibitsPerSecond(this double? value) => BitRate.FromPebibitsPerSecond(value); + + /// + public static BitRate PebibitsPerSecond(this float value) => BitRate.FromPebibitsPerSecond(value); + + /// + public static BitRate? PebibitsPerSecond(this float? value) => BitRate.FromPebibitsPerSecond(value); + + /// + public static BitRate PebibitsPerSecond(this decimal value) => BitRate.FromPebibitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? PebibitsPerSecond(this decimal? value) => BitRate.FromPebibitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region PebibytePerSecond + + /// + public static BitRate PebibytesPerSecond(this int value) => BitRate.FromPebibytesPerSecond(value); + + /// + public static BitRate? PebibytesPerSecond(this int? value) => BitRate.FromPebibytesPerSecond(value); + + /// + public static BitRate PebibytesPerSecond(this long value) => BitRate.FromPebibytesPerSecond(value); + + /// + public static BitRate? PebibytesPerSecond(this long? value) => BitRate.FromPebibytesPerSecond(value); + + /// + public static BitRate PebibytesPerSecond(this double value) => BitRate.FromPebibytesPerSecond(value); + + /// + public static BitRate? PebibytesPerSecond(this double? value) => BitRate.FromPebibytesPerSecond(value); + + /// + public static BitRate PebibytesPerSecond(this float value) => BitRate.FromPebibytesPerSecond(value); + + /// + public static BitRate? PebibytesPerSecond(this float? value) => BitRate.FromPebibytesPerSecond(value); + + /// + public static BitRate PebibytesPerSecond(this decimal value) => BitRate.FromPebibytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? PebibytesPerSecond(this decimal? value) => BitRate.FromPebibytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region PetabitPerSecond + + /// + public static BitRate PetabitsPerSecond(this int value) => BitRate.FromPetabitsPerSecond(value); + + /// + public static BitRate? PetabitsPerSecond(this int? value) => BitRate.FromPetabitsPerSecond(value); + + /// + public static BitRate PetabitsPerSecond(this long value) => BitRate.FromPetabitsPerSecond(value); + + /// + public static BitRate? PetabitsPerSecond(this long? value) => BitRate.FromPetabitsPerSecond(value); + + /// + public static BitRate PetabitsPerSecond(this double value) => BitRate.FromPetabitsPerSecond(value); + + /// + public static BitRate? PetabitsPerSecond(this double? value) => BitRate.FromPetabitsPerSecond(value); + + /// + public static BitRate PetabitsPerSecond(this float value) => BitRate.FromPetabitsPerSecond(value); + + /// + public static BitRate? PetabitsPerSecond(this float? value) => BitRate.FromPetabitsPerSecond(value); + + /// + public static BitRate PetabitsPerSecond(this decimal value) => BitRate.FromPetabitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? PetabitsPerSecond(this decimal? value) => BitRate.FromPetabitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region PetabytePerSecond + + /// + public static BitRate PetabytesPerSecond(this int value) => BitRate.FromPetabytesPerSecond(value); + + /// + public static BitRate? PetabytesPerSecond(this int? value) => BitRate.FromPetabytesPerSecond(value); + + /// + public static BitRate PetabytesPerSecond(this long value) => BitRate.FromPetabytesPerSecond(value); + + /// + public static BitRate? PetabytesPerSecond(this long? value) => BitRate.FromPetabytesPerSecond(value); + + /// + public static BitRate PetabytesPerSecond(this double value) => BitRate.FromPetabytesPerSecond(value); + + /// + public static BitRate? PetabytesPerSecond(this double? value) => BitRate.FromPetabytesPerSecond(value); + + /// + public static BitRate PetabytesPerSecond(this float value) => BitRate.FromPetabytesPerSecond(value); + + /// + public static BitRate? PetabytesPerSecond(this float? value) => BitRate.FromPetabytesPerSecond(value); + + /// + public static BitRate PetabytesPerSecond(this decimal value) => BitRate.FromPetabytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? PetabytesPerSecond(this decimal? value) => BitRate.FromPetabytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region TebibitPerSecond + + /// + public static BitRate TebibitsPerSecond(this int value) => BitRate.FromTebibitsPerSecond(value); + + /// + public static BitRate? TebibitsPerSecond(this int? value) => BitRate.FromTebibitsPerSecond(value); + + /// + public static BitRate TebibitsPerSecond(this long value) => BitRate.FromTebibitsPerSecond(value); + + /// + public static BitRate? TebibitsPerSecond(this long? value) => BitRate.FromTebibitsPerSecond(value); + + /// + public static BitRate TebibitsPerSecond(this double value) => BitRate.FromTebibitsPerSecond(value); + + /// + public static BitRate? TebibitsPerSecond(this double? value) => BitRate.FromTebibitsPerSecond(value); + + /// + public static BitRate TebibitsPerSecond(this float value) => BitRate.FromTebibitsPerSecond(value); + + /// + public static BitRate? TebibitsPerSecond(this float? value) => BitRate.FromTebibitsPerSecond(value); + + /// + public static BitRate TebibitsPerSecond(this decimal value) => BitRate.FromTebibitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? TebibitsPerSecond(this decimal? value) => BitRate.FromTebibitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region TebibytePerSecond + + /// + public static BitRate TebibytesPerSecond(this int value) => BitRate.FromTebibytesPerSecond(value); + + /// + public static BitRate? TebibytesPerSecond(this int? value) => BitRate.FromTebibytesPerSecond(value); + + /// + public static BitRate TebibytesPerSecond(this long value) => BitRate.FromTebibytesPerSecond(value); + + /// + public static BitRate? TebibytesPerSecond(this long? value) => BitRate.FromTebibytesPerSecond(value); + + /// + public static BitRate TebibytesPerSecond(this double value) => BitRate.FromTebibytesPerSecond(value); + + /// + public static BitRate? TebibytesPerSecond(this double? value) => BitRate.FromTebibytesPerSecond(value); + + /// + public static BitRate TebibytesPerSecond(this float value) => BitRate.FromTebibytesPerSecond(value); + + /// + public static BitRate? TebibytesPerSecond(this float? value) => BitRate.FromTebibytesPerSecond(value); + + /// + public static BitRate TebibytesPerSecond(this decimal value) => BitRate.FromTebibytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? TebibytesPerSecond(this decimal? value) => BitRate.FromTebibytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region TerabitPerSecond + + /// + public static BitRate TerabitsPerSecond(this int value) => BitRate.FromTerabitsPerSecond(value); + + /// + public static BitRate? TerabitsPerSecond(this int? value) => BitRate.FromTerabitsPerSecond(value); + + /// + public static BitRate TerabitsPerSecond(this long value) => BitRate.FromTerabitsPerSecond(value); + + /// + public static BitRate? TerabitsPerSecond(this long? value) => BitRate.FromTerabitsPerSecond(value); + + /// + public static BitRate TerabitsPerSecond(this double value) => BitRate.FromTerabitsPerSecond(value); + + /// + public static BitRate? TerabitsPerSecond(this double? value) => BitRate.FromTerabitsPerSecond(value); + + /// + public static BitRate TerabitsPerSecond(this float value) => BitRate.FromTerabitsPerSecond(value); + + /// + public static BitRate? TerabitsPerSecond(this float? value) => BitRate.FromTerabitsPerSecond(value); + + /// + public static BitRate TerabitsPerSecond(this decimal value) => BitRate.FromTerabitsPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? TerabitsPerSecond(this decimal? value) => BitRate.FromTerabitsPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + #region TerabytePerSecond + + /// + public static BitRate TerabytesPerSecond(this int value) => BitRate.FromTerabytesPerSecond(value); + + /// + public static BitRate? TerabytesPerSecond(this int? value) => BitRate.FromTerabytesPerSecond(value); + + /// + public static BitRate TerabytesPerSecond(this long value) => BitRate.FromTerabytesPerSecond(value); + + /// + public static BitRate? TerabytesPerSecond(this long? value) => BitRate.FromTerabytesPerSecond(value); + + /// + public static BitRate TerabytesPerSecond(this double value) => BitRate.FromTerabytesPerSecond(value); + + /// + public static BitRate? TerabytesPerSecond(this double? value) => BitRate.FromTerabytesPerSecond(value); + + /// + public static BitRate TerabytesPerSecond(this float value) => BitRate.FromTerabytesPerSecond(value); + + /// + public static BitRate? TerabytesPerSecond(this float? value) => BitRate.FromTerabytesPerSecond(value); + + /// + public static BitRate TerabytesPerSecond(this decimal value) => BitRate.FromTerabytesPerSecond(Convert.ToDouble(value)); + + /// + public static BitRate? TerabytesPerSecond(this decimal? value) => BitRate.FromTerabytesPerSecond(value == null ? (double?)null : Convert.ToDouble(value.Value)); + + #endregion + + } +} +#endif diff --git a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs new file mode 100644 index 0000000000..fa8cd00cd6 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs @@ -0,0 +1,1849 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyUnit.extra.cs files to add code to generated quantities. +// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; + +// Windows Runtime Component does not support CultureInfo type, so use culture name string instead for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP +using Culture = System.String; +#else +using Culture = System.IFormatProvider; +#endif + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// In telecommunications and computing, bit rate is the number of bits that are conveyed or processed per unit of time. + /// + // ReSharper disable once PartialTypeWithSinglePart + + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. +#if WINDOWS_UWP + public sealed partial class BitRate +#else + public partial struct BitRate : IComparable, IComparable +#endif + { + /// + /// Base unit of BitRate. + /// + private readonly decimal _bitsPerSecond; + + // Windows Runtime Component requires a default constructor +#if WINDOWS_UWP + public BitRate() : this(0) + { + } +#endif + + public BitRate(double bitspersecond) + { + _bitsPerSecond = Convert.ToDecimal(bitspersecond); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods +#if WINDOWS_UWP + private +#else + public +#endif + BitRate(long bitspersecond) + { + _bitsPerSecond = Convert.ToDecimal(bitspersecond); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods + // Windows Runtime Component does not support decimal type +#if WINDOWS_UWP + private +#else + public +#endif + BitRate(decimal bitspersecond) + { + _bitsPerSecond = Convert.ToDecimal(bitspersecond); + } + + #region Properties + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType => QuantityType.BitRate; + + /// + /// The base unit representation of this quantity for the numeric value stored internally. All conversions go via this value. + /// + public static BitRateUnit BaseUnit + { + get { return BitRateUnit.BitPerSecond; } + } + + /// + /// All units of measurement for the BitRate quantity. + /// + public static BitRateUnit[] Units { get; } = Enum.GetValues(typeof(BitRateUnit)).Cast().ToArray(); + + /// + /// Get BitRate in BitsPerSecond. + /// + public double BitsPerSecond + { + get { return Convert.ToDouble(_bitsPerSecond); } + } + + /// + /// Get BitRate in BytesPerSecond. + /// + public double BytesPerSecond + { + get { return Convert.ToDouble(_bitsPerSecond/8m); } + } + + /// + /// Get BitRate in ExabitsPerSecond. + /// + public double ExabitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / 1e18m); } + } + + /// + /// Get BitRate in ExabytesPerSecond. + /// + public double ExabytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / 1e18m); } + } + + /// + /// Get BitRate in ExbibitsPerSecond. + /// + public double ExbibitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / (1024m * 1024 * 1024 * 1024 * 1024 * 1024)); } + } + + /// + /// Get BitRate in ExbibytesPerSecond. + /// + public double ExbibytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / (1024m * 1024 * 1024 * 1024 * 1024 * 1024)); } + } + + /// + /// Get BitRate in GibibitsPerSecond. + /// + public double GibibitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / (1024m * 1024 * 1024)); } + } + + /// + /// Get BitRate in GibibytesPerSecond. + /// + public double GibibytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / (1024m * 1024 * 1024)); } + } + + /// + /// Get BitRate in GigabitsPerSecond. + /// + public double GigabitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / 1e9m); } + } + + /// + /// Get BitRate in GigabytesPerSecond. + /// + public double GigabytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / 1e9m); } + } + + /// + /// Get BitRate in KibibitsPerSecond. + /// + public double KibibitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / 1024m); } + } + + /// + /// Get BitRate in KibibytesPerSecond. + /// + public double KibibytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / 1024m); } + } + + /// + /// Get BitRate in KilobitsPerSecond. + /// + public double KilobitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / 1e3m); } + } + + /// + /// Get BitRate in KilobytesPerSecond. + /// + public double KilobytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / 1e3m); } + } + + /// + /// Get BitRate in MebibitsPerSecond. + /// + public double MebibitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / (1024m * 1024)); } + } + + /// + /// Get BitRate in MebibytesPerSecond. + /// + public double MebibytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / (1024m * 1024)); } + } + + /// + /// Get BitRate in MegabitsPerSecond. + /// + public double MegabitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / 1e6m); } + } + + /// + /// Get BitRate in MegabytesPerSecond. + /// + public double MegabytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / 1e6m); } + } + + /// + /// Get BitRate in PebibitsPerSecond. + /// + public double PebibitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / (1024m * 1024 * 1024 * 1024 * 1024)); } + } + + /// + /// Get BitRate in PebibytesPerSecond. + /// + public double PebibytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / (1024m * 1024 * 1024 * 1024 * 1024)); } + } + + /// + /// Get BitRate in PetabitsPerSecond. + /// + public double PetabitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / 1e15m); } + } + + /// + /// Get BitRate in PetabytesPerSecond. + /// + public double PetabytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / 1e15m); } + } + + /// + /// Get BitRate in TebibitsPerSecond. + /// + public double TebibitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / (1024m * 1024 * 1024 * 1024)); } + } + + /// + /// Get BitRate in TebibytesPerSecond. + /// + public double TebibytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / (1024m * 1024 * 1024 * 1024)); } + } + + /// + /// Get BitRate in TerabitsPerSecond. + /// + public double TerabitsPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond) / 1e12m); } + } + + /// + /// Get BitRate in TerabytesPerSecond. + /// + public double TerabytesPerSecond + { + get { return Convert.ToDouble((_bitsPerSecond/8m) / 1e12m); } + } + + #endregion + + #region Static + + public static BitRate Zero + { + get { return new BitRate(); } + } + + /// + /// Get BitRate from BitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromBitsPerSecond(double bitspersecond) + { + double value = (double) bitspersecond; + return new BitRate(Convert.ToDecimal(value)); + } +#else + public static BitRate FromBitsPerSecond(QuantityValue bitspersecond) + { + double value = (double) bitspersecond; + return new BitRate((Convert.ToDecimal(value))); + } +#endif + + /// + /// Get BitRate from BytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromBytesPerSecond(double bytespersecond) + { + double value = (double) bytespersecond; + return new BitRate(Convert.ToDecimal(value*8d)); + } +#else + public static BitRate FromBytesPerSecond(QuantityValue bytespersecond) + { + double value = (double) bytespersecond; + return new BitRate((Convert.ToDecimal(value*8d))); + } +#endif + + /// + /// Get BitRate from ExabitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromExabitsPerSecond(double exabitspersecond) + { + double value = (double) exabitspersecond; + return new BitRate(Convert.ToDecimal((value) * 1e18d)); + } +#else + public static BitRate FromExabitsPerSecond(QuantityValue exabitspersecond) + { + double value = (double) exabitspersecond; + return new BitRate((Convert.ToDecimal((value) * 1e18d))); + } +#endif + + /// + /// Get BitRate from ExabytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromExabytesPerSecond(double exabytespersecond) + { + double value = (double) exabytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * 1e18d)); + } +#else + public static BitRate FromExabytesPerSecond(QuantityValue exabytespersecond) + { + double value = (double) exabytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * 1e18d))); + } +#endif + + /// + /// Get BitRate from ExbibitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromExbibitsPerSecond(double exbibitspersecond) + { + double value = (double) exbibitspersecond; + return new BitRate(Convert.ToDecimal((value) * (1024d * 1024 * 1024 * 1024 * 1024 * 1024))); + } +#else + public static BitRate FromExbibitsPerSecond(QuantityValue exbibitspersecond) + { + double value = (double) exbibitspersecond; + return new BitRate((Convert.ToDecimal((value) * (1024d * 1024 * 1024 * 1024 * 1024 * 1024)))); + } +#endif + + /// + /// Get BitRate from ExbibytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromExbibytesPerSecond(double exbibytespersecond) + { + double value = (double) exbibytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * (1024d * 1024 * 1024 * 1024 * 1024 * 1024))); + } +#else + public static BitRate FromExbibytesPerSecond(QuantityValue exbibytespersecond) + { + double value = (double) exbibytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * (1024d * 1024 * 1024 * 1024 * 1024 * 1024)))); + } +#endif + + /// + /// Get BitRate from GibibitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromGibibitsPerSecond(double gibibitspersecond) + { + double value = (double) gibibitspersecond; + return new BitRate(Convert.ToDecimal((value) * (1024d * 1024 * 1024))); + } +#else + public static BitRate FromGibibitsPerSecond(QuantityValue gibibitspersecond) + { + double value = (double) gibibitspersecond; + return new BitRate((Convert.ToDecimal((value) * (1024d * 1024 * 1024)))); + } +#endif + + /// + /// Get BitRate from GibibytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromGibibytesPerSecond(double gibibytespersecond) + { + double value = (double) gibibytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * (1024d * 1024 * 1024))); + } +#else + public static BitRate FromGibibytesPerSecond(QuantityValue gibibytespersecond) + { + double value = (double) gibibytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * (1024d * 1024 * 1024)))); + } +#endif + + /// + /// Get BitRate from GigabitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromGigabitsPerSecond(double gigabitspersecond) + { + double value = (double) gigabitspersecond; + return new BitRate(Convert.ToDecimal((value) * 1e9d)); + } +#else + public static BitRate FromGigabitsPerSecond(QuantityValue gigabitspersecond) + { + double value = (double) gigabitspersecond; + return new BitRate((Convert.ToDecimal((value) * 1e9d))); + } +#endif + + /// + /// Get BitRate from GigabytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromGigabytesPerSecond(double gigabytespersecond) + { + double value = (double) gigabytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * 1e9d)); + } +#else + public static BitRate FromGigabytesPerSecond(QuantityValue gigabytespersecond) + { + double value = (double) gigabytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * 1e9d))); + } +#endif + + /// + /// Get BitRate from KibibitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromKibibitsPerSecond(double kibibitspersecond) + { + double value = (double) kibibitspersecond; + return new BitRate(Convert.ToDecimal((value) * 1024d)); + } +#else + public static BitRate FromKibibitsPerSecond(QuantityValue kibibitspersecond) + { + double value = (double) kibibitspersecond; + return new BitRate((Convert.ToDecimal((value) * 1024d))); + } +#endif + + /// + /// Get BitRate from KibibytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromKibibytesPerSecond(double kibibytespersecond) + { + double value = (double) kibibytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * 1024d)); + } +#else + public static BitRate FromKibibytesPerSecond(QuantityValue kibibytespersecond) + { + double value = (double) kibibytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * 1024d))); + } +#endif + + /// + /// Get BitRate from KilobitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromKilobitsPerSecond(double kilobitspersecond) + { + double value = (double) kilobitspersecond; + return new BitRate(Convert.ToDecimal((value) * 1e3d)); + } +#else + public static BitRate FromKilobitsPerSecond(QuantityValue kilobitspersecond) + { + double value = (double) kilobitspersecond; + return new BitRate((Convert.ToDecimal((value) * 1e3d))); + } +#endif + + /// + /// Get BitRate from KilobytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromKilobytesPerSecond(double kilobytespersecond) + { + double value = (double) kilobytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * 1e3d)); + } +#else + public static BitRate FromKilobytesPerSecond(QuantityValue kilobytespersecond) + { + double value = (double) kilobytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * 1e3d))); + } +#endif + + /// + /// Get BitRate from MebibitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromMebibitsPerSecond(double mebibitspersecond) + { + double value = (double) mebibitspersecond; + return new BitRate(Convert.ToDecimal((value) * (1024d * 1024))); + } +#else + public static BitRate FromMebibitsPerSecond(QuantityValue mebibitspersecond) + { + double value = (double) mebibitspersecond; + return new BitRate((Convert.ToDecimal((value) * (1024d * 1024)))); + } +#endif + + /// + /// Get BitRate from MebibytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromMebibytesPerSecond(double mebibytespersecond) + { + double value = (double) mebibytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * (1024d * 1024))); + } +#else + public static BitRate FromMebibytesPerSecond(QuantityValue mebibytespersecond) + { + double value = (double) mebibytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * (1024d * 1024)))); + } +#endif + + /// + /// Get BitRate from MegabitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromMegabitsPerSecond(double megabitspersecond) + { + double value = (double) megabitspersecond; + return new BitRate(Convert.ToDecimal((value) * 1e6d)); + } +#else + public static BitRate FromMegabitsPerSecond(QuantityValue megabitspersecond) + { + double value = (double) megabitspersecond; + return new BitRate((Convert.ToDecimal((value) * 1e6d))); + } +#endif + + /// + /// Get BitRate from MegabytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromMegabytesPerSecond(double megabytespersecond) + { + double value = (double) megabytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * 1e6d)); + } +#else + public static BitRate FromMegabytesPerSecond(QuantityValue megabytespersecond) + { + double value = (double) megabytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * 1e6d))); + } +#endif + + /// + /// Get BitRate from PebibitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromPebibitsPerSecond(double pebibitspersecond) + { + double value = (double) pebibitspersecond; + return new BitRate(Convert.ToDecimal((value) * (1024d * 1024 * 1024 * 1024 * 1024))); + } +#else + public static BitRate FromPebibitsPerSecond(QuantityValue pebibitspersecond) + { + double value = (double) pebibitspersecond; + return new BitRate((Convert.ToDecimal((value) * (1024d * 1024 * 1024 * 1024 * 1024)))); + } +#endif + + /// + /// Get BitRate from PebibytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromPebibytesPerSecond(double pebibytespersecond) + { + double value = (double) pebibytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * (1024d * 1024 * 1024 * 1024 * 1024))); + } +#else + public static BitRate FromPebibytesPerSecond(QuantityValue pebibytespersecond) + { + double value = (double) pebibytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * (1024d * 1024 * 1024 * 1024 * 1024)))); + } +#endif + + /// + /// Get BitRate from PetabitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromPetabitsPerSecond(double petabitspersecond) + { + double value = (double) petabitspersecond; + return new BitRate(Convert.ToDecimal((value) * 1e15d)); + } +#else + public static BitRate FromPetabitsPerSecond(QuantityValue petabitspersecond) + { + double value = (double) petabitspersecond; + return new BitRate((Convert.ToDecimal((value) * 1e15d))); + } +#endif + + /// + /// Get BitRate from PetabytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromPetabytesPerSecond(double petabytespersecond) + { + double value = (double) petabytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * 1e15d)); + } +#else + public static BitRate FromPetabytesPerSecond(QuantityValue petabytespersecond) + { + double value = (double) petabytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * 1e15d))); + } +#endif + + /// + /// Get BitRate from TebibitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromTebibitsPerSecond(double tebibitspersecond) + { + double value = (double) tebibitspersecond; + return new BitRate(Convert.ToDecimal((value) * (1024d * 1024 * 1024 * 1024))); + } +#else + public static BitRate FromTebibitsPerSecond(QuantityValue tebibitspersecond) + { + double value = (double) tebibitspersecond; + return new BitRate((Convert.ToDecimal((value) * (1024d * 1024 * 1024 * 1024)))); + } +#endif + + /// + /// Get BitRate from TebibytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromTebibytesPerSecond(double tebibytespersecond) + { + double value = (double) tebibytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * (1024d * 1024 * 1024 * 1024))); + } +#else + public static BitRate FromTebibytesPerSecond(QuantityValue tebibytespersecond) + { + double value = (double) tebibytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * (1024d * 1024 * 1024 * 1024)))); + } +#endif + + /// + /// Get BitRate from TerabitsPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromTerabitsPerSecond(double terabitspersecond) + { + double value = (double) terabitspersecond; + return new BitRate(Convert.ToDecimal((value) * 1e12d)); + } +#else + public static BitRate FromTerabitsPerSecond(QuantityValue terabitspersecond) + { + double value = (double) terabitspersecond; + return new BitRate((Convert.ToDecimal((value) * 1e12d))); + } +#endif + + /// + /// Get BitRate from TerabytesPerSecond. + /// +#if WINDOWS_UWP + [Windows.Foundation.Metadata.DefaultOverload] + public static BitRate FromTerabytesPerSecond(double terabytespersecond) + { + double value = (double) terabytespersecond; + return new BitRate(Convert.ToDecimal((value*8d) * 1e12d)); + } +#else + public static BitRate FromTerabytesPerSecond(QuantityValue terabytespersecond) + { + double value = (double) terabytespersecond; + return new BitRate((Convert.ToDecimal((value*8d) * 1e12d))); + } +#endif + + // Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + /// + /// Get nullable BitRate from nullable BitsPerSecond. + /// + public static BitRate? FromBitsPerSecond(QuantityValue? bitspersecond) + { + if (bitspersecond.HasValue) + { + return FromBitsPerSecond(bitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable BytesPerSecond. + /// + public static BitRate? FromBytesPerSecond(QuantityValue? bytespersecond) + { + if (bytespersecond.HasValue) + { + return FromBytesPerSecond(bytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable ExabitsPerSecond. + /// + public static BitRate? FromExabitsPerSecond(QuantityValue? exabitspersecond) + { + if (exabitspersecond.HasValue) + { + return FromExabitsPerSecond(exabitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable ExabytesPerSecond. + /// + public static BitRate? FromExabytesPerSecond(QuantityValue? exabytespersecond) + { + if (exabytespersecond.HasValue) + { + return FromExabytesPerSecond(exabytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable ExbibitsPerSecond. + /// + public static BitRate? FromExbibitsPerSecond(QuantityValue? exbibitspersecond) + { + if (exbibitspersecond.HasValue) + { + return FromExbibitsPerSecond(exbibitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable ExbibytesPerSecond. + /// + public static BitRate? FromExbibytesPerSecond(QuantityValue? exbibytespersecond) + { + if (exbibytespersecond.HasValue) + { + return FromExbibytesPerSecond(exbibytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable GibibitsPerSecond. + /// + public static BitRate? FromGibibitsPerSecond(QuantityValue? gibibitspersecond) + { + if (gibibitspersecond.HasValue) + { + return FromGibibitsPerSecond(gibibitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable GibibytesPerSecond. + /// + public static BitRate? FromGibibytesPerSecond(QuantityValue? gibibytespersecond) + { + if (gibibytespersecond.HasValue) + { + return FromGibibytesPerSecond(gibibytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable GigabitsPerSecond. + /// + public static BitRate? FromGigabitsPerSecond(QuantityValue? gigabitspersecond) + { + if (gigabitspersecond.HasValue) + { + return FromGigabitsPerSecond(gigabitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable GigabytesPerSecond. + /// + public static BitRate? FromGigabytesPerSecond(QuantityValue? gigabytespersecond) + { + if (gigabytespersecond.HasValue) + { + return FromGigabytesPerSecond(gigabytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable KibibitsPerSecond. + /// + public static BitRate? FromKibibitsPerSecond(QuantityValue? kibibitspersecond) + { + if (kibibitspersecond.HasValue) + { + return FromKibibitsPerSecond(kibibitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable KibibytesPerSecond. + /// + public static BitRate? FromKibibytesPerSecond(QuantityValue? kibibytespersecond) + { + if (kibibytespersecond.HasValue) + { + return FromKibibytesPerSecond(kibibytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable KilobitsPerSecond. + /// + public static BitRate? FromKilobitsPerSecond(QuantityValue? kilobitspersecond) + { + if (kilobitspersecond.HasValue) + { + return FromKilobitsPerSecond(kilobitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable KilobytesPerSecond. + /// + public static BitRate? FromKilobytesPerSecond(QuantityValue? kilobytespersecond) + { + if (kilobytespersecond.HasValue) + { + return FromKilobytesPerSecond(kilobytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable MebibitsPerSecond. + /// + public static BitRate? FromMebibitsPerSecond(QuantityValue? mebibitspersecond) + { + if (mebibitspersecond.HasValue) + { + return FromMebibitsPerSecond(mebibitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable MebibytesPerSecond. + /// + public static BitRate? FromMebibytesPerSecond(QuantityValue? mebibytespersecond) + { + if (mebibytespersecond.HasValue) + { + return FromMebibytesPerSecond(mebibytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable MegabitsPerSecond. + /// + public static BitRate? FromMegabitsPerSecond(QuantityValue? megabitspersecond) + { + if (megabitspersecond.HasValue) + { + return FromMegabitsPerSecond(megabitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable MegabytesPerSecond. + /// + public static BitRate? FromMegabytesPerSecond(QuantityValue? megabytespersecond) + { + if (megabytespersecond.HasValue) + { + return FromMegabytesPerSecond(megabytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable PebibitsPerSecond. + /// + public static BitRate? FromPebibitsPerSecond(QuantityValue? pebibitspersecond) + { + if (pebibitspersecond.HasValue) + { + return FromPebibitsPerSecond(pebibitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable PebibytesPerSecond. + /// + public static BitRate? FromPebibytesPerSecond(QuantityValue? pebibytespersecond) + { + if (pebibytespersecond.HasValue) + { + return FromPebibytesPerSecond(pebibytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable PetabitsPerSecond. + /// + public static BitRate? FromPetabitsPerSecond(QuantityValue? petabitspersecond) + { + if (petabitspersecond.HasValue) + { + return FromPetabitsPerSecond(petabitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable PetabytesPerSecond. + /// + public static BitRate? FromPetabytesPerSecond(QuantityValue? petabytespersecond) + { + if (petabytespersecond.HasValue) + { + return FromPetabytesPerSecond(petabytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable TebibitsPerSecond. + /// + public static BitRate? FromTebibitsPerSecond(QuantityValue? tebibitspersecond) + { + if (tebibitspersecond.HasValue) + { + return FromTebibitsPerSecond(tebibitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable TebibytesPerSecond. + /// + public static BitRate? FromTebibytesPerSecond(QuantityValue? tebibytespersecond) + { + if (tebibytespersecond.HasValue) + { + return FromTebibytesPerSecond(tebibytespersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable TerabitsPerSecond. + /// + public static BitRate? FromTerabitsPerSecond(QuantityValue? terabitspersecond) + { + if (terabitspersecond.HasValue) + { + return FromTerabitsPerSecond(terabitspersecond.Value); + } + else + { + return null; + } + } + + /// + /// Get nullable BitRate from nullable TerabytesPerSecond. + /// + public static BitRate? FromTerabytesPerSecond(QuantityValue? terabytespersecond) + { + if (terabytespersecond.HasValue) + { + return FromTerabytesPerSecond(terabytespersecond.Value); + } + else + { + return null; + } + } + +#endif + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// BitRate unit value. +#if WINDOWS_UWP + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static BitRate From(double value, BitRateUnit fromUnit) +#else + public static BitRate From(QuantityValue value, BitRateUnit fromUnit) +#endif + { + switch (fromUnit) + { + case BitRateUnit.BitPerSecond: + return FromBitsPerSecond(value); + case BitRateUnit.BytePerSecond: + return FromBytesPerSecond(value); + case BitRateUnit.ExabitPerSecond: + return FromExabitsPerSecond(value); + case BitRateUnit.ExabytePerSecond: + return FromExabytesPerSecond(value); + case BitRateUnit.ExbibitPerSecond: + return FromExbibitsPerSecond(value); + case BitRateUnit.ExbibytePerSecond: + return FromExbibytesPerSecond(value); + case BitRateUnit.GibibitPerSecond: + return FromGibibitsPerSecond(value); + case BitRateUnit.GibibytePerSecond: + return FromGibibytesPerSecond(value); + case BitRateUnit.GigabitPerSecond: + return FromGigabitsPerSecond(value); + case BitRateUnit.GigabytePerSecond: + return FromGigabytesPerSecond(value); + case BitRateUnit.KibibitPerSecond: + return FromKibibitsPerSecond(value); + case BitRateUnit.KibibytePerSecond: + return FromKibibytesPerSecond(value); + case BitRateUnit.KilobitPerSecond: + return FromKilobitsPerSecond(value); + case BitRateUnit.KilobytePerSecond: + return FromKilobytesPerSecond(value); + case BitRateUnit.MebibitPerSecond: + return FromMebibitsPerSecond(value); + case BitRateUnit.MebibytePerSecond: + return FromMebibytesPerSecond(value); + case BitRateUnit.MegabitPerSecond: + return FromMegabitsPerSecond(value); + case BitRateUnit.MegabytePerSecond: + return FromMegabytesPerSecond(value); + case BitRateUnit.PebibitPerSecond: + return FromPebibitsPerSecond(value); + case BitRateUnit.PebibytePerSecond: + return FromPebibytesPerSecond(value); + case BitRateUnit.PetabitPerSecond: + return FromPetabitsPerSecond(value); + case BitRateUnit.PetabytePerSecond: + return FromPetabytesPerSecond(value); + case BitRateUnit.TebibitPerSecond: + return FromTebibitsPerSecond(value); + case BitRateUnit.TebibytePerSecond: + return FromTebibytesPerSecond(value); + case BitRateUnit.TerabitPerSecond: + return FromTerabitsPerSecond(value); + case BitRateUnit.TerabytePerSecond: + return FromTerabytesPerSecond(value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } + + // Windows Runtime Component does not support nullable types (double?): https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// BitRate unit value. + public static BitRate? From(QuantityValue? value, BitRateUnit fromUnit) + { + if (!value.HasValue) + { + return null; + } + switch (fromUnit) + { + case BitRateUnit.BitPerSecond: + return FromBitsPerSecond(value.Value); + case BitRateUnit.BytePerSecond: + return FromBytesPerSecond(value.Value); + case BitRateUnit.ExabitPerSecond: + return FromExabitsPerSecond(value.Value); + case BitRateUnit.ExabytePerSecond: + return FromExabytesPerSecond(value.Value); + case BitRateUnit.ExbibitPerSecond: + return FromExbibitsPerSecond(value.Value); + case BitRateUnit.ExbibytePerSecond: + return FromExbibytesPerSecond(value.Value); + case BitRateUnit.GibibitPerSecond: + return FromGibibitsPerSecond(value.Value); + case BitRateUnit.GibibytePerSecond: + return FromGibibytesPerSecond(value.Value); + case BitRateUnit.GigabitPerSecond: + return FromGigabitsPerSecond(value.Value); + case BitRateUnit.GigabytePerSecond: + return FromGigabytesPerSecond(value.Value); + case BitRateUnit.KibibitPerSecond: + return FromKibibitsPerSecond(value.Value); + case BitRateUnit.KibibytePerSecond: + return FromKibibytesPerSecond(value.Value); + case BitRateUnit.KilobitPerSecond: + return FromKilobitsPerSecond(value.Value); + case BitRateUnit.KilobytePerSecond: + return FromKilobytesPerSecond(value.Value); + case BitRateUnit.MebibitPerSecond: + return FromMebibitsPerSecond(value.Value); + case BitRateUnit.MebibytePerSecond: + return FromMebibytesPerSecond(value.Value); + case BitRateUnit.MegabitPerSecond: + return FromMegabitsPerSecond(value.Value); + case BitRateUnit.MegabytePerSecond: + return FromMegabytesPerSecond(value.Value); + case BitRateUnit.PebibitPerSecond: + return FromPebibitsPerSecond(value.Value); + case BitRateUnit.PebibytePerSecond: + return FromPebibytesPerSecond(value.Value); + case BitRateUnit.PetabitPerSecond: + return FromPetabitsPerSecond(value.Value); + case BitRateUnit.PetabytePerSecond: + return FromPetabytesPerSecond(value.Value); + case BitRateUnit.TebibitPerSecond: + return FromTebibitsPerSecond(value.Value); + case BitRateUnit.TebibytePerSecond: + return FromTebibytesPerSecond(value.Value); + case BitRateUnit.TerabitPerSecond: + return FromTerabitsPerSecond(value.Value); + case BitRateUnit.TerabytePerSecond: + return FromTerabytesPerSecond(value.Value); + + default: + throw new NotImplementedException("fromUnit: " + fromUnit); + } + } +#endif + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + [UsedImplicitly] + public static string GetAbbreviation(BitRateUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Culture to use for localization. Defaults to Thread.CurrentUICulture. + /// Unit abbreviation string. + [UsedImplicitly] + public static string GetAbbreviation(BitRateUnit unit, [CanBeNull] Culture culture) + { + return UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit); + } + + #endregion + + #region Arithmetic Operators + + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static BitRate operator -(BitRate right) + { + return new BitRate(-right._bitsPerSecond); + } + + public static BitRate operator +(BitRate left, BitRate right) + { + return new BitRate(left._bitsPerSecond + right._bitsPerSecond); + } + + public static BitRate operator -(BitRate left, BitRate right) + { + return new BitRate(left._bitsPerSecond - right._bitsPerSecond); + } + + public static BitRate operator *(decimal left, BitRate right) + { + return new BitRate(left*right._bitsPerSecond); + } + + public static BitRate operator *(BitRate left, double right) + { + return new BitRate(left._bitsPerSecond*(decimal)right); + } + + public static BitRate operator /(BitRate left, double right) + { + return new BitRate(left._bitsPerSecond/(decimal)right); + } + + public static double operator /(BitRate left, BitRate right) + { + return Convert.ToDouble(left._bitsPerSecond/right._bitsPerSecond); + } +#endif + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if (obj == null) throw new ArgumentNullException("obj"); + if (!(obj is BitRate)) throw new ArgumentException("Expected type BitRate.", "obj"); + return CompareTo((BitRate) obj); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods +#if WINDOWS_UWP + internal +#else + public +#endif + int CompareTo(BitRate other) + { + return _bitsPerSecond.CompareTo(other._bitsPerSecond); + } + + // Windows Runtime Component does not allow operator overloads: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if !WINDOWS_UWP + public static bool operator <=(BitRate left, BitRate right) + { + return left._bitsPerSecond <= right._bitsPerSecond; + } + + public static bool operator >=(BitRate left, BitRate right) + { + return left._bitsPerSecond >= right._bitsPerSecond; + } + + public static bool operator <(BitRate left, BitRate right) + { + return left._bitsPerSecond < right._bitsPerSecond; + } + + public static bool operator >(BitRate left, BitRate right) + { + return left._bitsPerSecond > right._bitsPerSecond; + } + + public static bool operator ==(BitRate left, BitRate right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._bitsPerSecond == right._bitsPerSecond; + } + + public static bool operator !=(BitRate left, BitRate right) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + return left._bitsPerSecond != right._bitsPerSecond; + } +#endif + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return _bitsPerSecond.Equals(((BitRate) obj)._bitsPerSecond); + } + + /// + /// Compare equality to another BitRate by specifying a max allowed difference. + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// Other quantity to compare to. + /// Max error allowed. + /// True if the difference between the two values is not greater than the specified max. + public bool Equals(BitRate other, BitRate maxError) + { + return Math.Abs(_bitsPerSecond - other._bitsPerSecond) <= maxError._bitsPerSecond; + } + + public override int GetHashCode() + { + return _bitsPerSecond.GetHashCode(); + } + + #endregion + + #region Conversion + + /// + /// Convert to the unit representation . + /// + /// Value in new unit if successful, exception otherwise. + /// If conversion was not successful. + public double As(BitRateUnit unit) + { + switch (unit) + { + case BitRateUnit.BitPerSecond: + return BitsPerSecond; + case BitRateUnit.BytePerSecond: + return BytesPerSecond; + case BitRateUnit.ExabitPerSecond: + return ExabitsPerSecond; + case BitRateUnit.ExabytePerSecond: + return ExabytesPerSecond; + case BitRateUnit.ExbibitPerSecond: + return ExbibitsPerSecond; + case BitRateUnit.ExbibytePerSecond: + return ExbibytesPerSecond; + case BitRateUnit.GibibitPerSecond: + return GibibitsPerSecond; + case BitRateUnit.GibibytePerSecond: + return GibibytesPerSecond; + case BitRateUnit.GigabitPerSecond: + return GigabitsPerSecond; + case BitRateUnit.GigabytePerSecond: + return GigabytesPerSecond; + case BitRateUnit.KibibitPerSecond: + return KibibitsPerSecond; + case BitRateUnit.KibibytePerSecond: + return KibibytesPerSecond; + case BitRateUnit.KilobitPerSecond: + return KilobitsPerSecond; + case BitRateUnit.KilobytePerSecond: + return KilobytesPerSecond; + case BitRateUnit.MebibitPerSecond: + return MebibitsPerSecond; + case BitRateUnit.MebibytePerSecond: + return MebibytesPerSecond; + case BitRateUnit.MegabitPerSecond: + return MegabitsPerSecond; + case BitRateUnit.MegabytePerSecond: + return MegabytesPerSecond; + case BitRateUnit.PebibitPerSecond: + return PebibitsPerSecond; + case BitRateUnit.PebibytePerSecond: + return PebibytesPerSecond; + case BitRateUnit.PetabitPerSecond: + return PetabitsPerSecond; + case BitRateUnit.PetabytePerSecond: + return PetabytesPerSecond; + case BitRateUnit.TebibitPerSecond: + return TebibitsPerSecond; + case BitRateUnit.TebibytePerSecond: + return TebibytesPerSecond; + case BitRateUnit.TerabitPerSecond: + return TerabitsPerSecond; + case BitRateUnit.TerabytePerSecond: + return TerabytesPerSecond; + + default: + throw new NotImplementedException("unit: " + unit); + } + } + + #endregion + + #region Parsing + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static BitRate Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Format to use when parsing number and unit. If it is null, it defaults to for parsing the number and for parsing the unit abbreviation by culture/language. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static BitRate Parse(string str, [CanBeNull] Culture culture) + { + if (str == null) throw new ArgumentNullException("str"); + + // Windows Runtime Component does not support CultureInfo type, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP + IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture); +#else + IFormatProvider formatProvider = culture; +#endif + return QuantityParser.Parse(str, formatProvider, + delegate(string value, string unit, IFormatProvider formatProvider2) + { + double parsedValue = double.Parse(value, formatProvider2); + BitRateUnit parsedUnit = ParseUnit(unit, formatProvider2); + return From(parsedValue, parsedUnit); + }, (x, y) => FromBitsPerSecond(x.BitsPerSecond + y.BitsPerSecond)); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out BitRate result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Format to use when parsing number and unit. If it is null, it defaults to for parsing the number and for parsing the unit abbreviation by culture/language. + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, [CanBeNull] Culture culture, out BitRate result) + { + try + { + result = Parse(str, culture); + return true; + } + catch + { + result = default(BitRate); + return false; + } + } + + /// + /// Parse a unit string. + /// + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static BitRateUnit ParseUnit(string str) + { + return ParseUnit(str, (IFormatProvider)null); + } + + /// + /// Parse a unit string. + /// + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static BitRateUnit ParseUnit(string str, [CanBeNull] string cultureName) + { + return ParseUnit(str, cultureName == null ? null : new CultureInfo(cultureName)); + } + + /// + /// Parse a unit string. + /// + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods +#if WINDOWS_UWP + internal +#else + public +#endif + static BitRateUnit ParseUnit(string str, IFormatProvider formatProvider = null) + { + if (str == null) throw new ArgumentNullException("str"); + + var unitSystem = UnitSystem.GetCached(formatProvider); + var unit = unitSystem.Parse(str.Trim()); + + if (unit == BitRateUnit.Undefined) + { + var newEx = new UnitsNetException("Error parsing string. The unit is not a recognized BitRateUnit."); + newEx.Data["input"] = str; + newEx.Data["formatprovider"] = formatProvider?.ToString() ?? "(null)"; + throw newEx; + } + + return unit; + } + + #endregion + + /// + /// Set the default unit used by ToString(). Default is BitPerSecond + /// + public static BitRateUnit ToStringDefaultUnit { get; set; } = BitRateUnit.BitPerSecond; + + /// + /// Get default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(ToStringDefaultUnit); + } + + /// + /// Get string representation of value and unit. Using current UI culture and two significant digits after radix. + /// + /// Unit representation to use. + /// String representation. + public string ToString(BitRateUnit unit) + { + return ToString(unit, null, 2); + } + + /// + /// Get string representation of value and unit. Using two significant digits after radix. + /// + /// Unit representation to use. + /// Culture to use for localization and number formatting. + /// String representation. + public string ToString(BitRateUnit unit, [CanBeNull] Culture culture) + { + return ToString(unit, culture, 2); + } + + /// + /// Get string representation of value and unit. + /// + /// Unit representation to use. + /// Culture to use for localization and number formatting. + /// The number of significant digits after the radix point. + /// String representation. + [UsedImplicitly] + public string ToString(BitRateUnit unit, [CanBeNull] Culture culture, int significantDigitsAfterRadix) + { + double value = As(unit); + string format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(unit, culture, format); + } + + /// + /// Get string representation of value and unit. + /// + /// Culture to use for localization and number formatting. + /// Unit representation to use. + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + [UsedImplicitly] + public string ToString(BitRateUnit unit, [CanBeNull] Culture culture, [NotNull] string format, + [NotNull] params object[] args) + { + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + // Windows Runtime Component does not support CultureInfo type, so use culture name string for public methods instead: https://msdn.microsoft.com/en-us/library/br230301.aspx +#if WINDOWS_UWP + IFormatProvider formatProvider = culture == null ? null : new CultureInfo(culture); +#else + IFormatProvider formatProvider = culture; +#endif + double value = As(unit); + object[] formatArgs = UnitFormatter.GetFormatArgs(unit, value, formatProvider, args); + return string.Format(formatProvider, format, formatArgs); + } + + /// + /// Represents the largest possible value of BitRate + /// + public static BitRate MaxValue + { + get + { + return new BitRate(decimal.MaxValue); + } + } + + /// + /// Represents the smallest possible value of BitRate + /// + public static BitRate MinValue + { + get + { + return new BitRate(decimal.MinValue); + } + } + } +} diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs index 06688fd25d..f6a67aa6f8 100644 --- a/UnitsNet/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet/GeneratedCode/QuantityType.g.cs @@ -56,6 +56,7 @@ public enum QuantityType ApparentPower, Area, AreaMomentOfInertia, + BitRate, BrakeSpecificFuelConsumption, Density, Duration, diff --git a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs index 1a0537c3df..340cb28567 100644 --- a/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs +++ b/UnitsNet/GeneratedCode/UnitSystem.Default.g.cs @@ -410,6 +410,140 @@ private static readonly ReadOnlyCollection DefaultLocalization new AbbreviationsForCulture("en-US", "mm⁴", "mm^4"), }), }), + new UnitLocalization(typeof (BitRateUnit), + new[] + { + new CulturesForEnumValue((int) BitRateUnit.BitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "bit/s", "bps"), + }), + new CulturesForEnumValue((int) BitRateUnit.BytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "B/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.ExabitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "Ebit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.ExabytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "EB/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.ExbibitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "Eibit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.ExbibytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "EiB/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.GibibitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "Gibit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.GibibytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "GiB/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.GigabitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "Gbit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.GigabytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "GB/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.KibibitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "Kibit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.KibibytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "KiB/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.KilobitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "kbit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.KilobytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "kB/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.MebibitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "Mibit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.MebibytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "MiB/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.MegabitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "Mbit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.MegabytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "MB/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.PebibitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "Pibit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.PebibytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "PiB/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.PetabitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "Pbit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.PetabytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "PB/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.TebibitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "Tibit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.TebibytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "TiB/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.TerabitPerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "Tbit/s"), + }), + new CulturesForEnumValue((int) BitRateUnit.TerabytePerSecond, + new[] + { + new AbbreviationsForCulture("en-US", "TB/s"), + }), + }), new UnitLocalization(typeof (BrakeSpecificFuelConsumptionUnit), new[] { diff --git a/UnitsNet/GeneratedCode/Units/BitRateUnit.g.cs b/UnitsNet/GeneratedCode/Units/BitRateUnit.g.cs new file mode 100644 index 0000000000..80a916d25a --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/BitRateUnit.g.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyUnit.extra.cs files to add code to generated quantities. +// Add Extensions\MyUnitExtensions.cs to decorate quantities with new behavior. +// Add UnitDefinitions\MyUnit.json and run GeneratUnits.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Copyright (c) 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). +// https://github.com/angularsen/UnitsNet +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + public enum BitRateUnit + { + Undefined = 0, + BitPerSecond, + BytePerSecond, + ExabitPerSecond, + ExabytePerSecond, + ExbibitPerSecond, + ExbibytePerSecond, + GibibitPerSecond, + GibibytePerSecond, + GigabitPerSecond, + GigabytePerSecond, + KibibitPerSecond, + KibibytePerSecond, + KilobitPerSecond, + KilobytePerSecond, + MebibitPerSecond, + MebibytePerSecond, + MegabitPerSecond, + MegabytePerSecond, + PebibitPerSecond, + PebibytePerSecond, + PetabitPerSecond, + PetabytePerSecond, + TebibitPerSecond, + TebibytePerSecond, + TerabitPerSecond, + TerabytePerSecond, + } +} diff --git a/UnitsNet/UnitDefinitions/BitRate.json b/UnitsNet/UnitDefinitions/BitRate.json new file mode 100644 index 0000000000..b768a1c9e5 --- /dev/null +++ b/UnitsNet/UnitDefinitions/BitRate.json @@ -0,0 +1,35 @@ +{ + "Name": "BitRate", + "BaseUnit": "BitPerSecond", + "BaseType": "decimal", + "XmlDoc": "In telecommunications and computing, bit rate is the number of bits that are conveyed or processed per unit of time.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Bit_rate", + "Units": [ + { + "SingularName": "BitPerSecond", + "PluralName": "BitsPerSecond", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": [ "Kilo", "Mega", "Giga", "Tera", "Peta", "Exa", "Kibi", "Mebi", "Gibi", "Tebi", "Pebi", "Exbi" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "bit/s", "bps" ] + } + ] + }, + { + "SingularName": "BytePerSecond", + "PluralName": "BytesPerSecond", + "FromUnitToBaseFunc": "x*8m", + "FromBaseToUnitFunc": "x/8m", + "Prefixes": [ "Kilo", "Mega", "Giga", "Tera", "Peta", "Exa", "Kibi", "Mebi", "Gibi", "Tebi", "Pebi", "Exbi" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "B/s" ] + } + ] + } + ] +} \ No newline at end of file From 34bcc5129496b49d95d94f5b2844b32e65cb7955 Mon Sep 17 00:00:00 2001 From: "coding@baxenergy.com" Date: Mon, 22 Jan 2018 14:56:22 +0100 Subject: [PATCH 2/3] Replaced computations to constant values in BitRate tests. --- UnitsNet.Tests/CustomCode/BitRateTests.cs | 44 +++++++++++------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/BitRateTests.cs b/UnitsNet.Tests/CustomCode/BitRateTests.cs index a4ac06ad57..6e2c24cb4d 100644 --- a/UnitsNet.Tests/CustomCode/BitRateTests.cs +++ b/UnitsNet.Tests/CustomCode/BitRateTests.cs @@ -50,52 +50,52 @@ public class BitRateTests : BitRateTestsBase protected override double BytesPerSecondInOneBitPerSecond => 0.125d; - protected override double ExabitsPerSecondInOneBitPerSecond => 1e-18d; + protected override double ExabitsPerSecondInOneBitPerSecond => 1E-18d; - protected override double ExabytesPerSecondInOneBitPerSecond => 0.125d * 1e-18d; + protected override double ExabytesPerSecondInOneBitPerSecond => 1.25E-19d; - protected override double ExbibitsPerSecondInOneBitPerSecond => 1d / Math.Pow(1024, 6); + protected override double ExbibitsPerSecondInOneBitPerSecond => 8.67361738E-19d; - protected override double ExbibytesPerSecondInOneBitPerSecond => 8d / Math.Pow(1024, 6); + protected override double ExbibytesPerSecondInOneBitPerSecond => 1.0842021724855E-19d; - protected override double GibibitsPerSecondInOneBitPerSecond => 1d / Math.Pow(1024, 3); + protected override double GibibitsPerSecondInOneBitPerSecond => 9.31322574615479E-10d; - protected override double GibibytesPerSecondInOneBitPerSecond => 1d / 8 / Math.Pow(1024, 3); + protected override double GibibytesPerSecondInOneBitPerSecond => 1.16415321826935E-10d; - protected override double GigabitsPerSecondInOneBitPerSecond => 1e-9d; + protected override double GigabitsPerSecondInOneBitPerSecond => 1E-9d; - protected override double GigabytesPerSecondInOneBitPerSecond => 0.125d * 1e-9d; + protected override double GigabytesPerSecondInOneBitPerSecond => 1.25E-10d; - protected override double KibibitsPerSecondInOneBitPerSecond => 1d / 1024d; + protected override double KibibitsPerSecondInOneBitPerSecond => 0.0009765625d; - protected override double KibibytesPerSecondInOneBitPerSecond => 1d / 8 / 1024d; + protected override double KibibytesPerSecondInOneBitPerSecond => 0.0001220703125d; protected override double KilobitsPerSecondInOneBitPerSecond => 0.001d; protected override double KilobytesPerSecondInOneBitPerSecond => 0.000125d; - protected override double MebibitsPerSecondInOneBitPerSecond => 1d / Math.Pow(1024, 2); + protected override double MebibitsPerSecondInOneBitPerSecond => 9.5367431640625E-07d; - protected override double MebibytesPerSecondInOneBitPerSecond => 1d / 8 / Math.Pow(1024, 2); + protected override double MebibytesPerSecondInOneBitPerSecond => 1.19209289550781E-07d; - protected override double MegabitsPerSecondInOneBitPerSecond => 1e-6d; + protected override double MegabitsPerSecondInOneBitPerSecond => 1E-6d; - protected override double MegabytesPerSecondInOneBitPerSecond => 0.125d * 1e-6d; + protected override double MegabytesPerSecondInOneBitPerSecond => 1.25E-07d; - protected override double PebibitsPerSecondInOneBitPerSecond => 1d / Math.Pow(1024, 5); + protected override double PebibitsPerSecondInOneBitPerSecond => 8.88178419700125E-16d; - protected override double PebibytesPerSecondInOneBitPerSecond => 1d / 8 / Math.Pow(1024, 5); + protected override double PebibytesPerSecondInOneBitPerSecond => 1.11022302462516E-16d; - protected override double PetabitsPerSecondInOneBitPerSecond => 1e-15d; + protected override double PetabitsPerSecondInOneBitPerSecond => 1E-15d; - protected override double PetabytesPerSecondInOneBitPerSecond => 0.125d * 1e-15d; + protected override double PetabytesPerSecondInOneBitPerSecond => 1.25E-16d; - protected override double TebibitsPerSecondInOneBitPerSecond => 1d / Math.Pow(1024, 4); + protected override double TebibitsPerSecondInOneBitPerSecond => 9.09494701772928E-13d; - protected override double TebibytesPerSecondInOneBitPerSecond => 1d / 8 / Math.Pow(1024, 4); + protected override double TebibytesPerSecondInOneBitPerSecond => 1.13686837721616E-13d; - protected override double TerabitsPerSecondInOneBitPerSecond => 1e-12d; + protected override double TerabitsPerSecondInOneBitPerSecond => 1E-12d; - protected override double TerabytesPerSecondInOneBitPerSecond => 0.125d * 1e-12d; + protected override double TerabytesPerSecondInOneBitPerSecond => 1.25E-13d; } } From 345774868b7a701ea3c2ef1bb624001d47d04a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Tun=C3=A7er?= Date: Tue, 23 Jan 2018 19:05:11 +0300 Subject: [PATCH 3/3] prettification --- UnitsNet.Tests/CustomCode/BitRateTests.cs | 57 ++++++++--------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/UnitsNet.Tests/CustomCode/BitRateTests.cs b/UnitsNet.Tests/CustomCode/BitRateTests.cs index 6e2c24cb4d..6c0b361cb6 100644 --- a/UnitsNet.Tests/CustomCode/BitRateTests.cs +++ b/UnitsNet.Tests/CustomCode/BitRateTests.cs @@ -47,55 +47,36 @@ namespace UnitsNet.Tests.CustomCode public class BitRateTests : BitRateTestsBase { protected override double BitsPerSecondInOneBitPerSecond => 1d; + protected override double BytesPerSecondInOneBitPerSecond => 1.25E-1d; - protected override double BytesPerSecondInOneBitPerSecond => 0.125d; - - protected override double ExabitsPerSecondInOneBitPerSecond => 1E-18d; - - protected override double ExabytesPerSecondInOneBitPerSecond => 1.25E-19d; - - protected override double ExbibitsPerSecondInOneBitPerSecond => 8.67361738E-19d; - - protected override double ExbibytesPerSecondInOneBitPerSecond => 1.0842021724855E-19d; - - protected override double GibibitsPerSecondInOneBitPerSecond => 9.31322574615479E-10d; - - protected override double GibibytesPerSecondInOneBitPerSecond => 1.16415321826935E-10d; - - protected override double GigabitsPerSecondInOneBitPerSecond => 1E-9d; - - protected override double GigabytesPerSecondInOneBitPerSecond => 1.25E-10d; - + protected override double KilobitsPerSecondInOneBitPerSecond => 1E-3d; + protected override double KilobytesPerSecondInOneBitPerSecond => 1.25E-4d; protected override double KibibitsPerSecondInOneBitPerSecond => 0.0009765625d; - protected override double KibibytesPerSecondInOneBitPerSecond => 0.0001220703125d; - protected override double KilobitsPerSecondInOneBitPerSecond => 0.001d; - - protected override double KilobytesPerSecondInOneBitPerSecond => 0.000125d; - - protected override double MebibitsPerSecondInOneBitPerSecond => 9.5367431640625E-07d; - - protected override double MebibytesPerSecondInOneBitPerSecond => 1.19209289550781E-07d; - protected override double MegabitsPerSecondInOneBitPerSecond => 1E-6d; - protected override double MegabytesPerSecondInOneBitPerSecond => 1.25E-07d; + protected override double MebibitsPerSecondInOneBitPerSecond => 9.5367431640625E-07d; + protected override double MebibytesPerSecondInOneBitPerSecond => 1.19209289550781E-07d; - protected override double PebibitsPerSecondInOneBitPerSecond => 8.88178419700125E-16d; - - protected override double PebibytesPerSecondInOneBitPerSecond => 1.11022302462516E-16d; - - protected override double PetabitsPerSecondInOneBitPerSecond => 1E-15d; - - protected override double PetabytesPerSecondInOneBitPerSecond => 1.25E-16d; + protected override double GigabitsPerSecondInOneBitPerSecond => 1E-9d; + protected override double GigabytesPerSecondInOneBitPerSecond => 1.25E-10d; + protected override double GibibitsPerSecondInOneBitPerSecond => 9.31322574615479E-10d; + protected override double GibibytesPerSecondInOneBitPerSecond => 1.16415321826935E-10d; + protected override double TerabitsPerSecondInOneBitPerSecond => 1E-12d; + protected override double TerabytesPerSecondInOneBitPerSecond => 1.25E-13d; protected override double TebibitsPerSecondInOneBitPerSecond => 9.09494701772928E-13d; - protected override double TebibytesPerSecondInOneBitPerSecond => 1.13686837721616E-13d; - protected override double TerabitsPerSecondInOneBitPerSecond => 1E-12d; + protected override double PetabitsPerSecondInOneBitPerSecond => 1E-15d; + protected override double PetabytesPerSecondInOneBitPerSecond => 1.25E-16d; + protected override double PebibitsPerSecondInOneBitPerSecond => 8.88178419700125E-16d; + protected override double PebibytesPerSecondInOneBitPerSecond => 1.11022302462516E-16d; - protected override double TerabytesPerSecondInOneBitPerSecond => 1.25E-13d; + protected override double ExabitsPerSecondInOneBitPerSecond => 1E-18d; + protected override double ExabytesPerSecondInOneBitPerSecond => 1.25E-19d; + protected override double ExbibitsPerSecondInOneBitPerSecond => 8.67361738E-19d; + protected override double ExbibytesPerSecondInOneBitPerSecond => 1.0842021724855E-19d; } }