diff --git a/Common/UnitDefinitions/Length.json b/Common/UnitDefinitions/Length.json index 303b217ad5..e18ed9fcec 100644 --- a/Common/UnitDefinitions/Length.json +++ b/Common/UnitDefinitions/Length.json @@ -293,6 +293,50 @@ "Abbreviations": [ "h", "hh" ] } ] + }, + { + "SingularName": "AstronomicalUnit", + "PluralName": "AstronomicalUnits", + "FromUnitToBaseFunc": "x * 1.4959787070e11", + "FromBaseToUnitFunc": "x / 1.4959787070e11", + "XmlDocSummary": "One Astronomical Unit is the distance from the solar system Star, the sun, to planet Earth.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Astronomical_unit", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "au", "ua" ] + } + ] + }, + { + "SingularName": "Parsec", + "PluralName": "Parsecs", + "FromUnitToBaseFunc": "x * 3.08567758128e16", + "FromBaseToUnitFunc": "x / 3.08567758128e16", + "XmlDocSummary": "A parsec is defined as the distance at which one astronomical unit (AU) subtends an angle of one arcsecond.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Parsec", + "Prefixes": [ "Kilo", "Mega" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "pc" ] + } + ] + }, + { + "SingularName": "LightYear", + "PluralName": "LightYears", + "FromUnitToBaseFunc": "x * 9.46073047258e15", + "FromBaseToUnitFunc": "x / 9.46073047258e15", + "XmlDocSummary": "A Light Year (ly) is the distance that light travel during an Earth year, ie 365 days.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Light-year", + "Prefixes": [ "Kilo", "Mega" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "ly" ] + } + ] } ] } diff --git a/Common/UnitDefinitions/Luminosity.json b/Common/UnitDefinitions/Luminosity.json new file mode 100644 index 0000000000..59a1d82efd --- /dev/null +++ b/Common/UnitDefinitions/Luminosity.json @@ -0,0 +1,40 @@ +{ + "Name": "Luminosity", + "BaseUnit": "Watt", + "BaseType": "double", + "XmlDoc": "Luminosity is an absolute measure of radiated electromagnetic power (light), the radiant power emitted by a light-emitting object.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Luminosity", + "BaseDimensions": { + "L": 2, + "M": 1, + "T": -3 + }, + "Units": [ + { + "SingularName": "Watt", + "PluralName": "Watts", + "FromUnitToBaseFunc": "x", + "FromBaseToUnitFunc": "x", + "Prefixes": [ "Femto", "Pico", "Nano", "Micro", "Milli", "Deci", "Deca", "Kilo", "Mega", "Giga", "Tera", "Peta" ], + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "W" ] + } + ] + }, + { + "SingularName": "SolarLuminosity", + "PluralName": "SolarLuminosities", + "FromUnitToBaseFunc": "x * 3.846e26", + "FromBaseToUnitFunc": "x / 3.846e26", + "XmlDocRemarks": "https://www.britannica.com/science/luminosity", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "L⊙" ] + } + ] + } + ] +} \ No newline at end of file diff --git a/Common/UnitDefinitions/Mass.json b/Common/UnitDefinitions/Mass.json index df53d1792d..ab018920e2 100644 --- a/Common/UnitDefinitions/Mass.json +++ b/Common/UnitDefinitions/Mass.json @@ -210,6 +210,40 @@ "Abbreviations": [ "gr" ] } ] + }, + { + "SingularName": "SolarMass", + "PluralName": "SolarMasses", + "BaseUnits": { + "M": "SolarMass" + }, + "FromUnitToBaseFunc": "x * 1.98947e30", + "FromBaseToUnitFunc": "x / 1.98947e30", + "XmlDocSummary": "Solar mass is a ratio unit to the mass of the solar system star, the sun.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Solar_mass", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "M⊙" ] + } + ] + }, + { + "SingularName": "EarthMass", + "PluralName": "EarthMasses", + "BaseUnits": { + "M": "EarthMass" + }, + "FromUnitToBaseFunc": "x * 5.9722E+24", + "FromBaseToUnitFunc": "x / 5.9722E+24", + "XmlDocSummary": "Earth mass is a ratio unit to the mass of planet Earth.", + "XmlDocRemarks": "https://en.wikipedia.org/wiki/Earth_mass", + "Localization": [ + { + "Culture": "en-US", + "Abbreviations": [ "em" ] + } + ] } ] } diff --git a/UnitsNet.Tests/CustomCode/LengthTests.cs b/UnitsNet.Tests/CustomCode/LengthTests.cs index 8ab2bd21ec..6ce73bad38 100644 --- a/UnitsNet.Tests/CustomCode/LengthTests.cs +++ b/UnitsNet.Tests/CustomCode/LengthTests.cs @@ -57,6 +57,20 @@ public class LengthTests : LengthTestsBase protected override double HandsInOneMeter => 9.8425196850393701; + protected override double AstronomicalUnitsInOneMeter => 6.6845871222684500000000000E-12; + + protected override double KilolightYearsInOneMeter => 1.0570008340247000000000000E-19; + + protected override double KiloparsecsInOneMeter => 3.2407790389471100000000000E-20; + + protected override double LightYearsInOneMeter => 1.0570008340247000000000000E-16; + + protected override double MegalightYearsInOneMeter => 1.0570008340247000000000000E-22; + + protected override double MegaparsecsInOneMeter => 3.2407790389471100000000000E-23; + + protected override double ParsecsInOneMeter => 3.2407790389471100000000000E-17; + [ Fact] public void AreaTimesLengthEqualsVolume() { diff --git a/UnitsNet.Tests/CustomCode/LuminosityTests.cs b/UnitsNet.Tests/CustomCode/LuminosityTests.cs new file mode 100644 index 0000000000..51ee9d494f --- /dev/null +++ b/UnitsNet.Tests/CustomCode/LuminosityTests.cs @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; + +namespace UnitsNet.Tests.CustomCode +{ + public class LuminosityTests : LuminosityTestsBase + { + // Override properties in base class here + protected override double FemtowattsInOneWatt => 1e15; + + protected override double PicowattsInOneWatt => 1e12; + + protected override double NanowattsInOneWatt => 1e9; + + protected override double MicrowattsInOneWatt => 1e6; + + protected override double MilliwattsInOneWatt => 1e3; + + protected override double DeciwattsInOneWatt => 1e1; + + protected override double WattsInOneWatt => 1; + + protected override double DecawattsInOneWatt => 1e-1; + + protected override double KilowattsInOneWatt => 1e-3; + + protected override double MegawattsInOneWatt => 1e-6; + + protected override double GigawattsInOneWatt => 1e-9; + + protected override double TerawattsInOneWatt => 1e-12; + + protected override double PetawattsInOneWatt => 1e-15; + + protected override double SolarLuminositiesInOneWatt => 2.6001040041601700000000000E-27; + + } +} diff --git a/UnitsNet.Tests/CustomCode/MassTests.cs b/UnitsNet.Tests/CustomCode/MassTests.cs index 3771c716a4..18cb904f33 100644 --- a/UnitsNet.Tests/CustomCode/MassTests.cs +++ b/UnitsNet.Tests/CustomCode/MassTests.cs @@ -57,6 +57,12 @@ public class MassTests : MassTestsBase protected override double ShortHundredweightInOneKilogram => 0.022046226218487758; + protected override double EarthMassesInOneKilogram => 1.6744248350691500000000000E-25; + + protected override double SolarMassesInOneKilogram => 5.0264643347223100000000000E-31; + + //protected override double SolarMassesTolerance => 0.1; + [Fact] public void AccelerationTimesMassEqualsForce() { diff --git a/UnitsNet.Tests/GeneratedCode/LengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/LengthTestsBase.g.cs index a020c068ce..de43669211 100644 --- a/UnitsNet.Tests/GeneratedCode/LengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/LengthTestsBase.g.cs @@ -34,6 +34,7 @@ namespace UnitsNet.Tests // ReSharper disable once PartialTypeWithSinglePart public abstract partial class LengthTestsBase { + protected abstract double AstronomicalUnitsInOneMeter { get; } protected abstract double CentimetersInOneMeter { get; } protected abstract double DecimetersInOneMeter { get; } protected abstract double DtpPicasInOneMeter { get; } @@ -43,7 +44,12 @@ public abstract partial class LengthTestsBase protected abstract double HandsInOneMeter { get; } protected abstract double HectometersInOneMeter { get; } protected abstract double InchesInOneMeter { get; } + protected abstract double KilolightYearsInOneMeter { get; } protected abstract double KilometersInOneMeter { get; } + protected abstract double KiloparsecsInOneMeter { get; } + protected abstract double LightYearsInOneMeter { get; } + protected abstract double MegalightYearsInOneMeter { get; } + protected abstract double MegaparsecsInOneMeter { get; } protected abstract double MetersInOneMeter { get; } protected abstract double MicroinchesInOneMeter { get; } protected abstract double MicrometersInOneMeter { get; } @@ -52,6 +58,7 @@ public abstract partial class LengthTestsBase protected abstract double MillimetersInOneMeter { get; } protected abstract double NanometersInOneMeter { get; } protected abstract double NauticalMilesInOneMeter { get; } + protected abstract double ParsecsInOneMeter { get; } protected abstract double PrinterPicasInOneMeter { get; } protected abstract double PrinterPointsInOneMeter { get; } protected abstract double ShacklesInOneMeter { get; } @@ -60,6 +67,7 @@ public abstract partial class LengthTestsBase protected abstract double YardsInOneMeter { get; } // ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double AstronomicalUnitsTolerance { get { return 1e-5; } } protected virtual double CentimetersTolerance { get { return 1e-5; } } protected virtual double DecimetersTolerance { get { return 1e-5; } } protected virtual double DtpPicasTolerance { get { return 1e-5; } } @@ -69,7 +77,12 @@ public abstract partial class LengthTestsBase protected virtual double HandsTolerance { get { return 1e-5; } } protected virtual double HectometersTolerance { get { return 1e-5; } } protected virtual double InchesTolerance { get { return 1e-5; } } + protected virtual double KilolightYearsTolerance { get { return 1e-5; } } protected virtual double KilometersTolerance { get { return 1e-5; } } + protected virtual double KiloparsecsTolerance { get { return 1e-5; } } + protected virtual double LightYearsTolerance { get { return 1e-5; } } + protected virtual double MegalightYearsTolerance { get { return 1e-5; } } + protected virtual double MegaparsecsTolerance { get { return 1e-5; } } protected virtual double MetersTolerance { get { return 1e-5; } } protected virtual double MicroinchesTolerance { get { return 1e-5; } } protected virtual double MicrometersTolerance { get { return 1e-5; } } @@ -78,6 +91,7 @@ public abstract partial class LengthTestsBase protected virtual double MillimetersTolerance { get { return 1e-5; } } protected virtual double NanometersTolerance { get { return 1e-5; } } protected virtual double NauticalMilesTolerance { get { return 1e-5; } } + protected virtual double ParsecsTolerance { get { return 1e-5; } } protected virtual double PrinterPicasTolerance { get { return 1e-5; } } protected virtual double PrinterPointsTolerance { get { return 1e-5; } } protected virtual double ShacklesTolerance { get { return 1e-5; } } @@ -109,6 +123,7 @@ public void Ctor_WithNaNValue_ThrowsArgumentException() public void MeterToLengthUnits() { Length meter = Length.FromMeters(1); + AssertEx.EqualTolerance(AstronomicalUnitsInOneMeter, meter.AstronomicalUnits, AstronomicalUnitsTolerance); AssertEx.EqualTolerance(CentimetersInOneMeter, meter.Centimeters, CentimetersTolerance); AssertEx.EqualTolerance(DecimetersInOneMeter, meter.Decimeters, DecimetersTolerance); AssertEx.EqualTolerance(DtpPicasInOneMeter, meter.DtpPicas, DtpPicasTolerance); @@ -118,7 +133,12 @@ public void MeterToLengthUnits() AssertEx.EqualTolerance(HandsInOneMeter, meter.Hands, HandsTolerance); AssertEx.EqualTolerance(HectometersInOneMeter, meter.Hectometers, HectometersTolerance); AssertEx.EqualTolerance(InchesInOneMeter, meter.Inches, InchesTolerance); + AssertEx.EqualTolerance(KilolightYearsInOneMeter, meter.KilolightYears, KilolightYearsTolerance); AssertEx.EqualTolerance(KilometersInOneMeter, meter.Kilometers, KilometersTolerance); + AssertEx.EqualTolerance(KiloparsecsInOneMeter, meter.Kiloparsecs, KiloparsecsTolerance); + AssertEx.EqualTolerance(LightYearsInOneMeter, meter.LightYears, LightYearsTolerance); + AssertEx.EqualTolerance(MegalightYearsInOneMeter, meter.MegalightYears, MegalightYearsTolerance); + AssertEx.EqualTolerance(MegaparsecsInOneMeter, meter.Megaparsecs, MegaparsecsTolerance); AssertEx.EqualTolerance(MetersInOneMeter, meter.Meters, MetersTolerance); AssertEx.EqualTolerance(MicroinchesInOneMeter, meter.Microinches, MicroinchesTolerance); AssertEx.EqualTolerance(MicrometersInOneMeter, meter.Micrometers, MicrometersTolerance); @@ -127,6 +147,7 @@ public void MeterToLengthUnits() AssertEx.EqualTolerance(MillimetersInOneMeter, meter.Millimeters, MillimetersTolerance); AssertEx.EqualTolerance(NanometersInOneMeter, meter.Nanometers, NanometersTolerance); AssertEx.EqualTolerance(NauticalMilesInOneMeter, meter.NauticalMiles, NauticalMilesTolerance); + AssertEx.EqualTolerance(ParsecsInOneMeter, meter.Parsecs, ParsecsTolerance); AssertEx.EqualTolerance(PrinterPicasInOneMeter, meter.PrinterPicas, PrinterPicasTolerance); AssertEx.EqualTolerance(PrinterPointsInOneMeter, meter.PrinterPoints, PrinterPointsTolerance); AssertEx.EqualTolerance(ShacklesInOneMeter, meter.Shackles, ShacklesTolerance); @@ -138,6 +159,7 @@ public void MeterToLengthUnits() [Fact] public void FromValueAndUnit() { + AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.AstronomicalUnit).AstronomicalUnits, AstronomicalUnitsTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Centimeter).Centimeters, CentimetersTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Decimeter).Decimeters, DecimetersTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.DtpPica).DtpPicas, DtpPicasTolerance); @@ -147,7 +169,12 @@ public void FromValueAndUnit() AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Hand).Hands, HandsTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Hectometer).Hectometers, HectometersTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Inch).Inches, InchesTolerance); + AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.KilolightYear).KilolightYears, KilolightYearsTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Kilometer).Kilometers, KilometersTolerance); + AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Kiloparsec).Kiloparsecs, KiloparsecsTolerance); + AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.LightYear).LightYears, LightYearsTolerance); + AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.MegalightYear).MegalightYears, MegalightYearsTolerance); + AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Megaparsec).Megaparsecs, MegaparsecsTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Meter).Meters, MetersTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Microinch).Microinches, MicroinchesTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Micrometer).Micrometers, MicrometersTolerance); @@ -156,6 +183,7 @@ public void FromValueAndUnit() AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Millimeter).Millimeters, MillimetersTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Nanometer).Nanometers, NanometersTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.NauticalMile).NauticalMiles, NauticalMilesTolerance); + AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Parsec).Parsecs, ParsecsTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.PrinterPica).PrinterPicas, PrinterPicasTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.PrinterPoint).PrinterPoints, PrinterPointsTolerance); AssertEx.EqualTolerance(1, Length.From(1, LengthUnit.Shackle).Shackles, ShacklesTolerance); @@ -181,6 +209,7 @@ public void FromMeters_WithNanValue_ThrowsArgumentException() public void As() { var meter = Length.FromMeters(1); + AssertEx.EqualTolerance(AstronomicalUnitsInOneMeter, meter.As(LengthUnit.AstronomicalUnit), AstronomicalUnitsTolerance); AssertEx.EqualTolerance(CentimetersInOneMeter, meter.As(LengthUnit.Centimeter), CentimetersTolerance); AssertEx.EqualTolerance(DecimetersInOneMeter, meter.As(LengthUnit.Decimeter), DecimetersTolerance); AssertEx.EqualTolerance(DtpPicasInOneMeter, meter.As(LengthUnit.DtpPica), DtpPicasTolerance); @@ -190,7 +219,12 @@ public void As() AssertEx.EqualTolerance(HandsInOneMeter, meter.As(LengthUnit.Hand), HandsTolerance); AssertEx.EqualTolerance(HectometersInOneMeter, meter.As(LengthUnit.Hectometer), HectometersTolerance); AssertEx.EqualTolerance(InchesInOneMeter, meter.As(LengthUnit.Inch), InchesTolerance); + AssertEx.EqualTolerance(KilolightYearsInOneMeter, meter.As(LengthUnit.KilolightYear), KilolightYearsTolerance); AssertEx.EqualTolerance(KilometersInOneMeter, meter.As(LengthUnit.Kilometer), KilometersTolerance); + AssertEx.EqualTolerance(KiloparsecsInOneMeter, meter.As(LengthUnit.Kiloparsec), KiloparsecsTolerance); + AssertEx.EqualTolerance(LightYearsInOneMeter, meter.As(LengthUnit.LightYear), LightYearsTolerance); + AssertEx.EqualTolerance(MegalightYearsInOneMeter, meter.As(LengthUnit.MegalightYear), MegalightYearsTolerance); + AssertEx.EqualTolerance(MegaparsecsInOneMeter, meter.As(LengthUnit.Megaparsec), MegaparsecsTolerance); AssertEx.EqualTolerance(MetersInOneMeter, meter.As(LengthUnit.Meter), MetersTolerance); AssertEx.EqualTolerance(MicroinchesInOneMeter, meter.As(LengthUnit.Microinch), MicroinchesTolerance); AssertEx.EqualTolerance(MicrometersInOneMeter, meter.As(LengthUnit.Micrometer), MicrometersTolerance); @@ -199,6 +233,7 @@ public void As() AssertEx.EqualTolerance(MillimetersInOneMeter, meter.As(LengthUnit.Millimeter), MillimetersTolerance); AssertEx.EqualTolerance(NanometersInOneMeter, meter.As(LengthUnit.Nanometer), NanometersTolerance); AssertEx.EqualTolerance(NauticalMilesInOneMeter, meter.As(LengthUnit.NauticalMile), NauticalMilesTolerance); + AssertEx.EqualTolerance(ParsecsInOneMeter, meter.As(LengthUnit.Parsec), ParsecsTolerance); AssertEx.EqualTolerance(PrinterPicasInOneMeter, meter.As(LengthUnit.PrinterPica), PrinterPicasTolerance); AssertEx.EqualTolerance(PrinterPointsInOneMeter, meter.As(LengthUnit.PrinterPoint), PrinterPointsTolerance); AssertEx.EqualTolerance(ShacklesInOneMeter, meter.As(LengthUnit.Shackle), ShacklesTolerance); @@ -212,6 +247,10 @@ public void ToUnit() { var meter = Length.FromMeters(1); + var astronomicalunitQuantity = meter.ToUnit(LengthUnit.AstronomicalUnit); + AssertEx.EqualTolerance(AstronomicalUnitsInOneMeter, (double)astronomicalunitQuantity.Value, AstronomicalUnitsTolerance); + Assert.Equal(LengthUnit.AstronomicalUnit, astronomicalunitQuantity.Unit); + var centimeterQuantity = meter.ToUnit(LengthUnit.Centimeter); AssertEx.EqualTolerance(CentimetersInOneMeter, (double)centimeterQuantity.Value, CentimetersTolerance); Assert.Equal(LengthUnit.Centimeter, centimeterQuantity.Unit); @@ -248,10 +287,30 @@ public void ToUnit() AssertEx.EqualTolerance(InchesInOneMeter, (double)inchQuantity.Value, InchesTolerance); Assert.Equal(LengthUnit.Inch, inchQuantity.Unit); + var kilolightyearQuantity = meter.ToUnit(LengthUnit.KilolightYear); + AssertEx.EqualTolerance(KilolightYearsInOneMeter, (double)kilolightyearQuantity.Value, KilolightYearsTolerance); + Assert.Equal(LengthUnit.KilolightYear, kilolightyearQuantity.Unit); + var kilometerQuantity = meter.ToUnit(LengthUnit.Kilometer); AssertEx.EqualTolerance(KilometersInOneMeter, (double)kilometerQuantity.Value, KilometersTolerance); Assert.Equal(LengthUnit.Kilometer, kilometerQuantity.Unit); + var kiloparsecQuantity = meter.ToUnit(LengthUnit.Kiloparsec); + AssertEx.EqualTolerance(KiloparsecsInOneMeter, (double)kiloparsecQuantity.Value, KiloparsecsTolerance); + Assert.Equal(LengthUnit.Kiloparsec, kiloparsecQuantity.Unit); + + var lightyearQuantity = meter.ToUnit(LengthUnit.LightYear); + AssertEx.EqualTolerance(LightYearsInOneMeter, (double)lightyearQuantity.Value, LightYearsTolerance); + Assert.Equal(LengthUnit.LightYear, lightyearQuantity.Unit); + + var megalightyearQuantity = meter.ToUnit(LengthUnit.MegalightYear); + AssertEx.EqualTolerance(MegalightYearsInOneMeter, (double)megalightyearQuantity.Value, MegalightYearsTolerance); + Assert.Equal(LengthUnit.MegalightYear, megalightyearQuantity.Unit); + + var megaparsecQuantity = meter.ToUnit(LengthUnit.Megaparsec); + AssertEx.EqualTolerance(MegaparsecsInOneMeter, (double)megaparsecQuantity.Value, MegaparsecsTolerance); + Assert.Equal(LengthUnit.Megaparsec, megaparsecQuantity.Unit); + var meterQuantity = meter.ToUnit(LengthUnit.Meter); AssertEx.EqualTolerance(MetersInOneMeter, (double)meterQuantity.Value, MetersTolerance); Assert.Equal(LengthUnit.Meter, meterQuantity.Unit); @@ -284,6 +343,10 @@ public void ToUnit() AssertEx.EqualTolerance(NauticalMilesInOneMeter, (double)nauticalmileQuantity.Value, NauticalMilesTolerance); Assert.Equal(LengthUnit.NauticalMile, nauticalmileQuantity.Unit); + var parsecQuantity = meter.ToUnit(LengthUnit.Parsec); + AssertEx.EqualTolerance(ParsecsInOneMeter, (double)parsecQuantity.Value, ParsecsTolerance); + Assert.Equal(LengthUnit.Parsec, parsecQuantity.Unit); + var printerpicaQuantity = meter.ToUnit(LengthUnit.PrinterPica); AssertEx.EqualTolerance(PrinterPicasInOneMeter, (double)printerpicaQuantity.Value, PrinterPicasTolerance); Assert.Equal(LengthUnit.PrinterPica, printerpicaQuantity.Unit); @@ -313,6 +376,7 @@ public void ToUnit() public void ConversionRoundTrip() { Length meter = Length.FromMeters(1); + AssertEx.EqualTolerance(1, Length.FromAstronomicalUnits(meter.AstronomicalUnits).Meters, AstronomicalUnitsTolerance); AssertEx.EqualTolerance(1, Length.FromCentimeters(meter.Centimeters).Meters, CentimetersTolerance); AssertEx.EqualTolerance(1, Length.FromDecimeters(meter.Decimeters).Meters, DecimetersTolerance); AssertEx.EqualTolerance(1, Length.FromDtpPicas(meter.DtpPicas).Meters, DtpPicasTolerance); @@ -322,7 +386,12 @@ public void ConversionRoundTrip() AssertEx.EqualTolerance(1, Length.FromHands(meter.Hands).Meters, HandsTolerance); AssertEx.EqualTolerance(1, Length.FromHectometers(meter.Hectometers).Meters, HectometersTolerance); AssertEx.EqualTolerance(1, Length.FromInches(meter.Inches).Meters, InchesTolerance); + AssertEx.EqualTolerance(1, Length.FromKilolightYears(meter.KilolightYears).Meters, KilolightYearsTolerance); AssertEx.EqualTolerance(1, Length.FromKilometers(meter.Kilometers).Meters, KilometersTolerance); + AssertEx.EqualTolerance(1, Length.FromKiloparsecs(meter.Kiloparsecs).Meters, KiloparsecsTolerance); + AssertEx.EqualTolerance(1, Length.FromLightYears(meter.LightYears).Meters, LightYearsTolerance); + AssertEx.EqualTolerance(1, Length.FromMegalightYears(meter.MegalightYears).Meters, MegalightYearsTolerance); + AssertEx.EqualTolerance(1, Length.FromMegaparsecs(meter.Megaparsecs).Meters, MegaparsecsTolerance); AssertEx.EqualTolerance(1, Length.FromMeters(meter.Meters).Meters, MetersTolerance); AssertEx.EqualTolerance(1, Length.FromMicroinches(meter.Microinches).Meters, MicroinchesTolerance); AssertEx.EqualTolerance(1, Length.FromMicrometers(meter.Micrometers).Meters, MicrometersTolerance); @@ -331,6 +400,7 @@ public void ConversionRoundTrip() AssertEx.EqualTolerance(1, Length.FromMillimeters(meter.Millimeters).Meters, MillimetersTolerance); AssertEx.EqualTolerance(1, Length.FromNanometers(meter.Nanometers).Meters, NanometersTolerance); AssertEx.EqualTolerance(1, Length.FromNauticalMiles(meter.NauticalMiles).Meters, NauticalMilesTolerance); + AssertEx.EqualTolerance(1, Length.FromParsecs(meter.Parsecs).Meters, ParsecsTolerance); AssertEx.EqualTolerance(1, Length.FromPrinterPicas(meter.PrinterPicas).Meters, PrinterPicasTolerance); AssertEx.EqualTolerance(1, Length.FromPrinterPoints(meter.PrinterPoints).Meters, PrinterPointsTolerance); AssertEx.EqualTolerance(1, Length.FromShackles(meter.Shackles).Meters, ShacklesTolerance); diff --git a/UnitsNet.Tests/GeneratedCode/LuminosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/LuminosityTestsBase.g.cs new file mode 100644 index 0000000000..d179367255 --- /dev/null +++ b/UnitsNet.Tests/GeneratedCode/LuminosityTestsBase.g.cs @@ -0,0 +1,373 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Linq; +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 Luminosity. + /// +// ReSharper disable once PartialTypeWithSinglePart + public abstract partial class LuminosityTestsBase + { + protected abstract double DecawattsInOneWatt { get; } + protected abstract double DeciwattsInOneWatt { get; } + protected abstract double FemtowattsInOneWatt { get; } + protected abstract double GigawattsInOneWatt { get; } + protected abstract double KilowattsInOneWatt { get; } + protected abstract double MegawattsInOneWatt { get; } + protected abstract double MicrowattsInOneWatt { get; } + protected abstract double MilliwattsInOneWatt { get; } + protected abstract double NanowattsInOneWatt { get; } + protected abstract double PetawattsInOneWatt { get; } + protected abstract double PicowattsInOneWatt { get; } + protected abstract double SolarLuminositiesInOneWatt { get; } + protected abstract double TerawattsInOneWatt { get; } + protected abstract double WattsInOneWatt { get; } + +// ReSharper disable VirtualMemberNeverOverriden.Global + protected virtual double DecawattsTolerance { get { return 1e-5; } } + protected virtual double DeciwattsTolerance { get { return 1e-5; } } + protected virtual double FemtowattsTolerance { get { return 1e-5; } } + protected virtual double GigawattsTolerance { get { return 1e-5; } } + protected virtual double KilowattsTolerance { get { return 1e-5; } } + protected virtual double MegawattsTolerance { get { return 1e-5; } } + protected virtual double MicrowattsTolerance { get { return 1e-5; } } + protected virtual double MilliwattsTolerance { get { return 1e-5; } } + protected virtual double NanowattsTolerance { get { return 1e-5; } } + protected virtual double PetawattsTolerance { get { return 1e-5; } } + protected virtual double PicowattsTolerance { get { return 1e-5; } } + protected virtual double SolarLuminositiesTolerance { get { return 1e-5; } } + protected virtual double TerawattsTolerance { get { return 1e-5; } } + protected virtual double WattsTolerance { get { return 1e-5; } } +// ReSharper restore VirtualMemberNeverOverriden.Global + + [Fact] + public void Ctor_WithUndefinedUnit_ThrowsArgumentException() + { + Assert.Throws(() => new Luminosity((double)0.0, LuminosityUnit.Undefined)); + } + + [Fact] + public void Ctor_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => new Luminosity(double.PositiveInfinity, LuminosityUnit.Watt)); + Assert.Throws(() => new Luminosity(double.NegativeInfinity, LuminosityUnit.Watt)); + } + + [Fact] + public void Ctor_WithNaNValue_ThrowsArgumentException() + { + Assert.Throws(() => new Luminosity(double.NaN, LuminosityUnit.Watt)); + } + + [Fact] + public void WattToLuminosityUnits() + { + Luminosity watt = Luminosity.FromWatts(1); + AssertEx.EqualTolerance(DecawattsInOneWatt, watt.Decawatts, DecawattsTolerance); + AssertEx.EqualTolerance(DeciwattsInOneWatt, watt.Deciwatts, DeciwattsTolerance); + AssertEx.EqualTolerance(FemtowattsInOneWatt, watt.Femtowatts, FemtowattsTolerance); + AssertEx.EqualTolerance(GigawattsInOneWatt, watt.Gigawatts, GigawattsTolerance); + AssertEx.EqualTolerance(KilowattsInOneWatt, watt.Kilowatts, KilowattsTolerance); + AssertEx.EqualTolerance(MegawattsInOneWatt, watt.Megawatts, MegawattsTolerance); + AssertEx.EqualTolerance(MicrowattsInOneWatt, watt.Microwatts, MicrowattsTolerance); + AssertEx.EqualTolerance(MilliwattsInOneWatt, watt.Milliwatts, MilliwattsTolerance); + AssertEx.EqualTolerance(NanowattsInOneWatt, watt.Nanowatts, NanowattsTolerance); + AssertEx.EqualTolerance(PetawattsInOneWatt, watt.Petawatts, PetawattsTolerance); + AssertEx.EqualTolerance(PicowattsInOneWatt, watt.Picowatts, PicowattsTolerance); + AssertEx.EqualTolerance(SolarLuminositiesInOneWatt, watt.SolarLuminosities, SolarLuminositiesTolerance); + AssertEx.EqualTolerance(TerawattsInOneWatt, watt.Terawatts, TerawattsTolerance); + AssertEx.EqualTolerance(WattsInOneWatt, watt.Watts, WattsTolerance); + } + + [Fact] + public void FromValueAndUnit() + { + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Decawatt).Decawatts, DecawattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Deciwatt).Deciwatts, DeciwattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Femtowatt).Femtowatts, FemtowattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Gigawatt).Gigawatts, GigawattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Kilowatt).Kilowatts, KilowattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Megawatt).Megawatts, MegawattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Microwatt).Microwatts, MicrowattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Milliwatt).Milliwatts, MilliwattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Nanowatt).Nanowatts, NanowattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Petawatt).Petawatts, PetawattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Picowatt).Picowatts, PicowattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.SolarLuminosity).SolarLuminosities, SolarLuminositiesTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Terawatt).Terawatts, TerawattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.From(1, LuminosityUnit.Watt).Watts, WattsTolerance); + } + + [Fact] + public void FromWatts_WithInfinityValue_ThrowsArgumentException() + { + Assert.Throws(() => Luminosity.FromWatts(double.PositiveInfinity)); + Assert.Throws(() => Luminosity.FromWatts(double.NegativeInfinity)); + } + + [Fact] + public void FromWatts_WithNanValue_ThrowsArgumentException() + { + Assert.Throws(() => Luminosity.FromWatts(double.NaN)); + } + + [Fact] + public void As() + { + var watt = Luminosity.FromWatts(1); + AssertEx.EqualTolerance(DecawattsInOneWatt, watt.As(LuminosityUnit.Decawatt), DecawattsTolerance); + AssertEx.EqualTolerance(DeciwattsInOneWatt, watt.As(LuminosityUnit.Deciwatt), DeciwattsTolerance); + AssertEx.EqualTolerance(FemtowattsInOneWatt, watt.As(LuminosityUnit.Femtowatt), FemtowattsTolerance); + AssertEx.EqualTolerance(GigawattsInOneWatt, watt.As(LuminosityUnit.Gigawatt), GigawattsTolerance); + AssertEx.EqualTolerance(KilowattsInOneWatt, watt.As(LuminosityUnit.Kilowatt), KilowattsTolerance); + AssertEx.EqualTolerance(MegawattsInOneWatt, watt.As(LuminosityUnit.Megawatt), MegawattsTolerance); + AssertEx.EqualTolerance(MicrowattsInOneWatt, watt.As(LuminosityUnit.Microwatt), MicrowattsTolerance); + AssertEx.EqualTolerance(MilliwattsInOneWatt, watt.As(LuminosityUnit.Milliwatt), MilliwattsTolerance); + AssertEx.EqualTolerance(NanowattsInOneWatt, watt.As(LuminosityUnit.Nanowatt), NanowattsTolerance); + AssertEx.EqualTolerance(PetawattsInOneWatt, watt.As(LuminosityUnit.Petawatt), PetawattsTolerance); + AssertEx.EqualTolerance(PicowattsInOneWatt, watt.As(LuminosityUnit.Picowatt), PicowattsTolerance); + AssertEx.EqualTolerance(SolarLuminositiesInOneWatt, watt.As(LuminosityUnit.SolarLuminosity), SolarLuminositiesTolerance); + AssertEx.EqualTolerance(TerawattsInOneWatt, watt.As(LuminosityUnit.Terawatt), TerawattsTolerance); + AssertEx.EqualTolerance(WattsInOneWatt, watt.As(LuminosityUnit.Watt), WattsTolerance); + } + + [Fact] + public void ToUnit() + { + var watt = Luminosity.FromWatts(1); + + var decawattQuantity = watt.ToUnit(LuminosityUnit.Decawatt); + AssertEx.EqualTolerance(DecawattsInOneWatt, (double)decawattQuantity.Value, DecawattsTolerance); + Assert.Equal(LuminosityUnit.Decawatt, decawattQuantity.Unit); + + var deciwattQuantity = watt.ToUnit(LuminosityUnit.Deciwatt); + AssertEx.EqualTolerance(DeciwattsInOneWatt, (double)deciwattQuantity.Value, DeciwattsTolerance); + Assert.Equal(LuminosityUnit.Deciwatt, deciwattQuantity.Unit); + + var femtowattQuantity = watt.ToUnit(LuminosityUnit.Femtowatt); + AssertEx.EqualTolerance(FemtowattsInOneWatt, (double)femtowattQuantity.Value, FemtowattsTolerance); + Assert.Equal(LuminosityUnit.Femtowatt, femtowattQuantity.Unit); + + var gigawattQuantity = watt.ToUnit(LuminosityUnit.Gigawatt); + AssertEx.EqualTolerance(GigawattsInOneWatt, (double)gigawattQuantity.Value, GigawattsTolerance); + Assert.Equal(LuminosityUnit.Gigawatt, gigawattQuantity.Unit); + + var kilowattQuantity = watt.ToUnit(LuminosityUnit.Kilowatt); + AssertEx.EqualTolerance(KilowattsInOneWatt, (double)kilowattQuantity.Value, KilowattsTolerance); + Assert.Equal(LuminosityUnit.Kilowatt, kilowattQuantity.Unit); + + var megawattQuantity = watt.ToUnit(LuminosityUnit.Megawatt); + AssertEx.EqualTolerance(MegawattsInOneWatt, (double)megawattQuantity.Value, MegawattsTolerance); + Assert.Equal(LuminosityUnit.Megawatt, megawattQuantity.Unit); + + var microwattQuantity = watt.ToUnit(LuminosityUnit.Microwatt); + AssertEx.EqualTolerance(MicrowattsInOneWatt, (double)microwattQuantity.Value, MicrowattsTolerance); + Assert.Equal(LuminosityUnit.Microwatt, microwattQuantity.Unit); + + var milliwattQuantity = watt.ToUnit(LuminosityUnit.Milliwatt); + AssertEx.EqualTolerance(MilliwattsInOneWatt, (double)milliwattQuantity.Value, MilliwattsTolerance); + Assert.Equal(LuminosityUnit.Milliwatt, milliwattQuantity.Unit); + + var nanowattQuantity = watt.ToUnit(LuminosityUnit.Nanowatt); + AssertEx.EqualTolerance(NanowattsInOneWatt, (double)nanowattQuantity.Value, NanowattsTolerance); + Assert.Equal(LuminosityUnit.Nanowatt, nanowattQuantity.Unit); + + var petawattQuantity = watt.ToUnit(LuminosityUnit.Petawatt); + AssertEx.EqualTolerance(PetawattsInOneWatt, (double)petawattQuantity.Value, PetawattsTolerance); + Assert.Equal(LuminosityUnit.Petawatt, petawattQuantity.Unit); + + var picowattQuantity = watt.ToUnit(LuminosityUnit.Picowatt); + AssertEx.EqualTolerance(PicowattsInOneWatt, (double)picowattQuantity.Value, PicowattsTolerance); + Assert.Equal(LuminosityUnit.Picowatt, picowattQuantity.Unit); + + var solarluminosityQuantity = watt.ToUnit(LuminosityUnit.SolarLuminosity); + AssertEx.EqualTolerance(SolarLuminositiesInOneWatt, (double)solarluminosityQuantity.Value, SolarLuminositiesTolerance); + Assert.Equal(LuminosityUnit.SolarLuminosity, solarluminosityQuantity.Unit); + + var terawattQuantity = watt.ToUnit(LuminosityUnit.Terawatt); + AssertEx.EqualTolerance(TerawattsInOneWatt, (double)terawattQuantity.Value, TerawattsTolerance); + Assert.Equal(LuminosityUnit.Terawatt, terawattQuantity.Unit); + + var wattQuantity = watt.ToUnit(LuminosityUnit.Watt); + AssertEx.EqualTolerance(WattsInOneWatt, (double)wattQuantity.Value, WattsTolerance); + Assert.Equal(LuminosityUnit.Watt, wattQuantity.Unit); + } + + [Fact] + public void ConversionRoundTrip() + { + Luminosity watt = Luminosity.FromWatts(1); + AssertEx.EqualTolerance(1, Luminosity.FromDecawatts(watt.Decawatts).Watts, DecawattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromDeciwatts(watt.Deciwatts).Watts, DeciwattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromFemtowatts(watt.Femtowatts).Watts, FemtowattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromGigawatts(watt.Gigawatts).Watts, GigawattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromKilowatts(watt.Kilowatts).Watts, KilowattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromMegawatts(watt.Megawatts).Watts, MegawattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromMicrowatts(watt.Microwatts).Watts, MicrowattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromMilliwatts(watt.Milliwatts).Watts, MilliwattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromNanowatts(watt.Nanowatts).Watts, NanowattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromPetawatts(watt.Petawatts).Watts, PetawattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromPicowatts(watt.Picowatts).Watts, PicowattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromSolarLuminosities(watt.SolarLuminosities).Watts, SolarLuminositiesTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromTerawatts(watt.Terawatts).Watts, TerawattsTolerance); + AssertEx.EqualTolerance(1, Luminosity.FromWatts(watt.Watts).Watts, WattsTolerance); + } + + [Fact] + public void ArithmeticOperators() + { + Luminosity v = Luminosity.FromWatts(1); + AssertEx.EqualTolerance(-1, -v.Watts, WattsTolerance); + AssertEx.EqualTolerance(2, (Luminosity.FromWatts(3)-v).Watts, WattsTolerance); + AssertEx.EqualTolerance(2, (v + v).Watts, WattsTolerance); + AssertEx.EqualTolerance(10, (v*10).Watts, WattsTolerance); + AssertEx.EqualTolerance(10, (10*v).Watts, WattsTolerance); + AssertEx.EqualTolerance(2, (Luminosity.FromWatts(10)/5).Watts, WattsTolerance); + AssertEx.EqualTolerance(2, Luminosity.FromWatts(10)/Luminosity.FromWatts(5), WattsTolerance); + } + + [Fact] + public void ComparisonOperators() + { + Luminosity oneWatt = Luminosity.FromWatts(1); + Luminosity twoWatts = Luminosity.FromWatts(2); + + Assert.True(oneWatt < twoWatts); + Assert.True(oneWatt <= twoWatts); + Assert.True(twoWatts > oneWatt); + Assert.True(twoWatts >= oneWatt); + + Assert.False(oneWatt > twoWatts); + Assert.False(oneWatt >= twoWatts); + Assert.False(twoWatts < oneWatt); + Assert.False(twoWatts <= oneWatt); + } + + [Fact] + public void CompareToIsImplemented() + { + Luminosity watt = Luminosity.FromWatts(1); + Assert.Equal(0, watt.CompareTo(watt)); + Assert.True(watt.CompareTo(Luminosity.Zero) > 0); + Assert.True(Luminosity.Zero.CompareTo(watt) < 0); + } + + [Fact] + public void CompareToThrowsOnTypeMismatch() + { + Luminosity watt = Luminosity.FromWatts(1); + Assert.Throws(() => watt.CompareTo(new object())); + } + + [Fact] + public void CompareToThrowsOnNull() + { + Luminosity watt = Luminosity.FromWatts(1); + Assert.Throws(() => watt.CompareTo(null)); + } + + [Fact] + public void EqualityOperators() + { + var a = Luminosity.FromWatts(1); + var b = Luminosity.FromWatts(2); + + // ReSharper disable EqualExpressionComparison + + Assert.True(a == a); + Assert.False(a != a); + + Assert.True(a != b); + Assert.False(a == b); + + Assert.False(a == null); + Assert.False(null == a); + +// ReSharper restore EqualExpressionComparison + } + + [Fact] + public void EqualsIsImplemented() + { + var a = Luminosity.FromWatts(1); + var b = Luminosity.FromWatts(2); + + Assert.True(a.Equals(a)); + Assert.False(a.Equals(b)); + Assert.False(a.Equals(null)); + } + + [Fact] + public void EqualsRelativeToleranceIsImplemented() + { + var v = Luminosity.FromWatts(1); + Assert.True(v.Equals(Luminosity.FromWatts(1), WattsTolerance, ComparisonType.Relative)); + Assert.False(v.Equals(Luminosity.Zero, WattsTolerance, ComparisonType.Relative)); + } + + [Fact] + public void EqualsReturnsFalseOnTypeMismatch() + { + Luminosity watt = Luminosity.FromWatts(1); + Assert.False(watt.Equals(new object())); + } + + [Fact] + public void EqualsReturnsFalseOnNull() + { + Luminosity watt = Luminosity.FromWatts(1); + Assert.False(watt.Equals(null)); + } + + [Fact] + public void UnitsDoesNotContainUndefined() + { + Assert.DoesNotContain(LuminosityUnit.Undefined, Luminosity.Units); + } + + [Fact] + public void HasAtLeastOneAbbreviationSpecified() + { + var units = Enum.GetValues(typeof(LuminosityUnit)).Cast(); + foreach(var unit in units) + { + if(unit == LuminosityUnit.Undefined) + continue; + + var defaultAbbreviation = UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit); + } + } + + [Fact] + public void BaseDimensionsShouldNeverBeNull() + { + Assert.False(Luminosity.BaseDimensions is null); + } + } +} diff --git a/UnitsNet.Tests/GeneratedCode/MassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/MassTestsBase.g.cs index f955d07347..df6c140b10 100644 --- a/UnitsNet.Tests/GeneratedCode/MassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/MassTestsBase.g.cs @@ -37,6 +37,7 @@ public abstract partial class MassTestsBase protected abstract double CentigramsInOneKilogram { get; } protected abstract double DecagramsInOneKilogram { get; } protected abstract double DecigramsInOneKilogram { get; } + protected abstract double EarthMassesInOneKilogram { get; } protected abstract double GrainsInOneKilogram { get; } protected abstract double GramsInOneKilogram { get; } protected abstract double HectogramsInOneKilogram { get; } @@ -55,6 +56,7 @@ public abstract partial class MassTestsBase protected abstract double ShortHundredweightInOneKilogram { get; } protected abstract double ShortTonsInOneKilogram { get; } protected abstract double SlugsInOneKilogram { get; } + protected abstract double SolarMassesInOneKilogram { get; } protected abstract double StoneInOneKilogram { get; } protected abstract double TonnesInOneKilogram { get; } @@ -62,6 +64,7 @@ public abstract partial class MassTestsBase protected virtual double CentigramsTolerance { get { return 1e-5; } } protected virtual double DecagramsTolerance { get { return 1e-5; } } protected virtual double DecigramsTolerance { get { return 1e-5; } } + protected virtual double EarthMassesTolerance { get { return 1e-5; } } protected virtual double GrainsTolerance { get { return 1e-5; } } protected virtual double GramsTolerance { get { return 1e-5; } } protected virtual double HectogramsTolerance { get { return 1e-5; } } @@ -80,6 +83,7 @@ public abstract partial class MassTestsBase protected virtual double ShortHundredweightTolerance { get { return 1e-5; } } protected virtual double ShortTonsTolerance { get { return 1e-5; } } protected virtual double SlugsTolerance { get { return 1e-5; } } + protected virtual double SolarMassesTolerance { get { return 1e-5; } } protected virtual double StoneTolerance { get { return 1e-5; } } protected virtual double TonnesTolerance { get { return 1e-5; } } // ReSharper restore VirtualMemberNeverOverriden.Global @@ -110,6 +114,7 @@ public void KilogramToMassUnits() AssertEx.EqualTolerance(CentigramsInOneKilogram, kilogram.Centigrams, CentigramsTolerance); AssertEx.EqualTolerance(DecagramsInOneKilogram, kilogram.Decagrams, DecagramsTolerance); AssertEx.EqualTolerance(DecigramsInOneKilogram, kilogram.Decigrams, DecigramsTolerance); + AssertEx.EqualTolerance(EarthMassesInOneKilogram, kilogram.EarthMasses, EarthMassesTolerance); AssertEx.EqualTolerance(GrainsInOneKilogram, kilogram.Grains, GrainsTolerance); AssertEx.EqualTolerance(GramsInOneKilogram, kilogram.Grams, GramsTolerance); AssertEx.EqualTolerance(HectogramsInOneKilogram, kilogram.Hectograms, HectogramsTolerance); @@ -128,6 +133,7 @@ public void KilogramToMassUnits() AssertEx.EqualTolerance(ShortHundredweightInOneKilogram, kilogram.ShortHundredweight, ShortHundredweightTolerance); AssertEx.EqualTolerance(ShortTonsInOneKilogram, kilogram.ShortTons, ShortTonsTolerance); AssertEx.EqualTolerance(SlugsInOneKilogram, kilogram.Slugs, SlugsTolerance); + AssertEx.EqualTolerance(SolarMassesInOneKilogram, kilogram.SolarMasses, SolarMassesTolerance); AssertEx.EqualTolerance(StoneInOneKilogram, kilogram.Stone, StoneTolerance); AssertEx.EqualTolerance(TonnesInOneKilogram, kilogram.Tonnes, TonnesTolerance); } @@ -138,6 +144,7 @@ public void FromValueAndUnit() AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Centigram).Centigrams, CentigramsTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Decagram).Decagrams, DecagramsTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Decigram).Decigrams, DecigramsTolerance); + AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.EarthMass).EarthMasses, EarthMassesTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Grain).Grains, GrainsTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Gram).Grams, GramsTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Hectogram).Hectograms, HectogramsTolerance); @@ -156,6 +163,7 @@ public void FromValueAndUnit() AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.ShortHundredweight).ShortHundredweight, ShortHundredweightTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.ShortTon).ShortTons, ShortTonsTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Slug).Slugs, SlugsTolerance); + AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.SolarMass).SolarMasses, SolarMassesTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Stone).Stone, StoneTolerance); AssertEx.EqualTolerance(1, Mass.From(1, MassUnit.Tonne).Tonnes, TonnesTolerance); } @@ -180,6 +188,7 @@ public void As() AssertEx.EqualTolerance(CentigramsInOneKilogram, kilogram.As(MassUnit.Centigram), CentigramsTolerance); AssertEx.EqualTolerance(DecagramsInOneKilogram, kilogram.As(MassUnit.Decagram), DecagramsTolerance); AssertEx.EqualTolerance(DecigramsInOneKilogram, kilogram.As(MassUnit.Decigram), DecigramsTolerance); + AssertEx.EqualTolerance(EarthMassesInOneKilogram, kilogram.As(MassUnit.EarthMass), EarthMassesTolerance); AssertEx.EqualTolerance(GrainsInOneKilogram, kilogram.As(MassUnit.Grain), GrainsTolerance); AssertEx.EqualTolerance(GramsInOneKilogram, kilogram.As(MassUnit.Gram), GramsTolerance); AssertEx.EqualTolerance(HectogramsInOneKilogram, kilogram.As(MassUnit.Hectogram), HectogramsTolerance); @@ -198,6 +207,7 @@ public void As() AssertEx.EqualTolerance(ShortHundredweightInOneKilogram, kilogram.As(MassUnit.ShortHundredweight), ShortHundredweightTolerance); AssertEx.EqualTolerance(ShortTonsInOneKilogram, kilogram.As(MassUnit.ShortTon), ShortTonsTolerance); AssertEx.EqualTolerance(SlugsInOneKilogram, kilogram.As(MassUnit.Slug), SlugsTolerance); + AssertEx.EqualTolerance(SolarMassesInOneKilogram, kilogram.As(MassUnit.SolarMass), SolarMassesTolerance); AssertEx.EqualTolerance(StoneInOneKilogram, kilogram.As(MassUnit.Stone), StoneTolerance); AssertEx.EqualTolerance(TonnesInOneKilogram, kilogram.As(MassUnit.Tonne), TonnesTolerance); } @@ -219,6 +229,10 @@ public void ToUnit() AssertEx.EqualTolerance(DecigramsInOneKilogram, (double)decigramQuantity.Value, DecigramsTolerance); Assert.Equal(MassUnit.Decigram, decigramQuantity.Unit); + var earthmassQuantity = kilogram.ToUnit(MassUnit.EarthMass); + AssertEx.EqualTolerance(EarthMassesInOneKilogram, (double)earthmassQuantity.Value, EarthMassesTolerance); + Assert.Equal(MassUnit.EarthMass, earthmassQuantity.Unit); + var grainQuantity = kilogram.ToUnit(MassUnit.Grain); AssertEx.EqualTolerance(GrainsInOneKilogram, (double)grainQuantity.Value, GrainsTolerance); Assert.Equal(MassUnit.Grain, grainQuantity.Unit); @@ -291,6 +305,10 @@ public void ToUnit() AssertEx.EqualTolerance(SlugsInOneKilogram, (double)slugQuantity.Value, SlugsTolerance); Assert.Equal(MassUnit.Slug, slugQuantity.Unit); + var solarmassQuantity = kilogram.ToUnit(MassUnit.SolarMass); + AssertEx.EqualTolerance(SolarMassesInOneKilogram, (double)solarmassQuantity.Value, SolarMassesTolerance); + Assert.Equal(MassUnit.SolarMass, solarmassQuantity.Unit); + var stoneQuantity = kilogram.ToUnit(MassUnit.Stone); AssertEx.EqualTolerance(StoneInOneKilogram, (double)stoneQuantity.Value, StoneTolerance); Assert.Equal(MassUnit.Stone, stoneQuantity.Unit); @@ -307,6 +325,7 @@ public void ConversionRoundTrip() AssertEx.EqualTolerance(1, Mass.FromCentigrams(kilogram.Centigrams).Kilograms, CentigramsTolerance); AssertEx.EqualTolerance(1, Mass.FromDecagrams(kilogram.Decagrams).Kilograms, DecagramsTolerance); AssertEx.EqualTolerance(1, Mass.FromDecigrams(kilogram.Decigrams).Kilograms, DecigramsTolerance); + AssertEx.EqualTolerance(1, Mass.FromEarthMasses(kilogram.EarthMasses).Kilograms, EarthMassesTolerance); AssertEx.EqualTolerance(1, Mass.FromGrains(kilogram.Grains).Kilograms, GrainsTolerance); AssertEx.EqualTolerance(1, Mass.FromGrams(kilogram.Grams).Kilograms, GramsTolerance); AssertEx.EqualTolerance(1, Mass.FromHectograms(kilogram.Hectograms).Kilograms, HectogramsTolerance); @@ -325,6 +344,7 @@ public void ConversionRoundTrip() AssertEx.EqualTolerance(1, Mass.FromShortHundredweight(kilogram.ShortHundredweight).Kilograms, ShortHundredweightTolerance); AssertEx.EqualTolerance(1, Mass.FromShortTons(kilogram.ShortTons).Kilograms, ShortTonsTolerance); AssertEx.EqualTolerance(1, Mass.FromSlugs(kilogram.Slugs).Kilograms, SlugsTolerance); + AssertEx.EqualTolerance(1, Mass.FromSolarMasses(kilogram.SolarMasses).Kilograms, SolarMassesTolerance); AssertEx.EqualTolerance(1, Mass.FromStone(kilogram.Stone).Kilograms, StoneTolerance); AssertEx.EqualTolerance(1, Mass.FromTonnes(kilogram.Tonnes).Kilograms, TonnesTolerance); } diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Length.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Length.g.cs index 2a7adf9f5c..a8b3de6459 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Length.g.cs @@ -155,6 +155,11 @@ private Length(double numericValue, LengthUnit unit) #region Conversion Properties + /// + /// Get Length in AstronomicalUnits. + /// + public double AstronomicalUnits => As(LengthUnit.AstronomicalUnit); + /// /// Get Length in Centimeters. /// @@ -200,11 +205,36 @@ private Length(double numericValue, LengthUnit unit) /// public double Inches => As(LengthUnit.Inch); + /// + /// Get Length in KilolightYears. + /// + public double KilolightYears => As(LengthUnit.KilolightYear); + /// /// Get Length in Kilometers. /// public double Kilometers => As(LengthUnit.Kilometer); + /// + /// Get Length in Kiloparsecs. + /// + public double Kiloparsecs => As(LengthUnit.Kiloparsec); + + /// + /// Get Length in LightYears. + /// + public double LightYears => As(LengthUnit.LightYear); + + /// + /// Get Length in MegalightYears. + /// + public double MegalightYears => As(LengthUnit.MegalightYear); + + /// + /// Get Length in Megaparsecs. + /// + public double Megaparsecs => As(LengthUnit.Megaparsec); + /// /// Get Length in Meters. /// @@ -245,6 +275,11 @@ private Length(double numericValue, LengthUnit unit) /// public double NauticalMiles => As(LengthUnit.NauticalMile); + /// + /// Get Length in Parsecs. + /// + public double Parsecs => As(LengthUnit.Parsec); + /// /// Get Length in PrinterPicas. /// @@ -305,6 +340,16 @@ public static string GetAbbreviation(LengthUnit unit, [CanBeNull] string culture #region Static Factory Methods + /// + /// Get Length from AstronomicalUnits. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Length FromAstronomicalUnits(double astronomicalunits) + { + double value = (double) astronomicalunits; + return new Length(value, LengthUnit.AstronomicalUnit); + } /// /// Get Length from Centimeters. /// @@ -396,6 +441,16 @@ public static Length FromInches(double inches) return new Length(value, LengthUnit.Inch); } /// + /// Get Length from KilolightYears. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Length FromKilolightYears(double kilolightyears) + { + double value = (double) kilolightyears; + return new Length(value, LengthUnit.KilolightYear); + } + /// /// Get Length from Kilometers. /// /// If value is NaN or Infinity. @@ -406,6 +461,46 @@ public static Length FromKilometers(double kilometers) return new Length(value, LengthUnit.Kilometer); } /// + /// Get Length from Kiloparsecs. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Length FromKiloparsecs(double kiloparsecs) + { + double value = (double) kiloparsecs; + return new Length(value, LengthUnit.Kiloparsec); + } + /// + /// Get Length from LightYears. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Length FromLightYears(double lightyears) + { + double value = (double) lightyears; + return new Length(value, LengthUnit.LightYear); + } + /// + /// Get Length from MegalightYears. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Length FromMegalightYears(double megalightyears) + { + double value = (double) megalightyears; + return new Length(value, LengthUnit.MegalightYear); + } + /// + /// Get Length from Megaparsecs. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Length FromMegaparsecs(double megaparsecs) + { + double value = (double) megaparsecs; + return new Length(value, LengthUnit.Megaparsec); + } + /// /// Get Length from Meters. /// /// If value is NaN or Infinity. @@ -486,6 +581,16 @@ public static Length FromNauticalMiles(double nauticalmiles) return new Length(value, LengthUnit.NauticalMile); } /// + /// Get Length from Parsecs. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Length FromParsecs(double parsecs) + { + double value = (double) parsecs; + return new Length(value, LengthUnit.Parsec); + } + /// /// Get Length from PrinterPicas. /// /// If value is NaN or Infinity. @@ -836,6 +941,7 @@ private double AsBaseUnit() { switch(Unit) { + case LengthUnit.AstronomicalUnit: return _value * 1.4959787070e11; case LengthUnit.Centimeter: return (_value) * 1e-2d; case LengthUnit.Decimeter: return (_value) * 1e-1d; case LengthUnit.DtpPica: return _value/236.220472441; @@ -845,7 +951,12 @@ private double AsBaseUnit() case LengthUnit.Hand: return _value * 1.016e-1; case LengthUnit.Hectometer: return (_value) * 1e2d; case LengthUnit.Inch: return _value*2.54e-2; + case LengthUnit.KilolightYear: return (_value * 9.46073047258e15) * 1e3d; case LengthUnit.Kilometer: return (_value) * 1e3d; + case LengthUnit.Kiloparsec: return (_value * 3.08567758128e16) * 1e3d; + case LengthUnit.LightYear: return _value * 9.46073047258e15; + case LengthUnit.MegalightYear: return (_value * 9.46073047258e15) * 1e6d; + case LengthUnit.Megaparsec: return (_value * 3.08567758128e16) * 1e6d; case LengthUnit.Meter: return _value; case LengthUnit.Microinch: return _value*2.54e-8; case LengthUnit.Micrometer: return (_value) * 1e-6d; @@ -854,6 +965,7 @@ private double AsBaseUnit() case LengthUnit.Millimeter: return (_value) * 1e-3d; case LengthUnit.Nanometer: return (_value) * 1e-9d; case LengthUnit.NauticalMile: return _value*1852; + case LengthUnit.Parsec: return _value * 3.08567758128e16; case LengthUnit.PrinterPica: return _value/237.106301584; case LengthUnit.PrinterPoint: return (_value/72.27)*2.54e-2; case LengthUnit.Shackle: return _value*27.432; @@ -874,6 +986,7 @@ private double AsBaseNumericType(LengthUnit unit) switch(unit) { + case LengthUnit.AstronomicalUnit: return baseUnitValue / 1.4959787070e11; case LengthUnit.Centimeter: return (baseUnitValue) / 1e-2d; case LengthUnit.Decimeter: return (baseUnitValue) / 1e-1d; case LengthUnit.DtpPica: return baseUnitValue*236.220472441; @@ -883,7 +996,12 @@ private double AsBaseNumericType(LengthUnit unit) case LengthUnit.Hand: return baseUnitValue / 1.016e-1; case LengthUnit.Hectometer: return (baseUnitValue) / 1e2d; case LengthUnit.Inch: return baseUnitValue/2.54e-2; + case LengthUnit.KilolightYear: return (baseUnitValue / 9.46073047258e15) / 1e3d; case LengthUnit.Kilometer: return (baseUnitValue) / 1e3d; + case LengthUnit.Kiloparsec: return (baseUnitValue / 3.08567758128e16) / 1e3d; + case LengthUnit.LightYear: return baseUnitValue / 9.46073047258e15; + case LengthUnit.MegalightYear: return (baseUnitValue / 9.46073047258e15) / 1e6d; + case LengthUnit.Megaparsec: return (baseUnitValue / 3.08567758128e16) / 1e6d; case LengthUnit.Meter: return baseUnitValue; case LengthUnit.Microinch: return baseUnitValue/2.54e-8; case LengthUnit.Micrometer: return (baseUnitValue) / 1e-6d; @@ -892,6 +1010,7 @@ private double AsBaseNumericType(LengthUnit unit) case LengthUnit.Millimeter: return (baseUnitValue) / 1e-3d; case LengthUnit.Nanometer: return (baseUnitValue) / 1e-9d; case LengthUnit.NauticalMile: return baseUnitValue/1852; + case LengthUnit.Parsec: return baseUnitValue / 3.08567758128e16; case LengthUnit.PrinterPica: return baseUnitValue*237.106301584; case LengthUnit.PrinterPoint: return (baseUnitValue/2.54e-2)*72.27; case LengthUnit.Shackle: return baseUnitValue/27.432; diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Luminosity.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Luminosity.g.cs new file mode 100644 index 0000000000..ae4ae5285c --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Luminosity.g.cs @@ -0,0 +1,804 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.Units; +using UnitsNet.InternalHelpers; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// Luminosity is an absolute measure of radiated electromagnetic power (light), the radiant power emitted by a light-emitting object. + /// + /// + /// https://en.wikipedia.org/wiki/Luminosity + /// + // Windows Runtime Component has constraints on public types: https://msdn.microsoft.com/en-us/library/br230301.aspx#Declaring types in Windows Runtime Components + // Public structures can't have any members other than public fields, and those fields must be value types or strings. + // Public classes must be sealed (NotInheritable in Visual Basic). If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. + public sealed partial class Luminosity : IQuantity + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly LuminosityUnit? _unit; + + static Luminosity() + { + BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); + Info = new QuantityInfo(QuantityType.Luminosity, Units.Cast().ToArray(), BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with a value of 0 in the base unit Watt. + /// + /// + /// Windows Runtime Component requires a default constructor. + /// + public Luminosity() + { + _value = 0; + _unit = BaseUnit; + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to contruct this quantity with. + /// The unit representation to contruct this quantity with. + /// Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component. + /// If value is NaN or Infinity. + private Luminosity(double numericValue, LuminosityUnit unit) + { + if(unit == LuminosityUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = unit; + } + + #region Static Properties + + /// + /// Information about the quantity type, such as unit values and names. + /// + internal static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of Luminosity, which is Watt. All conversions go via this value. + /// + public static LuminosityUnit BaseUnit { get; } = LuminosityUnit.Watt; + + /// + /// Represents the largest possible value of Luminosity + /// + public static Luminosity MaxValue { get; } = new Luminosity(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of Luminosity + /// + public static Luminosity MinValue { get; } = new Luminosity(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.Luminosity; + + /// + /// All units of measurement for the Luminosity quantity. + /// + public static LuminosityUnit[] Units { get; } = Enum.GetValues(typeof(LuminosityUnit)).Cast().Except(new LuminosityUnit[]{ LuminosityUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Watt. + /// + public static Luminosity Zero { get; } = new Luminosity(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => Convert.ToDouble(_value); + + /// + object IQuantity.Unit => Unit; + + /// + /// The unit this quantity was constructed with -or- if default ctor was used. + /// + public LuminosityUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + internal QuantityInfo QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => Luminosity.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => Luminosity.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get Luminosity in Decawatts. + /// + public double Decawatts => As(LuminosityUnit.Decawatt); + + /// + /// Get Luminosity in Deciwatts. + /// + public double Deciwatts => As(LuminosityUnit.Deciwatt); + + /// + /// Get Luminosity in Femtowatts. + /// + public double Femtowatts => As(LuminosityUnit.Femtowatt); + + /// + /// Get Luminosity in Gigawatts. + /// + public double Gigawatts => As(LuminosityUnit.Gigawatt); + + /// + /// Get Luminosity in Kilowatts. + /// + public double Kilowatts => As(LuminosityUnit.Kilowatt); + + /// + /// Get Luminosity in Megawatts. + /// + public double Megawatts => As(LuminosityUnit.Megawatt); + + /// + /// Get Luminosity in Microwatts. + /// + public double Microwatts => As(LuminosityUnit.Microwatt); + + /// + /// Get Luminosity in Milliwatts. + /// + public double Milliwatts => As(LuminosityUnit.Milliwatt); + + /// + /// Get Luminosity in Nanowatts. + /// + public double Nanowatts => As(LuminosityUnit.Nanowatt); + + /// + /// Get Luminosity in Petawatts. + /// + public double Petawatts => As(LuminosityUnit.Petawatt); + + /// + /// Get Luminosity in Picowatts. + /// + public double Picowatts => As(LuminosityUnit.Picowatt); + + /// + /// Get Luminosity in SolarLuminosities. + /// + public double SolarLuminosities => As(LuminosityUnit.SolarLuminosity); + + /// + /// Get Luminosity in Terawatts. + /// + public double Terawatts => As(LuminosityUnit.Terawatt); + + /// + /// Get Luminosity in Watts. + /// + public double Watts => As(LuminosityUnit.Watt); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(LuminosityUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static string GetAbbreviation(LuminosityUnit unit, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get Luminosity from Decawatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromDecawatts(double decawatts) + { + double value = (double) decawatts; + return new Luminosity(value, LuminosityUnit.Decawatt); + } + /// + /// Get Luminosity from Deciwatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromDeciwatts(double deciwatts) + { + double value = (double) deciwatts; + return new Luminosity(value, LuminosityUnit.Deciwatt); + } + /// + /// Get Luminosity from Femtowatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromFemtowatts(double femtowatts) + { + double value = (double) femtowatts; + return new Luminosity(value, LuminosityUnit.Femtowatt); + } + /// + /// Get Luminosity from Gigawatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromGigawatts(double gigawatts) + { + double value = (double) gigawatts; + return new Luminosity(value, LuminosityUnit.Gigawatt); + } + /// + /// Get Luminosity from Kilowatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromKilowatts(double kilowatts) + { + double value = (double) kilowatts; + return new Luminosity(value, LuminosityUnit.Kilowatt); + } + /// + /// Get Luminosity from Megawatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromMegawatts(double megawatts) + { + double value = (double) megawatts; + return new Luminosity(value, LuminosityUnit.Megawatt); + } + /// + /// Get Luminosity from Microwatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromMicrowatts(double microwatts) + { + double value = (double) microwatts; + return new Luminosity(value, LuminosityUnit.Microwatt); + } + /// + /// Get Luminosity from Milliwatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromMilliwatts(double milliwatts) + { + double value = (double) milliwatts; + return new Luminosity(value, LuminosityUnit.Milliwatt); + } + /// + /// Get Luminosity from Nanowatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromNanowatts(double nanowatts) + { + double value = (double) nanowatts; + return new Luminosity(value, LuminosityUnit.Nanowatt); + } + /// + /// Get Luminosity from Petawatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromPetawatts(double petawatts) + { + double value = (double) petawatts; + return new Luminosity(value, LuminosityUnit.Petawatt); + } + /// + /// Get Luminosity from Picowatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromPicowatts(double picowatts) + { + double value = (double) picowatts; + return new Luminosity(value, LuminosityUnit.Picowatt); + } + /// + /// Get Luminosity from SolarLuminosities. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromSolarLuminosities(double solarluminosities) + { + double value = (double) solarluminosities; + return new Luminosity(value, LuminosityUnit.SolarLuminosity); + } + /// + /// Get Luminosity from Terawatts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromTerawatts(double terawatts) + { + double value = (double) terawatts; + return new Luminosity(value, LuminosityUnit.Terawatt); + } + /// + /// Get Luminosity from Watts. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Luminosity FromWatts(double watts) + { + double value = (double) watts; + return new Luminosity(value, LuminosityUnit.Watt); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Luminosity unit value. + // Fix name conflict with parameter "value" + [return: System.Runtime.InteropServices.WindowsRuntime.ReturnValueName("returnValue")] + public static Luminosity From(double value, LuminosityUnit fromUnit) + { + return new Luminosity((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static Luminosity Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static Luminosity Parse(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out Luminosity result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] string cultureName, out Luminosity result) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static LuminosityUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static LuminosityUnit ParseUnit(string str, [CanBeNull] string cultureName) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.Parse(str, provider); + } + + public static bool TryParseUnit(string str, out LuminosityUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out LuminosityUnit unit) + { + IFormatProvider provider = GetFormatProviderFromCultureName(cultureName); + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Equality / IComparable + + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is Luminosity objLuminosity)) throw new ArgumentException("Expected type Luminosity.", nameof(obj)); + + return CompareTo(objLuminosity); + } + + // Windows Runtime Component does not allow public methods/ctors with same number of parameters: https://msdn.microsoft.com/en-us/library/br230301.aspx#Overloaded methods + internal int CompareTo(Luminosity other) + { + return _value.CompareTo(other.AsBaseNumericType(this.Unit)); + } + + [Windows.Foundation.Metadata.DefaultOverload] + public override bool Equals(object obj) + { + if(obj is null || !(obj is Luminosity objLuminosity)) + return false; + + return Equals(objLuminosity); + } + + public bool Equals(Luminosity other) + { + return _value.Equals(other.AsBaseNumericType(this.Unit)); + } + + /// + /// + /// Compare equality to another Luminosity within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// + /// The other quantity to compare to. + /// The absolute or relative tolerance value. Must be greater than or equal to 0. + /// The comparison type: either relative or absolute. + /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + public bool Equals(Luminosity other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current Luminosity. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + double IQuantity.As(object unit) => As((LuminosityUnit)unit); + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(LuminosityUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = AsBaseNumericType(unit); + return Convert.ToDouble(converted); + } + + /// + /// Converts this Luminosity to another Luminosity with the unit representation . + /// + /// A Luminosity with the specified unit. + public Luminosity ToUnit(LuminosityUnit unit) + { + var convertedValue = AsBaseNumericType(unit); + return new Luminosity(convertedValue, unit); + } + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double AsBaseUnit() + { + switch(Unit) + { + case LuminosityUnit.Decawatt: return (_value) * 1e1d; + case LuminosityUnit.Deciwatt: return (_value) * 1e-1d; + case LuminosityUnit.Femtowatt: return (_value) * 1e-15d; + case LuminosityUnit.Gigawatt: return (_value) * 1e9d; + case LuminosityUnit.Kilowatt: return (_value) * 1e3d; + case LuminosityUnit.Megawatt: return (_value) * 1e6d; + case LuminosityUnit.Microwatt: return (_value) * 1e-6d; + case LuminosityUnit.Milliwatt: return (_value) * 1e-3d; + case LuminosityUnit.Nanowatt: return (_value) * 1e-9d; + case LuminosityUnit.Petawatt: return (_value) * 1e15d; + case LuminosityUnit.Picowatt: return (_value) * 1e-12d; + case LuminosityUnit.SolarLuminosity: return _value * 3.846e26; + case LuminosityUnit.Terawatt: return (_value) * 1e12d; + case LuminosityUnit.Watt: return _value; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + private double AsBaseNumericType(LuminosityUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = AsBaseUnit(); + + switch(unit) + { + case LuminosityUnit.Decawatt: return (baseUnitValue) / 1e1d; + case LuminosityUnit.Deciwatt: return (baseUnitValue) / 1e-1d; + case LuminosityUnit.Femtowatt: return (baseUnitValue) / 1e-15d; + case LuminosityUnit.Gigawatt: return (baseUnitValue) / 1e9d; + case LuminosityUnit.Kilowatt: return (baseUnitValue) / 1e3d; + case LuminosityUnit.Megawatt: return (baseUnitValue) / 1e6d; + case LuminosityUnit.Microwatt: return (baseUnitValue) / 1e-6d; + case LuminosityUnit.Milliwatt: return (baseUnitValue) / 1e-3d; + case LuminosityUnit.Nanowatt: return (baseUnitValue) / 1e-9d; + case LuminosityUnit.Petawatt: return (baseUnitValue) / 1e15d; + case LuminosityUnit.Picowatt: return (baseUnitValue) / 1e-12d; + case LuminosityUnit.SolarLuminosity: return baseUnitValue / 3.846e26; + case LuminosityUnit.Terawatt: return (baseUnitValue) / 1e12d; + case LuminosityUnit.Watt: return baseUnitValue; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Get default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString(null); + } + + /// + /// Get string representation of value and unit. Using two significant digits after radix. + /// + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName) + { + var provider = cultureName; + return ToString(provider, 2); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString(string cultureName, int significantDigitsAfterRadix) + { + var provider = cultureName; + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + /// Name of culture (ex: "en-US") to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] string cultureName, [NotNull] string format, [NotNull] params object[] args) + { + var provider = GetFormatProviderFromCultureName(cultureName); + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? GlobalConfiguration.DefaultCulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + #endregion + + private static IFormatProvider GetFormatProviderFromCultureName([CanBeNull] string cultureName) + { + return cultureName != null ? new CultureInfo(cultureName) : (IFormatProvider)null; + } + } +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Mass.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Mass.g.cs index b5c3b63a4c..b22f693205 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Mass.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantities/Mass.g.cs @@ -170,6 +170,11 @@ private Mass(double numericValue, MassUnit unit) /// public double Decigrams => As(MassUnit.Decigram); + /// + /// Get Mass in EarthMasses. + /// + public double EarthMasses => As(MassUnit.EarthMass); + /// /// Get Mass in Grains. /// @@ -260,6 +265,11 @@ private Mass(double numericValue, MassUnit unit) /// public double Slugs => As(MassUnit.Slug); + /// + /// Get Mass in SolarMasses. + /// + public double SolarMasses => As(MassUnit.SolarMass); + /// /// Get Mass in Stone. /// @@ -331,6 +341,16 @@ public static Mass FromDecigrams(double decigrams) return new Mass(value, MassUnit.Decigram); } /// + /// Get Mass from EarthMasses. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Mass FromEarthMasses(double earthmasses) + { + double value = (double) earthmasses; + return new Mass(value, MassUnit.EarthMass); + } + /// /// Get Mass from Grains. /// /// If value is NaN or Infinity. @@ -511,6 +531,16 @@ public static Mass FromSlugs(double slugs) return new Mass(value, MassUnit.Slug); } /// + /// Get Mass from SolarMasses. + /// + /// If value is NaN or Infinity. + [Windows.Foundation.Metadata.DefaultOverload] + public static Mass FromSolarMasses(double solarmasses) + { + double value = (double) solarmasses; + return new Mass(value, MassUnit.SolarMass); + } + /// /// Get Mass from Stone. /// /// If value is NaN or Infinity. @@ -824,6 +854,7 @@ private double AsBaseUnit() case MassUnit.Centigram: return (_value/1e3) * 1e-2d; case MassUnit.Decagram: return (_value/1e3) * 1e1d; case MassUnit.Decigram: return (_value/1e3) * 1e-1d; + case MassUnit.EarthMass: return _value * 5.9722E+24; case MassUnit.Grain: return _value/15432.358352941431; case MassUnit.Gram: return _value/1e3; case MassUnit.Hectogram: return (_value/1e3) * 1e2d; @@ -842,6 +873,7 @@ private double AsBaseUnit() case MassUnit.ShortHundredweight: return _value/0.022046226218487758; case MassUnit.ShortTon: return _value*9.0718474e2; case MassUnit.Slug: return _value/6.852176556196105e-2; + case MassUnit.SolarMass: return _value * 1.98947e30; case MassUnit.Stone: return _value/0.1574731728702698; case MassUnit.Tonne: return _value*1e3; default: @@ -861,6 +893,7 @@ private double AsBaseNumericType(MassUnit unit) case MassUnit.Centigram: return (baseUnitValue*1e3) / 1e-2d; case MassUnit.Decagram: return (baseUnitValue*1e3) / 1e1d; case MassUnit.Decigram: return (baseUnitValue*1e3) / 1e-1d; + case MassUnit.EarthMass: return baseUnitValue / 5.9722E+24; case MassUnit.Grain: return baseUnitValue*15432.358352941431; case MassUnit.Gram: return baseUnitValue*1e3; case MassUnit.Hectogram: return (baseUnitValue*1e3) / 1e2d; @@ -879,6 +912,7 @@ private double AsBaseNumericType(MassUnit unit) case MassUnit.ShortHundredweight: return baseUnitValue*0.022046226218487758; case MassUnit.ShortTon: return baseUnitValue/9.0718474e2; case MassUnit.Slug: return baseUnitValue*6.852176556196105e-2; + case MassUnit.SolarMass: return baseUnitValue / 1.98947e30; case MassUnit.Stone: return baseUnitValue*0.1574731728702698; case MassUnit.Tonne: return baseUnitValue/1e3; default: diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs index 7c78d3cc57..ed8d512991 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Quantity.g.cs @@ -188,6 +188,9 @@ internal static bool TryFrom(double value, Enum unit, out IQuantity quantity) case LinearDensityUnit linearDensityUnit: quantity = LinearDensity.From(value, linearDensityUnit); return true; + case LuminosityUnit luminosityUnit: + quantity = Luminosity.From(value, luminosityUnit); + return true; case LuminousFluxUnit luminousFluxUnit: quantity = LuminousFlux.From(value, luminousFluxUnit); return true; @@ -526,6 +529,9 @@ internal static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type q if (quantityType == typeof(LinearDensity)) return parser.TryParse(quantityString, formatProvider, LinearDensity.From, out quantity); + if (quantityType == typeof(Luminosity)) + return parser.TryParse(quantityString, formatProvider, Luminosity.From, out quantity); + if (quantityType == typeof(LuminousFlux)) return parser.TryParse(quantityString, formatProvider, LuminousFlux.From, out quantity); diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs index bf102c95d6..eb1c05724b 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/QuantityType.g.cs @@ -78,6 +78,7 @@ public enum QuantityType Length, Level, LinearDensity, + Luminosity, LuminousFlux, LuminousIntensity, MagneticField, diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs index d3575ccc79..5cc7e8e025 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -496,6 +496,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(KinematicViscosityUnit), (int)KinematicViscosityUnit.Stokes, new string[]{"St"}), ("ru-RU", typeof(KinematicViscosityUnit), (int)KinematicViscosityUnit.Stokes, new string[]{"Ст"}), ("en-US", typeof(LapseRateUnit), (int)LapseRateUnit.DegreeCelsiusPerKilometer, new string[]{"∆°C/km"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.AstronomicalUnit, new string[]{"au", "ua"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Centimeter, new string[]{"cm"}), ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Centimeter, new string[]{"см"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Decimeter, new string[]{"dm"}), @@ -510,8 +511,13 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Hectometer, new string[]{"гм"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Inch, new string[]{"in", "\"", "″"}), ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Inch, new string[]{"дюйм"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.KilolightYear, new string[]{"kly"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Kilometer, new string[]{"km"}), ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Kilometer, new string[]{"км"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.Kiloparsec, new string[]{"kpc"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.LightYear, new string[]{"ly"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.MegalightYear, new string[]{"Mly"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.Megaparsec, new string[]{"Mpc"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Meter, new string[]{"m"}), ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Meter, new string[]{"м"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Microinch, new string[]{"µin"}), @@ -528,6 +534,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Nanometer, new string[]{"нм"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.NauticalMile, new string[]{"NM"}), ("ru-RU", typeof(LengthUnit), (int)LengthUnit.NauticalMile, new string[]{"мил"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.Parsec, new string[]{"pc"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.PrinterPica, new string[]{"pica"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.PrinterPoint, new string[]{"pt"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Shackle, new string[]{"shackle"}), @@ -540,6 +547,20 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.GramPerMeter, new string[]{"g/m"}), ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.KilogramPerMeter, new string[]{"kg/m"}), ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.PoundPerFoot, new string[]{"lb/ft"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Decawatt, new string[]{"daW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Deciwatt, new string[]{"dW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Femtowatt, new string[]{"fW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Gigawatt, new string[]{"GW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Kilowatt, new string[]{"kW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Megawatt, new string[]{"MW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Microwatt, new string[]{"µW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Milliwatt, new string[]{"mW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Nanowatt, new string[]{"nW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Petawatt, new string[]{"PW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Picowatt, new string[]{"pW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.SolarLuminosity, new string[]{"L⊙"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Terawatt, new string[]{"TW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Watt, new string[]{"W"}), ("en-US", typeof(LuminousFluxUnit), (int)LuminousFluxUnit.Lumen, new string[]{"lm"}), ("en-US", typeof(LuminousIntensityUnit), (int)LuminousIntensityUnit.Candela, new string[]{"cd"}), ("en-US", typeof(MagneticFieldUnit), (int)MagneticFieldUnit.Microtesla, new string[]{"µT"}), @@ -554,6 +575,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("ru-RU", typeof(MassUnit), (int)MassUnit.Decagram, new string[]{"даг"}), ("en-US", typeof(MassUnit), (int)MassUnit.Decigram, new string[]{"dg"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.Decigram, new string[]{"дг"}), + ("en-US", typeof(MassUnit), (int)MassUnit.EarthMass, new string[]{"em"}), ("en-US", typeof(MassUnit), (int)MassUnit.Grain, new string[]{"gr"}), ("en-US", typeof(MassUnit), (int)MassUnit.Gram, new string[]{"g"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.Gram, new string[]{"г"}), @@ -585,6 +607,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassUnit), (int)MassUnit.ShortTon, new string[]{"short tn"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.ShortTon, new string[]{"тонна малая"}), ("en-US", typeof(MassUnit), (int)MassUnit.Slug, new string[]{"slug"}), + ("en-US", typeof(MassUnit), (int)MassUnit.SolarMass, new string[]{"M⊙"}), ("en-US", typeof(MassUnit), (int)MassUnit.Stone, new string[]{"st"}), ("en-US", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"t"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"т"}), diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LengthUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LengthUnit.g.cs index 9cdede7100..b8e05a1b47 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LengthUnit.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LengthUnit.g.cs @@ -26,6 +26,12 @@ namespace UnitsNet.Units public enum LengthUnit { Undefined = 0, + + /// + /// One Astronomical Unit is the distance from the solar system Star, the sun, to planet Earth. + /// + /// https://en.wikipedia.org/wiki/Astronomical_unit + AstronomicalUnit, Centimeter, Decimeter, DtpPica, @@ -35,7 +41,17 @@ public enum LengthUnit Hand, Hectometer, Inch, + KilolightYear, Kilometer, + Kiloparsec, + + /// + /// A Light Year (ly) is the distance that light travel during an Earth year, ie 365 days. + /// + /// https://en.wikipedia.org/wiki/Light-year + LightYear, + MegalightYear, + Megaparsec, Meter, Microinch, Micrometer, @@ -44,6 +60,12 @@ public enum LengthUnit Millimeter, Nanometer, NauticalMile, + + /// + /// A parsec is defined as the distance at which one astronomical unit (AU) subtends an angle of one arcsecond. + /// + /// https://en.wikipedia.org/wiki/Parsec + Parsec, PrinterPica, PrinterPoint, Shackle, diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LuminosityUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LuminosityUnit.g.cs new file mode 100644 index 0000000000..53bbdda773 --- /dev/null +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/LuminosityUnit.g.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum LuminosityUnit + { + Undefined = 0, + Decawatt, + Deciwatt, + Femtowatt, + Gigawatt, + Kilowatt, + Megawatt, + Microwatt, + Milliwatt, + Nanowatt, + Petawatt, + Picowatt, + /// https://www.britannica.com/science/luminosity + SolarLuminosity, + Terawatt, + Watt, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassUnit.g.cs b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassUnit.g.cs index d5f20ebe4b..790ab72fc3 100644 --- a/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassUnit.g.cs +++ b/UnitsNet.WindowsRuntimeComponent/GeneratedCode/Units/MassUnit.g.cs @@ -30,6 +30,12 @@ public enum MassUnit Decagram, Decigram, + /// + /// Earth mass is a ratio unit to the mass of planet Earth. + /// + /// https://en.wikipedia.org/wiki/Earth_mass + EarthMass, + /// /// A grain is a unit of measurement of mass, and in the troy weight, avoirdupois, and Apothecaries' system, equal to exactly 64.79891 milligrams. /// @@ -87,6 +93,12 @@ public enum MassUnit /// http://en.wikipedia.org/wiki/Slug_(unit) Slug, + /// + /// Solar mass is a ratio unit to the mass of the solar system star, the sun. + /// + /// https://en.wikipedia.org/wiki/Solar_mass + SolarMass, + /// /// The stone (abbreviation st) is a unit of mass equal to 14 pounds avoirdupois (about 6.35 kilograms) used in Great Britain and Ireland for measuring human body weight. /// diff --git a/UnitsNet/GeneratedCode/Quantities/Length.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.g.cs index 88edd9ca0e..e287982a11 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.g.cs @@ -50,6 +50,7 @@ static Length() Info = new QuantityInfo(QuantityType.Length, new UnitInfo[] { + new UnitInfo(LengthUnit.AstronomicalUnit, BaseUnits.Undefined), new UnitInfo(LengthUnit.Centimeter, BaseUnits.Undefined), new UnitInfo(LengthUnit.Decimeter, BaseUnits.Undefined), new UnitInfo(LengthUnit.DtpPica, new BaseUnits(length: LengthUnit.DtpPica)), @@ -59,7 +60,12 @@ static Length() new UnitInfo(LengthUnit.Hand, new BaseUnits(length: LengthUnit.Hand)), new UnitInfo(LengthUnit.Hectometer, BaseUnits.Undefined), new UnitInfo(LengthUnit.Inch, new BaseUnits(length: LengthUnit.Inch)), + new UnitInfo(LengthUnit.KilolightYear, BaseUnits.Undefined), new UnitInfo(LengthUnit.Kilometer, BaseUnits.Undefined), + new UnitInfo(LengthUnit.Kiloparsec, BaseUnits.Undefined), + new UnitInfo(LengthUnit.LightYear, BaseUnits.Undefined), + new UnitInfo(LengthUnit.MegalightYear, BaseUnits.Undefined), + new UnitInfo(LengthUnit.Megaparsec, BaseUnits.Undefined), new UnitInfo(LengthUnit.Meter, new BaseUnits(length: LengthUnit.Meter)), new UnitInfo(LengthUnit.Microinch, new BaseUnits(length: LengthUnit.Microinch)), new UnitInfo(LengthUnit.Micrometer, BaseUnits.Undefined), @@ -68,6 +74,7 @@ static Length() new UnitInfo(LengthUnit.Millimeter, BaseUnits.Undefined), new UnitInfo(LengthUnit.Nanometer, BaseUnits.Undefined), new UnitInfo(LengthUnit.NauticalMile, new BaseUnits(length: LengthUnit.NauticalMile)), + new UnitInfo(LengthUnit.Parsec, BaseUnits.Undefined), new UnitInfo(LengthUnit.PrinterPica, new BaseUnits(length: LengthUnit.PrinterPica)), new UnitInfo(LengthUnit.PrinterPoint, new BaseUnits(length: LengthUnit.PrinterPoint)), new UnitInfo(LengthUnit.Shackle, new BaseUnits(length: LengthUnit.Shackle)), @@ -186,6 +193,11 @@ public Length(double numericValue, UnitSystem unitSystem) #region Conversion Properties + /// + /// Get Length in AstronomicalUnits. + /// + public double AstronomicalUnits => As(LengthUnit.AstronomicalUnit); + /// /// Get Length in Centimeters. /// @@ -231,11 +243,36 @@ public Length(double numericValue, UnitSystem unitSystem) /// public double Inches => As(LengthUnit.Inch); + /// + /// Get Length in KilolightYears. + /// + public double KilolightYears => As(LengthUnit.KilolightYear); + /// /// Get Length in Kilometers. /// public double Kilometers => As(LengthUnit.Kilometer); + /// + /// Get Length in Kiloparsecs. + /// + public double Kiloparsecs => As(LengthUnit.Kiloparsec); + + /// + /// Get Length in LightYears. + /// + public double LightYears => As(LengthUnit.LightYear); + + /// + /// Get Length in MegalightYears. + /// + public double MegalightYears => As(LengthUnit.MegalightYear); + + /// + /// Get Length in Megaparsecs. + /// + public double Megaparsecs => As(LengthUnit.Megaparsec); + /// /// Get Length in Meters. /// @@ -276,6 +313,11 @@ public Length(double numericValue, UnitSystem unitSystem) /// public double NauticalMiles => As(LengthUnit.NauticalMile); + /// + /// Get Length in Parsecs. + /// + public double Parsecs => As(LengthUnit.Parsec); + /// /// Get Length in PrinterPicas. /// @@ -335,6 +377,15 @@ public static string GetAbbreviation(LengthUnit unit, [CanBeNull] IFormatProvide #region Static Factory Methods + /// + /// Get Length from AstronomicalUnits. + /// + /// If value is NaN or Infinity. + public static Length FromAstronomicalUnits(QuantityValue astronomicalunits) + { + double value = (double) astronomicalunits; + return new Length(value, LengthUnit.AstronomicalUnit); + } /// /// Get Length from Centimeters. /// @@ -417,6 +468,15 @@ public static Length FromInches(QuantityValue inches) return new Length(value, LengthUnit.Inch); } /// + /// Get Length from KilolightYears. + /// + /// If value is NaN or Infinity. + public static Length FromKilolightYears(QuantityValue kilolightyears) + { + double value = (double) kilolightyears; + return new Length(value, LengthUnit.KilolightYear); + } + /// /// Get Length from Kilometers. /// /// If value is NaN or Infinity. @@ -426,6 +486,42 @@ public static Length FromKilometers(QuantityValue kilometers) return new Length(value, LengthUnit.Kilometer); } /// + /// Get Length from Kiloparsecs. + /// + /// If value is NaN or Infinity. + public static Length FromKiloparsecs(QuantityValue kiloparsecs) + { + double value = (double) kiloparsecs; + return new Length(value, LengthUnit.Kiloparsec); + } + /// + /// Get Length from LightYears. + /// + /// If value is NaN or Infinity. + public static Length FromLightYears(QuantityValue lightyears) + { + double value = (double) lightyears; + return new Length(value, LengthUnit.LightYear); + } + /// + /// Get Length from MegalightYears. + /// + /// If value is NaN or Infinity. + public static Length FromMegalightYears(QuantityValue megalightyears) + { + double value = (double) megalightyears; + return new Length(value, LengthUnit.MegalightYear); + } + /// + /// Get Length from Megaparsecs. + /// + /// If value is NaN or Infinity. + public static Length FromMegaparsecs(QuantityValue megaparsecs) + { + double value = (double) megaparsecs; + return new Length(value, LengthUnit.Megaparsec); + } + /// /// Get Length from Meters. /// /// If value is NaN or Infinity. @@ -498,6 +594,15 @@ public static Length FromNauticalMiles(QuantityValue nauticalmiles) return new Length(value, LengthUnit.NauticalMile); } /// + /// Get Length from Parsecs. + /// + /// If value is NaN or Infinity. + public static Length FromParsecs(QuantityValue parsecs) + { + double value = (double) parsecs; + return new Length(value, LengthUnit.Parsec); + } + /// /// Get Length from PrinterPicas. /// /// If value is NaN or Infinity. @@ -980,6 +1085,7 @@ private double GetValueInBaseUnit() { switch(Unit) { + case LengthUnit.AstronomicalUnit: return _value * 1.4959787070e11; case LengthUnit.Centimeter: return (_value) * 1e-2d; case LengthUnit.Decimeter: return (_value) * 1e-1d; case LengthUnit.DtpPica: return _value/236.220472441; @@ -989,7 +1095,12 @@ private double GetValueInBaseUnit() case LengthUnit.Hand: return _value * 1.016e-1; case LengthUnit.Hectometer: return (_value) * 1e2d; case LengthUnit.Inch: return _value*2.54e-2; + case LengthUnit.KilolightYear: return (_value * 9.46073047258e15) * 1e3d; case LengthUnit.Kilometer: return (_value) * 1e3d; + case LengthUnit.Kiloparsec: return (_value * 3.08567758128e16) * 1e3d; + case LengthUnit.LightYear: return _value * 9.46073047258e15; + case LengthUnit.MegalightYear: return (_value * 9.46073047258e15) * 1e6d; + case LengthUnit.Megaparsec: return (_value * 3.08567758128e16) * 1e6d; case LengthUnit.Meter: return _value; case LengthUnit.Microinch: return _value*2.54e-8; case LengthUnit.Micrometer: return (_value) * 1e-6d; @@ -998,6 +1109,7 @@ private double GetValueInBaseUnit() case LengthUnit.Millimeter: return (_value) * 1e-3d; case LengthUnit.Nanometer: return (_value) * 1e-9d; case LengthUnit.NauticalMile: return _value*1852; + case LengthUnit.Parsec: return _value * 3.08567758128e16; case LengthUnit.PrinterPica: return _value/237.106301584; case LengthUnit.PrinterPoint: return (_value/72.27)*2.54e-2; case LengthUnit.Shackle: return _value*27.432; @@ -1029,6 +1141,7 @@ private double GetValueAs(LengthUnit unit) switch(unit) { + case LengthUnit.AstronomicalUnit: return baseUnitValue / 1.4959787070e11; case LengthUnit.Centimeter: return (baseUnitValue) / 1e-2d; case LengthUnit.Decimeter: return (baseUnitValue) / 1e-1d; case LengthUnit.DtpPica: return baseUnitValue*236.220472441; @@ -1038,7 +1151,12 @@ private double GetValueAs(LengthUnit unit) case LengthUnit.Hand: return baseUnitValue / 1.016e-1; case LengthUnit.Hectometer: return (baseUnitValue) / 1e2d; case LengthUnit.Inch: return baseUnitValue/2.54e-2; + case LengthUnit.KilolightYear: return (baseUnitValue / 9.46073047258e15) / 1e3d; case LengthUnit.Kilometer: return (baseUnitValue) / 1e3d; + case LengthUnit.Kiloparsec: return (baseUnitValue / 3.08567758128e16) / 1e3d; + case LengthUnit.LightYear: return baseUnitValue / 9.46073047258e15; + case LengthUnit.MegalightYear: return (baseUnitValue / 9.46073047258e15) / 1e6d; + case LengthUnit.Megaparsec: return (baseUnitValue / 3.08567758128e16) / 1e6d; case LengthUnit.Meter: return baseUnitValue; case LengthUnit.Microinch: return baseUnitValue/2.54e-8; case LengthUnit.Micrometer: return (baseUnitValue) / 1e-6d; @@ -1047,6 +1165,7 @@ private double GetValueAs(LengthUnit unit) case LengthUnit.Millimeter: return (baseUnitValue) / 1e-3d; case LengthUnit.Nanometer: return (baseUnitValue) / 1e-9d; case LengthUnit.NauticalMile: return baseUnitValue/1852; + case LengthUnit.Parsec: return baseUnitValue / 3.08567758128e16; case LengthUnit.PrinterPica: return baseUnitValue*237.106301584; case LengthUnit.PrinterPoint: return (baseUnitValue/2.54e-2)*72.27; case LengthUnit.Shackle: return baseUnitValue/27.432; diff --git a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs new file mode 100644 index 0000000000..e518ddf5b7 --- /dev/null +++ b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs @@ -0,0 +1,1074 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Globalization; +using System.Linq; +using JetBrains.Annotations; +using UnitsNet.InternalHelpers; +using UnitsNet.Units; + +// ReSharper disable once CheckNamespace + +namespace UnitsNet +{ + /// + /// + /// Luminosity is an absolute measure of radiated electromagnetic power (light), the radiant power emitted by a light-emitting object. + /// + /// + /// https://en.wikipedia.org/wiki/Luminosity + /// + public partial struct Luminosity : IQuantity, IEquatable, IComparable, IComparable, IConvertible, IFormattable + { + /// + /// The numeric value this quantity was constructed with. + /// + private readonly double _value; + + /// + /// The unit this quantity was constructed with. + /// + private readonly LuminosityUnit? _unit; + + static Luminosity() + { + BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); + + Info = new QuantityInfo(QuantityType.Luminosity, + new UnitInfo[] { + new UnitInfo(LuminosityUnit.Decawatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Deciwatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Femtowatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Gigawatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Kilowatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Megawatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Microwatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Milliwatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Nanowatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Petawatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Picowatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.SolarLuminosity, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Terawatt, BaseUnits.Undefined), + new UnitInfo(LuminosityUnit.Watt, BaseUnits.Undefined), + }, + BaseUnit, Zero, BaseDimensions); + } + + /// + /// Creates the quantity with the given numeric value and unit. + /// + /// The numeric value to contruct this quantity with. + /// The unit representation to contruct this quantity with. + /// If value is NaN or Infinity. + public Luminosity(double numericValue, LuminosityUnit unit) + { + if(unit == LuminosityUnit.Undefined) + throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit)); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = unit; + } + + /// + /// Creates an instance of the quantity with the given numeric value in units compatible with the given . + /// If multiple compatible units were found, the first match is used. + /// + /// The numeric value to contruct this quantity with. + /// The unit system to create the quantity with. + /// The given is null. + /// No unit was found for the given . + public Luminosity(double numericValue, UnitSystem unitSystem) + { + if(unitSystem == null) throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + var firstUnitInfo = unitInfos.FirstOrDefault(); + + _value = Guard.EnsureValidNumber(numericValue, nameof(numericValue)); + _unit = firstUnitInfo?.Value ?? throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + } + + #region Static Properties + + /// + public static QuantityInfo Info { get; } + + /// + /// The of this quantity. + /// + public static BaseDimensions BaseDimensions { get; } + + /// + /// The base unit of Luminosity, which is Watt. All conversions go via this value. + /// + public static LuminosityUnit BaseUnit { get; } = LuminosityUnit.Watt; + + /// + /// Represents the largest possible value of Luminosity + /// + public static Luminosity MaxValue { get; } = new Luminosity(double.MaxValue, BaseUnit); + + /// + /// Represents the smallest possible value of Luminosity + /// + public static Luminosity MinValue { get; } = new Luminosity(double.MinValue, BaseUnit); + + /// + /// The of this quantity. + /// + public static QuantityType QuantityType { get; } = QuantityType.Luminosity; + + /// + /// All units of measurement for the Luminosity quantity. + /// + public static LuminosityUnit[] Units { get; } = Enum.GetValues(typeof(LuminosityUnit)).Cast().Except(new LuminosityUnit[]{ LuminosityUnit.Undefined }).ToArray(); + + /// + /// Gets an instance of this quantity with a value of 0 in the base unit Watt. + /// + public static Luminosity Zero { get; } = new Luminosity(0, BaseUnit); + + #endregion + + #region Properties + + /// + /// The numeric value this quantity was constructed with. + /// + public double Value => _value; + + Enum IQuantity.Unit => Unit; + + /// + public LuminosityUnit Unit => _unit.GetValueOrDefault(BaseUnit); + + /// + public QuantityInfo QuantityInfo => Info; + + /// + QuantityInfo IQuantity.QuantityInfo => Info; + + /// + /// The of this quantity. + /// + public QuantityType Type => Luminosity.QuantityType; + + /// + /// The of this quantity. + /// + public BaseDimensions Dimensions => Luminosity.BaseDimensions; + + #endregion + + #region Conversion Properties + + /// + /// Get Luminosity in Decawatts. + /// + public double Decawatts => As(LuminosityUnit.Decawatt); + + /// + /// Get Luminosity in Deciwatts. + /// + public double Deciwatts => As(LuminosityUnit.Deciwatt); + + /// + /// Get Luminosity in Femtowatts. + /// + public double Femtowatts => As(LuminosityUnit.Femtowatt); + + /// + /// Get Luminosity in Gigawatts. + /// + public double Gigawatts => As(LuminosityUnit.Gigawatt); + + /// + /// Get Luminosity in Kilowatts. + /// + public double Kilowatts => As(LuminosityUnit.Kilowatt); + + /// + /// Get Luminosity in Megawatts. + /// + public double Megawatts => As(LuminosityUnit.Megawatt); + + /// + /// Get Luminosity in Microwatts. + /// + public double Microwatts => As(LuminosityUnit.Microwatt); + + /// + /// Get Luminosity in Milliwatts. + /// + public double Milliwatts => As(LuminosityUnit.Milliwatt); + + /// + /// Get Luminosity in Nanowatts. + /// + public double Nanowatts => As(LuminosityUnit.Nanowatt); + + /// + /// Get Luminosity in Petawatts. + /// + public double Petawatts => As(LuminosityUnit.Petawatt); + + /// + /// Get Luminosity in Picowatts. + /// + public double Picowatts => As(LuminosityUnit.Picowatt); + + /// + /// Get Luminosity in SolarLuminosities. + /// + public double SolarLuminosities => As(LuminosityUnit.SolarLuminosity); + + /// + /// Get Luminosity in Terawatts. + /// + public double Terawatts => As(LuminosityUnit.Terawatt); + + /// + /// Get Luminosity in Watts. + /// + public double Watts => As(LuminosityUnit.Watt); + + #endregion + + #region Static Methods + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + public static string GetAbbreviation(LuminosityUnit unit) + { + return GetAbbreviation(unit, null); + } + + /// + /// Get unit abbreviation string. + /// + /// Unit to get abbreviation for. + /// Unit abbreviation string. + /// Format to use for localization. Defaults to if null. + public static string GetAbbreviation(LuminosityUnit unit, [CanBeNull] IFormatProvider provider) + { + return UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider); + } + + #endregion + + #region Static Factory Methods + + /// + /// Get Luminosity from Decawatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromDecawatts(QuantityValue decawatts) + { + double value = (double) decawatts; + return new Luminosity(value, LuminosityUnit.Decawatt); + } + /// + /// Get Luminosity from Deciwatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromDeciwatts(QuantityValue deciwatts) + { + double value = (double) deciwatts; + return new Luminosity(value, LuminosityUnit.Deciwatt); + } + /// + /// Get Luminosity from Femtowatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromFemtowatts(QuantityValue femtowatts) + { + double value = (double) femtowatts; + return new Luminosity(value, LuminosityUnit.Femtowatt); + } + /// + /// Get Luminosity from Gigawatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromGigawatts(QuantityValue gigawatts) + { + double value = (double) gigawatts; + return new Luminosity(value, LuminosityUnit.Gigawatt); + } + /// + /// Get Luminosity from Kilowatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromKilowatts(QuantityValue kilowatts) + { + double value = (double) kilowatts; + return new Luminosity(value, LuminosityUnit.Kilowatt); + } + /// + /// Get Luminosity from Megawatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromMegawatts(QuantityValue megawatts) + { + double value = (double) megawatts; + return new Luminosity(value, LuminosityUnit.Megawatt); + } + /// + /// Get Luminosity from Microwatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromMicrowatts(QuantityValue microwatts) + { + double value = (double) microwatts; + return new Luminosity(value, LuminosityUnit.Microwatt); + } + /// + /// Get Luminosity from Milliwatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromMilliwatts(QuantityValue milliwatts) + { + double value = (double) milliwatts; + return new Luminosity(value, LuminosityUnit.Milliwatt); + } + /// + /// Get Luminosity from Nanowatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromNanowatts(QuantityValue nanowatts) + { + double value = (double) nanowatts; + return new Luminosity(value, LuminosityUnit.Nanowatt); + } + /// + /// Get Luminosity from Petawatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromPetawatts(QuantityValue petawatts) + { + double value = (double) petawatts; + return new Luminosity(value, LuminosityUnit.Petawatt); + } + /// + /// Get Luminosity from Picowatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromPicowatts(QuantityValue picowatts) + { + double value = (double) picowatts; + return new Luminosity(value, LuminosityUnit.Picowatt); + } + /// + /// Get Luminosity from SolarLuminosities. + /// + /// If value is NaN or Infinity. + public static Luminosity FromSolarLuminosities(QuantityValue solarluminosities) + { + double value = (double) solarluminosities; + return new Luminosity(value, LuminosityUnit.SolarLuminosity); + } + /// + /// Get Luminosity from Terawatts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromTerawatts(QuantityValue terawatts) + { + double value = (double) terawatts; + return new Luminosity(value, LuminosityUnit.Terawatt); + } + /// + /// Get Luminosity from Watts. + /// + /// If value is NaN or Infinity. + public static Luminosity FromWatts(QuantityValue watts) + { + double value = (double) watts; + return new Luminosity(value, LuminosityUnit.Watt); + } + + /// + /// Dynamically convert from value and unit enum to . + /// + /// Value to convert from. + /// Unit to convert from. + /// Luminosity unit value. + public static Luminosity From(QuantityValue value, LuminosityUnit fromUnit) + { + return new Luminosity((double)value, fromUnit); + } + + #endregion + + #region Static Parse Methods + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + public static Luminosity Parse(string str) + { + return Parse(str, null); + } + + /// + /// Parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// + /// Expected string to have one or two pairs of quantity and unit in the format + /// "<quantity> <unit>". Eg. "5.5 m" or "1ft 2in" + /// + /// + /// More than one unit is represented by the specified unit abbreviation. + /// Example: Volume.Parse("1 cup") will throw, because it can refer to any of + /// , and . + /// + /// + /// If anything else goes wrong, typically due to a bug or unhandled case. + /// We wrap exceptions in to allow you to distinguish + /// Units.NET exceptions from other exceptions. + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static Luminosity Parse(string str, [CanBeNull] IFormatProvider provider) + { + return QuantityParser.Default.Parse( + str, + provider, + From); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + public static bool TryParse([CanBeNull] string str, out Luminosity result) + { + return TryParse(str, null, out result); + } + + /// + /// Try to parse a string with one or two quantities of the format "<quantity> <unit>". + /// + /// String to parse. Typically in the form: {number} {unit} + /// Resulting unit quantity if successful. + /// True if successful, otherwise false. + /// + /// Length.Parse("5.5 m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParse([CanBeNull] string str, [CanBeNull] IFormatProvider provider, out Luminosity result) + { + return QuantityParser.Default.TryParse( + str, + provider, + From, + out result); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + public static LuminosityUnit ParseUnit(string str) + { + return ParseUnit(str, null); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// + /// Length.ParseUnit("m", new CultureInfo("en-US")); + /// + /// The value of 'str' cannot be null. + /// Error parsing string. + /// Format to use when parsing number and unit. Defaults to if null. + public static LuminosityUnit ParseUnit(string str, IFormatProvider provider = null) + { + return UnitParser.Default.Parse(str, provider); + } + + /// + public static bool TryParseUnit(string str, out LuminosityUnit unit) + { + return TryParseUnit(str, null, out unit); + } + + /// + /// Parse a unit string. + /// + /// String to parse. Typically in the form: {number} {unit} + /// The parsed unit if successful. + /// True if successful, otherwise false. + /// + /// Length.TryParseUnit("m", new CultureInfo("en-US")); + /// + /// Format to use when parsing number and unit. Defaults to if null. + public static bool TryParseUnit(string str, IFormatProvider provider, out LuminosityUnit unit) + { + return UnitParser.Default.TryParse(str, provider, out unit); + } + + #endregion + + #region Arithmetic Operators + + /// Negate the value. + public static Luminosity operator -(Luminosity right) + { + return new Luminosity(-right.Value, right.Unit); + } + + /// Get from adding two . + public static Luminosity operator +(Luminosity left, Luminosity right) + { + return new Luminosity(left.Value + right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from subtracting two . + public static Luminosity operator -(Luminosity left, Luminosity right) + { + return new Luminosity(left.Value - right.GetValueAs(left.Unit), left.Unit); + } + + /// Get from multiplying value and . + public static Luminosity operator *(double left, Luminosity right) + { + return new Luminosity(left * right.Value, right.Unit); + } + + /// Get from multiplying value and . + public static Luminosity operator *(Luminosity left, double right) + { + return new Luminosity(left.Value * right, left.Unit); + } + + /// Get from dividing by value. + public static Luminosity operator /(Luminosity left, double right) + { + return new Luminosity(left.Value / right, left.Unit); + } + + /// Get ratio value from dividing by . + public static double operator /(Luminosity left, Luminosity right) + { + return left.Watts / right.Watts; + } + + #endregion + + #region Equality / IComparable + + /// Returns true if less or equal to. + public static bool operator <=(Luminosity left, Luminosity right) + { + return left.Value <= right.GetValueAs(left.Unit); + } + + /// Returns true if greater than or equal to. + public static bool operator >=(Luminosity left, Luminosity right) + { + return left.Value >= right.GetValueAs(left.Unit); + } + + /// Returns true if less than. + public static bool operator <(Luminosity left, Luminosity right) + { + return left.Value < right.GetValueAs(left.Unit); + } + + /// Returns true if greater than. + public static bool operator >(Luminosity left, Luminosity right) + { + return left.Value > right.GetValueAs(left.Unit); + } + + /// Returns true if exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator ==(Luminosity left, Luminosity right) + { + return left.Equals(right); + } + + /// Returns true if not exactly equal. + /// Consider using for safely comparing floating point values. + public static bool operator !=(Luminosity left, Luminosity right) + { + return !(left == right); + } + + /// + public int CompareTo(object obj) + { + if(obj is null) throw new ArgumentNullException(nameof(obj)); + if(!(obj is Luminosity objLuminosity)) throw new ArgumentException("Expected type Luminosity.", nameof(obj)); + + return CompareTo(objLuminosity); + } + + /// + public int CompareTo(Luminosity other) + { + return _value.CompareTo(other.GetValueAs(this.Unit)); + } + + /// + /// Consider using for safely comparing floating point values. + public override bool Equals(object obj) + { + if(obj is null || !(obj is Luminosity objLuminosity)) + return false; + + return Equals(objLuminosity); + } + + /// + /// Consider using for safely comparing floating point values. + public bool Equals(Luminosity other) + { + return _value.Equals(other.GetValueAs(this.Unit)); + } + + /// + /// + /// Compare equality to another Luminosity within the given absolute or relative tolerance. + /// + /// + /// Relative tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a percentage of this quantity's value. will be converted into + /// this quantity's unit for comparison. A relative tolerance of 0.01 means the absolute difference must be within +/- 1% of + /// this quantity's value to be considered equal. + /// + /// In this example, the two quantities will be equal if the value of b is within +/- 1% of a (0.02m or 2cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Relative); + /// + /// + /// + /// + /// Absolute tolerance is defined as the maximum allowable absolute difference between this quantity's value and + /// as a fixed number in this quantity's unit. will be converted into + /// this quantity's unit for comparison. + /// + /// In this example, the two quantities will be equal if the value of b is within 0.01 of a (0.01m or 1cm). + /// + /// var a = Length.FromMeters(2.0); + /// var b = Length.FromInches(50.0); + /// a.Equals(b, 0.01, ComparisonType.Absolute); + /// + /// + /// + /// + /// Note that it is advised against specifying zero difference, due to the nature + /// of floating point operations and using System.Double internally. + /// + /// + /// The other quantity to compare to. + /// The absolute or relative tolerance value. Must be greater than or equal to 0. + /// The comparison type: either relative or absolute. + /// True if the absolute difference between the two values is not greater than the specified relative or absolute tolerance. + public bool Equals(Luminosity other, double tolerance, ComparisonType comparisonType) + { + if(tolerance < 0) + throw new ArgumentOutOfRangeException("tolerance", "Tolerance must be greater than or equal to 0."); + + double thisValue = (double)this.Value; + double otherValueInThisUnits = other.As(this.Unit); + + return UnitsNet.Comparison.Equals(thisValue, otherValueInThisUnits, tolerance, comparisonType); + } + + /// + /// Returns the hash code for this instance. + /// + /// A hash code for the current Luminosity. + public override int GetHashCode() + { + return new { QuantityType, Value, Unit }.GetHashCode(); + } + + #endregion + + #region Conversion Methods + + /// + /// Convert to the unit representation . + /// + /// Value converted to the specified unit. + public double As(LuminosityUnit unit) + { + if(Unit == unit) + return Convert.ToDouble(Value); + + var converted = GetValueAs(unit); + return Convert.ToDouble(converted); + } + + /// + public double As(UnitSystem unitSystem) + { + if(unitSystem == null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return As(firstUnitInfo.Value); + } + + /// + double IQuantity.As(Enum unit) + { + if(!(unit is LuminosityUnit unitAsLuminosityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminosityUnit)} is supported.", nameof(unit)); + + return As(unitAsLuminosityUnit); + } + + /// + /// Converts this Luminosity to another Luminosity with the unit representation . + /// + /// A Luminosity with the specified unit. + public Luminosity ToUnit(LuminosityUnit unit) + { + var convertedValue = GetValueAs(unit); + return new Luminosity(convertedValue, unit); + } + + /// + IQuantity IQuantity.ToUnit(Enum unit) + { + if(!(unit is LuminosityUnit unitAsLuminosityUnit)) + throw new ArgumentException($"The given unit is of type {unit.GetType()}. Only {typeof(LuminosityUnit)} is supported.", nameof(unit)); + + return ToUnit(unitAsLuminosityUnit); + } + + /// + public Luminosity ToUnit(UnitSystem unitSystem) + { + if(unitSystem == null) + throw new ArgumentNullException(nameof(unitSystem)); + + var unitInfos = Info.GetUnitInfosFor(unitSystem.BaseUnits); + + var firstUnitInfo = unitInfos.FirstOrDefault(); + if(firstUnitInfo == null) + throw new ArgumentException("No units were found for the given UnitSystem.", nameof(unitSystem)); + + return ToUnit(firstUnitInfo.Value); + } + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + IQuantity IQuantity.ToUnit(LuminosityUnit unit) => ToUnit(unit); + + /// + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) => ToUnit(unitSystem); + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + private double GetValueInBaseUnit() + { + switch(Unit) + { + case LuminosityUnit.Decawatt: return (_value) * 1e1d; + case LuminosityUnit.Deciwatt: return (_value) * 1e-1d; + case LuminosityUnit.Femtowatt: return (_value) * 1e-15d; + case LuminosityUnit.Gigawatt: return (_value) * 1e9d; + case LuminosityUnit.Kilowatt: return (_value) * 1e3d; + case LuminosityUnit.Megawatt: return (_value) * 1e6d; + case LuminosityUnit.Microwatt: return (_value) * 1e-6d; + case LuminosityUnit.Milliwatt: return (_value) * 1e-3d; + case LuminosityUnit.Nanowatt: return (_value) * 1e-9d; + case LuminosityUnit.Petawatt: return (_value) * 1e15d; + case LuminosityUnit.Picowatt: return (_value) * 1e-12d; + case LuminosityUnit.SolarLuminosity: return _value * 3.846e26; + case LuminosityUnit.Terawatt: return (_value) * 1e12d; + case LuminosityUnit.Watt: return _value; + default: + throw new NotImplementedException($"Can not convert {Unit} to base units."); + } + } + + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + internal Luminosity ToBaseUnit() + { + var baseUnitValue = GetValueInBaseUnit(); + return new Luminosity(baseUnitValue, BaseUnit); + } + + private double GetValueAs(LuminosityUnit unit) + { + if(Unit == unit) + return _value; + + var baseUnitValue = GetValueInBaseUnit(); + + switch(unit) + { + case LuminosityUnit.Decawatt: return (baseUnitValue) / 1e1d; + case LuminosityUnit.Deciwatt: return (baseUnitValue) / 1e-1d; + case LuminosityUnit.Femtowatt: return (baseUnitValue) / 1e-15d; + case LuminosityUnit.Gigawatt: return (baseUnitValue) / 1e9d; + case LuminosityUnit.Kilowatt: return (baseUnitValue) / 1e3d; + case LuminosityUnit.Megawatt: return (baseUnitValue) / 1e6d; + case LuminosityUnit.Microwatt: return (baseUnitValue) / 1e-6d; + case LuminosityUnit.Milliwatt: return (baseUnitValue) / 1e-3d; + case LuminosityUnit.Nanowatt: return (baseUnitValue) / 1e-9d; + case LuminosityUnit.Petawatt: return (baseUnitValue) / 1e15d; + case LuminosityUnit.Picowatt: return (baseUnitValue) / 1e-12d; + case LuminosityUnit.SolarLuminosity: return baseUnitValue / 3.846e26; + case LuminosityUnit.Terawatt: return (baseUnitValue) / 1e12d; + case LuminosityUnit.Watt: return baseUnitValue; + default: + throw new NotImplementedException($"Can not convert {Unit} to {unit}."); + } + } + + #endregion + + #region ToString Methods + + /// + /// Gets the default string representation of value and unit. + /// + /// String representation. + public override string ToString() + { + return ToString("g"); + } + + /// + /// Gets the default string representation of value and unit using the given format provider. + /// + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + public string ToString([CanBeNull] IFormatProvider provider) + { + return ToString("g", provider); + } + + /// + /// Get string representation of value and unit. + /// + /// The number of significant digits after the radix point. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete(@"This method is deprecated and will be removed at a future release. Please use ToString(""s2"") or ToString(""s2"", provider) where 2 is an example of the number passed to significantDigitsAfterRadix.")] + public string ToString([CanBeNull] IFormatProvider provider, int significantDigitsAfterRadix) + { + var value = Convert.ToDouble(Value); + var format = UnitFormatter.GetFormat(value, significantDigitsAfterRadix); + return ToString(provider, format); + } + + /// + /// Get string representation of value and unit. + /// + /// String format to use. Default: "{0:0.##} {1} for value and unit abbreviation respectively." + /// Arguments for string format. Value and unit are implictly included as arguments 0 and 1. + /// String representation. + /// Format to use for localization and number formatting. Defaults to if null. + [Obsolete("This method is deprecated and will be removed at a future release. Please use string.Format().")] + public string ToString([CanBeNull] IFormatProvider provider, [NotNull] string format, [NotNull] params object[] args) + { + if (format == null) throw new ArgumentNullException(nameof(format)); + if (args == null) throw new ArgumentNullException(nameof(args)); + + provider = provider ?? CultureInfo.CurrentUICulture; + + var value = Convert.ToDouble(Value); + var formatArgs = UnitFormatter.GetFormatArgs(Unit, value, provider, args); + return string.Format(provider, format, formatArgs); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using . + /// + /// The format string. + /// The string representation. + public string ToString(string format) + { + return ToString(format, CultureInfo.CurrentUICulture); + } + + /// + /// + /// Gets the string representation of this instance in the specified format string using the specified format provider, or if null. + /// + /// The format string. + /// Format to use for localization and number formatting. Defaults to if null. + /// The string representation. + public string ToString(string format, IFormatProvider formatProvider) + { + return QuantityFormatter.Format(this, format, formatProvider); + } + + #endregion + + #region IConvertible Methods + + TypeCode IConvertible.GetTypeCode() + { + return TypeCode.Object; + } + + bool IConvertible.ToBoolean(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(Luminosity)} to bool is not supported."); + } + + byte IConvertible.ToByte(IFormatProvider provider) + { + return Convert.ToByte(_value); + } + + char IConvertible.ToChar(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(Luminosity)} to char is not supported."); + } + + DateTime IConvertible.ToDateTime(IFormatProvider provider) + { + throw new InvalidCastException($"Converting {typeof(Luminosity)} to DateTime is not supported."); + } + + decimal IConvertible.ToDecimal(IFormatProvider provider) + { + return Convert.ToDecimal(_value); + } + + double IConvertible.ToDouble(IFormatProvider provider) + { + return Convert.ToDouble(_value); + } + + short IConvertible.ToInt16(IFormatProvider provider) + { + return Convert.ToInt16(_value); + } + + int IConvertible.ToInt32(IFormatProvider provider) + { + return Convert.ToInt32(_value); + } + + long IConvertible.ToInt64(IFormatProvider provider) + { + return Convert.ToInt64(_value); + } + + sbyte IConvertible.ToSByte(IFormatProvider provider) + { + return Convert.ToSByte(_value); + } + + float IConvertible.ToSingle(IFormatProvider provider) + { + return Convert.ToSingle(_value); + } + + string IConvertible.ToString(IFormatProvider provider) + { + return ToString("g", provider); + } + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) + { + if(conversionType == typeof(Luminosity)) + return this; + else if(conversionType == typeof(LuminosityUnit)) + return Unit; + else if(conversionType == typeof(QuantityType)) + return Luminosity.QuantityType; + else if(conversionType == typeof(BaseDimensions)) + return Luminosity.BaseDimensions; + else + throw new InvalidCastException($"Converting {typeof(Luminosity)} to {conversionType} is not supported."); + } + + ushort IConvertible.ToUInt16(IFormatProvider provider) + { + return Convert.ToUInt16(_value); + } + + uint IConvertible.ToUInt32(IFormatProvider provider) + { + return Convert.ToUInt32(_value); + } + + ulong IConvertible.ToUInt64(IFormatProvider provider) + { + return Convert.ToUInt64(_value); + } + + #endregion + } +} diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs index 20462e281f..f6545d9ecd 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs @@ -53,6 +53,7 @@ static Mass() new UnitInfo(MassUnit.Centigram, BaseUnits.Undefined), new UnitInfo(MassUnit.Decagram, BaseUnits.Undefined), new UnitInfo(MassUnit.Decigram, BaseUnits.Undefined), + new UnitInfo(MassUnit.EarthMass, new BaseUnits(mass: MassUnit.EarthMass)), new UnitInfo(MassUnit.Grain, new BaseUnits(mass: MassUnit.Grain)), new UnitInfo(MassUnit.Gram, new BaseUnits(mass: MassUnit.Gram)), new UnitInfo(MassUnit.Hectogram, BaseUnits.Undefined), @@ -71,6 +72,7 @@ static Mass() new UnitInfo(MassUnit.ShortHundredweight, new BaseUnits(mass: MassUnit.ShortHundredweight)), new UnitInfo(MassUnit.ShortTon, new BaseUnits(mass: MassUnit.ShortTon)), new UnitInfo(MassUnit.Slug, new BaseUnits(mass: MassUnit.Slug)), + new UnitInfo(MassUnit.SolarMass, new BaseUnits(mass: MassUnit.SolarMass)), new UnitInfo(MassUnit.Stone, new BaseUnits(mass: MassUnit.Stone)), new UnitInfo(MassUnit.Tonne, new BaseUnits(mass: MassUnit.Tonne)), }, @@ -200,6 +202,11 @@ public Mass(double numericValue, UnitSystem unitSystem) /// public double Decigrams => As(MassUnit.Decigram); + /// + /// Get Mass in EarthMasses. + /// + public double EarthMasses => As(MassUnit.EarthMass); + /// /// Get Mass in Grains. /// @@ -290,6 +297,11 @@ public Mass(double numericValue, UnitSystem unitSystem) /// public double Slugs => As(MassUnit.Slug); + /// + /// Get Mass in SolarMasses. + /// + public double SolarMasses => As(MassUnit.SolarMass); + /// /// Get Mass in Stone. /// @@ -357,6 +369,15 @@ public static Mass FromDecigrams(QuantityValue decigrams) return new Mass(value, MassUnit.Decigram); } /// + /// Get Mass from EarthMasses. + /// + /// If value is NaN or Infinity. + public static Mass FromEarthMasses(QuantityValue earthmasses) + { + double value = (double) earthmasses; + return new Mass(value, MassUnit.EarthMass); + } + /// /// Get Mass from Grains. /// /// If value is NaN or Infinity. @@ -519,6 +540,15 @@ public static Mass FromSlugs(QuantityValue slugs) return new Mass(value, MassUnit.Slug); } /// + /// Get Mass from SolarMasses. + /// + /// If value is NaN or Infinity. + public static Mass FromSolarMasses(QuantityValue solarmasses) + { + double value = (double) solarmasses; + return new Mass(value, MassUnit.SolarMass); + } + /// /// Get Mass from Stone. /// /// If value is NaN or Infinity. @@ -968,6 +998,7 @@ private double GetValueInBaseUnit() case MassUnit.Centigram: return (_value/1e3) * 1e-2d; case MassUnit.Decagram: return (_value/1e3) * 1e1d; case MassUnit.Decigram: return (_value/1e3) * 1e-1d; + case MassUnit.EarthMass: return _value * 5.9722E+24; case MassUnit.Grain: return _value/15432.358352941431; case MassUnit.Gram: return _value/1e3; case MassUnit.Hectogram: return (_value/1e3) * 1e2d; @@ -986,6 +1017,7 @@ private double GetValueInBaseUnit() case MassUnit.ShortHundredweight: return _value/0.022046226218487758; case MassUnit.ShortTon: return _value*9.0718474e2; case MassUnit.Slug: return _value/6.852176556196105e-2; + case MassUnit.SolarMass: return _value * 1.98947e30; case MassUnit.Stone: return _value/0.1574731728702698; case MassUnit.Tonne: return _value*1e3; default: @@ -1016,6 +1048,7 @@ private double GetValueAs(MassUnit unit) case MassUnit.Centigram: return (baseUnitValue*1e3) / 1e-2d; case MassUnit.Decagram: return (baseUnitValue*1e3) / 1e1d; case MassUnit.Decigram: return (baseUnitValue*1e3) / 1e-1d; + case MassUnit.EarthMass: return baseUnitValue / 5.9722E+24; case MassUnit.Grain: return baseUnitValue*15432.358352941431; case MassUnit.Gram: return baseUnitValue*1e3; case MassUnit.Hectogram: return (baseUnitValue*1e3) / 1e2d; @@ -1034,6 +1067,7 @@ private double GetValueAs(MassUnit unit) case MassUnit.ShortHundredweight: return baseUnitValue*0.022046226218487758; case MassUnit.ShortTon: return baseUnitValue/9.0718474e2; case MassUnit.Slug: return baseUnitValue*6.852176556196105e-2; + case MassUnit.SolarMass: return baseUnitValue / 1.98947e30; case MassUnit.Stone: return baseUnitValue*0.1574731728702698; case MassUnit.Tonne: return baseUnitValue/1e3; default: diff --git a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs index 862136dbae..33e1cfdc4a 100644 --- a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs @@ -657,6 +657,17 @@ private double GetValueInBaseUnit() } } + /// + /// Converts the current value + unit to the base unit. + /// This is typically the first step in converting from one unit to another. + /// + /// The value in the base unit representation. + internal RatioChangeRate ToBaseUnit() + { + var baseUnitValue = GetValueInBaseUnit(); + return new RatioChangeRate(baseUnitValue, BaseUnit); + } + private double GetValueAs(RatioChangeRateUnit unit) { if(Unit == unit) diff --git a/UnitsNet/GeneratedCode/Quantity.g.cs b/UnitsNet/GeneratedCode/Quantity.g.cs index 686d328a81..8ad605eb01 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -138,6 +138,8 @@ public static IQuantity FromQuantityType(QuantityType quantityType, QuantityValu return Level.From(value, Level.BaseUnit); case QuantityType.LinearDensity: return LinearDensity.From(value, LinearDensity.BaseUnit); + case QuantityType.Luminosity: + return Luminosity.From(value, Luminosity.BaseUnit); case QuantityType.LuminousFlux: return LuminousFlux.From(value, LuminousFlux.BaseUnit); case QuantityType.LuminousIntensity: @@ -395,6 +397,9 @@ public static bool TryFrom(QuantityValue value, Enum unit, out IQuantity quantit case LinearDensityUnit linearDensityUnit: quantity = LinearDensity.From(value, linearDensityUnit); return true; + case LuminosityUnit luminosityUnit: + quantity = Luminosity.From(value, luminosityUnit); + return true; case LuminousFluxUnit luminousFluxUnit: quantity = LuminousFlux.From(value, luminousFluxUnit); return true; @@ -661,6 +666,8 @@ public static bool TryParse([CanBeNull] IFormatProvider formatProvider, Type qua return parser.TryParse(quantityString, formatProvider, Level.From, out quantity); case Type _ when quantityType == typeof(LinearDensity): return parser.TryParse(quantityString, formatProvider, LinearDensity.From, out quantity); + case Type _ when quantityType == typeof(Luminosity): + return parser.TryParse(quantityString, formatProvider, Luminosity.From, out quantity); case Type _ when quantityType == typeof(LuminousFlux): return parser.TryParse(quantityString, formatProvider, LuminousFlux.From, out quantity); case Type _ when quantityType == typeof(LuminousIntensity): diff --git a/UnitsNet/GeneratedCode/QuantityType.g.cs b/UnitsNet/GeneratedCode/QuantityType.g.cs index 9a57db759d..4c71b1ac40 100644 --- a/UnitsNet/GeneratedCode/QuantityType.g.cs +++ b/UnitsNet/GeneratedCode/QuantityType.g.cs @@ -80,6 +80,7 @@ public enum QuantityType Length, Level, LinearDensity, + Luminosity, LuminousFlux, LuminousIntensity, MagneticField, diff --git a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs index 3a7263bef8..51639c5cb3 100644 --- a/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs +++ b/UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs @@ -496,6 +496,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(KinematicViscosityUnit), (int)KinematicViscosityUnit.Stokes, new string[]{"St"}), ("ru-RU", typeof(KinematicViscosityUnit), (int)KinematicViscosityUnit.Stokes, new string[]{"Ст"}), ("en-US", typeof(LapseRateUnit), (int)LapseRateUnit.DegreeCelsiusPerKilometer, new string[]{"∆°C/km"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.AstronomicalUnit, new string[]{"au", "ua"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Centimeter, new string[]{"cm"}), ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Centimeter, new string[]{"см"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Decimeter, new string[]{"dm"}), @@ -510,8 +511,13 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Hectometer, new string[]{"гм"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Inch, new string[]{"in", "\"", "″"}), ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Inch, new string[]{"дюйм"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.KilolightYear, new string[]{"kly"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Kilometer, new string[]{"km"}), ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Kilometer, new string[]{"км"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.Kiloparsec, new string[]{"kpc"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.LightYear, new string[]{"ly"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.MegalightYear, new string[]{"Mly"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.Megaparsec, new string[]{"Mpc"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Meter, new string[]{"m"}), ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Meter, new string[]{"м"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Microinch, new string[]{"µin"}), @@ -528,6 +534,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("ru-RU", typeof(LengthUnit), (int)LengthUnit.Nanometer, new string[]{"нм"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.NauticalMile, new string[]{"NM"}), ("ru-RU", typeof(LengthUnit), (int)LengthUnit.NauticalMile, new string[]{"мил"}), + ("en-US", typeof(LengthUnit), (int)LengthUnit.Parsec, new string[]{"pc"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.PrinterPica, new string[]{"pica"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.PrinterPoint, new string[]{"pt"}), ("en-US", typeof(LengthUnit), (int)LengthUnit.Shackle, new string[]{"shackle"}), @@ -540,6 +547,20 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.GramPerMeter, new string[]{"g/m"}), ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.KilogramPerMeter, new string[]{"kg/m"}), ("en-US", typeof(LinearDensityUnit), (int)LinearDensityUnit.PoundPerFoot, new string[]{"lb/ft"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Decawatt, new string[]{"daW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Deciwatt, new string[]{"dW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Femtowatt, new string[]{"fW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Gigawatt, new string[]{"GW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Kilowatt, new string[]{"kW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Megawatt, new string[]{"MW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Microwatt, new string[]{"µW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Milliwatt, new string[]{"mW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Nanowatt, new string[]{"nW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Petawatt, new string[]{"PW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Picowatt, new string[]{"pW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.SolarLuminosity, new string[]{"L⊙"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Terawatt, new string[]{"TW"}), + ("en-US", typeof(LuminosityUnit), (int)LuminosityUnit.Watt, new string[]{"W"}), ("en-US", typeof(LuminousFluxUnit), (int)LuminousFluxUnit.Lumen, new string[]{"lm"}), ("en-US", typeof(LuminousIntensityUnit), (int)LuminousIntensityUnit.Candela, new string[]{"cd"}), ("en-US", typeof(MagneticFieldUnit), (int)MagneticFieldUnit.Microtesla, new string[]{"µT"}), @@ -554,6 +575,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("ru-RU", typeof(MassUnit), (int)MassUnit.Decagram, new string[]{"даг"}), ("en-US", typeof(MassUnit), (int)MassUnit.Decigram, new string[]{"dg"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.Decigram, new string[]{"дг"}), + ("en-US", typeof(MassUnit), (int)MassUnit.EarthMass, new string[]{"em"}), ("en-US", typeof(MassUnit), (int)MassUnit.Grain, new string[]{"gr"}), ("en-US", typeof(MassUnit), (int)MassUnit.Gram, new string[]{"g"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.Gram, new string[]{"г"}), @@ -585,6 +607,7 @@ private static readonly (string CultureName, Type UnitType, int UnitValue, strin ("en-US", typeof(MassUnit), (int)MassUnit.ShortTon, new string[]{"short tn"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.ShortTon, new string[]{"тонна малая"}), ("en-US", typeof(MassUnit), (int)MassUnit.Slug, new string[]{"slug"}), + ("en-US", typeof(MassUnit), (int)MassUnit.SolarMass, new string[]{"M⊙"}), ("en-US", typeof(MassUnit), (int)MassUnit.Stone, new string[]{"st"}), ("en-US", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"t"}), ("ru-RU", typeof(MassUnit), (int)MassUnit.Tonne, new string[]{"т"}), diff --git a/UnitsNet/GeneratedCode/UnitConverter.g.cs b/UnitsNet/GeneratedCode/UnitConverter.g.cs index 9c6f6748c1..79e235043c 100644 --- a/UnitsNet/GeneratedCode/UnitConverter.g.cs +++ b/UnitsNet/GeneratedCode/UnitConverter.g.cs @@ -774,6 +774,8 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(KinematicViscosity.BaseUnit, KinematicViscosityUnit.Stokes, q => q.ToUnit(KinematicViscosityUnit.Stokes)); unitConverter.SetConversionFunction(KinematicViscosityUnit.Stokes, KinematicViscosity.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(LapseRate.BaseUnit, LapseRate.BaseUnit, q => q); + unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.AstronomicalUnit, q => q.ToUnit(LengthUnit.AstronomicalUnit)); + unitConverter.SetConversionFunction(LengthUnit.AstronomicalUnit, Length.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.Centimeter, q => q.ToUnit(LengthUnit.Centimeter)); unitConverter.SetConversionFunction(LengthUnit.Centimeter, Length.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.Decimeter, q => q.ToUnit(LengthUnit.Decimeter)); @@ -792,8 +794,18 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(LengthUnit.Hectometer, Length.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.Inch, q => q.ToUnit(LengthUnit.Inch)); unitConverter.SetConversionFunction(LengthUnit.Inch, Length.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.KilolightYear, q => q.ToUnit(LengthUnit.KilolightYear)); + unitConverter.SetConversionFunction(LengthUnit.KilolightYear, Length.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.Kilometer, q => q.ToUnit(LengthUnit.Kilometer)); unitConverter.SetConversionFunction(LengthUnit.Kilometer, Length.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.Kiloparsec, q => q.ToUnit(LengthUnit.Kiloparsec)); + unitConverter.SetConversionFunction(LengthUnit.Kiloparsec, Length.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.LightYear, q => q.ToUnit(LengthUnit.LightYear)); + unitConverter.SetConversionFunction(LengthUnit.LightYear, Length.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.MegalightYear, q => q.ToUnit(LengthUnit.MegalightYear)); + unitConverter.SetConversionFunction(LengthUnit.MegalightYear, Length.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.Megaparsec, q => q.ToUnit(LengthUnit.Megaparsec)); + unitConverter.SetConversionFunction(LengthUnit.Megaparsec, Length.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Length.BaseUnit, Length.BaseUnit, q => q); unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.Microinch, q => q.ToUnit(LengthUnit.Microinch)); unitConverter.SetConversionFunction(LengthUnit.Microinch, Length.BaseUnit, q => q.ToBaseUnit()); @@ -809,6 +821,8 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(LengthUnit.Nanometer, Length.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.NauticalMile, q => q.ToUnit(LengthUnit.NauticalMile)); unitConverter.SetConversionFunction(LengthUnit.NauticalMile, Length.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.Parsec, q => q.ToUnit(LengthUnit.Parsec)); + unitConverter.SetConversionFunction(LengthUnit.Parsec, Length.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.PrinterPica, q => q.ToUnit(LengthUnit.PrinterPica)); unitConverter.SetConversionFunction(LengthUnit.PrinterPica, Length.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Length.BaseUnit, LengthUnit.PrinterPoint, q => q.ToUnit(LengthUnit.PrinterPoint)); @@ -829,6 +843,33 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(LinearDensity.BaseUnit, LinearDensity.BaseUnit, q => q); unitConverter.SetConversionFunction(LinearDensity.BaseUnit, LinearDensityUnit.PoundPerFoot, q => q.ToUnit(LinearDensityUnit.PoundPerFoot)); unitConverter.SetConversionFunction(LinearDensityUnit.PoundPerFoot, LinearDensity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Decawatt, q => q.ToUnit(LuminosityUnit.Decawatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Decawatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Deciwatt, q => q.ToUnit(LuminosityUnit.Deciwatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Deciwatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Femtowatt, q => q.ToUnit(LuminosityUnit.Femtowatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Femtowatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Gigawatt, q => q.ToUnit(LuminosityUnit.Gigawatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Gigawatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Kilowatt, q => q.ToUnit(LuminosityUnit.Kilowatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Kilowatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Megawatt, q => q.ToUnit(LuminosityUnit.Megawatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Megawatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Microwatt, q => q.ToUnit(LuminosityUnit.Microwatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Microwatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Milliwatt, q => q.ToUnit(LuminosityUnit.Milliwatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Milliwatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Nanowatt, q => q.ToUnit(LuminosityUnit.Nanowatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Nanowatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Petawatt, q => q.ToUnit(LuminosityUnit.Petawatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Petawatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Picowatt, q => q.ToUnit(LuminosityUnit.Picowatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Picowatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.SolarLuminosity, q => q.ToUnit(LuminosityUnit.SolarLuminosity)); + unitConverter.SetConversionFunction(LuminosityUnit.SolarLuminosity, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, LuminosityUnit.Terawatt, q => q.ToUnit(LuminosityUnit.Terawatt)); + unitConverter.SetConversionFunction(LuminosityUnit.Terawatt, Luminosity.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Luminosity.BaseUnit, Luminosity.BaseUnit, q => q); unitConverter.SetConversionFunction(LuminousFlux.BaseUnit, LuminousFlux.BaseUnit, q => q); unitConverter.SetConversionFunction(LuminousIntensity.BaseUnit, LuminousIntensity.BaseUnit, q => q); unitConverter.SetConversionFunction(MagneticField.BaseUnit, MagneticFieldUnit.Microtesla, q => q.ToUnit(MagneticFieldUnit.Microtesla)); @@ -846,6 +887,8 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(MassUnit.Decagram, Mass.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Mass.BaseUnit, MassUnit.Decigram, q => q.ToUnit(MassUnit.Decigram)); unitConverter.SetConversionFunction(MassUnit.Decigram, Mass.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Mass.BaseUnit, MassUnit.EarthMass, q => q.ToUnit(MassUnit.EarthMass)); + unitConverter.SetConversionFunction(MassUnit.EarthMass, Mass.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Mass.BaseUnit, MassUnit.Grain, q => q.ToUnit(MassUnit.Grain)); unitConverter.SetConversionFunction(MassUnit.Grain, Mass.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Mass.BaseUnit, MassUnit.Gram, q => q.ToUnit(MassUnit.Gram)); @@ -881,6 +924,8 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(MassUnit.ShortTon, Mass.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Mass.BaseUnit, MassUnit.Slug, q => q.ToUnit(MassUnit.Slug)); unitConverter.SetConversionFunction(MassUnit.Slug, Mass.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(Mass.BaseUnit, MassUnit.SolarMass, q => q.ToUnit(MassUnit.SolarMass)); + unitConverter.SetConversionFunction(MassUnit.SolarMass, Mass.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Mass.BaseUnit, MassUnit.Stone, q => q.ToUnit(MassUnit.Stone)); unitConverter.SetConversionFunction(MassUnit.Stone, Mass.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Mass.BaseUnit, MassUnit.Tonne, q => q.ToUnit(MassUnit.Tonne)); @@ -1420,6 +1465,9 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) unitConverter.SetConversionFunction(RatioUnit.PartPerTrillion, Ratio.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(Ratio.BaseUnit, RatioUnit.Percent, q => q.ToUnit(RatioUnit.Percent)); unitConverter.SetConversionFunction(RatioUnit.Percent, Ratio.BaseUnit, q => q.ToBaseUnit()); + unitConverter.SetConversionFunction(RatioChangeRate.BaseUnit, RatioChangeRate.BaseUnit, q => q); + unitConverter.SetConversionFunction(RatioChangeRate.BaseUnit, RatioChangeRateUnit.PercentPerSecond, q => q.ToUnit(RatioChangeRateUnit.PercentPerSecond)); + unitConverter.SetConversionFunction(RatioChangeRateUnit.PercentPerSecond, RatioChangeRate.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(ReactiveEnergy.BaseUnit, ReactiveEnergyUnit.KilovoltampereReactiveHour, q => q.ToUnit(ReactiveEnergyUnit.KilovoltampereReactiveHour)); unitConverter.SetConversionFunction(ReactiveEnergyUnit.KilovoltampereReactiveHour, ReactiveEnergy.BaseUnit, q => q.ToBaseUnit()); unitConverter.SetConversionFunction(ReactiveEnergy.BaseUnit, ReactiveEnergyUnit.MegavoltampereReactiveHour, q => q.ToUnit(ReactiveEnergyUnit.MegavoltampereReactiveHour)); diff --git a/UnitsNet/GeneratedCode/Units/LengthUnit.g.cs b/UnitsNet/GeneratedCode/Units/LengthUnit.g.cs index 9cdede7100..b8e05a1b47 100644 --- a/UnitsNet/GeneratedCode/Units/LengthUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/LengthUnit.g.cs @@ -26,6 +26,12 @@ namespace UnitsNet.Units public enum LengthUnit { Undefined = 0, + + /// + /// One Astronomical Unit is the distance from the solar system Star, the sun, to planet Earth. + /// + /// https://en.wikipedia.org/wiki/Astronomical_unit + AstronomicalUnit, Centimeter, Decimeter, DtpPica, @@ -35,7 +41,17 @@ public enum LengthUnit Hand, Hectometer, Inch, + KilolightYear, Kilometer, + Kiloparsec, + + /// + /// A Light Year (ly) is the distance that light travel during an Earth year, ie 365 days. + /// + /// https://en.wikipedia.org/wiki/Light-year + LightYear, + MegalightYear, + Megaparsec, Meter, Microinch, Micrometer, @@ -44,6 +60,12 @@ public enum LengthUnit Millimeter, Nanometer, NauticalMile, + + /// + /// A parsec is defined as the distance at which one astronomical unit (AU) subtends an angle of one arcsecond. + /// + /// https://en.wikipedia.org/wiki/Parsec + Parsec, PrinterPica, PrinterPoint, Shackle, diff --git a/UnitsNet/GeneratedCode/Units/LuminosityUnit.g.cs b/UnitsNet/GeneratedCode/Units/LuminosityUnit.g.cs new file mode 100644 index 0000000000..53bbdda773 --- /dev/null +++ b/UnitsNet/GeneratedCode/Units/LuminosityUnit.g.cs @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by \generate-code.bat. +// +// Changes to this file will be lost when the code is regenerated. +// The build server regenerates the code before each build and a pre-build +// step will regenerate the code on each local build. +// +// See https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit for how to add or edit units. +// +// Add CustomCode\Quantities\MyQuantity.extra.cs files to add code to generated quantities. +// Add UnitDefinitions\MyQuantity.json and run generate-code.bat to generate new units or quantities. +// +// +//------------------------------------------------------------------------------ + +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +// ReSharper disable once CheckNamespace +namespace UnitsNet.Units +{ + // Disable missing XML comment warnings for the generated unit enums. + #pragma warning disable 1591 + + public enum LuminosityUnit + { + Undefined = 0, + Decawatt, + Deciwatt, + Femtowatt, + Gigawatt, + Kilowatt, + Megawatt, + Microwatt, + Milliwatt, + Nanowatt, + Petawatt, + Picowatt, + /// https://www.britannica.com/science/luminosity + SolarLuminosity, + Terawatt, + Watt, + } + + #pragma warning restore 1591 +} diff --git a/UnitsNet/GeneratedCode/Units/MassUnit.g.cs b/UnitsNet/GeneratedCode/Units/MassUnit.g.cs index d5f20ebe4b..790ab72fc3 100644 --- a/UnitsNet/GeneratedCode/Units/MassUnit.g.cs +++ b/UnitsNet/GeneratedCode/Units/MassUnit.g.cs @@ -30,6 +30,12 @@ public enum MassUnit Decagram, Decigram, + /// + /// Earth mass is a ratio unit to the mass of planet Earth. + /// + /// https://en.wikipedia.org/wiki/Earth_mass + EarthMass, + /// /// A grain is a unit of measurement of mass, and in the troy weight, avoirdupois, and Apothecaries' system, equal to exactly 64.79891 milligrams. /// @@ -87,6 +93,12 @@ public enum MassUnit /// http://en.wikipedia.org/wiki/Slug_(unit) Slug, + /// + /// Solar mass is a ratio unit to the mass of the solar system star, the sun. + /// + /// https://en.wikipedia.org/wiki/Solar_mass + SolarMass, + /// /// The stone (abbreviation st) is a unit of mass equal to 14 pounds avoirdupois (about 6.35 kilograms) used in Great Britain and Ireland for measuring human body weight. /// diff --git a/UnitsNet/UnitsNet.csproj b/UnitsNet/UnitsNet.csproj index 1f62ed32e4..4efe36b644 100644 --- a/UnitsNet/UnitsNet.csproj +++ b/UnitsNet/UnitsNet.csproj @@ -1,4 +1,4 @@ - + UnitsNet @@ -57,4 +57,5 @@ +