diff --git a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs index b9a6039db9..b9d609739c 100644 --- a/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs @@ -5,6 +5,7 @@ using System.Linq; using CodeGen.Helpers; using CodeGen.JsonTypes; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace CodeGen.Generators.UnitsNetGen { @@ -34,13 +35,10 @@ public string Generate() { Writer.WL(GeneratedFileHeader); Writer.WL(@" -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; + using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -122,6 +120,7 @@ namespace UnitsNet [DataMember(Name = ""Unit"", Order = 2)] private readonly {_unitEnumName}? _unit; "); + GenerateQuantityInfo(); GenerateStaticConstructor(); GenerateInstanceConstructors(); GenerateStaticProperties(); @@ -141,36 +140,86 @@ namespace UnitsNet }}"); return Writer.ToString(); } - - private void GenerateStaticConstructor() + + private void GenerateQuantityInfo() { + var quantityInfoClassName = $"{_quantity.Name}Info"; BaseDimensions baseDimensions = _quantity.BaseDimensions; + var createDimensionsExpression = _isDimensionless + ? "BaseDimensions.Dimensionless" + : $"new BaseDimensions({baseDimensions.L}, {baseDimensions.M}, {baseDimensions.T}, {baseDimensions.I}, {baseDimensions.Θ}, {baseDimensions.N}, {baseDimensions.J})"; + Writer.WL($@" - static {_quantity.Name}() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class {quantityInfoClassName}: QuantityInfo<{_quantity.Name}, {_unitEnumName}> {{"); - Writer.WL(_isDimensionless ? $@" - BaseDimensions = BaseDimensions.Dimensionless;" : $@" - BaseDimensions = new BaseDimensions({baseDimensions.L}, {baseDimensions.M}, {baseDimensions.T}, {baseDimensions.I}, {baseDimensions.Θ}, {baseDimensions.N}, {baseDimensions.J});"); - Writer.WL($@" - BaseUnit = {_unitEnumName}.{_quantity.BaseUnit}; - Units = Enum.GetValues(typeof({_unitEnumName})).Cast<{_unitEnumName}>().ToArray(); - Zero = new {_quantity.Name}(0, BaseUnit); - Info = new QuantityInfo<{_unitEnumName}>(""{_quantity.Name}"", - new UnitInfo<{_unitEnumName}>[] - {{"); + /// + public {quantityInfoClassName}(string name, {_unitEnumName} baseUnit, IEnumerable> unitMappings, {_quantity.Name} zero, BaseDimensions baseDimensions, + QuantityFromDelegate<{_quantity.Name}, {_unitEnumName}> fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + {{ + }} + + /// + public {quantityInfoClassName}(string name, {_unitEnumName} baseUnit, IEnumerable> unitMappings, {_quantity.Name} zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, {_quantity.Name}.From, new ResourceManager(""UnitsNet.GeneratedCode.Resources.{_quantity.Name}"", typeof({_quantity.Name}).Assembly)) + {{ + }} + + /// + /// Creates a new instance of the class with the default settings for the {_quantity.Name} quantity. + /// + /// A new instance of the class with the default settings. + public static {quantityInfoClassName} CreateDefault() + {{ + return new {quantityInfoClassName}(nameof({_quantity.Name}), DefaultBaseUnit, GetDefaultMappings(), new {_quantity.Name}(0, DefaultBaseUnit), DefaultBaseDimensions); + }} + + /// + /// Creates a new instance of the class with the default settings for the {_quantity.Name} quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static {quantityInfoClassName} CreateDefault(Func>, IEnumerable>> customizeUnits) + {{ + return new {quantityInfoClassName}(nameof({_quantity.Name}), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new {_quantity.Name}(0, DefaultBaseUnit), DefaultBaseDimensions); + }} + /// + /// The for is {_quantity.BaseDimensions}. + /// + public static BaseDimensions DefaultBaseDimensions {{ get; }} = {createDimensionsExpression}; + + /// + /// The default base unit of {_quantity.Name} is {_baseUnit.SingularName}. All conversions, as defined in the , go via this value. + /// + public static {_unitEnumName} DefaultBaseUnit {{ get; }} = {_unitEnumName}.{_baseUnit.SingularName}; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for {_quantity.Name}. + public static IEnumerable> GetDefaultMappings() + {{"); + foreach (Unit unit in _quantity.Units) { BaseUnits? baseUnits = unit.BaseUnits; + string baseUnitsFormat; if (baseUnits == null) { - Writer.WL($@" - new UnitInfo<{_unitEnumName}>({_unitEnumName}.{unit.SingularName}, ""{unit.PluralName}"", BaseUnits.Undefined, ""{_quantity.Name}""),"); + baseUnitsFormat = "BaseUnits.Undefined"; } else { - var baseUnitsCtorArgs = string.Join(", ", + baseUnitsFormat = $"new BaseUnits({string.Join(", ", new[] { baseUnits.L != null ? $"length: LengthUnit.{baseUnits.L}" : null, @@ -180,17 +229,26 @@ private void GenerateStaticConstructor() baseUnits.Θ != null ? $"temperature: TemperatureUnit.{baseUnits.Θ}" : null, baseUnits.N != null ? $"amount: AmountOfSubstanceUnit.{baseUnits.N}" : null, baseUnits.J != null ? $"luminousIntensity: LuminousIntensityUnit.{baseUnits.J}" : null - }.Where(str => str != null)); - - Writer.WL($@" - new UnitInfo<{_unitEnumName}>({_unitEnumName}.{unit.SingularName}, ""{unit.PluralName}"", new BaseUnits({baseUnitsCtorArgs}), ""{_quantity.Name}""),"); + }.Where(str => str != null))})"; } + + Writer.WL($@" + yield return new ({_unitEnumName}.{unit.SingularName}, ""{unit.SingularName}"", ""{unit.PluralName}"", {baseUnitsFormat});"); } Writer.WL($@" - }}, - BaseUnit, Zero, BaseDimensions); - + }} + }} +"); + } + + private void GenerateStaticConstructor() + { + Writer.WL($@" + static {_quantity.Name}() + {{"); + Writer.WL($@" + Info = {_quantity.Name}Info.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); }} @@ -244,27 +302,27 @@ private void GenerateStaticProperties() public static UnitConverter DefaultConversionFunctions {{ get; }} /// - public static QuantityInfo<{_unitEnumName}> Info {{ get; }} + public static QuantityInfo<{_quantity.Name}, {_unitEnumName}> Info {{ get; }} /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions {{ get; }} + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of {_quantity.Name}, which is {_quantity.BaseUnit}. All conversions go via this value. /// - public static {_unitEnumName} BaseUnit {{ get; }} + public static {_unitEnumName} BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the {_quantity.Name} quantity. /// - public static {_unitEnumName}[] Units {{ get; }} + public static IReadOnlyCollection<{_unitEnumName}> Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit {_quantity.BaseUnit}. /// - public static {_quantity.Name} Zero {{ get; }} + public static {_quantity.Name} Zero => Info.Zero; "); if (_quantity.GenerateArithmetic) @@ -294,7 +352,7 @@ private void GenerateProperties() public {_unitEnumName} Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo<{_unitEnumName}> QuantityInfo => Info; + public QuantityInfo<{_quantity.Name}, {_unitEnumName}> QuantityInfo => Info; /// /// The of this quantity. @@ -312,6 +370,9 @@ private void GenerateProperties() [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo<{_unitEnumName}> IQuantity<{_unitEnumName}>.QuantityInfo => Info; + #endregion #endregion diff --git a/CodeGen/Generators/UnitsNetGen/StaticQuantityGenerator.cs b/CodeGen/Generators/UnitsNetGen/StaticQuantityGenerator.cs index 69443fa2d5..04cb812d54 100644 --- a/CodeGen/Generators/UnitsNetGen/StaticQuantityGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/StaticQuantityGenerator.cs @@ -1,5 +1,4 @@ -using CodeGen.Helpers; -using CodeGen.JsonTypes; +using CodeGen.JsonTypes; namespace CodeGen.Generators.UnitsNetGen { @@ -16,120 +15,31 @@ public string Generate() { Writer.WL(GeneratedFileHeader); Writer.WL(@" -using System; -using System.Globalization; -using UnitsNet.Units; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; #nullable enable -namespace UnitsNet +namespace UnitsNet; + +/// +/// Dynamically parse or construct quantities when types are only known at runtime. +/// +public partial class Quantity { /// - /// Dynamically parse or construct quantities when types are only known at runtime. + /// Serves as a repository for predefined quantity conversion mappings, facilitating the automatic generation and retrieval of unit conversions in the UnitsNet library. /// - public partial class Quantity + internal static class Provider { /// - /// All QuantityInfo instances mapped by quantity name that are present in UnitsNet by default. + /// All QuantityInfo instances that are present in UnitsNet by default. /// - public static readonly IDictionary ByName = new Dictionary + internal static IReadOnlyList DefaultQuantities => new QuantityInfo[] {"); foreach (var quantity in _quantities) Writer.WL($@" - {{ ""{quantity.Name}"", {quantity.Name}.Info }},"); + {quantity.Name}.Info,"); Writer.WL(@" }; - - /// - /// Dynamically constructs a quantity of the given with the value in the quantity's base units. - /// - /// The of the quantity to create. - /// The value to construct the quantity with. - /// The created quantity. - public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, double value) - { - return quantityInfo.Name switch - {"); - foreach (var quantity in _quantities) - { - var quantityName = quantity.Name; - Writer.WL($@" - ""{quantityName}"" => {quantityName}.From(value, {quantityName}.BaseUnit),"); - } - - Writer.WL(@" - _ => throw new ArgumentException($""{quantityInfo.Name} is not a supported quantity."") - }; - } - - /// - /// Try to dynamically construct a quantity. - /// - /// Numeric value. - /// Unit enum value. - /// The resulting quantity if successful, otherwise default. - /// True if successful with assigned the value, otherwise false. - public static bool TryFrom(double value, Enum? unit, [NotNullWhen(true)] out IQuantity? quantity) - { - quantity = unit switch - {"); - foreach (var quantity in _quantities) - { - var quantityName = quantity.Name; - var unitTypeName = $"{quantityName}Unit"; - var unitValue = unitTypeName.ToCamelCase(); - Writer.WL($@" - {unitTypeName} {unitValue} => {quantityName}.From(value, {unitValue}),"); - } - - Writer.WL(@" - _ => null - }; - - return quantity is not null; - } - - /// - /// Try to dynamically parse a quantity string representation. - /// - /// The format provider to use for lookup. Defaults to if null. - /// Type of quantity, such as . - /// Quantity string representation, such as ""1.5 kg"". Must be compatible with given quantity type. - /// The resulting quantity if successful, otherwise default. - /// The parsed quantity. - public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, [NotNullWhen(true)] string? quantityString, [NotNullWhen(true)] out IQuantity? quantity) - { - quantity = default(IQuantity); - - if (!typeof(IQuantity).IsAssignableFrom(quantityType)) - return false; - - var parser = UnitsNetSetup.Default.QuantityParser; - - return quantityType switch - {"); - foreach (var quantity in _quantities) - { - var quantityName = quantity.Name; - Writer.WL($@" - Type _ when quantityType == typeof({quantityName}) => parser.TryParse<{quantityName}, {quantityName}Unit>(quantityString, formatProvider, {quantityName}.From, out quantity),"); - } - - Writer.WL(@" - _ => false - }; - } - - internal static IEnumerable GetQuantityTypes() - {"); - foreach (var quantity in _quantities) - Writer.WL($@" - yield return typeof({quantity.Name});"); - Writer.WL(@" - } } }"); return Writer.ToString(); diff --git a/UnitsNet.Benchmark/Conversions/FromString/QuantityFromStringBenchmarks.cs b/UnitsNet.Benchmark/Conversions/FromString/QuantityFromStringBenchmarks.cs index 8abb153032..9c7b03f1d1 100644 --- a/UnitsNet.Benchmark/Conversions/FromString/QuantityFromStringBenchmarks.cs +++ b/UnitsNet.Benchmark/Conversions/FromString/QuantityFromStringBenchmarks.cs @@ -9,7 +9,7 @@ namespace UnitsNet.Benchmark.Conversions.FromString; [MemoryDiagnoser] [SimpleJob(RuntimeMoniker.Net48)] -[SimpleJob(RuntimeMoniker.Net80)] +[SimpleJob(RuntimeMoniker.Net90)] public class QuantityFromStringBenchmarks { private static readonly CultureInfo Culture = CultureInfo.InvariantCulture; @@ -28,20 +28,20 @@ public void PrepareMassStrings() _quantitiesToParse = _random.GetItems(["kg", "lbs", "Mlbs"], NbAbbreviations).Select(abbreviation => $"{ValueToParse} {abbreviation}").ToArray(); } - [GlobalSetup(Target = nameof(FromVolumeUnitAbbreviation))] + [GlobalSetup(Target = nameof(FromVolumeString))] public void PrepareVolumeStrings() { _quantitiesToParse = _random.GetItems(["ml", "l", "cm³", "m³"], NbAbbreviations).Select(abbreviation => $"{ValueToParse} {abbreviation}").ToArray();; } - [GlobalSetup(Target = nameof(FromPressureUnitAbbreviation))] - public void PreparePressureUnits() + [GlobalSetup(Target = nameof(FromPressureString))] + public void PreparePressureStrings() { _quantitiesToParse = _random.GetRandomAbbreviations(UnitsNetSetup.Default.UnitAbbreviations, NbAbbreviations).Select(abbreviation => $"{ValueToParse} {abbreviation}").ToArray();; } - [GlobalSetup(Target = nameof(FromVolumeFlowUnitAbbreviation))] - public void PrepareVolumeFlowUnits() + [GlobalSetup(Target = nameof(FromVolumeFlowString))] + public void PrepareVolumeFlowStrings() { // can't have "bpm" (see Frequency) _quantitiesToParse = @@ -63,7 +63,7 @@ public IQuantity FromMassString() } [Benchmark(Baseline = false)] - public IQuantity FromVolumeUnitAbbreviation() + public IQuantity FromVolumeString() { IQuantity quantity = null; foreach (var quantityString in _quantitiesToParse) @@ -75,7 +75,7 @@ public IQuantity FromVolumeUnitAbbreviation() } [Benchmark(Baseline = false)] - public IQuantity FromPressureUnitAbbreviation() + public IQuantity FromPressureString() { IQuantity quantity = null; foreach (var quantityString in _quantitiesToParse) @@ -87,7 +87,7 @@ public IQuantity FromPressureUnitAbbreviation() } [Benchmark(Baseline = false)] - public IQuantity FromVolumeFlowUnitAbbreviation() + public IQuantity FromVolumeFlowString() { IQuantity quantity = null; foreach (var quantityString in _quantitiesToParse) diff --git a/UnitsNet.Benchmark/Conversions/FromString/QuantityFromUnitAbbreviationBenchmarks.cs b/UnitsNet.Benchmark/Conversions/FromString/QuantityFromUnitAbbreviationBenchmarks.cs index 9a6b3ae576..a46e137560 100644 --- a/UnitsNet.Benchmark/Conversions/FromString/QuantityFromUnitAbbreviationBenchmarks.cs +++ b/UnitsNet.Benchmark/Conversions/FromString/QuantityFromUnitAbbreviationBenchmarks.cs @@ -9,7 +9,7 @@ namespace UnitsNet.Benchmark.Conversions.FromString; [MemoryDiagnoser] [SimpleJob(RuntimeMoniker.Net48)] -[SimpleJob(RuntimeMoniker.Net80)] +[SimpleJob(RuntimeMoniker.Net90)] public class QuantityFromUnitAbbreviationBenchmarks { private static readonly CultureInfo Culture = CultureInfo.InvariantCulture; diff --git a/UnitsNet.Benchmark/Conversions/ToString/ToStringWithDefaultPrecisionBenchmarks.cs b/UnitsNet.Benchmark/Conversions/ToString/ToStringWithDefaultPrecisionBenchmarks.cs index 5b1381e91f..c26521c225 100644 --- a/UnitsNet.Benchmark/Conversions/ToString/ToStringWithDefaultPrecisionBenchmarks.cs +++ b/UnitsNet.Benchmark/Conversions/ToString/ToStringWithDefaultPrecisionBenchmarks.cs @@ -27,13 +27,13 @@ public class ToStringWithDefaultPrecisionBenchmarks [GlobalSetup(Target = nameof(MassToString))] public void PrepareMassesToTest() { - _masses = _random.GetRandomQuantities(Value, Mass.Units, NbConversions).ToArray(); + _masses = _random.GetRandomQuantities(Value, Mass.Units.ToArray(), NbConversions).ToArray(); } [GlobalSetup(Target = nameof(VolumeFlowToString))] public void PrepareVolumeFlowsToTest() { - _volumeFlows = _random.GetRandomQuantities(Value, VolumeFlow.Units, NbConversions).ToArray(); + _volumeFlows = _random.GetRandomQuantities(Value, VolumeFlow.Units.ToArray(), NbConversions).ToArray(); } [Benchmark(Baseline = true)] diff --git a/UnitsNet.Benchmark/Conversions/ToUnit/QuantityToUnitBenchmarks.cs b/UnitsNet.Benchmark/Conversions/ToUnit/QuantityToUnitBenchmarks.cs index 31160857f1..6ced1efc3e 100644 --- a/UnitsNet.Benchmark/Conversions/ToUnit/QuantityToUnitBenchmarks.cs +++ b/UnitsNet.Benchmark/Conversions/ToUnit/QuantityToUnitBenchmarks.cs @@ -2,6 +2,7 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; +using System.Linq; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Jobs; using UnitsNet.Units; @@ -25,13 +26,13 @@ public class QuantityToUnitBenchmarks [GlobalSetup(Target = nameof(MassToUnit))] public void PrepareMassConversionsToTest() { - _massConversions = _random.GetRandomConversions(Value, Mass.Units, NbConversions); + _massConversions = _random.GetRandomConversions(Value, Mass.Units.ToArray(), NbConversions); } [GlobalSetup(Target = nameof(VolumeFlowToUnit))] public void PrepareVolumeFlowConversionsToTest() { - _volumeFlowConversions = _random.GetRandomConversions(Value, VolumeFlow.Units, NbConversions); + _volumeFlowConversions = _random.GetRandomConversions(Value, VolumeFlow.Units.ToArray(), NbConversions); } [Benchmark(Baseline = true)] diff --git a/UnitsNet.Benchmark/Conversions/ToValue/QuantityAsBenchmarks.cs b/UnitsNet.Benchmark/Conversions/ToValue/QuantityAsBenchmarks.cs index bbab51b9a6..0dc28a0694 100644 --- a/UnitsNet.Benchmark/Conversions/ToValue/QuantityAsBenchmarks.cs +++ b/UnitsNet.Benchmark/Conversions/ToValue/QuantityAsBenchmarks.cs @@ -2,6 +2,7 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; +using System.Linq; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Jobs; using UnitsNet.Units; @@ -29,31 +30,31 @@ public class QuantityAsBenchmarks [GlobalSetup(Target = nameof(MassAs))] public void PrepareMassConversionsToTest() { - _massConversions = _random.GetRandomConversions(Value, Mass.Units, NbConversions); + _massConversions = _random.GetRandomConversions(Value, Mass.Units.ToArray(), NbConversions); } [GlobalSetup(Target = nameof(VolumeAs))] public void PrepareVolumeConversionsToTest() { - _volumeConversions = _random.GetRandomConversions(Value, Volume.Units, NbConversions); + _volumeConversions = _random.GetRandomConversions(Value, Volume.Units.ToArray(), NbConversions); } [GlobalSetup(Target = nameof(DensityAs))] public void PrepareDensityConversionsToTest() { - _densityConversions = _random.GetRandomConversions(Value, Density.Units, NbConversions); + _densityConversions = _random.GetRandomConversions(Value, Density.Units.ToArray(), NbConversions); } [GlobalSetup(Target = nameof(PressureAs))] public void PreparePressureConversionsToTest() { - _pressureConversions = _random.GetRandomConversions(Value, Pressure.Units, NbConversions); + _pressureConversions = _random.GetRandomConversions(Value, Pressure.Units.ToArray(), NbConversions); } [GlobalSetup(Target = nameof(VolumeFlowAs))] public void PrepareVolumeFlowConversionsToTest() { - _volumeFlowConversions = _random.GetRandomConversions(Value, VolumeFlow.Units, NbConversions); + _volumeFlowConversions = _random.GetRandomConversions(Value, VolumeFlow.Units.ToArray(), NbConversions); } [Benchmark(Baseline = true)] diff --git a/UnitsNet.Benchmark/Initializations/QuantityInfoInitializationBenchmarks.cs b/UnitsNet.Benchmark/Initializations/QuantityInfoInitializationBenchmarks.cs new file mode 100644 index 0000000000..11f0241673 --- /dev/null +++ b/UnitsNet.Benchmark/Initializations/QuantityInfoInitializationBenchmarks.cs @@ -0,0 +1,43 @@ +// 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 BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; + +namespace UnitsNet.Benchmark.Initializations; + +[MemoryDiagnoser] +[SimpleJob(RuntimeMoniker.Net48)] +[SimpleJob(RuntimeMoniker.Net90)] +public class QuantityInfoInitializationBenchmarks +{ + [Params(1000)] + public int NbIterations { get; set; } + + [Benchmark(Baseline = true)] + public void CreateDefaultMass() + { + for (var i = 0; i < NbIterations; i++) + { + var quantityInfo = Mass.MassInfo.CreateDefault(); + } + } + + [Benchmark] + public void CreateDefaultVolume() + { + for (var i = 0; i < NbIterations; i++) + { + var quantityInfo = Volume.VolumeInfo.CreateDefault(); + } + } + + [Benchmark] + public void CreateDefaultVolumeFlow() + { + for (var i = 0; i < NbIterations; i++) + { + var quantityInfo = VolumeFlow.VolumeFlowInfo.CreateDefault(); + } + } +} diff --git a/UnitsNet.Benchmark/Initializations/UnitAbbreviationsCacheInitializationBenchmarks.cs b/UnitsNet.Benchmark/Initializations/UnitAbbreviationsCacheInitializationBenchmarks.cs index 4ca3b7a855..ccd99f7d44 100644 --- a/UnitsNet.Benchmark/Initializations/UnitAbbreviationsCacheInitializationBenchmarks.cs +++ b/UnitsNet.Benchmark/Initializations/UnitAbbreviationsCacheInitializationBenchmarks.cs @@ -9,7 +9,7 @@ namespace UnitsNet.Benchmark.Initializations; [MemoryDiagnoser] [SimpleJob(RuntimeMoniker.Net48)] -[SimpleJob(RuntimeMoniker.Net80)] +[SimpleJob(RuntimeMoniker.Net90)] public class UnitAbbreviationsCacheInitializationBenchmarks { [GlobalSetup] diff --git a/UnitsNet.Benchmark/Operators/Additions/AddToTemperatureWithRandomUnitsBenchmarks.cs b/UnitsNet.Benchmark/Operators/Additions/AddToTemperatureWithRandomUnitsBenchmarks.cs index 443da4b645..596e17a990 100644 --- a/UnitsNet.Benchmark/Operators/Additions/AddToTemperatureWithRandomUnitsBenchmarks.cs +++ b/UnitsNet.Benchmark/Operators/Additions/AddToTemperatureWithRandomUnitsBenchmarks.cs @@ -26,8 +26,8 @@ public class AddToTemperatureWithRandomUnitsBenchmarks [GlobalSetup] public void PrepareQuantities() { - _operands = _random.GetRandomQuantities(LeftValue, Temperature.Units, NbOperations) - .Zip(_random.GetRandomQuantities(RightValue, TemperatureDelta.Units, NbOperations), + _operands = _random.GetRandomQuantities(LeftValue, Temperature.Units.ToArray(), NbOperations) + .Zip(_random.GetRandomQuantities(RightValue, TemperatureDelta.Units.ToArray(), NbOperations), (left, right) => (left, right)) .ToArray(); } diff --git a/UnitsNet.Benchmark/Operators/Additions/AddTwoMassesWithRandomUnitsBenchmarks.cs b/UnitsNet.Benchmark/Operators/Additions/AddTwoMassesWithRandomUnitsBenchmarks.cs index 1c456fb9ac..e7a921104a 100644 --- a/UnitsNet.Benchmark/Operators/Additions/AddTwoMassesWithRandomUnitsBenchmarks.cs +++ b/UnitsNet.Benchmark/Operators/Additions/AddTwoMassesWithRandomUnitsBenchmarks.cs @@ -26,8 +26,8 @@ public class AddTwoMassesWithRandomUnitsBenchmarks [GlobalSetup] public void PrepareQuantities() { - _operands = _random.GetRandomQuantities(LeftValue, Mass.Units, NbOperations) - .Zip(_random.GetRandomQuantities(RightValue, Mass.Units, NbOperations), + _operands = _random.GetRandomQuantities(LeftValue, Mass.Units.ToArray(), NbOperations) + .Zip(_random.GetRandomQuantities(RightValue, Mass.Units.ToArray(), NbOperations), (left, right) => (left, right)) .ToArray(); } diff --git a/UnitsNet.Benchmark/Operators/Additions/AddTwoTemperatureDeltasWithRandomUnitsBenchmarks.cs b/UnitsNet.Benchmark/Operators/Additions/AddTwoTemperatureDeltasWithRandomUnitsBenchmarks.cs index a3239d3010..3f61a4973d 100644 --- a/UnitsNet.Benchmark/Operators/Additions/AddTwoTemperatureDeltasWithRandomUnitsBenchmarks.cs +++ b/UnitsNet.Benchmark/Operators/Additions/AddTwoTemperatureDeltasWithRandomUnitsBenchmarks.cs @@ -26,8 +26,8 @@ public class AddTwoTemperatureDeltasWithRandomUnitsBenchmarks [GlobalSetup] public void PrepareQuantities() { - _operands = _random.GetRandomQuantities(LeftValue, TemperatureDelta.Units, NbOperations) - .Zip(_random.GetRandomQuantities(RightValue, TemperatureDelta.Units, NbOperations), + _operands = _random.GetRandomQuantities(LeftValue, TemperatureDelta.Units.ToArray(), NbOperations) + .Zip(_random.GetRandomQuantities(RightValue, TemperatureDelta.Units.ToArray(), NbOperations), (left, right) => (left, right)) .ToArray(); } diff --git a/UnitsNet.Benchmark/Operators/Additions/AddTwoTemperatureDeltasWithSameUnitsBenchmarks.cs b/UnitsNet.Benchmark/Operators/Additions/AddTwoTemperatureDeltasWithSameUnitsBenchmarks.cs index 03c93cfee9..963bc588dd 100644 --- a/UnitsNet.Benchmark/Operators/Additions/AddTwoTemperatureDeltasWithSameUnitsBenchmarks.cs +++ b/UnitsNet.Benchmark/Operators/Additions/AddTwoTemperatureDeltasWithSameUnitsBenchmarks.cs @@ -29,8 +29,8 @@ public class AddTwoTemperatureDeltasWithSameUnitsBenchmarks [GlobalSetup] public void PrepareQuantities() { - _operands = _random.GetRandomQuantities(LeftValue, TemperatureDelta.Units, NbOperations) - .Zip(_random.GetRandomQuantities(RightValue, TemperatureDelta.Units, NbOperations), + _operands = _random.GetRandomQuantities(LeftValue, TemperatureDelta.Units.ToArray(), NbOperations) + .Zip(_random.GetRandomQuantities(RightValue, TemperatureDelta.Units.ToArray(), NbOperations), (left, right) => (left, right)) .ToArray(); } diff --git a/UnitsNet.Benchmark/Operators/Additions/AddTwoVolumesWithRandomUnitsBenchmarks.cs b/UnitsNet.Benchmark/Operators/Additions/AddTwoVolumesWithRandomUnitsBenchmarks.cs index dcf3224e0b..b0cde2daa1 100644 --- a/UnitsNet.Benchmark/Operators/Additions/AddTwoVolumesWithRandomUnitsBenchmarks.cs +++ b/UnitsNet.Benchmark/Operators/Additions/AddTwoVolumesWithRandomUnitsBenchmarks.cs @@ -26,8 +26,8 @@ public class AddTwoVolumesWithRandomUnitsBenchmarks [GlobalSetup] public void PrepareQuantities() { - _operands = _random.GetRandomQuantities(LeftValue, Volume.Units, NbOperations) - .Zip(_random.GetRandomQuantities(RightValue, Volume.Units, NbOperations), + _operands = _random.GetRandomQuantities(LeftValue, Volume.Units.ToArray(), NbOperations) + .Zip(_random.GetRandomQuantities(RightValue, Volume.Units.ToArray(), NbOperations), (left, right) => (left, right)) .ToArray(); } diff --git a/UnitsNet.Benchmark/Operators/Additions/SumOfMassesWithRandomUnitsBenchmarks.cs b/UnitsNet.Benchmark/Operators/Additions/SumOfMassesWithRandomUnitsBenchmarks.cs index 696242b9b7..3a59f6b6ca 100644 --- a/UnitsNet.Benchmark/Operators/Additions/SumOfMassesWithRandomUnitsBenchmarks.cs +++ b/UnitsNet.Benchmark/Operators/Additions/SumOfMassesWithRandomUnitsBenchmarks.cs @@ -25,7 +25,7 @@ public class SumOfMassesWithRandomUnitsBenchmarks [GlobalSetup] public void PrepareQuantities() { - _quantities = _random.GetRandomQuantities(Value, Mass.Units, NbOperations).ToArray(); + _quantities = _random.GetRandomQuantities(Value, Mass.Units.ToArray(), NbOperations).ToArray(); } [Benchmark(Baseline = true)] diff --git a/UnitsNet.Benchmark/Operators/Additions/SumOfTemperatureDeltasWithRandomUnitsBenchmarks.cs b/UnitsNet.Benchmark/Operators/Additions/SumOfTemperatureDeltasWithRandomUnitsBenchmarks.cs index 65e135e3ae..cd9877e6bc 100644 --- a/UnitsNet.Benchmark/Operators/Additions/SumOfTemperatureDeltasWithRandomUnitsBenchmarks.cs +++ b/UnitsNet.Benchmark/Operators/Additions/SumOfTemperatureDeltasWithRandomUnitsBenchmarks.cs @@ -25,7 +25,7 @@ public class SumOfTemperatureDeltasWithRandomUnitsBenchmarks [GlobalSetup] public void PrepareQuantities() { - _quantities = _random.GetRandomQuantities(Value, TemperatureDelta.Units, NbOperations).ToArray(); + _quantities = _random.GetRandomQuantities(Value, TemperatureDelta.Units.ToArray(), NbOperations).ToArray(); } [Benchmark(Baseline = true)] diff --git a/UnitsNet.Benchmark/Operators/Additions/SumOfVolumesWithRandomUnitsBenchmarks.cs b/UnitsNet.Benchmark/Operators/Additions/SumOfVolumesWithRandomUnitsBenchmarks.cs index 76beab1238..c7bf590527 100644 --- a/UnitsNet.Benchmark/Operators/Additions/SumOfVolumesWithRandomUnitsBenchmarks.cs +++ b/UnitsNet.Benchmark/Operators/Additions/SumOfVolumesWithRandomUnitsBenchmarks.cs @@ -25,7 +25,7 @@ public class SumOfVolumesWithRandomUnitsBenchmarks [GlobalSetup] public void PrepareQuantities() { - _quantities = _random.GetRandomQuantities(Value, Volume.Units, NbOperations).ToArray(); + _quantities = _random.GetRandomQuantities(Value, Volume.Units.ToArray(), NbOperations).ToArray(); Quantity.From(Value, Volume.BaseUnit); // TODO we need a better way to "disable" the lazy loading of the _quantitiesByUnitType (QuantityInfoLookup) Console.Out.WriteLine("Quantities prepared: starting unit = {0}", _quantities[0].Unit); } diff --git a/UnitsNet.Benchmark/Operators/Additions/SumOfVolumesWithRandomUnitsWithIteratorBenchmarks.cs b/UnitsNet.Benchmark/Operators/Additions/SumOfVolumesWithRandomUnitsWithIteratorBenchmarks.cs index 624a0ee775..2cf21ae684 100644 --- a/UnitsNet.Benchmark/Operators/Additions/SumOfVolumesWithRandomUnitsWithIteratorBenchmarks.cs +++ b/UnitsNet.Benchmark/Operators/Additions/SumOfVolumesWithRandomUnitsWithIteratorBenchmarks.cs @@ -24,7 +24,7 @@ public class SumOfVolumesWithRandomUnitsWithIteratorBenchmarks [GlobalSetup] public void PrepareQuantities() { - _quantities = _random.GetRandomQuantities(Value, Volume.Units, NbOperations).ToArray(); + _quantities = _random.GetRandomQuantities(Value, Volume.Units.ToArray(), NbOperations).ToArray(); Quantity.From(Value, Volume.BaseUnit); // TODO we need a better way to "disable" the lazy loading of the _quantitiesByUnitType (QuantityInfoLookup) Console.Out.WriteLine("Quantities prepared: starting unit = {0}", _quantities[0].Unit); } diff --git a/UnitsNet.Benchmark/Operators/Divisions/MassDividedByVolumeWithRandomUnitsBenchmarks.cs b/UnitsNet.Benchmark/Operators/Divisions/MassDividedByVolumeWithRandomUnitsBenchmarks.cs index e880d6185d..581a282700 100644 --- a/UnitsNet.Benchmark/Operators/Divisions/MassDividedByVolumeWithRandomUnitsBenchmarks.cs +++ b/UnitsNet.Benchmark/Operators/Divisions/MassDividedByVolumeWithRandomUnitsBenchmarks.cs @@ -26,8 +26,8 @@ public class MassDividedByVolumeWithRandomUnitsBenchmarks [GlobalSetup] public void PrepareQuantities() { - _operands = _random.GetRandomQuantities(MassValue, Mass.Units, NbOperations) - .Zip(_random.GetRandomQuantities(VolumeValue, Volume.Units, NbOperations), (mass, volume) => (volume: mass, density: volume)) + _operands = _random.GetRandomQuantities(MassValue, Mass.Units.ToArray(), NbOperations) + .Zip(_random.GetRandomQuantities(VolumeValue, Volume.Units.ToArray(), NbOperations), (mass, volume) => (volume: mass, density: volume)) .ToArray(); } diff --git a/UnitsNet.Benchmark/Operators/Multiplications/VolumeTimesDensityWithRandomUnitsBenchmarks.cs b/UnitsNet.Benchmark/Operators/Multiplications/VolumeTimesDensityWithRandomUnitsBenchmarks.cs index db2a40c94b..b9e4c2f56b 100644 --- a/UnitsNet.Benchmark/Operators/Multiplications/VolumeTimesDensityWithRandomUnitsBenchmarks.cs +++ b/UnitsNet.Benchmark/Operators/Multiplications/VolumeTimesDensityWithRandomUnitsBenchmarks.cs @@ -26,8 +26,8 @@ public class VolumeTimesDensityWithRandomUnitsBenchmarks [GlobalSetup] public void PrepareQuantities() { - _operands = _random.GetRandomQuantities(VolumeValue, Volume.Units, NbOperations) - .Zip(_random.GetRandomQuantities(DensityValue, Density.Units, NbOperations), + _operands = _random.GetRandomQuantities(VolumeValue, Volume.Units.ToArray(), NbOperations) + .Zip(_random.GetRandomQuantities(DensityValue, Density.Units.ToArray(), NbOperations), (volume, density) => (volume, density)) .ToArray(); } diff --git a/UnitsNet.Serialization.JsonNet/AbbreviatedUnitsConverter.cs b/UnitsNet.Serialization.JsonNet/AbbreviatedUnitsConverter.cs index 27eb4149fe..10fc5b9b19 100644 --- a/UnitsNet.Serialization.JsonNet/AbbreviatedUnitsConverter.cs +++ b/UnitsNet.Serialization.JsonNet/AbbreviatedUnitsConverter.cs @@ -29,7 +29,7 @@ public class AbbreviatedUnitsConverter : NullableQuantityConverter private readonly UnitAbbreviationsCache _abbreviations; private readonly IEqualityComparer _propertyComparer; - private readonly IDictionary _quantities; + private readonly IReadOnlyDictionary _quantities; private readonly UnitParser _unitParser; /// @@ -45,7 +45,7 @@ public AbbreviatedUnitsConverter() /// /// The comparer used to compare the property/quantity names (e.g. StringComparer.OrdinalIgnoreCase) public AbbreviatedUnitsConverter(IEqualityComparer comparer) - : this(new Dictionary(Quantity.ByName, comparer), UnitsNetSetup.Default.UnitAbbreviations, comparer) + : this(Quantity.ByName, UnitsNetSetup.Default.UnitAbbreviations, comparer) { } @@ -55,7 +55,7 @@ public AbbreviatedUnitsConverter(IEqualityComparer comparer) /// The dictionary of quantity names /// The unit abbreviations used for the serialization /// The comparer used to compare the property names (e.g. StringComparer.OrdinalIgnoreCase) - public AbbreviatedUnitsConverter(IDictionary quantities, UnitAbbreviationsCache abbreviations, IEqualityComparer propertyComparer) + public AbbreviatedUnitsConverter(IReadOnlyDictionary quantities, UnitAbbreviationsCache abbreviations, IEqualityComparer propertyComparer) { _quantities = quantities; _abbreviations = abbreviations; diff --git a/UnitsNet.Serialization.JsonNet/UnitsNetBaseJsonConverter.cs b/UnitsNet.Serialization.JsonNet/UnitsNetBaseJsonConverter.cs index 87b5309c6d..2ba1d5aead 100644 --- a/UnitsNet.Serialization.JsonNet/UnitsNetBaseJsonConverter.cs +++ b/UnitsNet.Serialization.JsonNet/UnitsNetBaseJsonConverter.cs @@ -21,7 +21,7 @@ public abstract class UnitsNetBaseJsonConverter : NullableQuantityConverter /// Register custom types so that the converter can instantiate these quantities. - /// Instead of calling , the will be used to instantiate the object. + /// Instead of calling , the will be used to instantiate the object. /// It is therefore assumed that the constructor of is specified with new T(double value, typeof() unit). /// Registering the same multiple times, it will overwrite the one registered. /// diff --git a/UnitsNet.Tests/CustomQuantities/HowMuch.cs b/UnitsNet.Tests/CustomQuantities/HowMuch.cs index 40ed9752e6..6703471241 100644 --- a/UnitsNet.Tests/CustomQuantities/HowMuch.cs +++ b/UnitsNet.Tests/CustomQuantities/HowMuch.cs @@ -1,4 +1,5 @@ using System; +using UnitsNet.Units; namespace UnitsNet.Tests.CustomQuantities { @@ -6,51 +7,62 @@ namespace UnitsNet.Tests.CustomQuantities /// /// Example of a custom/third-party quantity implementation, for plugging in quantities and units at runtime. /// - public readonly struct HowMuch : IQuantity + public readonly struct HowMuch : IQuantity { public HowMuch(double value, HowMuchUnit unit) { Unit = unit; Value = value; } - + public static HowMuch From(double value, HowMuchUnit unit) { return new HowMuch(value, unit); } - public bool Equals(IQuantity? other, IQuantity tolerance) => throw new NotImplementedException(); + public double As(HowMuchUnit unit) + { + throw new NotImplementedException(); + } - Enum IQuantity.Unit => Unit; public HowMuchUnit Unit { get; } public double Value { get; } #region IQuantity - - private static readonly HowMuch Zero = new HowMuch(0, HowMuchUnit.Some); - - public BaseDimensions Dimensions => BaseDimensions.Dimensionless; - - public static QuantityInfo Info = new( + + public static readonly QuantityInfo Info = new( nameof(HowMuch), - typeof(HowMuchUnit), - new UnitInfo[] + HowMuchUnit.Some, + new UnitDefinition[] { - new UnitInfo(HowMuchUnit.Some, "Some", BaseUnits.Undefined, nameof(HowMuch)), - new UnitInfo(HowMuchUnit.ATon, "Tons", BaseUnits.Undefined, nameof(HowMuch)), - new UnitInfo(HowMuchUnit.AShitTon, "ShitTons", BaseUnits.Undefined, nameof(HowMuch)), + new(HowMuchUnit.Some, "Some", BaseUnits.Undefined), + new(HowMuchUnit.ATon, "Tons", new BaseUnits(mass: MassUnit.Tonne)), + new(HowMuchUnit.AShitTon, "ShitTons", BaseUnits.Undefined) }, - HowMuchUnit.Some, - Zero, - BaseDimensions.Dimensionless); + new HowMuch(0, HowMuchUnit.Some), + new BaseDimensions(0, 1, 0, 0, 0, 0, 0), + From); + + QuantityInfo IQuantity.QuantityInfo + { + get => Info; + } + + QuantityInfo IQuantity.QuantityInfo + { + get => Info; + } QuantityInfo IQuantity.QuantityInfo { - get { return Info; } + get => Info; } - - public UnitKey UnitKey + + public BaseDimensions Dimensions => Info.BaseDimensions; + + + UnitKey IQuantity.UnitKey { get => UnitKey.ForUnit(Unit); } @@ -65,12 +77,38 @@ public IQuantity ToUnit(Enum unit) throw new ArgumentException("Must be of type HowMuchUnit.", nameof(unit)); } + public IQuantity ToUnit(HowMuchUnit unit) + { + throw new NotImplementedException(); + } + + IQuantity IQuantity.ToUnit(UnitSystem unitSystem) + { + throw new NotImplementedException(); + } + public IQuantity ToUnit(UnitSystem unitSystem) => throw new NotImplementedException(); public override string ToString() => $"{Value} {Unit}"; public string ToString(string? format, IFormatProvider? formatProvider) => $"HowMuch ({format}, {formatProvider})"; public string ToString(IFormatProvider? provider) => $"HowMuch ({provider})"; + public bool Equals(IQuantity? other, IQuantity tolerance) => throw new NotImplementedException(); + + public bool Equals(HowMuch other, HowMuch tolerance) + { + throw new NotImplementedException(); + } + +#if !NET + + QuantityInfo IQuantity.QuantityInfo + { + get { return Info; } + } + + Enum IQuantity.Unit => Unit; +#endif #endregion } } diff --git a/UnitsNet.Tests/QuantityInfoTest.cs b/UnitsNet.Tests/QuantityInfoTest.cs index 420f726fcf..623bea64c2 100644 --- a/UnitsNet.Tests/QuantityInfoTest.cs +++ b/UnitsNet.Tests/QuantityInfoTest.cs @@ -1,264 +1,671 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; using System.Diagnostics.CodeAnalysis; -using System.Linq; +using System.Resources; using UnitsNet.Tests.CustomQuantities; -using UnitsNet.Units; -using Xunit; -namespace UnitsNet.Tests +namespace UnitsNet.Tests; + +public class QuantityInfoTest { - public class QuantityInfoTest - { - private UnitInfo[] _lengthUnitInfos = Length.Info.UnitInfos.Cast().ToArray(); - - [Fact] - public void Constructor_AssignsProperties() - { - var expectedZero = Length.FromCentimeters(10); - UnitInfo[] expectedUnitInfos = { - new(LengthUnit.Centimeter, "Centimeters", new BaseUnits(LengthUnit.Centimeter), nameof(Length)), - new(LengthUnit.Kilometer, "Kilometers", new BaseUnits(LengthUnit.Kilometer), nameof(Length)) - }; - var expectedBaseUnit = LengthUnit.Centimeter; - var expectedBaseDimensions = Length.BaseDimensions; - - var info = new QuantityInfo(nameof(Length), typeof(LengthUnit), expectedUnitInfos, - expectedBaseUnit, expectedZero, expectedBaseDimensions); - - Assert.Equal(expectedZero, info.Zero); - Assert.Equal("Length", info.Name); - Assert.Equal(expectedUnitInfos, info.UnitInfos); - Assert.Equal(expectedBaseDimensions, info.BaseDimensions); - } - - [Fact] - public void Constructor_AssignsPropertiesForCustomQuantity() - { - var expectedZero = new HowMuch(10, HowMuchUnit.Some); - UnitInfo[] expectedUnitInfos = { - new(HowMuchUnit.Some, "Some", BaseUnits.Undefined, nameof(HowMuch)), - new(HowMuchUnit.ATon, "Tons", BaseUnits.Undefined, nameof(HowMuch)), - new(HowMuchUnit.AShitTon, "ShitTons", BaseUnits.Undefined, nameof(HowMuch)) - }; - var expectedBaseUnit = HowMuchUnit.Some; - var expectedBaseDimensions = BaseDimensions.Dimensionless; - - var info = new QuantityInfo(nameof(HowMuch), typeof(HowMuchUnit), expectedUnitInfos, - expectedBaseUnit, expectedZero, expectedBaseDimensions); - - Assert.Equal(expectedZero, info.Zero); - Assert.Equal(nameof(HowMuch), info.Name); - Assert.Equal(expectedUnitInfos, info.UnitInfos); - Assert.Equal(expectedBaseDimensions, info.BaseDimensions); - } - - [Fact] - public void GenericsConstructor_AssignsProperties() - { - var expectedZero = Length.FromCentimeters(10); - UnitInfo[] expectedUnitInfos = { - new(LengthUnit.Centimeter, "Centimeters", new BaseUnits(LengthUnit.Centimeter), nameof(Length)), - new(LengthUnit.Kilometer,"Kilometers", new BaseUnits(LengthUnit.Kilometer), nameof(Length)) - }; - var expectedBaseUnit = LengthUnit.Centimeter; - var expectedBaseDimensions = Length.BaseDimensions; - - var info = new QuantityInfo(nameof(Length), expectedUnitInfos, expectedBaseUnit, expectedZero, expectedBaseDimensions); - Assert.Equal(expectedZero, info.Zero); - Assert.Equal("Length", info.Name); - Assert.Equal(expectedUnitInfos, info.UnitInfos); - Assert.Equal(expectedBaseDimensions, info.BaseDimensions); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void Constructor_GivenNullAsUnitInfos_ThrowsArgumentNullException() - { - Assert.Throws(() => new QuantityInfo(nameof(Length), typeof(LengthUnit), - null!, Length.BaseUnit, Length.Zero, Length.BaseDimensions)); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void GenericsConstructor_GivenNullAsUnitInfos_ThrowsArgumentNullException() - { - Assert.Throws(() => new QuantityInfo(nameof(Length), - null!, Length.BaseUnit, Length.Zero, Length.BaseDimensions)); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void Constructor_GivenNullAsBaseUnit_ThrowsArgumentNullException() - { - Assert.Throws(() => new QuantityInfo(nameof(Length), typeof(LengthUnit), - _lengthUnitInfos, null!, Length.Zero, Length.BaseDimensions)); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void Constructor_GivenNullAsZero_ThrowsArgumentNullException() - { - Assert.Throws(() => new QuantityInfo(nameof(Length), typeof(LengthUnit), - _lengthUnitInfos, Length.BaseUnit, null!, Length.BaseDimensions)); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void GenericsConstructor_GivenNullAsZero_ThrowsArgumentNullException() - { - Assert.Throws(() => new QuantityInfo(nameof(Length), - Length.Info.UnitInfos, Length.BaseUnit, null!, Length.BaseDimensions)); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void Constructor_GivenNullAsBaseDimensions_ThrowsArgumentNullException() - { - Assert.Throws(() => new QuantityInfo(nameof(Length), typeof(LengthUnit), - _lengthUnitInfos, Length.BaseUnit, Length.Zero, null!)); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void GenericsConstructor_GivenNullAsBaseDimensions_ThrowsArgumentNullException() - { - Assert.Throws(() => new QuantityInfo(nameof(Length), - Length.Info.UnitInfos, Length.BaseUnit, Length.Zero, null!)); - } - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void Constructor2_GivenNullAsUnitInfos_ThrowsArgumentNullException() - { - Assert.Throws(() => new QuantityInfo(Length.Info.Name, typeof(LengthUnit), - null!, Length.BaseUnit, Length.Zero, Length.BaseDimensions)); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void GenericsConstructor2_GivenNullAsUnitInfos_ThrowsArgumentNullException() - { - Assert.Throws(() => new QuantityInfo(Length.Info.Name, - null!, Length.BaseUnit, Length.Zero, Length.BaseDimensions)); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void Constructor2_GivenNullAsBaseUnit_ThrowsArgumentNullException() - { - Assert.Throws(() => new QuantityInfo(Length.Info.Name, typeof(LengthUnit), - _lengthUnitInfos, null!, Length.Zero, Length.BaseDimensions)); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void Constructor2_GivenNullAsZero_ThrowsArgumentNullException() - { - Assert.Throws(() => new QuantityInfo(Length.Info.Name, typeof(LengthUnit), - _lengthUnitInfos, Length.BaseUnit, null!, Length.BaseDimensions)); - } - - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void GenericsConstructor2_GivenNullAsZero_ThrowsArgumentNullException() + [Fact] + [SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local")] + public void Constructor_AssignsProperties() + { + UnitDefinition[] expectedUnitInfos = + [ + new(LengthUnit.Centimeter, "Centimeters", new BaseUnits(LengthUnit.Centimeter)), + new(LengthUnit.Kilometer, "Kilometers", new BaseUnits(LengthUnit.Kilometer)) + ]; + const LengthUnit expectedBaseUnit = LengthUnit.Centimeter; + var expectedZero = Length.FromCentimeters(10); + BaseDimensions expectedBaseDimensions = Length.BaseDimensions; + var abbreviations = new ResourceManager("UnitsNet.GeneratedCode.Resources.Length", typeof(Length).Assembly); + + var quantityInfo = new QuantityInfo(nameof(Length), expectedBaseUnit, expectedUnitInfos, expectedZero, expectedBaseDimensions, + Length.From, abbreviations); + + Assert.Equal(nameof(Length), quantityInfo.Name); + Assert.Equal(typeof(Length), quantityInfo.QuantityType); + Assert.Equal(typeof(LengthUnit), quantityInfo.UnitType); + + // BaseUnitInfo + Assert.Multiple(() => + { + UnitInfo baseUnitInfo = quantityInfo.BaseUnitInfo; + Assert.Equal(expectedBaseUnit, baseUnitInfo.Value); + }, () => + { + QuantityInfo genericQuantityInfo = quantityInfo; + UnitInfo unitInfos = genericQuantityInfo.BaseUnitInfo; + Assert.Equal(quantityInfo.BaseUnitInfo, unitInfos); + }, () => + { + QuantityInfo genericQuantityInfo = quantityInfo; + UnitInfo unitInfos = genericQuantityInfo.BaseUnitInfo; + Assert.Equal(quantityInfo.BaseUnitInfo, unitInfos); + }); + + // UnitInfos + Assert.Multiple(() => + { + Assert.Collection(quantityInfo.UnitInfos, firstUnitInfo => + { + Assert.Equal(LengthUnit.Centimeter, firstUnitInfo.Value); + Assert.Equal(expectedUnitInfos[0].Name, firstUnitInfo.Name); + Assert.Equal(expectedUnitInfos[0].PluralName, firstUnitInfo.PluralName); + Assert.Equal(expectedUnitInfos[0].BaseUnits, firstUnitInfo.BaseUnits); + Assert.Equal(quantityInfo, firstUnitInfo.QuantityInfo); + }, secondUnitInfo => + { + Assert.Equal(LengthUnit.Kilometer, secondUnitInfo.Value); + Assert.Equal(expectedUnitInfos[1].Name, secondUnitInfo.Name); + Assert.Equal(expectedUnitInfos[1].PluralName, secondUnitInfo.PluralName); + Assert.Equal(expectedUnitInfos[1].BaseUnits, secondUnitInfo.BaseUnits); + Assert.Equal(quantityInfo, secondUnitInfo.QuantityInfo); + }); + }, () => + { + QuantityInfo genericQuantityInfo = quantityInfo; + IReadOnlyCollection> unitInfos = genericQuantityInfo.UnitInfos; + Assert.Equal(quantityInfo.UnitInfos, unitInfos); + }, () => + { + QuantityInfo genericQuantityInfo = quantityInfo; + IReadOnlyCollection unitInfos = genericQuantityInfo.UnitInfos; + Assert.Equal(quantityInfo.UnitInfos, unitInfos); + }); + + // Zero + Assert.Multiple(() => + { + Length zero = quantityInfo.Zero; + Assert.Equal(expectedZero, zero); + }, () => + { + QuantityInfo genericQuantityInfo = quantityInfo; + IQuantity zero = genericQuantityInfo.Zero; + Assert.Equal(expectedZero, zero); + }, () => + { + QuantityInfo genericQuantityInfo = quantityInfo; + IQuantity zero = genericQuantityInfo.Zero; + Assert.Equal(expectedZero, zero); + }); + + Assert.Equal(expectedBaseDimensions, quantityInfo.BaseDimensions); + Assert.Equal(abbreviations, quantityInfo.UnitAbbreviations); + } + + [Fact] + [SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local")] + public void Constructor_AssignsPropertiesForCustomQuantity() + { + UnitDefinition[] expectedUnitInfos = + [ + new(HowMuchUnit.Some, "Some", BaseUnits.Undefined), + new(HowMuchUnit.ATon, "Tons", BaseUnits.Undefined), + new(HowMuchUnit.AShitTon, "ShitTons", BaseUnits.Undefined) + ]; + const HowMuchUnit expectedBaseUnit = HowMuchUnit.Some; + var expectedZero = new HowMuch(10, HowMuchUnit.Some); + BaseDimensions expectedBaseDimensions = BaseDimensions.Dimensionless; + + var quantityInfo = new QuantityInfo(nameof(HowMuch), expectedBaseUnit, + expectedUnitInfos, expectedZero, expectedBaseDimensions, HowMuch.From); + + Assert.Equal(nameof(HowMuch), quantityInfo.Name); + Assert.Equal(typeof(HowMuch), quantityInfo.QuantityType); + Assert.Equal(typeof(HowMuchUnit), quantityInfo.UnitType); + Assert.Equal(expectedBaseUnit, quantityInfo.BaseUnitInfo.Value); + Assert.Collection(quantityInfo.UnitInfos, firstUnitInfo => + { + Assert.Equal(HowMuchUnit.Some, firstUnitInfo.Value); + Assert.Equal(expectedUnitInfos[0].Name, firstUnitInfo.Name); + Assert.Equal(expectedUnitInfos[0].PluralName, firstUnitInfo.PluralName); + Assert.Equal(expectedUnitInfos[0].BaseUnits, firstUnitInfo.BaseUnits); + Assert.Equal(quantityInfo, firstUnitInfo.QuantityInfo); + }, secondUnitInfo => + { + Assert.Equal(HowMuchUnit.ATon, secondUnitInfo.Value); + Assert.Equal(expectedUnitInfos[1].Name, secondUnitInfo.Name); + Assert.Equal(expectedUnitInfos[1].PluralName, secondUnitInfo.PluralName); + Assert.Equal(expectedUnitInfos[1].BaseUnits, secondUnitInfo.BaseUnits); + Assert.Equal(quantityInfo, secondUnitInfo.QuantityInfo); + }, thirdUnitInfo => + { + Assert.Equal(HowMuchUnit.AShitTon, thirdUnitInfo.Value); + Assert.Equal(expectedUnitInfos[2].Name, thirdUnitInfo.Name); + Assert.Equal(expectedUnitInfos[2].PluralName, thirdUnitInfo.PluralName); + Assert.Equal(expectedUnitInfos[2].BaseUnits, thirdUnitInfo.BaseUnits); + Assert.Equal(quantityInfo, thirdUnitInfo.QuantityInfo); + }); + Assert.Equal(expectedZero, quantityInfo.Zero); + Assert.Equal(expectedBaseDimensions, quantityInfo.BaseDimensions); + Assert.Null(quantityInfo.UnitAbbreviations); + } + + [Fact] + public void Constructor_WithoutZero_UsesZeroBaseUnit() + { + UnitDefinition[] expectedUnitInfos = + [ + new(HowMuchUnit.Some, "Some", BaseUnits.Undefined) + ]; + const HowMuchUnit expectedBaseUnit = HowMuchUnit.Some; + BaseDimensions expectedBaseDimensions = BaseDimensions.Dimensionless; + var expectedZero = new HowMuch(0, HowMuchUnit.Some); + + var quantityInfo = new QuantityInfo(nameof(HowMuch), expectedBaseUnit, + expectedUnitInfos, expectedBaseDimensions, HowMuch.From); + + Assert.Equal(expectedZero, quantityInfo.Zero); + Assert.Equal(nameof(HowMuch), quantityInfo.Name); + Assert.Equal(expectedBaseUnit, quantityInfo.BaseUnitInfo.Value); + Assert.Single(quantityInfo.UnitInfos, unitInfo => + expectedBaseUnit == unitInfo.Value && + expectedUnitInfos[0].Name == unitInfo.Name && + expectedUnitInfos[0].PluralName == unitInfo.PluralName && + expectedUnitInfos[0].BaseUnits == unitInfo.BaseUnits + ); + Assert.Equal(expectedBaseDimensions, quantityInfo.BaseDimensions); + Assert.Null(quantityInfo.UnitAbbreviations); + } + + [Fact] + public void Constructor_WithoutName_UsesDefaultQuantityTypeName() + { + UnitDefinition[] expectedUnitInfos = + [ + new(HowMuchUnit.Some, "Some", BaseUnits.Undefined) + ]; + const HowMuchUnit expectedBaseUnit = HowMuchUnit.Some; + var expectedZero = new HowMuch(0, HowMuchUnit.Some); + BaseDimensions expectedBaseDimensions = BaseDimensions.Dimensionless; + var abbreviations = new ResourceManager("UnitsNet.GeneratedCode.Resources.Length", typeof(Length).Assembly); + + var quantityInfo = + new QuantityInfo(expectedBaseUnit, expectedUnitInfos, expectedBaseDimensions, HowMuch.From, abbreviations); + + Assert.Equal(expectedZero, quantityInfo.Zero); + Assert.Equal(nameof(HowMuch), quantityInfo.Name); + Assert.Equal(expectedBaseUnit, quantityInfo.BaseUnitInfo.Value); + Assert.Single(quantityInfo.UnitInfos, firstUnitInfo => + expectedBaseUnit == firstUnitInfo.Value && + expectedUnitInfos[0].Name == firstUnitInfo.Name && + expectedUnitInfos[0].PluralName == firstUnitInfo.PluralName && + expectedUnitInfos[0].BaseUnits == firstUnitInfo.BaseUnits + ); + Assert.Equal(expectedBaseDimensions, quantityInfo.BaseDimensions); + Assert.Equal(abbreviations, quantityInfo.UnitAbbreviations); + } + + [Fact] + [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] + public void Constructor_GivenNullAsQuantityName_ThrowsArgumentNullException() + { + Assert.Throws(() => new QuantityInfo(null!, + LengthUnit.Meter, Length.Info.UnitInfos, Length.BaseDimensions, Length.From)); + } + + [Fact] + [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] + public void Constructor_GivenNullAsUnitInfos_ThrowsArgumentNullException() + { + IEnumerable> nullCollection = null!; + Assert.Throws(() => new QuantityInfo(nameof(Length), + LengthUnit.Meter, nullCollection, Length.BaseDimensions, Length.From)); + } + + [Fact] + [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] + public void Constructor_GivenANullUnitInfo_ThrowsArgumentNullException() + { + IEnumerable> collectionContainingANull = [null!]; +#if NET + Assert.Throws(() => new QuantityInfo(nameof(Length), + LengthUnit.Meter, collectionContainingANull, Length.BaseDimensions, Length.From)); +#else + Assert.Throws(() => new QuantityInfo(nameof(Length), + LengthUnit.Meter, collectionContainingANull, Length.BaseDimensions, Length.From)); +#endif + } + + [Fact] + [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] + public void Constructor_GivenNullAsBaseDimensions_ThrowsArgumentNullException() + { + Assert.Throws(() => new QuantityInfo(nameof(Length), + LengthUnit.Meter, Length.Info.UnitInfos, null!, Length.From)); + } + + [Fact] + public void Constructor_GivenAMissingBaseUnitDefinition_ThrowsUnitNotFoundException() + { + Assert.Throws(() => + new QuantityInfo(Length.BaseUnit, [], Length.BaseDimensions, Length.From)); + } + + [Fact] + public void GetUnitInfoFor_GivenNullAsBaseUnits_ThrowsArgumentNullException() + { + Assert.Multiple(() => { - Assert.Throws(() => new QuantityInfo(Length.Info.Name, - Length.Info.UnitInfos, Length.BaseUnit, null!, Length.BaseDimensions)); - } + QuantityInfo quantityInfo = Length.Info; + Assert.Throws(() => quantityInfo.GetUnitInfoFor(null!)); + }, () => + { + QuantityInfo quantityInfo = Length.Info; + Assert.Throws(() => quantityInfo.GetUnitInfoFor(null!)); + }, () => + { + QuantityInfo quantityInfo = Length.Info; + Assert.Throws(() => quantityInfo.GetUnitInfoFor(null!)); + }); + } - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void Constructor2_GivenNullAsBaseDimensions_ThrowsArgumentNullException() + [Fact] + public void GetUnitInfoFor_GivenBaseUnitsWithNoMatch_ThrowsInvalidOperationException() + { + var baseUnitsWithNoMatch = new BaseUnits(mass: MassUnit.Kilogram); + Assert.Multiple(() => + { + QuantityInfo quantityInfo = Length.Info; + Assert.Throws(() => quantityInfo.GetUnitInfoFor(baseUnitsWithNoMatch)); + }, () => + { + QuantityInfo quantityInfo = Length.Info; + Assert.Throws(() => quantityInfo.GetUnitInfoFor(baseUnitsWithNoMatch)); + }, () => { - Assert.Throws(() => new QuantityInfo(Length.Info.Name, typeof(LengthUnit), - _lengthUnitInfos, Length.BaseUnit, Length.Zero, null!)); - } + QuantityInfo quantityInfo = Length.Info; + Assert.Throws(() => quantityInfo.GetUnitInfoFor(baseUnitsWithNoMatch)); + }); + } - [Fact] - [SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] - public void GenericsConstructor2_GivenNullAsBaseDimensions_ThrowsArgumentNullException() + [Fact] + public void GetUnitInfoFor_GivenBaseUnitsWithMultipleMatches_ThrowsInvalidOperationException() + { + var baseUnits = new BaseUnits(LengthUnit.Meter); + UnitDefinition[] duplicateBaseUnits = + [ + new(LengthUnit.Meter, "Meters", baseUnits), + new(LengthUnit.Foot, "Feet", baseUnits) + ]; + BaseDimensions dimensions = Length.BaseDimensions; + Assert.Multiple(() => + { + var quantityInfo = new QuantityInfo(LengthUnit.Meter, duplicateBaseUnits, dimensions, Length.From); + Assert.Throws(() => quantityInfo.GetUnitInfoFor(baseUnits)); + }, () => + { + QuantityInfo genericQuantityInfo = new QuantityInfo(LengthUnit.Meter, duplicateBaseUnits, dimensions, Length.From); + Assert.Throws(() => genericQuantityInfo.GetUnitInfoFor(baseUnits)); + }, () => { - Assert.Throws(() => new QuantityInfo(Length.Info.Name, - Length.Info.UnitInfos, Length.BaseUnit, Length.Zero, null!)); - } + QuantityInfo genericQuantityInfo = new QuantityInfo(LengthUnit.Meter, duplicateBaseUnits, dimensions, Length.From); + Assert.Throws(() => genericQuantityInfo.GetUnitInfoFor(baseUnits)); + }); + } + + [Fact] + public void GetUnitInfoFor_GivenBaseUnitsWithOneMatch_ReturnsTheMatch() + { + var baseUnitsWithOneMatch = new BaseUnits(LengthUnit.Foot); + UnitInfo expectedUnitInfo = Length.Info[LengthUnit.Foot]; - [Fact] - public void GetUnitInfoFor_GivenNullAsBaseUnits_ThrowsArgumentNullException() + Assert.Multiple(() => { - Assert.Throws(() => Length.Info.GetUnitInfoFor(null!)); - } + QuantityInfo quantityInfo = Length.Info; - [Fact] - public void GetUnitInfoFor_GivenBaseUnitsWithNoMatch_ThrowsInvalidOperationException() + UnitInfo result = quantityInfo.GetUnitInfoFor(baseUnitsWithOneMatch); + + Assert.Equal(expectedUnitInfo, result); + }, () => { - var baseUnitsWithNoMatch = new BaseUnits(mass: MassUnit.Kilogram); - Assert.Throws(() => Length.Info.GetUnitInfoFor(baseUnitsWithNoMatch)); - } + QuantityInfo quantityInfo = Length.Info; + + UnitInfo result = quantityInfo.GetUnitInfoFor(baseUnitsWithOneMatch); - [Fact] - public void GetUnitInfoFor_GivenBaseUnitsWithMultipleMatches_ThrowsInvalidOperationException() + Assert.Equal(expectedUnitInfo, result); + }, () => { - var baseUnits = new BaseUnits(LengthUnit.Meter); + QuantityInfo quantityInfo = Length.Info; - var quantityInfo = new QuantityInfo(Length.Info.Name, - new UnitInfo[] { - new(LengthUnit.Meter, "Meters", baseUnits, nameof(Length)), - new(LengthUnit.Foot, "Feet", baseUnits, nameof(Length)) - }, - LengthUnit.Meter, Length.Zero, Length.BaseDimensions); + UnitInfo result = quantityInfo.GetUnitInfoFor(baseUnitsWithOneMatch); - Assert.Throws(() => quantityInfo.GetUnitInfoFor(baseUnits)); - } + Assert.Equal(expectedUnitInfo, result); + }); + } - [Fact] - public void GetUnitInfosFor_GivenNullAsBaseUnits_ThrowsArgumentNullException() + [Fact] + public void GetUnitInfosFor_GivenNullAsBaseUnits_ThrowsArgumentNullException() + { + Assert.Multiple(() => + { + QuantityInfo quantityInfo = Length.Info; + Assert.Throws(() => quantityInfo.GetUnitInfosFor(null!)); + }, () => { - Assert.Throws(() => Length.Info.GetUnitInfosFor(null!)); - } + QuantityInfo quantityInfo = Length.Info; + Assert.Throws(() => quantityInfo.GetUnitInfosFor(null!)); + }, () => + { + QuantityInfo quantityInfo = Length.Info; + Assert.Throws(() => quantityInfo.GetUnitInfosFor(null!)); + }); + } - [Fact] - public void GetUnitInfosFor_GivenBaseUnitsWithNoMatch_ReturnsEmpty() + [Fact] + public void GetUnitInfosFor_GivenBaseUnitsWithNoMatch_ReturnsEmpty() + { + var baseUnitsWithNoMatch = new BaseUnits(mass: MassUnit.Kilogram); + Assert.Multiple(() => + { + QuantityInfo quantityInfo = Length.Info; + + IEnumerable> result = quantityInfo.GetUnitInfosFor(baseUnitsWithNoMatch); + + Assert.Empty(result); + }, () => { - var baseUnitsWithNoMatch = new BaseUnits(mass: MassUnit.Kilogram); - var result = Length.Info.GetUnitInfosFor(baseUnitsWithNoMatch); + QuantityInfo quantityInfo = Length.Info; + + IEnumerable> result = quantityInfo.GetUnitInfosFor(baseUnitsWithNoMatch); + + Assert.Empty(result); + }, () => + { + QuantityInfo quantityInfo = Length.Info; + + IEnumerable result = quantityInfo.GetUnitInfosFor(baseUnitsWithNoMatch); + Assert.Empty(result); - } - - [Fact] - public void GetUnitInfosFor_GivenBaseUnitsWithOneMatch_ReturnsOneMatch() - { - var baseUnitsWithOneMatch = new BaseUnits(LengthUnit.Foot); - var result = Length.Info.GetUnitInfosFor(baseUnitsWithOneMatch); - Assert.Collection(result, element1 => Assert.Equal(LengthUnit.Foot, element1.Value)); - } - - [Fact] - [SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local")] - public void GetUnitInfosFor_GivenBaseUnitsWithMultipleMatches_ReturnsMultipleMatches() - { - var baseUnits = new BaseUnits(LengthUnit.Meter); - - var quantityInfo = new QuantityInfo(Length.Info.Name, - new UnitInfo[] { - new(LengthUnit.Meter, "Meters", baseUnits, nameof(Length)), - new(LengthUnit.Foot, "Feet", baseUnits, nameof(Length)) }, - LengthUnit.Meter, Length.Zero, Length.BaseDimensions); - - var result = quantityInfo.GetUnitInfosFor(baseUnits); - - Assert.Collection(result, - element1 => - { - Assert.Equal(LengthUnit.Meter, element1.Value); - Assert.Equal(baseUnits, element1.BaseUnits); - }, - element2 => - { - Assert.Equal(LengthUnit.Foot, element2.Value); - Assert.Equal(baseUnits, element2.BaseUnits); - } ); - } + }); + } + + [Fact] + public void GetUnitInfosFor_GivenBaseUnitsWithOneMatch_ReturnsOneMatch() + { + var baseUnitsWithOneMatch = new BaseUnits(LengthUnit.Foot); + IEnumerable> result = Length.Info.GetUnitInfosFor(baseUnitsWithOneMatch); + Assert.Collection(result, element1 => Assert.Equal(LengthUnit.Foot, element1.Value)); + } + + [Fact] + public void GetUnitInfosFor_GivenBaseUnitsWithMultipleMatches_ReturnsMultipleMatches() + { + var baseUnits = new BaseUnits(LengthUnit.Meter); + + var quantityInfo = new QuantityInfo(Length.Info.Name, + LengthUnit.Meter, new UnitDefinition[] { new(LengthUnit.Meter, "Meters", baseUnits), new(LengthUnit.Foot, "Feet", baseUnits) }, + Length.BaseDimensions, Length.From); + + var result = quantityInfo.GetUnitInfosFor(baseUnits).ToList(); + + Assert.Equal(2, result.Count); + Assert.Contains(result, info => info.Value == LengthUnit.Meter && info.BaseUnits == baseUnits); + Assert.Contains(result, info => info.Value == LengthUnit.Foot && info.BaseUnits == baseUnits); + } + + // [Fact] + // public void TryGetUnitInfo_WithEnum_ReturnsTheExpectedResult() + // { + // QuantityInfo quantityInfo = HowMuch.Info; + // + // var success = quantityInfo.TryGetUnitInfo(HowMuchUnit.ATon, out UnitInfo? unitInfo); + // + // Assert.True(success); + // Assert.Equal(HowMuchUnit.ATon, unitInfo!.Value); + // } + // + // [Fact] + // public void TryGetUnitInfo_WithInvalidEnum_ReturnsTheExpectedResult() + // { + // QuantityInfo quantityInfo = HowMuch.Info; + // + // var success = quantityInfo.TryGetUnitInfo(LengthUnit.Meter, out UnitInfo? unitInfo); + // + // Assert.False(success); + // Assert.Null(unitInfo); + // } + + [Fact] + public void TryGetUnitInfo_WithUnit_ReturnsTheExpectedResult() + { + QuantityInfo quantityInfo = Mass.Info; + + var success = quantityInfo.TryGetUnitInfo(MassUnit.Milligram, out UnitInfo? unitInfo); + + Assert.True(success); + Assert.Equal(MassUnit.Milligram, unitInfo!.Value); + } + + [Fact] + public void TryGetUnitInfo_WithInvalidUnit_ReturnsTheExpectedResult() + { + QuantityInfo quantityInfo = Mass.Info; + + var success = quantityInfo.TryGetUnitInfo((MassUnit)(-1), out UnitInfo? unitInfo); + + Assert.False(success); + Assert.Null(unitInfo); + } + + [Fact] + public void Indexer_WithValidEnum_ReturnsTheTargetUnitInfo() + { + QuantityInfo quantityInfo = HowMuch.Info; + + UnitInfo unitInfo = quantityInfo[HowMuchUnit.ATon]; + + Assert.Equal(HowMuchUnit.ATon, unitInfo.Value); + } + + [Fact] + public void Indexer_WithInvalidEnum_ThrowsKeyNotFoundException() + { + QuantityInfo quantityInfo = HowMuch.Info; + + Assert.Throws(() => quantityInfo[(HowMuchUnit)(-1)]); + } + + [Fact] + public void Indexer_WithValidUnit_ReturnsTheTargetUnitInfo() + { + QuantityInfo quantityInfo = Mass.Info; + + UnitInfo unitInfo = quantityInfo[MassUnit.Milligram]; + + Assert.Equal(MassUnit.Milligram, unitInfo.Value); + } + + [Fact] + public void Indexer_WithInvalidUnit_ThrowsKeyNotFoundException() + { + QuantityInfo quantityInfo = Mass.Info; + + Assert.Throws(() => quantityInfo[(MassUnit)(-1)]); + } + + [Fact] + public void Indexer_WithValidUnitKey_ReturnsTheTargetUnitInfo() + { + QuantityInfo quantityInfo = Mass.Info; + var unitKey = UnitKey.ForUnit(MassUnit.Milligram); + + UnitInfo unitInfo = quantityInfo[unitKey]; + + Assert.Equal(MassUnit.Milligram, unitInfo.Value); + } + + [Fact] + public void Indexer_WithInvalidUnitKeyType_ThrowsInvalidOperationException() + { + QuantityInfo quantityInfo = Mass.Info; + var unitKey = UnitKey.ForUnit(LengthUnit.Meter); + + Assert.Throws(() => quantityInfo[unitKey]); + } + + [Fact] + public void Indexer_WithUnknownUnitKeyValue_ThrowsInvalidOperationException() + { + QuantityInfo quantityInfo = Mass.Info; + var unitKey = new UnitKey(typeof(MassUnit), -1); + + Assert.Throws(() => quantityInfo[unitKey]); + } + + [Fact] + public void UntypedIndexer_WithUnknownUnitKeyValue_ThrowsInvalidOperationException() + { + QuantityInfo quantityInfo = Mass.Info; + var unitKey = new UnitKey(typeof(MassUnit), -1); + + Assert.Throws(() => quantityInfo[unitKey]); + } + + [Theory] + [InlineData(1, MassUnit.Kilogram)] + [InlineData(2, MassUnit.Milligram)] + public void From_ValueAndUnit_ReturnsTheExpectedQuantity(double value, MassUnit unit) + { + Assert.Multiple(() => + { + QuantityInfo quantityInfo = Mass.Info; + + Mass quantity = quantityInfo.From(value, unit); + + Assert.Equal(value, quantity.Value); + Assert.Equal(unit, quantity.Unit); + }, () => + { + QuantityInfo quantityInfo = Mass.Info; + + IQuantity quantity = quantityInfo.From(value, unit); + + Assert.Equal(value, quantity.Value); + Assert.Equal(unit, quantity.Unit); + }, () => + { + QuantityInfo quantityInfo = Mass.Info; + + IQuantity quantity = quantityInfo.From(value, unit); + + Assert.Equal(value, quantity.Value); + Assert.Equal(unit, quantity.Unit); + }); } + + [Theory] + [InlineData(1, MassUnit.Kilogram)] + [InlineData(2, MassUnit.Milligram)] + public void From_ValueAndUnitKey_WithSameUnitType_ReturnsTheExpectedQuantity(double value, MassUnit unit) + { + IQuantityInstanceInfo quantityInfo = Mass.Info; + + Mass quantity = quantityInfo.Create(value, UnitKey.ForUnit(unit)); + + Assert.Equal(value, quantity.Value); + Assert.Equal(unit, quantity.Unit); + } + + [Theory] + [InlineData(1, MassUnit.Kilogram)] + [InlineData(2, MassUnit.Milligram)] + public void From_ValueAnEnum_WithSameUnitType_ReturnsTheExpectedQuantity(double value, Enum unit) + { + QuantityInfo quantityInfo = Mass.Info; + + IQuantity quantity = quantityInfo.From(value, unit); + + Assert.Equal(value, quantity.Value); + Assert.Equal(unit, quantity.Unit); + } + + [Fact] + public void From_ValueAndUnitKey_WIthDifferentUnitType_ThrowsArgumentException() + { + IQuantityInstanceInfo quantityInfo = Mass.Info; + var unitKey = UnitKey.ForUnit(LengthUnit.Meter); + + Assert.Throws(() => quantityInfo.Create(1, unitKey)); + } + + [Fact] + public void From_ValueAndEnum_WIthDifferentUnitType_ThrowsInvalidOperationException() + { + QuantityInfo quantityInfo = Mass.Info; + + Assert.Throws(() => quantityInfo.From(1, LengthUnit.Meter)); + } + + [Fact] + public void ToString_ReturnsTheQuantityName() + { + QuantityInfo quantityInfo = Mass.Info; + + Assert.Equal(quantityInfo.Name, quantityInfo.ToString()); + } + +#if NET + + [Fact] + public void Constructor_WithoutDelegate_UsesTheDefaultQuantityFrom() + { + UnitDefinition[] expectedUnitInfos = + [ + new(HowMuchUnit.Some, "Some", BaseUnits.Undefined) + ]; + const string quantityName = "How Much?"; + const HowMuchUnit expectedBaseUnit = HowMuchUnit.Some; + var expectedZero = new HowMuch(0, HowMuchUnit.Some); + BaseDimensions expectedBaseDimensions = BaseDimensions.Dimensionless; + var abbreviations = new ResourceManager("UnitsNet.GeneratedCode.Resources.Length", typeof(Length).Assembly); + + var quantityInfo = new QuantityInfo(quantityName, expectedBaseUnit, expectedUnitInfos, expectedBaseDimensions, abbreviations); + + Assert.Equal(quantityName, quantityInfo.Name); + Assert.Equal(expectedZero, quantityInfo.Zero); + Assert.Equal(expectedBaseUnit, quantityInfo.BaseUnitInfo.Value); + Assert.Single(quantityInfo.UnitInfos, firstUnitInfo => + expectedBaseUnit == firstUnitInfo.Value && + expectedUnitInfos[0].Name == firstUnitInfo.Name && + expectedUnitInfos[0].PluralName == firstUnitInfo.PluralName && + expectedUnitInfos[0].BaseUnits == firstUnitInfo.BaseUnits + ); + Assert.Equal(expectedBaseDimensions, quantityInfo.BaseDimensions); + Assert.Equal(abbreviations, quantityInfo.UnitAbbreviations); + } + + [Fact] + public void Constructor_WithoutNameOrDelegate_UsesTheDefaultQuantityNameAndFrom() + { + UnitDefinition[] expectedUnitInfos = + [ + new(HowMuchUnit.Some, "Some", BaseUnits.Undefined) + ]; + const HowMuchUnit expectedBaseUnit = HowMuchUnit.Some; + var expectedZero = new HowMuch(0, HowMuchUnit.Some); + BaseDimensions expectedBaseDimensions = BaseDimensions.Dimensionless; + var abbreviations = new ResourceManager("UnitsNet.GeneratedCode.Resources.Length", typeof(Length).Assembly); + + var quantityInfo = new QuantityInfo(expectedBaseUnit, expectedUnitInfos, expectedBaseDimensions, abbreviations); + + Assert.Equal(expectedZero, quantityInfo.Zero); + Assert.Equal(nameof(HowMuch), quantityInfo.Name); + Assert.Equal(expectedBaseUnit, quantityInfo.BaseUnitInfo.Value); + Assert.Single(quantityInfo.UnitInfos, firstUnitInfo => + expectedBaseUnit == firstUnitInfo.Value && + expectedUnitInfos[0].Name == firstUnitInfo.Name && + expectedUnitInfos[0].PluralName == firstUnitInfo.PluralName && + expectedUnitInfos[0].BaseUnits == firstUnitInfo.BaseUnits + ); + Assert.Equal(expectedBaseDimensions, quantityInfo.BaseDimensions); + Assert.Equal(abbreviations, quantityInfo.UnitAbbreviations); + } + +#endif } diff --git a/UnitsNet.Tests/QuantityTest.cs b/UnitsNet.Tests/QuantityTest.cs index d683968a39..94b3e49926 100644 --- a/UnitsNet.Tests/QuantityTest.cs +++ b/UnitsNet.Tests/QuantityTest.cs @@ -1,12 +1,7 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Collections.Generic; using System.Globalization; -using System.Linq; -using UnitsNet.Units; -using Xunit; using static System.Globalization.CultureInfo; namespace UnitsNet.Tests @@ -20,7 +15,7 @@ public class QuantityTest [InlineData(double.NaN)] [InlineData(double.PositiveInfinity)] [InlineData(double.NegativeInfinity)] - public void From_GivenNaNOrInfinity_DoNotThrowsArgumentException(double value) + public void From_GivenNaNOrInfinity_DoesNotThrowArgumentException(double value) { var exception = Record.Exception(() => Quantity.From(value, LengthUnit.Centimeter)); @@ -43,6 +38,12 @@ public void TryFrom_GivenNullUnit_ReturnsFalse() Enum? nullUnit = null; Assert.False(Quantity.TryFrom(1, nullUnit, out IQuantity? _)); } + + [Fact] + public void TryFrom_GivenUnknownUnitType_ReturnsFalse() + { + Assert.False(Quantity.TryFrom(1, ConsoleColor.Red, out IQuantity? _)); + } [Fact] public void From_GivenValueAndUnit_ReturnsQuantity() @@ -52,6 +53,14 @@ public void From_GivenValueAndUnit_ReturnsQuantity() Assert.Equal(Pressure.FromMegabars(3), Quantity.From(3, PressureUnit.Megabar)); } + [Fact] + public void FromQuantityInfo_ReturnsQuantityWithBaseUnit() + { + IQuantity quantity = Quantity.FromQuantityInfo(Length.Info, 1); + Assert.Equal(1, quantity.Value); + Assert.Equal(Length.BaseUnit, quantity.Unit); + } + [Fact] public void ByName_GivenLength_ReturnsQuantityInfoForLength() { @@ -215,7 +224,7 @@ public void Types_ReturnsKnownQuantityTypes() { var knownQuantities = new List { Length.Info, Force.Info, Mass.Info }; - ICollection types = Quantity.ByName.Values; + IEnumerable types = Quantity.ByName.Values; Assert.Superset(knownQuantities.ToHashSet(), types.ToHashSet()); } diff --git a/UnitsNet.Tests/QuantityTests.cs b/UnitsNet.Tests/QuantityTests.cs index e50a25ba23..26e61b917c 100644 --- a/UnitsNet.Tests/QuantityTests.cs +++ b/UnitsNet.Tests/QuantityTests.cs @@ -1,10 +1,7 @@ // 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 UnitsNet.Units; -using Xunit; namespace UnitsNet.Tests { @@ -153,7 +150,7 @@ public void From_InvalidUnitName_ThrowsUnitNotFoundException() [Fact] public void FromUnitAbbreviation_ReturnsQuantity() { - IQuantity q = Quantity.FromUnitAbbreviation(5, "cm"); + IQuantity q = Quantity.FromUnitAbbreviation(CultureInfo.InvariantCulture, 5, "cm"); Assert.Equal(5, q.Value); Assert.Equal(LengthUnit.Centimeter, q.Unit); } @@ -161,16 +158,16 @@ public void FromUnitAbbreviation_ReturnsQuantity() [Fact] public void TryFromUnitAbbreviation_ReturnsQuantity() { - Assert.True(Quantity.TryFromUnitAbbreviation(5, "cm", out IQuantity? q)); - Assert.Equal(LengthUnit.Centimeter, q!.Unit); + Assert.True(Quantity.TryFromUnitAbbreviation(5, "cm", out IQuantity? quantity)); + Assert.Equal(LengthUnit.Centimeter, quantity!.Unit); } [Fact] public void FromUnitAbbreviation_MatchingCulture_ReturnsQuantity() { - IQuantity q = Quantity.FromUnitAbbreviation(Russian, 5, "см"); - Assert.Equal(5, q.Value); - Assert.Equal(LengthUnit.Centimeter, q.Unit); + IQuantity quantity = Quantity.FromUnitAbbreviation(Russian, 5, "см"); + Assert.Equal(5, quantity.Value); + Assert.Equal(LengthUnit.Centimeter, quantity.Unit); } [Fact] diff --git a/UnitsNet.Tests/QuantityTypeConverterTest.cs b/UnitsNet.Tests/QuantityTypeConverterTest.cs index ca15b50c97..13ba43058d 100644 --- a/UnitsNet.Tests/QuantityTypeConverterTest.cs +++ b/UnitsNet.Tests/QuantityTypeConverterTest.cs @@ -1,12 +1,11 @@ // 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.ComponentModel; using System.Globalization; using System.Reflection; +using UnitsNet.Tests.CustomQuantities; using UnitsNet.Tests.Helpers; -using Xunit; namespace UnitsNet.Tests { @@ -122,6 +121,53 @@ public void ConvertFrom_GivenQuantityStringAndContextWithDefaultUnitAndConvertTo Assert.Equal(expectedUnit, convertedValue.Unit); } + [Theory] + [InlineData(1.234)] + [InlineData(-1.234)] + [InlineData(double.NaN)] + [InlineData(double.PositiveInfinity)] + [InlineData(double.NegativeInfinity)] + public void ConvertFrom_GivenQuantityStringAndNullCulture_ReturnsQuantityConvertedToUnit(double expectedValue) + { + var str = expectedValue.ToString(CultureInfo.CurrentCulture) + "mm"; + var converter = new QuantityTypeConverter(); + + var convertedValue = (Length)converter.ConvertFrom(null, null, str)!; + + Assert.Equal(expectedValue, convertedValue.Value); + Assert.Equal(LengthUnit.Millimeter, convertedValue.Unit); + } + + [Fact] + public void ConvertFrom_WithUnknownQuantity_ThrowsQuantityNotFoundException() + { + var converter = new QuantityTypeConverter(); + ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); + + Assert.Throws(() => converter.ConvertFrom(context, Culture, "42 st")); + } + + [Fact] + public void ConvertFrom_WithUnknownUnit_ThrowsUnitNotFoundException() + { + var converter = new QuantityTypeConverter(); + ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] + { + new DefaultUnitAttribute(HowMuchUnit.Some) + }); + + Assert.Throws(() => converter.ConvertFrom(context, Culture, "42")); + } + + [Fact] + public void ConvertFrom_GivenUnsupportedValueType_ThrowsNotSupportedException() + { + var converter = new QuantityTypeConverter(); + ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); + + Assert.Throws(() => converter.ConvertFrom(context, Culture, DateTime.Now)); + } + [Fact] public void ConvertFrom_GivenEmptyString_ThrowsNotSupportedException() { @@ -132,12 +178,12 @@ public void ConvertFrom_GivenEmptyString_ThrowsNotSupportedException() } [Fact] - public void ConvertFrom_GivenWrongQuantity_ThrowsUnitNotFoundException() + public void ConvertFrom_GivenWrongQuantityStringFormat_ThrowsFormatException() { var converter = new QuantityTypeConverter(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); - Assert.Throws(() => converter.ConvertFrom(context, Culture, "1m^2")); + Assert.Throws(() => converter.ConvertFrom(context, Culture, "1 meter")); } [Theory] diff --git a/UnitsNet.Tests/UnitInfoTests.cs b/UnitsNet.Tests/UnitInfoTests.cs index e05e3a51f9..1b428c442d 100644 --- a/UnitsNet.Tests/UnitInfoTests.cs +++ b/UnitsNet.Tests/UnitInfoTests.cs @@ -1,27 +1,125 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using UnitsNet.Units; -using Xunit; +namespace UnitsNet.Tests; -namespace UnitsNet.Tests +public class UnitInfoTests { - public class UnitInfoTests + [Fact] + public void UnitInfo_QuantityInfo_ReturnsTheParentQuantityInfo() { - [Fact] - public void ConstructorTest() + Assert.Multiple(() => { - var unitInfo = new UnitInfo(LengthUnit.Meter, "Meters", new BaseUnits(LengthUnit.Meter), nameof(Length)); - Assert.Equal(LengthUnit.Meter, unitInfo.Value); - Assert.Equal(LengthUnit.Meter.ToString(), unitInfo.Name); - } + UnitInfo unitInfo = Mass.Info.BaseUnitInfo; - [Fact] - public void GenericConstructorTest() + QuantityInfo quantityInfo = unitInfo.QuantityInfo; + + Assert.Equal(Mass.Info, quantityInfo); + }, () => + { + UnitInfo unitInfo = Mass.Info.BaseUnitInfo; + + QuantityInfo quantityInfo = unitInfo.QuantityInfo; + + Assert.Equal(Mass.Info, quantityInfo); + }); + } + + [Fact] + public void UnitInfo_QuantityName_ReturnsTheParentQuantityName() + { + Assert.Equal(Mass.Info.Name, Mass.Info.BaseUnitInfo.QuantityName); + } + + [Fact] + public void UnitInfo_Value_ReturnsTheUnitValue() + { + Assert.Multiple(() => + { + UnitInfo unitInfo = Mass.Info.BaseUnitInfo; + + MassUnit unitInfoValue = unitInfo.Value; + + Assert.Equal(Mass.BaseUnit, unitInfoValue); + }, () => + { + UnitInfo unitInfo = Mass.Info.BaseUnitInfo; + + MassUnit unitInfoValue = unitInfo.Value; + + Assert.Equal(Mass.BaseUnit, unitInfoValue); + }, () => + { + UnitInfo unitInfo = Mass.Info.BaseUnitInfo; + + Enum unitInfoValue = unitInfo.Value; + + Assert.Equal(Mass.BaseUnit, unitInfoValue); + }); + } + + [Fact] + public void UnitInfo_UnitKey_ReturnsTheUnitKey() + { + Assert.Multiple(() => + { + UnitInfo unitInfo = Mass.Info.BaseUnitInfo; + + UnitKey unitInfoValue = unitInfo.UnitKey; + + Assert.Equal(Mass.BaseUnit, unitInfoValue); + }, () => + { + UnitInfo unitInfo = Mass.Info.BaseUnitInfo; + + UnitKey unitInfoValue = unitInfo.UnitKey; + + Assert.Equal(Mass.BaseUnit, unitInfoValue); + }, () => + { + UnitInfo unitInfo = Mass.Info.BaseUnitInfo; + + UnitKey unitInfoValue = unitInfo.UnitKey; + + Assert.Equal(Mass.BaseUnit, unitInfoValue); + }); + } + + [Theory] + [InlineData(1, MassUnit.Kilogram)] + [InlineData(2, MassUnit.Milligram)] + public void UnitInfo_FromValueAndUnit_ReturnsTheExpectedQuantity(double value, MassUnit unit) + { + var expectedQuantity = new Mass(value, unit); + Assert.Multiple(() => + { + UnitInfo unitInfo = Mass.Info[unit]; + + Mass quantity = unitInfo.From(value); + + Assert.Equal(expectedQuantity, quantity); + }, () => + { + UnitInfo unitInfo = Mass.Info[unit]; + + IQuantity quantity = unitInfo.From(value); + + Assert.Equal(expectedQuantity, quantity); + }, () => { - var unitInfo = new UnitInfo(LengthUnit.Meter, "Meters", new BaseUnits(LengthUnit.Meter), nameof(Length)); - Assert.Equal(LengthUnit.Meter, unitInfo.Value); - Assert.Equal(LengthUnit.Meter.ToString(), unitInfo.Name); - } + UnitInfo unitInfo = Mass.Info[unit]; + + IQuantity quantity = unitInfo.From(value); + + Assert.Equal(expectedQuantity, quantity); + }); + } + + [Fact] + public void ToString_ReturnsTheUnitName() + { + UnitInfo unitInfo = Mass.Info.BaseUnitInfo; + + Assert.Equal(unitInfo.Name, unitInfo.ToString()); } } diff --git a/UnitsNet.Tests/UnitParserTests.cs b/UnitsNet.Tests/UnitParserTests.cs index 63131e4483..de3fa48a26 100644 --- a/UnitsNet.Tests/UnitParserTests.cs +++ b/UnitsNet.Tests/UnitParserTests.cs @@ -1,11 +1,8 @@ // 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 UnitsNet.Tests.CustomQuantities; -using UnitsNet.Units; -using Xunit; namespace UnitsNet.Tests { @@ -92,6 +89,12 @@ public void Parse_NullAbbreviation_Throws_ArgumentNullException() Assert.Throws(() => UnitsNetSetup.Default.UnitParser.Parse(null!, typeof(LengthUnit))); } + [Fact] + public void Parse_UnknownUnitTypeThrowsUnitNotFoundException() + { + Assert.Throws(() => UnitsNetSetup.Default.UnitParser.Parse("something")); + } + [Fact] public void Parse_UnknownAbbreviationThrowsUnitNotFoundException() { @@ -198,11 +201,17 @@ public void TryParse_WithNullAbbreviation_ReturnsFalse() Assert.False(success); }, () => { - var success = unitParser.TryParse(null, [], null, out UnitInfo? _); + var success = unitParser.TryParse(null, [], null, out UnitInfo? _); Assert.False(success); }); } + [Fact] + public void TryParse_UnknownUnitType_ReturnsFalse() + { + Assert.False(UnitsNetSetup.Default.UnitParser.TryParse("something", out StringComparison _)); + } + [Theory] [InlineData("")] [InlineData("z^2")] @@ -217,7 +226,7 @@ public void TryParse_WithAmbiguousUnits_ReturnsFalse() { UnitParser unitParser = UnitsNetSetup.Default.UnitParser; Assert.False(unitParser.TryParse("pt", CultureInfo.InvariantCulture, out LengthUnit _)); - Assert.False(unitParser.TryParse("pt", Length.Info.UnitInfos, CultureInfo.InvariantCulture, out UnitInfo? _)); + Assert.False(unitParser.TryParse("pt", Length.Info.UnitInfos, CultureInfo.InvariantCulture, out UnitInfo? _)); } [Theory] @@ -248,8 +257,7 @@ public void TryGetUnitFromAbbreviation_WithLocalizedUnit_MatchingCulture_Returns var success = unitParser.TryGetUnitFromAbbreviation("кг", formatProvider, out UnitInfo? unitInfo); Assert.True(success); - Assert.NotNull(unitInfo); - Assert.Equal(MassUnit.Kilogram, unitInfo.Value); + Assert.Equal(Mass.Info[MassUnit.Kilogram], unitInfo); } [Fact] @@ -261,8 +269,7 @@ public void TryGetUnitFromAbbreviation_MatchingFallbackCulture_ReturnsTrue() var success = unitParser.TryGetUnitFromAbbreviation("kg", formatProvider, out UnitInfo? unitInfo); Assert.True(success); - Assert.NotNull(unitInfo); - Assert.Equal(MassUnit.Kilogram, unitInfo.Value); + Assert.Equal(Mass.Info[MassUnit.Kilogram], unitInfo); } [Fact] diff --git a/UnitsNet.Tests/UnitsNet.Tests.csproj b/UnitsNet.Tests/UnitsNet.Tests.csproj index d23783c60f..1e2a8c7f2f 100644 --- a/UnitsNet.Tests/UnitsNet.Tests.csproj +++ b/UnitsNet.Tests/UnitsNet.Tests.csproj @@ -3,9 +3,11 @@ net8.0;net9.0 latest + enable true CS0618 enable + xunit @@ -36,4 +38,9 @@ + + + + + diff --git a/UnitsNet/CustomCode/Quantity.cs b/UnitsNet/CustomCode/Quantity.cs index d606ea55da..abc4e309e8 100644 --- a/UnitsNet/CustomCode/Quantity.cs +++ b/UnitsNet/CustomCode/Quantity.cs @@ -1,44 +1,41 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using UnitsNet.Units; +using System.Globalization; namespace UnitsNet { - public partial class Quantity + public static partial class Quantity { private static QuantityInfoLookup Quantities => UnitsNetSetup.Default.QuantityInfoLookup; + private static QuantityParser QuantityParser => UnitsNetSetup.Default.QuantityParser; private static UnitParser UnitParser => UnitsNetSetup.Default.UnitParser; /// - /// All quantity names of , such as "Length" and "Mass". + /// All quantity names, such as "Length" and "Mass", that are present in the configuration. /// public static IReadOnlyCollection Names => Quantities.Names; /// - /// All quantity information objects, such as and . + /// All quantity information objects, such as and , that are present in the configuration. /// public static IReadOnlyList Infos => Quantities.Infos; - + /// - /// Get for a given unit enum value. + /// All QuantityInfo instances mapped by quantity name that are present in the configuration. /// - public static UnitInfo GetUnitInfo(Enum unitEnum) => Quantities.GetUnitInfo(unitEnum); + public static IReadOnlyDictionary ByName => Quantities.ByName; /// - /// Try to get for a given unit enum value. + /// Get for a given unit enum value. /// - public static bool TryGetUnitInfo(Enum unitEnum, [NotNullWhen(true)] out UnitInfo? unitInfo) => - Quantities.TryGetUnitInfo(unitEnum, out unitInfo); + public static UnitInfo GetUnitInfo(UnitKey unitEnum) => Quantities.GetUnitInfo(unitEnum); /// - /// + /// Try to get for a given unit enum value. /// - /// - /// - public static void AddUnitInfo(Enum unit, UnitInfo unitInfo) => Quantities.AddUnitInfo(unitInfo); - + public static bool TryGetUnitInfo(UnitKey unitEnum, [NotNullWhen(true)] out UnitInfo? unitInfo) + { + return Quantities.TryGetUnitInfo(unitEnum, out unitInfo); + } + /// /// Dynamically constructs a quantity from a numeric value and a unit enum value. /// @@ -46,11 +43,9 @@ public static bool TryGetUnitInfo(Enum unitEnum, [NotNullWhen(true)] out UnitInf /// Unit enum value. /// An object. /// Unit value is not a known unit enum type. - public static IQuantity From(double value, Enum unit) + public static IQuantity From(double value, UnitKey unit) { - return TryFrom(value, unit, out IQuantity? quantity) - ? quantity - : throw new UnitNotFoundException($"Unit value {unit} of type {unit.GetType()} is not a known unit enum type. Expected types like UnitsNet.Units.LengthUnit. Did you pass in a custom enum type defined outside the UnitsNet library?"); + return Quantities.From(value, unit); } /// @@ -68,7 +63,26 @@ public static IQuantity From(double value, Enum unit) /// public static IQuantity From(double value, string quantityName, string unitName) { - return From(value, Quantities.GetUnitByName(quantityName, unitName).Value); + return Quantities.GetUnitByName(quantityName, unitName).From(value); + } + + /// + /// Dynamically constructs a quantity of the given with the value in the quantity's base + /// units. + /// + /// The of the quantity to create. + /// The value to construct the quantity with. + /// The created quantity. + /// + /// This is the equivalent to: + /// quantityInfo.From(value, quantityInfo.BaseUnitInfo.Value) + /// or + /// quantityInfo.BaseUnitInfo.From(value) + /// + [Obsolete("Consider using: quantityInfo.BaseUnitInfo.From(value)")] + public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, double value) + { + return quantityInfo.BaseUnitInfo.From(value); } /// @@ -79,7 +93,7 @@ public static IQuantity From(double value, string quantityName, string unitName) /// Unit abbreviation matching is case-insensitive.
///
/// This will fail if more than one unit across all quantities share the same unit abbreviation.
- /// Prefer or instead. + /// Prefer or instead. /// /// Numeric value. /// Unit abbreviation, such as "kg" for . @@ -96,7 +110,7 @@ public static IQuantity From(double value, string quantityName, string unitName) /// Unit abbreviation matching is case-insensitive.
///
/// This will fail if more than one unit across all quantities share the same unit abbreviation.
- /// Prefer or instead. + /// Prefer or instead. /// /// The format provider to use for lookup. Defaults to if null. /// Numeric value. @@ -106,7 +120,7 @@ public static IQuantity From(double value, string quantityName, string unitName) /// Multiple units found matching the given unit abbreviation. public static IQuantity FromUnitAbbreviation(IFormatProvider? formatProvider, double value, string unitAbbreviation) { - return From(value, UnitParser.GetUnitFromAbbreviation(unitAbbreviation, formatProvider).Value); + return UnitParser.FromUnitAbbreviation(value, unitAbbreviation, formatProvider); } /// @@ -119,13 +133,31 @@ public static IQuantity FromUnitAbbreviation(IFormatProvider? formatProvider, do /// True if successful with assigned the value, otherwise false. public static bool TryFrom(double value, string quantityName, string unitName, [NotNullWhen(true)] out IQuantity? quantity) { - if (Quantities.TryGetUnitByName(quantityName, unitName, out UnitInfo? unitInfo)) + if (!Quantities.TryGetUnitByName(quantityName, unitName, out UnitInfo? unitInfo)) { - return TryFrom(value, unitInfo.Value, out quantity); + quantity = null; + return false; } - - quantity = null; - return false; + + quantity = unitInfo.From(value); + return true; + } + + /// + /// Attempts to create a quantity from the specified value and unit. + /// + /// The value of the quantity. + /// The unit of the quantity, represented as an . + /// + /// When this method returns, contains the created quantity if the conversion succeeded, + /// or null if the conversion failed. This parameter is passed uninitialized. + /// + /// + /// true if the quantity was successfully created; otherwise, false. + /// + public static bool TryFrom(double value, Enum? unit, [NotNullWhen(true)] out IQuantity? quantity) + { + return Quantities.TryFrom(value, unit, out quantity); } /// @@ -136,7 +168,7 @@ public static bool TryFrom(double value, string quantityName, string unitName, [ /// Unit abbreviation matching is case-insensitive.
///
/// This will fail if more than one unit across all quantities share the same unit abbreviation.
- /// Prefer or instead. + /// Prefer or instead. /// /// Numeric value. /// Unit abbreviation, such as "kg" for . @@ -154,7 +186,7 @@ public static bool TryFromUnitAbbreviation(double value, string unitAbbreviation /// Unit abbreviation matching is case-insensitive.
///
/// This will fail if more than one unit across all quantities share the same unit abbreviation.
- /// Prefer or instead. + /// Prefer or instead. /// /// The format provider to use for lookup. Defaults to if null. /// Numeric value. @@ -166,7 +198,8 @@ public static bool TryFromUnitAbbreviation(IFormatProvider? formatProvider, doub { if (UnitParser.TryGetUnitFromAbbreviation(unitAbbreviation, formatProvider, out UnitInfo? unitInfo)) { - return TryFrom(value, unitInfo.Value, out quantity); + quantity = unitInfo.From(value); + return true; } quantity = null; @@ -183,27 +216,37 @@ public static bool TryFromUnitAbbreviation(IFormatProvider? formatProvider, doub /// Type of quantity, such as . /// Quantity string representation, such as "1.5 kg". Must be compatible with given quantity type. /// The parsed quantity. - /// Type must be of type UnitsNet.IQuantity -or- Type is not a known quantity type. - /// Type must be of type UnitsNet.IQuantity -or- Type is not a known quantity type. + /// + /// Thrown when the is not of type . + /// + /// + /// Thrown when the specified quantity type is not registered in the current configuration. + /// + /// Thrown when the is not in the expected format. public static IQuantity Parse(IFormatProvider? formatProvider, Type quantityType, string quantityString) { - // TODO Support custom units (via the QuantityParser), currently only hardcoded built-in quantities are supported. - if (!typeof(IQuantity).IsAssignableFrom(quantityType)) - throw new ArgumentException($"Type {quantityType} must be of type UnitsNet.IQuantity."); - - if (TryParse(formatProvider, quantityType, quantityString, out IQuantity? quantity)) - return quantity; - - throw new UnitNotFoundException($"Quantity string '{quantityString}' could not be parsed to quantity '{quantityType}'."); + QuantityInfo quantityInfo = Quantities.GetQuantityInfo(quantityType); + return QuantityParser.Parse(quantityString, formatProvider, quantityInfo); } /// public static bool TryParse(Type quantityType, string quantityString, [NotNullWhen(true)] out IQuantity? quantity) { - // TODO Support custom units (via the QuantityParser), currently only hardcoded built-in quantities are supported. return TryParse(null, quantityType, quantityString, out quantity); } + /// + public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, string quantityString, [NotNullWhen(true)] out IQuantity? quantity) + { + if (Quantities.TryGetQuantityInfo(quantityType, out QuantityInfo? quantityInfo)) + { + return QuantityParser.TryParse(quantityString, formatProvider, quantityInfo, out quantity); + } + + quantity = null; + return false; + } + /// /// Get a list of quantities that has the given base dimensions. /// diff --git a/UnitsNet/CustomCode/QuantityInfo/QuantityInfoExtensions.cs b/UnitsNet/CustomCode/QuantityInfo/QuantityInfoExtensions.cs index 8d74808c67..e8b93c6d20 100644 --- a/UnitsNet/CustomCode/QuantityInfo/QuantityInfoExtensions.cs +++ b/UnitsNet/CustomCode/QuantityInfo/QuantityInfoExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using UnitsNet.Units; namespace UnitsNet; @@ -24,6 +25,62 @@ public static IEnumerable GetQuantitiesWithBaseDimensions(this IEn return quantityInfos.Where(info => info.BaseDimensions.Equals(baseDimensions)); } + + /// + /// Filters a collection of unit information based on the specified base units. + /// + /// The type of the unit information. + /// The collection of unit information to filter. + /// The base units to filter by. + /// An containing the unit information that matches the specified base units. + /// Thrown when is null. + public static IEnumerable GetUnitInfosFor(this IEnumerable unitInfos, BaseUnits baseUnits) + where TUnitInfo : UnitInfo + { + if (baseUnits is null) + { + throw new ArgumentNullException(nameof(baseUnits)); + } + + return unitInfos.Where(unitInfo => unitInfo.BaseUnits.IsSubsetOf(baseUnits)); + } + + /// + /// Gets the whose is a subset of . + /// + /// + /// Length.Info.GetUnitInfoFor(unitSystemWithFootAsLengthUnit) returns for + /// . + /// + /// The collection of unit information to filter. + /// The to check against. + /// + /// The that has that is a subset of + /// . + /// + /// is null. + /// No unit was found that is a subset of . + /// + /// More than one unit was found that is a subset of + /// . + /// + public static TUnitInfo GetUnitInfoFor(this IEnumerable unitInfos, BaseUnits baseUnits) + where TUnitInfo : UnitInfo + { + using IEnumerator enumerator = unitInfos.GetUnitInfosFor(baseUnits).GetEnumerator(); + if (!enumerator.MoveNext()) + { + throw new InvalidOperationException($"No unit was found that is a subset of {nameof(baseUnits)}"); + } + + TUnitInfo firstUnitInfo = enumerator.Current!; + if (enumerator.MoveNext()) + { + throw new InvalidOperationException($"More than one unit was found that is a subset of {nameof(baseUnits)}"); + } + + return firstUnitInfo; + } /// /// Retrieves the default unit for a specified quantity and unit system. diff --git a/UnitsNet/CustomCode/QuantityInfo/Units/UnitDefinition.cs b/UnitsNet/CustomCode/QuantityInfo/Units/UnitDefinition.cs new file mode 100644 index 0000000000..4919be5115 --- /dev/null +++ b/UnitsNet/CustomCode/QuantityInfo/Units/UnitDefinition.cs @@ -0,0 +1,64 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Diagnostics; +using UnitsNet.Units; + +namespace UnitsNet; + +/// +[DebuggerDisplay("{Name} ({Value})")] +public sealed class UnitDefinition : IUnitDefinition + where TUnit : struct, Enum +{ + /// + /// Initializes a new instance of the class for the base unit. + /// + /// The enum value for this unit, for example . + /// The plural name of the unit, such as "Centimeters". + /// The for this unit. + public UnitDefinition(TUnit value, string pluralName, BaseUnits baseUnits) + : this(value, value.ToString(), pluralName, baseUnits) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The enum value representing the unit, for example . + /// The singular name of the unit, such as "Centimeter". + /// The plural name of the unit, such as "Centimeters". + /// The associated with this unit. + /// + /// Thrown when , , , or + /// is null. + /// + public UnitDefinition(TUnit value, string singularName, string pluralName, BaseUnits baseUnits) + { + Value = value; + Name = singularName ?? throw new ArgumentNullException(nameof(singularName)); + PluralName = pluralName ?? throw new ArgumentNullException(nameof(pluralName)); + BaseUnits = baseUnits ?? throw new ArgumentNullException(nameof(baseUnits)); + } + + /// + /// The enum value of the unit, such as . + /// + public TUnit Value { get; } + + /// + /// The singular name of the unit, such as "Centimeter". + /// + public string Name { get; } + + /// + /// The plural name of the unit, such as "Centimeters". + /// + public string PluralName { get; } + + /// + /// Gets the for this unit. + /// + public BaseUnits BaseUnits { get; } +} diff --git a/UnitsNet/CustomCode/QuantityInfo/Units/UnitEqualityComparer.cs b/UnitsNet/CustomCode/QuantityInfo/Units/UnitEqualityComparer.cs new file mode 100644 index 0000000000..99f99e8c20 --- /dev/null +++ b/UnitsNet/CustomCode/QuantityInfo/Units/UnitEqualityComparer.cs @@ -0,0 +1,42 @@ +#if NETSTANDARD2_0 +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace UnitsNet; + +/// +/// Provides a custom equality comparer for enumerations that represent units. +/// +/// The enumeration type representing the unit. +/// +/// This comparer uses the class to convert the enumeration to an +/// integer, +/// which is faster than the default equality comparer on .NET Framework. On .NET 8, the performance is comparable. +/// +internal class UnitEqualityComparer : IEqualityComparer + where TUnit : struct, Enum +{ + // Singleton instance of the comparer + public static readonly UnitEqualityComparer Default = new(); + + private UnitEqualityComparer() + { + } + + public bool Equals(TUnit x, TUnit y) + { + // Use Unsafe.As to convert enums to integers for comparison + var xInt = Unsafe.As(ref x); + var yInt = Unsafe.As(ref y); + return xInt == yInt; + } + + public int GetHashCode(TUnit obj) + { + // Use Unsafe.As to convert enum to integer for hash code calculation + var objInt = Unsafe.As(ref obj); + return objInt.GetHashCode(); + } +} +#endif diff --git a/UnitsNet/CustomCode/QuantityParser.cs b/UnitsNet/CustomCode/QuantityParser.cs index 4ca6bfde4c..d542a2e59f 100644 --- a/UnitsNet/CustomCode/QuantityParser.cs +++ b/UnitsNet/CustomCode/QuantityParser.cs @@ -1,13 +1,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Text.RegularExpressions; -using UnitsNet.Units; // ReSharper disable once CheckNamespace namespace UnitsNet; @@ -36,7 +32,7 @@ public class QuantityParser private const NumberStyles ParseNumberStyles = NumberStyles.Number | NumberStyles.Float | NumberStyles.AllowExponent; private readonly UnitParser _unitParser; - + /// /// Initializes a new instance of the class using the specified /// . @@ -107,6 +103,26 @@ public TQuantity Parse(string str, IFormatProvider? format return ParseWithRegex(valueString, unitString, fromDelegate, formatProvider); } + /// + internal IQuantity Parse(string str, IFormatProvider? formatProvider, QuantityInfo quantityInfo) + { + if (str == null) throw new ArgumentNullException(nameof(str)); + str = str.Trim(); + + Regex regex = CreateRegexForQuantity(quantityInfo.UnitType, formatProvider); + + if (!TryExtractValueAndUnit(regex, str, out var valueString, out var unitString)) + { + throw new FormatException( + "Unable to parse quantity. Expected the form \"{value} {unit abbreviation}\", such as \"5.5 m\". The spacing is optional.") + { + Data = { ["input"] = str } + }; + } + + return ParseWithRegex(valueString, unitString, quantityInfo.UnitInfos, formatProvider); + } + /// /// Tries to parse a quantity from a string, such as "1.2 kg" to or "100 cm" to /// . @@ -142,47 +158,18 @@ public bool TryParse(string? str, IFormatProvider? formatP TryParseWithRegex(valueString, unitString, fromDelegate, formatProvider, out result); } - /// - /// Tries to parse a quantity from a string, such as "1.2 kg" to or "100 cm" to - /// . - /// - /// - /// Similar to - /// - /// , - /// but returns instead. This is workaround for C# not allowing to pass on 'out' param from - /// type Length to IQuantity, - /// even though they are compatible. - /// - /// The string to parse, such as "1.2 kg". - /// - /// The culture for looking up localized unit abbreviations for a language, and for parsing - /// the number formatted in this culture. Defaults to . - /// - /// A function to create a quantity given a numeric value and a unit enum value. - /// The parsed quantity if successful, otherwise null. - /// The type of quantity to create, such as . - /// - /// The type of unit enum that belongs to this quantity, such as for - /// . - /// - /// True if successful. - /// The string was null. - /// Failed to parse quantity. - internal bool TryParse(string? str, IFormatProvider? formatProvider, QuantityFromDelegate fromDelegate, - [NotNullWhen(true)] out IQuantity? result) - where TQuantity : IQuantity - where TUnitType : struct, Enum + /// + internal bool TryParse(string? str, IFormatProvider? formatProvider, QuantityInfo quantityInfo, [NotNullWhen(true)] out IQuantity? result) { - if (TryParse(str, formatProvider, fromDelegate, out TQuantity? quantityParsed)) - { - result = quantityParsed; - return true; - } - result = null; - return false; + + if (string.IsNullOrWhiteSpace(str)) return false; + str = str!.Trim(); // netstandard2.0 nullable quirk + + Regex regex = CreateRegexForQuantity(quantityInfo.UnitType, formatProvider); + + return TryExtractValueAndUnit(regex, str, out var valueString, out var unitString) && + TryParseWithRegex(valueString, unitString, quantityInfo.UnitInfos, formatProvider, out result); } internal string CreateRegexPatternForUnit(TUnitType unit, IFormatProvider? formatProvider, bool matchEntireString = true) @@ -218,6 +205,17 @@ private TQuantity ParseWithRegex(string valueString, strin return fromDelegate(value, parsedUnit); } + /// + /// Parse a string given a particular regular expression. + /// + /// Error parsing string. + private IQuantity ParseWithRegex(string valueString, string unitString, IReadOnlyList units, IFormatProvider? formatProvider) + { + var value = double.Parse(valueString, ParseNumberStyles, formatProvider); + UnitInfo unitInfo = _unitParser.Parse(unitString, units, formatProvider); + return unitInfo.From(value); + } + /// /// Parse a string given a particular regular expression. /// @@ -243,6 +241,29 @@ private bool TryParseWithRegex(string? valueString, string return true; } + /// + /// Parse a string given a particular regular expression. + /// + /// Error parsing string. + private bool TryParseWithRegex(string? valueString, string? unitString, IReadOnlyList units, IFormatProvider? formatProvider, + [NotNullWhen(true)] out IQuantity? result) + { + result = null; + + if (!double.TryParse(valueString, ParseNumberStyles, formatProvider, out var value)) + { + return false; + } + + if (!_unitParser.TryParse(unitString, units, formatProvider, out UnitInfo? parsedUnit)) + { + return false; + } + + result = parsedUnit.From(value); + return true; + } + private static bool TryExtractValueAndUnit(Regex regex, string str, [NotNullWhen(true)] out string? valueString, [NotNullWhen(true)] out string? unitString) { Match match = regex.Match(str); diff --git a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs index 05c5f21fce..f9819870b8 100644 --- a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs +++ b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs @@ -1,14 +1,10 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Reflection; using System.Resources; -using UnitsNet.Units; using AbbreviationMapKey = System.ValueTuple; // ReSharper disable once CheckNamespace @@ -88,9 +84,9 @@ public static UnitAbbreviationsCache CreateDefault() { return new UnitAbbreviationsCache(); } - + #region MapUnitToAbbreviation overloads - + /// /// Adds one or more unit abbreviation for the given unit enum value. /// This is used to dynamically add abbreviations for existing unit enums such as or to extend with third-party unit enums @@ -114,6 +110,12 @@ public void MapUnitToAbbreviation(TUnitType unit, params IEnumerable< /// The unit enum value. /// The format provider to use for lookup. Defaults to if null. /// Unit abbreviations to add. + /// + /// Thrown when the provided type is null. + /// + /// + /// Thrown when the provided type is not an enumeration type. + /// public void MapUnitToAbbreviation(Type unitType, int unitValue, IFormatProvider? formatProvider, params IEnumerable abbreviations) { MapUnitToAbbreviation(UnitKey.Create(unitType, unitValue), formatProvider, abbreviations); @@ -492,20 +494,18 @@ private static AbbreviationMapKey GetAbbreviationMapKey(UnitInfo unitInfo, Cultu private static List ReadAbbreviationsFromResourceFile(UnitInfo unitInfo, CultureInfo culture) { var abbreviationsList = new List(); - // we currently don't have any way of providing external resource dictionaries - Assembly unitAssembly = unitInfo.UnitKey.UnitEnumType.Assembly; - if (unitAssembly != typeof(UnitAbbreviationsCache).Assembly) + QuantityInfo quantityInfo = unitInfo.QuantityInfo; + ResourceManager? resourceManager = quantityInfo.UnitAbbreviations; + if (resourceManager is null) { return abbreviationsList; } - - var quantityName = unitInfo.QuantityName; - string resourceName = $"UnitsNet.GeneratedCode.Resources.{quantityName}"; - var resourceManager = new ResourceManager(resourceName, unitAssembly); var abbreviationsString = resourceManager.GetString(unitInfo.PluralName, culture); - if(abbreviationsString is not null) + if (abbreviationsString is not null) + { abbreviationsList.AddRange(abbreviationsString.Split(',')); + } return abbreviationsList; } diff --git a/UnitsNet/CustomCode/UnitParser.cs b/UnitsNet/CustomCode/UnitParser.cs index a27917f70f..b2339e9122 100644 --- a/UnitsNet/CustomCode/UnitParser.cs +++ b/UnitsNet/CustomCode/UnitParser.cs @@ -1,13 +1,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Text; -using UnitsNet.Units; // ReSharper disable once CheckNamespace namespace UnitsNet; @@ -36,7 +32,7 @@ internal UnitParser(QuantityInfoLookup quantitiesLookup) : this(new UnitAbbreviationsCache(quantitiesLookup)) { } - + /// /// Initializes a new instance of the class using the specified unit abbreviations cache. /// @@ -93,7 +89,9 @@ public static UnitParser CreateDefault() /// /// The format provider to use for lookup. Defaults to if null. /// - /// + /// Unit enum value, such as . + /// No quantity found matching the unit type. + /// No units match the abbreviation. public TUnitType Parse(string unitAbbreviation, IFormatProvider? formatProvider = null) where TUnitType : struct, Enum { @@ -114,6 +112,9 @@ public TUnitType Parse(string unitAbbreviation, IFormatProvider? form /// Unit enum type, such as and . /// The format provider to use for lookup. Defaults to if null. /// Unit enum value, such as . + /// The or the is null. + /// The is not a valid enumeration type. + /// No quantity found matching the unit type. /// No units match the abbreviation. /// More than one unit matches the abbreviation. public Enum Parse(string unitAbbreviation, Type unitType, IFormatProvider? formatProvider = null) @@ -586,4 +587,25 @@ public bool TryGetUnitFromAbbreviation([NotNullWhen(true)]string? unitAbbreviati return unitAbbreviationsPairs; } + + /// + /// Dynamically construct a quantity from a numeric value and a unit abbreviation. + /// + /// + /// This method is currently not optimized for performance and will enumerate all units and their unit abbreviations + /// each time.
+ /// Unit abbreviation matching in the overload is case-insensitive.
+ ///
+ /// This will fail if more than one unit across all quantities share the same unit abbreviation.
+ ///
+ /// Numeric value. + /// Unit abbreviation, such as "kg" for . + /// The format provider to use for lookup. Defaults to if null. + /// An object. + /// Unit abbreviation is not known. + /// Multiple units found matching the given unit abbreviation. + internal IQuantity FromUnitAbbreviation(double value, string unitAbbreviation, IFormatProvider? formatProvider) + { + return GetUnitFromAbbreviation(unitAbbreviation, formatProvider).From(value); + } } diff --git a/UnitsNet/CustomCode/UnitsNetSetup.cs b/UnitsNet/CustomCode/UnitsNetSetup.cs index 6533fa4244..cb45d2063b 100644 --- a/UnitsNet/CustomCode/UnitsNetSetup.cs +++ b/UnitsNet/CustomCode/UnitsNetSetup.cs @@ -21,8 +21,9 @@ public sealed class UnitsNetSetup { static UnitsNetSetup() { + IReadOnlyCollection quantityInfos = Quantity.Provider.DefaultQuantities; + // note: in order to support the ConvertByAbbreviation, the unit converter should require a UnitParser in the constructor var unitConverter = UnitConverter.CreateDefault(); - IReadOnlyCollection quantityInfos = Quantity.ByName.Values.ToList(); Default = new UnitsNetSetup(quantityInfos, unitConverter); } diff --git a/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs b/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs index 57cfee1b8d..fb23350f7b 100644 --- a/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,34 +62,85 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly AbsorbedDoseOfIonizingRadiationUnit? _unit; - static AbsorbedDoseOfIonizingRadiation() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class AbsorbedDoseOfIonizingRadiationInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 0, -2, 0, 0, 0, 0); - BaseUnit = AbsorbedDoseOfIonizingRadiationUnit.Gray; - Units = Enum.GetValues(typeof(AbsorbedDoseOfIonizingRadiationUnit)).Cast().ToArray(); - Zero = new AbsorbedDoseOfIonizingRadiation(0, BaseUnit); - Info = new QuantityInfo("AbsorbedDoseOfIonizingRadiation", - new UnitInfo[] - { - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Centigray, "Centigrays", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Second), "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Femtogray, "Femtograys", BaseUnits.Undefined, "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Gigagray, "Gigagrays", BaseUnits.Undefined, "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Gray, "Grays", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Kilogray, "Kilograys", BaseUnits.Undefined, "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Kilorad, "Kilorads", BaseUnits.Undefined, "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Megagray, "Megagrays", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second), "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Megarad, "Megarads", BaseUnits.Undefined, "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Microgray, "Micrograys", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second), "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Milligray, "Milligrays", BaseUnits.Undefined, "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Millirad, "Millirads", BaseUnits.Undefined, "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Nanogray, "Nanograys", BaseUnits.Undefined, "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Petagray, "Petagrays", BaseUnits.Undefined, "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Picogray, "Picograys", new BaseUnits(length: LengthUnit.Micrometer, time: DurationUnit.Second), "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Rad, "Rads", BaseUnits.Undefined, "AbsorbedDoseOfIonizingRadiation"), - new UnitInfo(AbsorbedDoseOfIonizingRadiationUnit.Teragray, "Teragrays", new BaseUnits(length: LengthUnit.Megameter, time: DurationUnit.Second), "AbsorbedDoseOfIonizingRadiation"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public AbsorbedDoseOfIonizingRadiationInfo(string name, AbsorbedDoseOfIonizingRadiationUnit baseUnit, IEnumerable> unitMappings, AbsorbedDoseOfIonizingRadiation zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public AbsorbedDoseOfIonizingRadiationInfo(string name, AbsorbedDoseOfIonizingRadiationUnit baseUnit, IEnumerable> unitMappings, AbsorbedDoseOfIonizingRadiation zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, AbsorbedDoseOfIonizingRadiation.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.AbsorbedDoseOfIonizingRadiation", typeof(AbsorbedDoseOfIonizingRadiation).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the AbsorbedDoseOfIonizingRadiation quantity. + /// + /// A new instance of the class with the default settings. + public static AbsorbedDoseOfIonizingRadiationInfo CreateDefault() + { + return new AbsorbedDoseOfIonizingRadiationInfo(nameof(AbsorbedDoseOfIonizingRadiation), DefaultBaseUnit, GetDefaultMappings(), new AbsorbedDoseOfIonizingRadiation(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the AbsorbedDoseOfIonizingRadiation quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static AbsorbedDoseOfIonizingRadiationInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new AbsorbedDoseOfIonizingRadiationInfo(nameof(AbsorbedDoseOfIonizingRadiation), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new AbsorbedDoseOfIonizingRadiation(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 0, -2, 0, 0, 0, 0); + + /// + /// The default base unit of AbsorbedDoseOfIonizingRadiation is Gray. All conversions, as defined in the , go via this value. + /// + public static AbsorbedDoseOfIonizingRadiationUnit DefaultBaseUnit { get; } = AbsorbedDoseOfIonizingRadiationUnit.Gray; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for AbsorbedDoseOfIonizingRadiation. + public static IEnumerable> GetDefaultMappings() + { + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Centigray, "Centigray", "Centigrays", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Second)); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Femtogray, "Femtogray", "Femtograys", BaseUnits.Undefined); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Gigagray, "Gigagray", "Gigagrays", BaseUnits.Undefined); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Gray, "Gray", "Grays", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Kilogray, "Kilogray", "Kilograys", BaseUnits.Undefined); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Kilorad, "Kilorad", "Kilorads", BaseUnits.Undefined); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Megagray, "Megagray", "Megagrays", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second)); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Megarad, "Megarad", "Megarads", BaseUnits.Undefined); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Microgray, "Microgray", "Micrograys", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second)); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Milligray, "Milligray", "Milligrays", BaseUnits.Undefined); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Millirad, "Millirad", "Millirads", BaseUnits.Undefined); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Nanogray, "Nanogray", "Nanograys", BaseUnits.Undefined); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Petagray, "Petagray", "Petagrays", BaseUnits.Undefined); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Picogray, "Picogray", "Picograys", new BaseUnits(length: LengthUnit.Micrometer, time: DurationUnit.Second)); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Rad, "Rad", "Rads", BaseUnits.Undefined); + yield return new (AbsorbedDoseOfIonizingRadiationUnit.Teragray, "Teragray", "Teragrays", new BaseUnits(length: LengthUnit.Megameter, time: DurationUnit.Second)); + } + } + + static AbsorbedDoseOfIonizingRadiation() + { + Info = AbsorbedDoseOfIonizingRadiationInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -131,27 +178,27 @@ public AbsorbedDoseOfIonizingRadiation(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of AbsorbedDoseOfIonizingRadiation, which is Gray. All conversions go via this value. /// - public static AbsorbedDoseOfIonizingRadiationUnit BaseUnit { get; } + public static AbsorbedDoseOfIonizingRadiationUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the AbsorbedDoseOfIonizingRadiation quantity. /// - public static AbsorbedDoseOfIonizingRadiationUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Gray. /// - public static AbsorbedDoseOfIonizingRadiation Zero { get; } + public static AbsorbedDoseOfIonizingRadiation Zero => Info.Zero; /// public static AbsorbedDoseOfIonizingRadiation AdditiveIdentity => Zero; @@ -169,7 +216,7 @@ public AbsorbedDoseOfIonizingRadiation(double value, UnitSystem unitSystem) public AbsorbedDoseOfIonizingRadiationUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -187,6 +234,9 @@ public AbsorbedDoseOfIonizingRadiation(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs index 584ac0de3e..5eafbc6d55 100644 --- a/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -70,32 +66,83 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly AccelerationUnit? _unit; - static Acceleration() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class AccelerationInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 0, -2, 0, 0, 0, 0); - BaseUnit = AccelerationUnit.MeterPerSecondSquared; - Units = Enum.GetValues(typeof(AccelerationUnit)).Cast().ToArray(); - Zero = new Acceleration(0, BaseUnit); - Info = new QuantityInfo("Acceleration", - new UnitInfo[] - { - new UnitInfo(AccelerationUnit.CentimeterPerSecondSquared, "CentimetersPerSecondSquared", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Second), "Acceleration"), - new UnitInfo(AccelerationUnit.DecimeterPerSecondSquared, "DecimetersPerSecondSquared", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Second), "Acceleration"), - new UnitInfo(AccelerationUnit.FootPerSecondSquared, "FeetPerSecondSquared", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second), "Acceleration"), - new UnitInfo(AccelerationUnit.InchPerSecondSquared, "InchesPerSecondSquared", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Second), "Acceleration"), - new UnitInfo(AccelerationUnit.KilometerPerSecondSquared, "KilometersPerSecondSquared", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second), "Acceleration"), - new UnitInfo(AccelerationUnit.KnotPerHour, "KnotsPerHour", new BaseUnits(length: LengthUnit.NauticalMile, time: DurationUnit.Hour), "Acceleration"), - new UnitInfo(AccelerationUnit.KnotPerMinute, "KnotsPerMinute", new BaseUnits(length: LengthUnit.NauticalMile, time: DurationUnit.Minute), "Acceleration"), - new UnitInfo(AccelerationUnit.KnotPerSecond, "KnotsPerSecond", new BaseUnits(length: LengthUnit.NauticalMile, time: DurationUnit.Second), "Acceleration"), - new UnitInfo(AccelerationUnit.MeterPerSecondSquared, "MetersPerSecondSquared", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "Acceleration"), - new UnitInfo(AccelerationUnit.MicrometerPerSecondSquared, "MicrometersPerSecondSquared", new BaseUnits(length: LengthUnit.Micrometer, time: DurationUnit.Second), "Acceleration"), - new UnitInfo(AccelerationUnit.MillimeterPerSecondSquared, "MillimetersPerSecondSquared", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second), "Acceleration"), - new UnitInfo(AccelerationUnit.MillistandardGravity, "MillistandardGravity", BaseUnits.Undefined, "Acceleration"), - new UnitInfo(AccelerationUnit.NanometerPerSecondSquared, "NanometersPerSecondSquared", new BaseUnits(length: LengthUnit.Nanometer, time: DurationUnit.Second), "Acceleration"), - new UnitInfo(AccelerationUnit.StandardGravity, "StandardGravity", BaseUnits.Undefined, "Acceleration"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public AccelerationInfo(string name, AccelerationUnit baseUnit, IEnumerable> unitMappings, Acceleration zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public AccelerationInfo(string name, AccelerationUnit baseUnit, IEnumerable> unitMappings, Acceleration zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Acceleration.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Acceleration", typeof(Acceleration).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Acceleration quantity. + /// + /// A new instance of the class with the default settings. + public static AccelerationInfo CreateDefault() + { + return new AccelerationInfo(nameof(Acceleration), DefaultBaseUnit, GetDefaultMappings(), new Acceleration(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Acceleration quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static AccelerationInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new AccelerationInfo(nameof(Acceleration), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Acceleration(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 0, -2, 0, 0, 0, 0); + + /// + /// The default base unit of Acceleration is MeterPerSecondSquared. All conversions, as defined in the , go via this value. + /// + public static AccelerationUnit DefaultBaseUnit { get; } = AccelerationUnit.MeterPerSecondSquared; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Acceleration. + public static IEnumerable> GetDefaultMappings() + { + yield return new (AccelerationUnit.CentimeterPerSecondSquared, "CentimeterPerSecondSquared", "CentimetersPerSecondSquared", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Second)); + yield return new (AccelerationUnit.DecimeterPerSecondSquared, "DecimeterPerSecondSquared", "DecimetersPerSecondSquared", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Second)); + yield return new (AccelerationUnit.FootPerSecondSquared, "FootPerSecondSquared", "FeetPerSecondSquared", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second)); + yield return new (AccelerationUnit.InchPerSecondSquared, "InchPerSecondSquared", "InchesPerSecondSquared", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Second)); + yield return new (AccelerationUnit.KilometerPerSecondSquared, "KilometerPerSecondSquared", "KilometersPerSecondSquared", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second)); + yield return new (AccelerationUnit.KnotPerHour, "KnotPerHour", "KnotsPerHour", new BaseUnits(length: LengthUnit.NauticalMile, time: DurationUnit.Hour)); + yield return new (AccelerationUnit.KnotPerMinute, "KnotPerMinute", "KnotsPerMinute", new BaseUnits(length: LengthUnit.NauticalMile, time: DurationUnit.Minute)); + yield return new (AccelerationUnit.KnotPerSecond, "KnotPerSecond", "KnotsPerSecond", new BaseUnits(length: LengthUnit.NauticalMile, time: DurationUnit.Second)); + yield return new (AccelerationUnit.MeterPerSecondSquared, "MeterPerSecondSquared", "MetersPerSecondSquared", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + yield return new (AccelerationUnit.MicrometerPerSecondSquared, "MicrometerPerSecondSquared", "MicrometersPerSecondSquared", new BaseUnits(length: LengthUnit.Micrometer, time: DurationUnit.Second)); + yield return new (AccelerationUnit.MillimeterPerSecondSquared, "MillimeterPerSecondSquared", "MillimetersPerSecondSquared", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second)); + yield return new (AccelerationUnit.MillistandardGravity, "MillistandardGravity", "MillistandardGravity", BaseUnits.Undefined); + yield return new (AccelerationUnit.NanometerPerSecondSquared, "NanometerPerSecondSquared", "NanometersPerSecondSquared", new BaseUnits(length: LengthUnit.Nanometer, time: DurationUnit.Second)); + yield return new (AccelerationUnit.StandardGravity, "StandardGravity", "StandardGravity", BaseUnits.Undefined); + } + } + + static Acceleration() + { + Info = AccelerationInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -133,27 +180,27 @@ public Acceleration(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Acceleration, which is MeterPerSecondSquared. All conversions go via this value. /// - public static AccelerationUnit BaseUnit { get; } + public static AccelerationUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Acceleration quantity. /// - public static AccelerationUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit MeterPerSecondSquared. /// - public static Acceleration Zero { get; } + public static Acceleration Zero => Info.Zero; /// public static Acceleration AdditiveIdentity => Zero; @@ -171,7 +218,7 @@ public Acceleration(double value, UnitSystem unitSystem) public AccelerationUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -189,6 +236,9 @@ public Acceleration(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs index e381b30dd4..99dee1950d 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -71,35 +67,86 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly AmountOfSubstanceUnit? _unit; - static AmountOfSubstance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class AmountOfSubstanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, 0, 0, 0, 1, 0); - BaseUnit = AmountOfSubstanceUnit.Mole; - Units = Enum.GetValues(typeof(AmountOfSubstanceUnit)).Cast().ToArray(); - Zero = new AmountOfSubstance(0, BaseUnit); - Info = new QuantityInfo("AmountOfSubstance", - new UnitInfo[] - { - new UnitInfo(AmountOfSubstanceUnit.Centimole, "Centimoles", new BaseUnits(amount: AmountOfSubstanceUnit.Centimole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.CentipoundMole, "CentipoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.CentipoundMole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.Decimole, "Decimoles", new BaseUnits(amount: AmountOfSubstanceUnit.Decimole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.DecipoundMole, "DecipoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.DecipoundMole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.Femtomole, "Femtomoles", new BaseUnits(amount: AmountOfSubstanceUnit.Femtomole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.Kilomole, "Kilomoles", new BaseUnits(amount: AmountOfSubstanceUnit.Kilomole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.KilopoundMole, "KilopoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.KilopoundMole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.Megamole, "Megamoles", new BaseUnits(amount: AmountOfSubstanceUnit.Megamole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.Micromole, "Micromoles", new BaseUnits(amount: AmountOfSubstanceUnit.Micromole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.MicropoundMole, "MicropoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.MicropoundMole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.Millimole, "Millimoles", new BaseUnits(amount: AmountOfSubstanceUnit.Millimole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.MillipoundMole, "MillipoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.MillipoundMole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.Mole, "Moles", new BaseUnits(amount: AmountOfSubstanceUnit.Mole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.Nanomole, "Nanomoles", new BaseUnits(amount: AmountOfSubstanceUnit.Nanomole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.NanopoundMole, "NanopoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.NanopoundMole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.Picomole, "Picomoles", new BaseUnits(amount: AmountOfSubstanceUnit.Picomole), "AmountOfSubstance"), - new UnitInfo(AmountOfSubstanceUnit.PoundMole, "PoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.PoundMole), "AmountOfSubstance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public AmountOfSubstanceInfo(string name, AmountOfSubstanceUnit baseUnit, IEnumerable> unitMappings, AmountOfSubstance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public AmountOfSubstanceInfo(string name, AmountOfSubstanceUnit baseUnit, IEnumerable> unitMappings, AmountOfSubstance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, AmountOfSubstance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.AmountOfSubstance", typeof(AmountOfSubstance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the AmountOfSubstance quantity. + /// + /// A new instance of the class with the default settings. + public static AmountOfSubstanceInfo CreateDefault() + { + return new AmountOfSubstanceInfo(nameof(AmountOfSubstance), DefaultBaseUnit, GetDefaultMappings(), new AmountOfSubstance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the AmountOfSubstance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static AmountOfSubstanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new AmountOfSubstanceInfo(nameof(AmountOfSubstance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new AmountOfSubstance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [N]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, 0, 0, 0, 1, 0); + + /// + /// The default base unit of AmountOfSubstance is Mole. All conversions, as defined in the , go via this value. + /// + public static AmountOfSubstanceUnit DefaultBaseUnit { get; } = AmountOfSubstanceUnit.Mole; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for AmountOfSubstance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (AmountOfSubstanceUnit.Centimole, "Centimole", "Centimoles", new BaseUnits(amount: AmountOfSubstanceUnit.Centimole)); + yield return new (AmountOfSubstanceUnit.CentipoundMole, "CentipoundMole", "CentipoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.CentipoundMole)); + yield return new (AmountOfSubstanceUnit.Decimole, "Decimole", "Decimoles", new BaseUnits(amount: AmountOfSubstanceUnit.Decimole)); + yield return new (AmountOfSubstanceUnit.DecipoundMole, "DecipoundMole", "DecipoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.DecipoundMole)); + yield return new (AmountOfSubstanceUnit.Femtomole, "Femtomole", "Femtomoles", new BaseUnits(amount: AmountOfSubstanceUnit.Femtomole)); + yield return new (AmountOfSubstanceUnit.Kilomole, "Kilomole", "Kilomoles", new BaseUnits(amount: AmountOfSubstanceUnit.Kilomole)); + yield return new (AmountOfSubstanceUnit.KilopoundMole, "KilopoundMole", "KilopoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.KilopoundMole)); + yield return new (AmountOfSubstanceUnit.Megamole, "Megamole", "Megamoles", new BaseUnits(amount: AmountOfSubstanceUnit.Megamole)); + yield return new (AmountOfSubstanceUnit.Micromole, "Micromole", "Micromoles", new BaseUnits(amount: AmountOfSubstanceUnit.Micromole)); + yield return new (AmountOfSubstanceUnit.MicropoundMole, "MicropoundMole", "MicropoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.MicropoundMole)); + yield return new (AmountOfSubstanceUnit.Millimole, "Millimole", "Millimoles", new BaseUnits(amount: AmountOfSubstanceUnit.Millimole)); + yield return new (AmountOfSubstanceUnit.MillipoundMole, "MillipoundMole", "MillipoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.MillipoundMole)); + yield return new (AmountOfSubstanceUnit.Mole, "Mole", "Moles", new BaseUnits(amount: AmountOfSubstanceUnit.Mole)); + yield return new (AmountOfSubstanceUnit.Nanomole, "Nanomole", "Nanomoles", new BaseUnits(amount: AmountOfSubstanceUnit.Nanomole)); + yield return new (AmountOfSubstanceUnit.NanopoundMole, "NanopoundMole", "NanopoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.NanopoundMole)); + yield return new (AmountOfSubstanceUnit.Picomole, "Picomole", "Picomoles", new BaseUnits(amount: AmountOfSubstanceUnit.Picomole)); + yield return new (AmountOfSubstanceUnit.PoundMole, "PoundMole", "PoundMoles", new BaseUnits(amount: AmountOfSubstanceUnit.PoundMole)); + } + } + + static AmountOfSubstance() + { + Info = AmountOfSubstanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -137,27 +184,27 @@ public AmountOfSubstance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of AmountOfSubstance, which is Mole. All conversions go via this value. /// - public static AmountOfSubstanceUnit BaseUnit { get; } + public static AmountOfSubstanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the AmountOfSubstance quantity. /// - public static AmountOfSubstanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Mole. /// - public static AmountOfSubstance Zero { get; } + public static AmountOfSubstance Zero => Info.Zero; /// public static AmountOfSubstance AdditiveIdentity => Zero; @@ -175,7 +222,7 @@ public AmountOfSubstance(double value, UnitSystem unitSystem) public AmountOfSubstanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -193,6 +240,9 @@ public AmountOfSubstance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs index bc258c9816..9cb9801e61 100644 --- a/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,22 +59,73 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly AmplitudeRatioUnit? _unit; - static AmplitudeRatio() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class AmplitudeRatioInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = AmplitudeRatioUnit.DecibelVolt; - Units = Enum.GetValues(typeof(AmplitudeRatioUnit)).Cast().ToArray(); - Zero = new AmplitudeRatio(0, BaseUnit); - Info = new QuantityInfo("AmplitudeRatio", - new UnitInfo[] - { - new UnitInfo(AmplitudeRatioUnit.DecibelMicrovolt, "DecibelMicrovolts", BaseUnits.Undefined, "AmplitudeRatio"), - new UnitInfo(AmplitudeRatioUnit.DecibelMillivolt, "DecibelMillivolts", BaseUnits.Undefined, "AmplitudeRatio"), - new UnitInfo(AmplitudeRatioUnit.DecibelUnloaded, "DecibelsUnloaded", BaseUnits.Undefined, "AmplitudeRatio"), - new UnitInfo(AmplitudeRatioUnit.DecibelVolt, "DecibelVolts", BaseUnits.Undefined, "AmplitudeRatio"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public AmplitudeRatioInfo(string name, AmplitudeRatioUnit baseUnit, IEnumerable> unitMappings, AmplitudeRatio zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public AmplitudeRatioInfo(string name, AmplitudeRatioUnit baseUnit, IEnumerable> unitMappings, AmplitudeRatio zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, AmplitudeRatio.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.AmplitudeRatio", typeof(AmplitudeRatio).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the AmplitudeRatio quantity. + /// + /// A new instance of the class with the default settings. + public static AmplitudeRatioInfo CreateDefault() + { + return new AmplitudeRatioInfo(nameof(AmplitudeRatio), DefaultBaseUnit, GetDefaultMappings(), new AmplitudeRatio(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the AmplitudeRatio quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static AmplitudeRatioInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new AmplitudeRatioInfo(nameof(AmplitudeRatio), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new AmplitudeRatio(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of AmplitudeRatio is DecibelVolt. All conversions, as defined in the , go via this value. + /// + public static AmplitudeRatioUnit DefaultBaseUnit { get; } = AmplitudeRatioUnit.DecibelVolt; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for AmplitudeRatio. + public static IEnumerable> GetDefaultMappings() + { + yield return new (AmplitudeRatioUnit.DecibelMicrovolt, "DecibelMicrovolt", "DecibelMicrovolts", BaseUnits.Undefined); + yield return new (AmplitudeRatioUnit.DecibelMillivolt, "DecibelMillivolt", "DecibelMillivolts", BaseUnits.Undefined); + yield return new (AmplitudeRatioUnit.DecibelUnloaded, "DecibelUnloaded", "DecibelsUnloaded", BaseUnits.Undefined); + yield return new (AmplitudeRatioUnit.DecibelVolt, "DecibelVolt", "DecibelVolts", BaseUnits.Undefined); + } + } + + static AmplitudeRatio() + { + Info = AmplitudeRatioInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -102,27 +149,27 @@ public AmplitudeRatio(double value, AmplitudeRatioUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of AmplitudeRatio, which is DecibelVolt. All conversions go via this value. /// - public static AmplitudeRatioUnit BaseUnit { get; } + public static AmplitudeRatioUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the AmplitudeRatio quantity. /// - public static AmplitudeRatioUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit DecibelVolt. /// - public static AmplitudeRatio Zero { get; } + public static AmplitudeRatio Zero => Info.Zero; /// public static AmplitudeRatio AdditiveIdentity => Zero; @@ -140,7 +187,7 @@ public AmplitudeRatio(double value, AmplitudeRatioUnit unit) public AmplitudeRatioUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -158,6 +205,9 @@ public AmplitudeRatio(double value, AmplitudeRatioUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs index 7ceef7ca45..bbaf04ceb0 100644 --- a/UnitsNet/GeneratedCode/Quantities/Angle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Angle.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -68,33 +64,84 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly AngleUnit? _unit; - static Angle() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class AngleInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = AngleUnit.Radian; - Units = Enum.GetValues(typeof(AngleUnit)).Cast().ToArray(); - Zero = new Angle(0, BaseUnit); - Info = new QuantityInfo("Angle", - new UnitInfo[] - { - new UnitInfo(AngleUnit.Arcminute, "Arcminutes", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Arcsecond, "Arcseconds", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Centiradian, "Centiradians", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Deciradian, "Deciradians", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Degree, "Degrees", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Gradian, "Gradians", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Microdegree, "Microdegrees", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Microradian, "Microradians", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Millidegree, "Millidegrees", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Milliradian, "Milliradians", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Nanodegree, "Nanodegrees", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Nanoradian, "Nanoradians", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.NatoMil, "NatoMils", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Radian, "Radians", BaseUnits.Undefined, "Angle"), - new UnitInfo(AngleUnit.Revolution, "Revolutions", BaseUnits.Undefined, "Angle"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public AngleInfo(string name, AngleUnit baseUnit, IEnumerable> unitMappings, Angle zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public AngleInfo(string name, AngleUnit baseUnit, IEnumerable> unitMappings, Angle zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Angle.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Angle", typeof(Angle).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Angle quantity. + /// + /// A new instance of the class with the default settings. + public static AngleInfo CreateDefault() + { + return new AngleInfo(nameof(Angle), DefaultBaseUnit, GetDefaultMappings(), new Angle(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Angle quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static AngleInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new AngleInfo(nameof(Angle), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Angle(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of Angle is Radian. All conversions, as defined in the , go via this value. + /// + public static AngleUnit DefaultBaseUnit { get; } = AngleUnit.Radian; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Angle. + public static IEnumerable> GetDefaultMappings() + { + yield return new (AngleUnit.Arcminute, "Arcminute", "Arcminutes", BaseUnits.Undefined); + yield return new (AngleUnit.Arcsecond, "Arcsecond", "Arcseconds", BaseUnits.Undefined); + yield return new (AngleUnit.Centiradian, "Centiradian", "Centiradians", BaseUnits.Undefined); + yield return new (AngleUnit.Deciradian, "Deciradian", "Deciradians", BaseUnits.Undefined); + yield return new (AngleUnit.Degree, "Degree", "Degrees", BaseUnits.Undefined); + yield return new (AngleUnit.Gradian, "Gradian", "Gradians", BaseUnits.Undefined); + yield return new (AngleUnit.Microdegree, "Microdegree", "Microdegrees", BaseUnits.Undefined); + yield return new (AngleUnit.Microradian, "Microradian", "Microradians", BaseUnits.Undefined); + yield return new (AngleUnit.Millidegree, "Millidegree", "Millidegrees", BaseUnits.Undefined); + yield return new (AngleUnit.Milliradian, "Milliradian", "Milliradians", BaseUnits.Undefined); + yield return new (AngleUnit.Nanodegree, "Nanodegree", "Nanodegrees", BaseUnits.Undefined); + yield return new (AngleUnit.Nanoradian, "Nanoradian", "Nanoradians", BaseUnits.Undefined); + yield return new (AngleUnit.NatoMil, "NatoMil", "NatoMils", BaseUnits.Undefined); + yield return new (AngleUnit.Radian, "Radian", "Radians", BaseUnits.Undefined); + yield return new (AngleUnit.Revolution, "Revolution", "Revolutions", BaseUnits.Undefined); + } + } + + static Angle() + { + Info = AngleInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -118,27 +165,27 @@ public Angle(double value, AngleUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Angle, which is Radian. All conversions go via this value. /// - public static AngleUnit BaseUnit { get; } + public static AngleUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Angle quantity. /// - public static AngleUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Radian. /// - public static Angle Zero { get; } + public static Angle Zero => Info.Zero; /// public static Angle AdditiveIdentity => Zero; @@ -156,7 +203,7 @@ public Angle(double value, AngleUnit unit) public AngleUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -174,6 +221,9 @@ public Angle(double value, AngleUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Area.g.cs b/UnitsNet/GeneratedCode/Quantities/Area.g.cs index 0b0b9cfcfd..3839e4c0df 100644 --- a/UnitsNet/GeneratedCode/Quantities/Area.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Area.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -81,32 +77,83 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly AreaUnit? _unit; - static Area() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class AreaInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 0, 0, 0, 0, 0, 0); - BaseUnit = AreaUnit.SquareMeter; - Units = Enum.GetValues(typeof(AreaUnit)).Cast().ToArray(); - Zero = new Area(0, BaseUnit); - Info = new QuantityInfo("Area", - new UnitInfo[] - { - new UnitInfo(AreaUnit.Acre, "Acres", BaseUnits.Undefined, "Area"), - new UnitInfo(AreaUnit.Hectare, "Hectares", BaseUnits.Undefined, "Area"), - new UnitInfo(AreaUnit.SquareCentimeter, "SquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter), "Area"), - new UnitInfo(AreaUnit.SquareDecimeter, "SquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter), "Area"), - new UnitInfo(AreaUnit.SquareFoot, "SquareFeet", new BaseUnits(length: LengthUnit.Foot), "Area"), - new UnitInfo(AreaUnit.SquareInch, "SquareInches", new BaseUnits(length: LengthUnit.Inch), "Area"), - new UnitInfo(AreaUnit.SquareKilometer, "SquareKilometers", new BaseUnits(length: LengthUnit.Kilometer), "Area"), - new UnitInfo(AreaUnit.SquareMeter, "SquareMeters", new BaseUnits(length: LengthUnit.Meter), "Area"), - new UnitInfo(AreaUnit.SquareMicrometer, "SquareMicrometers", new BaseUnits(length: LengthUnit.Micrometer), "Area"), - new UnitInfo(AreaUnit.SquareMile, "SquareMiles", new BaseUnits(length: LengthUnit.Mile), "Area"), - new UnitInfo(AreaUnit.SquareMillimeter, "SquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter), "Area"), - new UnitInfo(AreaUnit.SquareNauticalMile, "SquareNauticalMiles", BaseUnits.Undefined, "Area"), - new UnitInfo(AreaUnit.SquareYard, "SquareYards", new BaseUnits(length: LengthUnit.Yard), "Area"), - new UnitInfo(AreaUnit.UsSurveySquareFoot, "UsSurveySquareFeet", new BaseUnits(length: LengthUnit.UsSurveyFoot), "Area"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public AreaInfo(string name, AreaUnit baseUnit, IEnumerable> unitMappings, Area zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public AreaInfo(string name, AreaUnit baseUnit, IEnumerable> unitMappings, Area zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Area.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Area", typeof(Area).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Area quantity. + /// + /// A new instance of the class with the default settings. + public static AreaInfo CreateDefault() + { + return new AreaInfo(nameof(Area), DefaultBaseUnit, GetDefaultMappings(), new Area(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Area quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static AreaInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new AreaInfo(nameof(Area), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Area(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 0, 0, 0, 0, 0, 0); + + /// + /// The default base unit of Area is SquareMeter. All conversions, as defined in the , go via this value. + /// + public static AreaUnit DefaultBaseUnit { get; } = AreaUnit.SquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Area. + public static IEnumerable> GetDefaultMappings() + { + yield return new (AreaUnit.Acre, "Acre", "Acres", BaseUnits.Undefined); + yield return new (AreaUnit.Hectare, "Hectare", "Hectares", BaseUnits.Undefined); + yield return new (AreaUnit.SquareCentimeter, "SquareCentimeter", "SquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter)); + yield return new (AreaUnit.SquareDecimeter, "SquareDecimeter", "SquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter)); + yield return new (AreaUnit.SquareFoot, "SquareFoot", "SquareFeet", new BaseUnits(length: LengthUnit.Foot)); + yield return new (AreaUnit.SquareInch, "SquareInch", "SquareInches", new BaseUnits(length: LengthUnit.Inch)); + yield return new (AreaUnit.SquareKilometer, "SquareKilometer", "SquareKilometers", new BaseUnits(length: LengthUnit.Kilometer)); + yield return new (AreaUnit.SquareMeter, "SquareMeter", "SquareMeters", new BaseUnits(length: LengthUnit.Meter)); + yield return new (AreaUnit.SquareMicrometer, "SquareMicrometer", "SquareMicrometers", new BaseUnits(length: LengthUnit.Micrometer)); + yield return new (AreaUnit.SquareMile, "SquareMile", "SquareMiles", new BaseUnits(length: LengthUnit.Mile)); + yield return new (AreaUnit.SquareMillimeter, "SquareMillimeter", "SquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter)); + yield return new (AreaUnit.SquareNauticalMile, "SquareNauticalMile", "SquareNauticalMiles", BaseUnits.Undefined); + yield return new (AreaUnit.SquareYard, "SquareYard", "SquareYards", new BaseUnits(length: LengthUnit.Yard)); + yield return new (AreaUnit.UsSurveySquareFoot, "UsSurveySquareFoot", "UsSurveySquareFeet", new BaseUnits(length: LengthUnit.UsSurveyFoot)); + } + } + + static Area() + { + Info = AreaInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -144,27 +191,27 @@ public Area(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Area, which is SquareMeter. All conversions go via this value. /// - public static AreaUnit BaseUnit { get; } + public static AreaUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Area quantity. /// - public static AreaUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit SquareMeter. /// - public static Area Zero { get; } + public static Area Zero => Info.Zero; /// public static Area AdditiveIdentity => Zero; @@ -182,7 +229,7 @@ public Area(double value, UnitSystem unitSystem) public AreaUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -200,6 +247,9 @@ public Area(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs index 6c495102d4..062f978916 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,21 +62,72 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly AreaDensityUnit? _unit; - static AreaDensity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class AreaDensityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, 1, 0, 0, 0, 0, 0); - BaseUnit = AreaDensityUnit.KilogramPerSquareMeter; - Units = Enum.GetValues(typeof(AreaDensityUnit)).Cast().ToArray(); - Zero = new AreaDensity(0, BaseUnit); - Info = new QuantityInfo("AreaDensity", - new UnitInfo[] - { - new UnitInfo(AreaDensityUnit.GramPerSquareMeter, "GramsPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram), "AreaDensity"), - new UnitInfo(AreaDensityUnit.KilogramPerSquareMeter, "KilogramsPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram), "AreaDensity"), - new UnitInfo(AreaDensityUnit.MilligramPerSquareMeter, "MilligramsPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram), "AreaDensity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public AreaDensityInfo(string name, AreaDensityUnit baseUnit, IEnumerable> unitMappings, AreaDensity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public AreaDensityInfo(string name, AreaDensityUnit baseUnit, IEnumerable> unitMappings, AreaDensity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, AreaDensity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.AreaDensity", typeof(AreaDensity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the AreaDensity quantity. + /// + /// A new instance of the class with the default settings. + public static AreaDensityInfo CreateDefault() + { + return new AreaDensityInfo(nameof(AreaDensity), DefaultBaseUnit, GetDefaultMappings(), new AreaDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the AreaDensity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static AreaDensityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new AreaDensityInfo(nameof(AreaDensity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new AreaDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, 1, 0, 0, 0, 0, 0); + + /// + /// The default base unit of AreaDensity is KilogramPerSquareMeter. All conversions, as defined in the , go via this value. + /// + public static AreaDensityUnit DefaultBaseUnit { get; } = AreaDensityUnit.KilogramPerSquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for AreaDensity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (AreaDensityUnit.GramPerSquareMeter, "GramPerSquareMeter", "GramsPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram)); + yield return new (AreaDensityUnit.KilogramPerSquareMeter, "KilogramPerSquareMeter", "KilogramsPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)); + yield return new (AreaDensityUnit.MilligramPerSquareMeter, "MilligramPerSquareMeter", "MilligramsPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram)); + } + } + + static AreaDensity() + { + Info = AreaDensityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -118,27 +165,27 @@ public AreaDensity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of AreaDensity, which is KilogramPerSquareMeter. All conversions go via this value. /// - public static AreaDensityUnit BaseUnit { get; } + public static AreaDensityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the AreaDensity quantity. /// - public static AreaDensityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerSquareMeter. /// - public static AreaDensity Zero { get; } + public static AreaDensity Zero => Info.Zero; /// public static AreaDensity AdditiveIdentity => Zero; @@ -156,7 +203,7 @@ public AreaDensity(double value, UnitSystem unitSystem) public AreaDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -174,6 +221,9 @@ public AreaDensity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs index 9bf65b7675..bc0d5fdea8 100644 --- a/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -67,24 +63,75 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly AreaMomentOfInertiaUnit? _unit; - static AreaMomentOfInertia() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class AreaMomentOfInertiaInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(4, 0, 0, 0, 0, 0, 0); - BaseUnit = AreaMomentOfInertiaUnit.MeterToTheFourth; - Units = Enum.GetValues(typeof(AreaMomentOfInertiaUnit)).Cast().ToArray(); - Zero = new AreaMomentOfInertia(0, BaseUnit); - Info = new QuantityInfo("AreaMomentOfInertia", - new UnitInfo[] - { - new UnitInfo(AreaMomentOfInertiaUnit.CentimeterToTheFourth, "CentimetersToTheFourth", new BaseUnits(length: LengthUnit.Centimeter), "AreaMomentOfInertia"), - new UnitInfo(AreaMomentOfInertiaUnit.DecimeterToTheFourth, "DecimetersToTheFourth", new BaseUnits(length: LengthUnit.Decimeter), "AreaMomentOfInertia"), - new UnitInfo(AreaMomentOfInertiaUnit.FootToTheFourth, "FeetToTheFourth", new BaseUnits(length: LengthUnit.Foot), "AreaMomentOfInertia"), - new UnitInfo(AreaMomentOfInertiaUnit.InchToTheFourth, "InchesToTheFourth", new BaseUnits(length: LengthUnit.Inch), "AreaMomentOfInertia"), - new UnitInfo(AreaMomentOfInertiaUnit.MeterToTheFourth, "MetersToTheFourth", new BaseUnits(length: LengthUnit.Meter), "AreaMomentOfInertia"), - new UnitInfo(AreaMomentOfInertiaUnit.MillimeterToTheFourth, "MillimetersToTheFourth", new BaseUnits(length: LengthUnit.Millimeter), "AreaMomentOfInertia"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public AreaMomentOfInertiaInfo(string name, AreaMomentOfInertiaUnit baseUnit, IEnumerable> unitMappings, AreaMomentOfInertia zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public AreaMomentOfInertiaInfo(string name, AreaMomentOfInertiaUnit baseUnit, IEnumerable> unitMappings, AreaMomentOfInertia zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, AreaMomentOfInertia.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.AreaMomentOfInertia", typeof(AreaMomentOfInertia).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the AreaMomentOfInertia quantity. + /// + /// A new instance of the class with the default settings. + public static AreaMomentOfInertiaInfo CreateDefault() + { + return new AreaMomentOfInertiaInfo(nameof(AreaMomentOfInertia), DefaultBaseUnit, GetDefaultMappings(), new AreaMomentOfInertia(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the AreaMomentOfInertia quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static AreaMomentOfInertiaInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new AreaMomentOfInertiaInfo(nameof(AreaMomentOfInertia), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new AreaMomentOfInertia(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^4]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(4, 0, 0, 0, 0, 0, 0); + + /// + /// The default base unit of AreaMomentOfInertia is MeterToTheFourth. All conversions, as defined in the , go via this value. + /// + public static AreaMomentOfInertiaUnit DefaultBaseUnit { get; } = AreaMomentOfInertiaUnit.MeterToTheFourth; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for AreaMomentOfInertia. + public static IEnumerable> GetDefaultMappings() + { + yield return new (AreaMomentOfInertiaUnit.CentimeterToTheFourth, "CentimeterToTheFourth", "CentimetersToTheFourth", new BaseUnits(length: LengthUnit.Centimeter)); + yield return new (AreaMomentOfInertiaUnit.DecimeterToTheFourth, "DecimeterToTheFourth", "DecimetersToTheFourth", new BaseUnits(length: LengthUnit.Decimeter)); + yield return new (AreaMomentOfInertiaUnit.FootToTheFourth, "FootToTheFourth", "FeetToTheFourth", new BaseUnits(length: LengthUnit.Foot)); + yield return new (AreaMomentOfInertiaUnit.InchToTheFourth, "InchToTheFourth", "InchesToTheFourth", new BaseUnits(length: LengthUnit.Inch)); + yield return new (AreaMomentOfInertiaUnit.MeterToTheFourth, "MeterToTheFourth", "MetersToTheFourth", new BaseUnits(length: LengthUnit.Meter)); + yield return new (AreaMomentOfInertiaUnit.MillimeterToTheFourth, "MillimeterToTheFourth", "MillimetersToTheFourth", new BaseUnits(length: LengthUnit.Millimeter)); + } + } + + static AreaMomentOfInertia() + { + Info = AreaMomentOfInertiaInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -122,27 +169,27 @@ public AreaMomentOfInertia(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of AreaMomentOfInertia, which is MeterToTheFourth. All conversions go via this value. /// - public static AreaMomentOfInertiaUnit BaseUnit { get; } + public static AreaMomentOfInertiaUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the AreaMomentOfInertia quantity. /// - public static AreaMomentOfInertiaUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit MeterToTheFourth. /// - public static AreaMomentOfInertia Zero { get; } + public static AreaMomentOfInertia Zero => Info.Zero; /// public static AreaMomentOfInertia AdditiveIdentity => Zero; @@ -160,7 +207,7 @@ public AreaMomentOfInertia(double value, UnitSystem unitSystem) public AreaMomentOfInertiaUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -178,6 +225,9 @@ public AreaMomentOfInertia(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs index 62ce547c49..d1a1b882d4 100644 --- a/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BitRate.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,57 +62,108 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly BitRateUnit? _unit; - static BitRate() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class BitRateInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, -1, 0, 0, 0, 0); - BaseUnit = BitRateUnit.BitPerSecond; - Units = Enum.GetValues(typeof(BitRateUnit)).Cast().ToArray(); - Zero = new BitRate(0, BaseUnit); - Info = new QuantityInfo("BitRate", - new UnitInfo[] - { - new UnitInfo(BitRateUnit.BitPerSecond, "BitsPerSecond", new BaseUnits(time: DurationUnit.Second), "BitRate"), - new UnitInfo(BitRateUnit.BytePerSecond, "BytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.ExabitPerSecond, "ExabitsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.ExabytePerSecond, "ExabytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.ExaoctetPerSecond, "ExaoctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.ExbibitPerSecond, "ExbibitsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.ExbibytePerSecond, "ExbibytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.ExbioctetPerSecond, "ExbioctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.GibibitPerSecond, "GibibitsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.GibibytePerSecond, "GibibytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.GibioctetPerSecond, "GibioctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.GigabitPerSecond, "GigabitsPerSecond", new BaseUnits(time: DurationUnit.Nanosecond), "BitRate"), - new UnitInfo(BitRateUnit.GigabytePerSecond, "GigabytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.GigaoctetPerSecond, "GigaoctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.KibibitPerSecond, "KibibitsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.KibibytePerSecond, "KibibytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.KibioctetPerSecond, "KibioctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.KilobitPerSecond, "KilobitsPerSecond", new BaseUnits(time: DurationUnit.Millisecond), "BitRate"), - new UnitInfo(BitRateUnit.KilobytePerSecond, "KilobytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.KilooctetPerSecond, "KilooctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.MebibitPerSecond, "MebibitsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.MebibytePerSecond, "MebibytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.MebioctetPerSecond, "MebioctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.MegabitPerSecond, "MegabitsPerSecond", new BaseUnits(time: DurationUnit.Microsecond), "BitRate"), - new UnitInfo(BitRateUnit.MegabytePerSecond, "MegabytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.MegaoctetPerSecond, "MegaoctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.OctetPerSecond, "OctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.PebibitPerSecond, "PebibitsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.PebibytePerSecond, "PebibytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.PebioctetPerSecond, "PebioctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.PetabitPerSecond, "PetabitsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.PetabytePerSecond, "PetabytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.PetaoctetPerSecond, "PetaoctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.TebibitPerSecond, "TebibitsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.TebibytePerSecond, "TebibytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.TebioctetPerSecond, "TebioctetsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.TerabitPerSecond, "TerabitsPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.TerabytePerSecond, "TerabytesPerSecond", BaseUnits.Undefined, "BitRate"), - new UnitInfo(BitRateUnit.TeraoctetPerSecond, "TeraoctetsPerSecond", BaseUnits.Undefined, "BitRate"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public BitRateInfo(string name, BitRateUnit baseUnit, IEnumerable> unitMappings, BitRate zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public BitRateInfo(string name, BitRateUnit baseUnit, IEnumerable> unitMappings, BitRate zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, BitRate.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.BitRate", typeof(BitRate).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the BitRate quantity. + /// + /// A new instance of the class with the default settings. + public static BitRateInfo CreateDefault() + { + return new BitRateInfo(nameof(BitRate), DefaultBaseUnit, GetDefaultMappings(), new BitRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the BitRate quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static BitRateInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new BitRateInfo(nameof(BitRate), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new BitRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, -1, 0, 0, 0, 0); + + /// + /// The default base unit of BitRate is BitPerSecond. All conversions, as defined in the , go via this value. + /// + public static BitRateUnit DefaultBaseUnit { get; } = BitRateUnit.BitPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for BitRate. + public static IEnumerable> GetDefaultMappings() + { + yield return new (BitRateUnit.BitPerSecond, "BitPerSecond", "BitsPerSecond", new BaseUnits(time: DurationUnit.Second)); + yield return new (BitRateUnit.BytePerSecond, "BytePerSecond", "BytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.ExabitPerSecond, "ExabitPerSecond", "ExabitsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.ExabytePerSecond, "ExabytePerSecond", "ExabytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.ExaoctetPerSecond, "ExaoctetPerSecond", "ExaoctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.ExbibitPerSecond, "ExbibitPerSecond", "ExbibitsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.ExbibytePerSecond, "ExbibytePerSecond", "ExbibytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.ExbioctetPerSecond, "ExbioctetPerSecond", "ExbioctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.GibibitPerSecond, "GibibitPerSecond", "GibibitsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.GibibytePerSecond, "GibibytePerSecond", "GibibytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.GibioctetPerSecond, "GibioctetPerSecond", "GibioctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.GigabitPerSecond, "GigabitPerSecond", "GigabitsPerSecond", new BaseUnits(time: DurationUnit.Nanosecond)); + yield return new (BitRateUnit.GigabytePerSecond, "GigabytePerSecond", "GigabytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.GigaoctetPerSecond, "GigaoctetPerSecond", "GigaoctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.KibibitPerSecond, "KibibitPerSecond", "KibibitsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.KibibytePerSecond, "KibibytePerSecond", "KibibytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.KibioctetPerSecond, "KibioctetPerSecond", "KibioctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.KilobitPerSecond, "KilobitPerSecond", "KilobitsPerSecond", new BaseUnits(time: DurationUnit.Millisecond)); + yield return new (BitRateUnit.KilobytePerSecond, "KilobytePerSecond", "KilobytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.KilooctetPerSecond, "KilooctetPerSecond", "KilooctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.MebibitPerSecond, "MebibitPerSecond", "MebibitsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.MebibytePerSecond, "MebibytePerSecond", "MebibytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.MebioctetPerSecond, "MebioctetPerSecond", "MebioctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.MegabitPerSecond, "MegabitPerSecond", "MegabitsPerSecond", new BaseUnits(time: DurationUnit.Microsecond)); + yield return new (BitRateUnit.MegabytePerSecond, "MegabytePerSecond", "MegabytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.MegaoctetPerSecond, "MegaoctetPerSecond", "MegaoctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.OctetPerSecond, "OctetPerSecond", "OctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.PebibitPerSecond, "PebibitPerSecond", "PebibitsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.PebibytePerSecond, "PebibytePerSecond", "PebibytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.PebioctetPerSecond, "PebioctetPerSecond", "PebioctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.PetabitPerSecond, "PetabitPerSecond", "PetabitsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.PetabytePerSecond, "PetabytePerSecond", "PetabytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.PetaoctetPerSecond, "PetaoctetPerSecond", "PetaoctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.TebibitPerSecond, "TebibitPerSecond", "TebibitsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.TebibytePerSecond, "TebibytePerSecond", "TebibytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.TebioctetPerSecond, "TebioctetPerSecond", "TebioctetsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.TerabitPerSecond, "TerabitPerSecond", "TerabitsPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.TerabytePerSecond, "TerabytePerSecond", "TerabytesPerSecond", BaseUnits.Undefined); + yield return new (BitRateUnit.TeraoctetPerSecond, "TeraoctetPerSecond", "TeraoctetsPerSecond", BaseUnits.Undefined); + } + } + + static BitRate() + { + Info = BitRateInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -154,27 +201,27 @@ public BitRate(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of BitRate, which is BitPerSecond. All conversions go via this value. /// - public static BitRateUnit BaseUnit { get; } + public static BitRateUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the BitRate quantity. /// - public static BitRateUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit BitPerSecond. /// - public static BitRate Zero { get; } + public static BitRate Zero => Info.Zero; /// public static BitRate AdditiveIdentity => Zero; @@ -192,7 +239,7 @@ public BitRate(double value, UnitSystem unitSystem) public BitRateUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -210,6 +257,9 @@ public BitRate(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs index 87b0f7dcf6..481a57ac14 100644 --- a/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -67,21 +63,72 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly BrakeSpecificFuelConsumptionUnit? _unit; - static BrakeSpecificFuelConsumption() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class BrakeSpecificFuelConsumptionInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, 0, 2, 0, 0, 0, 0); - BaseUnit = BrakeSpecificFuelConsumptionUnit.KilogramPerJoule; - Units = Enum.GetValues(typeof(BrakeSpecificFuelConsumptionUnit)).Cast().ToArray(); - Zero = new BrakeSpecificFuelConsumption(0, BaseUnit); - Info = new QuantityInfo("BrakeSpecificFuelConsumption", - new UnitInfo[] - { - new UnitInfo(BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, "GramsPerKiloWattHour", BaseUnits.Undefined, "BrakeSpecificFuelConsumption"), - new UnitInfo(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, "KilogramsPerJoule", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "BrakeSpecificFuelConsumption"), - new UnitInfo(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, "PoundsPerMechanicalHorsepowerHour", BaseUnits.Undefined, "BrakeSpecificFuelConsumption"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public BrakeSpecificFuelConsumptionInfo(string name, BrakeSpecificFuelConsumptionUnit baseUnit, IEnumerable> unitMappings, BrakeSpecificFuelConsumption zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public BrakeSpecificFuelConsumptionInfo(string name, BrakeSpecificFuelConsumptionUnit baseUnit, IEnumerable> unitMappings, BrakeSpecificFuelConsumption zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, BrakeSpecificFuelConsumption.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.BrakeSpecificFuelConsumption", typeof(BrakeSpecificFuelConsumption).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the BrakeSpecificFuelConsumption quantity. + /// + /// A new instance of the class with the default settings. + public static BrakeSpecificFuelConsumptionInfo CreateDefault() + { + return new BrakeSpecificFuelConsumptionInfo(nameof(BrakeSpecificFuelConsumption), DefaultBaseUnit, GetDefaultMappings(), new BrakeSpecificFuelConsumption(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the BrakeSpecificFuelConsumption quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static BrakeSpecificFuelConsumptionInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new BrakeSpecificFuelConsumptionInfo(nameof(BrakeSpecificFuelConsumption), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new BrakeSpecificFuelConsumption(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^2][L^-2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, 0, 2, 0, 0, 0, 0); + + /// + /// The default base unit of BrakeSpecificFuelConsumption is KilogramPerJoule. All conversions, as defined in the , go via this value. + /// + public static BrakeSpecificFuelConsumptionUnit DefaultBaseUnit { get; } = BrakeSpecificFuelConsumptionUnit.KilogramPerJoule; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for BrakeSpecificFuelConsumption. + public static IEnumerable> GetDefaultMappings() + { + yield return new (BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, "GramPerKiloWattHour", "GramsPerKiloWattHour", BaseUnits.Undefined); + yield return new (BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, "KilogramPerJoule", "KilogramsPerJoule", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + yield return new (BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, "PoundPerMechanicalHorsepowerHour", "PoundsPerMechanicalHorsepowerHour", BaseUnits.Undefined); + } + } + + static BrakeSpecificFuelConsumption() + { + Info = BrakeSpecificFuelConsumptionInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -119,27 +166,27 @@ public BrakeSpecificFuelConsumption(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of BrakeSpecificFuelConsumption, which is KilogramPerJoule. All conversions go via this value. /// - public static BrakeSpecificFuelConsumptionUnit BaseUnit { get; } + public static BrakeSpecificFuelConsumptionUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the BrakeSpecificFuelConsumption quantity. /// - public static BrakeSpecificFuelConsumptionUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerJoule. /// - public static BrakeSpecificFuelConsumption Zero { get; } + public static BrakeSpecificFuelConsumption Zero => Info.Zero; /// public static BrakeSpecificFuelConsumption AdditiveIdentity => Zero; @@ -157,7 +204,7 @@ public BrakeSpecificFuelConsumption(double value, UnitSystem unitSystem) public BrakeSpecificFuelConsumptionUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -175,6 +222,9 @@ public BrakeSpecificFuelConsumption(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs index 01ab892215..18330ee02a 100644 --- a/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,24 +62,75 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly CoefficientOfThermalExpansionUnit? _unit; - static CoefficientOfThermalExpansion() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class CoefficientOfThermalExpansionInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, 0, 0, -1, 0, 0); - BaseUnit = CoefficientOfThermalExpansionUnit.PerKelvin; - Units = Enum.GetValues(typeof(CoefficientOfThermalExpansionUnit)).Cast().ToArray(); - Zero = new CoefficientOfThermalExpansion(0, BaseUnit); - Info = new QuantityInfo("CoefficientOfThermalExpansion", - new UnitInfo[] - { - new UnitInfo(CoefficientOfThermalExpansionUnit.PerDegreeCelsius, "PerDegreeCelsius", new BaseUnits(temperature: TemperatureUnit.DegreeCelsius), "CoefficientOfThermalExpansion"), - new UnitInfo(CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit, "PerDegreeFahrenheit", new BaseUnits(temperature: TemperatureUnit.DegreeFahrenheit), "CoefficientOfThermalExpansion"), - new UnitInfo(CoefficientOfThermalExpansionUnit.PerKelvin, "PerKelvin", new BaseUnits(temperature: TemperatureUnit.Kelvin), "CoefficientOfThermalExpansion"), - new UnitInfo(CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius, "PpmPerDegreeCelsius", BaseUnits.Undefined, "CoefficientOfThermalExpansion"), - new UnitInfo(CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit, "PpmPerDegreeFahrenheit", BaseUnits.Undefined, "CoefficientOfThermalExpansion"), - new UnitInfo(CoefficientOfThermalExpansionUnit.PpmPerKelvin, "PpmPerKelvin", BaseUnits.Undefined, "CoefficientOfThermalExpansion"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public CoefficientOfThermalExpansionInfo(string name, CoefficientOfThermalExpansionUnit baseUnit, IEnumerable> unitMappings, CoefficientOfThermalExpansion zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public CoefficientOfThermalExpansionInfo(string name, CoefficientOfThermalExpansionUnit baseUnit, IEnumerable> unitMappings, CoefficientOfThermalExpansion zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, CoefficientOfThermalExpansion.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.CoefficientOfThermalExpansion", typeof(CoefficientOfThermalExpansion).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the CoefficientOfThermalExpansion quantity. + /// + /// A new instance of the class with the default settings. + public static CoefficientOfThermalExpansionInfo CreateDefault() + { + return new CoefficientOfThermalExpansionInfo(nameof(CoefficientOfThermalExpansion), DefaultBaseUnit, GetDefaultMappings(), new CoefficientOfThermalExpansion(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the CoefficientOfThermalExpansion quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static CoefficientOfThermalExpansionInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new CoefficientOfThermalExpansionInfo(nameof(CoefficientOfThermalExpansion), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new CoefficientOfThermalExpansion(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [Θ^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, 0, 0, -1, 0, 0); + + /// + /// The default base unit of CoefficientOfThermalExpansion is PerKelvin. All conversions, as defined in the , go via this value. + /// + public static CoefficientOfThermalExpansionUnit DefaultBaseUnit { get; } = CoefficientOfThermalExpansionUnit.PerKelvin; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for CoefficientOfThermalExpansion. + public static IEnumerable> GetDefaultMappings() + { + yield return new (CoefficientOfThermalExpansionUnit.PerDegreeCelsius, "PerDegreeCelsius", "PerDegreeCelsius", new BaseUnits(temperature: TemperatureUnit.DegreeCelsius)); + yield return new (CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit, "PerDegreeFahrenheit", "PerDegreeFahrenheit", new BaseUnits(temperature: TemperatureUnit.DegreeFahrenheit)); + yield return new (CoefficientOfThermalExpansionUnit.PerKelvin, "PerKelvin", "PerKelvin", new BaseUnits(temperature: TemperatureUnit.Kelvin)); + yield return new (CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius, "PpmPerDegreeCelsius", "PpmPerDegreeCelsius", BaseUnits.Undefined); + yield return new (CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit, "PpmPerDegreeFahrenheit", "PpmPerDegreeFahrenheit", BaseUnits.Undefined); + yield return new (CoefficientOfThermalExpansionUnit.PpmPerKelvin, "PpmPerKelvin", "PpmPerKelvin", BaseUnits.Undefined); + } + } + + static CoefficientOfThermalExpansion() + { + Info = CoefficientOfThermalExpansionInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -121,27 +168,27 @@ public CoefficientOfThermalExpansion(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of CoefficientOfThermalExpansion, which is PerKelvin. All conversions go via this value. /// - public static CoefficientOfThermalExpansionUnit BaseUnit { get; } + public static CoefficientOfThermalExpansionUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the CoefficientOfThermalExpansion quantity. /// - public static CoefficientOfThermalExpansionUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit PerKelvin. /// - public static CoefficientOfThermalExpansion Zero { get; } + public static CoefficientOfThermalExpansion Zero => Info.Zero; /// public static CoefficientOfThermalExpansion AdditiveIdentity => Zero; @@ -159,7 +206,7 @@ public CoefficientOfThermalExpansion(double value, UnitSystem unitSystem) public CoefficientOfThermalExpansionUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -177,6 +224,9 @@ public CoefficientOfThermalExpansion(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs index 1286088069..90f0980db9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,25 +59,76 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly CompressibilityUnit? _unit; - static Compressibility() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class CompressibilityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, -1, 2, 0, 0, 0, 0); - BaseUnit = CompressibilityUnit.InversePascal; - Units = Enum.GetValues(typeof(CompressibilityUnit)).Cast().ToArray(); - Zero = new Compressibility(0, BaseUnit); - Info = new QuantityInfo("Compressibility", - new UnitInfo[] - { - new UnitInfo(CompressibilityUnit.InverseAtmosphere, "InverseAtmospheres", BaseUnits.Undefined, "Compressibility"), - new UnitInfo(CompressibilityUnit.InverseBar, "InverseBars", BaseUnits.Undefined, "Compressibility"), - new UnitInfo(CompressibilityUnit.InverseKilopascal, "InverseKilopascals", BaseUnits.Undefined, "Compressibility"), - new UnitInfo(CompressibilityUnit.InverseMegapascal, "InverseMegapascals", BaseUnits.Undefined, "Compressibility"), - new UnitInfo(CompressibilityUnit.InverseMillibar, "InverseMillibars", BaseUnits.Undefined, "Compressibility"), - new UnitInfo(CompressibilityUnit.InversePascal, "InversePascals", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Compressibility"), - new UnitInfo(CompressibilityUnit.InversePoundForcePerSquareInch, "InversePoundsForcePerSquareInch", BaseUnits.Undefined, "Compressibility"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public CompressibilityInfo(string name, CompressibilityUnit baseUnit, IEnumerable> unitMappings, Compressibility zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public CompressibilityInfo(string name, CompressibilityUnit baseUnit, IEnumerable> unitMappings, Compressibility zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Compressibility.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Compressibility", typeof(Compressibility).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Compressibility quantity. + /// + /// A new instance of the class with the default settings. + public static CompressibilityInfo CreateDefault() + { + return new CompressibilityInfo(nameof(Compressibility), DefaultBaseUnit, GetDefaultMappings(), new Compressibility(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Compressibility quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static CompressibilityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new CompressibilityInfo(nameof(Compressibility), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Compressibility(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^2][L][M^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, -1, 2, 0, 0, 0, 0); + + /// + /// The default base unit of Compressibility is InversePascal. All conversions, as defined in the , go via this value. + /// + public static CompressibilityUnit DefaultBaseUnit { get; } = CompressibilityUnit.InversePascal; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Compressibility. + public static IEnumerable> GetDefaultMappings() + { + yield return new (CompressibilityUnit.InverseAtmosphere, "InverseAtmosphere", "InverseAtmospheres", BaseUnits.Undefined); + yield return new (CompressibilityUnit.InverseBar, "InverseBar", "InverseBars", BaseUnits.Undefined); + yield return new (CompressibilityUnit.InverseKilopascal, "InverseKilopascal", "InverseKilopascals", BaseUnits.Undefined); + yield return new (CompressibilityUnit.InverseMegapascal, "InverseMegapascal", "InverseMegapascals", BaseUnits.Undefined); + yield return new (CompressibilityUnit.InverseMillibar, "InverseMillibar", "InverseMillibars", BaseUnits.Undefined); + yield return new (CompressibilityUnit.InversePascal, "InversePascal", "InversePascals", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (CompressibilityUnit.InversePoundForcePerSquareInch, "InversePoundForcePerSquareInch", "InversePoundsForcePerSquareInch", BaseUnits.Undefined); + } + } + + static Compressibility() + { + Info = CompressibilityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -119,27 +166,27 @@ public Compressibility(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Compressibility, which is InversePascal. All conversions go via this value. /// - public static CompressibilityUnit BaseUnit { get; } + public static CompressibilityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Compressibility quantity. /// - public static CompressibilityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit InversePascal. /// - public static Compressibility Zero { get; } + public static Compressibility Zero => Info.Zero; /// public static Compressibility AdditiveIdentity => Zero; @@ -157,7 +204,7 @@ public Compressibility(double value, UnitSystem unitSystem) public CompressibilityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -175,6 +222,9 @@ public Compressibility(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Density.g.cs b/UnitsNet/GeneratedCode/Quantities/Density.g.cs index 9c5f68a4b6..954a1bcf74 100644 --- a/UnitsNet/GeneratedCode/Quantities/Density.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Density.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -75,74 +71,125 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly DensityUnit? _unit; - static Density() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class DensityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-3, 1, 0, 0, 0, 0, 0); - BaseUnit = DensityUnit.KilogramPerCubicMeter; - Units = Enum.GetValues(typeof(DensityUnit)).Cast().ToArray(); - Zero = new Density(0, BaseUnit); - Info = new QuantityInfo("Density", - new UnitInfo[] - { - new UnitInfo(DensityUnit.CentigramPerDeciliter, "CentigramsPerDeciliter", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.CentigramPerLiter, "CentigramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Centigram), "Density"), - new UnitInfo(DensityUnit.CentigramPerMilliliter, "CentigramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Centigram), "Density"), - new UnitInfo(DensityUnit.DecigramPerDeciliter, "DecigramsPerDeciliter", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.DecigramPerLiter, "DecigramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Decigram), "Density"), - new UnitInfo(DensityUnit.DecigramPerMilliliter, "DecigramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Decigram), "Density"), - new UnitInfo(DensityUnit.FemtogramPerDeciliter, "FemtogramsPerDeciliter", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.FemtogramPerLiter, "FemtogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Femtogram), "Density"), - new UnitInfo(DensityUnit.FemtogramPerMilliliter, "FemtogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Femtogram), "Density"), - new UnitInfo(DensityUnit.GramPerCubicCentimeter, "GramsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram), "Density"), - new UnitInfo(DensityUnit.GramPerCubicFoot, "GramsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Gram), "Density"), - new UnitInfo(DensityUnit.GramPerCubicInch, "GramsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Gram), "Density"), - new UnitInfo(DensityUnit.GramPerCubicMeter, "GramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram), "Density"), - new UnitInfo(DensityUnit.GramPerCubicMillimeter, "GramsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram), "Density"), - new UnitInfo(DensityUnit.GramPerDeciliter, "GramsPerDeciliter", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.GramPerLiter, "GramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram), "Density"), - new UnitInfo(DensityUnit.GramPerMilliliter, "GramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram), "Density"), - new UnitInfo(DensityUnit.KilogramPerCubicCentimeter, "KilogramsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram), "Density"), - new UnitInfo(DensityUnit.KilogramPerCubicMeter, "KilogramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram), "Density"), - new UnitInfo(DensityUnit.KilogramPerCubicMillimeter, "KilogramsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram), "Density"), - new UnitInfo(DensityUnit.KilogramPerLiter, "KilogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram), "Density"), - new UnitInfo(DensityUnit.KilopoundPerCubicFoot, "KilopoundsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Kilopound), "Density"), - new UnitInfo(DensityUnit.KilopoundPerCubicInch, "KilopoundsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Kilopound), "Density"), - new UnitInfo(DensityUnit.KilopoundPerCubicYard, "KilopoundsPerCubicYard", new BaseUnits(length: LengthUnit.Yard, mass: MassUnit.Kilopound), "Density"), - new UnitInfo(DensityUnit.MicrogramPerCubicMeter, "MicrogramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram), "Density"), - new UnitInfo(DensityUnit.MicrogramPerDeciliter, "MicrogramsPerDeciliter", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.MicrogramPerLiter, "MicrogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Microgram), "Density"), - new UnitInfo(DensityUnit.MicrogramPerMilliliter, "MicrogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Microgram), "Density"), - new UnitInfo(DensityUnit.MilligramPerCubicMeter, "MilligramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram), "Density"), - new UnitInfo(DensityUnit.MilligramPerDeciliter, "MilligramsPerDeciliter", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.MilligramPerLiter, "MilligramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Milligram), "Density"), - new UnitInfo(DensityUnit.MilligramPerMilliliter, "MilligramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Milligram), "Density"), - new UnitInfo(DensityUnit.NanogramPerDeciliter, "NanogramsPerDeciliter", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.NanogramPerLiter, "NanogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Nanogram), "Density"), - new UnitInfo(DensityUnit.NanogramPerMilliliter, "NanogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Nanogram), "Density"), - new UnitInfo(DensityUnit.PicogramPerDeciliter, "PicogramsPerDeciliter", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.PicogramPerLiter, "PicogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Picogram), "Density"), - new UnitInfo(DensityUnit.PicogramPerMilliliter, "PicogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Picogram), "Density"), - new UnitInfo(DensityUnit.PoundPerCubicCentimeter, "PoundsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Pound), "Density"), - new UnitInfo(DensityUnit.PoundPerCubicFoot, "PoundsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound), "Density"), - new UnitInfo(DensityUnit.PoundPerCubicInch, "PoundsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound), "Density"), - new UnitInfo(DensityUnit.PoundPerCubicMeter, "PoundsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Pound), "Density"), - new UnitInfo(DensityUnit.PoundPerCubicMillimeter, "PoundsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Pound), "Density"), - new UnitInfo(DensityUnit.PoundPerCubicYard, "PoundsPerCubicYard", new BaseUnits(length: LengthUnit.Yard, mass: MassUnit.Pound), "Density"), - new UnitInfo(DensityUnit.PoundPerImperialGallon, "PoundsPerImperialGallon", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.PoundPerUSGallon, "PoundsPerUSGallon", BaseUnits.Undefined, "Density"), - new UnitInfo(DensityUnit.SlugPerCubicCentimeter, "SlugsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Slug), "Density"), - new UnitInfo(DensityUnit.SlugPerCubicFoot, "SlugsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug), "Density"), - new UnitInfo(DensityUnit.SlugPerCubicInch, "SlugsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Slug), "Density"), - new UnitInfo(DensityUnit.SlugPerCubicMeter, "SlugsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Slug), "Density"), - new UnitInfo(DensityUnit.SlugPerCubicMillimeter, "SlugsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Slug), "Density"), - new UnitInfo(DensityUnit.TonnePerCubicCentimeter, "TonnesPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Tonne), "Density"), - new UnitInfo(DensityUnit.TonnePerCubicFoot, "TonnesPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Tonne), "Density"), - new UnitInfo(DensityUnit.TonnePerCubicInch, "TonnesPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Tonne), "Density"), - new UnitInfo(DensityUnit.TonnePerCubicMeter, "TonnesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Tonne), "Density"), - new UnitInfo(DensityUnit.TonnePerCubicMillimeter, "TonnesPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Tonne), "Density"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public DensityInfo(string name, DensityUnit baseUnit, IEnumerable> unitMappings, Density zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public DensityInfo(string name, DensityUnit baseUnit, IEnumerable> unitMappings, Density zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Density.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Density", typeof(Density).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Density quantity. + /// + /// A new instance of the class with the default settings. + public static DensityInfo CreateDefault() + { + return new DensityInfo(nameof(Density), DefaultBaseUnit, GetDefaultMappings(), new Density(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Density quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static DensityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new DensityInfo(nameof(Density), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Density(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-3][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-3, 1, 0, 0, 0, 0, 0); + + /// + /// The default base unit of Density is KilogramPerCubicMeter. All conversions, as defined in the , go via this value. + /// + public static DensityUnit DefaultBaseUnit { get; } = DensityUnit.KilogramPerCubicMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Density. + public static IEnumerable> GetDefaultMappings() + { + yield return new (DensityUnit.CentigramPerDeciliter, "CentigramPerDeciliter", "CentigramsPerDeciliter", BaseUnits.Undefined); + yield return new (DensityUnit.CentigramPerLiter, "CentigramPerLiter", "CentigramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Centigram)); + yield return new (DensityUnit.CentigramPerMilliliter, "CentigramPerMilliliter", "CentigramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Centigram)); + yield return new (DensityUnit.DecigramPerDeciliter, "DecigramPerDeciliter", "DecigramsPerDeciliter", BaseUnits.Undefined); + yield return new (DensityUnit.DecigramPerLiter, "DecigramPerLiter", "DecigramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Decigram)); + yield return new (DensityUnit.DecigramPerMilliliter, "DecigramPerMilliliter", "DecigramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Decigram)); + yield return new (DensityUnit.FemtogramPerDeciliter, "FemtogramPerDeciliter", "FemtogramsPerDeciliter", BaseUnits.Undefined); + yield return new (DensityUnit.FemtogramPerLiter, "FemtogramPerLiter", "FemtogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Femtogram)); + yield return new (DensityUnit.FemtogramPerMilliliter, "FemtogramPerMilliliter", "FemtogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Femtogram)); + yield return new (DensityUnit.GramPerCubicCentimeter, "GramPerCubicCentimeter", "GramsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)); + yield return new (DensityUnit.GramPerCubicFoot, "GramPerCubicFoot", "GramsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Gram)); + yield return new (DensityUnit.GramPerCubicInch, "GramPerCubicInch", "GramsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Gram)); + yield return new (DensityUnit.GramPerCubicMeter, "GramPerCubicMeter", "GramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram)); + yield return new (DensityUnit.GramPerCubicMillimeter, "GramPerCubicMillimeter", "GramsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram)); + yield return new (DensityUnit.GramPerDeciliter, "GramPerDeciliter", "GramsPerDeciliter", BaseUnits.Undefined); + yield return new (DensityUnit.GramPerLiter, "GramPerLiter", "GramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram)); + yield return new (DensityUnit.GramPerMilliliter, "GramPerMilliliter", "GramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)); + yield return new (DensityUnit.KilogramPerCubicCentimeter, "KilogramPerCubicCentimeter", "KilogramsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram)); + yield return new (DensityUnit.KilogramPerCubicMeter, "KilogramPerCubicMeter", "KilogramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)); + yield return new (DensityUnit.KilogramPerCubicMillimeter, "KilogramPerCubicMillimeter", "KilogramsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram)); + yield return new (DensityUnit.KilogramPerLiter, "KilogramPerLiter", "KilogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram)); + yield return new (DensityUnit.KilopoundPerCubicFoot, "KilopoundPerCubicFoot", "KilopoundsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Kilopound)); + yield return new (DensityUnit.KilopoundPerCubicInch, "KilopoundPerCubicInch", "KilopoundsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Kilopound)); + yield return new (DensityUnit.KilopoundPerCubicYard, "KilopoundPerCubicYard", "KilopoundsPerCubicYard", new BaseUnits(length: LengthUnit.Yard, mass: MassUnit.Kilopound)); + yield return new (DensityUnit.MicrogramPerCubicMeter, "MicrogramPerCubicMeter", "MicrogramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram)); + yield return new (DensityUnit.MicrogramPerDeciliter, "MicrogramPerDeciliter", "MicrogramsPerDeciliter", BaseUnits.Undefined); + yield return new (DensityUnit.MicrogramPerLiter, "MicrogramPerLiter", "MicrogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Microgram)); + yield return new (DensityUnit.MicrogramPerMilliliter, "MicrogramPerMilliliter", "MicrogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Microgram)); + yield return new (DensityUnit.MilligramPerCubicMeter, "MilligramPerCubicMeter", "MilligramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram)); + yield return new (DensityUnit.MilligramPerDeciliter, "MilligramPerDeciliter", "MilligramsPerDeciliter", BaseUnits.Undefined); + yield return new (DensityUnit.MilligramPerLiter, "MilligramPerLiter", "MilligramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Milligram)); + yield return new (DensityUnit.MilligramPerMilliliter, "MilligramPerMilliliter", "MilligramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Milligram)); + yield return new (DensityUnit.NanogramPerDeciliter, "NanogramPerDeciliter", "NanogramsPerDeciliter", BaseUnits.Undefined); + yield return new (DensityUnit.NanogramPerLiter, "NanogramPerLiter", "NanogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Nanogram)); + yield return new (DensityUnit.NanogramPerMilliliter, "NanogramPerMilliliter", "NanogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Nanogram)); + yield return new (DensityUnit.PicogramPerDeciliter, "PicogramPerDeciliter", "PicogramsPerDeciliter", BaseUnits.Undefined); + yield return new (DensityUnit.PicogramPerLiter, "PicogramPerLiter", "PicogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Picogram)); + yield return new (DensityUnit.PicogramPerMilliliter, "PicogramPerMilliliter", "PicogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Picogram)); + yield return new (DensityUnit.PoundPerCubicCentimeter, "PoundPerCubicCentimeter", "PoundsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Pound)); + yield return new (DensityUnit.PoundPerCubicFoot, "PoundPerCubicFoot", "PoundsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound)); + yield return new (DensityUnit.PoundPerCubicInch, "PoundPerCubicInch", "PoundsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound)); + yield return new (DensityUnit.PoundPerCubicMeter, "PoundPerCubicMeter", "PoundsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Pound)); + yield return new (DensityUnit.PoundPerCubicMillimeter, "PoundPerCubicMillimeter", "PoundsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Pound)); + yield return new (DensityUnit.PoundPerCubicYard, "PoundPerCubicYard", "PoundsPerCubicYard", new BaseUnits(length: LengthUnit.Yard, mass: MassUnit.Pound)); + yield return new (DensityUnit.PoundPerImperialGallon, "PoundPerImperialGallon", "PoundsPerImperialGallon", BaseUnits.Undefined); + yield return new (DensityUnit.PoundPerUSGallon, "PoundPerUSGallon", "PoundsPerUSGallon", BaseUnits.Undefined); + yield return new (DensityUnit.SlugPerCubicCentimeter, "SlugPerCubicCentimeter", "SlugsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Slug)); + yield return new (DensityUnit.SlugPerCubicFoot, "SlugPerCubicFoot", "SlugsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug)); + yield return new (DensityUnit.SlugPerCubicInch, "SlugPerCubicInch", "SlugsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Slug)); + yield return new (DensityUnit.SlugPerCubicMeter, "SlugPerCubicMeter", "SlugsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Slug)); + yield return new (DensityUnit.SlugPerCubicMillimeter, "SlugPerCubicMillimeter", "SlugsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Slug)); + yield return new (DensityUnit.TonnePerCubicCentimeter, "TonnePerCubicCentimeter", "TonnesPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Tonne)); + yield return new (DensityUnit.TonnePerCubicFoot, "TonnePerCubicFoot", "TonnesPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Tonne)); + yield return new (DensityUnit.TonnePerCubicInch, "TonnePerCubicInch", "TonnesPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Tonne)); + yield return new (DensityUnit.TonnePerCubicMeter, "TonnePerCubicMeter", "TonnesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Tonne)); + yield return new (DensityUnit.TonnePerCubicMillimeter, "TonnePerCubicMillimeter", "TonnesPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Tonne)); + } + } + + static Density() + { + Info = DensityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -180,27 +227,27 @@ public Density(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Density, which is KilogramPerCubicMeter. All conversions go via this value. /// - public static DensityUnit BaseUnit { get; } + public static DensityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Density quantity. /// - public static DensityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerCubicMeter. /// - public static Density Zero { get; } + public static Density Zero => Info.Zero; /// public static Density AdditiveIdentity => Zero; @@ -218,7 +265,7 @@ public Density(double value, UnitSystem unitSystem) public DensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -236,6 +283,9 @@ public Density(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs b/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs index 0258546dca..6947140302 100644 --- a/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/DoseAreaProduct.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,38 +62,89 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly DoseAreaProductUnit? _unit; - static DoseAreaProduct() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class DoseAreaProductInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(4, 0, -2, 0, 0, 0, 0); - BaseUnit = DoseAreaProductUnit.GraySquareMeter; - Units = Enum.GetValues(typeof(DoseAreaProductUnit)).Cast().ToArray(); - Zero = new DoseAreaProduct(0, BaseUnit); - Info = new QuantityInfo("DoseAreaProduct", - new UnitInfo[] - { - new UnitInfo(DoseAreaProductUnit.CentigraySquareCentimeter, "CentigraySquareCentimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.CentigraySquareDecimeter, "CentigraySquareDecimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.CentigraySquareMeter, "CentigraySquareMeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.CentigraySquareMillimeter, "CentigraySquareMillimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.DecigraySquareCentimeter, "DecigraySquareCentimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.DecigraySquareDecimeter, "DecigraySquareDecimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.DecigraySquareMeter, "DecigraySquareMeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.DecigraySquareMillimeter, "DecigraySquareMillimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.GraySquareCentimeter, "GraySquareCentimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.GraySquareDecimeter, "GraySquareDecimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.GraySquareMeter, "GraySquareMeters", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.GraySquareMillimeter, "GraySquareMillimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.MicrograySquareCentimeter, "MicrograySquareCentimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.MicrograySquareDecimeter, "MicrograySquareDecimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.MicrograySquareMeter, "MicrograySquareMeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.MicrograySquareMillimeter, "MicrograySquareMillimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.MilligraySquareCentimeter, "MilligraySquareCentimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.MilligraySquareDecimeter, "MilligraySquareDecimeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.MilligraySquareMeter, "MilligraySquareMeters", BaseUnits.Undefined, "DoseAreaProduct"), - new UnitInfo(DoseAreaProductUnit.MilligraySquareMillimeter, "MilligraySquareMillimeters", BaseUnits.Undefined, "DoseAreaProduct"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public DoseAreaProductInfo(string name, DoseAreaProductUnit baseUnit, IEnumerable> unitMappings, DoseAreaProduct zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public DoseAreaProductInfo(string name, DoseAreaProductUnit baseUnit, IEnumerable> unitMappings, DoseAreaProduct zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, DoseAreaProduct.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.DoseAreaProduct", typeof(DoseAreaProduct).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the DoseAreaProduct quantity. + /// + /// A new instance of the class with the default settings. + public static DoseAreaProductInfo CreateDefault() + { + return new DoseAreaProductInfo(nameof(DoseAreaProduct), DefaultBaseUnit, GetDefaultMappings(), new DoseAreaProduct(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the DoseAreaProduct quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static DoseAreaProductInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new DoseAreaProductInfo(nameof(DoseAreaProduct), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new DoseAreaProduct(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^4]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(4, 0, -2, 0, 0, 0, 0); + + /// + /// The default base unit of DoseAreaProduct is GraySquareMeter. All conversions, as defined in the , go via this value. + /// + public static DoseAreaProductUnit DefaultBaseUnit { get; } = DoseAreaProductUnit.GraySquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for DoseAreaProduct. + public static IEnumerable> GetDefaultMappings() + { + yield return new (DoseAreaProductUnit.CentigraySquareCentimeter, "CentigraySquareCentimeter", "CentigraySquareCentimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.CentigraySquareDecimeter, "CentigraySquareDecimeter", "CentigraySquareDecimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.CentigraySquareMeter, "CentigraySquareMeter", "CentigraySquareMeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.CentigraySquareMillimeter, "CentigraySquareMillimeter", "CentigraySquareMillimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.DecigraySquareCentimeter, "DecigraySquareCentimeter", "DecigraySquareCentimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.DecigraySquareDecimeter, "DecigraySquareDecimeter", "DecigraySquareDecimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.DecigraySquareMeter, "DecigraySquareMeter", "DecigraySquareMeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.DecigraySquareMillimeter, "DecigraySquareMillimeter", "DecigraySquareMillimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.GraySquareCentimeter, "GraySquareCentimeter", "GraySquareCentimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.GraySquareDecimeter, "GraySquareDecimeter", "GraySquareDecimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.GraySquareMeter, "GraySquareMeter", "GraySquareMeters", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + yield return new (DoseAreaProductUnit.GraySquareMillimeter, "GraySquareMillimeter", "GraySquareMillimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.MicrograySquareCentimeter, "MicrograySquareCentimeter", "MicrograySquareCentimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.MicrograySquareDecimeter, "MicrograySquareDecimeter", "MicrograySquareDecimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.MicrograySquareMeter, "MicrograySquareMeter", "MicrograySquareMeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.MicrograySquareMillimeter, "MicrograySquareMillimeter", "MicrograySquareMillimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.MilligraySquareCentimeter, "MilligraySquareCentimeter", "MilligraySquareCentimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.MilligraySquareDecimeter, "MilligraySquareDecimeter", "MilligraySquareDecimeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.MilligraySquareMeter, "MilligraySquareMeter", "MilligraySquareMeters", BaseUnits.Undefined); + yield return new (DoseAreaProductUnit.MilligraySquareMillimeter, "MilligraySquareMillimeter", "MilligraySquareMillimeters", BaseUnits.Undefined); + } + } + + static DoseAreaProduct() + { + Info = DoseAreaProductInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -135,27 +182,27 @@ public DoseAreaProduct(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of DoseAreaProduct, which is GraySquareMeter. All conversions go via this value. /// - public static DoseAreaProductUnit BaseUnit { get; } + public static DoseAreaProductUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the DoseAreaProduct quantity. /// - public static DoseAreaProductUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit GraySquareMeter. /// - public static DoseAreaProduct Zero { get; } + public static DoseAreaProduct Zero => Info.Zero; /// public static DoseAreaProduct AdditiveIdentity => Zero; @@ -173,7 +220,7 @@ public DoseAreaProduct(double value, UnitSystem unitSystem) public DoseAreaProductUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -191,6 +238,9 @@ public DoseAreaProduct(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs index 29a6b52b27..5b5480b7b1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Duration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Duration.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -80,30 +76,81 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly DurationUnit? _unit; - static Duration() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class DurationInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, 1, 0, 0, 0, 0); - BaseUnit = DurationUnit.Second; - Units = Enum.GetValues(typeof(DurationUnit)).Cast().ToArray(); - Zero = new Duration(0, BaseUnit); - Info = new QuantityInfo("Duration", - new UnitInfo[] - { - new UnitInfo(DurationUnit.Day, "Days", new BaseUnits(time: DurationUnit.Day), "Duration"), - new UnitInfo(DurationUnit.Hour, "Hours", new BaseUnits(time: DurationUnit.Hour), "Duration"), - new UnitInfo(DurationUnit.JulianYear, "JulianYears", new BaseUnits(time: DurationUnit.JulianYear), "Duration"), - new UnitInfo(DurationUnit.Microsecond, "Microseconds", new BaseUnits(time: DurationUnit.Microsecond), "Duration"), - new UnitInfo(DurationUnit.Millisecond, "Milliseconds", new BaseUnits(time: DurationUnit.Millisecond), "Duration"), - new UnitInfo(DurationUnit.Minute, "Minutes", new BaseUnits(time: DurationUnit.Minute), "Duration"), - new UnitInfo(DurationUnit.Month30, "Months30", new BaseUnits(time: DurationUnit.Month30), "Duration"), - new UnitInfo(DurationUnit.Nanosecond, "Nanoseconds", new BaseUnits(time: DurationUnit.Nanosecond), "Duration"), - new UnitInfo(DurationUnit.Second, "Seconds", new BaseUnits(time: DurationUnit.Second), "Duration"), - new UnitInfo(DurationUnit.Sol, "Sols", new BaseUnits(time: DurationUnit.Sol), "Duration"), - new UnitInfo(DurationUnit.Week, "Weeks", new BaseUnits(time: DurationUnit.Week), "Duration"), - new UnitInfo(DurationUnit.Year365, "Years365", new BaseUnits(time: DurationUnit.Year365), "Duration"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public DurationInfo(string name, DurationUnit baseUnit, IEnumerable> unitMappings, Duration zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public DurationInfo(string name, DurationUnit baseUnit, IEnumerable> unitMappings, Duration zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Duration.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Duration", typeof(Duration).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Duration quantity. + /// + /// A new instance of the class with the default settings. + public static DurationInfo CreateDefault() + { + return new DurationInfo(nameof(Duration), DefaultBaseUnit, GetDefaultMappings(), new Duration(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Duration quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static DurationInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new DurationInfo(nameof(Duration), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Duration(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, 1, 0, 0, 0, 0); + + /// + /// The default base unit of Duration is Second. All conversions, as defined in the , go via this value. + /// + public static DurationUnit DefaultBaseUnit { get; } = DurationUnit.Second; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Duration. + public static IEnumerable> GetDefaultMappings() + { + yield return new (DurationUnit.Day, "Day", "Days", new BaseUnits(time: DurationUnit.Day)); + yield return new (DurationUnit.Hour, "Hour", "Hours", new BaseUnits(time: DurationUnit.Hour)); + yield return new (DurationUnit.JulianYear, "JulianYear", "JulianYears", new BaseUnits(time: DurationUnit.JulianYear)); + yield return new (DurationUnit.Microsecond, "Microsecond", "Microseconds", new BaseUnits(time: DurationUnit.Microsecond)); + yield return new (DurationUnit.Millisecond, "Millisecond", "Milliseconds", new BaseUnits(time: DurationUnit.Millisecond)); + yield return new (DurationUnit.Minute, "Minute", "Minutes", new BaseUnits(time: DurationUnit.Minute)); + yield return new (DurationUnit.Month30, "Month30", "Months30", new BaseUnits(time: DurationUnit.Month30)); + yield return new (DurationUnit.Nanosecond, "Nanosecond", "Nanoseconds", new BaseUnits(time: DurationUnit.Nanosecond)); + yield return new (DurationUnit.Second, "Second", "Seconds", new BaseUnits(time: DurationUnit.Second)); + yield return new (DurationUnit.Sol, "Sol", "Sols", new BaseUnits(time: DurationUnit.Sol)); + yield return new (DurationUnit.Week, "Week", "Weeks", new BaseUnits(time: DurationUnit.Week)); + yield return new (DurationUnit.Year365, "Year365", "Years365", new BaseUnits(time: DurationUnit.Year365)); + } + } + + static Duration() + { + Info = DurationInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -141,27 +188,27 @@ public Duration(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Duration, which is Second. All conversions go via this value. /// - public static DurationUnit BaseUnit { get; } + public static DurationUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Duration quantity. /// - public static DurationUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Second. /// - public static Duration Zero { get; } + public static Duration Zero => Info.Zero; /// public static Duration AdditiveIdentity => Zero; @@ -179,7 +226,7 @@ public Duration(double value, UnitSystem unitSystem) public DurationUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -197,6 +244,9 @@ public Duration(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs index 7c99e89231..7cf3ea3467 100644 --- a/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -70,28 +66,79 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly DynamicViscosityUnit? _unit; - static DynamicViscosity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class DynamicViscosityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-1, 1, -1, 0, 0, 0, 0); - BaseUnit = DynamicViscosityUnit.NewtonSecondPerMeterSquared; - Units = Enum.GetValues(typeof(DynamicViscosityUnit)).Cast().ToArray(); - Zero = new DynamicViscosity(0, BaseUnit); - Info = new QuantityInfo("DynamicViscosity", - new UnitInfo[] - { - new UnitInfo(DynamicViscosityUnit.Centipoise, "Centipoise", BaseUnits.Undefined, "DynamicViscosity"), - new UnitInfo(DynamicViscosityUnit.MicropascalSecond, "MicropascalSeconds", BaseUnits.Undefined, "DynamicViscosity"), - new UnitInfo(DynamicViscosityUnit.MillipascalSecond, "MillipascalSeconds", BaseUnits.Undefined, "DynamicViscosity"), - new UnitInfo(DynamicViscosityUnit.NewtonSecondPerMeterSquared, "NewtonSecondsPerMeterSquared", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "DynamicViscosity"), - new UnitInfo(DynamicViscosityUnit.PascalSecond, "PascalSeconds", BaseUnits.Undefined, "DynamicViscosity"), - new UnitInfo(DynamicViscosityUnit.Poise, "Poise", BaseUnits.Undefined, "DynamicViscosity"), - new UnitInfo(DynamicViscosityUnit.PoundForceSecondPerSquareFoot, "PoundsForceSecondPerSquareFoot", BaseUnits.Undefined, "DynamicViscosity"), - new UnitInfo(DynamicViscosityUnit.PoundForceSecondPerSquareInch, "PoundsForceSecondPerSquareInch", BaseUnits.Undefined, "DynamicViscosity"), - new UnitInfo(DynamicViscosityUnit.PoundPerFootSecond, "PoundsPerFootSecond", BaseUnits.Undefined, "DynamicViscosity"), - new UnitInfo(DynamicViscosityUnit.Reyn, "Reyns", BaseUnits.Undefined, "DynamicViscosity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public DynamicViscosityInfo(string name, DynamicViscosityUnit baseUnit, IEnumerable> unitMappings, DynamicViscosity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public DynamicViscosityInfo(string name, DynamicViscosityUnit baseUnit, IEnumerable> unitMappings, DynamicViscosity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, DynamicViscosity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.DynamicViscosity", typeof(DynamicViscosity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the DynamicViscosity quantity. + /// + /// A new instance of the class with the default settings. + public static DynamicViscosityInfo CreateDefault() + { + return new DynamicViscosityInfo(nameof(DynamicViscosity), DefaultBaseUnit, GetDefaultMappings(), new DynamicViscosity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the DynamicViscosity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static DynamicViscosityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new DynamicViscosityInfo(nameof(DynamicViscosity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new DynamicViscosity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][L^-1][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-1, 1, -1, 0, 0, 0, 0); + + /// + /// The default base unit of DynamicViscosity is NewtonSecondPerMeterSquared. All conversions, as defined in the , go via this value. + /// + public static DynamicViscosityUnit DefaultBaseUnit { get; } = DynamicViscosityUnit.NewtonSecondPerMeterSquared; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for DynamicViscosity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (DynamicViscosityUnit.Centipoise, "Centipoise", "Centipoise", BaseUnits.Undefined); + yield return new (DynamicViscosityUnit.MicropascalSecond, "MicropascalSecond", "MicropascalSeconds", BaseUnits.Undefined); + yield return new (DynamicViscosityUnit.MillipascalSecond, "MillipascalSecond", "MillipascalSeconds", BaseUnits.Undefined); + yield return new (DynamicViscosityUnit.NewtonSecondPerMeterSquared, "NewtonSecondPerMeterSquared", "NewtonSecondsPerMeterSquared", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (DynamicViscosityUnit.PascalSecond, "PascalSecond", "PascalSeconds", BaseUnits.Undefined); + yield return new (DynamicViscosityUnit.Poise, "Poise", "Poise", BaseUnits.Undefined); + yield return new (DynamicViscosityUnit.PoundForceSecondPerSquareFoot, "PoundForceSecondPerSquareFoot", "PoundsForceSecondPerSquareFoot", BaseUnits.Undefined); + yield return new (DynamicViscosityUnit.PoundForceSecondPerSquareInch, "PoundForceSecondPerSquareInch", "PoundsForceSecondPerSquareInch", BaseUnits.Undefined); + yield return new (DynamicViscosityUnit.PoundPerFootSecond, "PoundPerFootSecond", "PoundsPerFootSecond", BaseUnits.Undefined); + yield return new (DynamicViscosityUnit.Reyn, "Reyn", "Reyns", BaseUnits.Undefined); + } + } + + static DynamicViscosity() + { + Info = DynamicViscosityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -129,27 +176,27 @@ public DynamicViscosity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of DynamicViscosity, which is NewtonSecondPerMeterSquared. All conversions go via this value. /// - public static DynamicViscosityUnit BaseUnit { get; } + public static DynamicViscosityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the DynamicViscosity quantity. /// - public static DynamicViscosityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit NewtonSecondPerMeterSquared. /// - public static DynamicViscosity Zero { get; } + public static DynamicViscosity Zero => Info.Zero; /// public static DynamicViscosity AdditiveIdentity => Zero; @@ -167,7 +214,7 @@ public DynamicViscosity(double value, UnitSystem unitSystem) public DynamicViscosityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -185,6 +232,9 @@ public DynamicViscosity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs index 9fccdb2ac0..afdc8cdb5b 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -67,34 +63,85 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricAdmittanceUnit? _unit; - static ElectricAdmittance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricAdmittanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, -1, 3, 2, 0, 0, 0); - BaseUnit = ElectricAdmittanceUnit.Siemens; - Units = Enum.GetValues(typeof(ElectricAdmittanceUnit)).Cast().ToArray(); - Zero = new ElectricAdmittance(0, BaseUnit); - Info = new QuantityInfo("ElectricAdmittance", - new UnitInfo[] - { - new UnitInfo(ElectricAdmittanceUnit.Gigamho, "Gigamhos", BaseUnits.Undefined, "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Gigasiemens, "Gigasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Kilomho, "Kilomhos", BaseUnits.Undefined, "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Kilosiemens, "Kilosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Megamho, "Megamhos", BaseUnits.Undefined, "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Megasiemens, "Megasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Mho, "Mhos", BaseUnits.Undefined, "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Micromho, "Micromhos", BaseUnits.Undefined, "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Microsiemens, "Microsiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere), "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Millimho, "Millimhos", BaseUnits.Undefined, "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Millisiemens, "Millisiemens", BaseUnits.Undefined, "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Nanomho, "Nanomhos", BaseUnits.Undefined, "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Nanosiemens, "Nanosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere), "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Siemens, "Siemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Teramho, "Teramhos", BaseUnits.Undefined, "ElectricAdmittance"), - new UnitInfo(ElectricAdmittanceUnit.Terasiemens, "Terasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricAdmittance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricAdmittanceInfo(string name, ElectricAdmittanceUnit baseUnit, IEnumerable> unitMappings, ElectricAdmittance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricAdmittanceInfo(string name, ElectricAdmittanceUnit baseUnit, IEnumerable> unitMappings, ElectricAdmittance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricAdmittance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricAdmittance", typeof(ElectricAdmittance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricAdmittance quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricAdmittanceInfo CreateDefault() + { + return new ElectricAdmittanceInfo(nameof(ElectricAdmittance), DefaultBaseUnit, GetDefaultMappings(), new ElectricAdmittance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricAdmittance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricAdmittanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricAdmittanceInfo(nameof(ElectricAdmittance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricAdmittance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^3][L^-2][M^-1][I^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, -1, 3, 2, 0, 0, 0); + + /// + /// The default base unit of ElectricAdmittance is Siemens. All conversions, as defined in the , go via this value. + /// + public static ElectricAdmittanceUnit DefaultBaseUnit { get; } = ElectricAdmittanceUnit.Siemens; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricAdmittance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricAdmittanceUnit.Gigamho, "Gigamho", "Gigamhos", BaseUnits.Undefined); + yield return new (ElectricAdmittanceUnit.Gigasiemens, "Gigasiemens", "Gigasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricAdmittanceUnit.Kilomho, "Kilomho", "Kilomhos", BaseUnits.Undefined); + yield return new (ElectricAdmittanceUnit.Kilosiemens, "Kilosiemens", "Kilosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricAdmittanceUnit.Megamho, "Megamho", "Megamhos", BaseUnits.Undefined); + yield return new (ElectricAdmittanceUnit.Megasiemens, "Megasiemens", "Megasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricAdmittanceUnit.Mho, "Mho", "Mhos", BaseUnits.Undefined); + yield return new (ElectricAdmittanceUnit.Micromho, "Micromho", "Micromhos", BaseUnits.Undefined); + yield return new (ElectricAdmittanceUnit.Microsiemens, "Microsiemens", "Microsiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricAdmittanceUnit.Millimho, "Millimho", "Millimhos", BaseUnits.Undefined); + yield return new (ElectricAdmittanceUnit.Millisiemens, "Millisiemens", "Millisiemens", BaseUnits.Undefined); + yield return new (ElectricAdmittanceUnit.Nanomho, "Nanomho", "Nanomhos", BaseUnits.Undefined); + yield return new (ElectricAdmittanceUnit.Nanosiemens, "Nanosiemens", "Nanosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricAdmittanceUnit.Siemens, "Siemens", "Siemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricAdmittanceUnit.Teramho, "Teramho", "Teramhos", BaseUnits.Undefined); + yield return new (ElectricAdmittanceUnit.Terasiemens, "Terasiemens", "Terasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricAdmittance() + { + Info = ElectricAdmittanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -132,27 +179,27 @@ public ElectricAdmittance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricAdmittance, which is Siemens. All conversions go via this value. /// - public static ElectricAdmittanceUnit BaseUnit { get; } + public static ElectricAdmittanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricAdmittance quantity. /// - public static ElectricAdmittanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Siemens. /// - public static ElectricAdmittance Zero { get; } + public static ElectricAdmittance Zero => Info.Zero; /// public static ElectricAdmittance AdditiveIdentity => Zero; @@ -170,7 +217,7 @@ public ElectricAdmittance(double value, UnitSystem unitSystem) public ElectricAdmittanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -188,6 +235,9 @@ public ElectricAdmittance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs index c3c0cb98eb..220c519777 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricApparentEnergy.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,21 +59,72 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricApparentEnergyUnit? _unit; - static ElectricApparentEnergy() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricApparentEnergyInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); - BaseUnit = ElectricApparentEnergyUnit.VoltampereHour; - Units = Enum.GetValues(typeof(ElectricApparentEnergyUnit)).Cast().ToArray(); - Zero = new ElectricApparentEnergy(0, BaseUnit); - Info = new QuantityInfo("ElectricApparentEnergy", - new UnitInfo[] - { - new UnitInfo(ElectricApparentEnergyUnit.KilovoltampereHour, "KilovoltampereHours", BaseUnits.Undefined, "ElectricApparentEnergy"), - new UnitInfo(ElectricApparentEnergyUnit.MegavoltampereHour, "MegavoltampereHours", BaseUnits.Undefined, "ElectricApparentEnergy"), - new UnitInfo(ElectricApparentEnergyUnit.VoltampereHour, "VoltampereHours", BaseUnits.Undefined, "ElectricApparentEnergy"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricApparentEnergyInfo(string name, ElectricApparentEnergyUnit baseUnit, IEnumerable> unitMappings, ElectricApparentEnergy zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricApparentEnergyInfo(string name, ElectricApparentEnergyUnit baseUnit, IEnumerable> unitMappings, ElectricApparentEnergy zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricApparentEnergy.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricApparentEnergy", typeof(ElectricApparentEnergy).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricApparentEnergy quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricApparentEnergyInfo CreateDefault() + { + return new ElectricApparentEnergyInfo(nameof(ElectricApparentEnergy), DefaultBaseUnit, GetDefaultMappings(), new ElectricApparentEnergy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricApparentEnergy quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricApparentEnergyInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricApparentEnergyInfo(nameof(ElectricApparentEnergy), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricApparentEnergy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of ElectricApparentEnergy is VoltampereHour. All conversions, as defined in the , go via this value. + /// + public static ElectricApparentEnergyUnit DefaultBaseUnit { get; } = ElectricApparentEnergyUnit.VoltampereHour; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricApparentEnergy. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricApparentEnergyUnit.KilovoltampereHour, "KilovoltampereHour", "KilovoltampereHours", BaseUnits.Undefined); + yield return new (ElectricApparentEnergyUnit.MegavoltampereHour, "MegavoltampereHour", "MegavoltampereHours", BaseUnits.Undefined); + yield return new (ElectricApparentEnergyUnit.VoltampereHour, "VoltampereHour", "VoltampereHours", BaseUnits.Undefined); + } + } + + static ElectricApparentEnergy() + { + Info = ElectricApparentEnergyInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -115,27 +162,27 @@ public ElectricApparentEnergy(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricApparentEnergy, which is VoltampereHour. All conversions go via this value. /// - public static ElectricApparentEnergyUnit BaseUnit { get; } + public static ElectricApparentEnergyUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricApparentEnergy quantity. /// - public static ElectricApparentEnergyUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit VoltampereHour. /// - public static ElectricApparentEnergy Zero { get; } + public static ElectricApparentEnergy Zero => Info.Zero; /// public static ElectricApparentEnergy AdditiveIdentity => Zero; @@ -153,7 +200,7 @@ public ElectricApparentEnergy(double value, UnitSystem unitSystem) public ElectricApparentEnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -171,6 +218,9 @@ public ElectricApparentEnergy(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs index 7582b2cee5..ad98db63aa 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricApparentPower.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,24 +62,75 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricApparentPowerUnit? _unit; - static ElectricApparentPower() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricApparentPowerInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); - BaseUnit = ElectricApparentPowerUnit.Voltampere; - Units = Enum.GetValues(typeof(ElectricApparentPowerUnit)).Cast().ToArray(); - Zero = new ElectricApparentPower(0, BaseUnit); - Info = new QuantityInfo("ElectricApparentPower", - new UnitInfo[] - { - new UnitInfo(ElectricApparentPowerUnit.Gigavoltampere, "Gigavoltamperes", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond), "ElectricApparentPower"), - new UnitInfo(ElectricApparentPowerUnit.Kilovoltampere, "Kilovoltamperes", BaseUnits.Undefined, "ElectricApparentPower"), - new UnitInfo(ElectricApparentPowerUnit.Megavoltampere, "Megavoltamperes", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ElectricApparentPower"), - new UnitInfo(ElectricApparentPowerUnit.Microvoltampere, "Microvoltamperes", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second), "ElectricApparentPower"), - new UnitInfo(ElectricApparentPowerUnit.Millivoltampere, "Millivoltamperes", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second), "ElectricApparentPower"), - new UnitInfo(ElectricApparentPowerUnit.Voltampere, "Voltamperes", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ElectricApparentPower"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricApparentPowerInfo(string name, ElectricApparentPowerUnit baseUnit, IEnumerable> unitMappings, ElectricApparentPower zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricApparentPowerInfo(string name, ElectricApparentPowerUnit baseUnit, IEnumerable> unitMappings, ElectricApparentPower zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricApparentPower.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricApparentPower", typeof(ElectricApparentPower).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricApparentPower quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricApparentPowerInfo CreateDefault() + { + return new ElectricApparentPowerInfo(nameof(ElectricApparentPower), DefaultBaseUnit, GetDefaultMappings(), new ElectricApparentPower(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricApparentPower quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricApparentPowerInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricApparentPowerInfo(nameof(ElectricApparentPower), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricApparentPower(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); + + /// + /// The default base unit of ElectricApparentPower is Voltampere. All conversions, as defined in the , go via this value. + /// + public static ElectricApparentPowerUnit DefaultBaseUnit { get; } = ElectricApparentPowerUnit.Voltampere; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricApparentPower. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricApparentPowerUnit.Gigavoltampere, "Gigavoltampere", "Gigavoltamperes", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond)); + yield return new (ElectricApparentPowerUnit.Kilovoltampere, "Kilovoltampere", "Kilovoltamperes", BaseUnits.Undefined); + yield return new (ElectricApparentPowerUnit.Megavoltampere, "Megavoltampere", "Megavoltamperes", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ElectricApparentPowerUnit.Microvoltampere, "Microvoltampere", "Microvoltamperes", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second)); + yield return new (ElectricApparentPowerUnit.Millivoltampere, "Millivoltampere", "Millivoltamperes", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (ElectricApparentPowerUnit.Voltampere, "Voltampere", "Voltamperes", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + } + } + + static ElectricApparentPower() + { + Info = ElectricApparentPowerInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -121,27 +168,27 @@ public ElectricApparentPower(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricApparentPower, which is Voltampere. All conversions go via this value. /// - public static ElectricApparentPowerUnit BaseUnit { get; } + public static ElectricApparentPowerUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricApparentPower quantity. /// - public static ElectricApparentPowerUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Voltampere. /// - public static ElectricApparentPower Zero { get; } + public static ElectricApparentPower Zero => Info.Zero; /// public static ElectricApparentPower AdditiveIdentity => Zero; @@ -159,7 +206,7 @@ public ElectricApparentPower(double value, UnitSystem unitSystem) public ElectricApparentPowerUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -177,6 +224,9 @@ public ElectricApparentPower(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs index 5b9e0a6516..bcdc85d203 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCapacitance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,25 +62,76 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricCapacitanceUnit? _unit; - static ElectricCapacitance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricCapacitanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, -1, 4, 2, 0, 0, 0); - BaseUnit = ElectricCapacitanceUnit.Farad; - Units = Enum.GetValues(typeof(ElectricCapacitanceUnit)).Cast().ToArray(); - Zero = new ElectricCapacitance(0, BaseUnit); - Info = new QuantityInfo("ElectricCapacitance", - new UnitInfo[] - { - new UnitInfo(ElectricCapacitanceUnit.Farad, "Farads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricCapacitance"), - new UnitInfo(ElectricCapacitanceUnit.Kilofarad, "Kilofarads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricCapacitance"), - new UnitInfo(ElectricCapacitanceUnit.Megafarad, "Megafarads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricCapacitance"), - new UnitInfo(ElectricCapacitanceUnit.Microfarad, "Microfarads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere), "ElectricCapacitance"), - new UnitInfo(ElectricCapacitanceUnit.Millifarad, "Millifarads", BaseUnits.Undefined, "ElectricCapacitance"), - new UnitInfo(ElectricCapacitanceUnit.Nanofarad, "Nanofarads", BaseUnits.Undefined, "ElectricCapacitance"), - new UnitInfo(ElectricCapacitanceUnit.Picofarad, "Picofarads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere), "ElectricCapacitance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricCapacitanceInfo(string name, ElectricCapacitanceUnit baseUnit, IEnumerable> unitMappings, ElectricCapacitance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricCapacitanceInfo(string name, ElectricCapacitanceUnit baseUnit, IEnumerable> unitMappings, ElectricCapacitance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricCapacitance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricCapacitance", typeof(ElectricCapacitance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricCapacitance quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricCapacitanceInfo CreateDefault() + { + return new ElectricCapacitanceInfo(nameof(ElectricCapacitance), DefaultBaseUnit, GetDefaultMappings(), new ElectricCapacitance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricCapacitance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricCapacitanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricCapacitanceInfo(nameof(ElectricCapacitance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricCapacitance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^4][L^-2][M^-1][I^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, -1, 4, 2, 0, 0, 0); + + /// + /// The default base unit of ElectricCapacitance is Farad. All conversions, as defined in the , go via this value. + /// + public static ElectricCapacitanceUnit DefaultBaseUnit { get; } = ElectricCapacitanceUnit.Farad; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricCapacitance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricCapacitanceUnit.Farad, "Farad", "Farads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricCapacitanceUnit.Kilofarad, "Kilofarad", "Kilofarads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricCapacitanceUnit.Megafarad, "Megafarad", "Megafarads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricCapacitanceUnit.Microfarad, "Microfarad", "Microfarads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricCapacitanceUnit.Millifarad, "Millifarad", "Millifarads", BaseUnits.Undefined); + yield return new (ElectricCapacitanceUnit.Nanofarad, "Nanofarad", "Nanofarads", BaseUnits.Undefined); + yield return new (ElectricCapacitanceUnit.Picofarad, "Picofarad", "Picofarads", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere)); + } + } + + static ElectricCapacitance() + { + Info = ElectricCapacitanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -122,27 +169,27 @@ public ElectricCapacitance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricCapacitance, which is Farad. All conversions go via this value. /// - public static ElectricCapacitanceUnit BaseUnit { get; } + public static ElectricCapacitanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricCapacitance quantity. /// - public static ElectricCapacitanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Farad. /// - public static ElectricCapacitance Zero { get; } + public static ElectricCapacitance Zero => Info.Zero; /// public static ElectricCapacitance AdditiveIdentity => Zero; @@ -160,7 +207,7 @@ public ElectricCapacitance(double value, UnitSystem unitSystem) public ElectricCapacitanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -178,6 +225,9 @@ public ElectricCapacitance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs index 6d0fe93098..84c6b7d75d 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -71,29 +67,80 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricChargeUnit? _unit; - static ElectricCharge() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricChargeInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, 1, 1, 0, 0, 0); - BaseUnit = ElectricChargeUnit.Coulomb; - Units = Enum.GetValues(typeof(ElectricChargeUnit)).Cast().ToArray(); - Zero = new ElectricCharge(0, BaseUnit); - Info = new QuantityInfo("ElectricCharge", - new UnitInfo[] - { - new UnitInfo(ElectricChargeUnit.AmpereHour, "AmpereHours", new BaseUnits(time: DurationUnit.Hour, current: ElectricCurrentUnit.Ampere), "ElectricCharge"), - new UnitInfo(ElectricChargeUnit.Coulomb, "Coulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricCharge"), - new UnitInfo(ElectricChargeUnit.KiloampereHour, "KiloampereHours", new BaseUnits(time: DurationUnit.Hour, current: ElectricCurrentUnit.Kiloampere), "ElectricCharge"), - new UnitInfo(ElectricChargeUnit.Kilocoulomb, "Kilocoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Kiloampere), "ElectricCharge"), - new UnitInfo(ElectricChargeUnit.MegaampereHour, "MegaampereHours", new BaseUnits(time: DurationUnit.Hour, current: ElectricCurrentUnit.Megaampere), "ElectricCharge"), - new UnitInfo(ElectricChargeUnit.Megacoulomb, "Megacoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Megaampere), "ElectricCharge"), - new UnitInfo(ElectricChargeUnit.Microcoulomb, "Microcoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere), "ElectricCharge"), - new UnitInfo(ElectricChargeUnit.MilliampereHour, "MilliampereHours", new BaseUnits(time: DurationUnit.Hour, current: ElectricCurrentUnit.Milliampere), "ElectricCharge"), - new UnitInfo(ElectricChargeUnit.Millicoulomb, "Millicoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere), "ElectricCharge"), - new UnitInfo(ElectricChargeUnit.Nanocoulomb, "Nanocoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Nanoampere), "ElectricCharge"), - new UnitInfo(ElectricChargeUnit.Picocoulomb, "Picocoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Picoampere), "ElectricCharge"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricChargeInfo(string name, ElectricChargeUnit baseUnit, IEnumerable> unitMappings, ElectricCharge zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricChargeInfo(string name, ElectricChargeUnit baseUnit, IEnumerable> unitMappings, ElectricCharge zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricCharge.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricCharge", typeof(ElectricCharge).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricCharge quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricChargeInfo CreateDefault() + { + return new ElectricChargeInfo(nameof(ElectricCharge), DefaultBaseUnit, GetDefaultMappings(), new ElectricCharge(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricCharge quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricChargeInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricChargeInfo(nameof(ElectricCharge), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricCharge(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T][I]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, 1, 1, 0, 0, 0); + + /// + /// The default base unit of ElectricCharge is Coulomb. All conversions, as defined in the , go via this value. + /// + public static ElectricChargeUnit DefaultBaseUnit { get; } = ElectricChargeUnit.Coulomb; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricCharge. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricChargeUnit.AmpereHour, "AmpereHour", "AmpereHours", new BaseUnits(time: DurationUnit.Hour, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricChargeUnit.Coulomb, "Coulomb", "Coulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricChargeUnit.KiloampereHour, "KiloampereHour", "KiloampereHours", new BaseUnits(time: DurationUnit.Hour, current: ElectricCurrentUnit.Kiloampere)); + yield return new (ElectricChargeUnit.Kilocoulomb, "Kilocoulomb", "Kilocoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Kiloampere)); + yield return new (ElectricChargeUnit.MegaampereHour, "MegaampereHour", "MegaampereHours", new BaseUnits(time: DurationUnit.Hour, current: ElectricCurrentUnit.Megaampere)); + yield return new (ElectricChargeUnit.Megacoulomb, "Megacoulomb", "Megacoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Megaampere)); + yield return new (ElectricChargeUnit.Microcoulomb, "Microcoulomb", "Microcoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere)); + yield return new (ElectricChargeUnit.MilliampereHour, "MilliampereHour", "MilliampereHours", new BaseUnits(time: DurationUnit.Hour, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricChargeUnit.Millicoulomb, "Millicoulomb", "Millicoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricChargeUnit.Nanocoulomb, "Nanocoulomb", "Nanocoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Nanoampere)); + yield return new (ElectricChargeUnit.Picocoulomb, "Picocoulomb", "Picocoulombs", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Picoampere)); + } + } + + static ElectricCharge() + { + Info = ElectricChargeInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -131,27 +178,27 @@ public ElectricCharge(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricCharge, which is Coulomb. All conversions go via this value. /// - public static ElectricChargeUnit BaseUnit { get; } + public static ElectricChargeUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricCharge quantity. /// - public static ElectricChargeUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Coulomb. /// - public static ElectricCharge Zero { get; } + public static ElectricCharge Zero => Info.Zero; /// public static ElectricCharge AdditiveIdentity => Zero; @@ -169,7 +216,7 @@ public ElectricCharge(double value, UnitSystem unitSystem) public ElectricChargeUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -187,6 +234,9 @@ public ElectricCharge(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs index 8dc4b7eb73..03fc5692bb 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,19 +62,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricChargeDensityUnit? _unit; - static ElectricChargeDensity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricChargeDensityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-3, 0, 1, 1, 0, 0, 0); - BaseUnit = ElectricChargeDensityUnit.CoulombPerCubicMeter; - Units = Enum.GetValues(typeof(ElectricChargeDensityUnit)).Cast().ToArray(); - Zero = new ElectricChargeDensity(0, BaseUnit); - Info = new QuantityInfo("ElectricChargeDensity", - new UnitInfo[] - { - new UnitInfo(ElectricChargeDensityUnit.CoulombPerCubicMeter, "CoulombsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricChargeDensity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricChargeDensityInfo(string name, ElectricChargeDensityUnit baseUnit, IEnumerable> unitMappings, ElectricChargeDensity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricChargeDensityInfo(string name, ElectricChargeDensityUnit baseUnit, IEnumerable> unitMappings, ElectricChargeDensity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricChargeDensity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricChargeDensity", typeof(ElectricChargeDensity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricChargeDensity quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricChargeDensityInfo CreateDefault() + { + return new ElectricChargeDensityInfo(nameof(ElectricChargeDensity), DefaultBaseUnit, GetDefaultMappings(), new ElectricChargeDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricChargeDensity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricChargeDensityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricChargeDensityInfo(nameof(ElectricChargeDensity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricChargeDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T][L^-3][I]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-3, 0, 1, 1, 0, 0, 0); + + /// + /// The default base unit of ElectricChargeDensity is CoulombPerCubicMeter. All conversions, as defined in the , go via this value. + /// + public static ElectricChargeDensityUnit DefaultBaseUnit { get; } = ElectricChargeDensityUnit.CoulombPerCubicMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricChargeDensity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricChargeDensityUnit.CoulombPerCubicMeter, "CoulombPerCubicMeter", "CoulombsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricChargeDensity() + { + Info = ElectricChargeDensityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -116,27 +163,27 @@ public ElectricChargeDensity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricChargeDensity, which is CoulombPerCubicMeter. All conversions go via this value. /// - public static ElectricChargeDensityUnit BaseUnit { get; } + public static ElectricChargeDensityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricChargeDensity quantity. /// - public static ElectricChargeDensityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit CoulombPerCubicMeter. /// - public static ElectricChargeDensity Zero { get; } + public static ElectricChargeDensity Zero => Info.Zero; /// public static ElectricChargeDensity AdditiveIdentity => Zero; @@ -154,7 +201,7 @@ public ElectricChargeDensity(double value, UnitSystem unitSystem) public ElectricChargeDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -172,6 +219,9 @@ public ElectricChargeDensity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs index 31ae1f7508..051736cea3 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,34 +62,85 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricConductanceUnit? _unit; - static ElectricConductance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricConductanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, -1, 3, 2, 0, 0, 0); - BaseUnit = ElectricConductanceUnit.Siemens; - Units = Enum.GetValues(typeof(ElectricConductanceUnit)).Cast().ToArray(); - Zero = new ElectricConductance(0, BaseUnit); - Info = new QuantityInfo("ElectricConductance", - new UnitInfo[] - { - new UnitInfo(ElectricConductanceUnit.Gigamho, "Gigamhos", BaseUnits.Undefined, "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Gigasiemens, "Gigasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Kilomho, "Kilomhos", BaseUnits.Undefined, "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Kilosiemens, "Kilosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Megamho, "Megamhos", BaseUnits.Undefined, "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Megasiemens, "Megasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Mho, "Mhos", BaseUnits.Undefined, "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Micromho, "Micromhos", BaseUnits.Undefined, "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Microsiemens, "Microsiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere), "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Millimho, "Millimhos", BaseUnits.Undefined, "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Millisiemens, "Millisiemens", BaseUnits.Undefined, "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Nanomho, "Nanomhos", BaseUnits.Undefined, "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Nanosiemens, "Nanosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere), "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Siemens, "Siemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Teramho, "Teramhos", BaseUnits.Undefined, "ElectricConductance"), - new UnitInfo(ElectricConductanceUnit.Terasiemens, "Terasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricConductance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricConductanceInfo(string name, ElectricConductanceUnit baseUnit, IEnumerable> unitMappings, ElectricConductance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricConductanceInfo(string name, ElectricConductanceUnit baseUnit, IEnumerable> unitMappings, ElectricConductance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricConductance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricConductance", typeof(ElectricConductance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricConductance quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricConductanceInfo CreateDefault() + { + return new ElectricConductanceInfo(nameof(ElectricConductance), DefaultBaseUnit, GetDefaultMappings(), new ElectricConductance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricConductance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricConductanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricConductanceInfo(nameof(ElectricConductance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricConductance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^3][L^-2][M^-1][I^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, -1, 3, 2, 0, 0, 0); + + /// + /// The default base unit of ElectricConductance is Siemens. All conversions, as defined in the , go via this value. + /// + public static ElectricConductanceUnit DefaultBaseUnit { get; } = ElectricConductanceUnit.Siemens; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricConductance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricConductanceUnit.Gigamho, "Gigamho", "Gigamhos", BaseUnits.Undefined); + yield return new (ElectricConductanceUnit.Gigasiemens, "Gigasiemens", "Gigasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricConductanceUnit.Kilomho, "Kilomho", "Kilomhos", BaseUnits.Undefined); + yield return new (ElectricConductanceUnit.Kilosiemens, "Kilosiemens", "Kilosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricConductanceUnit.Megamho, "Megamho", "Megamhos", BaseUnits.Undefined); + yield return new (ElectricConductanceUnit.Megasiemens, "Megasiemens", "Megasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricConductanceUnit.Mho, "Mho", "Mhos", BaseUnits.Undefined); + yield return new (ElectricConductanceUnit.Micromho, "Micromho", "Micromhos", BaseUnits.Undefined); + yield return new (ElectricConductanceUnit.Microsiemens, "Microsiemens", "Microsiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricConductanceUnit.Millimho, "Millimho", "Millimhos", BaseUnits.Undefined); + yield return new (ElectricConductanceUnit.Millisiemens, "Millisiemens", "Millisiemens", BaseUnits.Undefined); + yield return new (ElectricConductanceUnit.Nanomho, "Nanomho", "Nanomhos", BaseUnits.Undefined); + yield return new (ElectricConductanceUnit.Nanosiemens, "Nanosiemens", "Nanosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricConductanceUnit.Siemens, "Siemens", "Siemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricConductanceUnit.Teramho, "Teramho", "Teramhos", BaseUnits.Undefined); + yield return new (ElectricConductanceUnit.Terasiemens, "Terasiemens", "Terasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricConductance() + { + Info = ElectricConductanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -131,27 +178,27 @@ public ElectricConductance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricConductance, which is Siemens. All conversions go via this value. /// - public static ElectricConductanceUnit BaseUnit { get; } + public static ElectricConductanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricConductance quantity. /// - public static ElectricConductanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Siemens. /// - public static ElectricConductance Zero { get; } + public static ElectricConductance Zero => Info.Zero; /// public static ElectricConductance AdditiveIdentity => Zero; @@ -169,7 +216,7 @@ public ElectricConductance(double value, UnitSystem unitSystem) public ElectricConductanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -187,6 +234,9 @@ public ElectricConductance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs index 6185357f60..7af479783b 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,24 +62,75 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricConductivityUnit? _unit; - static ElectricConductivity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricConductivityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-3, -1, 3, 2, 0, 0, 0); - BaseUnit = ElectricConductivityUnit.SiemensPerMeter; - Units = Enum.GetValues(typeof(ElectricConductivityUnit)).Cast().ToArray(); - Zero = new ElectricConductivity(0, BaseUnit); - Info = new QuantityInfo("ElectricConductivity", - new UnitInfo[] - { - new UnitInfo(ElectricConductivityUnit.MicrosiemensPerCentimeter, "MicrosiemensPerCentimeter", BaseUnits.Undefined, "ElectricConductivity"), - new UnitInfo(ElectricConductivityUnit.MillisiemensPerCentimeter, "MillisiemensPerCentimeter", BaseUnits.Undefined, "ElectricConductivity"), - new UnitInfo(ElectricConductivityUnit.SiemensPerCentimeter, "SiemensPerCentimeter", BaseUnits.Undefined, "ElectricConductivity"), - new UnitInfo(ElectricConductivityUnit.SiemensPerFoot, "SiemensPerFoot", BaseUnits.Undefined, "ElectricConductivity"), - new UnitInfo(ElectricConductivityUnit.SiemensPerInch, "SiemensPerInch", BaseUnits.Undefined, "ElectricConductivity"), - new UnitInfo(ElectricConductivityUnit.SiemensPerMeter, "SiemensPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricConductivity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricConductivityInfo(string name, ElectricConductivityUnit baseUnit, IEnumerable> unitMappings, ElectricConductivity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricConductivityInfo(string name, ElectricConductivityUnit baseUnit, IEnumerable> unitMappings, ElectricConductivity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricConductivity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricConductivity", typeof(ElectricConductivity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricConductivity quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricConductivityInfo CreateDefault() + { + return new ElectricConductivityInfo(nameof(ElectricConductivity), DefaultBaseUnit, GetDefaultMappings(), new ElectricConductivity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricConductivity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricConductivityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricConductivityInfo(nameof(ElectricConductivity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricConductivity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^3][L^-3][M^-1][I^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-3, -1, 3, 2, 0, 0, 0); + + /// + /// The default base unit of ElectricConductivity is SiemensPerMeter. All conversions, as defined in the , go via this value. + /// + public static ElectricConductivityUnit DefaultBaseUnit { get; } = ElectricConductivityUnit.SiemensPerMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricConductivity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricConductivityUnit.MicrosiemensPerCentimeter, "MicrosiemensPerCentimeter", "MicrosiemensPerCentimeter", BaseUnits.Undefined); + yield return new (ElectricConductivityUnit.MillisiemensPerCentimeter, "MillisiemensPerCentimeter", "MillisiemensPerCentimeter", BaseUnits.Undefined); + yield return new (ElectricConductivityUnit.SiemensPerCentimeter, "SiemensPerCentimeter", "SiemensPerCentimeter", BaseUnits.Undefined); + yield return new (ElectricConductivityUnit.SiemensPerFoot, "SiemensPerFoot", "SiemensPerFoot", BaseUnits.Undefined); + yield return new (ElectricConductivityUnit.SiemensPerInch, "SiemensPerInch", "SiemensPerInch", BaseUnits.Undefined); + yield return new (ElectricConductivityUnit.SiemensPerMeter, "SiemensPerMeter", "SiemensPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricConductivity() + { + Info = ElectricConductivityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -121,27 +168,27 @@ public ElectricConductivity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricConductivity, which is SiemensPerMeter. All conversions go via this value. /// - public static ElectricConductivityUnit BaseUnit { get; } + public static ElectricConductivityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricConductivity quantity. /// - public static ElectricConductivityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit SiemensPerMeter. /// - public static ElectricConductivity Zero { get; } + public static ElectricConductivity Zero => Info.Zero; /// public static ElectricConductivity AdditiveIdentity => Zero; @@ -159,7 +206,7 @@ public ElectricConductivity(double value, UnitSystem unitSystem) public ElectricConductivityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -177,6 +224,9 @@ public ElectricConductivity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs index 1f401e6938..087d8bb27e 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -73,27 +69,78 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricCurrentUnit? _unit; - static ElectricCurrent() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricCurrentInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, 0, 1, 0, 0, 0); - BaseUnit = ElectricCurrentUnit.Ampere; - Units = Enum.GetValues(typeof(ElectricCurrentUnit)).Cast().ToArray(); - Zero = new ElectricCurrent(0, BaseUnit); - Info = new QuantityInfo("ElectricCurrent", - new UnitInfo[] - { - new UnitInfo(ElectricCurrentUnit.Ampere, "Amperes", new BaseUnits(current: ElectricCurrentUnit.Ampere), "ElectricCurrent"), - new UnitInfo(ElectricCurrentUnit.Centiampere, "Centiamperes", new BaseUnits(current: ElectricCurrentUnit.Centiampere), "ElectricCurrent"), - new UnitInfo(ElectricCurrentUnit.Femtoampere, "Femtoamperes", new BaseUnits(current: ElectricCurrentUnit.Femtoampere), "ElectricCurrent"), - new UnitInfo(ElectricCurrentUnit.Kiloampere, "Kiloamperes", new BaseUnits(current: ElectricCurrentUnit.Kiloampere), "ElectricCurrent"), - new UnitInfo(ElectricCurrentUnit.Megaampere, "Megaamperes", new BaseUnits(current: ElectricCurrentUnit.Megaampere), "ElectricCurrent"), - new UnitInfo(ElectricCurrentUnit.Microampere, "Microamperes", new BaseUnits(current: ElectricCurrentUnit.Microampere), "ElectricCurrent"), - new UnitInfo(ElectricCurrentUnit.Milliampere, "Milliamperes", new BaseUnits(current: ElectricCurrentUnit.Milliampere), "ElectricCurrent"), - new UnitInfo(ElectricCurrentUnit.Nanoampere, "Nanoamperes", new BaseUnits(current: ElectricCurrentUnit.Nanoampere), "ElectricCurrent"), - new UnitInfo(ElectricCurrentUnit.Picoampere, "Picoamperes", new BaseUnits(current: ElectricCurrentUnit.Picoampere), "ElectricCurrent"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricCurrentInfo(string name, ElectricCurrentUnit baseUnit, IEnumerable> unitMappings, ElectricCurrent zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricCurrentInfo(string name, ElectricCurrentUnit baseUnit, IEnumerable> unitMappings, ElectricCurrent zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricCurrent.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricCurrent", typeof(ElectricCurrent).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricCurrent quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricCurrentInfo CreateDefault() + { + return new ElectricCurrentInfo(nameof(ElectricCurrent), DefaultBaseUnit, GetDefaultMappings(), new ElectricCurrent(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricCurrent quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricCurrentInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricCurrentInfo(nameof(ElectricCurrent), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricCurrent(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [I]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, 0, 1, 0, 0, 0); + + /// + /// The default base unit of ElectricCurrent is Ampere. All conversions, as defined in the , go via this value. + /// + public static ElectricCurrentUnit DefaultBaseUnit { get; } = ElectricCurrentUnit.Ampere; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricCurrent. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricCurrentUnit.Ampere, "Ampere", "Amperes", new BaseUnits(current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricCurrentUnit.Centiampere, "Centiampere", "Centiamperes", new BaseUnits(current: ElectricCurrentUnit.Centiampere)); + yield return new (ElectricCurrentUnit.Femtoampere, "Femtoampere", "Femtoamperes", new BaseUnits(current: ElectricCurrentUnit.Femtoampere)); + yield return new (ElectricCurrentUnit.Kiloampere, "Kiloampere", "Kiloamperes", new BaseUnits(current: ElectricCurrentUnit.Kiloampere)); + yield return new (ElectricCurrentUnit.Megaampere, "Megaampere", "Megaamperes", new BaseUnits(current: ElectricCurrentUnit.Megaampere)); + yield return new (ElectricCurrentUnit.Microampere, "Microampere", "Microamperes", new BaseUnits(current: ElectricCurrentUnit.Microampere)); + yield return new (ElectricCurrentUnit.Milliampere, "Milliampere", "Milliamperes", new BaseUnits(current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricCurrentUnit.Nanoampere, "Nanoampere", "Nanoamperes", new BaseUnits(current: ElectricCurrentUnit.Nanoampere)); + yield return new (ElectricCurrentUnit.Picoampere, "Picoampere", "Picoamperes", new BaseUnits(current: ElectricCurrentUnit.Picoampere)); + } + } + + static ElectricCurrent() + { + Info = ElectricCurrentInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -131,27 +178,27 @@ public ElectricCurrent(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricCurrent, which is Ampere. All conversions go via this value. /// - public static ElectricCurrentUnit BaseUnit { get; } + public static ElectricCurrentUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricCurrent quantity. /// - public static ElectricCurrentUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Ampere. /// - public static ElectricCurrent Zero { get; } + public static ElectricCurrent Zero => Info.Zero; /// public static ElectricCurrent AdditiveIdentity => Zero; @@ -169,7 +216,7 @@ public ElectricCurrent(double value, UnitSystem unitSystem) public ElectricCurrentUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -187,6 +234,9 @@ public ElectricCurrent(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs index 6e60b45b35..82a13cca7f 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentDensity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,21 +62,72 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricCurrentDensityUnit? _unit; - static ElectricCurrentDensity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricCurrentDensityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, 0, 0, 1, 0, 0, 0); - BaseUnit = ElectricCurrentDensityUnit.AmperePerSquareMeter; - Units = Enum.GetValues(typeof(ElectricCurrentDensityUnit)).Cast().ToArray(); - Zero = new ElectricCurrentDensity(0, BaseUnit); - Info = new QuantityInfo("ElectricCurrentDensity", - new UnitInfo[] - { - new UnitInfo(ElectricCurrentDensityUnit.AmperePerSquareFoot, "AmperesPerSquareFoot", new BaseUnits(length: LengthUnit.Foot, current: ElectricCurrentUnit.Ampere), "ElectricCurrentDensity"), - new UnitInfo(ElectricCurrentDensityUnit.AmperePerSquareInch, "AmperesPerSquareInch", new BaseUnits(length: LengthUnit.Inch, current: ElectricCurrentUnit.Ampere), "ElectricCurrentDensity"), - new UnitInfo(ElectricCurrentDensityUnit.AmperePerSquareMeter, "AmperesPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, current: ElectricCurrentUnit.Ampere), "ElectricCurrentDensity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricCurrentDensityInfo(string name, ElectricCurrentDensityUnit baseUnit, IEnumerable> unitMappings, ElectricCurrentDensity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricCurrentDensityInfo(string name, ElectricCurrentDensityUnit baseUnit, IEnumerable> unitMappings, ElectricCurrentDensity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricCurrentDensity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricCurrentDensity", typeof(ElectricCurrentDensity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricCurrentDensity quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricCurrentDensityInfo CreateDefault() + { + return new ElectricCurrentDensityInfo(nameof(ElectricCurrentDensity), DefaultBaseUnit, GetDefaultMappings(), new ElectricCurrentDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricCurrentDensity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricCurrentDensityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricCurrentDensityInfo(nameof(ElectricCurrentDensity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricCurrentDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-2][I]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, 0, 0, 1, 0, 0, 0); + + /// + /// The default base unit of ElectricCurrentDensity is AmperePerSquareMeter. All conversions, as defined in the , go via this value. + /// + public static ElectricCurrentDensityUnit DefaultBaseUnit { get; } = ElectricCurrentDensityUnit.AmperePerSquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricCurrentDensity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricCurrentDensityUnit.AmperePerSquareFoot, "AmperePerSquareFoot", "AmperesPerSquareFoot", new BaseUnits(length: LengthUnit.Foot, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricCurrentDensityUnit.AmperePerSquareInch, "AmperePerSquareInch", "AmperesPerSquareInch", new BaseUnits(length: LengthUnit.Inch, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricCurrentDensityUnit.AmperePerSquareMeter, "AmperePerSquareMeter", "AmperesPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricCurrentDensity() + { + Info = ElectricCurrentDensityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -118,27 +165,27 @@ public ElectricCurrentDensity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricCurrentDensity, which is AmperePerSquareMeter. All conversions go via this value. /// - public static ElectricCurrentDensityUnit BaseUnit { get; } + public static ElectricCurrentDensityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricCurrentDensity quantity. /// - public static ElectricCurrentDensityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit AmperePerSquareMeter. /// - public static ElectricCurrentDensity Zero { get; } + public static ElectricCurrentDensity Zero => Info.Zero; /// public static ElectricCurrentDensity AdditiveIdentity => Zero; @@ -156,7 +203,7 @@ public ElectricCurrentDensity(double value, UnitSystem unitSystem) public ElectricCurrentDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -174,6 +221,9 @@ public ElectricCurrentDensity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs index d6f5d8e9b2..e311b30f86 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricCurrentGradient.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,25 +62,76 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricCurrentGradientUnit? _unit; - static ElectricCurrentGradient() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricCurrentGradientInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, -1, 1, 0, 0, 0); - BaseUnit = ElectricCurrentGradientUnit.AmperePerSecond; - Units = Enum.GetValues(typeof(ElectricCurrentGradientUnit)).Cast().ToArray(); - Zero = new ElectricCurrentGradient(0, BaseUnit); - Info = new QuantityInfo("ElectricCurrentGradient", - new UnitInfo[] - { - new UnitInfo(ElectricCurrentGradientUnit.AmperePerMicrosecond, "AmperesPerMicrosecond", new BaseUnits(time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Ampere), "ElectricCurrentGradient"), - new UnitInfo(ElectricCurrentGradientUnit.AmperePerMillisecond, "AmperesPerMillisecond", new BaseUnits(time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere), "ElectricCurrentGradient"), - new UnitInfo(ElectricCurrentGradientUnit.AmperePerMinute, "AmperesPerMinute", new BaseUnits(time: DurationUnit.Minute, current: ElectricCurrentUnit.Ampere), "ElectricCurrentGradient"), - new UnitInfo(ElectricCurrentGradientUnit.AmperePerNanosecond, "AmperesPerNanosecond", new BaseUnits(time: DurationUnit.Nanosecond, current: ElectricCurrentUnit.Ampere), "ElectricCurrentGradient"), - new UnitInfo(ElectricCurrentGradientUnit.AmperePerSecond, "AmperesPerSecond", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricCurrentGradient"), - new UnitInfo(ElectricCurrentGradientUnit.MilliamperePerMinute, "MilliamperesPerMinute", new BaseUnits(time: DurationUnit.Minute, current: ElectricCurrentUnit.Milliampere), "ElectricCurrentGradient"), - new UnitInfo(ElectricCurrentGradientUnit.MilliamperePerSecond, "MilliamperesPerSecond", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere), "ElectricCurrentGradient"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricCurrentGradientInfo(string name, ElectricCurrentGradientUnit baseUnit, IEnumerable> unitMappings, ElectricCurrentGradient zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricCurrentGradientInfo(string name, ElectricCurrentGradientUnit baseUnit, IEnumerable> unitMappings, ElectricCurrentGradient zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricCurrentGradient.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricCurrentGradient", typeof(ElectricCurrentGradient).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricCurrentGradient quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricCurrentGradientInfo CreateDefault() + { + return new ElectricCurrentGradientInfo(nameof(ElectricCurrentGradient), DefaultBaseUnit, GetDefaultMappings(), new ElectricCurrentGradient(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricCurrentGradient quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricCurrentGradientInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricCurrentGradientInfo(nameof(ElectricCurrentGradient), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricCurrentGradient(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][I]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, -1, 1, 0, 0, 0); + + /// + /// The default base unit of ElectricCurrentGradient is AmperePerSecond. All conversions, as defined in the , go via this value. + /// + public static ElectricCurrentGradientUnit DefaultBaseUnit { get; } = ElectricCurrentGradientUnit.AmperePerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricCurrentGradient. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricCurrentGradientUnit.AmperePerMicrosecond, "AmperePerMicrosecond", "AmperesPerMicrosecond", new BaseUnits(time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricCurrentGradientUnit.AmperePerMillisecond, "AmperePerMillisecond", "AmperesPerMillisecond", new BaseUnits(time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricCurrentGradientUnit.AmperePerMinute, "AmperePerMinute", "AmperesPerMinute", new BaseUnits(time: DurationUnit.Minute, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricCurrentGradientUnit.AmperePerNanosecond, "AmperePerNanosecond", "AmperesPerNanosecond", new BaseUnits(time: DurationUnit.Nanosecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricCurrentGradientUnit.AmperePerSecond, "AmperePerSecond", "AmperesPerSecond", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricCurrentGradientUnit.MilliamperePerMinute, "MilliamperePerMinute", "MilliamperesPerMinute", new BaseUnits(time: DurationUnit.Minute, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricCurrentGradientUnit.MilliamperePerSecond, "MilliamperePerSecond", "MilliamperesPerSecond", new BaseUnits(time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere)); + } + } + + static ElectricCurrentGradient() + { + Info = ElectricCurrentGradientInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -122,27 +169,27 @@ public ElectricCurrentGradient(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricCurrentGradient, which is AmperePerSecond. All conversions go via this value. /// - public static ElectricCurrentGradientUnit BaseUnit { get; } + public static ElectricCurrentGradientUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricCurrentGradient quantity. /// - public static ElectricCurrentGradientUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit AmperePerSecond. /// - public static ElectricCurrentGradient Zero { get; } + public static ElectricCurrentGradient Zero => Info.Zero; /// public static ElectricCurrentGradient AdditiveIdentity => Zero; @@ -160,7 +207,7 @@ public ElectricCurrentGradient(double value, UnitSystem unitSystem) public ElectricCurrentGradientUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -178,6 +225,9 @@ public ElectricCurrentGradient(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs index c18116b8d2..e9fb0bbd94 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricField.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,19 +62,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricFieldUnit? _unit; - static ElectricField() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricFieldInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 1, -3, -1, 0, 0, 0); - BaseUnit = ElectricFieldUnit.VoltPerMeter; - Units = Enum.GetValues(typeof(ElectricFieldUnit)).Cast().ToArray(); - Zero = new ElectricField(0, BaseUnit); - Info = new QuantityInfo("ElectricField", - new UnitInfo[] - { - new UnitInfo(ElectricFieldUnit.VoltPerMeter, "VoltsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricField"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricFieldInfo(string name, ElectricFieldUnit baseUnit, IEnumerable> unitMappings, ElectricField zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricFieldInfo(string name, ElectricFieldUnit baseUnit, IEnumerable> unitMappings, ElectricField zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricField.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricField", typeof(ElectricField).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricField quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricFieldInfo CreateDefault() + { + return new ElectricFieldInfo(nameof(ElectricField), DefaultBaseUnit, GetDefaultMappings(), new ElectricField(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricField quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricFieldInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricFieldInfo(nameof(ElectricField), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricField(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L][M][I^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 1, -3, -1, 0, 0, 0); + + /// + /// The default base unit of ElectricField is VoltPerMeter. All conversions, as defined in the , go via this value. + /// + public static ElectricFieldUnit DefaultBaseUnit { get; } = ElectricFieldUnit.VoltPerMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricField. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricFieldUnit.VoltPerMeter, "VoltPerMeter", "VoltsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricField() + { + Info = ElectricFieldInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -116,27 +163,27 @@ public ElectricField(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricField, which is VoltPerMeter. All conversions go via this value. /// - public static ElectricFieldUnit BaseUnit { get; } + public static ElectricFieldUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricField quantity. /// - public static ElectricFieldUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit VoltPerMeter. /// - public static ElectricField Zero { get; } + public static ElectricField Zero => Info.Zero; /// public static ElectricField AdditiveIdentity => Zero; @@ -154,7 +201,7 @@ public ElectricField(double value, UnitSystem unitSystem) public ElectricFieldUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -172,6 +219,9 @@ public ElectricField(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs index 3bc020f499..f37c26a00a 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricImpedance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -67,26 +63,77 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricImpedanceUnit? _unit; - static ElectricImpedance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricImpedanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -3, -2, 0, 0, 0); - BaseUnit = ElectricImpedanceUnit.Ohm; - Units = Enum.GetValues(typeof(ElectricImpedanceUnit)).Cast().ToArray(); - Zero = new ElectricImpedance(0, BaseUnit); - Info = new QuantityInfo("ElectricImpedance", - new UnitInfo[] - { - new UnitInfo(ElectricImpedanceUnit.Gigaohm, "Gigaohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere), "ElectricImpedance"), - new UnitInfo(ElectricImpedanceUnit.Kiloohm, "Kiloohms", BaseUnits.Undefined, "ElectricImpedance"), - new UnitInfo(ElectricImpedanceUnit.Megaohm, "Megaohms", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricImpedance"), - new UnitInfo(ElectricImpedanceUnit.Microohm, "Microohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricImpedance"), - new UnitInfo(ElectricImpedanceUnit.Milliohm, "Milliohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricImpedance"), - new UnitInfo(ElectricImpedanceUnit.Nanoohm, "Nanoohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricImpedance"), - new UnitInfo(ElectricImpedanceUnit.Ohm, "Ohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricImpedance"), - new UnitInfo(ElectricImpedanceUnit.Teraohm, "Teraohms", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricImpedance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricImpedanceInfo(string name, ElectricImpedanceUnit baseUnit, IEnumerable> unitMappings, ElectricImpedance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricImpedanceInfo(string name, ElectricImpedanceUnit baseUnit, IEnumerable> unitMappings, ElectricImpedance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricImpedance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricImpedance", typeof(ElectricImpedance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricImpedance quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricImpedanceInfo CreateDefault() + { + return new ElectricImpedanceInfo(nameof(ElectricImpedance), DefaultBaseUnit, GetDefaultMappings(), new ElectricImpedance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricImpedance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricImpedanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricImpedanceInfo(nameof(ElectricImpedance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricImpedance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^2][M][I^-2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -3, -2, 0, 0, 0); + + /// + /// The default base unit of ElectricImpedance is Ohm. All conversions, as defined in the , go via this value. + /// + public static ElectricImpedanceUnit DefaultBaseUnit { get; } = ElectricImpedanceUnit.Ohm; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricImpedance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricImpedanceUnit.Gigaohm, "Gigaohm", "Gigaohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricImpedanceUnit.Kiloohm, "Kiloohm", "Kiloohms", BaseUnits.Undefined); + yield return new (ElectricImpedanceUnit.Megaohm, "Megaohm", "Megaohms", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricImpedanceUnit.Microohm, "Microohm", "Microohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricImpedanceUnit.Milliohm, "Milliohm", "Milliohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricImpedanceUnit.Nanoohm, "Nanoohm", "Nanoohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricImpedanceUnit.Ohm, "Ohm", "Ohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricImpedanceUnit.Teraohm, "Teraohm", "Teraohms", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricImpedance() + { + Info = ElectricImpedanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -124,27 +171,27 @@ public ElectricImpedance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricImpedance, which is Ohm. All conversions go via this value. /// - public static ElectricImpedanceUnit BaseUnit { get; } + public static ElectricImpedanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricImpedance quantity. /// - public static ElectricImpedanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Ohm. /// - public static ElectricImpedance Zero { get; } + public static ElectricImpedance Zero => Info.Zero; /// public static ElectricImpedance AdditiveIdentity => Zero; @@ -162,7 +209,7 @@ public ElectricImpedance(double value, UnitSystem unitSystem) public ElectricImpedanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -180,6 +227,9 @@ public ElectricImpedance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs index 73e87af91e..3984ab9fb7 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricInductance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,23 +62,74 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricInductanceUnit? _unit; - static ElectricInductance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricInductanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -2, -2, 0, 0, 0); - BaseUnit = ElectricInductanceUnit.Henry; - Units = Enum.GetValues(typeof(ElectricInductanceUnit)).Cast().ToArray(); - Zero = new ElectricInductance(0, BaseUnit); - Info = new QuantityInfo("ElectricInductance", - new UnitInfo[] - { - new UnitInfo(ElectricInductanceUnit.Henry, "Henries", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricInductance"), - new UnitInfo(ElectricInductanceUnit.Microhenry, "Microhenries", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricInductance"), - new UnitInfo(ElectricInductanceUnit.Millihenry, "Millihenries", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricInductance"), - new UnitInfo(ElectricInductanceUnit.Nanohenry, "Nanohenries", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricInductance"), - new UnitInfo(ElectricInductanceUnit.Picohenry, "Picohenries", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricInductance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricInductanceInfo(string name, ElectricInductanceUnit baseUnit, IEnumerable> unitMappings, ElectricInductance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricInductanceInfo(string name, ElectricInductanceUnit baseUnit, IEnumerable> unitMappings, ElectricInductance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricInductance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricInductance", typeof(ElectricInductance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricInductance quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricInductanceInfo CreateDefault() + { + return new ElectricInductanceInfo(nameof(ElectricInductance), DefaultBaseUnit, GetDefaultMappings(), new ElectricInductance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricInductance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricInductanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricInductanceInfo(nameof(ElectricInductance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricInductance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2][M][I^-2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -2, -2, 0, 0, 0); + + /// + /// The default base unit of ElectricInductance is Henry. All conversions, as defined in the , go via this value. + /// + public static ElectricInductanceUnit DefaultBaseUnit { get; } = ElectricInductanceUnit.Henry; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricInductance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricInductanceUnit.Henry, "Henry", "Henries", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricInductanceUnit.Microhenry, "Microhenry", "Microhenries", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricInductanceUnit.Millihenry, "Millihenry", "Millihenries", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricInductanceUnit.Nanohenry, "Nanohenry", "Nanohenries", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricInductanceUnit.Picohenry, "Picohenry", "Picohenries", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricInductance() + { + Info = ElectricInductanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -120,27 +167,27 @@ public ElectricInductance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricInductance, which is Henry. All conversions go via this value. /// - public static ElectricInductanceUnit BaseUnit { get; } + public static ElectricInductanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricInductance quantity. /// - public static ElectricInductanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Henry. /// - public static ElectricInductance Zero { get; } + public static ElectricInductance Zero => Info.Zero; /// public static ElectricInductance AdditiveIdentity => Zero; @@ -158,7 +205,7 @@ public ElectricInductance(double value, UnitSystem unitSystem) public ElectricInductanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -176,6 +223,9 @@ public ElectricInductance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs index 0524f7ba67..b5acee7a78 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotential.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -72,24 +68,75 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricPotentialUnit? _unit; - static ElectricPotential() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricPotentialInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -3, -1, 0, 0, 0); - BaseUnit = ElectricPotentialUnit.Volt; - Units = Enum.GetValues(typeof(ElectricPotentialUnit)).Cast().ToArray(); - Zero = new ElectricPotential(0, BaseUnit); - Info = new QuantityInfo("ElectricPotential", - new UnitInfo[] - { - new UnitInfo(ElectricPotentialUnit.Kilovolt, "Kilovolts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere), "ElectricPotential"), - new UnitInfo(ElectricPotentialUnit.Megavolt, "Megavolts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere), "ElectricPotential"), - new UnitInfo(ElectricPotentialUnit.Microvolt, "Microvolts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricPotential"), - new UnitInfo(ElectricPotentialUnit.Millivolt, "Millivolts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricPotential"), - new UnitInfo(ElectricPotentialUnit.Nanovolt, "Nanovolts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricPotential"), - new UnitInfo(ElectricPotentialUnit.Volt, "Volts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricPotential"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricPotentialInfo(string name, ElectricPotentialUnit baseUnit, IEnumerable> unitMappings, ElectricPotential zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricPotentialInfo(string name, ElectricPotentialUnit baseUnit, IEnumerable> unitMappings, ElectricPotential zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricPotential.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricPotential", typeof(ElectricPotential).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricPotential quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricPotentialInfo CreateDefault() + { + return new ElectricPotentialInfo(nameof(ElectricPotential), DefaultBaseUnit, GetDefaultMappings(), new ElectricPotential(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricPotential quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricPotentialInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricPotentialInfo(nameof(ElectricPotential), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricPotential(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^2][M][I^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -3, -1, 0, 0, 0); + + /// + /// The default base unit of ElectricPotential is Volt. All conversions, as defined in the , go via this value. + /// + public static ElectricPotentialUnit DefaultBaseUnit { get; } = ElectricPotentialUnit.Volt; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricPotential. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricPotentialUnit.Kilovolt, "Kilovolt", "Kilovolts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricPotentialUnit.Megavolt, "Megavolt", "Megavolts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere)); + yield return new (ElectricPotentialUnit.Microvolt, "Microvolt", "Microvolts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialUnit.Millivolt, "Millivolt", "Millivolts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialUnit.Nanovolt, "Nanovolt", "Nanovolts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialUnit.Volt, "Volt", "Volts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricPotential() + { + Info = ElectricPotentialInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -127,27 +174,27 @@ public ElectricPotential(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricPotential, which is Volt. All conversions go via this value. /// - public static ElectricPotentialUnit BaseUnit { get; } + public static ElectricPotentialUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricPotential quantity. /// - public static ElectricPotentialUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Volt. /// - public static ElectricPotential Zero { get; } + public static ElectricPotential Zero => Info.Zero; /// public static ElectricPotential AdditiveIdentity => Zero; @@ -165,7 +212,7 @@ public ElectricPotential(double value, UnitSystem unitSystem) public ElectricPotentialUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -183,6 +230,9 @@ public ElectricPotential(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs index 1a7d89b1ca..58d6360c10 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricPotentialChangeRate.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,38 +59,89 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricPotentialChangeRateUnit? _unit; - static ElectricPotentialChangeRate() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricPotentialChangeRateInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -4, -1, 0, 0, 0); - BaseUnit = ElectricPotentialChangeRateUnit.VoltPerSecond; - Units = Enum.GetValues(typeof(ElectricPotentialChangeRateUnit)).Cast().ToArray(); - Zero = new ElectricPotentialChangeRate(0, BaseUnit); - Info = new QuantityInfo("ElectricPotentialChangeRate", - new UnitInfo[] - { - new UnitInfo(ElectricPotentialChangeRateUnit.KilovoltPerHour, "KilovoltsPerHour", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Hour, current: ElectricCurrentUnit.Milliampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, "KilovoltsPerMicrosecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Milliampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.KilovoltPerMinute, "KilovoltsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute, current: ElectricCurrentUnit.Milliampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.KilovoltPerSecond, "KilovoltsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MegavoltPerHour, "MegavoltsPerHour", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Hour, current: ElectricCurrentUnit.Microampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, "MegavoltsPerMicrosecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Microampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MegavoltPerMinute, "MegavoltsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute, current: ElectricCurrentUnit.Microampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MegavoltPerSecond, "MegavoltsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MicrovoltPerHour, "MicrovoltsPerHour", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Hour, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, "MicrovoltsPerMicrosecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MicrovoltPerMinute, "MicrovoltsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Minute, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MicrovoltPerSecond, "MicrovoltsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MillivoltPerHour, "MillivoltsPerHour", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Hour, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, "MillivoltsPerMicrosecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MillivoltPerMinute, "MillivoltsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Minute, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.MillivoltPerSecond, "MillivoltsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.VoltPerHour, "VoltsPerHour", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Hour, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.VoltPerMicrosecond, "VoltsPerMicrosecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.VoltPerMinute, "VoltsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - new UnitInfo(ElectricPotentialChangeRateUnit.VoltPerSecond, "VoltsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricPotentialChangeRate"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricPotentialChangeRateInfo(string name, ElectricPotentialChangeRateUnit baseUnit, IEnumerable> unitMappings, ElectricPotentialChangeRate zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricPotentialChangeRateInfo(string name, ElectricPotentialChangeRateUnit baseUnit, IEnumerable> unitMappings, ElectricPotentialChangeRate zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricPotentialChangeRate.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricPotentialChangeRate", typeof(ElectricPotentialChangeRate).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricPotentialChangeRate quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricPotentialChangeRateInfo CreateDefault() + { + return new ElectricPotentialChangeRateInfo(nameof(ElectricPotentialChangeRate), DefaultBaseUnit, GetDefaultMappings(), new ElectricPotentialChangeRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricPotentialChangeRate quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricPotentialChangeRateInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricPotentialChangeRateInfo(nameof(ElectricPotentialChangeRate), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricPotentialChangeRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-4][L^2][M][I^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -4, -1, 0, 0, 0); + + /// + /// The default base unit of ElectricPotentialChangeRate is VoltPerSecond. All conversions, as defined in the , go via this value. + /// + public static ElectricPotentialChangeRateUnit DefaultBaseUnit { get; } = ElectricPotentialChangeRateUnit.VoltPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricPotentialChangeRate. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricPotentialChangeRateUnit.KilovoltPerHour, "KilovoltPerHour", "KilovoltsPerHour", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Hour, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, "KilovoltPerMicrosecond", "KilovoltsPerMicrosecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricPotentialChangeRateUnit.KilovoltPerMinute, "KilovoltPerMinute", "KilovoltsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricPotentialChangeRateUnit.KilovoltPerSecond, "KilovoltPerSecond", "KilovoltsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricPotentialChangeRateUnit.MegavoltPerHour, "MegavoltPerHour", "MegavoltsPerHour", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Hour, current: ElectricCurrentUnit.Microampere)); + yield return new (ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, "MegavoltPerMicrosecond", "MegavoltsPerMicrosecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Microampere)); + yield return new (ElectricPotentialChangeRateUnit.MegavoltPerMinute, "MegavoltPerMinute", "MegavoltsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute, current: ElectricCurrentUnit.Microampere)); + yield return new (ElectricPotentialChangeRateUnit.MegavoltPerSecond, "MegavoltPerSecond", "MegavoltsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere)); + yield return new (ElectricPotentialChangeRateUnit.MicrovoltPerHour, "MicrovoltPerHour", "MicrovoltsPerHour", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Hour, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, "MicrovoltPerMicrosecond", "MicrovoltsPerMicrosecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialChangeRateUnit.MicrovoltPerMinute, "MicrovoltPerMinute", "MicrovoltsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Minute, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialChangeRateUnit.MicrovoltPerSecond, "MicrovoltPerSecond", "MicrovoltsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialChangeRateUnit.MillivoltPerHour, "MillivoltPerHour", "MillivoltsPerHour", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Hour, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, "MillivoltPerMicrosecond", "MillivoltsPerMicrosecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialChangeRateUnit.MillivoltPerMinute, "MillivoltPerMinute", "MillivoltsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Minute, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialChangeRateUnit.MillivoltPerSecond, "MillivoltPerSecond", "MillivoltsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialChangeRateUnit.VoltPerHour, "VoltPerHour", "VoltsPerHour", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Hour, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialChangeRateUnit.VoltPerMicrosecond, "VoltPerMicrosecond", "VoltsPerMicrosecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Microsecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialChangeRateUnit.VoltPerMinute, "VoltPerMinute", "VoltsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricPotentialChangeRateUnit.VoltPerSecond, "VoltPerSecond", "VoltsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricPotentialChangeRate() + { + Info = ElectricPotentialChangeRateInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -132,27 +179,27 @@ public ElectricPotentialChangeRate(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricPotentialChangeRate, which is VoltPerSecond. All conversions go via this value. /// - public static ElectricPotentialChangeRateUnit BaseUnit { get; } + public static ElectricPotentialChangeRateUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricPotentialChangeRate quantity. /// - public static ElectricPotentialChangeRateUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit VoltPerSecond. /// - public static ElectricPotentialChangeRate Zero { get; } + public static ElectricPotentialChangeRate Zero => Info.Zero; /// public static ElectricPotentialChangeRate AdditiveIdentity => Zero; @@ -170,7 +217,7 @@ public ElectricPotentialChangeRate(double value, UnitSystem unitSystem) public ElectricPotentialChangeRateUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -188,6 +235,9 @@ public ElectricPotentialChangeRate(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs index d38bbf9f28..392a5f58d6 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,26 +62,77 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricReactanceUnit? _unit; - static ElectricReactance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricReactanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -3, -2, 0, 0, 0); - BaseUnit = ElectricReactanceUnit.Ohm; - Units = Enum.GetValues(typeof(ElectricReactanceUnit)).Cast().ToArray(); - Zero = new ElectricReactance(0, BaseUnit); - Info = new QuantityInfo("ElectricReactance", - new UnitInfo[] - { - new UnitInfo(ElectricReactanceUnit.Gigaohm, "Gigaohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere), "ElectricReactance"), - new UnitInfo(ElectricReactanceUnit.Kiloohm, "Kiloohms", BaseUnits.Undefined, "ElectricReactance"), - new UnitInfo(ElectricReactanceUnit.Megaohm, "Megaohms", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricReactance"), - new UnitInfo(ElectricReactanceUnit.Microohm, "Microohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricReactance"), - new UnitInfo(ElectricReactanceUnit.Milliohm, "Milliohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricReactance"), - new UnitInfo(ElectricReactanceUnit.Nanoohm, "Nanoohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricReactance"), - new UnitInfo(ElectricReactanceUnit.Ohm, "Ohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricReactance"), - new UnitInfo(ElectricReactanceUnit.Teraohm, "Teraohms", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricReactance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricReactanceInfo(string name, ElectricReactanceUnit baseUnit, IEnumerable> unitMappings, ElectricReactance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricReactanceInfo(string name, ElectricReactanceUnit baseUnit, IEnumerable> unitMappings, ElectricReactance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricReactance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricReactance", typeof(ElectricReactance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricReactance quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricReactanceInfo CreateDefault() + { + return new ElectricReactanceInfo(nameof(ElectricReactance), DefaultBaseUnit, GetDefaultMappings(), new ElectricReactance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricReactance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricReactanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricReactanceInfo(nameof(ElectricReactance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricReactance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^2][M][I^-2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -3, -2, 0, 0, 0); + + /// + /// The default base unit of ElectricReactance is Ohm. All conversions, as defined in the , go via this value. + /// + public static ElectricReactanceUnit DefaultBaseUnit { get; } = ElectricReactanceUnit.Ohm; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricReactance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricReactanceUnit.Gigaohm, "Gigaohm", "Gigaohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricReactanceUnit.Kiloohm, "Kiloohm", "Kiloohms", BaseUnits.Undefined); + yield return new (ElectricReactanceUnit.Megaohm, "Megaohm", "Megaohms", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricReactanceUnit.Microohm, "Microohm", "Microohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricReactanceUnit.Milliohm, "Milliohm", "Milliohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricReactanceUnit.Nanoohm, "Nanoohm", "Nanoohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricReactanceUnit.Ohm, "Ohm", "Ohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricReactanceUnit.Teraohm, "Teraohm", "Teraohms", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricReactance() + { + Info = ElectricReactanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -123,27 +170,27 @@ public ElectricReactance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricReactance, which is Ohm. All conversions go via this value. /// - public static ElectricReactanceUnit BaseUnit { get; } + public static ElectricReactanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricReactance quantity. /// - public static ElectricReactanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Ohm. /// - public static ElectricReactance Zero { get; } + public static ElectricReactance Zero => Info.Zero; /// public static ElectricReactance AdditiveIdentity => Zero; @@ -161,7 +208,7 @@ public ElectricReactance(double value, UnitSystem unitSystem) public ElectricReactanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -179,6 +226,9 @@ public ElectricReactance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs index fcbda67d80..34cfc9fb17 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactiveEnergy.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,21 +59,72 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricReactiveEnergyUnit? _unit; - static ElectricReactiveEnergy() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricReactiveEnergyInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); - BaseUnit = ElectricReactiveEnergyUnit.VoltampereReactiveHour; - Units = Enum.GetValues(typeof(ElectricReactiveEnergyUnit)).Cast().ToArray(); - Zero = new ElectricReactiveEnergy(0, BaseUnit); - Info = new QuantityInfo("ElectricReactiveEnergy", - new UnitInfo[] - { - new UnitInfo(ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, "KilovoltampereReactiveHours", BaseUnits.Undefined, "ElectricReactiveEnergy"), - new UnitInfo(ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, "MegavoltampereReactiveHours", BaseUnits.Undefined, "ElectricReactiveEnergy"), - new UnitInfo(ElectricReactiveEnergyUnit.VoltampereReactiveHour, "VoltampereReactiveHours", BaseUnits.Undefined, "ElectricReactiveEnergy"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricReactiveEnergyInfo(string name, ElectricReactiveEnergyUnit baseUnit, IEnumerable> unitMappings, ElectricReactiveEnergy zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricReactiveEnergyInfo(string name, ElectricReactiveEnergyUnit baseUnit, IEnumerable> unitMappings, ElectricReactiveEnergy zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricReactiveEnergy.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricReactiveEnergy", typeof(ElectricReactiveEnergy).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricReactiveEnergy quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricReactiveEnergyInfo CreateDefault() + { + return new ElectricReactiveEnergyInfo(nameof(ElectricReactiveEnergy), DefaultBaseUnit, GetDefaultMappings(), new ElectricReactiveEnergy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricReactiveEnergy quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricReactiveEnergyInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricReactiveEnergyInfo(nameof(ElectricReactiveEnergy), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricReactiveEnergy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of ElectricReactiveEnergy is VoltampereReactiveHour. All conversions, as defined in the , go via this value. + /// + public static ElectricReactiveEnergyUnit DefaultBaseUnit { get; } = ElectricReactiveEnergyUnit.VoltampereReactiveHour; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricReactiveEnergy. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricReactiveEnergyUnit.KilovoltampereReactiveHour, "KilovoltampereReactiveHour", "KilovoltampereReactiveHours", BaseUnits.Undefined); + yield return new (ElectricReactiveEnergyUnit.MegavoltampereReactiveHour, "MegavoltampereReactiveHour", "MegavoltampereReactiveHours", BaseUnits.Undefined); + yield return new (ElectricReactiveEnergyUnit.VoltampereReactiveHour, "VoltampereReactiveHour", "VoltampereReactiveHours", BaseUnits.Undefined); + } + } + + static ElectricReactiveEnergy() + { + Info = ElectricReactiveEnergyInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -115,27 +162,27 @@ public ElectricReactiveEnergy(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricReactiveEnergy, which is VoltampereReactiveHour. All conversions go via this value. /// - public static ElectricReactiveEnergyUnit BaseUnit { get; } + public static ElectricReactiveEnergyUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricReactiveEnergy quantity. /// - public static ElectricReactiveEnergyUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit VoltampereReactiveHour. /// - public static ElectricReactiveEnergy Zero { get; } + public static ElectricReactiveEnergy Zero => Info.Zero; /// public static ElectricReactiveEnergy AdditiveIdentity => Zero; @@ -153,7 +200,7 @@ public ElectricReactiveEnergy(double value, UnitSystem unitSystem) public ElectricReactiveEnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -171,6 +218,9 @@ public ElectricReactiveEnergy(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs index 7e3602d3af..5e636725b6 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricReactivePower.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,22 +62,73 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricReactivePowerUnit? _unit; - static ElectricReactivePower() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricReactivePowerInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); - BaseUnit = ElectricReactivePowerUnit.VoltampereReactive; - Units = Enum.GetValues(typeof(ElectricReactivePowerUnit)).Cast().ToArray(); - Zero = new ElectricReactivePower(0, BaseUnit); - Info = new QuantityInfo("ElectricReactivePower", - new UnitInfo[] - { - new UnitInfo(ElectricReactivePowerUnit.GigavoltampereReactive, "GigavoltamperesReactive", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond), "ElectricReactivePower"), - new UnitInfo(ElectricReactivePowerUnit.KilovoltampereReactive, "KilovoltamperesReactive", BaseUnits.Undefined, "ElectricReactivePower"), - new UnitInfo(ElectricReactivePowerUnit.MegavoltampereReactive, "MegavoltamperesReactive", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ElectricReactivePower"), - new UnitInfo(ElectricReactivePowerUnit.VoltampereReactive, "VoltamperesReactive", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ElectricReactivePower"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricReactivePowerInfo(string name, ElectricReactivePowerUnit baseUnit, IEnumerable> unitMappings, ElectricReactivePower zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricReactivePowerInfo(string name, ElectricReactivePowerUnit baseUnit, IEnumerable> unitMappings, ElectricReactivePower zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricReactivePower.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricReactivePower", typeof(ElectricReactivePower).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricReactivePower quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricReactivePowerInfo CreateDefault() + { + return new ElectricReactivePowerInfo(nameof(ElectricReactivePower), DefaultBaseUnit, GetDefaultMappings(), new ElectricReactivePower(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricReactivePower quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricReactivePowerInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricReactivePowerInfo(nameof(ElectricReactivePower), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricReactivePower(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); + + /// + /// The default base unit of ElectricReactivePower is VoltampereReactive. All conversions, as defined in the , go via this value. + /// + public static ElectricReactivePowerUnit DefaultBaseUnit { get; } = ElectricReactivePowerUnit.VoltampereReactive; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricReactivePower. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricReactivePowerUnit.GigavoltampereReactive, "GigavoltampereReactive", "GigavoltamperesReactive", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond)); + yield return new (ElectricReactivePowerUnit.KilovoltampereReactive, "KilovoltampereReactive", "KilovoltamperesReactive", BaseUnits.Undefined); + yield return new (ElectricReactivePowerUnit.MegavoltampereReactive, "MegavoltampereReactive", "MegavoltamperesReactive", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ElectricReactivePowerUnit.VoltampereReactive, "VoltampereReactive", "VoltamperesReactive", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + } + } + + static ElectricReactivePower() + { + Info = ElectricReactivePowerInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -119,27 +166,27 @@ public ElectricReactivePower(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricReactivePower, which is VoltampereReactive. All conversions go via this value. /// - public static ElectricReactivePowerUnit BaseUnit { get; } + public static ElectricReactivePowerUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricReactivePower quantity. /// - public static ElectricReactivePowerUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit VoltampereReactive. /// - public static ElectricReactivePower Zero { get; } + public static ElectricReactivePower Zero => Info.Zero; /// public static ElectricReactivePower AdditiveIdentity => Zero; @@ -157,7 +204,7 @@ public ElectricReactivePower(double value, UnitSystem unitSystem) public ElectricReactivePowerUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -175,6 +222,9 @@ public ElectricReactivePower(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs index f4680cbd50..b2c6f4bcd5 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -69,26 +65,77 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricResistanceUnit? _unit; - static ElectricResistance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricResistanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -3, -2, 0, 0, 0); - BaseUnit = ElectricResistanceUnit.Ohm; - Units = Enum.GetValues(typeof(ElectricResistanceUnit)).Cast().ToArray(); - Zero = new ElectricResistance(0, BaseUnit); - Info = new QuantityInfo("ElectricResistance", - new UnitInfo[] - { - new UnitInfo(ElectricResistanceUnit.Gigaohm, "Gigaohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere), "ElectricResistance"), - new UnitInfo(ElectricResistanceUnit.Kiloohm, "Kiloohms", BaseUnits.Undefined, "ElectricResistance"), - new UnitInfo(ElectricResistanceUnit.Megaohm, "Megaohms", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistance"), - new UnitInfo(ElectricResistanceUnit.Microohm, "Microohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistance"), - new UnitInfo(ElectricResistanceUnit.Milliohm, "Milliohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistance"), - new UnitInfo(ElectricResistanceUnit.Nanoohm, "Nanoohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistance"), - new UnitInfo(ElectricResistanceUnit.Ohm, "Ohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistance"), - new UnitInfo(ElectricResistanceUnit.Teraohm, "Teraohms", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricResistanceInfo(string name, ElectricResistanceUnit baseUnit, IEnumerable> unitMappings, ElectricResistance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricResistanceInfo(string name, ElectricResistanceUnit baseUnit, IEnumerable> unitMappings, ElectricResistance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricResistance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricResistance", typeof(ElectricResistance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricResistance quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricResistanceInfo CreateDefault() + { + return new ElectricResistanceInfo(nameof(ElectricResistance), DefaultBaseUnit, GetDefaultMappings(), new ElectricResistance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricResistance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricResistanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricResistanceInfo(nameof(ElectricResistance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricResistance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^2][M][I^-2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -3, -2, 0, 0, 0); + + /// + /// The default base unit of ElectricResistance is Ohm. All conversions, as defined in the , go via this value. + /// + public static ElectricResistanceUnit DefaultBaseUnit { get; } = ElectricResistanceUnit.Ohm; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricResistance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricResistanceUnit.Gigaohm, "Gigaohm", "Gigaohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricResistanceUnit.Kiloohm, "Kiloohm", "Kiloohms", BaseUnits.Undefined); + yield return new (ElectricResistanceUnit.Megaohm, "Megaohm", "Megaohms", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricResistanceUnit.Microohm, "Microohm", "Microohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricResistanceUnit.Milliohm, "Milliohm", "Milliohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricResistanceUnit.Nanoohm, "Nanoohm", "Nanoohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricResistanceUnit.Ohm, "Ohm", "Ohms", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricResistanceUnit.Teraohm, "Teraohm", "Teraohms", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricResistance() + { + Info = ElectricResistanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -126,27 +173,27 @@ public ElectricResistance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricResistance, which is Ohm. All conversions go via this value. /// - public static ElectricResistanceUnit BaseUnit { get; } + public static ElectricResistanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricResistance quantity. /// - public static ElectricResistanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Ohm. /// - public static ElectricResistance Zero { get; } + public static ElectricResistance Zero => Info.Zero; /// public static ElectricResistance AdditiveIdentity => Zero; @@ -164,7 +211,7 @@ public ElectricResistance(double value, UnitSystem unitSystem) public ElectricResistanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -182,6 +229,9 @@ public ElectricResistance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs index 549bc37d8d..790cfa0f20 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricResistivity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,32 +62,83 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricResistivityUnit? _unit; - static ElectricResistivity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricResistivityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(3, 1, -3, -2, 0, 0, 0); - BaseUnit = ElectricResistivityUnit.OhmMeter; - Units = Enum.GetValues(typeof(ElectricResistivityUnit)).Cast().ToArray(); - Zero = new ElectricResistivity(0, BaseUnit); - Info = new QuantityInfo("ElectricResistivity", - new UnitInfo[] - { - new UnitInfo(ElectricResistivityUnit.KiloohmCentimeter, "KiloohmsCentimeter", BaseUnits.Undefined, "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.KiloohmMeter, "KiloohmMeters", new BaseUnits(length: LengthUnit.Decameter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.MegaohmCentimeter, "MegaohmsCentimeter", BaseUnits.Undefined, "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.MegaohmMeter, "MegaohmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere), "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.MicroohmCentimeter, "MicroohmsCentimeter", BaseUnits.Undefined, "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.MicroohmMeter, "MicroohmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.MilliohmCentimeter, "MilliohmsCentimeter", BaseUnits.Undefined, "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.MilliohmMeter, "MilliohmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.NanoohmCentimeter, "NanoohmsCentimeter", BaseUnits.Undefined, "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.NanoohmMeter, "NanoohmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.OhmCentimeter, "OhmsCentimeter", BaseUnits.Undefined, "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.OhmMeter, "OhmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.PicoohmCentimeter, "PicoohmsCentimeter", BaseUnits.Undefined, "ElectricResistivity"), - new UnitInfo(ElectricResistivityUnit.PicoohmMeter, "PicoohmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricResistivity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricResistivityInfo(string name, ElectricResistivityUnit baseUnit, IEnumerable> unitMappings, ElectricResistivity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricResistivityInfo(string name, ElectricResistivityUnit baseUnit, IEnumerable> unitMappings, ElectricResistivity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricResistivity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricResistivity", typeof(ElectricResistivity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricResistivity quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricResistivityInfo CreateDefault() + { + return new ElectricResistivityInfo(nameof(ElectricResistivity), DefaultBaseUnit, GetDefaultMappings(), new ElectricResistivity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricResistivity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricResistivityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricResistivityInfo(nameof(ElectricResistivity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricResistivity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^3][M][I^-2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(3, 1, -3, -2, 0, 0, 0); + + /// + /// The default base unit of ElectricResistivity is OhmMeter. All conversions, as defined in the , go via this value. + /// + public static ElectricResistivityUnit DefaultBaseUnit { get; } = ElectricResistivityUnit.OhmMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricResistivity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricResistivityUnit.KiloohmCentimeter, "KiloohmCentimeter", "KiloohmsCentimeter", BaseUnits.Undefined); + yield return new (ElectricResistivityUnit.KiloohmMeter, "KiloohmMeter", "KiloohmMeters", new BaseUnits(length: LengthUnit.Decameter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricResistivityUnit.MegaohmCentimeter, "MegaohmCentimeter", "MegaohmsCentimeter", BaseUnits.Undefined); + yield return new (ElectricResistivityUnit.MegaohmMeter, "MegaohmMeter", "MegaohmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricResistivityUnit.MicroohmCentimeter, "MicroohmCentimeter", "MicroohmsCentimeter", BaseUnits.Undefined); + yield return new (ElectricResistivityUnit.MicroohmMeter, "MicroohmMeter", "MicroohmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricResistivityUnit.MilliohmCentimeter, "MilliohmCentimeter", "MilliohmsCentimeter", BaseUnits.Undefined); + yield return new (ElectricResistivityUnit.MilliohmMeter, "MilliohmMeter", "MilliohmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricResistivityUnit.NanoohmCentimeter, "NanoohmCentimeter", "NanoohmsCentimeter", BaseUnits.Undefined); + yield return new (ElectricResistivityUnit.NanoohmMeter, "NanoohmMeter", "NanoohmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricResistivityUnit.OhmCentimeter, "OhmCentimeter", "OhmsCentimeter", BaseUnits.Undefined); + yield return new (ElectricResistivityUnit.OhmMeter, "OhmMeter", "OhmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricResistivityUnit.PicoohmCentimeter, "PicoohmCentimeter", "PicoohmsCentimeter", BaseUnits.Undefined); + yield return new (ElectricResistivityUnit.PicoohmMeter, "PicoohmMeter", "PicoohmMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricResistivity() + { + Info = ElectricResistivityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -129,27 +176,27 @@ public ElectricResistivity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricResistivity, which is OhmMeter. All conversions go via this value. /// - public static ElectricResistivityUnit BaseUnit { get; } + public static ElectricResistivityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricResistivity quantity. /// - public static ElectricResistivityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit OhmMeter. /// - public static ElectricResistivity Zero { get; } + public static ElectricResistivity Zero => Info.Zero; /// public static ElectricResistivity AdditiveIdentity => Zero; @@ -167,7 +214,7 @@ public ElectricResistivity(double value, UnitSystem unitSystem) public ElectricResistivityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -185,6 +232,9 @@ public ElectricResistivity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs index 6e48ad9179..7245e9c424 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricSurfaceChargeDensity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,21 +62,72 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricSurfaceChargeDensityUnit? _unit; - static ElectricSurfaceChargeDensity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricSurfaceChargeDensityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, 0, 1, 1, 0, 0, 0); - BaseUnit = ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter; - Units = Enum.GetValues(typeof(ElectricSurfaceChargeDensityUnit)).Cast().ToArray(); - Zero = new ElectricSurfaceChargeDensity(0, BaseUnit); - Info = new QuantityInfo("ElectricSurfaceChargeDensity", - new UnitInfo[] - { - new UnitInfo(ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter, "CoulombsPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricSurfaceChargeDensity"), - new UnitInfo(ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch, "CoulombsPerSquareInch", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricSurfaceChargeDensity"), - new UnitInfo(ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, "CoulombsPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricSurfaceChargeDensity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricSurfaceChargeDensityInfo(string name, ElectricSurfaceChargeDensityUnit baseUnit, IEnumerable> unitMappings, ElectricSurfaceChargeDensity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricSurfaceChargeDensityInfo(string name, ElectricSurfaceChargeDensityUnit baseUnit, IEnumerable> unitMappings, ElectricSurfaceChargeDensity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricSurfaceChargeDensity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricSurfaceChargeDensity", typeof(ElectricSurfaceChargeDensity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricSurfaceChargeDensity quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricSurfaceChargeDensityInfo CreateDefault() + { + return new ElectricSurfaceChargeDensityInfo(nameof(ElectricSurfaceChargeDensity), DefaultBaseUnit, GetDefaultMappings(), new ElectricSurfaceChargeDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricSurfaceChargeDensity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricSurfaceChargeDensityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricSurfaceChargeDensityInfo(nameof(ElectricSurfaceChargeDensity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricSurfaceChargeDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T][L^-2][I]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, 0, 1, 1, 0, 0, 0); + + /// + /// The default base unit of ElectricSurfaceChargeDensity is CoulombPerSquareMeter. All conversions, as defined in the , go via this value. + /// + public static ElectricSurfaceChargeDensityUnit DefaultBaseUnit { get; } = ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricSurfaceChargeDensity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter, "CoulombPerSquareCentimeter", "CoulombsPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch, "CoulombPerSquareInch", "CoulombsPerSquareInch", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, "CoulombPerSquareMeter", "CoulombsPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricSurfaceChargeDensity() + { + Info = ElectricSurfaceChargeDensityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -118,27 +165,27 @@ public ElectricSurfaceChargeDensity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricSurfaceChargeDensity, which is CoulombPerSquareMeter. All conversions go via this value. /// - public static ElectricSurfaceChargeDensityUnit BaseUnit { get; } + public static ElectricSurfaceChargeDensityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricSurfaceChargeDensity quantity. /// - public static ElectricSurfaceChargeDensityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit CoulombPerSquareMeter. /// - public static ElectricSurfaceChargeDensity Zero { get; } + public static ElectricSurfaceChargeDensity Zero => Info.Zero; /// public static ElectricSurfaceChargeDensity AdditiveIdentity => Zero; @@ -156,7 +203,7 @@ public ElectricSurfaceChargeDensity(double value, UnitSystem unitSystem) public ElectricSurfaceChargeDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -174,6 +221,9 @@ public ElectricSurfaceChargeDensity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs b/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs index 9de5b7aa28..5c0e0a95d5 100644 --- a/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ElectricSusceptance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,34 +62,85 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ElectricSusceptanceUnit? _unit; - static ElectricSusceptance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ElectricSusceptanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, -1, 3, 2, 0, 0, 0); - BaseUnit = ElectricSusceptanceUnit.Siemens; - Units = Enum.GetValues(typeof(ElectricSusceptanceUnit)).Cast().ToArray(); - Zero = new ElectricSusceptance(0, BaseUnit); - Info = new QuantityInfo("ElectricSusceptance", - new UnitInfo[] - { - new UnitInfo(ElectricSusceptanceUnit.Gigamho, "Gigamhos", BaseUnits.Undefined, "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Gigasiemens, "Gigasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Kilomho, "Kilomhos", BaseUnits.Undefined, "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Kilosiemens, "Kilosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Megamho, "Megamhos", BaseUnits.Undefined, "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Megasiemens, "Megasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Mho, "Mhos", BaseUnits.Undefined, "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Micromho, "Micromhos", BaseUnits.Undefined, "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Microsiemens, "Microsiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere), "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Millimho, "Millimhos", BaseUnits.Undefined, "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Millisiemens, "Millisiemens", BaseUnits.Undefined, "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Nanomho, "Nanomhos", BaseUnits.Undefined, "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Nanosiemens, "Nanosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere), "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Siemens, "Siemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Teramho, "Teramhos", BaseUnits.Undefined, "ElectricSusceptance"), - new UnitInfo(ElectricSusceptanceUnit.Terasiemens, "Terasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "ElectricSusceptance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ElectricSusceptanceInfo(string name, ElectricSusceptanceUnit baseUnit, IEnumerable> unitMappings, ElectricSusceptance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ElectricSusceptanceInfo(string name, ElectricSusceptanceUnit baseUnit, IEnumerable> unitMappings, ElectricSusceptance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ElectricSusceptance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ElectricSusceptance", typeof(ElectricSusceptance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ElectricSusceptance quantity. + /// + /// A new instance of the class with the default settings. + public static ElectricSusceptanceInfo CreateDefault() + { + return new ElectricSusceptanceInfo(nameof(ElectricSusceptance), DefaultBaseUnit, GetDefaultMappings(), new ElectricSusceptance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ElectricSusceptance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ElectricSusceptanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ElectricSusceptanceInfo(nameof(ElectricSusceptance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ElectricSusceptance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^3][L^-2][M^-1][I^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, -1, 3, 2, 0, 0, 0); + + /// + /// The default base unit of ElectricSusceptance is Siemens. All conversions, as defined in the , go via this value. + /// + public static ElectricSusceptanceUnit DefaultBaseUnit { get; } = ElectricSusceptanceUnit.Siemens; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ElectricSusceptance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ElectricSusceptanceUnit.Gigamho, "Gigamho", "Gigamhos", BaseUnits.Undefined); + yield return new (ElectricSusceptanceUnit.Gigasiemens, "Gigasiemens", "Gigasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricSusceptanceUnit.Kilomho, "Kilomho", "Kilomhos", BaseUnits.Undefined); + yield return new (ElectricSusceptanceUnit.Kilosiemens, "Kilosiemens", "Kilosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricSusceptanceUnit.Megamho, "Megamho", "Megamhos", BaseUnits.Undefined); + yield return new (ElectricSusceptanceUnit.Megasiemens, "Megasiemens", "Megasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricSusceptanceUnit.Mho, "Mho", "Mhos", BaseUnits.Undefined); + yield return new (ElectricSusceptanceUnit.Micromho, "Micromho", "Micromhos", BaseUnits.Undefined); + yield return new (ElectricSusceptanceUnit.Microsiemens, "Microsiemens", "Microsiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere)); + yield return new (ElectricSusceptanceUnit.Millimho, "Millimho", "Millimhos", BaseUnits.Undefined); + yield return new (ElectricSusceptanceUnit.Millisiemens, "Millisiemens", "Millisiemens", BaseUnits.Undefined); + yield return new (ElectricSusceptanceUnit.Nanomho, "Nanomho", "Nanomhos", BaseUnits.Undefined); + yield return new (ElectricSusceptanceUnit.Nanosiemens, "Nanosiemens", "Nanosiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricSusceptanceUnit.Siemens, "Siemens", "Siemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (ElectricSusceptanceUnit.Teramho, "Teramho", "Teramhos", BaseUnits.Undefined); + yield return new (ElectricSusceptanceUnit.Terasiemens, "Terasiemens", "Terasiemens", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static ElectricSusceptance() + { + Info = ElectricSusceptanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -131,27 +178,27 @@ public ElectricSusceptance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ElectricSusceptance, which is Siemens. All conversions go via this value. /// - public static ElectricSusceptanceUnit BaseUnit { get; } + public static ElectricSusceptanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ElectricSusceptance quantity. /// - public static ElectricSusceptanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Siemens. /// - public static ElectricSusceptance Zero { get; } + public static ElectricSusceptance Zero => Info.Zero; /// public static ElectricSusceptance AdditiveIdentity => Zero; @@ -169,7 +216,7 @@ public ElectricSusceptance(double value, UnitSystem unitSystem) public ElectricSusceptanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -187,6 +234,9 @@ public ElectricSusceptance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs index b1023afba3..c20e57437f 100644 --- a/UnitsNet/GeneratedCode/Quantities/Energy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Energy.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -78,58 +74,109 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly EnergyUnit? _unit; - static Energy() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class EnergyInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); - BaseUnit = EnergyUnit.Joule; - Units = Enum.GetValues(typeof(EnergyUnit)).Cast().ToArray(); - Zero = new Energy(0, BaseUnit); - Info = new QuantityInfo("Energy", - new UnitInfo[] - { - new UnitInfo(EnergyUnit.BritishThermalUnit, "BritishThermalUnits", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.Calorie, "Calories", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.DecathermEc, "DecathermsEc", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.DecathermImperial, "DecathermsImperial", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.DecathermUs, "DecathermsUs", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.ElectronVolt, "ElectronVolts", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.Erg, "Ergs", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.FootPound, "FootPounds", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.GigabritishThermalUnit, "GigabritishThermalUnits", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.GigaelectronVolt, "GigaelectronVolts", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.Gigajoule, "Gigajoules", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.GigawattDay, "GigawattDays", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.GigawattHour, "GigawattHours", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.HorsepowerHour, "HorsepowerHours", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.Joule, "Joules", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Energy"), - new UnitInfo(EnergyUnit.KilobritishThermalUnit, "KilobritishThermalUnits", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.Kilocalorie, "Kilocalories", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.KiloelectronVolt, "KiloelectronVolts", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.Kilojoule, "Kilojoules", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.KilowattDay, "KilowattDays", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.KilowattHour, "KilowattHours", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.MegabritishThermalUnit, "MegabritishThermalUnits", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.Megacalorie, "Megacalories", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.MegaelectronVolt, "MegaelectronVolts", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.Megajoule, "Megajoules", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Energy"), - new UnitInfo(EnergyUnit.MegawattDay, "MegawattDays", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.MegawattHour, "MegawattHours", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.Microjoule, "Microjoules", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second), "Energy"), - new UnitInfo(EnergyUnit.Millijoule, "Millijoules", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second), "Energy"), - new UnitInfo(EnergyUnit.Nanojoule, "Nanojoules", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second), "Energy"), - new UnitInfo(EnergyUnit.Petajoule, "Petajoules", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.TeraelectronVolt, "TeraelectronVolts", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.Terajoule, "Terajoules", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Energy"), - new UnitInfo(EnergyUnit.TerawattDay, "TerawattDays", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.TerawattHour, "TerawattHours", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.ThermEc, "ThermsEc", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.ThermImperial, "ThermsImperial", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.ThermUs, "ThermsUs", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.WattDay, "WattDays", BaseUnits.Undefined, "Energy"), - new UnitInfo(EnergyUnit.WattHour, "WattHours", BaseUnits.Undefined, "Energy"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public EnergyInfo(string name, EnergyUnit baseUnit, IEnumerable> unitMappings, Energy zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public EnergyInfo(string name, EnergyUnit baseUnit, IEnumerable> unitMappings, Energy zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Energy.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Energy", typeof(Energy).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Energy quantity. + /// + /// A new instance of the class with the default settings. + public static EnergyInfo CreateDefault() + { + return new EnergyInfo(nameof(Energy), DefaultBaseUnit, GetDefaultMappings(), new Energy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Energy quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static EnergyInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new EnergyInfo(nameof(Energy), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Energy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of Energy is Joule. All conversions, as defined in the , go via this value. + /// + public static EnergyUnit DefaultBaseUnit { get; } = EnergyUnit.Joule; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Energy. + public static IEnumerable> GetDefaultMappings() + { + yield return new (EnergyUnit.BritishThermalUnit, "BritishThermalUnit", "BritishThermalUnits", BaseUnits.Undefined); + yield return new (EnergyUnit.Calorie, "Calorie", "Calories", BaseUnits.Undefined); + yield return new (EnergyUnit.DecathermEc, "DecathermEc", "DecathermsEc", BaseUnits.Undefined); + yield return new (EnergyUnit.DecathermImperial, "DecathermImperial", "DecathermsImperial", BaseUnits.Undefined); + yield return new (EnergyUnit.DecathermUs, "DecathermUs", "DecathermsUs", BaseUnits.Undefined); + yield return new (EnergyUnit.ElectronVolt, "ElectronVolt", "ElectronVolts", BaseUnits.Undefined); + yield return new (EnergyUnit.Erg, "Erg", "Ergs", BaseUnits.Undefined); + yield return new (EnergyUnit.FootPound, "FootPound", "FootPounds", BaseUnits.Undefined); + yield return new (EnergyUnit.GigabritishThermalUnit, "GigabritishThermalUnit", "GigabritishThermalUnits", BaseUnits.Undefined); + yield return new (EnergyUnit.GigaelectronVolt, "GigaelectronVolt", "GigaelectronVolts", BaseUnits.Undefined); + yield return new (EnergyUnit.Gigajoule, "Gigajoule", "Gigajoules", BaseUnits.Undefined); + yield return new (EnergyUnit.GigawattDay, "GigawattDay", "GigawattDays", BaseUnits.Undefined); + yield return new (EnergyUnit.GigawattHour, "GigawattHour", "GigawattHours", BaseUnits.Undefined); + yield return new (EnergyUnit.HorsepowerHour, "HorsepowerHour", "HorsepowerHours", BaseUnits.Undefined); + yield return new (EnergyUnit.Joule, "Joule", "Joules", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (EnergyUnit.KilobritishThermalUnit, "KilobritishThermalUnit", "KilobritishThermalUnits", BaseUnits.Undefined); + yield return new (EnergyUnit.Kilocalorie, "Kilocalorie", "Kilocalories", BaseUnits.Undefined); + yield return new (EnergyUnit.KiloelectronVolt, "KiloelectronVolt", "KiloelectronVolts", BaseUnits.Undefined); + yield return new (EnergyUnit.Kilojoule, "Kilojoule", "Kilojoules", BaseUnits.Undefined); + yield return new (EnergyUnit.KilowattDay, "KilowattDay", "KilowattDays", BaseUnits.Undefined); + yield return new (EnergyUnit.KilowattHour, "KilowattHour", "KilowattHours", BaseUnits.Undefined); + yield return new (EnergyUnit.MegabritishThermalUnit, "MegabritishThermalUnit", "MegabritishThermalUnits", BaseUnits.Undefined); + yield return new (EnergyUnit.Megacalorie, "Megacalorie", "Megacalories", BaseUnits.Undefined); + yield return new (EnergyUnit.MegaelectronVolt, "MegaelectronVolt", "MegaelectronVolts", BaseUnits.Undefined); + yield return new (EnergyUnit.Megajoule, "Megajoule", "Megajoules", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (EnergyUnit.MegawattDay, "MegawattDay", "MegawattDays", BaseUnits.Undefined); + yield return new (EnergyUnit.MegawattHour, "MegawattHour", "MegawattHours", BaseUnits.Undefined); + yield return new (EnergyUnit.Microjoule, "Microjoule", "Microjoules", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second)); + yield return new (EnergyUnit.Millijoule, "Millijoule", "Millijoules", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (EnergyUnit.Nanojoule, "Nanojoule", "Nanojoules", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second)); + yield return new (EnergyUnit.Petajoule, "Petajoule", "Petajoules", BaseUnits.Undefined); + yield return new (EnergyUnit.TeraelectronVolt, "TeraelectronVolt", "TeraelectronVolts", BaseUnits.Undefined); + yield return new (EnergyUnit.Terajoule, "Terajoule", "Terajoules", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (EnergyUnit.TerawattDay, "TerawattDay", "TerawattDays", BaseUnits.Undefined); + yield return new (EnergyUnit.TerawattHour, "TerawattHour", "TerawattHours", BaseUnits.Undefined); + yield return new (EnergyUnit.ThermEc, "ThermEc", "ThermsEc", BaseUnits.Undefined); + yield return new (EnergyUnit.ThermImperial, "ThermImperial", "ThermsImperial", BaseUnits.Undefined); + yield return new (EnergyUnit.ThermUs, "ThermUs", "ThermsUs", BaseUnits.Undefined); + yield return new (EnergyUnit.WattDay, "WattDay", "WattDays", BaseUnits.Undefined); + yield return new (EnergyUnit.WattHour, "WattHour", "WattHours", BaseUnits.Undefined); + } + } + + static Energy() + { + Info = EnergyInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -167,27 +214,27 @@ public Energy(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Energy, which is Joule. All conversions go via this value. /// - public static EnergyUnit BaseUnit { get; } + public static EnergyUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Energy quantity. /// - public static EnergyUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Joule. /// - public static Energy Zero { get; } + public static Energy Zero => Info.Zero; /// public static Energy AdditiveIdentity => Zero; @@ -205,7 +252,7 @@ public Energy(double value, UnitSystem unitSystem) public EnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -223,6 +270,9 @@ public Energy(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs index e8cc4d1578..4be819c599 100644 --- a/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/EnergyDensity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,30 +62,81 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly EnergyDensityUnit? _unit; - static EnergyDensity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class EnergyDensityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-1, 1, -2, 0, 0, 0, 0); - BaseUnit = EnergyDensityUnit.JoulePerCubicMeter; - Units = Enum.GetValues(typeof(EnergyDensityUnit)).Cast().ToArray(); - Zero = new EnergyDensity(0, BaseUnit); - Info = new QuantityInfo("EnergyDensity", - new UnitInfo[] - { - new UnitInfo(EnergyDensityUnit.GigajoulePerCubicMeter, "GigajoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Nanometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "EnergyDensity"), - new UnitInfo(EnergyDensityUnit.GigawattHourPerCubicMeter, "GigawattHoursPerCubicMeter", BaseUnits.Undefined, "EnergyDensity"), - new UnitInfo(EnergyDensityUnit.JoulePerCubicMeter, "JoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "EnergyDensity"), - new UnitInfo(EnergyDensityUnit.KilojoulePerCubicMeter, "KilojoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "EnergyDensity"), - new UnitInfo(EnergyDensityUnit.KilowattHourPerCubicMeter, "KilowattHoursPerCubicMeter", BaseUnits.Undefined, "EnergyDensity"), - new UnitInfo(EnergyDensityUnit.MegajoulePerCubicMeter, "MegajoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "EnergyDensity"), - new UnitInfo(EnergyDensityUnit.MegawattHourPerCubicMeter, "MegawattHoursPerCubicMeter", BaseUnits.Undefined, "EnergyDensity"), - new UnitInfo(EnergyDensityUnit.PetajoulePerCubicMeter, "PetajoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Femtometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "EnergyDensity"), - new UnitInfo(EnergyDensityUnit.PetawattHourPerCubicMeter, "PetawattHoursPerCubicMeter", BaseUnits.Undefined, "EnergyDensity"), - new UnitInfo(EnergyDensityUnit.TerajoulePerCubicMeter, "TerajoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Picometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "EnergyDensity"), - new UnitInfo(EnergyDensityUnit.TerawattHourPerCubicMeter, "TerawattHoursPerCubicMeter", BaseUnits.Undefined, "EnergyDensity"), - new UnitInfo(EnergyDensityUnit.WattHourPerCubicMeter, "WattHoursPerCubicMeter", BaseUnits.Undefined, "EnergyDensity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public EnergyDensityInfo(string name, EnergyDensityUnit baseUnit, IEnumerable> unitMappings, EnergyDensity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public EnergyDensityInfo(string name, EnergyDensityUnit baseUnit, IEnumerable> unitMappings, EnergyDensity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, EnergyDensity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.EnergyDensity", typeof(EnergyDensity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the EnergyDensity quantity. + /// + /// A new instance of the class with the default settings. + public static EnergyDensityInfo CreateDefault() + { + return new EnergyDensityInfo(nameof(EnergyDensity), DefaultBaseUnit, GetDefaultMappings(), new EnergyDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the EnergyDensity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static EnergyDensityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new EnergyDensityInfo(nameof(EnergyDensity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new EnergyDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^-1][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-1, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of EnergyDensity is JoulePerCubicMeter. All conversions, as defined in the , go via this value. + /// + public static EnergyDensityUnit DefaultBaseUnit { get; } = EnergyDensityUnit.JoulePerCubicMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for EnergyDensity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (EnergyDensityUnit.GigajoulePerCubicMeter, "GigajoulePerCubicMeter", "GigajoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Nanometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (EnergyDensityUnit.GigawattHourPerCubicMeter, "GigawattHourPerCubicMeter", "GigawattHoursPerCubicMeter", BaseUnits.Undefined); + yield return new (EnergyDensityUnit.JoulePerCubicMeter, "JoulePerCubicMeter", "JoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (EnergyDensityUnit.KilojoulePerCubicMeter, "KilojoulePerCubicMeter", "KilojoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (EnergyDensityUnit.KilowattHourPerCubicMeter, "KilowattHourPerCubicMeter", "KilowattHoursPerCubicMeter", BaseUnits.Undefined); + yield return new (EnergyDensityUnit.MegajoulePerCubicMeter, "MegajoulePerCubicMeter", "MegajoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (EnergyDensityUnit.MegawattHourPerCubicMeter, "MegawattHourPerCubicMeter", "MegawattHoursPerCubicMeter", BaseUnits.Undefined); + yield return new (EnergyDensityUnit.PetajoulePerCubicMeter, "PetajoulePerCubicMeter", "PetajoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Femtometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (EnergyDensityUnit.PetawattHourPerCubicMeter, "PetawattHourPerCubicMeter", "PetawattHoursPerCubicMeter", BaseUnits.Undefined); + yield return new (EnergyDensityUnit.TerajoulePerCubicMeter, "TerajoulePerCubicMeter", "TerajoulesPerCubicMeter", new BaseUnits(length: LengthUnit.Picometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (EnergyDensityUnit.TerawattHourPerCubicMeter, "TerawattHourPerCubicMeter", "TerawattHoursPerCubicMeter", BaseUnits.Undefined); + yield return new (EnergyDensityUnit.WattHourPerCubicMeter, "WattHourPerCubicMeter", "WattHoursPerCubicMeter", BaseUnits.Undefined); + } + } + + static EnergyDensity() + { + Info = EnergyDensityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -127,27 +174,27 @@ public EnergyDensity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of EnergyDensity, which is JoulePerCubicMeter. All conversions go via this value. /// - public static EnergyDensityUnit BaseUnit { get; } + public static EnergyDensityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the EnergyDensity quantity. /// - public static EnergyDensityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerCubicMeter. /// - public static EnergyDensity Zero { get; } + public static EnergyDensity Zero => Info.Zero; /// public static EnergyDensity AdditiveIdentity => Zero; @@ -165,7 +212,7 @@ public EnergyDensity(double value, UnitSystem unitSystem) public EnergyDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -183,6 +230,9 @@ public EnergyDensity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs index 96b8253b31..c5a861d5f0 100644 --- a/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Entropy.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -68,25 +64,76 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly EntropyUnit? _unit; - static Entropy() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class EntropyInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -2, 0, -1, 0, 0); - BaseUnit = EntropyUnit.JoulePerKelvin; - Units = Enum.GetValues(typeof(EntropyUnit)).Cast().ToArray(); - Zero = new Entropy(0, BaseUnit); - Info = new QuantityInfo("Entropy", - new UnitInfo[] - { - new UnitInfo(EntropyUnit.CaloriePerKelvin, "CaloriesPerKelvin", BaseUnits.Undefined, "Entropy"), - new UnitInfo(EntropyUnit.JoulePerDegreeCelsius, "JoulesPerDegreeCelsius", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "Entropy"), - new UnitInfo(EntropyUnit.JoulePerKelvin, "JoulesPerKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "Entropy"), - new UnitInfo(EntropyUnit.KilocaloriePerKelvin, "KilocaloriesPerKelvin", BaseUnits.Undefined, "Entropy"), - new UnitInfo(EntropyUnit.KilojoulePerDegreeCelsius, "KilojoulesPerDegreeCelsius", BaseUnits.Undefined, "Entropy"), - new UnitInfo(EntropyUnit.KilojoulePerKelvin, "KilojoulesPerKelvin", BaseUnits.Undefined, "Entropy"), - new UnitInfo(EntropyUnit.MegajoulePerKelvin, "MegajoulesPerKelvin", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "Entropy"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public EntropyInfo(string name, EntropyUnit baseUnit, IEnumerable> unitMappings, Entropy zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public EntropyInfo(string name, EntropyUnit baseUnit, IEnumerable> unitMappings, Entropy zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Entropy.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Entropy", typeof(Entropy).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Entropy quantity. + /// + /// A new instance of the class with the default settings. + public static EntropyInfo CreateDefault() + { + return new EntropyInfo(nameof(Entropy), DefaultBaseUnit, GetDefaultMappings(), new Entropy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Entropy quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static EntropyInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new EntropyInfo(nameof(Entropy), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Entropy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2][M][Θ^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -2, 0, -1, 0, 0); + + /// + /// The default base unit of Entropy is JoulePerKelvin. All conversions, as defined in the , go via this value. + /// + public static EntropyUnit DefaultBaseUnit { get; } = EntropyUnit.JoulePerKelvin; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Entropy. + public static IEnumerable> GetDefaultMappings() + { + yield return new (EntropyUnit.CaloriePerKelvin, "CaloriePerKelvin", "CaloriesPerKelvin", BaseUnits.Undefined); + yield return new (EntropyUnit.JoulePerDegreeCelsius, "JoulePerDegreeCelsius", "JoulesPerDegreeCelsius", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (EntropyUnit.JoulePerKelvin, "JoulePerKelvin", "JoulesPerKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin)); + yield return new (EntropyUnit.KilocaloriePerKelvin, "KilocaloriePerKelvin", "KilocaloriesPerKelvin", BaseUnits.Undefined); + yield return new (EntropyUnit.KilojoulePerDegreeCelsius, "KilojoulePerDegreeCelsius", "KilojoulesPerDegreeCelsius", BaseUnits.Undefined); + yield return new (EntropyUnit.KilojoulePerKelvin, "KilojoulePerKelvin", "KilojoulesPerKelvin", BaseUnits.Undefined); + yield return new (EntropyUnit.MegajoulePerKelvin, "MegajoulePerKelvin", "MegajoulesPerKelvin", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin)); + } + } + + static Entropy() + { + Info = EntropyInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -124,27 +171,27 @@ public Entropy(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Entropy, which is JoulePerKelvin. All conversions go via this value. /// - public static EntropyUnit BaseUnit { get; } + public static EntropyUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Entropy quantity. /// - public static EntropyUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerKelvin. /// - public static Entropy Zero { get; } + public static Entropy Zero => Info.Zero; /// public static Entropy AdditiveIdentity => Zero; @@ -162,7 +209,7 @@ public Entropy(double value, UnitSystem unitSystem) public EntropyUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -180,6 +227,9 @@ public Entropy(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/FluidResistance.g.cs b/UnitsNet/GeneratedCode/Quantities/FluidResistance.g.cs index c2051578d5..49b9c84e58 100644 --- a/UnitsNet/GeneratedCode/Quantities/FluidResistance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/FluidResistance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,37 +62,88 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly FluidResistanceUnit? _unit; - static FluidResistance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class FluidResistanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-4, 1, -1, 0, 0, 0, 0); - BaseUnit = FluidResistanceUnit.PascalSecondPerCubicMeter; - Units = Enum.GetValues(typeof(FluidResistanceUnit)).Cast().ToArray(); - Zero = new FluidResistance(0, BaseUnit); - Info = new QuantityInfo("FluidResistance", - new UnitInfo[] - { - new UnitInfo(FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, "DyneSecondsPerCentimeterToTheFifth", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.MegapascalSecondPerCubicMeter, "MegapascalSecondsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Microsecond), "FluidResistance"), - new UnitInfo(FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, "MillimeterMercuryMinutesPerCubicCentimeter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, "MillimeterMercuryMinutesPerCubicMeter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.MillimeterMercuryMinutePerLiter, "MillimeterMercuryMinutesPerLiter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, "MillimeterMercuryMinutesPerMilliliter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, "MillimeterMercurySecondsPerCubicCentimeter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, "MillimeterMercurySecondsPerCubicMeter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.MillimeterMercurySecondPerLiter, "MillimeterMercurySecondsPerLiter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, "MillimeterMercurySecondsPerMilliliter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.PascalMinutePerCubicCentimeter, "PascalMinutesPerCubicCentimeter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.PascalMinutePerCubicMeter, "PascalMinutesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute), "FluidResistance"), - new UnitInfo(FluidResistanceUnit.PascalMinutePerLiter, "PascalMinutesPerLiter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute), "FluidResistance"), - new UnitInfo(FluidResistanceUnit.PascalMinutePerMilliliter, "PascalMinutesPerMilliliter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.PascalSecondPerCubicCentimeter, "PascalSecondsPerCubicCentimeter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.PascalSecondPerCubicMeter, "PascalSecondsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "FluidResistance"), - new UnitInfo(FluidResistanceUnit.PascalSecondPerLiter, "PascalSecondsPerLiter", BaseUnits.Undefined, "FluidResistance"), - new UnitInfo(FluidResistanceUnit.PascalSecondPerMilliliter, "PascalSecondsPerMilliliter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second), "FluidResistance"), - new UnitInfo(FluidResistanceUnit.WoodUnit, "WoodUnits", BaseUnits.Undefined, "FluidResistance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public FluidResistanceInfo(string name, FluidResistanceUnit baseUnit, IEnumerable> unitMappings, FluidResistance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public FluidResistanceInfo(string name, FluidResistanceUnit baseUnit, IEnumerable> unitMappings, FluidResistance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, FluidResistance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.FluidResistance", typeof(FluidResistance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the FluidResistance quantity. + /// + /// A new instance of the class with the default settings. + public static FluidResistanceInfo CreateDefault() + { + return new FluidResistanceInfo(nameof(FluidResistance), DefaultBaseUnit, GetDefaultMappings(), new FluidResistance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the FluidResistance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static FluidResistanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new FluidResistanceInfo(nameof(FluidResistance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new FluidResistance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][L^-4][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-4, 1, -1, 0, 0, 0, 0); + + /// + /// The default base unit of FluidResistance is PascalSecondPerCubicMeter. All conversions, as defined in the , go via this value. + /// + public static FluidResistanceUnit DefaultBaseUnit { get; } = FluidResistanceUnit.PascalSecondPerCubicMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for FluidResistance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (FluidResistanceUnit.DyneSecondPerCentimeterToTheFifth, "DyneSecondPerCentimeterToTheFifth", "DyneSecondsPerCentimeterToTheFifth", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.MegapascalSecondPerCubicMeter, "MegapascalSecondPerCubicMeter", "MegapascalSecondsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Microsecond)); + yield return new (FluidResistanceUnit.MillimeterMercuryMinutePerCubicCentimeter, "MillimeterMercuryMinutePerCubicCentimeter", "MillimeterMercuryMinutesPerCubicCentimeter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.MillimeterMercuryMinutePerCubicMeter, "MillimeterMercuryMinutePerCubicMeter", "MillimeterMercuryMinutesPerCubicMeter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.MillimeterMercuryMinutePerLiter, "MillimeterMercuryMinutePerLiter", "MillimeterMercuryMinutesPerLiter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.MillimeterMercuryMinutePerMilliliter, "MillimeterMercuryMinutePerMilliliter", "MillimeterMercuryMinutesPerMilliliter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.MillimeterMercurySecondPerCubicCentimeter, "MillimeterMercurySecondPerCubicCentimeter", "MillimeterMercurySecondsPerCubicCentimeter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.MillimeterMercurySecondPerCubicMeter, "MillimeterMercurySecondPerCubicMeter", "MillimeterMercurySecondsPerCubicMeter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.MillimeterMercurySecondPerLiter, "MillimeterMercurySecondPerLiter", "MillimeterMercurySecondsPerLiter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.MillimeterMercurySecondPerMilliliter, "MillimeterMercurySecondPerMilliliter", "MillimeterMercurySecondsPerMilliliter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.PascalMinutePerCubicCentimeter, "PascalMinutePerCubicCentimeter", "PascalMinutesPerCubicCentimeter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.PascalMinutePerCubicMeter, "PascalMinutePerCubicMeter", "PascalMinutesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute)); + yield return new (FluidResistanceUnit.PascalMinutePerLiter, "PascalMinutePerLiter", "PascalMinutesPerLiter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute)); + yield return new (FluidResistanceUnit.PascalMinutePerMilliliter, "PascalMinutePerMilliliter", "PascalMinutesPerMilliliter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.PascalSecondPerCubicCentimeter, "PascalSecondPerCubicCentimeter", "PascalSecondsPerCubicCentimeter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.PascalSecondPerCubicMeter, "PascalSecondPerCubicMeter", "PascalSecondsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (FluidResistanceUnit.PascalSecondPerLiter, "PascalSecondPerLiter", "PascalSecondsPerLiter", BaseUnits.Undefined); + yield return new (FluidResistanceUnit.PascalSecondPerMilliliter, "PascalSecondPerMilliliter", "PascalSecondsPerMilliliter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (FluidResistanceUnit.WoodUnit, "WoodUnit", "WoodUnits", BaseUnits.Undefined); + } + } + + static FluidResistance() + { + Info = FluidResistanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -134,27 +181,27 @@ public FluidResistance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of FluidResistance, which is PascalSecondPerCubicMeter. All conversions go via this value. /// - public static FluidResistanceUnit BaseUnit { get; } + public static FluidResistanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the FluidResistance quantity. /// - public static FluidResistanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit PascalSecondPerCubicMeter. /// - public static FluidResistance Zero { get; } + public static FluidResistance Zero => Info.Zero; /// public static FluidResistance AdditiveIdentity => Zero; @@ -172,7 +219,7 @@ public FluidResistance(double value, UnitSystem unitSystem) public FluidResistanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -190,6 +237,9 @@ public FluidResistance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Force.g.cs b/UnitsNet/GeneratedCode/Quantities/Force.g.cs index 0cf91ae539..79b8e380d9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Force.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Force.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -77,33 +73,84 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ForceUnit? _unit; - static Force() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ForceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 1, -2, 0, 0, 0, 0); - BaseUnit = ForceUnit.Newton; - Units = Enum.GetValues(typeof(ForceUnit)).Cast().ToArray(); - Zero = new Force(0, BaseUnit); - Info = new QuantityInfo("Force", - new UnitInfo[] - { - new UnitInfo(ForceUnit.Decanewton, "Decanewtons", new BaseUnits(length: LengthUnit.Decameter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Force"), - new UnitInfo(ForceUnit.Dyn, "Dyne", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram, time: DurationUnit.Second), "Force"), - new UnitInfo(ForceUnit.KilogramForce, "KilogramsForce", BaseUnits.Undefined, "Force"), - new UnitInfo(ForceUnit.Kilonewton, "Kilonewtons", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Force"), - new UnitInfo(ForceUnit.KiloPond, "KiloPonds", BaseUnits.Undefined, "Force"), - new UnitInfo(ForceUnit.KilopoundForce, "KilopoundsForce", BaseUnits.Undefined, "Force"), - new UnitInfo(ForceUnit.Meganewton, "Meganewtons", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Force"), - new UnitInfo(ForceUnit.Micronewton, "Micronewtons", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Force"), - new UnitInfo(ForceUnit.Millinewton, "Millinewtons", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Force"), - new UnitInfo(ForceUnit.Newton, "Newtons", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Force"), - new UnitInfo(ForceUnit.OunceForce, "OunceForce", BaseUnits.Undefined, "Force"), - new UnitInfo(ForceUnit.Poundal, "Poundals", BaseUnits.Undefined, "Force"), - new UnitInfo(ForceUnit.PoundForce, "PoundsForce", BaseUnits.Undefined, "Force"), - new UnitInfo(ForceUnit.ShortTonForce, "ShortTonsForce", BaseUnits.Undefined, "Force"), - new UnitInfo(ForceUnit.TonneForce, "TonnesForce", BaseUnits.Undefined, "Force"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ForceInfo(string name, ForceUnit baseUnit, IEnumerable> unitMappings, Force zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ForceInfo(string name, ForceUnit baseUnit, IEnumerable> unitMappings, Force zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Force.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Force", typeof(Force).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Force quantity. + /// + /// A new instance of the class with the default settings. + public static ForceInfo CreateDefault() + { + return new ForceInfo(nameof(Force), DefaultBaseUnit, GetDefaultMappings(), new Force(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Force quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ForceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ForceInfo(nameof(Force), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Force(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of Force is Newton. All conversions, as defined in the , go via this value. + /// + public static ForceUnit DefaultBaseUnit { get; } = ForceUnit.Newton; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Force. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ForceUnit.Decanewton, "Decanewton", "Decanewtons", new BaseUnits(length: LengthUnit.Decameter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceUnit.Dyn, "Dyn", "Dyne", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (ForceUnit.KilogramForce, "KilogramForce", "KilogramsForce", BaseUnits.Undefined); + yield return new (ForceUnit.Kilonewton, "Kilonewton", "Kilonewtons", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceUnit.KiloPond, "KiloPond", "KiloPonds", BaseUnits.Undefined); + yield return new (ForceUnit.KilopoundForce, "KilopoundForce", "KilopoundsForce", BaseUnits.Undefined); + yield return new (ForceUnit.Meganewton, "Meganewton", "Meganewtons", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceUnit.Micronewton, "Micronewton", "Micronewtons", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceUnit.Millinewton, "Millinewton", "Millinewtons", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceUnit.Newton, "Newton", "Newtons", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceUnit.OunceForce, "OunceForce", "OunceForce", BaseUnits.Undefined); + yield return new (ForceUnit.Poundal, "Poundal", "Poundals", BaseUnits.Undefined); + yield return new (ForceUnit.PoundForce, "PoundForce", "PoundsForce", BaseUnits.Undefined); + yield return new (ForceUnit.ShortTonForce, "ShortTonForce", "ShortTonsForce", BaseUnits.Undefined); + yield return new (ForceUnit.TonneForce, "TonneForce", "TonnesForce", BaseUnits.Undefined); + } + } + + static Force() + { + Info = ForceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -141,27 +188,27 @@ public Force(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Force, which is Newton. All conversions go via this value. /// - public static ForceUnit BaseUnit { get; } + public static ForceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Force quantity. /// - public static ForceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Newton. /// - public static Force Zero { get; } + public static Force Zero => Info.Zero; /// public static Force AdditiveIdentity => Zero; @@ -179,7 +226,7 @@ public Force(double value, UnitSystem unitSystem) public ForceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -197,6 +244,9 @@ public Force(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs index 4d11b9388e..6cadddd8b8 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForceChangeRate.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,33 +62,84 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ForceChangeRateUnit? _unit; - static ForceChangeRate() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ForceChangeRateInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 1, -3, 0, 0, 0, 0); - BaseUnit = ForceChangeRateUnit.NewtonPerSecond; - Units = Enum.GetValues(typeof(ForceChangeRateUnit)).Cast().ToArray(); - Zero = new ForceChangeRate(0, BaseUnit); - Info = new QuantityInfo("ForceChangeRate", - new UnitInfo[] - { - new UnitInfo(ForceChangeRateUnit.CentinewtonPerSecond, "CentinewtonsPerSecond", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.DecanewtonPerMinute, "DecanewtonsPerMinute", BaseUnits.Undefined, "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.DecanewtonPerSecond, "DecanewtonsPerSecond", new BaseUnits(length: LengthUnit.Decameter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.DecinewtonPerSecond, "DecinewtonsPerSecond", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.KilonewtonPerMinute, "KilonewtonsPerMinute", BaseUnits.Undefined, "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.KilonewtonPerSecond, "KilonewtonsPerSecond", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.KilopoundForcePerMinute, "KilopoundsForcePerMinute", BaseUnits.Undefined, "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.KilopoundForcePerSecond, "KilopoundsForcePerSecond", BaseUnits.Undefined, "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.MicronewtonPerSecond, "MicronewtonsPerSecond", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.MillinewtonPerSecond, "MillinewtonsPerSecond", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.NanonewtonPerSecond, "NanonewtonsPerSecond", new BaseUnits(length: LengthUnit.Nanometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.NewtonPerMinute, "NewtonsPerMinute", BaseUnits.Undefined, "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.NewtonPerSecond, "NewtonsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.PoundForcePerMinute, "PoundsForcePerMinute", BaseUnits.Undefined, "ForceChangeRate"), - new UnitInfo(ForceChangeRateUnit.PoundForcePerSecond, "PoundsForcePerSecond", BaseUnits.Undefined, "ForceChangeRate"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ForceChangeRateInfo(string name, ForceChangeRateUnit baseUnit, IEnumerable> unitMappings, ForceChangeRate zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ForceChangeRateInfo(string name, ForceChangeRateUnit baseUnit, IEnumerable> unitMappings, ForceChangeRate zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ForceChangeRate.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ForceChangeRate", typeof(ForceChangeRate).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ForceChangeRate quantity. + /// + /// A new instance of the class with the default settings. + public static ForceChangeRateInfo CreateDefault() + { + return new ForceChangeRateInfo(nameof(ForceChangeRate), DefaultBaseUnit, GetDefaultMappings(), new ForceChangeRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ForceChangeRate quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ForceChangeRateInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ForceChangeRateInfo(nameof(ForceChangeRate), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ForceChangeRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 1, -3, 0, 0, 0, 0); + + /// + /// The default base unit of ForceChangeRate is NewtonPerSecond. All conversions, as defined in the , go via this value. + /// + public static ForceChangeRateUnit DefaultBaseUnit { get; } = ForceChangeRateUnit.NewtonPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ForceChangeRate. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ForceChangeRateUnit.CentinewtonPerSecond, "CentinewtonPerSecond", "CentinewtonsPerSecond", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceChangeRateUnit.DecanewtonPerMinute, "DecanewtonPerMinute", "DecanewtonsPerMinute", BaseUnits.Undefined); + yield return new (ForceChangeRateUnit.DecanewtonPerSecond, "DecanewtonPerSecond", "DecanewtonsPerSecond", new BaseUnits(length: LengthUnit.Decameter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceChangeRateUnit.DecinewtonPerSecond, "DecinewtonPerSecond", "DecinewtonsPerSecond", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceChangeRateUnit.KilonewtonPerMinute, "KilonewtonPerMinute", "KilonewtonsPerMinute", BaseUnits.Undefined); + yield return new (ForceChangeRateUnit.KilonewtonPerSecond, "KilonewtonPerSecond", "KilonewtonsPerSecond", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceChangeRateUnit.KilopoundForcePerMinute, "KilopoundForcePerMinute", "KilopoundsForcePerMinute", BaseUnits.Undefined); + yield return new (ForceChangeRateUnit.KilopoundForcePerSecond, "KilopoundForcePerSecond", "KilopoundsForcePerSecond", BaseUnits.Undefined); + yield return new (ForceChangeRateUnit.MicronewtonPerSecond, "MicronewtonPerSecond", "MicronewtonsPerSecond", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceChangeRateUnit.MillinewtonPerSecond, "MillinewtonPerSecond", "MillinewtonsPerSecond", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceChangeRateUnit.NanonewtonPerSecond, "NanonewtonPerSecond", "NanonewtonsPerSecond", new BaseUnits(length: LengthUnit.Nanometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceChangeRateUnit.NewtonPerMinute, "NewtonPerMinute", "NewtonsPerMinute", BaseUnits.Undefined); + yield return new (ForceChangeRateUnit.NewtonPerSecond, "NewtonPerSecond", "NewtonsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForceChangeRateUnit.PoundForcePerMinute, "PoundForcePerMinute", "PoundsForcePerMinute", BaseUnits.Undefined); + yield return new (ForceChangeRateUnit.PoundForcePerSecond, "PoundForcePerSecond", "PoundsForcePerSecond", BaseUnits.Undefined); + } + } + + static ForceChangeRate() + { + Info = ForceChangeRateInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -130,27 +177,27 @@ public ForceChangeRate(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ForceChangeRate, which is NewtonPerSecond. All conversions go via this value. /// - public static ForceChangeRateUnit BaseUnit { get; } + public static ForceChangeRateUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ForceChangeRate quantity. /// - public static ForceChangeRateUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit NewtonPerSecond. /// - public static ForceChangeRate Zero { get; } + public static ForceChangeRate Zero => Info.Zero; /// public static ForceChangeRate AdditiveIdentity => Zero; @@ -168,7 +215,7 @@ public ForceChangeRate(double value, UnitSystem unitSystem) public ForceChangeRateUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -186,6 +233,9 @@ public ForceChangeRate(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs index 4111623605..0433ab19a4 100644 --- a/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ForcePerLength.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -74,56 +70,107 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ForcePerLengthUnit? _unit; - static ForcePerLength() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ForcePerLengthInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 1, -2, 0, 0, 0, 0); - BaseUnit = ForcePerLengthUnit.NewtonPerMeter; - Units = Enum.GetValues(typeof(ForcePerLengthUnit)).Cast().ToArray(); - Zero = new ForcePerLength(0, BaseUnit); - Info = new QuantityInfo("ForcePerLength", - new UnitInfo[] - { - new UnitInfo(ForcePerLengthUnit.CentinewtonPerCentimeter, "CentinewtonsPerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.CentinewtonPerMeter, "CentinewtonsPerMeter", new BaseUnits(mass: MassUnit.Decagram, time: DurationUnit.Second), "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.CentinewtonPerMillimeter, "CentinewtonsPerMillimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.DecanewtonPerCentimeter, "DecanewtonsPerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.DecanewtonPerMeter, "DecanewtonsPerMeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.DecanewtonPerMillimeter, "DecanewtonsPerMillimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.DecinewtonPerCentimeter, "DecinewtonsPerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.DecinewtonPerMeter, "DecinewtonsPerMeter", new BaseUnits(mass: MassUnit.Hectogram, time: DurationUnit.Second), "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.DecinewtonPerMillimeter, "DecinewtonsPerMillimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.KilogramForcePerCentimeter, "KilogramsForcePerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.KilogramForcePerMeter, "KilogramsForcePerMeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.KilogramForcePerMillimeter, "KilogramsForcePerMillimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.KilonewtonPerCentimeter, "KilonewtonsPerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.KilonewtonPerMeter, "KilonewtonsPerMeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.KilonewtonPerMillimeter, "KilonewtonsPerMillimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.KilopoundForcePerFoot, "KilopoundsForcePerFoot", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.KilopoundForcePerInch, "KilopoundsForcePerInch", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.MeganewtonPerCentimeter, "MeganewtonsPerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.MeganewtonPerMeter, "MeganewtonsPerMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Millisecond), "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.MeganewtonPerMillimeter, "MeganewtonsPerMillimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.MicronewtonPerCentimeter, "MicronewtonsPerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.MicronewtonPerMeter, "MicronewtonsPerMeter", new BaseUnits(mass: MassUnit.Milligram, time: DurationUnit.Second), "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.MicronewtonPerMillimeter, "MicronewtonsPerMillimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.MillinewtonPerCentimeter, "MillinewtonsPerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.MillinewtonPerMeter, "MillinewtonsPerMeter", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Second), "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.MillinewtonPerMillimeter, "MillinewtonsPerMillimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.NanonewtonPerCentimeter, "NanonewtonsPerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.NanonewtonPerMeter, "NanonewtonsPerMeter", new BaseUnits(mass: MassUnit.Microgram, time: DurationUnit.Second), "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.NanonewtonPerMillimeter, "NanonewtonsPerMillimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.NewtonPerCentimeter, "NewtonsPerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.NewtonPerMeter, "NewtonsPerMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second), "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.NewtonPerMillimeter, "NewtonsPerMillimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.PoundForcePerFoot, "PoundsForcePerFoot", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.PoundForcePerInch, "PoundsForcePerInch", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.PoundForcePerYard, "PoundsForcePerYard", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.TonneForcePerCentimeter, "TonnesForcePerCentimeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.TonneForcePerMeter, "TonnesForcePerMeter", BaseUnits.Undefined, "ForcePerLength"), - new UnitInfo(ForcePerLengthUnit.TonneForcePerMillimeter, "TonnesForcePerMillimeter", BaseUnits.Undefined, "ForcePerLength"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ForcePerLengthInfo(string name, ForcePerLengthUnit baseUnit, IEnumerable> unitMappings, ForcePerLength zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ForcePerLengthInfo(string name, ForcePerLengthUnit baseUnit, IEnumerable> unitMappings, ForcePerLength zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ForcePerLength.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ForcePerLength", typeof(ForcePerLength).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ForcePerLength quantity. + /// + /// A new instance of the class with the default settings. + public static ForcePerLengthInfo CreateDefault() + { + return new ForcePerLengthInfo(nameof(ForcePerLength), DefaultBaseUnit, GetDefaultMappings(), new ForcePerLength(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ForcePerLength quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ForcePerLengthInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ForcePerLengthInfo(nameof(ForcePerLength), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ForcePerLength(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of ForcePerLength is NewtonPerMeter. All conversions, as defined in the , go via this value. + /// + public static ForcePerLengthUnit DefaultBaseUnit { get; } = ForcePerLengthUnit.NewtonPerMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ForcePerLength. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ForcePerLengthUnit.CentinewtonPerCentimeter, "CentinewtonPerCentimeter", "CentinewtonsPerCentimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.CentinewtonPerMeter, "CentinewtonPerMeter", "CentinewtonsPerMeter", new BaseUnits(mass: MassUnit.Decagram, time: DurationUnit.Second)); + yield return new (ForcePerLengthUnit.CentinewtonPerMillimeter, "CentinewtonPerMillimeter", "CentinewtonsPerMillimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.DecanewtonPerCentimeter, "DecanewtonPerCentimeter", "DecanewtonsPerCentimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.DecanewtonPerMeter, "DecanewtonPerMeter", "DecanewtonsPerMeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.DecanewtonPerMillimeter, "DecanewtonPerMillimeter", "DecanewtonsPerMillimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.DecinewtonPerCentimeter, "DecinewtonPerCentimeter", "DecinewtonsPerCentimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.DecinewtonPerMeter, "DecinewtonPerMeter", "DecinewtonsPerMeter", new BaseUnits(mass: MassUnit.Hectogram, time: DurationUnit.Second)); + yield return new (ForcePerLengthUnit.DecinewtonPerMillimeter, "DecinewtonPerMillimeter", "DecinewtonsPerMillimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.KilogramForcePerCentimeter, "KilogramForcePerCentimeter", "KilogramsForcePerCentimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.KilogramForcePerMeter, "KilogramForcePerMeter", "KilogramsForcePerMeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.KilogramForcePerMillimeter, "KilogramForcePerMillimeter", "KilogramsForcePerMillimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.KilonewtonPerCentimeter, "KilonewtonPerCentimeter", "KilonewtonsPerCentimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.KilonewtonPerMeter, "KilonewtonPerMeter", "KilonewtonsPerMeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.KilonewtonPerMillimeter, "KilonewtonPerMillimeter", "KilonewtonsPerMillimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.KilopoundForcePerFoot, "KilopoundForcePerFoot", "KilopoundsForcePerFoot", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.KilopoundForcePerInch, "KilopoundForcePerInch", "KilopoundsForcePerInch", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.MeganewtonPerCentimeter, "MeganewtonPerCentimeter", "MeganewtonsPerCentimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.MeganewtonPerMeter, "MeganewtonPerMeter", "MeganewtonsPerMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Millisecond)); + yield return new (ForcePerLengthUnit.MeganewtonPerMillimeter, "MeganewtonPerMillimeter", "MeganewtonsPerMillimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.MicronewtonPerCentimeter, "MicronewtonPerCentimeter", "MicronewtonsPerCentimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.MicronewtonPerMeter, "MicronewtonPerMeter", "MicronewtonsPerMeter", new BaseUnits(mass: MassUnit.Milligram, time: DurationUnit.Second)); + yield return new (ForcePerLengthUnit.MicronewtonPerMillimeter, "MicronewtonPerMillimeter", "MicronewtonsPerMillimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.MillinewtonPerCentimeter, "MillinewtonPerCentimeter", "MillinewtonsPerCentimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.MillinewtonPerMeter, "MillinewtonPerMeter", "MillinewtonsPerMeter", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (ForcePerLengthUnit.MillinewtonPerMillimeter, "MillinewtonPerMillimeter", "MillinewtonsPerMillimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.NanonewtonPerCentimeter, "NanonewtonPerCentimeter", "NanonewtonsPerCentimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.NanonewtonPerMeter, "NanonewtonPerMeter", "NanonewtonsPerMeter", new BaseUnits(mass: MassUnit.Microgram, time: DurationUnit.Second)); + yield return new (ForcePerLengthUnit.NanonewtonPerMillimeter, "NanonewtonPerMillimeter", "NanonewtonsPerMillimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.NewtonPerCentimeter, "NewtonPerCentimeter", "NewtonsPerCentimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.NewtonPerMeter, "NewtonPerMeter", "NewtonsPerMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ForcePerLengthUnit.NewtonPerMillimeter, "NewtonPerMillimeter", "NewtonsPerMillimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.PoundForcePerFoot, "PoundForcePerFoot", "PoundsForcePerFoot", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.PoundForcePerInch, "PoundForcePerInch", "PoundsForcePerInch", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.PoundForcePerYard, "PoundForcePerYard", "PoundsForcePerYard", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.TonneForcePerCentimeter, "TonneForcePerCentimeter", "TonnesForcePerCentimeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.TonneForcePerMeter, "TonneForcePerMeter", "TonnesForcePerMeter", BaseUnits.Undefined); + yield return new (ForcePerLengthUnit.TonneForcePerMillimeter, "TonneForcePerMillimeter", "TonnesForcePerMillimeter", BaseUnits.Undefined); + } + } + + static ForcePerLength() + { + Info = ForcePerLengthInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -161,27 +208,27 @@ public ForcePerLength(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ForcePerLength, which is NewtonPerMeter. All conversions go via this value. /// - public static ForcePerLengthUnit BaseUnit { get; } + public static ForcePerLengthUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ForcePerLength quantity. /// - public static ForcePerLengthUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit NewtonPerMeter. /// - public static ForcePerLength Zero { get; } + public static ForcePerLength Zero => Info.Zero; /// public static ForcePerLength AdditiveIdentity => Zero; @@ -199,7 +246,7 @@ public ForcePerLength(double value, UnitSystem unitSystem) public ForcePerLengthUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -217,6 +264,9 @@ public ForcePerLength(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs index 34e9ca573d..1056427f12 100644 --- a/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Frequency.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,30 +62,81 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly FrequencyUnit? _unit; - static Frequency() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class FrequencyInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, -1, 0, 0, 0, 0); - BaseUnit = FrequencyUnit.Hertz; - Units = Enum.GetValues(typeof(FrequencyUnit)).Cast().ToArray(); - Zero = new Frequency(0, BaseUnit); - Info = new QuantityInfo("Frequency", - new UnitInfo[] - { - new UnitInfo(FrequencyUnit.BeatPerMinute, "BeatsPerMinute", new BaseUnits(time: DurationUnit.Minute), "Frequency"), - new UnitInfo(FrequencyUnit.CyclePerHour, "CyclesPerHour", new BaseUnits(time: DurationUnit.Hour), "Frequency"), - new UnitInfo(FrequencyUnit.CyclePerMinute, "CyclesPerMinute", new BaseUnits(time: DurationUnit.Minute), "Frequency"), - new UnitInfo(FrequencyUnit.Gigahertz, "Gigahertz", new BaseUnits(time: DurationUnit.Nanosecond), "Frequency"), - new UnitInfo(FrequencyUnit.Hertz, "Hertz", new BaseUnits(time: DurationUnit.Second), "Frequency"), - new UnitInfo(FrequencyUnit.Kilohertz, "Kilohertz", new BaseUnits(time: DurationUnit.Millisecond), "Frequency"), - new UnitInfo(FrequencyUnit.Megahertz, "Megahertz", new BaseUnits(time: DurationUnit.Microsecond), "Frequency"), - new UnitInfo(FrequencyUnit.Microhertz, "Microhertz", BaseUnits.Undefined, "Frequency"), - new UnitInfo(FrequencyUnit.Millihertz, "Millihertz", BaseUnits.Undefined, "Frequency"), - new UnitInfo(FrequencyUnit.PerSecond, "PerSecond", new BaseUnits(time: DurationUnit.Second), "Frequency"), - new UnitInfo(FrequencyUnit.RadianPerSecond, "RadiansPerSecond", BaseUnits.Undefined, "Frequency"), - new UnitInfo(FrequencyUnit.Terahertz, "Terahertz", BaseUnits.Undefined, "Frequency"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public FrequencyInfo(string name, FrequencyUnit baseUnit, IEnumerable> unitMappings, Frequency zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public FrequencyInfo(string name, FrequencyUnit baseUnit, IEnumerable> unitMappings, Frequency zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Frequency.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Frequency", typeof(Frequency).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Frequency quantity. + /// + /// A new instance of the class with the default settings. + public static FrequencyInfo CreateDefault() + { + return new FrequencyInfo(nameof(Frequency), DefaultBaseUnit, GetDefaultMappings(), new Frequency(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Frequency quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static FrequencyInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new FrequencyInfo(nameof(Frequency), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Frequency(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, -1, 0, 0, 0, 0); + + /// + /// The default base unit of Frequency is Hertz. All conversions, as defined in the , go via this value. + /// + public static FrequencyUnit DefaultBaseUnit { get; } = FrequencyUnit.Hertz; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Frequency. + public static IEnumerable> GetDefaultMappings() + { + yield return new (FrequencyUnit.BeatPerMinute, "BeatPerMinute", "BeatsPerMinute", new BaseUnits(time: DurationUnit.Minute)); + yield return new (FrequencyUnit.CyclePerHour, "CyclePerHour", "CyclesPerHour", new BaseUnits(time: DurationUnit.Hour)); + yield return new (FrequencyUnit.CyclePerMinute, "CyclePerMinute", "CyclesPerMinute", new BaseUnits(time: DurationUnit.Minute)); + yield return new (FrequencyUnit.Gigahertz, "Gigahertz", "Gigahertz", new BaseUnits(time: DurationUnit.Nanosecond)); + yield return new (FrequencyUnit.Hertz, "Hertz", "Hertz", new BaseUnits(time: DurationUnit.Second)); + yield return new (FrequencyUnit.Kilohertz, "Kilohertz", "Kilohertz", new BaseUnits(time: DurationUnit.Millisecond)); + yield return new (FrequencyUnit.Megahertz, "Megahertz", "Megahertz", new BaseUnits(time: DurationUnit.Microsecond)); + yield return new (FrequencyUnit.Microhertz, "Microhertz", "Microhertz", BaseUnits.Undefined); + yield return new (FrequencyUnit.Millihertz, "Millihertz", "Millihertz", BaseUnits.Undefined); + yield return new (FrequencyUnit.PerSecond, "PerSecond", "PerSecond", new BaseUnits(time: DurationUnit.Second)); + yield return new (FrequencyUnit.RadianPerSecond, "RadianPerSecond", "RadiansPerSecond", BaseUnits.Undefined); + yield return new (FrequencyUnit.Terahertz, "Terahertz", "Terahertz", BaseUnits.Undefined); + } + } + + static Frequency() + { + Info = FrequencyInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -127,27 +174,27 @@ public Frequency(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Frequency, which is Hertz. All conversions go via this value. /// - public static FrequencyUnit BaseUnit { get; } + public static FrequencyUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Frequency quantity. /// - public static FrequencyUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Hertz. /// - public static Frequency Zero { get; } + public static Frequency Zero => Info.Zero; /// public static Frequency AdditiveIdentity => Zero; @@ -165,7 +212,7 @@ public Frequency(double value, UnitSystem unitSystem) public FrequencyUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -183,6 +230,9 @@ public Frequency(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs index 8df73ecc28..8d3d30bbe8 100644 --- a/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/FuelEfficiency.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,22 +62,73 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly FuelEfficiencyUnit? _unit; - static FuelEfficiency() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class FuelEfficiencyInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, 0, 0, 0, 0, 0, 0); - BaseUnit = FuelEfficiencyUnit.KilometerPerLiter; - Units = Enum.GetValues(typeof(FuelEfficiencyUnit)).Cast().ToArray(); - Zero = new FuelEfficiency(0, BaseUnit); - Info = new QuantityInfo("FuelEfficiency", - new UnitInfo[] - { - new UnitInfo(FuelEfficiencyUnit.KilometerPerLiter, "KilometersPerLiter", BaseUnits.Undefined, "FuelEfficiency"), - new UnitInfo(FuelEfficiencyUnit.LiterPer100Kilometers, "LitersPer100Kilometers", BaseUnits.Undefined, "FuelEfficiency"), - new UnitInfo(FuelEfficiencyUnit.MilePerUkGallon, "MilesPerUkGallon", BaseUnits.Undefined, "FuelEfficiency"), - new UnitInfo(FuelEfficiencyUnit.MilePerUsGallon, "MilesPerUsGallon", BaseUnits.Undefined, "FuelEfficiency"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public FuelEfficiencyInfo(string name, FuelEfficiencyUnit baseUnit, IEnumerable> unitMappings, FuelEfficiency zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public FuelEfficiencyInfo(string name, FuelEfficiencyUnit baseUnit, IEnumerable> unitMappings, FuelEfficiency zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, FuelEfficiency.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.FuelEfficiency", typeof(FuelEfficiency).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the FuelEfficiency quantity. + /// + /// A new instance of the class with the default settings. + public static FuelEfficiencyInfo CreateDefault() + { + return new FuelEfficiencyInfo(nameof(FuelEfficiency), DefaultBaseUnit, GetDefaultMappings(), new FuelEfficiency(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the FuelEfficiency quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static FuelEfficiencyInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new FuelEfficiencyInfo(nameof(FuelEfficiency), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new FuelEfficiency(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, 0, 0, 0, 0, 0, 0); + + /// + /// The default base unit of FuelEfficiency is KilometerPerLiter. All conversions, as defined in the , go via this value. + /// + public static FuelEfficiencyUnit DefaultBaseUnit { get; } = FuelEfficiencyUnit.KilometerPerLiter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for FuelEfficiency. + public static IEnumerable> GetDefaultMappings() + { + yield return new (FuelEfficiencyUnit.KilometerPerLiter, "KilometerPerLiter", "KilometersPerLiter", BaseUnits.Undefined); + yield return new (FuelEfficiencyUnit.LiterPer100Kilometers, "LiterPer100Kilometers", "LitersPer100Kilometers", BaseUnits.Undefined); + yield return new (FuelEfficiencyUnit.MilePerUkGallon, "MilePerUkGallon", "MilesPerUkGallon", BaseUnits.Undefined); + yield return new (FuelEfficiencyUnit.MilePerUsGallon, "MilePerUsGallon", "MilesPerUsGallon", BaseUnits.Undefined); + } + } + + static FuelEfficiency() + { + Info = FuelEfficiencyInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -119,27 +166,27 @@ public FuelEfficiency(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of FuelEfficiency, which is KilometerPerLiter. All conversions go via this value. /// - public static FuelEfficiencyUnit BaseUnit { get; } + public static FuelEfficiencyUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the FuelEfficiency quantity. /// - public static FuelEfficiencyUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit KilometerPerLiter. /// - public static FuelEfficiency Zero { get; } + public static FuelEfficiency Zero => Info.Zero; /// public static FuelEfficiency AdditiveIdentity => Zero; @@ -157,7 +204,7 @@ public FuelEfficiency(double value, UnitSystem unitSystem) public FuelEfficiencyUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -175,6 +222,9 @@ public FuelEfficiency(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs index 8006caf670..0f6f3034e6 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatFlux.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,36 +62,87 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly HeatFluxUnit? _unit; - static HeatFlux() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class HeatFluxInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 1, -3, 0, 0, 0, 0); - BaseUnit = HeatFluxUnit.WattPerSquareMeter; - Units = Enum.GetValues(typeof(HeatFluxUnit)).Cast().ToArray(); - Zero = new HeatFlux(0, BaseUnit); - Info = new QuantityInfo("HeatFlux", - new UnitInfo[] - { - new UnitInfo(HeatFluxUnit.BtuPerHourSquareFoot, "BtusPerHourSquareFoot", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.BtuPerMinuteSquareFoot, "BtusPerMinuteSquareFoot", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.BtuPerSecondSquareFoot, "BtusPerSecondSquareFoot", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.BtuPerSecondSquareInch, "BtusPerSecondSquareInch", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.CaloriePerSecondSquareCentimeter, "CaloriesPerSecondSquareCentimeter", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.CentiwattPerSquareMeter, "CentiwattsPerSquareMeter", new BaseUnits(mass: MassUnit.Decagram, time: DurationUnit.Second), "HeatFlux"), - new UnitInfo(HeatFluxUnit.DeciwattPerSquareMeter, "DeciwattsPerSquareMeter", new BaseUnits(mass: MassUnit.Hectogram, time: DurationUnit.Second), "HeatFlux"), - new UnitInfo(HeatFluxUnit.KilocaloriePerHourSquareMeter, "KilocaloriesPerHourSquareMeter", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.KilocaloriePerSecondSquareCentimeter, "KilocaloriesPerSecondSquareCentimeter", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.KilowattPerSquareMeter, "KilowattsPerSquareMeter", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.MicrowattPerSquareMeter, "MicrowattsPerSquareMeter", new BaseUnits(mass: MassUnit.Milligram, time: DurationUnit.Second), "HeatFlux"), - new UnitInfo(HeatFluxUnit.MilliwattPerSquareMeter, "MilliwattsPerSquareMeter", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Second), "HeatFlux"), - new UnitInfo(HeatFluxUnit.NanowattPerSquareMeter, "NanowattsPerSquareMeter", new BaseUnits(mass: MassUnit.Microgram, time: DurationUnit.Second), "HeatFlux"), - new UnitInfo(HeatFluxUnit.PoundForcePerFootSecond, "PoundsForcePerFootSecond", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.PoundPerSecondCubed, "PoundsPerSecondCubed", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.WattPerSquareFoot, "WattsPerSquareFoot", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.WattPerSquareInch, "WattsPerSquareInch", BaseUnits.Undefined, "HeatFlux"), - new UnitInfo(HeatFluxUnit.WattPerSquareMeter, "WattsPerSquareMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second), "HeatFlux"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public HeatFluxInfo(string name, HeatFluxUnit baseUnit, IEnumerable> unitMappings, HeatFlux zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public HeatFluxInfo(string name, HeatFluxUnit baseUnit, IEnumerable> unitMappings, HeatFlux zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, HeatFlux.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.HeatFlux", typeof(HeatFlux).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the HeatFlux quantity. + /// + /// A new instance of the class with the default settings. + public static HeatFluxInfo CreateDefault() + { + return new HeatFluxInfo(nameof(HeatFlux), DefaultBaseUnit, GetDefaultMappings(), new HeatFlux(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the HeatFlux quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static HeatFluxInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new HeatFluxInfo(nameof(HeatFlux), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new HeatFlux(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 1, -3, 0, 0, 0, 0); + + /// + /// The default base unit of HeatFlux is WattPerSquareMeter. All conversions, as defined in the , go via this value. + /// + public static HeatFluxUnit DefaultBaseUnit { get; } = HeatFluxUnit.WattPerSquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for HeatFlux. + public static IEnumerable> GetDefaultMappings() + { + yield return new (HeatFluxUnit.BtuPerHourSquareFoot, "BtuPerHourSquareFoot", "BtusPerHourSquareFoot", BaseUnits.Undefined); + yield return new (HeatFluxUnit.BtuPerMinuteSquareFoot, "BtuPerMinuteSquareFoot", "BtusPerMinuteSquareFoot", BaseUnits.Undefined); + yield return new (HeatFluxUnit.BtuPerSecondSquareFoot, "BtuPerSecondSquareFoot", "BtusPerSecondSquareFoot", BaseUnits.Undefined); + yield return new (HeatFluxUnit.BtuPerSecondSquareInch, "BtuPerSecondSquareInch", "BtusPerSecondSquareInch", BaseUnits.Undefined); + yield return new (HeatFluxUnit.CaloriePerSecondSquareCentimeter, "CaloriePerSecondSquareCentimeter", "CaloriesPerSecondSquareCentimeter", BaseUnits.Undefined); + yield return new (HeatFluxUnit.CentiwattPerSquareMeter, "CentiwattPerSquareMeter", "CentiwattsPerSquareMeter", new BaseUnits(mass: MassUnit.Decagram, time: DurationUnit.Second)); + yield return new (HeatFluxUnit.DeciwattPerSquareMeter, "DeciwattPerSquareMeter", "DeciwattsPerSquareMeter", new BaseUnits(mass: MassUnit.Hectogram, time: DurationUnit.Second)); + yield return new (HeatFluxUnit.KilocaloriePerHourSquareMeter, "KilocaloriePerHourSquareMeter", "KilocaloriesPerHourSquareMeter", BaseUnits.Undefined); + yield return new (HeatFluxUnit.KilocaloriePerSecondSquareCentimeter, "KilocaloriePerSecondSquareCentimeter", "KilocaloriesPerSecondSquareCentimeter", BaseUnits.Undefined); + yield return new (HeatFluxUnit.KilowattPerSquareMeter, "KilowattPerSquareMeter", "KilowattsPerSquareMeter", BaseUnits.Undefined); + yield return new (HeatFluxUnit.MicrowattPerSquareMeter, "MicrowattPerSquareMeter", "MicrowattsPerSquareMeter", new BaseUnits(mass: MassUnit.Milligram, time: DurationUnit.Second)); + yield return new (HeatFluxUnit.MilliwattPerSquareMeter, "MilliwattPerSquareMeter", "MilliwattsPerSquareMeter", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (HeatFluxUnit.NanowattPerSquareMeter, "NanowattPerSquareMeter", "NanowattsPerSquareMeter", new BaseUnits(mass: MassUnit.Microgram, time: DurationUnit.Second)); + yield return new (HeatFluxUnit.PoundForcePerFootSecond, "PoundForcePerFootSecond", "PoundsForcePerFootSecond", BaseUnits.Undefined); + yield return new (HeatFluxUnit.PoundPerSecondCubed, "PoundPerSecondCubed", "PoundsPerSecondCubed", BaseUnits.Undefined); + yield return new (HeatFluxUnit.WattPerSquareFoot, "WattPerSquareFoot", "WattsPerSquareFoot", BaseUnits.Undefined); + yield return new (HeatFluxUnit.WattPerSquareInch, "WattPerSquareInch", "WattsPerSquareInch", BaseUnits.Undefined); + yield return new (HeatFluxUnit.WattPerSquareMeter, "WattPerSquareMeter", "WattsPerSquareMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second)); + } + } + + static HeatFlux() + { + Info = HeatFluxInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -133,27 +180,27 @@ public HeatFlux(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of HeatFlux, which is WattPerSquareMeter. All conversions go via this value. /// - public static HeatFluxUnit BaseUnit { get; } + public static HeatFluxUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the HeatFlux quantity. /// - public static HeatFluxUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit WattPerSquareMeter. /// - public static HeatFlux Zero { get; } + public static HeatFlux Zero => Info.Zero; /// public static HeatFlux AdditiveIdentity => Zero; @@ -171,7 +218,7 @@ public HeatFlux(double value, UnitSystem unitSystem) public HeatFluxUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -189,6 +236,9 @@ public HeatFlux(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs index 7489c8f9ac..03b10723a7 100644 --- a/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/HeatTransferCoefficient.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,23 +59,74 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly HeatTransferCoefficientUnit? _unit; - static HeatTransferCoefficient() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class HeatTransferCoefficientInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 1, -3, 0, -1, 0, 0); - BaseUnit = HeatTransferCoefficientUnit.WattPerSquareMeterKelvin; - Units = Enum.GetValues(typeof(HeatTransferCoefficientUnit)).Cast().ToArray(); - Zero = new HeatTransferCoefficient(0, BaseUnit); - Info = new QuantityInfo("HeatTransferCoefficient", - new UnitInfo[] - { - new UnitInfo(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, "BtusPerHourSquareFootDegreeFahrenheit", BaseUnits.Undefined, "HeatTransferCoefficient"), - new UnitInfo(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, "CaloriesPerHourSquareMeterDegreeCelsius", BaseUnits.Undefined, "HeatTransferCoefficient"), - new UnitInfo(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, "KilocaloriesPerHourSquareMeterDegreeCelsius", BaseUnits.Undefined, "HeatTransferCoefficient"), - new UnitInfo(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, "WattsPerSquareMeterCelsius", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "HeatTransferCoefficient"), - new UnitInfo(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, "WattsPerSquareMeterKelvin", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "HeatTransferCoefficient"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public HeatTransferCoefficientInfo(string name, HeatTransferCoefficientUnit baseUnit, IEnumerable> unitMappings, HeatTransferCoefficient zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public HeatTransferCoefficientInfo(string name, HeatTransferCoefficientUnit baseUnit, IEnumerable> unitMappings, HeatTransferCoefficient zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, HeatTransferCoefficient.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.HeatTransferCoefficient", typeof(HeatTransferCoefficient).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the HeatTransferCoefficient quantity. + /// + /// A new instance of the class with the default settings. + public static HeatTransferCoefficientInfo CreateDefault() + { + return new HeatTransferCoefficientInfo(nameof(HeatTransferCoefficient), DefaultBaseUnit, GetDefaultMappings(), new HeatTransferCoefficient(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the HeatTransferCoefficient quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static HeatTransferCoefficientInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new HeatTransferCoefficientInfo(nameof(HeatTransferCoefficient), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new HeatTransferCoefficient(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][M][Θ^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 1, -3, 0, -1, 0, 0); + + /// + /// The default base unit of HeatTransferCoefficient is WattPerSquareMeterKelvin. All conversions, as defined in the , go via this value. + /// + public static HeatTransferCoefficientUnit DefaultBaseUnit { get; } = HeatTransferCoefficientUnit.WattPerSquareMeterKelvin; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for HeatTransferCoefficient. + public static IEnumerable> GetDefaultMappings() + { + yield return new (HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, "BtuPerHourSquareFootDegreeFahrenheit", "BtusPerHourSquareFootDegreeFahrenheit", BaseUnits.Undefined); + yield return new (HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, "CaloriePerHourSquareMeterDegreeCelsius", "CaloriesPerHourSquareMeterDegreeCelsius", BaseUnits.Undefined); + yield return new (HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, "KilocaloriePerHourSquareMeterDegreeCelsius", "KilocaloriesPerHourSquareMeterDegreeCelsius", BaseUnits.Undefined); + yield return new (HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, "WattPerSquareMeterCelsius", "WattsPerSquareMeterCelsius", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, "WattPerSquareMeterKelvin", "WattsPerSquareMeterKelvin", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin)); + } + } + + static HeatTransferCoefficient() + { + Info = HeatTransferCoefficientInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -117,27 +164,27 @@ public HeatTransferCoefficient(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of HeatTransferCoefficient, which is WattPerSquareMeterKelvin. All conversions go via this value. /// - public static HeatTransferCoefficientUnit BaseUnit { get; } + public static HeatTransferCoefficientUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the HeatTransferCoefficient quantity. /// - public static HeatTransferCoefficientUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit WattPerSquareMeterKelvin. /// - public static HeatTransferCoefficient Zero { get; } + public static HeatTransferCoefficient Zero => Info.Zero; /// public static HeatTransferCoefficient AdditiveIdentity => Zero; @@ -155,7 +202,7 @@ public HeatTransferCoefficient(double value, UnitSystem unitSystem) public HeatTransferCoefficientUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -173,6 +220,9 @@ public HeatTransferCoefficient(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs index 1919e9a0cb..cfa04020a9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Illuminance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -69,22 +65,73 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly IlluminanceUnit? _unit; - static Illuminance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class IlluminanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, 0, 0, 0, 0, 0, 1); - BaseUnit = IlluminanceUnit.Lux; - Units = Enum.GetValues(typeof(IlluminanceUnit)).Cast().ToArray(); - Zero = new Illuminance(0, BaseUnit); - Info = new QuantityInfo("Illuminance", - new UnitInfo[] - { - new UnitInfo(IlluminanceUnit.Kilolux, "Kilolux", BaseUnits.Undefined, "Illuminance"), - new UnitInfo(IlluminanceUnit.Lux, "Lux", new BaseUnits(length: LengthUnit.Meter, luminousIntensity: LuminousIntensityUnit.Candela), "Illuminance"), - new UnitInfo(IlluminanceUnit.Megalux, "Megalux", new BaseUnits(length: LengthUnit.Millimeter, luminousIntensity: LuminousIntensityUnit.Candela), "Illuminance"), - new UnitInfo(IlluminanceUnit.Millilux, "Millilux", BaseUnits.Undefined, "Illuminance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public IlluminanceInfo(string name, IlluminanceUnit baseUnit, IEnumerable> unitMappings, Illuminance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public IlluminanceInfo(string name, IlluminanceUnit baseUnit, IEnumerable> unitMappings, Illuminance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Illuminance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Illuminance", typeof(Illuminance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Illuminance quantity. + /// + /// A new instance of the class with the default settings. + public static IlluminanceInfo CreateDefault() + { + return new IlluminanceInfo(nameof(Illuminance), DefaultBaseUnit, GetDefaultMappings(), new Illuminance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Illuminance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static IlluminanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new IlluminanceInfo(nameof(Illuminance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Illuminance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-2][J]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, 0, 0, 0, 0, 0, 1); + + /// + /// The default base unit of Illuminance is Lux. All conversions, as defined in the , go via this value. + /// + public static IlluminanceUnit DefaultBaseUnit { get; } = IlluminanceUnit.Lux; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Illuminance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (IlluminanceUnit.Kilolux, "Kilolux", "Kilolux", BaseUnits.Undefined); + yield return new (IlluminanceUnit.Lux, "Lux", "Lux", new BaseUnits(length: LengthUnit.Meter, luminousIntensity: LuminousIntensityUnit.Candela)); + yield return new (IlluminanceUnit.Megalux, "Megalux", "Megalux", new BaseUnits(length: LengthUnit.Millimeter, luminousIntensity: LuminousIntensityUnit.Candela)); + yield return new (IlluminanceUnit.Millilux, "Millilux", "Millilux", BaseUnits.Undefined); + } + } + + static Illuminance() + { + Info = IlluminanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -122,27 +169,27 @@ public Illuminance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Illuminance, which is Lux. All conversions go via this value. /// - public static IlluminanceUnit BaseUnit { get; } + public static IlluminanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Illuminance quantity. /// - public static IlluminanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Lux. /// - public static Illuminance Zero { get; } + public static Illuminance Zero => Info.Zero; /// public static Illuminance AdditiveIdentity => Zero; @@ -160,7 +207,7 @@ public Illuminance(double value, UnitSystem unitSystem) public IlluminanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -178,6 +225,9 @@ public Illuminance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs b/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs index cadf0717ce..38636f6c80 100644 --- a/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Impulse.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,31 +59,82 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ImpulseUnit? _unit; - static Impulse() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ImpulseInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 1, -1, 0, 0, 0, 0); - BaseUnit = ImpulseUnit.NewtonSecond; - Units = Enum.GetValues(typeof(ImpulseUnit)).Cast().ToArray(); - Zero = new Impulse(0, BaseUnit); - Info = new QuantityInfo("Impulse", - new UnitInfo[] - { - new UnitInfo(ImpulseUnit.CentinewtonSecond, "CentinewtonSeconds", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), - new UnitInfo(ImpulseUnit.DecanewtonSecond, "DecanewtonSeconds", new BaseUnits(length: LengthUnit.Decameter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), - new UnitInfo(ImpulseUnit.DecinewtonSecond, "DecinewtonSeconds", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), - new UnitInfo(ImpulseUnit.KilogramMeterPerSecond, "KilogramMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), - new UnitInfo(ImpulseUnit.KilonewtonSecond, "KilonewtonSeconds", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), - new UnitInfo(ImpulseUnit.MeganewtonSecond, "MeganewtonSeconds", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), - new UnitInfo(ImpulseUnit.MicronewtonSecond, "MicronewtonSeconds", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), - new UnitInfo(ImpulseUnit.MillinewtonSecond, "MillinewtonSeconds", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), - new UnitInfo(ImpulseUnit.NanonewtonSecond, "NanonewtonSeconds", new BaseUnits(length: LengthUnit.Nanometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), - new UnitInfo(ImpulseUnit.NewtonSecond, "NewtonSeconds", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Impulse"), - new UnitInfo(ImpulseUnit.PoundFootPerSecond, "PoundFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound, time: DurationUnit.Second), "Impulse"), - new UnitInfo(ImpulseUnit.PoundForceSecond, "PoundForceSeconds", BaseUnits.Undefined, "Impulse"), - new UnitInfo(ImpulseUnit.SlugFootPerSecond, "SlugFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug, time: DurationUnit.Second), "Impulse"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ImpulseInfo(string name, ImpulseUnit baseUnit, IEnumerable> unitMappings, Impulse zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ImpulseInfo(string name, ImpulseUnit baseUnit, IEnumerable> unitMappings, Impulse zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Impulse.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Impulse", typeof(Impulse).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Impulse quantity. + /// + /// A new instance of the class with the default settings. + public static ImpulseInfo CreateDefault() + { + return new ImpulseInfo(nameof(Impulse), DefaultBaseUnit, GetDefaultMappings(), new Impulse(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Impulse quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ImpulseInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ImpulseInfo(nameof(Impulse), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Impulse(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][L][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 1, -1, 0, 0, 0, 0); + + /// + /// The default base unit of Impulse is NewtonSecond. All conversions, as defined in the , go via this value. + /// + public static ImpulseUnit DefaultBaseUnit { get; } = ImpulseUnit.NewtonSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Impulse. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ImpulseUnit.CentinewtonSecond, "CentinewtonSecond", "CentinewtonSeconds", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ImpulseUnit.DecanewtonSecond, "DecanewtonSecond", "DecanewtonSeconds", new BaseUnits(length: LengthUnit.Decameter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ImpulseUnit.DecinewtonSecond, "DecinewtonSecond", "DecinewtonSeconds", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ImpulseUnit.KilogramMeterPerSecond, "KilogramMeterPerSecond", "KilogramMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ImpulseUnit.KilonewtonSecond, "KilonewtonSecond", "KilonewtonSeconds", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ImpulseUnit.MeganewtonSecond, "MeganewtonSecond", "MeganewtonSeconds", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ImpulseUnit.MicronewtonSecond, "MicronewtonSecond", "MicronewtonSeconds", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ImpulseUnit.MillinewtonSecond, "MillinewtonSecond", "MillinewtonSeconds", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ImpulseUnit.NanonewtonSecond, "NanonewtonSecond", "NanonewtonSeconds", new BaseUnits(length: LengthUnit.Nanometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ImpulseUnit.NewtonSecond, "NewtonSecond", "NewtonSeconds", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (ImpulseUnit.PoundFootPerSecond, "PoundFootPerSecond", "PoundFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound, time: DurationUnit.Second)); + yield return new (ImpulseUnit.PoundForceSecond, "PoundForceSecond", "PoundForceSeconds", BaseUnits.Undefined); + yield return new (ImpulseUnit.SlugFootPerSecond, "SlugFootPerSecond", "SlugFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug, time: DurationUnit.Second)); + } + } + + static Impulse() + { + Info = ImpulseInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -125,27 +172,27 @@ public Impulse(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Impulse, which is NewtonSecond. All conversions go via this value. /// - public static ImpulseUnit BaseUnit { get; } + public static ImpulseUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Impulse quantity. /// - public static ImpulseUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit NewtonSecond. /// - public static Impulse Zero { get; } + public static Impulse Zero => Info.Zero; /// public static Impulse AdditiveIdentity => Zero; @@ -163,7 +210,7 @@ public Impulse(double value, UnitSystem unitSystem) public ImpulseUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -181,6 +228,9 @@ public Impulse(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Information.g.cs b/UnitsNet/GeneratedCode/Quantities/Information.g.cs index cca7dcbb53..2d3c49fbe1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Information.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Information.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,57 +59,108 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly InformationUnit? _unit; - static Information() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class InformationInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = InformationUnit.Bit; - Units = Enum.GetValues(typeof(InformationUnit)).Cast().ToArray(); - Zero = new Information(0, BaseUnit); - Info = new QuantityInfo("Information", - new UnitInfo[] - { - new UnitInfo(InformationUnit.Bit, "Bits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Byte, "Bytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Exabit, "Exabits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Exabyte, "Exabytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Exaoctet, "Exaoctets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Exbibit, "Exbibits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Exbibyte, "Exbibytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Exbioctet, "Exbioctets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Gibibit, "Gibibits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Gibibyte, "Gibibytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Gibioctet, "Gibioctets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Gigabit, "Gigabits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Gigabyte, "Gigabytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Gigaoctet, "Gigaoctets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Kibibit, "Kibibits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Kibibyte, "Kibibytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Kibioctet, "Kibioctets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Kilobit, "Kilobits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Kilobyte, "Kilobytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Kilooctet, "Kilooctets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Mebibit, "Mebibits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Mebibyte, "Mebibytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Mebioctet, "Mebioctets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Megabit, "Megabits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Megabyte, "Megabytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Megaoctet, "Megaoctets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Octet, "Octets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Pebibit, "Pebibits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Pebibyte, "Pebibytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Pebioctet, "Pebioctets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Petabit, "Petabits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Petabyte, "Petabytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Petaoctet, "Petaoctets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Tebibit, "Tebibits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Tebibyte, "Tebibytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Tebioctet, "Tebioctets", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Terabit, "Terabits", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Terabyte, "Terabytes", BaseUnits.Undefined, "Information"), - new UnitInfo(InformationUnit.Teraoctet, "Teraoctets", BaseUnits.Undefined, "Information"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public InformationInfo(string name, InformationUnit baseUnit, IEnumerable> unitMappings, Information zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public InformationInfo(string name, InformationUnit baseUnit, IEnumerable> unitMappings, Information zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Information.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Information", typeof(Information).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Information quantity. + /// + /// A new instance of the class with the default settings. + public static InformationInfo CreateDefault() + { + return new InformationInfo(nameof(Information), DefaultBaseUnit, GetDefaultMappings(), new Information(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Information quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static InformationInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new InformationInfo(nameof(Information), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Information(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of Information is Bit. All conversions, as defined in the , go via this value. + /// + public static InformationUnit DefaultBaseUnit { get; } = InformationUnit.Bit; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Information. + public static IEnumerable> GetDefaultMappings() + { + yield return new (InformationUnit.Bit, "Bit", "Bits", BaseUnits.Undefined); + yield return new (InformationUnit.Byte, "Byte", "Bytes", BaseUnits.Undefined); + yield return new (InformationUnit.Exabit, "Exabit", "Exabits", BaseUnits.Undefined); + yield return new (InformationUnit.Exabyte, "Exabyte", "Exabytes", BaseUnits.Undefined); + yield return new (InformationUnit.Exaoctet, "Exaoctet", "Exaoctets", BaseUnits.Undefined); + yield return new (InformationUnit.Exbibit, "Exbibit", "Exbibits", BaseUnits.Undefined); + yield return new (InformationUnit.Exbibyte, "Exbibyte", "Exbibytes", BaseUnits.Undefined); + yield return new (InformationUnit.Exbioctet, "Exbioctet", "Exbioctets", BaseUnits.Undefined); + yield return new (InformationUnit.Gibibit, "Gibibit", "Gibibits", BaseUnits.Undefined); + yield return new (InformationUnit.Gibibyte, "Gibibyte", "Gibibytes", BaseUnits.Undefined); + yield return new (InformationUnit.Gibioctet, "Gibioctet", "Gibioctets", BaseUnits.Undefined); + yield return new (InformationUnit.Gigabit, "Gigabit", "Gigabits", BaseUnits.Undefined); + yield return new (InformationUnit.Gigabyte, "Gigabyte", "Gigabytes", BaseUnits.Undefined); + yield return new (InformationUnit.Gigaoctet, "Gigaoctet", "Gigaoctets", BaseUnits.Undefined); + yield return new (InformationUnit.Kibibit, "Kibibit", "Kibibits", BaseUnits.Undefined); + yield return new (InformationUnit.Kibibyte, "Kibibyte", "Kibibytes", BaseUnits.Undefined); + yield return new (InformationUnit.Kibioctet, "Kibioctet", "Kibioctets", BaseUnits.Undefined); + yield return new (InformationUnit.Kilobit, "Kilobit", "Kilobits", BaseUnits.Undefined); + yield return new (InformationUnit.Kilobyte, "Kilobyte", "Kilobytes", BaseUnits.Undefined); + yield return new (InformationUnit.Kilooctet, "Kilooctet", "Kilooctets", BaseUnits.Undefined); + yield return new (InformationUnit.Mebibit, "Mebibit", "Mebibits", BaseUnits.Undefined); + yield return new (InformationUnit.Mebibyte, "Mebibyte", "Mebibytes", BaseUnits.Undefined); + yield return new (InformationUnit.Mebioctet, "Mebioctet", "Mebioctets", BaseUnits.Undefined); + yield return new (InformationUnit.Megabit, "Megabit", "Megabits", BaseUnits.Undefined); + yield return new (InformationUnit.Megabyte, "Megabyte", "Megabytes", BaseUnits.Undefined); + yield return new (InformationUnit.Megaoctet, "Megaoctet", "Megaoctets", BaseUnits.Undefined); + yield return new (InformationUnit.Octet, "Octet", "Octets", BaseUnits.Undefined); + yield return new (InformationUnit.Pebibit, "Pebibit", "Pebibits", BaseUnits.Undefined); + yield return new (InformationUnit.Pebibyte, "Pebibyte", "Pebibytes", BaseUnits.Undefined); + yield return new (InformationUnit.Pebioctet, "Pebioctet", "Pebioctets", BaseUnits.Undefined); + yield return new (InformationUnit.Petabit, "Petabit", "Petabits", BaseUnits.Undefined); + yield return new (InformationUnit.Petabyte, "Petabyte", "Petabytes", BaseUnits.Undefined); + yield return new (InformationUnit.Petaoctet, "Petaoctet", "Petaoctets", BaseUnits.Undefined); + yield return new (InformationUnit.Tebibit, "Tebibit", "Tebibits", BaseUnits.Undefined); + yield return new (InformationUnit.Tebibyte, "Tebibyte", "Tebibytes", BaseUnits.Undefined); + yield return new (InformationUnit.Tebioctet, "Tebioctet", "Tebioctets", BaseUnits.Undefined); + yield return new (InformationUnit.Terabit, "Terabit", "Terabits", BaseUnits.Undefined); + yield return new (InformationUnit.Terabyte, "Terabyte", "Terabytes", BaseUnits.Undefined); + yield return new (InformationUnit.Teraoctet, "Teraoctet", "Teraoctets", BaseUnits.Undefined); + } + } + + static Information() + { + Info = InformationInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -137,27 +184,27 @@ public Information(double value, InformationUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Information, which is Bit. All conversions go via this value. /// - public static InformationUnit BaseUnit { get; } + public static InformationUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Information quantity. /// - public static InformationUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Bit. /// - public static Information Zero { get; } + public static Information Zero => Info.Zero; /// public static Information AdditiveIdentity => Zero; @@ -175,7 +222,7 @@ public Information(double value, InformationUnit unit) public InformationUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -193,6 +240,9 @@ public Information(double value, InformationUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs index 7a9010e546..e29c553ea8 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,32 +59,83 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly IrradianceUnit? _unit; - static Irradiance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class IrradianceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 1, -3, 0, 0, 0, 0); - BaseUnit = IrradianceUnit.WattPerSquareMeter; - Units = Enum.GetValues(typeof(IrradianceUnit)).Cast().ToArray(); - Zero = new Irradiance(0, BaseUnit); - Info = new QuantityInfo("Irradiance", - new UnitInfo[] - { - new UnitInfo(IrradianceUnit.KilowattPerSquareCentimeter, "KilowattsPerSquareCentimeter", BaseUnits.Undefined, "Irradiance"), - new UnitInfo(IrradianceUnit.KilowattPerSquareMeter, "KilowattsPerSquareMeter", BaseUnits.Undefined, "Irradiance"), - new UnitInfo(IrradianceUnit.MegawattPerSquareCentimeter, "MegawattsPerSquareCentimeter", BaseUnits.Undefined, "Irradiance"), - new UnitInfo(IrradianceUnit.MegawattPerSquareMeter, "MegawattsPerSquareMeter", BaseUnits.Undefined, "Irradiance"), - new UnitInfo(IrradianceUnit.MicrowattPerSquareCentimeter, "MicrowattsPerSquareCentimeter", BaseUnits.Undefined, "Irradiance"), - new UnitInfo(IrradianceUnit.MicrowattPerSquareMeter, "MicrowattsPerSquareMeter", new BaseUnits(mass: MassUnit.Milligram, time: DurationUnit.Second), "Irradiance"), - new UnitInfo(IrradianceUnit.MilliwattPerSquareCentimeter, "MilliwattsPerSquareCentimeter", BaseUnits.Undefined, "Irradiance"), - new UnitInfo(IrradianceUnit.MilliwattPerSquareMeter, "MilliwattsPerSquareMeter", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Second), "Irradiance"), - new UnitInfo(IrradianceUnit.NanowattPerSquareCentimeter, "NanowattsPerSquareCentimeter", BaseUnits.Undefined, "Irradiance"), - new UnitInfo(IrradianceUnit.NanowattPerSquareMeter, "NanowattsPerSquareMeter", new BaseUnits(mass: MassUnit.Microgram, time: DurationUnit.Second), "Irradiance"), - new UnitInfo(IrradianceUnit.PicowattPerSquareCentimeter, "PicowattsPerSquareCentimeter", BaseUnits.Undefined, "Irradiance"), - new UnitInfo(IrradianceUnit.PicowattPerSquareMeter, "PicowattsPerSquareMeter", new BaseUnits(mass: MassUnit.Nanogram, time: DurationUnit.Second), "Irradiance"), - new UnitInfo(IrradianceUnit.WattPerSquareCentimeter, "WattsPerSquareCentimeter", BaseUnits.Undefined, "Irradiance"), - new UnitInfo(IrradianceUnit.WattPerSquareMeter, "WattsPerSquareMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second), "Irradiance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public IrradianceInfo(string name, IrradianceUnit baseUnit, IEnumerable> unitMappings, Irradiance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public IrradianceInfo(string name, IrradianceUnit baseUnit, IEnumerable> unitMappings, Irradiance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Irradiance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Irradiance", typeof(Irradiance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Irradiance quantity. + /// + /// A new instance of the class with the default settings. + public static IrradianceInfo CreateDefault() + { + return new IrradianceInfo(nameof(Irradiance), DefaultBaseUnit, GetDefaultMappings(), new Irradiance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Irradiance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static IrradianceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new IrradianceInfo(nameof(Irradiance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Irradiance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 1, -3, 0, 0, 0, 0); + + /// + /// The default base unit of Irradiance is WattPerSquareMeter. All conversions, as defined in the , go via this value. + /// + public static IrradianceUnit DefaultBaseUnit { get; } = IrradianceUnit.WattPerSquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Irradiance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (IrradianceUnit.KilowattPerSquareCentimeter, "KilowattPerSquareCentimeter", "KilowattsPerSquareCentimeter", BaseUnits.Undefined); + yield return new (IrradianceUnit.KilowattPerSquareMeter, "KilowattPerSquareMeter", "KilowattsPerSquareMeter", BaseUnits.Undefined); + yield return new (IrradianceUnit.MegawattPerSquareCentimeter, "MegawattPerSquareCentimeter", "MegawattsPerSquareCentimeter", BaseUnits.Undefined); + yield return new (IrradianceUnit.MegawattPerSquareMeter, "MegawattPerSquareMeter", "MegawattsPerSquareMeter", BaseUnits.Undefined); + yield return new (IrradianceUnit.MicrowattPerSquareCentimeter, "MicrowattPerSquareCentimeter", "MicrowattsPerSquareCentimeter", BaseUnits.Undefined); + yield return new (IrradianceUnit.MicrowattPerSquareMeter, "MicrowattPerSquareMeter", "MicrowattsPerSquareMeter", new BaseUnits(mass: MassUnit.Milligram, time: DurationUnit.Second)); + yield return new (IrradianceUnit.MilliwattPerSquareCentimeter, "MilliwattPerSquareCentimeter", "MilliwattsPerSquareCentimeter", BaseUnits.Undefined); + yield return new (IrradianceUnit.MilliwattPerSquareMeter, "MilliwattPerSquareMeter", "MilliwattsPerSquareMeter", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (IrradianceUnit.NanowattPerSquareCentimeter, "NanowattPerSquareCentimeter", "NanowattsPerSquareCentimeter", BaseUnits.Undefined); + yield return new (IrradianceUnit.NanowattPerSquareMeter, "NanowattPerSquareMeter", "NanowattsPerSquareMeter", new BaseUnits(mass: MassUnit.Microgram, time: DurationUnit.Second)); + yield return new (IrradianceUnit.PicowattPerSquareCentimeter, "PicowattPerSquareCentimeter", "PicowattsPerSquareCentimeter", BaseUnits.Undefined); + yield return new (IrradianceUnit.PicowattPerSquareMeter, "PicowattPerSquareMeter", "PicowattsPerSquareMeter", new BaseUnits(mass: MassUnit.Nanogram, time: DurationUnit.Second)); + yield return new (IrradianceUnit.WattPerSquareCentimeter, "WattPerSquareCentimeter", "WattsPerSquareCentimeter", BaseUnits.Undefined); + yield return new (IrradianceUnit.WattPerSquareMeter, "WattPerSquareMeter", "WattsPerSquareMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second)); + } + } + + static Irradiance() + { + Info = IrradianceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -126,27 +173,27 @@ public Irradiance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Irradiance, which is WattPerSquareMeter. All conversions go via this value. /// - public static IrradianceUnit BaseUnit { get; } + public static IrradianceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Irradiance quantity. /// - public static IrradianceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit WattPerSquareMeter. /// - public static Irradiance Zero { get; } + public static Irradiance Zero => Info.Zero; /// public static Irradiance AdditiveIdentity => Zero; @@ -164,7 +211,7 @@ public Irradiance(double value, UnitSystem unitSystem) public IrradianceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -182,6 +229,9 @@ public Irradiance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs index 5830988e67..baf9b37c87 100644 --- a/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Irradiation.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,27 +62,78 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly IrradiationUnit? _unit; - static Irradiation() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class IrradiationInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 1, -2, 0, 0, 0, 0); - BaseUnit = IrradiationUnit.JoulePerSquareMeter; - Units = Enum.GetValues(typeof(IrradiationUnit)).Cast().ToArray(); - Zero = new Irradiation(0, BaseUnit); - Info = new QuantityInfo("Irradiation", - new UnitInfo[] - { - new UnitInfo(IrradiationUnit.BtuPerSquareFoot, "BtusPerSquareFoot", BaseUnits.Undefined, "Irradiation"), - new UnitInfo(IrradiationUnit.JoulePerSquareCentimeter, "JoulesPerSquareCentimeter", BaseUnits.Undefined, "Irradiation"), - new UnitInfo(IrradiationUnit.JoulePerSquareMeter, "JoulesPerSquareMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second), "Irradiation"), - new UnitInfo(IrradiationUnit.JoulePerSquareMillimeter, "JoulesPerSquareMillimeter", BaseUnits.Undefined, "Irradiation"), - new UnitInfo(IrradiationUnit.KilobtuPerSquareFoot, "KilobtusPerSquareFoot", BaseUnits.Undefined, "Irradiation"), - new UnitInfo(IrradiationUnit.KilojoulePerSquareMeter, "KilojoulesPerSquareMeter", BaseUnits.Undefined, "Irradiation"), - new UnitInfo(IrradiationUnit.KilowattHourPerSquareMeter, "KilowattHoursPerSquareMeter", BaseUnits.Undefined, "Irradiation"), - new UnitInfo(IrradiationUnit.MillijoulePerSquareCentimeter, "MillijoulesPerSquareCentimeter", BaseUnits.Undefined, "Irradiation"), - new UnitInfo(IrradiationUnit.WattHourPerSquareMeter, "WattHoursPerSquareMeter", BaseUnits.Undefined, "Irradiation"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public IrradiationInfo(string name, IrradiationUnit baseUnit, IEnumerable> unitMappings, Irradiation zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public IrradiationInfo(string name, IrradiationUnit baseUnit, IEnumerable> unitMappings, Irradiation zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Irradiation.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Irradiation", typeof(Irradiation).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Irradiation quantity. + /// + /// A new instance of the class with the default settings. + public static IrradiationInfo CreateDefault() + { + return new IrradiationInfo(nameof(Irradiation), DefaultBaseUnit, GetDefaultMappings(), new Irradiation(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Irradiation quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static IrradiationInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new IrradiationInfo(nameof(Irradiation), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Irradiation(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of Irradiation is JoulePerSquareMeter. All conversions, as defined in the , go via this value. + /// + public static IrradiationUnit DefaultBaseUnit { get; } = IrradiationUnit.JoulePerSquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Irradiation. + public static IEnumerable> GetDefaultMappings() + { + yield return new (IrradiationUnit.BtuPerSquareFoot, "BtuPerSquareFoot", "BtusPerSquareFoot", BaseUnits.Undefined); + yield return new (IrradiationUnit.JoulePerSquareCentimeter, "JoulePerSquareCentimeter", "JoulesPerSquareCentimeter", BaseUnits.Undefined); + yield return new (IrradiationUnit.JoulePerSquareMeter, "JoulePerSquareMeter", "JoulesPerSquareMeter", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (IrradiationUnit.JoulePerSquareMillimeter, "JoulePerSquareMillimeter", "JoulesPerSquareMillimeter", BaseUnits.Undefined); + yield return new (IrradiationUnit.KilobtuPerSquareFoot, "KilobtuPerSquareFoot", "KilobtusPerSquareFoot", BaseUnits.Undefined); + yield return new (IrradiationUnit.KilojoulePerSquareMeter, "KilojoulePerSquareMeter", "KilojoulesPerSquareMeter", BaseUnits.Undefined); + yield return new (IrradiationUnit.KilowattHourPerSquareMeter, "KilowattHourPerSquareMeter", "KilowattHoursPerSquareMeter", BaseUnits.Undefined); + yield return new (IrradiationUnit.MillijoulePerSquareCentimeter, "MillijoulePerSquareCentimeter", "MillijoulesPerSquareCentimeter", BaseUnits.Undefined); + yield return new (IrradiationUnit.WattHourPerSquareMeter, "WattHourPerSquareMeter", "WattHoursPerSquareMeter", BaseUnits.Undefined); + } + } + + static Irradiation() + { + Info = IrradiationInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -124,27 +171,27 @@ public Irradiation(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Irradiation, which is JoulePerSquareMeter. All conversions go via this value. /// - public static IrradiationUnit BaseUnit { get; } + public static IrradiationUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Irradiation quantity. /// - public static IrradiationUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerSquareMeter. /// - public static Irradiation Zero { get; } + public static Irradiation Zero => Info.Zero; /// public static Irradiation AdditiveIdentity => Zero; @@ -162,7 +209,7 @@ public Irradiation(double value, UnitSystem unitSystem) public IrradiationUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -180,6 +227,9 @@ public Irradiation(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs index 0487a05d5f..c4831f3876 100644 --- a/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Jerk.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,29 +62,80 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly JerkUnit? _unit; - static Jerk() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class JerkInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 0, -3, 0, 0, 0, 0); - BaseUnit = JerkUnit.MeterPerSecondCubed; - Units = Enum.GetValues(typeof(JerkUnit)).Cast().ToArray(); - Zero = new Jerk(0, BaseUnit); - Info = new QuantityInfo("Jerk", - new UnitInfo[] - { - new UnitInfo(JerkUnit.CentimeterPerSecondCubed, "CentimetersPerSecondCubed", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Second), "Jerk"), - new UnitInfo(JerkUnit.DecimeterPerSecondCubed, "DecimetersPerSecondCubed", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Second), "Jerk"), - new UnitInfo(JerkUnit.FootPerSecondCubed, "FeetPerSecondCubed", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second), "Jerk"), - new UnitInfo(JerkUnit.InchPerSecondCubed, "InchesPerSecondCubed", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Second), "Jerk"), - new UnitInfo(JerkUnit.KilometerPerSecondCubed, "KilometersPerSecondCubed", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second), "Jerk"), - new UnitInfo(JerkUnit.MeterPerSecondCubed, "MetersPerSecondCubed", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "Jerk"), - new UnitInfo(JerkUnit.MicrometerPerSecondCubed, "MicrometersPerSecondCubed", new BaseUnits(length: LengthUnit.Micrometer, time: DurationUnit.Second), "Jerk"), - new UnitInfo(JerkUnit.MillimeterPerSecondCubed, "MillimetersPerSecondCubed", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second), "Jerk"), - new UnitInfo(JerkUnit.MillistandardGravitiesPerSecond, "MillistandardGravitiesPerSecond", BaseUnits.Undefined, "Jerk"), - new UnitInfo(JerkUnit.NanometerPerSecondCubed, "NanometersPerSecondCubed", new BaseUnits(length: LengthUnit.Nanometer, time: DurationUnit.Second), "Jerk"), - new UnitInfo(JerkUnit.StandardGravitiesPerSecond, "StandardGravitiesPerSecond", BaseUnits.Undefined, "Jerk"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public JerkInfo(string name, JerkUnit baseUnit, IEnumerable> unitMappings, Jerk zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public JerkInfo(string name, JerkUnit baseUnit, IEnumerable> unitMappings, Jerk zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Jerk.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Jerk", typeof(Jerk).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Jerk quantity. + /// + /// A new instance of the class with the default settings. + public static JerkInfo CreateDefault() + { + return new JerkInfo(nameof(Jerk), DefaultBaseUnit, GetDefaultMappings(), new Jerk(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Jerk quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static JerkInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new JerkInfo(nameof(Jerk), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Jerk(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 0, -3, 0, 0, 0, 0); + + /// + /// The default base unit of Jerk is MeterPerSecondCubed. All conversions, as defined in the , go via this value. + /// + public static JerkUnit DefaultBaseUnit { get; } = JerkUnit.MeterPerSecondCubed; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Jerk. + public static IEnumerable> GetDefaultMappings() + { + yield return new (JerkUnit.CentimeterPerSecondCubed, "CentimeterPerSecondCubed", "CentimetersPerSecondCubed", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Second)); + yield return new (JerkUnit.DecimeterPerSecondCubed, "DecimeterPerSecondCubed", "DecimetersPerSecondCubed", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Second)); + yield return new (JerkUnit.FootPerSecondCubed, "FootPerSecondCubed", "FeetPerSecondCubed", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second)); + yield return new (JerkUnit.InchPerSecondCubed, "InchPerSecondCubed", "InchesPerSecondCubed", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Second)); + yield return new (JerkUnit.KilometerPerSecondCubed, "KilometerPerSecondCubed", "KilometersPerSecondCubed", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second)); + yield return new (JerkUnit.MeterPerSecondCubed, "MeterPerSecondCubed", "MetersPerSecondCubed", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + yield return new (JerkUnit.MicrometerPerSecondCubed, "MicrometerPerSecondCubed", "MicrometersPerSecondCubed", new BaseUnits(length: LengthUnit.Micrometer, time: DurationUnit.Second)); + yield return new (JerkUnit.MillimeterPerSecondCubed, "MillimeterPerSecondCubed", "MillimetersPerSecondCubed", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second)); + yield return new (JerkUnit.MillistandardGravitiesPerSecond, "MillistandardGravitiesPerSecond", "MillistandardGravitiesPerSecond", BaseUnits.Undefined); + yield return new (JerkUnit.NanometerPerSecondCubed, "NanometerPerSecondCubed", "NanometersPerSecondCubed", new BaseUnits(length: LengthUnit.Nanometer, time: DurationUnit.Second)); + yield return new (JerkUnit.StandardGravitiesPerSecond, "StandardGravitiesPerSecond", "StandardGravitiesPerSecond", BaseUnits.Undefined); + } + } + + static Jerk() + { + Info = JerkInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -126,27 +173,27 @@ public Jerk(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Jerk, which is MeterPerSecondCubed. All conversions go via this value. /// - public static JerkUnit BaseUnit { get; } + public static JerkUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Jerk quantity. /// - public static JerkUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit MeterPerSecondCubed. /// - public static Jerk Zero { get; } + public static Jerk Zero => Info.Zero; /// public static Jerk AdditiveIdentity => Zero; @@ -164,7 +211,7 @@ public Jerk(double value, UnitSystem unitSystem) public JerkUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -182,6 +229,9 @@ public Jerk(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs index 15f8bec30c..10e8ef6247 100644 --- a/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/KinematicViscosity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -72,27 +68,78 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly KinematicViscosityUnit? _unit; - static KinematicViscosity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class KinematicViscosityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 0, -1, 0, 0, 0, 0); - BaseUnit = KinematicViscosityUnit.SquareMeterPerSecond; - Units = Enum.GetValues(typeof(KinematicViscosityUnit)).Cast().ToArray(); - Zero = new KinematicViscosity(0, BaseUnit); - Info = new QuantityInfo("KinematicViscosity", - new UnitInfo[] - { - new UnitInfo(KinematicViscosityUnit.Centistokes, "Centistokes", BaseUnits.Undefined, "KinematicViscosity"), - new UnitInfo(KinematicViscosityUnit.Decistokes, "Decistokes", BaseUnits.Undefined, "KinematicViscosity"), - new UnitInfo(KinematicViscosityUnit.Kilostokes, "Kilostokes", BaseUnits.Undefined, "KinematicViscosity"), - new UnitInfo(KinematicViscosityUnit.Microstokes, "Microstokes", BaseUnits.Undefined, "KinematicViscosity"), - new UnitInfo(KinematicViscosityUnit.Millistokes, "Millistokes", BaseUnits.Undefined, "KinematicViscosity"), - new UnitInfo(KinematicViscosityUnit.Nanostokes, "Nanostokes", BaseUnits.Undefined, "KinematicViscosity"), - new UnitInfo(KinematicViscosityUnit.SquareFootPerSecond, "SquareFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second), "KinematicViscosity"), - new UnitInfo(KinematicViscosityUnit.SquareMeterPerSecond, "SquareMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "KinematicViscosity"), - new UnitInfo(KinematicViscosityUnit.Stokes, "Stokes", BaseUnits.Undefined, "KinematicViscosity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public KinematicViscosityInfo(string name, KinematicViscosityUnit baseUnit, IEnumerable> unitMappings, KinematicViscosity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public KinematicViscosityInfo(string name, KinematicViscosityUnit baseUnit, IEnumerable> unitMappings, KinematicViscosity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, KinematicViscosity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.KinematicViscosity", typeof(KinematicViscosity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the KinematicViscosity quantity. + /// + /// A new instance of the class with the default settings. + public static KinematicViscosityInfo CreateDefault() + { + return new KinematicViscosityInfo(nameof(KinematicViscosity), DefaultBaseUnit, GetDefaultMappings(), new KinematicViscosity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the KinematicViscosity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static KinematicViscosityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new KinematicViscosityInfo(nameof(KinematicViscosity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new KinematicViscosity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][L^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 0, -1, 0, 0, 0, 0); + + /// + /// The default base unit of KinematicViscosity is SquareMeterPerSecond. All conversions, as defined in the , go via this value. + /// + public static KinematicViscosityUnit DefaultBaseUnit { get; } = KinematicViscosityUnit.SquareMeterPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for KinematicViscosity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (KinematicViscosityUnit.Centistokes, "Centistokes", "Centistokes", BaseUnits.Undefined); + yield return new (KinematicViscosityUnit.Decistokes, "Decistokes", "Decistokes", BaseUnits.Undefined); + yield return new (KinematicViscosityUnit.Kilostokes, "Kilostokes", "Kilostokes", BaseUnits.Undefined); + yield return new (KinematicViscosityUnit.Microstokes, "Microstokes", "Microstokes", BaseUnits.Undefined); + yield return new (KinematicViscosityUnit.Millistokes, "Millistokes", "Millistokes", BaseUnits.Undefined); + yield return new (KinematicViscosityUnit.Nanostokes, "Nanostokes", "Nanostokes", BaseUnits.Undefined); + yield return new (KinematicViscosityUnit.SquareFootPerSecond, "SquareFootPerSecond", "SquareFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second)); + yield return new (KinematicViscosityUnit.SquareMeterPerSecond, "SquareMeterPerSecond", "SquareMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + yield return new (KinematicViscosityUnit.Stokes, "Stokes", "Stokes", BaseUnits.Undefined); + } + } + + static KinematicViscosity() + { + Info = KinematicViscosityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -130,27 +177,27 @@ public KinematicViscosity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of KinematicViscosity, which is SquareMeterPerSecond. All conversions go via this value. /// - public static KinematicViscosityUnit BaseUnit { get; } + public static KinematicViscosityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the KinematicViscosity quantity. /// - public static KinematicViscosityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit SquareMeterPerSecond. /// - public static KinematicViscosity Zero { get; } + public static KinematicViscosity Zero => Info.Zero; /// public static KinematicViscosity AdditiveIdentity => Zero; @@ -168,7 +215,7 @@ public KinematicViscosity(double value, UnitSystem unitSystem) public KinematicViscosityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -186,6 +233,9 @@ public KinematicViscosity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs b/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs index 031d8571e5..519b61926a 100644 --- a/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LeakRate.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,21 +62,72 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly LeakRateUnit? _unit; - static LeakRate() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class LeakRateInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); - BaseUnit = LeakRateUnit.PascalCubicMeterPerSecond; - Units = Enum.GetValues(typeof(LeakRateUnit)).Cast().ToArray(); - Zero = new LeakRate(0, BaseUnit); - Info = new QuantityInfo("LeakRate", - new UnitInfo[] - { - new UnitInfo(LeakRateUnit.MillibarLiterPerSecond, "MillibarLitersPerSecond", BaseUnits.Undefined, "LeakRate"), - new UnitInfo(LeakRateUnit.PascalCubicMeterPerSecond, "PascalCubicMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "LeakRate"), - new UnitInfo(LeakRateUnit.TorrLiterPerSecond, "TorrLitersPerSecond", BaseUnits.Undefined, "LeakRate"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public LeakRateInfo(string name, LeakRateUnit baseUnit, IEnumerable> unitMappings, LeakRate zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public LeakRateInfo(string name, LeakRateUnit baseUnit, IEnumerable> unitMappings, LeakRate zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, LeakRate.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.LeakRate", typeof(LeakRate).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the LeakRate quantity. + /// + /// A new instance of the class with the default settings. + public static LeakRateInfo CreateDefault() + { + return new LeakRateInfo(nameof(LeakRate), DefaultBaseUnit, GetDefaultMappings(), new LeakRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the LeakRate quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static LeakRateInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new LeakRateInfo(nameof(LeakRate), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new LeakRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); + + /// + /// The default base unit of LeakRate is PascalCubicMeterPerSecond. All conversions, as defined in the , go via this value. + /// + public static LeakRateUnit DefaultBaseUnit { get; } = LeakRateUnit.PascalCubicMeterPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for LeakRate. + public static IEnumerable> GetDefaultMappings() + { + yield return new (LeakRateUnit.MillibarLiterPerSecond, "MillibarLiterPerSecond", "MillibarLitersPerSecond", BaseUnits.Undefined); + yield return new (LeakRateUnit.PascalCubicMeterPerSecond, "PascalCubicMeterPerSecond", "PascalCubicMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (LeakRateUnit.TorrLiterPerSecond, "TorrLiterPerSecond", "TorrLitersPerSecond", BaseUnits.Undefined); + } + } + + static LeakRate() + { + Info = LeakRateInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -118,27 +165,27 @@ public LeakRate(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of LeakRate, which is PascalCubicMeterPerSecond. All conversions go via this value. /// - public static LeakRateUnit BaseUnit { get; } + public static LeakRateUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the LeakRate quantity. /// - public static LeakRateUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit PascalCubicMeterPerSecond. /// - public static LeakRate Zero { get; } + public static LeakRate Zero => Info.Zero; /// public static LeakRate AdditiveIdentity => Zero; @@ -156,7 +203,7 @@ public LeakRate(double value, UnitSystem unitSystem) public LeakRateUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -174,6 +221,9 @@ public LeakRate(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Length.g.cs b/UnitsNet/GeneratedCode/Quantities/Length.g.cs index c60350df15..b5a0bec8be 100644 --- a/UnitsNet/GeneratedCode/Quantities/Length.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Length.g.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by \generate-code.bat. // @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -83,60 +79,111 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly LengthUnit? _unit; - static Length() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class LengthInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 0, 0, 0, 0, 0, 0); - BaseUnit = LengthUnit.Meter; - Units = Enum.GetValues(typeof(LengthUnit)).Cast().ToArray(); - Zero = new Length(0, BaseUnit); - Info = new QuantityInfo("Length", - new UnitInfo[] - { - new UnitInfo(LengthUnit.Angstrom, "Angstroms", new BaseUnits(length: LengthUnit.Angstrom), "Length"), - new UnitInfo(LengthUnit.AstronomicalUnit, "AstronomicalUnits", new BaseUnits(length: LengthUnit.AstronomicalUnit), "Length"), - new UnitInfo(LengthUnit.Centimeter, "Centimeters", new BaseUnits(length: LengthUnit.Centimeter), "Length"), - new UnitInfo(LengthUnit.Chain, "Chains", new BaseUnits(length: LengthUnit.Chain), "Length"), - new UnitInfo(LengthUnit.DataMile, "DataMiles", new BaseUnits(length: LengthUnit.DataMile), "Length"), - new UnitInfo(LengthUnit.Decameter, "Decameters", new BaseUnits(length: LengthUnit.Decameter), "Length"), - new UnitInfo(LengthUnit.Decimeter, "Decimeters", new BaseUnits(length: LengthUnit.Decimeter), "Length"), - new UnitInfo(LengthUnit.DtpPica, "DtpPicas", new BaseUnits(length: LengthUnit.DtpPica), "Length"), - new UnitInfo(LengthUnit.DtpPoint, "DtpPoints", new BaseUnits(length: LengthUnit.DtpPoint), "Length"), - new UnitInfo(LengthUnit.Fathom, "Fathoms", new BaseUnits(length: LengthUnit.Fathom), "Length"), - new UnitInfo(LengthUnit.Femtometer, "Femtometers", new BaseUnits(length: LengthUnit.Femtometer), "Length"), - new UnitInfo(LengthUnit.Foot, "Feet", new BaseUnits(length: LengthUnit.Foot), "Length"), - new UnitInfo(LengthUnit.Gigameter, "Gigameters", new BaseUnits(length: LengthUnit.Gigameter), "Length"), - new UnitInfo(LengthUnit.Hand, "Hands", new BaseUnits(length: LengthUnit.Hand), "Length"), - new UnitInfo(LengthUnit.Hectometer, "Hectometers", new BaseUnits(length: LengthUnit.Hectometer), "Length"), - new UnitInfo(LengthUnit.Inch, "Inches", new BaseUnits(length: LengthUnit.Inch), "Length"), - new UnitInfo(LengthUnit.Kilofoot, "Kilofeet", new BaseUnits(length: LengthUnit.Kilofoot), "Length"), - new UnitInfo(LengthUnit.KilolightYear, "KilolightYears", new BaseUnits(length: LengthUnit.KilolightYear), "Length"), - new UnitInfo(LengthUnit.Kilometer, "Kilometers", new BaseUnits(length: LengthUnit.Kilometer), "Length"), - new UnitInfo(LengthUnit.Kiloparsec, "Kiloparsecs", new BaseUnits(length: LengthUnit.Kiloparsec), "Length"), - new UnitInfo(LengthUnit.Kiloyard, "Kiloyards", new BaseUnits(length: LengthUnit.Kiloyard), "Length"), - new UnitInfo(LengthUnit.LightYear, "LightYears", new BaseUnits(length: LengthUnit.LightYear), "Length"), - new UnitInfo(LengthUnit.MegalightYear, "MegalightYears", new BaseUnits(length: LengthUnit.MegalightYear), "Length"), - new UnitInfo(LengthUnit.Megameter, "Megameters", new BaseUnits(length: LengthUnit.Megameter), "Length"), - new UnitInfo(LengthUnit.Megaparsec, "Megaparsecs", new BaseUnits(length: LengthUnit.Megaparsec), "Length"), - new UnitInfo(LengthUnit.Meter, "Meters", new BaseUnits(length: LengthUnit.Meter), "Length"), - new UnitInfo(LengthUnit.Microinch, "Microinches", new BaseUnits(length: LengthUnit.Microinch), "Length"), - new UnitInfo(LengthUnit.Micrometer, "Micrometers", new BaseUnits(length: LengthUnit.Micrometer), "Length"), - new UnitInfo(LengthUnit.Mil, "Mils", new BaseUnits(length: LengthUnit.Mil), "Length"), - new UnitInfo(LengthUnit.Mile, "Miles", new BaseUnits(length: LengthUnit.Mile), "Length"), - new UnitInfo(LengthUnit.Millimeter, "Millimeters", new BaseUnits(length: LengthUnit.Millimeter), "Length"), - new UnitInfo(LengthUnit.Nanometer, "Nanometers", new BaseUnits(length: LengthUnit.Nanometer), "Length"), - new UnitInfo(LengthUnit.NauticalMile, "NauticalMiles", new BaseUnits(length: LengthUnit.NauticalMile), "Length"), - new UnitInfo(LengthUnit.Parsec, "Parsecs", new BaseUnits(length: LengthUnit.Parsec), "Length"), - new UnitInfo(LengthUnit.Picometer, "Picometers", new BaseUnits(length: LengthUnit.Picometer), "Length"), - new UnitInfo(LengthUnit.PrinterPica, "PrinterPicas", new BaseUnits(length: LengthUnit.PrinterPica), "Length"), - new UnitInfo(LengthUnit.PrinterPoint, "PrinterPoints", new BaseUnits(length: LengthUnit.PrinterPoint), "Length"), - new UnitInfo(LengthUnit.Shackle, "Shackles", new BaseUnits(length: LengthUnit.Shackle), "Length"), - new UnitInfo(LengthUnit.SolarRadius, "SolarRadiuses", new BaseUnits(length: LengthUnit.SolarRadius), "Length"), - new UnitInfo(LengthUnit.Twip, "Twips", new BaseUnits(length: LengthUnit.Twip), "Length"), - new UnitInfo(LengthUnit.UsSurveyFoot, "UsSurveyFeet", new BaseUnits(length: LengthUnit.UsSurveyFoot), "Length"), - new UnitInfo(LengthUnit.Yard, "Yards", new BaseUnits(length: LengthUnit.Yard), "Length"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public LengthInfo(string name, LengthUnit baseUnit, IEnumerable> unitMappings, Length zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public LengthInfo(string name, LengthUnit baseUnit, IEnumerable> unitMappings, Length zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Length.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Length", typeof(Length).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Length quantity. + /// + /// A new instance of the class with the default settings. + public static LengthInfo CreateDefault() + { + return new LengthInfo(nameof(Length), DefaultBaseUnit, GetDefaultMappings(), new Length(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Length quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static LengthInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new LengthInfo(nameof(Length), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Length(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 0, 0, 0, 0, 0, 0); + + /// + /// The default base unit of Length is Meter. All conversions, as defined in the , go via this value. + /// + public static LengthUnit DefaultBaseUnit { get; } = LengthUnit.Meter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Length. + public static IEnumerable> GetDefaultMappings() + { + yield return new (LengthUnit.Angstrom, "Angstrom", "Angstroms", new BaseUnits(length: LengthUnit.Angstrom)); + yield return new (LengthUnit.AstronomicalUnit, "AstronomicalUnit", "AstronomicalUnits", new BaseUnits(length: LengthUnit.AstronomicalUnit)); + yield return new (LengthUnit.Centimeter, "Centimeter", "Centimeters", new BaseUnits(length: LengthUnit.Centimeter)); + yield return new (LengthUnit.Chain, "Chain", "Chains", new BaseUnits(length: LengthUnit.Chain)); + yield return new (LengthUnit.DataMile, "DataMile", "DataMiles", new BaseUnits(length: LengthUnit.DataMile)); + yield return new (LengthUnit.Decameter, "Decameter", "Decameters", new BaseUnits(length: LengthUnit.Decameter)); + yield return new (LengthUnit.Decimeter, "Decimeter", "Decimeters", new BaseUnits(length: LengthUnit.Decimeter)); + yield return new (LengthUnit.DtpPica, "DtpPica", "DtpPicas", new BaseUnits(length: LengthUnit.DtpPica)); + yield return new (LengthUnit.DtpPoint, "DtpPoint", "DtpPoints", new BaseUnits(length: LengthUnit.DtpPoint)); + yield return new (LengthUnit.Fathom, "Fathom", "Fathoms", new BaseUnits(length: LengthUnit.Fathom)); + yield return new (LengthUnit.Femtometer, "Femtometer", "Femtometers", new BaseUnits(length: LengthUnit.Femtometer)); + yield return new (LengthUnit.Foot, "Foot", "Feet", new BaseUnits(length: LengthUnit.Foot)); + yield return new (LengthUnit.Gigameter, "Gigameter", "Gigameters", new BaseUnits(length: LengthUnit.Gigameter)); + yield return new (LengthUnit.Hand, "Hand", "Hands", new BaseUnits(length: LengthUnit.Hand)); + yield return new (LengthUnit.Hectometer, "Hectometer", "Hectometers", new BaseUnits(length: LengthUnit.Hectometer)); + yield return new (LengthUnit.Inch, "Inch", "Inches", new BaseUnits(length: LengthUnit.Inch)); + yield return new (LengthUnit.Kilofoot, "Kilofoot", "Kilofeet", new BaseUnits(length: LengthUnit.Kilofoot)); + yield return new (LengthUnit.KilolightYear, "KilolightYear", "KilolightYears", new BaseUnits(length: LengthUnit.KilolightYear)); + yield return new (LengthUnit.Kilometer, "Kilometer", "Kilometers", new BaseUnits(length: LengthUnit.Kilometer)); + yield return new (LengthUnit.Kiloparsec, "Kiloparsec", "Kiloparsecs", new BaseUnits(length: LengthUnit.Kiloparsec)); + yield return new (LengthUnit.Kiloyard, "Kiloyard", "Kiloyards", new BaseUnits(length: LengthUnit.Kiloyard)); + yield return new (LengthUnit.LightYear, "LightYear", "LightYears", new BaseUnits(length: LengthUnit.LightYear)); + yield return new (LengthUnit.MegalightYear, "MegalightYear", "MegalightYears", new BaseUnits(length: LengthUnit.MegalightYear)); + yield return new (LengthUnit.Megameter, "Megameter", "Megameters", new BaseUnits(length: LengthUnit.Megameter)); + yield return new (LengthUnit.Megaparsec, "Megaparsec", "Megaparsecs", new BaseUnits(length: LengthUnit.Megaparsec)); + yield return new (LengthUnit.Meter, "Meter", "Meters", new BaseUnits(length: LengthUnit.Meter)); + yield return new (LengthUnit.Microinch, "Microinch", "Microinches", new BaseUnits(length: LengthUnit.Microinch)); + yield return new (LengthUnit.Micrometer, "Micrometer", "Micrometers", new BaseUnits(length: LengthUnit.Micrometer)); + yield return new (LengthUnit.Mil, "Mil", "Mils", new BaseUnits(length: LengthUnit.Mil)); + yield return new (LengthUnit.Mile, "Mile", "Miles", new BaseUnits(length: LengthUnit.Mile)); + yield return new (LengthUnit.Millimeter, "Millimeter", "Millimeters", new BaseUnits(length: LengthUnit.Millimeter)); + yield return new (LengthUnit.Nanometer, "Nanometer", "Nanometers", new BaseUnits(length: LengthUnit.Nanometer)); + yield return new (LengthUnit.NauticalMile, "NauticalMile", "NauticalMiles", new BaseUnits(length: LengthUnit.NauticalMile)); + yield return new (LengthUnit.Parsec, "Parsec", "Parsecs", new BaseUnits(length: LengthUnit.Parsec)); + yield return new (LengthUnit.Picometer, "Picometer", "Picometers", new BaseUnits(length: LengthUnit.Picometer)); + yield return new (LengthUnit.PrinterPica, "PrinterPica", "PrinterPicas", new BaseUnits(length: LengthUnit.PrinterPica)); + yield return new (LengthUnit.PrinterPoint, "PrinterPoint", "PrinterPoints", new BaseUnits(length: LengthUnit.PrinterPoint)); + yield return new (LengthUnit.Shackle, "Shackle", "Shackles", new BaseUnits(length: LengthUnit.Shackle)); + yield return new (LengthUnit.SolarRadius, "SolarRadius", "SolarRadiuses", new BaseUnits(length: LengthUnit.SolarRadius)); + yield return new (LengthUnit.Twip, "Twip", "Twips", new BaseUnits(length: LengthUnit.Twip)); + yield return new (LengthUnit.UsSurveyFoot, "UsSurveyFoot", "UsSurveyFeet", new BaseUnits(length: LengthUnit.UsSurveyFoot)); + yield return new (LengthUnit.Yard, "Yard", "Yards", new BaseUnits(length: LengthUnit.Yard)); + } + } + + static Length() + { + Info = LengthInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -174,27 +221,27 @@ public Length(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Length, which is Meter. All conversions go via this value. /// - public static LengthUnit BaseUnit { get; } + public static LengthUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Length quantity. /// - public static LengthUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Meter. /// - public static Length Zero { get; } + public static Length Zero => Info.Zero; /// public static Length AdditiveIdentity => Zero; @@ -212,7 +259,7 @@ public Length(double value, UnitSystem unitSystem) public LengthUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -230,6 +277,9 @@ public Length(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Level.g.cs b/UnitsNet/GeneratedCode/Quantities/Level.g.cs index 8b13dab6d0..629007f2d0 100644 --- a/UnitsNet/GeneratedCode/Quantities/Level.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Level.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,20 +59,71 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly LevelUnit? _unit; - static Level() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class LevelInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = LevelUnit.Decibel; - Units = Enum.GetValues(typeof(LevelUnit)).Cast().ToArray(); - Zero = new Level(0, BaseUnit); - Info = new QuantityInfo("Level", - new UnitInfo[] - { - new UnitInfo(LevelUnit.Decibel, "Decibels", BaseUnits.Undefined, "Level"), - new UnitInfo(LevelUnit.Neper, "Nepers", BaseUnits.Undefined, "Level"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public LevelInfo(string name, LevelUnit baseUnit, IEnumerable> unitMappings, Level zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public LevelInfo(string name, LevelUnit baseUnit, IEnumerable> unitMappings, Level zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Level.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Level", typeof(Level).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Level quantity. + /// + /// A new instance of the class with the default settings. + public static LevelInfo CreateDefault() + { + return new LevelInfo(nameof(Level), DefaultBaseUnit, GetDefaultMappings(), new Level(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Level quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static LevelInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new LevelInfo(nameof(Level), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Level(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of Level is Decibel. All conversions, as defined in the , go via this value. + /// + public static LevelUnit DefaultBaseUnit { get; } = LevelUnit.Decibel; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Level. + public static IEnumerable> GetDefaultMappings() + { + yield return new (LevelUnit.Decibel, "Decibel", "Decibels", BaseUnits.Undefined); + yield return new (LevelUnit.Neper, "Neper", "Nepers", BaseUnits.Undefined); + } + } + + static Level() + { + Info = LevelInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -100,27 +147,27 @@ public Level(double value, LevelUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Level, which is Decibel. All conversions go via this value. /// - public static LevelUnit BaseUnit { get; } + public static LevelUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Level quantity. /// - public static LevelUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Decibel. /// - public static Level Zero { get; } + public static Level Zero => Info.Zero; /// public static Level AdditiveIdentity => Zero; @@ -138,7 +185,7 @@ public Level(double value, LevelUnit unit) public LevelUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -156,6 +203,9 @@ public Level(double value, LevelUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs index 42be914595..2418b59c33 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearDensity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -71,36 +67,87 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly LinearDensityUnit? _unit; - static LinearDensity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class LinearDensityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-1, 1, 0, 0, 0, 0, 0); - BaseUnit = LinearDensityUnit.KilogramPerMeter; - Units = Enum.GetValues(typeof(LinearDensityUnit)).Cast().ToArray(); - Zero = new LinearDensity(0, BaseUnit); - Info = new QuantityInfo("LinearDensity", - new UnitInfo[] - { - new UnitInfo(LinearDensityUnit.GramPerCentimeter, "GramsPerCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.GramPerFoot, "GramsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Gram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.GramPerMeter, "GramsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.GramPerMillimeter, "GramsPerMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.KilogramPerCentimeter, "KilogramsPerCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.KilogramPerFoot, "KilogramsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Kilogram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.KilogramPerMeter, "KilogramsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.KilogramPerMillimeter, "KilogramsPerMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.MicrogramPerCentimeter, "MicrogramsPerCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Microgram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.MicrogramPerFoot, "MicrogramsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Microgram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.MicrogramPerMeter, "MicrogramsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.MicrogramPerMillimeter, "MicrogramsPerMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Microgram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.MilligramPerCentimeter, "MilligramsPerCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Milligram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.MilligramPerFoot, "MilligramsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Milligram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.MilligramPerMeter, "MilligramsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.MilligramPerMillimeter, "MilligramsPerMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Milligram), "LinearDensity"), - new UnitInfo(LinearDensityUnit.PoundPerFoot, "PoundsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound), "LinearDensity"), - new UnitInfo(LinearDensityUnit.PoundPerInch, "PoundsPerInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound), "LinearDensity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public LinearDensityInfo(string name, LinearDensityUnit baseUnit, IEnumerable> unitMappings, LinearDensity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public LinearDensityInfo(string name, LinearDensityUnit baseUnit, IEnumerable> unitMappings, LinearDensity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, LinearDensity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.LinearDensity", typeof(LinearDensity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the LinearDensity quantity. + /// + /// A new instance of the class with the default settings. + public static LinearDensityInfo CreateDefault() + { + return new LinearDensityInfo(nameof(LinearDensity), DefaultBaseUnit, GetDefaultMappings(), new LinearDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the LinearDensity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static LinearDensityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new LinearDensityInfo(nameof(LinearDensity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new LinearDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-1][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-1, 1, 0, 0, 0, 0, 0); + + /// + /// The default base unit of LinearDensity is KilogramPerMeter. All conversions, as defined in the , go via this value. + /// + public static LinearDensityUnit DefaultBaseUnit { get; } = LinearDensityUnit.KilogramPerMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for LinearDensity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (LinearDensityUnit.GramPerCentimeter, "GramPerCentimeter", "GramsPerCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)); + yield return new (LinearDensityUnit.GramPerFoot, "GramPerFoot", "GramsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Gram)); + yield return new (LinearDensityUnit.GramPerMeter, "GramPerMeter", "GramsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram)); + yield return new (LinearDensityUnit.GramPerMillimeter, "GramPerMillimeter", "GramsPerMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram)); + yield return new (LinearDensityUnit.KilogramPerCentimeter, "KilogramPerCentimeter", "KilogramsPerCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram)); + yield return new (LinearDensityUnit.KilogramPerFoot, "KilogramPerFoot", "KilogramsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Kilogram)); + yield return new (LinearDensityUnit.KilogramPerMeter, "KilogramPerMeter", "KilogramsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)); + yield return new (LinearDensityUnit.KilogramPerMillimeter, "KilogramPerMillimeter", "KilogramsPerMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram)); + yield return new (LinearDensityUnit.MicrogramPerCentimeter, "MicrogramPerCentimeter", "MicrogramsPerCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Microgram)); + yield return new (LinearDensityUnit.MicrogramPerFoot, "MicrogramPerFoot", "MicrogramsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Microgram)); + yield return new (LinearDensityUnit.MicrogramPerMeter, "MicrogramPerMeter", "MicrogramsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram)); + yield return new (LinearDensityUnit.MicrogramPerMillimeter, "MicrogramPerMillimeter", "MicrogramsPerMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Microgram)); + yield return new (LinearDensityUnit.MilligramPerCentimeter, "MilligramPerCentimeter", "MilligramsPerCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Milligram)); + yield return new (LinearDensityUnit.MilligramPerFoot, "MilligramPerFoot", "MilligramsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Milligram)); + yield return new (LinearDensityUnit.MilligramPerMeter, "MilligramPerMeter", "MilligramsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram)); + yield return new (LinearDensityUnit.MilligramPerMillimeter, "MilligramPerMillimeter", "MilligramsPerMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Milligram)); + yield return new (LinearDensityUnit.PoundPerFoot, "PoundPerFoot", "PoundsPerFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound)); + yield return new (LinearDensityUnit.PoundPerInch, "PoundPerInch", "PoundsPerInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound)); + } + } + + static LinearDensity() + { + Info = LinearDensityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -138,27 +185,27 @@ public LinearDensity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of LinearDensity, which is KilogramPerMeter. All conversions go via this value. /// - public static LinearDensityUnit BaseUnit { get; } + public static LinearDensityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the LinearDensity quantity. /// - public static LinearDensityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerMeter. /// - public static LinearDensity Zero { get; } + public static LinearDensity Zero => Info.Zero; /// public static LinearDensity AdditiveIdentity => Zero; @@ -176,7 +223,7 @@ public LinearDensity(double value, UnitSystem unitSystem) public LinearDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -194,6 +241,9 @@ public LinearDensity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs index 9f58cb012f..dfa62ba9f9 100644 --- a/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LinearPowerDensity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,43 +62,94 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly LinearPowerDensityUnit? _unit; - static LinearPowerDensity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class LinearPowerDensityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 1, -3, 0, 0, 0, 0); - BaseUnit = LinearPowerDensityUnit.WattPerMeter; - Units = Enum.GetValues(typeof(LinearPowerDensityUnit)).Cast().ToArray(); - Zero = new LinearPowerDensity(0, BaseUnit); - Info = new QuantityInfo("LinearPowerDensity", - new UnitInfo[] - { - new UnitInfo(LinearPowerDensityUnit.GigawattPerCentimeter, "GigawattsPerCentimeter", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.GigawattPerFoot, "GigawattsPerFoot", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.GigawattPerInch, "GigawattsPerInch", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.GigawattPerMeter, "GigawattsPerMeter", new BaseUnits(length: LengthUnit.Gigameter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.GigawattPerMillimeter, "GigawattsPerMillimeter", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.KilowattPerCentimeter, "KilowattsPerCentimeter", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.KilowattPerFoot, "KilowattsPerFoot", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.KilowattPerInch, "KilowattsPerInch", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.KilowattPerMeter, "KilowattsPerMeter", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.KilowattPerMillimeter, "KilowattsPerMillimeter", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.MegawattPerCentimeter, "MegawattsPerCentimeter", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.MegawattPerFoot, "MegawattsPerFoot", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.MegawattPerInch, "MegawattsPerInch", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.MegawattPerMeter, "MegawattsPerMeter", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.MegawattPerMillimeter, "MegawattsPerMillimeter", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.MilliwattPerCentimeter, "MilliwattsPerCentimeter", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.MilliwattPerFoot, "MilliwattsPerFoot", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.MilliwattPerInch, "MilliwattsPerInch", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.MilliwattPerMeter, "MilliwattsPerMeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.MilliwattPerMillimeter, "MilliwattsPerMillimeter", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.WattPerCentimeter, "WattsPerCentimeter", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.WattPerFoot, "WattsPerFoot", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.WattPerInch, "WattsPerInch", BaseUnits.Undefined, "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.WattPerMeter, "WattsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "LinearPowerDensity"), - new UnitInfo(LinearPowerDensityUnit.WattPerMillimeter, "WattsPerMillimeter", BaseUnits.Undefined, "LinearPowerDensity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public LinearPowerDensityInfo(string name, LinearPowerDensityUnit baseUnit, IEnumerable> unitMappings, LinearPowerDensity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public LinearPowerDensityInfo(string name, LinearPowerDensityUnit baseUnit, IEnumerable> unitMappings, LinearPowerDensity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, LinearPowerDensity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.LinearPowerDensity", typeof(LinearPowerDensity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the LinearPowerDensity quantity. + /// + /// A new instance of the class with the default settings. + public static LinearPowerDensityInfo CreateDefault() + { + return new LinearPowerDensityInfo(nameof(LinearPowerDensity), DefaultBaseUnit, GetDefaultMappings(), new LinearPowerDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the LinearPowerDensity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static LinearPowerDensityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new LinearPowerDensityInfo(nameof(LinearPowerDensity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new LinearPowerDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 1, -3, 0, 0, 0, 0); + + /// + /// The default base unit of LinearPowerDensity is WattPerMeter. All conversions, as defined in the , go via this value. + /// + public static LinearPowerDensityUnit DefaultBaseUnit { get; } = LinearPowerDensityUnit.WattPerMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for LinearPowerDensity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (LinearPowerDensityUnit.GigawattPerCentimeter, "GigawattPerCentimeter", "GigawattsPerCentimeter", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.GigawattPerFoot, "GigawattPerFoot", "GigawattsPerFoot", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.GigawattPerInch, "GigawattPerInch", "GigawattsPerInch", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.GigawattPerMeter, "GigawattPerMeter", "GigawattsPerMeter", new BaseUnits(length: LengthUnit.Gigameter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (LinearPowerDensityUnit.GigawattPerMillimeter, "GigawattPerMillimeter", "GigawattsPerMillimeter", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.KilowattPerCentimeter, "KilowattPerCentimeter", "KilowattsPerCentimeter", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.KilowattPerFoot, "KilowattPerFoot", "KilowattsPerFoot", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.KilowattPerInch, "KilowattPerInch", "KilowattsPerInch", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.KilowattPerMeter, "KilowattPerMeter", "KilowattsPerMeter", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (LinearPowerDensityUnit.KilowattPerMillimeter, "KilowattPerMillimeter", "KilowattsPerMillimeter", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.MegawattPerCentimeter, "MegawattPerCentimeter", "MegawattsPerCentimeter", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.MegawattPerFoot, "MegawattPerFoot", "MegawattsPerFoot", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.MegawattPerInch, "MegawattPerInch", "MegawattsPerInch", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.MegawattPerMeter, "MegawattPerMeter", "MegawattsPerMeter", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (LinearPowerDensityUnit.MegawattPerMillimeter, "MegawattPerMillimeter", "MegawattsPerMillimeter", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.MilliwattPerCentimeter, "MilliwattPerCentimeter", "MilliwattsPerCentimeter", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.MilliwattPerFoot, "MilliwattPerFoot", "MilliwattsPerFoot", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.MilliwattPerInch, "MilliwattPerInch", "MilliwattsPerInch", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.MilliwattPerMeter, "MilliwattPerMeter", "MilliwattsPerMeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (LinearPowerDensityUnit.MilliwattPerMillimeter, "MilliwattPerMillimeter", "MilliwattsPerMillimeter", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.WattPerCentimeter, "WattPerCentimeter", "WattsPerCentimeter", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.WattPerFoot, "WattPerFoot", "WattsPerFoot", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.WattPerInch, "WattPerInch", "WattsPerInch", BaseUnits.Undefined); + yield return new (LinearPowerDensityUnit.WattPerMeter, "WattPerMeter", "WattsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (LinearPowerDensityUnit.WattPerMillimeter, "WattPerMillimeter", "WattsPerMillimeter", BaseUnits.Undefined); + } + } + + static LinearPowerDensity() + { + Info = LinearPowerDensityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -140,27 +187,27 @@ public LinearPowerDensity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of LinearPowerDensity, which is WattPerMeter. All conversions go via this value. /// - public static LinearPowerDensityUnit BaseUnit { get; } + public static LinearPowerDensityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the LinearPowerDensity quantity. /// - public static LinearPowerDensityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit WattPerMeter. /// - public static LinearPowerDensity Zero { get; } + public static LinearPowerDensity Zero => Info.Zero; /// public static LinearPowerDensity AdditiveIdentity => Zero; @@ -178,7 +225,7 @@ public LinearPowerDensity(double value, UnitSystem unitSystem) public LinearPowerDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -196,6 +243,9 @@ public LinearPowerDensity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs index 763826f11b..35e3b41a94 100644 --- a/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Luminance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -69,28 +65,79 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly LuminanceUnit? _unit; - static Luminance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class LuminanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, 0, 0, 0, 0, 0, 1); - BaseUnit = LuminanceUnit.CandelaPerSquareMeter; - Units = Enum.GetValues(typeof(LuminanceUnit)).Cast().ToArray(); - Zero = new Luminance(0, BaseUnit); - Info = new QuantityInfo("Luminance", - new UnitInfo[] - { - new UnitInfo(LuminanceUnit.CandelaPerSquareFoot, "CandelasPerSquareFoot", BaseUnits.Undefined, "Luminance"), - new UnitInfo(LuminanceUnit.CandelaPerSquareInch, "CandelasPerSquareInch", BaseUnits.Undefined, "Luminance"), - new UnitInfo(LuminanceUnit.CandelaPerSquareMeter, "CandelasPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, luminousIntensity: LuminousIntensityUnit.Candela), "Luminance"), - new UnitInfo(LuminanceUnit.CenticandelaPerSquareMeter, "CenticandelasPerSquareMeter", new BaseUnits(length: LengthUnit.Decameter, luminousIntensity: LuminousIntensityUnit.Candela), "Luminance"), - new UnitInfo(LuminanceUnit.DecicandelaPerSquareMeter, "DecicandelasPerSquareMeter", BaseUnits.Undefined, "Luminance"), - new UnitInfo(LuminanceUnit.KilocandelaPerSquareMeter, "KilocandelasPerSquareMeter", BaseUnits.Undefined, "Luminance"), - new UnitInfo(LuminanceUnit.MicrocandelaPerSquareMeter, "MicrocandelasPerSquareMeter", new BaseUnits(length: LengthUnit.Kilometer, luminousIntensity: LuminousIntensityUnit.Candela), "Luminance"), - new UnitInfo(LuminanceUnit.MillicandelaPerSquareMeter, "MillicandelasPerSquareMeter", BaseUnits.Undefined, "Luminance"), - new UnitInfo(LuminanceUnit.NanocandelaPerSquareMeter, "NanocandelasPerSquareMeter", BaseUnits.Undefined, "Luminance"), - new UnitInfo(LuminanceUnit.Nit, "Nits", BaseUnits.Undefined, "Luminance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public LuminanceInfo(string name, LuminanceUnit baseUnit, IEnumerable> unitMappings, Luminance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public LuminanceInfo(string name, LuminanceUnit baseUnit, IEnumerable> unitMappings, Luminance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Luminance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Luminance", typeof(Luminance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Luminance quantity. + /// + /// A new instance of the class with the default settings. + public static LuminanceInfo CreateDefault() + { + return new LuminanceInfo(nameof(Luminance), DefaultBaseUnit, GetDefaultMappings(), new Luminance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Luminance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static LuminanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new LuminanceInfo(nameof(Luminance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Luminance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-2][J]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, 0, 0, 0, 0, 0, 1); + + /// + /// The default base unit of Luminance is CandelaPerSquareMeter. All conversions, as defined in the , go via this value. + /// + public static LuminanceUnit DefaultBaseUnit { get; } = LuminanceUnit.CandelaPerSquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Luminance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (LuminanceUnit.CandelaPerSquareFoot, "CandelaPerSquareFoot", "CandelasPerSquareFoot", BaseUnits.Undefined); + yield return new (LuminanceUnit.CandelaPerSquareInch, "CandelaPerSquareInch", "CandelasPerSquareInch", BaseUnits.Undefined); + yield return new (LuminanceUnit.CandelaPerSquareMeter, "CandelaPerSquareMeter", "CandelasPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, luminousIntensity: LuminousIntensityUnit.Candela)); + yield return new (LuminanceUnit.CenticandelaPerSquareMeter, "CenticandelaPerSquareMeter", "CenticandelasPerSquareMeter", new BaseUnits(length: LengthUnit.Decameter, luminousIntensity: LuminousIntensityUnit.Candela)); + yield return new (LuminanceUnit.DecicandelaPerSquareMeter, "DecicandelaPerSquareMeter", "DecicandelasPerSquareMeter", BaseUnits.Undefined); + yield return new (LuminanceUnit.KilocandelaPerSquareMeter, "KilocandelaPerSquareMeter", "KilocandelasPerSquareMeter", BaseUnits.Undefined); + yield return new (LuminanceUnit.MicrocandelaPerSquareMeter, "MicrocandelaPerSquareMeter", "MicrocandelasPerSquareMeter", new BaseUnits(length: LengthUnit.Kilometer, luminousIntensity: LuminousIntensityUnit.Candela)); + yield return new (LuminanceUnit.MillicandelaPerSquareMeter, "MillicandelaPerSquareMeter", "MillicandelasPerSquareMeter", BaseUnits.Undefined); + yield return new (LuminanceUnit.NanocandelaPerSquareMeter, "NanocandelaPerSquareMeter", "NanocandelasPerSquareMeter", BaseUnits.Undefined); + yield return new (LuminanceUnit.Nit, "Nit", "Nits", BaseUnits.Undefined); + } + } + + static Luminance() + { + Info = LuminanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -128,27 +175,27 @@ public Luminance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Luminance, which is CandelaPerSquareMeter. All conversions go via this value. /// - public static LuminanceUnit BaseUnit { get; } + public static LuminanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Luminance quantity. /// - public static LuminanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit CandelaPerSquareMeter. /// - public static Luminance Zero { get; } + public static Luminance Zero => Info.Zero; /// public static Luminance AdditiveIdentity => Zero; @@ -166,7 +213,7 @@ public Luminance(double value, UnitSystem unitSystem) public LuminanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -184,6 +231,9 @@ public Luminance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs index 6eaaaf560c..beb31748b1 100644 --- a/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Luminosity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,32 +62,83 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly LuminosityUnit? _unit; - static Luminosity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class LuminosityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); - BaseUnit = LuminosityUnit.Watt; - Units = Enum.GetValues(typeof(LuminosityUnit)).Cast().ToArray(); - Zero = new Luminosity(0, BaseUnit); - Info = new QuantityInfo("Luminosity", - new UnitInfo[] - { - new UnitInfo(LuminosityUnit.Decawatt, "Decawatts", BaseUnits.Undefined, "Luminosity"), - new UnitInfo(LuminosityUnit.Deciwatt, "Deciwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Hectogram, time: DurationUnit.Second), "Luminosity"), - new UnitInfo(LuminosityUnit.Femtowatt, "Femtowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Picogram, time: DurationUnit.Second), "Luminosity"), - new UnitInfo(LuminosityUnit.Gigawatt, "Gigawatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond), "Luminosity"), - new UnitInfo(LuminosityUnit.Kilowatt, "Kilowatts", BaseUnits.Undefined, "Luminosity"), - new UnitInfo(LuminosityUnit.Megawatt, "Megawatts", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Luminosity"), - new UnitInfo(LuminosityUnit.Microwatt, "Microwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second), "Luminosity"), - new UnitInfo(LuminosityUnit.Milliwatt, "Milliwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second), "Luminosity"), - new UnitInfo(LuminosityUnit.Nanowatt, "Nanowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second), "Luminosity"), - new UnitInfo(LuminosityUnit.Petawatt, "Petawatts", BaseUnits.Undefined, "Luminosity"), - new UnitInfo(LuminosityUnit.Picowatt, "Picowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second), "Luminosity"), - new UnitInfo(LuminosityUnit.SolarLuminosity, "SolarLuminosities", BaseUnits.Undefined, "Luminosity"), - new UnitInfo(LuminosityUnit.Terawatt, "Terawatts", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Luminosity"), - new UnitInfo(LuminosityUnit.Watt, "Watts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Luminosity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public LuminosityInfo(string name, LuminosityUnit baseUnit, IEnumerable> unitMappings, Luminosity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public LuminosityInfo(string name, LuminosityUnit baseUnit, IEnumerable> unitMappings, Luminosity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Luminosity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Luminosity", typeof(Luminosity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Luminosity quantity. + /// + /// A new instance of the class with the default settings. + public static LuminosityInfo CreateDefault() + { + return new LuminosityInfo(nameof(Luminosity), DefaultBaseUnit, GetDefaultMappings(), new Luminosity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Luminosity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static LuminosityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new LuminosityInfo(nameof(Luminosity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Luminosity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); + + /// + /// The default base unit of Luminosity is Watt. All conversions, as defined in the , go via this value. + /// + public static LuminosityUnit DefaultBaseUnit { get; } = LuminosityUnit.Watt; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Luminosity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (LuminosityUnit.Decawatt, "Decawatt", "Decawatts", BaseUnits.Undefined); + yield return new (LuminosityUnit.Deciwatt, "Deciwatt", "Deciwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Hectogram, time: DurationUnit.Second)); + yield return new (LuminosityUnit.Femtowatt, "Femtowatt", "Femtowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Picogram, time: DurationUnit.Second)); + yield return new (LuminosityUnit.Gigawatt, "Gigawatt", "Gigawatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond)); + yield return new (LuminosityUnit.Kilowatt, "Kilowatt", "Kilowatts", BaseUnits.Undefined); + yield return new (LuminosityUnit.Megawatt, "Megawatt", "Megawatts", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (LuminosityUnit.Microwatt, "Microwatt", "Microwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second)); + yield return new (LuminosityUnit.Milliwatt, "Milliwatt", "Milliwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (LuminosityUnit.Nanowatt, "Nanowatt", "Nanowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second)); + yield return new (LuminosityUnit.Petawatt, "Petawatt", "Petawatts", BaseUnits.Undefined); + yield return new (LuminosityUnit.Picowatt, "Picowatt", "Picowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second)); + yield return new (LuminosityUnit.SolarLuminosity, "SolarLuminosity", "SolarLuminosities", BaseUnits.Undefined); + yield return new (LuminosityUnit.Terawatt, "Terawatt", "Terawatts", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (LuminosityUnit.Watt, "Watt", "Watts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + } + } + + static Luminosity() + { + Info = LuminosityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -129,27 +176,27 @@ public Luminosity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Luminosity, which is Watt. All conversions go via this value. /// - public static LuminosityUnit BaseUnit { get; } + public static LuminosityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Luminosity quantity. /// - public static LuminosityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Watt. /// - public static Luminosity Zero { get; } + public static Luminosity Zero => Info.Zero; /// public static Luminosity AdditiveIdentity => Zero; @@ -167,7 +214,7 @@ public Luminosity(double value, UnitSystem unitSystem) public LuminosityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -185,6 +232,9 @@ public Luminosity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs index 51a7aedab5..0ddc111059 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousFlux.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -70,19 +66,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly LuminousFluxUnit? _unit; - static LuminousFlux() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class LuminousFluxInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, 0, 0, 0, 0, 1); - BaseUnit = LuminousFluxUnit.Lumen; - Units = Enum.GetValues(typeof(LuminousFluxUnit)).Cast().ToArray(); - Zero = new LuminousFlux(0, BaseUnit); - Info = new QuantityInfo("LuminousFlux", - new UnitInfo[] - { - new UnitInfo(LuminousFluxUnit.Lumen, "Lumens", new BaseUnits(luminousIntensity: LuminousIntensityUnit.Candela), "LuminousFlux"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public LuminousFluxInfo(string name, LuminousFluxUnit baseUnit, IEnumerable> unitMappings, LuminousFlux zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public LuminousFluxInfo(string name, LuminousFluxUnit baseUnit, IEnumerable> unitMappings, LuminousFlux zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, LuminousFlux.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.LuminousFlux", typeof(LuminousFlux).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the LuminousFlux quantity. + /// + /// A new instance of the class with the default settings. + public static LuminousFluxInfo CreateDefault() + { + return new LuminousFluxInfo(nameof(LuminousFlux), DefaultBaseUnit, GetDefaultMappings(), new LuminousFlux(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the LuminousFlux quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static LuminousFluxInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new LuminousFluxInfo(nameof(LuminousFlux), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new LuminousFlux(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [J]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, 0, 0, 0, 0, 1); + + /// + /// The default base unit of LuminousFlux is Lumen. All conversions, as defined in the , go via this value. + /// + public static LuminousFluxUnit DefaultBaseUnit { get; } = LuminousFluxUnit.Lumen; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for LuminousFlux. + public static IEnumerable> GetDefaultMappings() + { + yield return new (LuminousFluxUnit.Lumen, "Lumen", "Lumens", new BaseUnits(luminousIntensity: LuminousIntensityUnit.Candela)); + } + } + + static LuminousFlux() + { + Info = LuminousFluxInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -120,27 +167,27 @@ public LuminousFlux(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of LuminousFlux, which is Lumen. All conversions go via this value. /// - public static LuminousFluxUnit BaseUnit { get; } + public static LuminousFluxUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the LuminousFlux quantity. /// - public static LuminousFluxUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Lumen. /// - public static LuminousFlux Zero { get; } + public static LuminousFlux Zero => Info.Zero; /// public static LuminousFlux AdditiveIdentity => Zero; @@ -158,7 +205,7 @@ public LuminousFlux(double value, UnitSystem unitSystem) public LuminousFluxUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -176,6 +223,9 @@ public LuminousFlux(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs index cf10a6929e..06fe320720 100644 --- a/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/LuminousIntensity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -70,19 +66,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly LuminousIntensityUnit? _unit; - static LuminousIntensity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class LuminousIntensityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, 0, 0, 0, 0, 1); - BaseUnit = LuminousIntensityUnit.Candela; - Units = Enum.GetValues(typeof(LuminousIntensityUnit)).Cast().ToArray(); - Zero = new LuminousIntensity(0, BaseUnit); - Info = new QuantityInfo("LuminousIntensity", - new UnitInfo[] - { - new UnitInfo(LuminousIntensityUnit.Candela, "Candela", new BaseUnits(luminousIntensity: LuminousIntensityUnit.Candela), "LuminousIntensity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public LuminousIntensityInfo(string name, LuminousIntensityUnit baseUnit, IEnumerable> unitMappings, LuminousIntensity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public LuminousIntensityInfo(string name, LuminousIntensityUnit baseUnit, IEnumerable> unitMappings, LuminousIntensity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, LuminousIntensity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.LuminousIntensity", typeof(LuminousIntensity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the LuminousIntensity quantity. + /// + /// A new instance of the class with the default settings. + public static LuminousIntensityInfo CreateDefault() + { + return new LuminousIntensityInfo(nameof(LuminousIntensity), DefaultBaseUnit, GetDefaultMappings(), new LuminousIntensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the LuminousIntensity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static LuminousIntensityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new LuminousIntensityInfo(nameof(LuminousIntensity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new LuminousIntensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [J]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, 0, 0, 0, 0, 1); + + /// + /// The default base unit of LuminousIntensity is Candela. All conversions, as defined in the , go via this value. + /// + public static LuminousIntensityUnit DefaultBaseUnit { get; } = LuminousIntensityUnit.Candela; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for LuminousIntensity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (LuminousIntensityUnit.Candela, "Candela", "Candela", new BaseUnits(luminousIntensity: LuminousIntensityUnit.Candela)); + } + } + + static LuminousIntensity() + { + Info = LuminousIntensityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -120,27 +167,27 @@ public LuminousIntensity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of LuminousIntensity, which is Candela. All conversions go via this value. /// - public static LuminousIntensityUnit BaseUnit { get; } + public static LuminousIntensityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the LuminousIntensity quantity. /// - public static LuminousIntensityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Candela. /// - public static LuminousIntensity Zero { get; } + public static LuminousIntensity Zero => Info.Zero; /// public static LuminousIntensity AdditiveIdentity => Zero; @@ -158,7 +205,7 @@ public LuminousIntensity(double value, UnitSystem unitSystem) public LuminousIntensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -176,6 +223,9 @@ public LuminousIntensity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs index ea33a6055c..d2e61a1be0 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticField.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,24 +62,75 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MagneticFieldUnit? _unit; - static MagneticField() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MagneticFieldInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 1, -2, -1, 0, 0, 0); - BaseUnit = MagneticFieldUnit.Tesla; - Units = Enum.GetValues(typeof(MagneticFieldUnit)).Cast().ToArray(); - Zero = new MagneticField(0, BaseUnit); - Info = new QuantityInfo("MagneticField", - new UnitInfo[] - { - new UnitInfo(MagneticFieldUnit.Gauss, "Gausses", BaseUnits.Undefined, "MagneticField"), - new UnitInfo(MagneticFieldUnit.Microtesla, "Microteslas", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, current: ElectricCurrentUnit.Ampere), "MagneticField"), - new UnitInfo(MagneticFieldUnit.Milligauss, "Milligausses", BaseUnits.Undefined, "MagneticField"), - new UnitInfo(MagneticFieldUnit.Millitesla, "Milliteslas", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, current: ElectricCurrentUnit.Ampere), "MagneticField"), - new UnitInfo(MagneticFieldUnit.Nanotesla, "Nanoteslas", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, current: ElectricCurrentUnit.Ampere), "MagneticField"), - new UnitInfo(MagneticFieldUnit.Tesla, "Teslas", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, current: ElectricCurrentUnit.Ampere), "MagneticField"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MagneticFieldInfo(string name, MagneticFieldUnit baseUnit, IEnumerable> unitMappings, MagneticField zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MagneticFieldInfo(string name, MagneticFieldUnit baseUnit, IEnumerable> unitMappings, MagneticField zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, MagneticField.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.MagneticField", typeof(MagneticField).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the MagneticField quantity. + /// + /// A new instance of the class with the default settings. + public static MagneticFieldInfo CreateDefault() + { + return new MagneticFieldInfo(nameof(MagneticField), DefaultBaseUnit, GetDefaultMappings(), new MagneticField(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the MagneticField quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MagneticFieldInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MagneticFieldInfo(nameof(MagneticField), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new MagneticField(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][M][I^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 1, -2, -1, 0, 0, 0); + + /// + /// The default base unit of MagneticField is Tesla. All conversions, as defined in the , go via this value. + /// + public static MagneticFieldUnit DefaultBaseUnit { get; } = MagneticFieldUnit.Tesla; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for MagneticField. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MagneticFieldUnit.Gauss, "Gauss", "Gausses", BaseUnits.Undefined); + yield return new (MagneticFieldUnit.Microtesla, "Microtesla", "Microteslas", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, current: ElectricCurrentUnit.Ampere)); + yield return new (MagneticFieldUnit.Milligauss, "Milligauss", "Milligausses", BaseUnits.Undefined); + yield return new (MagneticFieldUnit.Millitesla, "Millitesla", "Milliteslas", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, current: ElectricCurrentUnit.Ampere)); + yield return new (MagneticFieldUnit.Nanotesla, "Nanotesla", "Nanoteslas", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, current: ElectricCurrentUnit.Ampere)); + yield return new (MagneticFieldUnit.Tesla, "Tesla", "Teslas", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, current: ElectricCurrentUnit.Ampere)); + } + } + + static MagneticField() + { + Info = MagneticFieldInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -121,27 +168,27 @@ public MagneticField(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of MagneticField, which is Tesla. All conversions go via this value. /// - public static MagneticFieldUnit BaseUnit { get; } + public static MagneticFieldUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the MagneticField quantity. /// - public static MagneticFieldUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Tesla. /// - public static MagneticField Zero { get; } + public static MagneticField Zero => Info.Zero; /// public static MagneticField AdditiveIdentity => Zero; @@ -159,7 +206,7 @@ public MagneticField(double value, UnitSystem unitSystem) public MagneticFieldUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -177,6 +224,9 @@ public MagneticField(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs index d7b0b286f4..e9714bc4b7 100644 --- a/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MagneticFlux.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,19 +62,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MagneticFluxUnit? _unit; - static MagneticFlux() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MagneticFluxInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -2, -1, 0, 0, 0); - BaseUnit = MagneticFluxUnit.Weber; - Units = Enum.GetValues(typeof(MagneticFluxUnit)).Cast().ToArray(); - Zero = new MagneticFlux(0, BaseUnit); - Info = new QuantityInfo("MagneticFlux", - new UnitInfo[] - { - new UnitInfo(MagneticFluxUnit.Weber, "Webers", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "MagneticFlux"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MagneticFluxInfo(string name, MagneticFluxUnit baseUnit, IEnumerable> unitMappings, MagneticFlux zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MagneticFluxInfo(string name, MagneticFluxUnit baseUnit, IEnumerable> unitMappings, MagneticFlux zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, MagneticFlux.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.MagneticFlux", typeof(MagneticFlux).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the MagneticFlux quantity. + /// + /// A new instance of the class with the default settings. + public static MagneticFluxInfo CreateDefault() + { + return new MagneticFluxInfo(nameof(MagneticFlux), DefaultBaseUnit, GetDefaultMappings(), new MagneticFlux(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the MagneticFlux quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MagneticFluxInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MagneticFluxInfo(nameof(MagneticFlux), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new MagneticFlux(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2][M][I^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -2, -1, 0, 0, 0); + + /// + /// The default base unit of MagneticFlux is Weber. All conversions, as defined in the , go via this value. + /// + public static MagneticFluxUnit DefaultBaseUnit { get; } = MagneticFluxUnit.Weber; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for MagneticFlux. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MagneticFluxUnit.Weber, "Weber", "Webers", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static MagneticFlux() + { + Info = MagneticFluxInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -116,27 +163,27 @@ public MagneticFlux(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of MagneticFlux, which is Weber. All conversions go via this value. /// - public static MagneticFluxUnit BaseUnit { get; } + public static MagneticFluxUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the MagneticFlux quantity. /// - public static MagneticFluxUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Weber. /// - public static MagneticFlux Zero { get; } + public static MagneticFlux Zero => Info.Zero; /// public static MagneticFlux AdditiveIdentity => Zero; @@ -154,7 +201,7 @@ public MagneticFlux(double value, UnitSystem unitSystem) public MagneticFluxUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -172,6 +219,9 @@ public MagneticFlux(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs b/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs index 57f3d001c6..8bac3fa31d 100644 --- a/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Magnetization.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,19 +62,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MagnetizationUnit? _unit; - static Magnetization() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MagnetizationInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-1, 0, 0, 1, 0, 0, 0); - BaseUnit = MagnetizationUnit.AmperePerMeter; - Units = Enum.GetValues(typeof(MagnetizationUnit)).Cast().ToArray(); - Zero = new Magnetization(0, BaseUnit); - Info = new QuantityInfo("Magnetization", - new UnitInfo[] - { - new UnitInfo(MagnetizationUnit.AmperePerMeter, "AmperesPerMeter", new BaseUnits(length: LengthUnit.Meter, current: ElectricCurrentUnit.Ampere), "Magnetization"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MagnetizationInfo(string name, MagnetizationUnit baseUnit, IEnumerable> unitMappings, Magnetization zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MagnetizationInfo(string name, MagnetizationUnit baseUnit, IEnumerable> unitMappings, Magnetization zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Magnetization.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Magnetization", typeof(Magnetization).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Magnetization quantity. + /// + /// A new instance of the class with the default settings. + public static MagnetizationInfo CreateDefault() + { + return new MagnetizationInfo(nameof(Magnetization), DefaultBaseUnit, GetDefaultMappings(), new Magnetization(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Magnetization quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MagnetizationInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MagnetizationInfo(nameof(Magnetization), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Magnetization(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-1][I]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-1, 0, 0, 1, 0, 0, 0); + + /// + /// The default base unit of Magnetization is AmperePerMeter. All conversions, as defined in the , go via this value. + /// + public static MagnetizationUnit DefaultBaseUnit { get; } = MagnetizationUnit.AmperePerMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Magnetization. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MagnetizationUnit.AmperePerMeter, "AmperePerMeter", "AmperesPerMeter", new BaseUnits(length: LengthUnit.Meter, current: ElectricCurrentUnit.Ampere)); + } + } + + static Magnetization() + { + Info = MagnetizationInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -116,27 +163,27 @@ public Magnetization(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Magnetization, which is AmperePerMeter. All conversions go via this value. /// - public static MagnetizationUnit BaseUnit { get; } + public static MagnetizationUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Magnetization quantity. /// - public static MagnetizationUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit AmperePerMeter. /// - public static Magnetization Zero { get; } + public static Magnetization Zero => Info.Zero; /// public static Magnetization AdditiveIdentity => Zero; @@ -154,7 +201,7 @@ public Magnetization(double value, UnitSystem unitSystem) public MagnetizationUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -172,6 +219,9 @@ public Magnetization(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs index 9ecb3ea89d..307434f2ba 100644 --- a/UnitsNet/GeneratedCode/Quantities/Mass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Mass.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -81,45 +77,96 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MassUnit? _unit; - static Mass() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MassInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 1, 0, 0, 0, 0, 0); - BaseUnit = MassUnit.Kilogram; - Units = Enum.GetValues(typeof(MassUnit)).Cast().ToArray(); - Zero = new Mass(0, BaseUnit); - Info = new QuantityInfo("Mass", - new UnitInfo[] - { - new UnitInfo(MassUnit.Centigram, "Centigrams", new BaseUnits(mass: MassUnit.Centigram), "Mass"), - new UnitInfo(MassUnit.Decagram, "Decagrams", new BaseUnits(mass: MassUnit.Decagram), "Mass"), - new UnitInfo(MassUnit.Decigram, "Decigrams", new BaseUnits(mass: MassUnit.Decigram), "Mass"), - new UnitInfo(MassUnit.EarthMass, "EarthMasses", new BaseUnits(mass: MassUnit.EarthMass), "Mass"), - new UnitInfo(MassUnit.Femtogram, "Femtograms", new BaseUnits(mass: MassUnit.Femtogram), "Mass"), - new UnitInfo(MassUnit.Grain, "Grains", new BaseUnits(mass: MassUnit.Grain), "Mass"), - new UnitInfo(MassUnit.Gram, "Grams", new BaseUnits(mass: MassUnit.Gram), "Mass"), - new UnitInfo(MassUnit.Hectogram, "Hectograms", new BaseUnits(mass: MassUnit.Hectogram), "Mass"), - new UnitInfo(MassUnit.Kilogram, "Kilograms", new BaseUnits(mass: MassUnit.Kilogram), "Mass"), - new UnitInfo(MassUnit.Kilopound, "Kilopounds", new BaseUnits(mass: MassUnit.Kilopound), "Mass"), - new UnitInfo(MassUnit.Kilotonne, "Kilotonnes", new BaseUnits(mass: MassUnit.Kilotonne), "Mass"), - new UnitInfo(MassUnit.LongHundredweight, "LongHundredweight", new BaseUnits(mass: MassUnit.LongHundredweight), "Mass"), - new UnitInfo(MassUnit.LongTon, "LongTons", new BaseUnits(mass: MassUnit.LongTon), "Mass"), - new UnitInfo(MassUnit.Megapound, "Megapounds", new BaseUnits(mass: MassUnit.Megapound), "Mass"), - new UnitInfo(MassUnit.Megatonne, "Megatonnes", new BaseUnits(mass: MassUnit.Megatonne), "Mass"), - new UnitInfo(MassUnit.Microgram, "Micrograms", new BaseUnits(mass: MassUnit.Microgram), "Mass"), - new UnitInfo(MassUnit.Milligram, "Milligrams", new BaseUnits(mass: MassUnit.Milligram), "Mass"), - new UnitInfo(MassUnit.Nanogram, "Nanograms", new BaseUnits(mass: MassUnit.Nanogram), "Mass"), - new UnitInfo(MassUnit.Ounce, "Ounces", new BaseUnits(mass: MassUnit.Ounce), "Mass"), - new UnitInfo(MassUnit.Picogram, "Picograms", new BaseUnits(mass: MassUnit.Picogram), "Mass"), - new UnitInfo(MassUnit.Pound, "Pounds", new BaseUnits(mass: MassUnit.Pound), "Mass"), - new UnitInfo(MassUnit.ShortHundredweight, "ShortHundredweight", new BaseUnits(mass: MassUnit.ShortHundredweight), "Mass"), - new UnitInfo(MassUnit.ShortTon, "ShortTons", new BaseUnits(mass: MassUnit.ShortTon), "Mass"), - new UnitInfo(MassUnit.Slug, "Slugs", new BaseUnits(mass: MassUnit.Slug), "Mass"), - new UnitInfo(MassUnit.SolarMass, "SolarMasses", new BaseUnits(mass: MassUnit.SolarMass), "Mass"), - new UnitInfo(MassUnit.Stone, "Stone", new BaseUnits(mass: MassUnit.Stone), "Mass"), - new UnitInfo(MassUnit.Tonne, "Tonnes", new BaseUnits(mass: MassUnit.Tonne), "Mass"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MassInfo(string name, MassUnit baseUnit, IEnumerable> unitMappings, Mass zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MassInfo(string name, MassUnit baseUnit, IEnumerable> unitMappings, Mass zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Mass.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Mass", typeof(Mass).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Mass quantity. + /// + /// A new instance of the class with the default settings. + public static MassInfo CreateDefault() + { + return new MassInfo(nameof(Mass), DefaultBaseUnit, GetDefaultMappings(), new Mass(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Mass quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MassInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MassInfo(nameof(Mass), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Mass(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 1, 0, 0, 0, 0, 0); + + /// + /// The default base unit of Mass is Kilogram. All conversions, as defined in the , go via this value. + /// + public static MassUnit DefaultBaseUnit { get; } = MassUnit.Kilogram; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Mass. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MassUnit.Centigram, "Centigram", "Centigrams", new BaseUnits(mass: MassUnit.Centigram)); + yield return new (MassUnit.Decagram, "Decagram", "Decagrams", new BaseUnits(mass: MassUnit.Decagram)); + yield return new (MassUnit.Decigram, "Decigram", "Decigrams", new BaseUnits(mass: MassUnit.Decigram)); + yield return new (MassUnit.EarthMass, "EarthMass", "EarthMasses", new BaseUnits(mass: MassUnit.EarthMass)); + yield return new (MassUnit.Femtogram, "Femtogram", "Femtograms", new BaseUnits(mass: MassUnit.Femtogram)); + yield return new (MassUnit.Grain, "Grain", "Grains", new BaseUnits(mass: MassUnit.Grain)); + yield return new (MassUnit.Gram, "Gram", "Grams", new BaseUnits(mass: MassUnit.Gram)); + yield return new (MassUnit.Hectogram, "Hectogram", "Hectograms", new BaseUnits(mass: MassUnit.Hectogram)); + yield return new (MassUnit.Kilogram, "Kilogram", "Kilograms", new BaseUnits(mass: MassUnit.Kilogram)); + yield return new (MassUnit.Kilopound, "Kilopound", "Kilopounds", new BaseUnits(mass: MassUnit.Kilopound)); + yield return new (MassUnit.Kilotonne, "Kilotonne", "Kilotonnes", new BaseUnits(mass: MassUnit.Kilotonne)); + yield return new (MassUnit.LongHundredweight, "LongHundredweight", "LongHundredweight", new BaseUnits(mass: MassUnit.LongHundredweight)); + yield return new (MassUnit.LongTon, "LongTon", "LongTons", new BaseUnits(mass: MassUnit.LongTon)); + yield return new (MassUnit.Megapound, "Megapound", "Megapounds", new BaseUnits(mass: MassUnit.Megapound)); + yield return new (MassUnit.Megatonne, "Megatonne", "Megatonnes", new BaseUnits(mass: MassUnit.Megatonne)); + yield return new (MassUnit.Microgram, "Microgram", "Micrograms", new BaseUnits(mass: MassUnit.Microgram)); + yield return new (MassUnit.Milligram, "Milligram", "Milligrams", new BaseUnits(mass: MassUnit.Milligram)); + yield return new (MassUnit.Nanogram, "Nanogram", "Nanograms", new BaseUnits(mass: MassUnit.Nanogram)); + yield return new (MassUnit.Ounce, "Ounce", "Ounces", new BaseUnits(mass: MassUnit.Ounce)); + yield return new (MassUnit.Picogram, "Picogram", "Picograms", new BaseUnits(mass: MassUnit.Picogram)); + yield return new (MassUnit.Pound, "Pound", "Pounds", new BaseUnits(mass: MassUnit.Pound)); + yield return new (MassUnit.ShortHundredweight, "ShortHundredweight", "ShortHundredweight", new BaseUnits(mass: MassUnit.ShortHundredweight)); + yield return new (MassUnit.ShortTon, "ShortTon", "ShortTons", new BaseUnits(mass: MassUnit.ShortTon)); + yield return new (MassUnit.Slug, "Slug", "Slugs", new BaseUnits(mass: MassUnit.Slug)); + yield return new (MassUnit.SolarMass, "SolarMass", "SolarMasses", new BaseUnits(mass: MassUnit.SolarMass)); + yield return new (MassUnit.Stone, "Stone", "Stone", new BaseUnits(mass: MassUnit.Stone)); + yield return new (MassUnit.Tonne, "Tonne", "Tonnes", new BaseUnits(mass: MassUnit.Tonne)); + } + } + + static Mass() + { + Info = MassInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -157,27 +204,27 @@ public Mass(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Mass, which is Kilogram. All conversions go via this value. /// - public static MassUnit BaseUnit { get; } + public static MassUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Mass quantity. /// - public static MassUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Kilogram. /// - public static Mass Zero { get; } + public static Mass Zero => Info.Zero; /// public static Mass AdditiveIdentity => Zero; @@ -195,7 +242,7 @@ public Mass(double value, UnitSystem unitSystem) public MassUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -213,6 +260,9 @@ public Mass(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs index 057487a995..c2f4737479 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassConcentration.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -73,67 +69,118 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MassConcentrationUnit? _unit; - static MassConcentration() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MassConcentrationInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-3, 1, 0, 0, 0, 0, 0); - BaseUnit = MassConcentrationUnit.KilogramPerCubicMeter; - Units = Enum.GetValues(typeof(MassConcentrationUnit)).Cast().ToArray(); - Zero = new MassConcentration(0, BaseUnit); - Info = new QuantityInfo("MassConcentration", - new UnitInfo[] - { - new UnitInfo(MassConcentrationUnit.CentigramPerDeciliter, "CentigramsPerDeciliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.CentigramPerLiter, "CentigramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Centigram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.CentigramPerMicroliter, "CentigramsPerMicroliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.CentigramPerMilliliter, "CentigramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Centigram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.DecigramPerDeciliter, "DecigramsPerDeciliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.DecigramPerLiter, "DecigramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Decigram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.DecigramPerMicroliter, "DecigramsPerMicroliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.DecigramPerMilliliter, "DecigramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Decigram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.GramPerCubicCentimeter, "GramsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.GramPerCubicMeter, "GramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.GramPerCubicMillimeter, "GramsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.GramPerDeciliter, "GramsPerDeciliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.GramPerLiter, "GramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.GramPerMicroliter, "GramsPerMicroliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.GramPerMilliliter, "GramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.KilogramPerCubicCentimeter, "KilogramsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.KilogramPerCubicMeter, "KilogramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.KilogramPerCubicMillimeter, "KilogramsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.KilogramPerLiter, "KilogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.KilopoundPerCubicFoot, "KilopoundsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Kilopound), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.KilopoundPerCubicInch, "KilopoundsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Kilopound), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.MicrogramPerCubicMeter, "MicrogramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.MicrogramPerDeciliter, "MicrogramsPerDeciliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.MicrogramPerLiter, "MicrogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Microgram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.MicrogramPerMicroliter, "MicrogramsPerMicroliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.MicrogramPerMilliliter, "MicrogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Microgram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.MilligramPerCubicMeter, "MilligramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.MilligramPerDeciliter, "MilligramsPerDeciliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.MilligramPerLiter, "MilligramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Milligram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.MilligramPerMicroliter, "MilligramsPerMicroliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.MilligramPerMilliliter, "MilligramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Milligram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.NanogramPerDeciliter, "NanogramsPerDeciliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.NanogramPerLiter, "NanogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Nanogram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.NanogramPerMicroliter, "NanogramsPerMicroliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.NanogramPerMilliliter, "NanogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Nanogram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.OuncePerImperialGallon, "OuncesPerImperialGallon", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.OuncePerUSGallon, "OuncesPerUSGallon", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.PicogramPerDeciliter, "PicogramsPerDeciliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.PicogramPerLiter, "PicogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Picogram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.PicogramPerMicroliter, "PicogramsPerMicroliter", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.PicogramPerMilliliter, "PicogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Picogram), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.PoundPerCubicFoot, "PoundsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.PoundPerCubicInch, "PoundsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.PoundPerImperialGallon, "PoundsPerImperialGallon", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.PoundPerUSGallon, "PoundsPerUSGallon", BaseUnits.Undefined, "MassConcentration"), - new UnitInfo(MassConcentrationUnit.SlugPerCubicFoot, "SlugsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.TonnePerCubicCentimeter, "TonnesPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Tonne), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.TonnePerCubicMeter, "TonnesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Tonne), "MassConcentration"), - new UnitInfo(MassConcentrationUnit.TonnePerCubicMillimeter, "TonnesPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Tonne), "MassConcentration"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MassConcentrationInfo(string name, MassConcentrationUnit baseUnit, IEnumerable> unitMappings, MassConcentration zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MassConcentrationInfo(string name, MassConcentrationUnit baseUnit, IEnumerable> unitMappings, MassConcentration zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, MassConcentration.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.MassConcentration", typeof(MassConcentration).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the MassConcentration quantity. + /// + /// A new instance of the class with the default settings. + public static MassConcentrationInfo CreateDefault() + { + return new MassConcentrationInfo(nameof(MassConcentration), DefaultBaseUnit, GetDefaultMappings(), new MassConcentration(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the MassConcentration quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MassConcentrationInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MassConcentrationInfo(nameof(MassConcentration), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new MassConcentration(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-3][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-3, 1, 0, 0, 0, 0, 0); + + /// + /// The default base unit of MassConcentration is KilogramPerCubicMeter. All conversions, as defined in the , go via this value. + /// + public static MassConcentrationUnit DefaultBaseUnit { get; } = MassConcentrationUnit.KilogramPerCubicMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for MassConcentration. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MassConcentrationUnit.CentigramPerDeciliter, "CentigramPerDeciliter", "CentigramsPerDeciliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.CentigramPerLiter, "CentigramPerLiter", "CentigramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Centigram)); + yield return new (MassConcentrationUnit.CentigramPerMicroliter, "CentigramPerMicroliter", "CentigramsPerMicroliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.CentigramPerMilliliter, "CentigramPerMilliliter", "CentigramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Centigram)); + yield return new (MassConcentrationUnit.DecigramPerDeciliter, "DecigramPerDeciliter", "DecigramsPerDeciliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.DecigramPerLiter, "DecigramPerLiter", "DecigramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Decigram)); + yield return new (MassConcentrationUnit.DecigramPerMicroliter, "DecigramPerMicroliter", "DecigramsPerMicroliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.DecigramPerMilliliter, "DecigramPerMilliliter", "DecigramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Decigram)); + yield return new (MassConcentrationUnit.GramPerCubicCentimeter, "GramPerCubicCentimeter", "GramsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)); + yield return new (MassConcentrationUnit.GramPerCubicMeter, "GramPerCubicMeter", "GramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram)); + yield return new (MassConcentrationUnit.GramPerCubicMillimeter, "GramPerCubicMillimeter", "GramsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram)); + yield return new (MassConcentrationUnit.GramPerDeciliter, "GramPerDeciliter", "GramsPerDeciliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.GramPerLiter, "GramPerLiter", "GramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram)); + yield return new (MassConcentrationUnit.GramPerMicroliter, "GramPerMicroliter", "GramsPerMicroliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.GramPerMilliliter, "GramPerMilliliter", "GramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)); + yield return new (MassConcentrationUnit.KilogramPerCubicCentimeter, "KilogramPerCubicCentimeter", "KilogramsPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram)); + yield return new (MassConcentrationUnit.KilogramPerCubicMeter, "KilogramPerCubicMeter", "KilogramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)); + yield return new (MassConcentrationUnit.KilogramPerCubicMillimeter, "KilogramPerCubicMillimeter", "KilogramsPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram)); + yield return new (MassConcentrationUnit.KilogramPerLiter, "KilogramPerLiter", "KilogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram)); + yield return new (MassConcentrationUnit.KilopoundPerCubicFoot, "KilopoundPerCubicFoot", "KilopoundsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Kilopound)); + yield return new (MassConcentrationUnit.KilopoundPerCubicInch, "KilopoundPerCubicInch", "KilopoundsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Kilopound)); + yield return new (MassConcentrationUnit.MicrogramPerCubicMeter, "MicrogramPerCubicMeter", "MicrogramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram)); + yield return new (MassConcentrationUnit.MicrogramPerDeciliter, "MicrogramPerDeciliter", "MicrogramsPerDeciliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.MicrogramPerLiter, "MicrogramPerLiter", "MicrogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Microgram)); + yield return new (MassConcentrationUnit.MicrogramPerMicroliter, "MicrogramPerMicroliter", "MicrogramsPerMicroliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.MicrogramPerMilliliter, "MicrogramPerMilliliter", "MicrogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Microgram)); + yield return new (MassConcentrationUnit.MilligramPerCubicMeter, "MilligramPerCubicMeter", "MilligramsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram)); + yield return new (MassConcentrationUnit.MilligramPerDeciliter, "MilligramPerDeciliter", "MilligramsPerDeciliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.MilligramPerLiter, "MilligramPerLiter", "MilligramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Milligram)); + yield return new (MassConcentrationUnit.MilligramPerMicroliter, "MilligramPerMicroliter", "MilligramsPerMicroliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.MilligramPerMilliliter, "MilligramPerMilliliter", "MilligramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Milligram)); + yield return new (MassConcentrationUnit.NanogramPerDeciliter, "NanogramPerDeciliter", "NanogramsPerDeciliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.NanogramPerLiter, "NanogramPerLiter", "NanogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Nanogram)); + yield return new (MassConcentrationUnit.NanogramPerMicroliter, "NanogramPerMicroliter", "NanogramsPerMicroliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.NanogramPerMilliliter, "NanogramPerMilliliter", "NanogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Nanogram)); + yield return new (MassConcentrationUnit.OuncePerImperialGallon, "OuncePerImperialGallon", "OuncesPerImperialGallon", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.OuncePerUSGallon, "OuncePerUSGallon", "OuncesPerUSGallon", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.PicogramPerDeciliter, "PicogramPerDeciliter", "PicogramsPerDeciliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.PicogramPerLiter, "PicogramPerLiter", "PicogramsPerLiter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Picogram)); + yield return new (MassConcentrationUnit.PicogramPerMicroliter, "PicogramPerMicroliter", "PicogramsPerMicroliter", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.PicogramPerMilliliter, "PicogramPerMilliliter", "PicogramsPerMilliliter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Picogram)); + yield return new (MassConcentrationUnit.PoundPerCubicFoot, "PoundPerCubicFoot", "PoundsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound)); + yield return new (MassConcentrationUnit.PoundPerCubicInch, "PoundPerCubicInch", "PoundsPerCubicInch", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound)); + yield return new (MassConcentrationUnit.PoundPerImperialGallon, "PoundPerImperialGallon", "PoundsPerImperialGallon", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.PoundPerUSGallon, "PoundPerUSGallon", "PoundsPerUSGallon", BaseUnits.Undefined); + yield return new (MassConcentrationUnit.SlugPerCubicFoot, "SlugPerCubicFoot", "SlugsPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug)); + yield return new (MassConcentrationUnit.TonnePerCubicCentimeter, "TonnePerCubicCentimeter", "TonnesPerCubicCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Tonne)); + yield return new (MassConcentrationUnit.TonnePerCubicMeter, "TonnePerCubicMeter", "TonnesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Tonne)); + yield return new (MassConcentrationUnit.TonnePerCubicMillimeter, "TonnePerCubicMillimeter", "TonnesPerCubicMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Tonne)); + } + } + + static MassConcentration() + { + Info = MassConcentrationInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -171,27 +218,27 @@ public MassConcentration(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of MassConcentration, which is KilogramPerCubicMeter. All conversions go via this value. /// - public static MassConcentrationUnit BaseUnit { get; } + public static MassConcentrationUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the MassConcentration quantity. /// - public static MassConcentrationUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerCubicMeter. /// - public static MassConcentration Zero { get; } + public static MassConcentration Zero => Info.Zero; /// public static MassConcentration AdditiveIdentity => Zero; @@ -209,7 +256,7 @@ public MassConcentration(double value, UnitSystem unitSystem) public MassConcentrationUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -227,6 +274,9 @@ public MassConcentration(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs index 5ef954faca..1d6d52e9d8 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlow.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -75,51 +71,102 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MassFlowUnit? _unit; - static MassFlow() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MassFlowInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 1, -1, 0, 0, 0, 0); - BaseUnit = MassFlowUnit.GramPerSecond; - Units = Enum.GetValues(typeof(MassFlowUnit)).Cast().ToArray(); - Zero = new MassFlow(0, BaseUnit); - Info = new QuantityInfo("MassFlow", - new UnitInfo[] - { - new UnitInfo(MassFlowUnit.CentigramPerDay, "CentigramsPerDay", new BaseUnits(mass: MassUnit.Centigram, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.CentigramPerSecond, "CentigramsPerSecond", new BaseUnits(mass: MassUnit.Centigram, time: DurationUnit.Second), "MassFlow"), - new UnitInfo(MassFlowUnit.DecagramPerDay, "DecagramsPerDay", new BaseUnits(mass: MassUnit.Decagram, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.DecagramPerSecond, "DecagramsPerSecond", new BaseUnits(mass: MassUnit.Decagram, time: DurationUnit.Second), "MassFlow"), - new UnitInfo(MassFlowUnit.DecigramPerDay, "DecigramsPerDay", new BaseUnits(mass: MassUnit.Decigram, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.DecigramPerSecond, "DecigramsPerSecond", new BaseUnits(mass: MassUnit.Decigram, time: DurationUnit.Second), "MassFlow"), - new UnitInfo(MassFlowUnit.GramPerDay, "GramsPerDay", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.GramPerHour, "GramsPerHour", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Hour), "MassFlow"), - new UnitInfo(MassFlowUnit.GramPerSecond, "GramsPerSecond", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Second), "MassFlow"), - new UnitInfo(MassFlowUnit.HectogramPerDay, "HectogramsPerDay", new BaseUnits(mass: MassUnit.Hectogram, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.HectogramPerSecond, "HectogramsPerSecond", new BaseUnits(mass: MassUnit.Hectogram, time: DurationUnit.Second), "MassFlow"), - new UnitInfo(MassFlowUnit.KilogramPerDay, "KilogramsPerDay", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.KilogramPerHour, "KilogramsPerHour", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Hour), "MassFlow"), - new UnitInfo(MassFlowUnit.KilogramPerMinute, "KilogramsPerMinute", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Minute), "MassFlow"), - new UnitInfo(MassFlowUnit.KilogramPerSecond, "KilogramsPerSecond", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second), "MassFlow"), - new UnitInfo(MassFlowUnit.MegagramPerDay, "MegagramsPerDay", BaseUnits.Undefined, "MassFlow"), - new UnitInfo(MassFlowUnit.MegapoundPerDay, "MegapoundsPerDay", new BaseUnits(mass: MassUnit.Megapound, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.MegapoundPerHour, "MegapoundsPerHour", new BaseUnits(mass: MassUnit.Megapound, time: DurationUnit.Hour), "MassFlow"), - new UnitInfo(MassFlowUnit.MegapoundPerMinute, "MegapoundsPerMinute", new BaseUnits(mass: MassUnit.Megapound, time: DurationUnit.Minute), "MassFlow"), - new UnitInfo(MassFlowUnit.MegapoundPerSecond, "MegapoundsPerSecond", new BaseUnits(mass: MassUnit.Megapound, time: DurationUnit.Second), "MassFlow"), - new UnitInfo(MassFlowUnit.MicrogramPerDay, "MicrogramsPerDay", new BaseUnits(mass: MassUnit.Microgram, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.MicrogramPerSecond, "MicrogramsPerSecond", new BaseUnits(mass: MassUnit.Microgram, time: DurationUnit.Second), "MassFlow"), - new UnitInfo(MassFlowUnit.MilligramPerDay, "MilligramsPerDay", new BaseUnits(mass: MassUnit.Milligram, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.MilligramPerSecond, "MilligramsPerSecond", new BaseUnits(mass: MassUnit.Milligram, time: DurationUnit.Second), "MassFlow"), - new UnitInfo(MassFlowUnit.NanogramPerDay, "NanogramsPerDay", new BaseUnits(mass: MassUnit.Nanogram, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.NanogramPerSecond, "NanogramsPerSecond", new BaseUnits(mass: MassUnit.Nanogram, time: DurationUnit.Second), "MassFlow"), - new UnitInfo(MassFlowUnit.PoundPerDay, "PoundsPerDay", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.PoundPerHour, "PoundsPerHour", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Hour), "MassFlow"), - new UnitInfo(MassFlowUnit.PoundPerMinute, "PoundsPerMinute", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Minute), "MassFlow"), - new UnitInfo(MassFlowUnit.PoundPerSecond, "PoundsPerSecond", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Second), "MassFlow"), - new UnitInfo(MassFlowUnit.ShortTonPerHour, "ShortTonsPerHour", new BaseUnits(mass: MassUnit.ShortTon, time: DurationUnit.Hour), "MassFlow"), - new UnitInfo(MassFlowUnit.TonnePerDay, "TonnesPerDay", new BaseUnits(mass: MassUnit.Tonne, time: DurationUnit.Day), "MassFlow"), - new UnitInfo(MassFlowUnit.TonnePerHour, "TonnesPerHour", new BaseUnits(mass: MassUnit.Tonne, time: DurationUnit.Hour), "MassFlow"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MassFlowInfo(string name, MassFlowUnit baseUnit, IEnumerable> unitMappings, MassFlow zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MassFlowInfo(string name, MassFlowUnit baseUnit, IEnumerable> unitMappings, MassFlow zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, MassFlow.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.MassFlow", typeof(MassFlow).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the MassFlow quantity. + /// + /// A new instance of the class with the default settings. + public static MassFlowInfo CreateDefault() + { + return new MassFlowInfo(nameof(MassFlow), DefaultBaseUnit, GetDefaultMappings(), new MassFlow(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the MassFlow quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MassFlowInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MassFlowInfo(nameof(MassFlow), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new MassFlow(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 1, -1, 0, 0, 0, 0); + + /// + /// The default base unit of MassFlow is GramPerSecond. All conversions, as defined in the , go via this value. + /// + public static MassFlowUnit DefaultBaseUnit { get; } = MassFlowUnit.GramPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for MassFlow. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MassFlowUnit.CentigramPerDay, "CentigramPerDay", "CentigramsPerDay", new BaseUnits(mass: MassUnit.Centigram, time: DurationUnit.Day)); + yield return new (MassFlowUnit.CentigramPerSecond, "CentigramPerSecond", "CentigramsPerSecond", new BaseUnits(mass: MassUnit.Centigram, time: DurationUnit.Second)); + yield return new (MassFlowUnit.DecagramPerDay, "DecagramPerDay", "DecagramsPerDay", new BaseUnits(mass: MassUnit.Decagram, time: DurationUnit.Day)); + yield return new (MassFlowUnit.DecagramPerSecond, "DecagramPerSecond", "DecagramsPerSecond", new BaseUnits(mass: MassUnit.Decagram, time: DurationUnit.Second)); + yield return new (MassFlowUnit.DecigramPerDay, "DecigramPerDay", "DecigramsPerDay", new BaseUnits(mass: MassUnit.Decigram, time: DurationUnit.Day)); + yield return new (MassFlowUnit.DecigramPerSecond, "DecigramPerSecond", "DecigramsPerSecond", new BaseUnits(mass: MassUnit.Decigram, time: DurationUnit.Second)); + yield return new (MassFlowUnit.GramPerDay, "GramPerDay", "GramsPerDay", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Day)); + yield return new (MassFlowUnit.GramPerHour, "GramPerHour", "GramsPerHour", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Hour)); + yield return new (MassFlowUnit.GramPerSecond, "GramPerSecond", "GramsPerSecond", new BaseUnits(mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (MassFlowUnit.HectogramPerDay, "HectogramPerDay", "HectogramsPerDay", new BaseUnits(mass: MassUnit.Hectogram, time: DurationUnit.Day)); + yield return new (MassFlowUnit.HectogramPerSecond, "HectogramPerSecond", "HectogramsPerSecond", new BaseUnits(mass: MassUnit.Hectogram, time: DurationUnit.Second)); + yield return new (MassFlowUnit.KilogramPerDay, "KilogramPerDay", "KilogramsPerDay", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Day)); + yield return new (MassFlowUnit.KilogramPerHour, "KilogramPerHour", "KilogramsPerHour", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Hour)); + yield return new (MassFlowUnit.KilogramPerMinute, "KilogramPerMinute", "KilogramsPerMinute", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Minute)); + yield return new (MassFlowUnit.KilogramPerSecond, "KilogramPerSecond", "KilogramsPerSecond", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (MassFlowUnit.MegagramPerDay, "MegagramPerDay", "MegagramsPerDay", BaseUnits.Undefined); + yield return new (MassFlowUnit.MegapoundPerDay, "MegapoundPerDay", "MegapoundsPerDay", new BaseUnits(mass: MassUnit.Megapound, time: DurationUnit.Day)); + yield return new (MassFlowUnit.MegapoundPerHour, "MegapoundPerHour", "MegapoundsPerHour", new BaseUnits(mass: MassUnit.Megapound, time: DurationUnit.Hour)); + yield return new (MassFlowUnit.MegapoundPerMinute, "MegapoundPerMinute", "MegapoundsPerMinute", new BaseUnits(mass: MassUnit.Megapound, time: DurationUnit.Minute)); + yield return new (MassFlowUnit.MegapoundPerSecond, "MegapoundPerSecond", "MegapoundsPerSecond", new BaseUnits(mass: MassUnit.Megapound, time: DurationUnit.Second)); + yield return new (MassFlowUnit.MicrogramPerDay, "MicrogramPerDay", "MicrogramsPerDay", new BaseUnits(mass: MassUnit.Microgram, time: DurationUnit.Day)); + yield return new (MassFlowUnit.MicrogramPerSecond, "MicrogramPerSecond", "MicrogramsPerSecond", new BaseUnits(mass: MassUnit.Microgram, time: DurationUnit.Second)); + yield return new (MassFlowUnit.MilligramPerDay, "MilligramPerDay", "MilligramsPerDay", new BaseUnits(mass: MassUnit.Milligram, time: DurationUnit.Day)); + yield return new (MassFlowUnit.MilligramPerSecond, "MilligramPerSecond", "MilligramsPerSecond", new BaseUnits(mass: MassUnit.Milligram, time: DurationUnit.Second)); + yield return new (MassFlowUnit.NanogramPerDay, "NanogramPerDay", "NanogramsPerDay", new BaseUnits(mass: MassUnit.Nanogram, time: DurationUnit.Day)); + yield return new (MassFlowUnit.NanogramPerSecond, "NanogramPerSecond", "NanogramsPerSecond", new BaseUnits(mass: MassUnit.Nanogram, time: DurationUnit.Second)); + yield return new (MassFlowUnit.PoundPerDay, "PoundPerDay", "PoundsPerDay", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Day)); + yield return new (MassFlowUnit.PoundPerHour, "PoundPerHour", "PoundsPerHour", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Hour)); + yield return new (MassFlowUnit.PoundPerMinute, "PoundPerMinute", "PoundsPerMinute", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Minute)); + yield return new (MassFlowUnit.PoundPerSecond, "PoundPerSecond", "PoundsPerSecond", new BaseUnits(mass: MassUnit.Pound, time: DurationUnit.Second)); + yield return new (MassFlowUnit.ShortTonPerHour, "ShortTonPerHour", "ShortTonsPerHour", new BaseUnits(mass: MassUnit.ShortTon, time: DurationUnit.Hour)); + yield return new (MassFlowUnit.TonnePerDay, "TonnePerDay", "TonnesPerDay", new BaseUnits(mass: MassUnit.Tonne, time: DurationUnit.Day)); + yield return new (MassFlowUnit.TonnePerHour, "TonnePerHour", "TonnesPerHour", new BaseUnits(mass: MassUnit.Tonne, time: DurationUnit.Hour)); + } + } + + static MassFlow() + { + Info = MassFlowInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -157,27 +204,27 @@ public MassFlow(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of MassFlow, which is GramPerSecond. All conversions go via this value. /// - public static MassFlowUnit BaseUnit { get; } + public static MassFlowUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the MassFlow quantity. /// - public static MassFlowUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit GramPerSecond. /// - public static MassFlow Zero { get; } + public static MassFlow Zero => Info.Zero; /// public static MassFlow AdditiveIdentity => Zero; @@ -195,7 +242,7 @@ public MassFlow(double value, UnitSystem unitSystem) public MassFlowUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -213,6 +260,9 @@ public MassFlow(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs index 2585ae1f64..39a94967e9 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFlux.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -68,30 +64,81 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MassFluxUnit? _unit; - static MassFlux() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MassFluxInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, 1, -1, 0, 0, 0, 0); - BaseUnit = MassFluxUnit.KilogramPerSecondPerSquareMeter; - Units = Enum.GetValues(typeof(MassFluxUnit)).Cast().ToArray(); - Zero = new MassFlux(0, BaseUnit); - Info = new QuantityInfo("MassFlux", - new UnitInfo[] - { - new UnitInfo(MassFluxUnit.GramPerHourPerSquareCentimeter, "GramsPerHourPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram, time: DurationUnit.Hour), "MassFlux"), - new UnitInfo(MassFluxUnit.GramPerHourPerSquareMeter, "GramsPerHourPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Hour), "MassFlux"), - new UnitInfo(MassFluxUnit.GramPerHourPerSquareMillimeter, "GramsPerHourPerSquareMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram, time: DurationUnit.Hour), "MassFlux"), - new UnitInfo(MassFluxUnit.GramPerSecondPerSquareCentimeter, "GramsPerSecondPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram, time: DurationUnit.Second), "MassFlux"), - new UnitInfo(MassFluxUnit.GramPerSecondPerSquareMeter, "GramsPerSecondPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second), "MassFlux"), - new UnitInfo(MassFluxUnit.GramPerSecondPerSquareMillimeter, "GramsPerSecondPerSquareMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram, time: DurationUnit.Second), "MassFlux"), - new UnitInfo(MassFluxUnit.KilogramPerHourPerSquareCentimeter, "KilogramsPerHourPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram, time: DurationUnit.Hour), "MassFlux"), - new UnitInfo(MassFluxUnit.KilogramPerHourPerSquareMeter, "KilogramsPerHourPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Hour), "MassFlux"), - new UnitInfo(MassFluxUnit.KilogramPerHourPerSquareMillimeter, "KilogramsPerHourPerSquareMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Hour), "MassFlux"), - new UnitInfo(MassFluxUnit.KilogramPerSecondPerSquareCentimeter, "KilogramsPerSecondPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "MassFlux"), - new UnitInfo(MassFluxUnit.KilogramPerSecondPerSquareMeter, "KilogramsPerSecondPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "MassFlux"), - new UnitInfo(MassFluxUnit.KilogramPerSecondPerSquareMillimeter, "KilogramsPerSecondPerSquareMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "MassFlux"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MassFluxInfo(string name, MassFluxUnit baseUnit, IEnumerable> unitMappings, MassFlux zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MassFluxInfo(string name, MassFluxUnit baseUnit, IEnumerable> unitMappings, MassFlux zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, MassFlux.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.MassFlux", typeof(MassFlux).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the MassFlux quantity. + /// + /// A new instance of the class with the default settings. + public static MassFluxInfo CreateDefault() + { + return new MassFluxInfo(nameof(MassFlux), DefaultBaseUnit, GetDefaultMappings(), new MassFlux(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the MassFlux quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MassFluxInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MassFluxInfo(nameof(MassFlux), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new MassFlux(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][L^-2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, 1, -1, 0, 0, 0, 0); + + /// + /// The default base unit of MassFlux is KilogramPerSecondPerSquareMeter. All conversions, as defined in the , go via this value. + /// + public static MassFluxUnit DefaultBaseUnit { get; } = MassFluxUnit.KilogramPerSecondPerSquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for MassFlux. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MassFluxUnit.GramPerHourPerSquareCentimeter, "GramPerHourPerSquareCentimeter", "GramsPerHourPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram, time: DurationUnit.Hour)); + yield return new (MassFluxUnit.GramPerHourPerSquareMeter, "GramPerHourPerSquareMeter", "GramsPerHourPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Hour)); + yield return new (MassFluxUnit.GramPerHourPerSquareMillimeter, "GramPerHourPerSquareMillimeter", "GramsPerHourPerSquareMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram, time: DurationUnit.Hour)); + yield return new (MassFluxUnit.GramPerSecondPerSquareCentimeter, "GramPerSecondPerSquareCentimeter", "GramsPerSecondPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (MassFluxUnit.GramPerSecondPerSquareMeter, "GramPerSecondPerSquareMeter", "GramsPerSecondPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (MassFluxUnit.GramPerSecondPerSquareMillimeter, "GramPerSecondPerSquareMillimeter", "GramsPerSecondPerSquareMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (MassFluxUnit.KilogramPerHourPerSquareCentimeter, "KilogramPerHourPerSquareCentimeter", "KilogramsPerHourPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram, time: DurationUnit.Hour)); + yield return new (MassFluxUnit.KilogramPerHourPerSquareMeter, "KilogramPerHourPerSquareMeter", "KilogramsPerHourPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Hour)); + yield return new (MassFluxUnit.KilogramPerHourPerSquareMillimeter, "KilogramPerHourPerSquareMillimeter", "KilogramsPerHourPerSquareMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Hour)); + yield return new (MassFluxUnit.KilogramPerSecondPerSquareCentimeter, "KilogramPerSecondPerSquareCentimeter", "KilogramsPerSecondPerSquareCentimeter", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (MassFluxUnit.KilogramPerSecondPerSquareMeter, "KilogramPerSecondPerSquareMeter", "KilogramsPerSecondPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (MassFluxUnit.KilogramPerSecondPerSquareMillimeter, "KilogramPerSecondPerSquareMillimeter", "KilogramsPerSecondPerSquareMillimeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + } + } + + static MassFlux() + { + Info = MassFluxInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -129,27 +176,27 @@ public MassFlux(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of MassFlux, which is KilogramPerSecondPerSquareMeter. All conversions go via this value. /// - public static MassFluxUnit BaseUnit { get; } + public static MassFluxUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the MassFlux quantity. /// - public static MassFluxUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerSecondPerSquareMeter. /// - public static MassFlux Zero { get; } + public static MassFlux Zero => Info.Zero; /// public static MassFlux AdditiveIdentity => Zero; @@ -167,7 +214,7 @@ public MassFlux(double value, UnitSystem unitSystem) public MassFluxUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -185,6 +232,9 @@ public MassFlux(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs b/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs index 7049f5d0c7..0702762b71 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassFraction.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -69,42 +65,93 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MassFractionUnit? _unit; - static MassFraction() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MassFractionInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = MassFractionUnit.DecimalFraction; - Units = Enum.GetValues(typeof(MassFractionUnit)).Cast().ToArray(); - Zero = new MassFraction(0, BaseUnit); - Info = new QuantityInfo("MassFraction", - new UnitInfo[] - { - new UnitInfo(MassFractionUnit.CentigramPerGram, "CentigramsPerGram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.CentigramPerKilogram, "CentigramsPerKilogram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.DecagramPerGram, "DecagramsPerGram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.DecagramPerKilogram, "DecagramsPerKilogram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.DecigramPerGram, "DecigramsPerGram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.DecigramPerKilogram, "DecigramsPerKilogram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.DecimalFraction, "DecimalFractions", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.GramPerGram, "GramsPerGram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.GramPerKilogram, "GramsPerKilogram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.HectogramPerGram, "HectogramsPerGram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.HectogramPerKilogram, "HectogramsPerKilogram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.KilogramPerGram, "KilogramsPerGram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.KilogramPerKilogram, "KilogramsPerKilogram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.MicrogramPerGram, "MicrogramsPerGram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.MicrogramPerKilogram, "MicrogramsPerKilogram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.MilligramPerGram, "MilligramsPerGram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.MilligramPerKilogram, "MilligramsPerKilogram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.NanogramPerGram, "NanogramsPerGram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.NanogramPerKilogram, "NanogramsPerKilogram", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.PartPerBillion, "PartsPerBillion", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.PartPerMillion, "PartsPerMillion", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.PartPerThousand, "PartsPerThousand", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.PartPerTrillion, "PartsPerTrillion", BaseUnits.Undefined, "MassFraction"), - new UnitInfo(MassFractionUnit.Percent, "Percent", BaseUnits.Undefined, "MassFraction"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MassFractionInfo(string name, MassFractionUnit baseUnit, IEnumerable> unitMappings, MassFraction zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MassFractionInfo(string name, MassFractionUnit baseUnit, IEnumerable> unitMappings, MassFraction zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, MassFraction.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.MassFraction", typeof(MassFraction).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the MassFraction quantity. + /// + /// A new instance of the class with the default settings. + public static MassFractionInfo CreateDefault() + { + return new MassFractionInfo(nameof(MassFraction), DefaultBaseUnit, GetDefaultMappings(), new MassFraction(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the MassFraction quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MassFractionInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MassFractionInfo(nameof(MassFraction), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new MassFraction(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of MassFraction is DecimalFraction. All conversions, as defined in the , go via this value. + /// + public static MassFractionUnit DefaultBaseUnit { get; } = MassFractionUnit.DecimalFraction; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for MassFraction. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MassFractionUnit.CentigramPerGram, "CentigramPerGram", "CentigramsPerGram", BaseUnits.Undefined); + yield return new (MassFractionUnit.CentigramPerKilogram, "CentigramPerKilogram", "CentigramsPerKilogram", BaseUnits.Undefined); + yield return new (MassFractionUnit.DecagramPerGram, "DecagramPerGram", "DecagramsPerGram", BaseUnits.Undefined); + yield return new (MassFractionUnit.DecagramPerKilogram, "DecagramPerKilogram", "DecagramsPerKilogram", BaseUnits.Undefined); + yield return new (MassFractionUnit.DecigramPerGram, "DecigramPerGram", "DecigramsPerGram", BaseUnits.Undefined); + yield return new (MassFractionUnit.DecigramPerKilogram, "DecigramPerKilogram", "DecigramsPerKilogram", BaseUnits.Undefined); + yield return new (MassFractionUnit.DecimalFraction, "DecimalFraction", "DecimalFractions", BaseUnits.Undefined); + yield return new (MassFractionUnit.GramPerGram, "GramPerGram", "GramsPerGram", BaseUnits.Undefined); + yield return new (MassFractionUnit.GramPerKilogram, "GramPerKilogram", "GramsPerKilogram", BaseUnits.Undefined); + yield return new (MassFractionUnit.HectogramPerGram, "HectogramPerGram", "HectogramsPerGram", BaseUnits.Undefined); + yield return new (MassFractionUnit.HectogramPerKilogram, "HectogramPerKilogram", "HectogramsPerKilogram", BaseUnits.Undefined); + yield return new (MassFractionUnit.KilogramPerGram, "KilogramPerGram", "KilogramsPerGram", BaseUnits.Undefined); + yield return new (MassFractionUnit.KilogramPerKilogram, "KilogramPerKilogram", "KilogramsPerKilogram", BaseUnits.Undefined); + yield return new (MassFractionUnit.MicrogramPerGram, "MicrogramPerGram", "MicrogramsPerGram", BaseUnits.Undefined); + yield return new (MassFractionUnit.MicrogramPerKilogram, "MicrogramPerKilogram", "MicrogramsPerKilogram", BaseUnits.Undefined); + yield return new (MassFractionUnit.MilligramPerGram, "MilligramPerGram", "MilligramsPerGram", BaseUnits.Undefined); + yield return new (MassFractionUnit.MilligramPerKilogram, "MilligramPerKilogram", "MilligramsPerKilogram", BaseUnits.Undefined); + yield return new (MassFractionUnit.NanogramPerGram, "NanogramPerGram", "NanogramsPerGram", BaseUnits.Undefined); + yield return new (MassFractionUnit.NanogramPerKilogram, "NanogramPerKilogram", "NanogramsPerKilogram", BaseUnits.Undefined); + yield return new (MassFractionUnit.PartPerBillion, "PartPerBillion", "PartsPerBillion", BaseUnits.Undefined); + yield return new (MassFractionUnit.PartPerMillion, "PartPerMillion", "PartsPerMillion", BaseUnits.Undefined); + yield return new (MassFractionUnit.PartPerThousand, "PartPerThousand", "PartsPerThousand", BaseUnits.Undefined); + yield return new (MassFractionUnit.PartPerTrillion, "PartPerTrillion", "PartsPerTrillion", BaseUnits.Undefined); + yield return new (MassFractionUnit.Percent, "Percent", "Percent", BaseUnits.Undefined); + } + } + + static MassFraction() + { + Info = MassFractionInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -128,27 +175,27 @@ public MassFraction(double value, MassFractionUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of MassFraction, which is DecimalFraction. All conversions go via this value. /// - public static MassFractionUnit BaseUnit { get; } + public static MassFractionUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the MassFraction quantity. /// - public static MassFractionUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit DecimalFraction. /// - public static MassFraction Zero { get; } + public static MassFraction Zero => Info.Zero; /// public static MassFraction AdditiveIdentity => Zero; @@ -166,7 +213,7 @@ public MassFraction(double value, MassFractionUnit unit) public MassFractionUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -184,6 +231,9 @@ public MassFraction(double value, MassFractionUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs index acd8dd86ba..f16d35f03d 100644 --- a/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MassMomentOfInertia.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,46 +59,97 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MassMomentOfInertiaUnit? _unit; - static MassMomentOfInertia() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MassMomentOfInertiaInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, 0, 0, 0, 0, 0); - BaseUnit = MassMomentOfInertiaUnit.KilogramSquareMeter; - Units = Enum.GetValues(typeof(MassMomentOfInertiaUnit)).Cast().ToArray(); - Zero = new MassMomentOfInertia(0, BaseUnit); - Info = new QuantityInfo("MassMomentOfInertia", - new UnitInfo[] - { - new UnitInfo(MassMomentOfInertiaUnit.GramSquareCentimeter, "GramSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.GramSquareDecimeter, "GramSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.GramSquareMeter, "GramSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.GramSquareMillimeter, "GramSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.KilogramSquareCentimeter, "KilogramSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.KilogramSquareDecimeter, "KilogramSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.KilogramSquareMeter, "KilogramSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.KilogramSquareMillimeter, "KilogramSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.KilotonneSquareCentimeter, "KilotonneSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilotonne), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.KilotonneSquareDecimeter, "KilotonneSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilotonne), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.KilotonneSquareMeter, "KilotonneSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilotonne), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.KilotonneSquareMillimeter, "KilotonneSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilotonne), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.MegatonneSquareCentimeter, "MegatonneSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Megatonne), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.MegatonneSquareDecimeter, "MegatonneSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Megatonne), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.MegatonneSquareMeter, "MegatonneSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Megatonne), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.MegatonneSquareMillimeter, "MegatonneSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Megatonne), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.MilligramSquareCentimeter, "MilligramSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Milligram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.MilligramSquareDecimeter, "MilligramSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Milligram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.MilligramSquareMeter, "MilligramSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.MilligramSquareMillimeter, "MilligramSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Milligram), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.PoundSquareFoot, "PoundSquareFeet", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.PoundSquareInch, "PoundSquareInches", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.SlugSquareFoot, "SlugSquareFeet", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.SlugSquareInch, "SlugSquareInches", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Slug), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.TonneSquareCentimeter, "TonneSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Tonne), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.TonneSquareDecimeter, "TonneSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Tonne), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.TonneSquareMeter, "TonneSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Tonne), "MassMomentOfInertia"), - new UnitInfo(MassMomentOfInertiaUnit.TonneSquareMillimeter, "TonneSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Tonne), "MassMomentOfInertia"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MassMomentOfInertiaInfo(string name, MassMomentOfInertiaUnit baseUnit, IEnumerable> unitMappings, MassMomentOfInertia zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MassMomentOfInertiaInfo(string name, MassMomentOfInertiaUnit baseUnit, IEnumerable> unitMappings, MassMomentOfInertia zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, MassMomentOfInertia.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.MassMomentOfInertia", typeof(MassMomentOfInertia).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the MassMomentOfInertia quantity. + /// + /// A new instance of the class with the default settings. + public static MassMomentOfInertiaInfo CreateDefault() + { + return new MassMomentOfInertiaInfo(nameof(MassMomentOfInertia), DefaultBaseUnit, GetDefaultMappings(), new MassMomentOfInertia(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the MassMomentOfInertia quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MassMomentOfInertiaInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MassMomentOfInertiaInfo(nameof(MassMomentOfInertia), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new MassMomentOfInertia(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, 0, 0, 0, 0, 0); + + /// + /// The default base unit of MassMomentOfInertia is KilogramSquareMeter. All conversions, as defined in the , go via this value. + /// + public static MassMomentOfInertiaUnit DefaultBaseUnit { get; } = MassMomentOfInertiaUnit.KilogramSquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for MassMomentOfInertia. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MassMomentOfInertiaUnit.GramSquareCentimeter, "GramSquareCentimeter", "GramSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Gram)); + yield return new (MassMomentOfInertiaUnit.GramSquareDecimeter, "GramSquareDecimeter", "GramSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Gram)); + yield return new (MassMomentOfInertiaUnit.GramSquareMeter, "GramSquareMeter", "GramSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram)); + yield return new (MassMomentOfInertiaUnit.GramSquareMillimeter, "GramSquareMillimeter", "GramSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Gram)); + yield return new (MassMomentOfInertiaUnit.KilogramSquareCentimeter, "KilogramSquareCentimeter", "KilogramSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram)); + yield return new (MassMomentOfInertiaUnit.KilogramSquareDecimeter, "KilogramSquareDecimeter", "KilogramSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram)); + yield return new (MassMomentOfInertiaUnit.KilogramSquareMeter, "KilogramSquareMeter", "KilogramSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)); + yield return new (MassMomentOfInertiaUnit.KilogramSquareMillimeter, "KilogramSquareMillimeter", "KilogramSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram)); + yield return new (MassMomentOfInertiaUnit.KilotonneSquareCentimeter, "KilotonneSquareCentimeter", "KilotonneSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilotonne)); + yield return new (MassMomentOfInertiaUnit.KilotonneSquareDecimeter, "KilotonneSquareDecimeter", "KilotonneSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilotonne)); + yield return new (MassMomentOfInertiaUnit.KilotonneSquareMeter, "KilotonneSquareMeter", "KilotonneSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilotonne)); + yield return new (MassMomentOfInertiaUnit.KilotonneSquareMillimeter, "KilotonneSquareMillimeter", "KilotonneSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilotonne)); + yield return new (MassMomentOfInertiaUnit.MegatonneSquareCentimeter, "MegatonneSquareCentimeter", "MegatonneSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Megatonne)); + yield return new (MassMomentOfInertiaUnit.MegatonneSquareDecimeter, "MegatonneSquareDecimeter", "MegatonneSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Megatonne)); + yield return new (MassMomentOfInertiaUnit.MegatonneSquareMeter, "MegatonneSquareMeter", "MegatonneSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Megatonne)); + yield return new (MassMomentOfInertiaUnit.MegatonneSquareMillimeter, "MegatonneSquareMillimeter", "MegatonneSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Megatonne)); + yield return new (MassMomentOfInertiaUnit.MilligramSquareCentimeter, "MilligramSquareCentimeter", "MilligramSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Milligram)); + yield return new (MassMomentOfInertiaUnit.MilligramSquareDecimeter, "MilligramSquareDecimeter", "MilligramSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Milligram)); + yield return new (MassMomentOfInertiaUnit.MilligramSquareMeter, "MilligramSquareMeter", "MilligramSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram)); + yield return new (MassMomentOfInertiaUnit.MilligramSquareMillimeter, "MilligramSquareMillimeter", "MilligramSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Milligram)); + yield return new (MassMomentOfInertiaUnit.PoundSquareFoot, "PoundSquareFoot", "PoundSquareFeet", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound)); + yield return new (MassMomentOfInertiaUnit.PoundSquareInch, "PoundSquareInch", "PoundSquareInches", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound)); + yield return new (MassMomentOfInertiaUnit.SlugSquareFoot, "SlugSquareFoot", "SlugSquareFeet", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Slug)); + yield return new (MassMomentOfInertiaUnit.SlugSquareInch, "SlugSquareInch", "SlugSquareInches", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Slug)); + yield return new (MassMomentOfInertiaUnit.TonneSquareCentimeter, "TonneSquareCentimeter", "TonneSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Tonne)); + yield return new (MassMomentOfInertiaUnit.TonneSquareDecimeter, "TonneSquareDecimeter", "TonneSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Tonne)); + yield return new (MassMomentOfInertiaUnit.TonneSquareMeter, "TonneSquareMeter", "TonneSquareMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Tonne)); + yield return new (MassMomentOfInertiaUnit.TonneSquareMillimeter, "TonneSquareMillimeter", "TonneSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Tonne)); + } + } + + static MassMomentOfInertia() + { + Info = MassMomentOfInertiaInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -140,27 +187,27 @@ public MassMomentOfInertia(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of MassMomentOfInertia, which is KilogramSquareMeter. All conversions go via this value. /// - public static MassMomentOfInertiaUnit BaseUnit { get; } + public static MassMomentOfInertiaUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the MassMomentOfInertia quantity. /// - public static MassMomentOfInertiaUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit KilogramSquareMeter. /// - public static MassMomentOfInertia Zero { get; } + public static MassMomentOfInertia Zero => Info.Zero; /// public static MassMomentOfInertia AdditiveIdentity => Zero; @@ -178,7 +225,7 @@ public MassMomentOfInertia(double value, UnitSystem unitSystem) public MassMomentOfInertiaUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -196,6 +243,9 @@ public MassMomentOfInertia(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Molality.g.cs b/UnitsNet/GeneratedCode/Quantities/Molality.g.cs index 15ac985bf3..371aa705a4 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molality.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molality.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,21 +62,72 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MolalityUnit? _unit; - static Molality() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MolalityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, -1, 0, 0, 0, 1, 0); - BaseUnit = MolalityUnit.MolePerKilogram; - Units = Enum.GetValues(typeof(MolalityUnit)).Cast().ToArray(); - Zero = new Molality(0, BaseUnit); - Info = new QuantityInfo("Molality", - new UnitInfo[] - { - new UnitInfo(MolalityUnit.MillimolePerKilogram, "MillimolesPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, amount: AmountOfSubstanceUnit.Millimole), "Molality"), - new UnitInfo(MolalityUnit.MolePerGram, "MolesPerGram", new BaseUnits(mass: MassUnit.Gram, amount: AmountOfSubstanceUnit.Mole), "Molality"), - new UnitInfo(MolalityUnit.MolePerKilogram, "MolesPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, amount: AmountOfSubstanceUnit.Mole), "Molality"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MolalityInfo(string name, MolalityUnit baseUnit, IEnumerable> unitMappings, Molality zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MolalityInfo(string name, MolalityUnit baseUnit, IEnumerable> unitMappings, Molality zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Molality.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Molality", typeof(Molality).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Molality quantity. + /// + /// A new instance of the class with the default settings. + public static MolalityInfo CreateDefault() + { + return new MolalityInfo(nameof(Molality), DefaultBaseUnit, GetDefaultMappings(), new Molality(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Molality quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MolalityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MolalityInfo(nameof(Molality), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Molality(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [M^-1][N]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, -1, 0, 0, 0, 1, 0); + + /// + /// The default base unit of Molality is MolePerKilogram. All conversions, as defined in the , go via this value. + /// + public static MolalityUnit DefaultBaseUnit { get; } = MolalityUnit.MolePerKilogram; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Molality. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MolalityUnit.MillimolePerKilogram, "MillimolePerKilogram", "MillimolesPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, amount: AmountOfSubstanceUnit.Millimole)); + yield return new (MolalityUnit.MolePerGram, "MolePerGram", "MolesPerGram", new BaseUnits(mass: MassUnit.Gram, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolalityUnit.MolePerKilogram, "MolePerKilogram", "MolesPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, amount: AmountOfSubstanceUnit.Mole)); + } + } + + static Molality() + { + Info = MolalityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -118,27 +165,27 @@ public Molality(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Molality, which is MolePerKilogram. All conversions go via this value. /// - public static MolalityUnit BaseUnit { get; } + public static MolalityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Molality quantity. /// - public static MolalityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit MolePerKilogram. /// - public static Molality Zero { get; } + public static Molality Zero => Info.Zero; /// public static Molality AdditiveIdentity => Zero; @@ -156,7 +203,7 @@ public Molality(double value, UnitSystem unitSystem) public MolalityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -174,6 +221,9 @@ public Molality(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs index ce6967aa3b..ed395e0d1b 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEnergy.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,21 +62,72 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MolarEnergyUnit? _unit; - static MolarEnergy() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MolarEnergyInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, -1, 0); - BaseUnit = MolarEnergyUnit.JoulePerMole; - Units = Enum.GetValues(typeof(MolarEnergyUnit)).Cast().ToArray(); - Zero = new MolarEnergy(0, BaseUnit); - Info = new QuantityInfo("MolarEnergy", - new UnitInfo[] - { - new UnitInfo(MolarEnergyUnit.JoulePerMole, "JoulesPerMole", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Mole), "MolarEnergy"), - new UnitInfo(MolarEnergyUnit.KilojoulePerMole, "KilojoulesPerMole", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Millimole), "MolarEnergy"), - new UnitInfo(MolarEnergyUnit.MegajoulePerMole, "MegajoulesPerMole", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Micromole), "MolarEnergy"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MolarEnergyInfo(string name, MolarEnergyUnit baseUnit, IEnumerable> unitMappings, MolarEnergy zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MolarEnergyInfo(string name, MolarEnergyUnit baseUnit, IEnumerable> unitMappings, MolarEnergy zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, MolarEnergy.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.MolarEnergy", typeof(MolarEnergy).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the MolarEnergy quantity. + /// + /// A new instance of the class with the default settings. + public static MolarEnergyInfo CreateDefault() + { + return new MolarEnergyInfo(nameof(MolarEnergy), DefaultBaseUnit, GetDefaultMappings(), new MolarEnergy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the MolarEnergy quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MolarEnergyInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MolarEnergyInfo(nameof(MolarEnergy), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new MolarEnergy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2][M][N^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -2, 0, 0, -1, 0); + + /// + /// The default base unit of MolarEnergy is JoulePerMole. All conversions, as defined in the , go via this value. + /// + public static MolarEnergyUnit DefaultBaseUnit { get; } = MolarEnergyUnit.JoulePerMole; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for MolarEnergy. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MolarEnergyUnit.JoulePerMole, "JoulePerMole", "JoulesPerMole", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarEnergyUnit.KilojoulePerMole, "KilojoulePerMole", "KilojoulesPerMole", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Millimole)); + yield return new (MolarEnergyUnit.MegajoulePerMole, "MegajoulePerMole", "MegajoulesPerMole", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Micromole)); + } + } + + static MolarEnergy() + { + Info = MolarEnergyInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -118,27 +165,27 @@ public MolarEnergy(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of MolarEnergy, which is JoulePerMole. All conversions go via this value. /// - public static MolarEnergyUnit BaseUnit { get; } + public static MolarEnergyUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the MolarEnergy quantity. /// - public static MolarEnergyUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerMole. /// - public static MolarEnergy Zero { get; } + public static MolarEnergy Zero => Info.Zero; /// public static MolarEnergy AdditiveIdentity => Zero; @@ -156,7 +203,7 @@ public MolarEnergy(double value, UnitSystem unitSystem) public MolarEnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -174,6 +221,9 @@ public MolarEnergy(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs index 1da342ca2b..eb92bbae90 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarEntropy.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,21 +59,72 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MolarEntropyUnit? _unit; - static MolarEntropy() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MolarEntropyInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -2, 0, -1, -1, 0); - BaseUnit = MolarEntropyUnit.JoulePerMoleKelvin; - Units = Enum.GetValues(typeof(MolarEntropyUnit)).Cast().ToArray(); - Zero = new MolarEntropy(0, BaseUnit); - Info = new QuantityInfo("MolarEntropy", - new UnitInfo[] - { - new UnitInfo(MolarEntropyUnit.JoulePerMoleKelvin, "JoulesPerMoleKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin, amount: AmountOfSubstanceUnit.Mole), "MolarEntropy"), - new UnitInfo(MolarEntropyUnit.KilojoulePerMoleKelvin, "KilojoulesPerMoleKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin, amount: AmountOfSubstanceUnit.Millimole), "MolarEntropy"), - new UnitInfo(MolarEntropyUnit.MegajoulePerMoleKelvin, "MegajoulesPerMoleKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin, amount: AmountOfSubstanceUnit.Micromole), "MolarEntropy"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MolarEntropyInfo(string name, MolarEntropyUnit baseUnit, IEnumerable> unitMappings, MolarEntropy zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MolarEntropyInfo(string name, MolarEntropyUnit baseUnit, IEnumerable> unitMappings, MolarEntropy zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, MolarEntropy.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.MolarEntropy", typeof(MolarEntropy).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the MolarEntropy quantity. + /// + /// A new instance of the class with the default settings. + public static MolarEntropyInfo CreateDefault() + { + return new MolarEntropyInfo(nameof(MolarEntropy), DefaultBaseUnit, GetDefaultMappings(), new MolarEntropy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the MolarEntropy quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MolarEntropyInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MolarEntropyInfo(nameof(MolarEntropy), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new MolarEntropy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2][M][Θ^-1][N^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -2, 0, -1, -1, 0); + + /// + /// The default base unit of MolarEntropy is JoulePerMoleKelvin. All conversions, as defined in the , go via this value. + /// + public static MolarEntropyUnit DefaultBaseUnit { get; } = MolarEntropyUnit.JoulePerMoleKelvin; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for MolarEntropy. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MolarEntropyUnit.JoulePerMoleKelvin, "JoulePerMoleKelvin", "JoulesPerMoleKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarEntropyUnit.KilojoulePerMoleKelvin, "KilojoulePerMoleKelvin", "KilojoulesPerMoleKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin, amount: AmountOfSubstanceUnit.Millimole)); + yield return new (MolarEntropyUnit.MegajoulePerMoleKelvin, "MegajoulePerMoleKelvin", "MegajoulesPerMoleKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin, amount: AmountOfSubstanceUnit.Micromole)); + } + } + + static MolarEntropy() + { + Info = MolarEntropyInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -115,27 +162,27 @@ public MolarEntropy(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of MolarEntropy, which is JoulePerMoleKelvin. All conversions go via this value. /// - public static MolarEntropyUnit BaseUnit { get; } + public static MolarEntropyUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the MolarEntropy quantity. /// - public static MolarEntropyUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerMoleKelvin. /// - public static MolarEntropy Zero { get; } + public static MolarEntropy Zero => Info.Zero; /// public static MolarEntropy AdditiveIdentity => Zero; @@ -153,7 +200,7 @@ public MolarEntropy(double value, UnitSystem unitSystem) public MolarEntropyUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -171,6 +218,9 @@ public MolarEntropy(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs index 280bfb5126..54bbee42b2 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarFlow.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -69,27 +65,78 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MolarFlowUnit? _unit; - static MolarFlow() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MolarFlowInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, -1, 0, 0, 1, 0); - BaseUnit = MolarFlowUnit.MolePerSecond; - Units = Enum.GetValues(typeof(MolarFlowUnit)).Cast().ToArray(); - Zero = new MolarFlow(0, BaseUnit); - Info = new QuantityInfo("MolarFlow", - new UnitInfo[] - { - new UnitInfo(MolarFlowUnit.KilomolePerHour, "KilomolesPerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.Kilomole), "MolarFlow"), - new UnitInfo(MolarFlowUnit.KilomolePerMinute, "KilomolesPerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.Kilomole), "MolarFlow"), - new UnitInfo(MolarFlowUnit.KilomolePerSecond, "KilomolesPerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Kilomole), "MolarFlow"), - new UnitInfo(MolarFlowUnit.MolePerHour, "MolesPerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.Mole), "MolarFlow"), - new UnitInfo(MolarFlowUnit.MolePerMinute, "MolesPerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.Mole), "MolarFlow"), - new UnitInfo(MolarFlowUnit.MolePerSecond, "MolesPerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Mole), "MolarFlow"), - new UnitInfo(MolarFlowUnit.PoundMolePerHour, "PoundMolesPerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.PoundMole), "MolarFlow"), - new UnitInfo(MolarFlowUnit.PoundMolePerMinute, "PoundMolesPerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.PoundMole), "MolarFlow"), - new UnitInfo(MolarFlowUnit.PoundMolePerSecond, "PoundMolesPerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.PoundMole), "MolarFlow"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MolarFlowInfo(string name, MolarFlowUnit baseUnit, IEnumerable> unitMappings, MolarFlow zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MolarFlowInfo(string name, MolarFlowUnit baseUnit, IEnumerable> unitMappings, MolarFlow zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, MolarFlow.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.MolarFlow", typeof(MolarFlow).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the MolarFlow quantity. + /// + /// A new instance of the class with the default settings. + public static MolarFlowInfo CreateDefault() + { + return new MolarFlowInfo(nameof(MolarFlow), DefaultBaseUnit, GetDefaultMappings(), new MolarFlow(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the MolarFlow quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MolarFlowInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MolarFlowInfo(nameof(MolarFlow), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new MolarFlow(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][N]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, -1, 0, 0, 1, 0); + + /// + /// The default base unit of MolarFlow is MolePerSecond. All conversions, as defined in the , go via this value. + /// + public static MolarFlowUnit DefaultBaseUnit { get; } = MolarFlowUnit.MolePerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for MolarFlow. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MolarFlowUnit.KilomolePerHour, "KilomolePerHour", "KilomolesPerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.Kilomole)); + yield return new (MolarFlowUnit.KilomolePerMinute, "KilomolePerMinute", "KilomolesPerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.Kilomole)); + yield return new (MolarFlowUnit.KilomolePerSecond, "KilomolePerSecond", "KilomolesPerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Kilomole)); + yield return new (MolarFlowUnit.MolePerHour, "MolePerHour", "MolesPerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarFlowUnit.MolePerMinute, "MolePerMinute", "MolesPerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarFlowUnit.MolePerSecond, "MolePerSecond", "MolesPerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarFlowUnit.PoundMolePerHour, "PoundMolePerHour", "PoundMolesPerHour", new BaseUnits(time: DurationUnit.Hour, amount: AmountOfSubstanceUnit.PoundMole)); + yield return new (MolarFlowUnit.PoundMolePerMinute, "PoundMolePerMinute", "PoundMolesPerMinute", new BaseUnits(time: DurationUnit.Minute, amount: AmountOfSubstanceUnit.PoundMole)); + yield return new (MolarFlowUnit.PoundMolePerSecond, "PoundMolePerSecond", "PoundMolesPerSecond", new BaseUnits(time: DurationUnit.Second, amount: AmountOfSubstanceUnit.PoundMole)); + } + } + + static MolarFlow() + { + Info = MolarFlowInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -127,27 +174,27 @@ public MolarFlow(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of MolarFlow, which is MolePerSecond. All conversions go via this value. /// - public static MolarFlowUnit BaseUnit { get; } + public static MolarFlowUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the MolarFlow quantity. /// - public static MolarFlowUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit MolePerSecond. /// - public static MolarFlow Zero { get; } + public static MolarFlow Zero => Info.Zero; /// public static MolarFlow AdditiveIdentity => Zero; @@ -165,7 +212,7 @@ public MolarFlow(double value, UnitSystem unitSystem) public MolarFlowUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -183,6 +230,9 @@ public MolarFlow(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs index b0dc8647f7..54688dbdb3 100644 --- a/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/MolarMass.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -68,31 +64,82 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MolarMassUnit? _unit; - static MolarMass() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MolarMassInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 1, 0, 0, 0, -1, 0); - BaseUnit = MolarMassUnit.KilogramPerMole; - Units = Enum.GetValues(typeof(MolarMassUnit)).Cast().ToArray(); - Zero = new MolarMass(0, BaseUnit); - Info = new QuantityInfo("MolarMass", - new UnitInfo[] - { - new UnitInfo(MolarMassUnit.CentigramPerMole, "CentigramsPerMole", new BaseUnits(mass: MassUnit.Centigram, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - new UnitInfo(MolarMassUnit.DecagramPerMole, "DecagramsPerMole", new BaseUnits(mass: MassUnit.Decagram, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - new UnitInfo(MolarMassUnit.DecigramPerMole, "DecigramsPerMole", new BaseUnits(mass: MassUnit.Decigram, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - new UnitInfo(MolarMassUnit.GramPerMole, "GramsPerMole", new BaseUnits(mass: MassUnit.Gram, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - new UnitInfo(MolarMassUnit.HectogramPerMole, "HectogramsPerMole", new BaseUnits(mass: MassUnit.Hectogram, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - new UnitInfo(MolarMassUnit.KilogramPerKilomole, "KilogramsPerKilomole", new BaseUnits(mass: MassUnit.Kilogram, amount: AmountOfSubstanceUnit.Kilomole), "MolarMass"), - new UnitInfo(MolarMassUnit.KilogramPerMole, "KilogramsPerMole", new BaseUnits(mass: MassUnit.Kilogram, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - new UnitInfo(MolarMassUnit.KilopoundPerMole, "KilopoundsPerMole", new BaseUnits(mass: MassUnit.Kilopound, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - new UnitInfo(MolarMassUnit.MegapoundPerMole, "MegapoundsPerMole", new BaseUnits(mass: MassUnit.Megapound, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - new UnitInfo(MolarMassUnit.MicrogramPerMole, "MicrogramsPerMole", new BaseUnits(mass: MassUnit.Microgram, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - new UnitInfo(MolarMassUnit.MilligramPerMole, "MilligramsPerMole", new BaseUnits(mass: MassUnit.Milligram, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - new UnitInfo(MolarMassUnit.NanogramPerMole, "NanogramsPerMole", new BaseUnits(mass: MassUnit.Nanogram, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - new UnitInfo(MolarMassUnit.PoundPerMole, "PoundsPerMole", new BaseUnits(mass: MassUnit.Pound, amount: AmountOfSubstanceUnit.Mole), "MolarMass"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MolarMassInfo(string name, MolarMassUnit baseUnit, IEnumerable> unitMappings, MolarMass zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MolarMassInfo(string name, MolarMassUnit baseUnit, IEnumerable> unitMappings, MolarMass zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, MolarMass.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.MolarMass", typeof(MolarMass).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the MolarMass quantity. + /// + /// A new instance of the class with the default settings. + public static MolarMassInfo CreateDefault() + { + return new MolarMassInfo(nameof(MolarMass), DefaultBaseUnit, GetDefaultMappings(), new MolarMass(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the MolarMass quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MolarMassInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MolarMassInfo(nameof(MolarMass), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new MolarMass(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [M][N^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 1, 0, 0, 0, -1, 0); + + /// + /// The default base unit of MolarMass is KilogramPerMole. All conversions, as defined in the , go via this value. + /// + public static MolarMassUnit DefaultBaseUnit { get; } = MolarMassUnit.KilogramPerMole; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for MolarMass. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MolarMassUnit.CentigramPerMole, "CentigramPerMole", "CentigramsPerMole", new BaseUnits(mass: MassUnit.Centigram, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarMassUnit.DecagramPerMole, "DecagramPerMole", "DecagramsPerMole", new BaseUnits(mass: MassUnit.Decagram, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarMassUnit.DecigramPerMole, "DecigramPerMole", "DecigramsPerMole", new BaseUnits(mass: MassUnit.Decigram, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarMassUnit.GramPerMole, "GramPerMole", "GramsPerMole", new BaseUnits(mass: MassUnit.Gram, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarMassUnit.HectogramPerMole, "HectogramPerMole", "HectogramsPerMole", new BaseUnits(mass: MassUnit.Hectogram, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarMassUnit.KilogramPerKilomole, "KilogramPerKilomole", "KilogramsPerKilomole", new BaseUnits(mass: MassUnit.Kilogram, amount: AmountOfSubstanceUnit.Kilomole)); + yield return new (MolarMassUnit.KilogramPerMole, "KilogramPerMole", "KilogramsPerMole", new BaseUnits(mass: MassUnit.Kilogram, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarMassUnit.KilopoundPerMole, "KilopoundPerMole", "KilopoundsPerMole", new BaseUnits(mass: MassUnit.Kilopound, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarMassUnit.MegapoundPerMole, "MegapoundPerMole", "MegapoundsPerMole", new BaseUnits(mass: MassUnit.Megapound, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarMassUnit.MicrogramPerMole, "MicrogramPerMole", "MicrogramsPerMole", new BaseUnits(mass: MassUnit.Microgram, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarMassUnit.MilligramPerMole, "MilligramPerMole", "MilligramsPerMole", new BaseUnits(mass: MassUnit.Milligram, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarMassUnit.NanogramPerMole, "NanogramPerMole", "NanogramsPerMole", new BaseUnits(mass: MassUnit.Nanogram, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarMassUnit.PoundPerMole, "PoundPerMole", "PoundsPerMole", new BaseUnits(mass: MassUnit.Pound, amount: AmountOfSubstanceUnit.Mole)); + } + } + + static MolarMass() + { + Info = MolarMassInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -130,27 +177,27 @@ public MolarMass(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of MolarMass, which is KilogramPerMole. All conversions go via this value. /// - public static MolarMassUnit BaseUnit { get; } + public static MolarMassUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the MolarMass quantity. /// - public static MolarMassUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit KilogramPerMole. /// - public static MolarMass Zero { get; } + public static MolarMass Zero => Info.Zero; /// public static MolarMass AdditiveIdentity => Zero; @@ -168,7 +215,7 @@ public MolarMass(double value, UnitSystem unitSystem) public MolarMassUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -186,6 +233,9 @@ public MolarMass(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs index 6cc86296ef..2ed2d195f9 100644 --- a/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Molarity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -73,29 +69,80 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly MolarityUnit? _unit; - static Molarity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class MolarityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-3, 0, 0, 0, 0, 1, 0); - BaseUnit = MolarityUnit.MolePerCubicMeter; - Units = Enum.GetValues(typeof(MolarityUnit)).Cast().ToArray(); - Zero = new Molarity(0, BaseUnit); - Info = new QuantityInfo("Molarity", - new UnitInfo[] - { - new UnitInfo(MolarityUnit.CentimolePerLiter, "CentimolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Centimole), "Molarity"), - new UnitInfo(MolarityUnit.DecimolePerLiter, "DecimolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Decimole), "Molarity"), - new UnitInfo(MolarityUnit.FemtomolePerLiter, "FemtomolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Femtomole), "Molarity"), - new UnitInfo(MolarityUnit.KilomolePerCubicMeter, "KilomolesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Kilomole), "Molarity"), - new UnitInfo(MolarityUnit.MicromolePerLiter, "MicromolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Micromole), "Molarity"), - new UnitInfo(MolarityUnit.MillimolePerLiter, "MillimolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Millimole), "Molarity"), - new UnitInfo(MolarityUnit.MolePerCubicMeter, "MolesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Mole), "Molarity"), - new UnitInfo(MolarityUnit.MolePerLiter, "MolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Mole), "Molarity"), - new UnitInfo(MolarityUnit.NanomolePerLiter, "NanomolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Nanomole), "Molarity"), - new UnitInfo(MolarityUnit.PicomolePerLiter, "PicomolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Picomole), "Molarity"), - new UnitInfo(MolarityUnit.PoundMolePerCubicFoot, "PoundMolesPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, amount: AmountOfSubstanceUnit.PoundMole), "Molarity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public MolarityInfo(string name, MolarityUnit baseUnit, IEnumerable> unitMappings, Molarity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public MolarityInfo(string name, MolarityUnit baseUnit, IEnumerable> unitMappings, Molarity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Molarity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Molarity", typeof(Molarity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Molarity quantity. + /// + /// A new instance of the class with the default settings. + public static MolarityInfo CreateDefault() + { + return new MolarityInfo(nameof(Molarity), DefaultBaseUnit, GetDefaultMappings(), new Molarity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Molarity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static MolarityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new MolarityInfo(nameof(Molarity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Molarity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-3][N]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-3, 0, 0, 0, 0, 1, 0); + + /// + /// The default base unit of Molarity is MolePerCubicMeter. All conversions, as defined in the , go via this value. + /// + public static MolarityUnit DefaultBaseUnit { get; } = MolarityUnit.MolePerCubicMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Molarity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (MolarityUnit.CentimolePerLiter, "CentimolePerLiter", "CentimolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Centimole)); + yield return new (MolarityUnit.DecimolePerLiter, "DecimolePerLiter", "DecimolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Decimole)); + yield return new (MolarityUnit.FemtomolePerLiter, "FemtomolePerLiter", "FemtomolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Femtomole)); + yield return new (MolarityUnit.KilomolePerCubicMeter, "KilomolePerCubicMeter", "KilomolesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Kilomole)); + yield return new (MolarityUnit.MicromolePerLiter, "MicromolePerLiter", "MicromolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Micromole)); + yield return new (MolarityUnit.MillimolePerLiter, "MillimolePerLiter", "MillimolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Millimole)); + yield return new (MolarityUnit.MolePerCubicMeter, "MolePerCubicMeter", "MolesPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarityUnit.MolePerLiter, "MolePerLiter", "MolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Mole)); + yield return new (MolarityUnit.NanomolePerLiter, "NanomolePerLiter", "NanomolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Nanomole)); + yield return new (MolarityUnit.PicomolePerLiter, "PicomolePerLiter", "PicomolesPerLiter", new BaseUnits(length: LengthUnit.Decimeter, amount: AmountOfSubstanceUnit.Picomole)); + yield return new (MolarityUnit.PoundMolePerCubicFoot, "PoundMolePerCubicFoot", "PoundMolesPerCubicFoot", new BaseUnits(length: LengthUnit.Foot, amount: AmountOfSubstanceUnit.PoundMole)); + } + } + + static Molarity() + { + Info = MolarityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -133,27 +180,27 @@ public Molarity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Molarity, which is MolePerCubicMeter. All conversions go via this value. /// - public static MolarityUnit BaseUnit { get; } + public static MolarityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Molarity quantity. /// - public static MolarityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit MolePerCubicMeter. /// - public static Molarity Zero { get; } + public static Molarity Zero => Info.Zero; /// public static Molarity AdditiveIdentity => Zero; @@ -171,7 +218,7 @@ public Molarity(double value, UnitSystem unitSystem) public MolarityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -189,6 +236,9 @@ public Molarity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs b/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs index 9a72750e46..b86f2a8533 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permeability.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,19 +62,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly PermeabilityUnit? _unit; - static Permeability() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class PermeabilityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 1, -2, -2, 0, 0, 0); - BaseUnit = PermeabilityUnit.HenryPerMeter; - Units = Enum.GetValues(typeof(PermeabilityUnit)).Cast().ToArray(); - Zero = new Permeability(0, BaseUnit); - Info = new QuantityInfo("Permeability", - new UnitInfo[] - { - new UnitInfo(PermeabilityUnit.HenryPerMeter, "HenriesPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "Permeability"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public PermeabilityInfo(string name, PermeabilityUnit baseUnit, IEnumerable> unitMappings, Permeability zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public PermeabilityInfo(string name, PermeabilityUnit baseUnit, IEnumerable> unitMappings, Permeability zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Permeability.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Permeability", typeof(Permeability).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Permeability quantity. + /// + /// A new instance of the class with the default settings. + public static PermeabilityInfo CreateDefault() + { + return new PermeabilityInfo(nameof(Permeability), DefaultBaseUnit, GetDefaultMappings(), new Permeability(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Permeability quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static PermeabilityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new PermeabilityInfo(nameof(Permeability), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Permeability(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L][M][I^-2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 1, -2, -2, 0, 0, 0); + + /// + /// The default base unit of Permeability is HenryPerMeter. All conversions, as defined in the , go via this value. + /// + public static PermeabilityUnit DefaultBaseUnit { get; } = PermeabilityUnit.HenryPerMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Permeability. + public static IEnumerable> GetDefaultMappings() + { + yield return new (PermeabilityUnit.HenryPerMeter, "HenryPerMeter", "HenriesPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static Permeability() + { + Info = PermeabilityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -116,27 +163,27 @@ public Permeability(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Permeability, which is HenryPerMeter. All conversions go via this value. /// - public static PermeabilityUnit BaseUnit { get; } + public static PermeabilityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Permeability quantity. /// - public static PermeabilityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit HenryPerMeter. /// - public static Permeability Zero { get; } + public static Permeability Zero => Info.Zero; /// public static Permeability AdditiveIdentity => Zero; @@ -154,7 +201,7 @@ public Permeability(double value, UnitSystem unitSystem) public PermeabilityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -172,6 +219,9 @@ public Permeability(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs b/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs index 8d8262bd1c..20e8b0e57a 100644 --- a/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Permittivity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,19 +62,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly PermittivityUnit? _unit; - static Permittivity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class PermittivityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-3, -1, 4, 2, 0, 0, 0); - BaseUnit = PermittivityUnit.FaradPerMeter; - Units = Enum.GetValues(typeof(PermittivityUnit)).Cast().ToArray(); - Zero = new Permittivity(0, BaseUnit); - Info = new QuantityInfo("Permittivity", - new UnitInfo[] - { - new UnitInfo(PermittivityUnit.FaradPerMeter, "FaradsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "Permittivity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public PermittivityInfo(string name, PermittivityUnit baseUnit, IEnumerable> unitMappings, Permittivity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public PermittivityInfo(string name, PermittivityUnit baseUnit, IEnumerable> unitMappings, Permittivity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Permittivity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Permittivity", typeof(Permittivity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Permittivity quantity. + /// + /// A new instance of the class with the default settings. + public static PermittivityInfo CreateDefault() + { + return new PermittivityInfo(nameof(Permittivity), DefaultBaseUnit, GetDefaultMappings(), new Permittivity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Permittivity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static PermittivityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new PermittivityInfo(nameof(Permittivity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Permittivity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^4][L^-3][M^-1][I^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-3, -1, 4, 2, 0, 0, 0); + + /// + /// The default base unit of Permittivity is FaradPerMeter. All conversions, as defined in the , go via this value. + /// + public static PermittivityUnit DefaultBaseUnit { get; } = PermittivityUnit.FaradPerMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Permittivity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (PermittivityUnit.FaradPerMeter, "FaradPerMeter", "FaradsPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static Permittivity() + { + Info = PermittivityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -116,27 +163,27 @@ public Permittivity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Permittivity, which is FaradPerMeter. All conversions go via this value. /// - public static PermittivityUnit BaseUnit { get; } + public static PermittivityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Permittivity quantity. /// - public static PermittivityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit FaradPerMeter. /// - public static Permittivity Zero { get; } + public static Permittivity Zero => Info.Zero; /// public static Permittivity AdditiveIdentity => Zero; @@ -154,7 +201,7 @@ public Permittivity(double value, UnitSystem unitSystem) public PermittivityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -172,6 +219,9 @@ public Permittivity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs b/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs index ed12c3eaa5..c03d0dc375 100644 --- a/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PorousMediumPermeability.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,23 +62,74 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly PorousMediumPermeabilityUnit? _unit; - static PorousMediumPermeability() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class PorousMediumPermeabilityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 0, 0, 0, 0, 0, 0); - BaseUnit = PorousMediumPermeabilityUnit.SquareMeter; - Units = Enum.GetValues(typeof(PorousMediumPermeabilityUnit)).Cast().ToArray(); - Zero = new PorousMediumPermeability(0, BaseUnit); - Info = new QuantityInfo("PorousMediumPermeability", - new UnitInfo[] - { - new UnitInfo(PorousMediumPermeabilityUnit.Darcy, "Darcys", BaseUnits.Undefined, "PorousMediumPermeability"), - new UnitInfo(PorousMediumPermeabilityUnit.Microdarcy, "Microdarcys", BaseUnits.Undefined, "PorousMediumPermeability"), - new UnitInfo(PorousMediumPermeabilityUnit.Millidarcy, "Millidarcys", BaseUnits.Undefined, "PorousMediumPermeability"), - new UnitInfo(PorousMediumPermeabilityUnit.SquareCentimeter, "SquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter), "PorousMediumPermeability"), - new UnitInfo(PorousMediumPermeabilityUnit.SquareMeter, "SquareMeters", new BaseUnits(length: LengthUnit.Meter), "PorousMediumPermeability"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public PorousMediumPermeabilityInfo(string name, PorousMediumPermeabilityUnit baseUnit, IEnumerable> unitMappings, PorousMediumPermeability zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public PorousMediumPermeabilityInfo(string name, PorousMediumPermeabilityUnit baseUnit, IEnumerable> unitMappings, PorousMediumPermeability zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, PorousMediumPermeability.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.PorousMediumPermeability", typeof(PorousMediumPermeability).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the PorousMediumPermeability quantity. + /// + /// A new instance of the class with the default settings. + public static PorousMediumPermeabilityInfo CreateDefault() + { + return new PorousMediumPermeabilityInfo(nameof(PorousMediumPermeability), DefaultBaseUnit, GetDefaultMappings(), new PorousMediumPermeability(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the PorousMediumPermeability quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static PorousMediumPermeabilityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new PorousMediumPermeabilityInfo(nameof(PorousMediumPermeability), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new PorousMediumPermeability(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 0, 0, 0, 0, 0, 0); + + /// + /// The default base unit of PorousMediumPermeability is SquareMeter. All conversions, as defined in the , go via this value. + /// + public static PorousMediumPermeabilityUnit DefaultBaseUnit { get; } = PorousMediumPermeabilityUnit.SquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for PorousMediumPermeability. + public static IEnumerable> GetDefaultMappings() + { + yield return new (PorousMediumPermeabilityUnit.Darcy, "Darcy", "Darcys", BaseUnits.Undefined); + yield return new (PorousMediumPermeabilityUnit.Microdarcy, "Microdarcy", "Microdarcys", BaseUnits.Undefined); + yield return new (PorousMediumPermeabilityUnit.Millidarcy, "Millidarcy", "Millidarcys", BaseUnits.Undefined); + yield return new (PorousMediumPermeabilityUnit.SquareCentimeter, "SquareCentimeter", "SquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter)); + yield return new (PorousMediumPermeabilityUnit.SquareMeter, "SquareMeter", "SquareMeters", new BaseUnits(length: LengthUnit.Meter)); + } + } + + static PorousMediumPermeability() + { + Info = PorousMediumPermeabilityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -120,27 +167,27 @@ public PorousMediumPermeability(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of PorousMediumPermeability, which is SquareMeter. All conversions go via this value. /// - public static PorousMediumPermeabilityUnit BaseUnit { get; } + public static PorousMediumPermeabilityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the PorousMediumPermeability quantity. /// - public static PorousMediumPermeabilityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit SquareMeter. /// - public static PorousMediumPermeability Zero { get; } + public static PorousMediumPermeability Zero => Info.Zero; /// public static PorousMediumPermeability AdditiveIdentity => Zero; @@ -158,7 +205,7 @@ public PorousMediumPermeability(double value, UnitSystem unitSystem) public PorousMediumPermeabilityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -176,6 +223,9 @@ public PorousMediumPermeability(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Power.g.cs b/UnitsNet/GeneratedCode/Quantities/Power.g.cs index 7246b0241d..f9009e8799 100644 --- a/UnitsNet/GeneratedCode/Quantities/Power.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Power.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -79,45 +75,96 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly PowerUnit? _unit; - static Power() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class PowerInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); - BaseUnit = PowerUnit.Watt; - Units = Enum.GetValues(typeof(PowerUnit)).Cast().ToArray(); - Zero = new Power(0, BaseUnit); - Info = new QuantityInfo("Power", - new UnitInfo[] - { - new UnitInfo(PowerUnit.BoilerHorsepower, "BoilerHorsepower", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.BritishThermalUnitPerHour, "BritishThermalUnitsPerHour", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.Decawatt, "Decawatts", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.Deciwatt, "Deciwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Hectogram, time: DurationUnit.Second), "Power"), - new UnitInfo(PowerUnit.ElectricalHorsepower, "ElectricalHorsepower", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.Femtowatt, "Femtowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Picogram, time: DurationUnit.Second), "Power"), - new UnitInfo(PowerUnit.GigajoulePerHour, "GigajoulesPerHour", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.Gigawatt, "Gigawatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond), "Power"), - new UnitInfo(PowerUnit.HydraulicHorsepower, "HydraulicHorsepower", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.JoulePerHour, "JoulesPerHour", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.KilobritishThermalUnitPerHour, "KilobritishThermalUnitsPerHour", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.KilojoulePerHour, "KilojoulesPerHour", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.Kilowatt, "Kilowatts", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.MechanicalHorsepower, "MechanicalHorsepower", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.MegabritishThermalUnitPerHour, "MegabritishThermalUnitsPerHour", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.MegajoulePerHour, "MegajoulesPerHour", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.Megawatt, "Megawatts", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Power"), - new UnitInfo(PowerUnit.MetricHorsepower, "MetricHorsepower", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.Microwatt, "Microwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second), "Power"), - new UnitInfo(PowerUnit.MillijoulePerHour, "MillijoulesPerHour", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.Milliwatt, "Milliwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second), "Power"), - new UnitInfo(PowerUnit.Nanowatt, "Nanowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second), "Power"), - new UnitInfo(PowerUnit.Petawatt, "Petawatts", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.Picowatt, "Picowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second), "Power"), - new UnitInfo(PowerUnit.Terawatt, "Terawatts", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Power"), - new UnitInfo(PowerUnit.TonOfRefrigeration, "TonsOfRefrigeration", BaseUnits.Undefined, "Power"), - new UnitInfo(PowerUnit.Watt, "Watts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Power"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public PowerInfo(string name, PowerUnit baseUnit, IEnumerable> unitMappings, Power zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public PowerInfo(string name, PowerUnit baseUnit, IEnumerable> unitMappings, Power zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Power.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Power", typeof(Power).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Power quantity. + /// + /// A new instance of the class with the default settings. + public static PowerInfo CreateDefault() + { + return new PowerInfo(nameof(Power), DefaultBaseUnit, GetDefaultMappings(), new Power(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Power quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static PowerInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new PowerInfo(nameof(Power), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Power(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -3, 0, 0, 0, 0); + + /// + /// The default base unit of Power is Watt. All conversions, as defined in the , go via this value. + /// + public static PowerUnit DefaultBaseUnit { get; } = PowerUnit.Watt; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Power. + public static IEnumerable> GetDefaultMappings() + { + yield return new (PowerUnit.BoilerHorsepower, "BoilerHorsepower", "BoilerHorsepower", BaseUnits.Undefined); + yield return new (PowerUnit.BritishThermalUnitPerHour, "BritishThermalUnitPerHour", "BritishThermalUnitsPerHour", BaseUnits.Undefined); + yield return new (PowerUnit.Decawatt, "Decawatt", "Decawatts", BaseUnits.Undefined); + yield return new (PowerUnit.Deciwatt, "Deciwatt", "Deciwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Hectogram, time: DurationUnit.Second)); + yield return new (PowerUnit.ElectricalHorsepower, "ElectricalHorsepower", "ElectricalHorsepower", BaseUnits.Undefined); + yield return new (PowerUnit.Femtowatt, "Femtowatt", "Femtowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Picogram, time: DurationUnit.Second)); + yield return new (PowerUnit.GigajoulePerHour, "GigajoulePerHour", "GigajoulesPerHour", BaseUnits.Undefined); + yield return new (PowerUnit.Gigawatt, "Gigawatt", "Gigawatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Millisecond)); + yield return new (PowerUnit.HydraulicHorsepower, "HydraulicHorsepower", "HydraulicHorsepower", BaseUnits.Undefined); + yield return new (PowerUnit.JoulePerHour, "JoulePerHour", "JoulesPerHour", BaseUnits.Undefined); + yield return new (PowerUnit.KilobritishThermalUnitPerHour, "KilobritishThermalUnitPerHour", "KilobritishThermalUnitsPerHour", BaseUnits.Undefined); + yield return new (PowerUnit.KilojoulePerHour, "KilojoulePerHour", "KilojoulesPerHour", BaseUnits.Undefined); + yield return new (PowerUnit.Kilowatt, "Kilowatt", "Kilowatts", BaseUnits.Undefined); + yield return new (PowerUnit.MechanicalHorsepower, "MechanicalHorsepower", "MechanicalHorsepower", BaseUnits.Undefined); + yield return new (PowerUnit.MegabritishThermalUnitPerHour, "MegabritishThermalUnitPerHour", "MegabritishThermalUnitsPerHour", BaseUnits.Undefined); + yield return new (PowerUnit.MegajoulePerHour, "MegajoulePerHour", "MegajoulesPerHour", BaseUnits.Undefined); + yield return new (PowerUnit.Megawatt, "Megawatt", "Megawatts", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PowerUnit.MetricHorsepower, "MetricHorsepower", "MetricHorsepower", BaseUnits.Undefined); + yield return new (PowerUnit.Microwatt, "Microwatt", "Microwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second)); + yield return new (PowerUnit.MillijoulePerHour, "MillijoulePerHour", "MillijoulesPerHour", BaseUnits.Undefined); + yield return new (PowerUnit.Milliwatt, "Milliwatt", "Milliwatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (PowerUnit.Nanowatt, "Nanowatt", "Nanowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second)); + yield return new (PowerUnit.Petawatt, "Petawatt", "Petawatts", BaseUnits.Undefined); + yield return new (PowerUnit.Picowatt, "Picowatt", "Picowatts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second)); + yield return new (PowerUnit.Terawatt, "Terawatt", "Terawatts", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PowerUnit.TonOfRefrigeration, "TonOfRefrigeration", "TonsOfRefrigeration", BaseUnits.Undefined); + yield return new (PowerUnit.Watt, "Watt", "Watts", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + } + } + + static Power() + { + Info = PowerInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -155,27 +202,27 @@ public Power(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Power, which is Watt. All conversions go via this value. /// - public static PowerUnit BaseUnit { get; } + public static PowerUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Power quantity. /// - public static PowerUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Watt. /// - public static Power Zero { get; } + public static Power Zero => Info.Zero; /// public static Power AdditiveIdentity => Zero; @@ -193,7 +240,7 @@ public Power(double value, UnitSystem unitSystem) public PowerUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -211,6 +258,9 @@ public Power(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs index 92e952fd10..6ee8664bbc 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerDensity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,62 +59,113 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly PowerDensityUnit? _unit; - static PowerDensity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class PowerDensityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-1, 1, -3, 0, 0, 0, 0); - BaseUnit = PowerDensityUnit.WattPerCubicMeter; - Units = Enum.GetValues(typeof(PowerDensityUnit)).Cast().ToArray(); - Zero = new PowerDensity(0, BaseUnit); - Info = new QuantityInfo("PowerDensity", - new UnitInfo[] - { - new UnitInfo(PowerDensityUnit.DecawattPerCubicFoot, "DecawattsPerCubicFoot", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.DecawattPerCubicInch, "DecawattsPerCubicInch", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.DecawattPerCubicMeter, "DecawattsPerCubicMeter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "PowerDensity"), - new UnitInfo(PowerDensityUnit.DecawattPerLiter, "DecawattsPerLiter", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.DeciwattPerCubicFoot, "DeciwattsPerCubicFoot", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.DeciwattPerCubicInch, "DeciwattsPerCubicInch", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.DeciwattPerCubicMeter, "DeciwattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Hectogram, time: DurationUnit.Second), "PowerDensity"), - new UnitInfo(PowerDensityUnit.DeciwattPerLiter, "DeciwattsPerLiter", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.GigawattPerCubicFoot, "GigawattsPerCubicFoot", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.GigawattPerCubicInch, "GigawattsPerCubicInch", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.GigawattPerCubicMeter, "GigawattsPerCubicMeter", new BaseUnits(length: LengthUnit.Nanometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "PowerDensity"), - new UnitInfo(PowerDensityUnit.GigawattPerLiter, "GigawattsPerLiter", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.KilowattPerCubicFoot, "KilowattsPerCubicFoot", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.KilowattPerCubicInch, "KilowattsPerCubicInch", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.KilowattPerCubicMeter, "KilowattsPerCubicMeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "PowerDensity"), - new UnitInfo(PowerDensityUnit.KilowattPerLiter, "KilowattsPerLiter", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.MegawattPerCubicFoot, "MegawattsPerCubicFoot", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.MegawattPerCubicInch, "MegawattsPerCubicInch", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.MegawattPerCubicMeter, "MegawattsPerCubicMeter", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "PowerDensity"), - new UnitInfo(PowerDensityUnit.MegawattPerLiter, "MegawattsPerLiter", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.MicrowattPerCubicFoot, "MicrowattsPerCubicFoot", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.MicrowattPerCubicInch, "MicrowattsPerCubicInch", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.MicrowattPerCubicMeter, "MicrowattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second), "PowerDensity"), - new UnitInfo(PowerDensityUnit.MicrowattPerLiter, "MicrowattsPerLiter", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.MilliwattPerCubicFoot, "MilliwattsPerCubicFoot", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.MilliwattPerCubicInch, "MilliwattsPerCubicInch", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.MilliwattPerCubicMeter, "MilliwattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second), "PowerDensity"), - new UnitInfo(PowerDensityUnit.MilliwattPerLiter, "MilliwattsPerLiter", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.NanowattPerCubicFoot, "NanowattsPerCubicFoot", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.NanowattPerCubicInch, "NanowattsPerCubicInch", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.NanowattPerCubicMeter, "NanowattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second), "PowerDensity"), - new UnitInfo(PowerDensityUnit.NanowattPerLiter, "NanowattsPerLiter", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.PicowattPerCubicFoot, "PicowattsPerCubicFoot", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.PicowattPerCubicInch, "PicowattsPerCubicInch", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.PicowattPerCubicMeter, "PicowattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second), "PowerDensity"), - new UnitInfo(PowerDensityUnit.PicowattPerLiter, "PicowattsPerLiter", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.TerawattPerCubicFoot, "TerawattsPerCubicFoot", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.TerawattPerCubicInch, "TerawattsPerCubicInch", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.TerawattPerCubicMeter, "TerawattsPerCubicMeter", new BaseUnits(length: LengthUnit.Picometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "PowerDensity"), - new UnitInfo(PowerDensityUnit.TerawattPerLiter, "TerawattsPerLiter", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.WattPerCubicFoot, "WattsPerCubicFoot", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.WattPerCubicInch, "WattsPerCubicInch", BaseUnits.Undefined, "PowerDensity"), - new UnitInfo(PowerDensityUnit.WattPerCubicMeter, "WattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "PowerDensity"), - new UnitInfo(PowerDensityUnit.WattPerLiter, "WattsPerLiter", BaseUnits.Undefined, "PowerDensity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public PowerDensityInfo(string name, PowerDensityUnit baseUnit, IEnumerable> unitMappings, PowerDensity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public PowerDensityInfo(string name, PowerDensityUnit baseUnit, IEnumerable> unitMappings, PowerDensity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, PowerDensity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.PowerDensity", typeof(PowerDensity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the PowerDensity quantity. + /// + /// A new instance of the class with the default settings. + public static PowerDensityInfo CreateDefault() + { + return new PowerDensityInfo(nameof(PowerDensity), DefaultBaseUnit, GetDefaultMappings(), new PowerDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the PowerDensity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static PowerDensityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new PowerDensityInfo(nameof(PowerDensity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new PowerDensity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^-1][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-1, 1, -3, 0, 0, 0, 0); + + /// + /// The default base unit of PowerDensity is WattPerCubicMeter. All conversions, as defined in the , go via this value. + /// + public static PowerDensityUnit DefaultBaseUnit { get; } = PowerDensityUnit.WattPerCubicMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for PowerDensity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (PowerDensityUnit.DecawattPerCubicFoot, "DecawattPerCubicFoot", "DecawattsPerCubicFoot", BaseUnits.Undefined); + yield return new (PowerDensityUnit.DecawattPerCubicInch, "DecawattPerCubicInch", "DecawattsPerCubicInch", BaseUnits.Undefined); + yield return new (PowerDensityUnit.DecawattPerCubicMeter, "DecawattPerCubicMeter", "DecawattsPerCubicMeter", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PowerDensityUnit.DecawattPerLiter, "DecawattPerLiter", "DecawattsPerLiter", BaseUnits.Undefined); + yield return new (PowerDensityUnit.DeciwattPerCubicFoot, "DeciwattPerCubicFoot", "DeciwattsPerCubicFoot", BaseUnits.Undefined); + yield return new (PowerDensityUnit.DeciwattPerCubicInch, "DeciwattPerCubicInch", "DeciwattsPerCubicInch", BaseUnits.Undefined); + yield return new (PowerDensityUnit.DeciwattPerCubicMeter, "DeciwattPerCubicMeter", "DeciwattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Hectogram, time: DurationUnit.Second)); + yield return new (PowerDensityUnit.DeciwattPerLiter, "DeciwattPerLiter", "DeciwattsPerLiter", BaseUnits.Undefined); + yield return new (PowerDensityUnit.GigawattPerCubicFoot, "GigawattPerCubicFoot", "GigawattsPerCubicFoot", BaseUnits.Undefined); + yield return new (PowerDensityUnit.GigawattPerCubicInch, "GigawattPerCubicInch", "GigawattsPerCubicInch", BaseUnits.Undefined); + yield return new (PowerDensityUnit.GigawattPerCubicMeter, "GigawattPerCubicMeter", "GigawattsPerCubicMeter", new BaseUnits(length: LengthUnit.Nanometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PowerDensityUnit.GigawattPerLiter, "GigawattPerLiter", "GigawattsPerLiter", BaseUnits.Undefined); + yield return new (PowerDensityUnit.KilowattPerCubicFoot, "KilowattPerCubicFoot", "KilowattsPerCubicFoot", BaseUnits.Undefined); + yield return new (PowerDensityUnit.KilowattPerCubicInch, "KilowattPerCubicInch", "KilowattsPerCubicInch", BaseUnits.Undefined); + yield return new (PowerDensityUnit.KilowattPerCubicMeter, "KilowattPerCubicMeter", "KilowattsPerCubicMeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PowerDensityUnit.KilowattPerLiter, "KilowattPerLiter", "KilowattsPerLiter", BaseUnits.Undefined); + yield return new (PowerDensityUnit.MegawattPerCubicFoot, "MegawattPerCubicFoot", "MegawattsPerCubicFoot", BaseUnits.Undefined); + yield return new (PowerDensityUnit.MegawattPerCubicInch, "MegawattPerCubicInch", "MegawattsPerCubicInch", BaseUnits.Undefined); + yield return new (PowerDensityUnit.MegawattPerCubicMeter, "MegawattPerCubicMeter", "MegawattsPerCubicMeter", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PowerDensityUnit.MegawattPerLiter, "MegawattPerLiter", "MegawattsPerLiter", BaseUnits.Undefined); + yield return new (PowerDensityUnit.MicrowattPerCubicFoot, "MicrowattPerCubicFoot", "MicrowattsPerCubicFoot", BaseUnits.Undefined); + yield return new (PowerDensityUnit.MicrowattPerCubicInch, "MicrowattPerCubicInch", "MicrowattsPerCubicInch", BaseUnits.Undefined); + yield return new (PowerDensityUnit.MicrowattPerCubicMeter, "MicrowattPerCubicMeter", "MicrowattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second)); + yield return new (PowerDensityUnit.MicrowattPerLiter, "MicrowattPerLiter", "MicrowattsPerLiter", BaseUnits.Undefined); + yield return new (PowerDensityUnit.MilliwattPerCubicFoot, "MilliwattPerCubicFoot", "MilliwattsPerCubicFoot", BaseUnits.Undefined); + yield return new (PowerDensityUnit.MilliwattPerCubicInch, "MilliwattPerCubicInch", "MilliwattsPerCubicInch", BaseUnits.Undefined); + yield return new (PowerDensityUnit.MilliwattPerCubicMeter, "MilliwattPerCubicMeter", "MilliwattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (PowerDensityUnit.MilliwattPerLiter, "MilliwattPerLiter", "MilliwattsPerLiter", BaseUnits.Undefined); + yield return new (PowerDensityUnit.NanowattPerCubicFoot, "NanowattPerCubicFoot", "NanowattsPerCubicFoot", BaseUnits.Undefined); + yield return new (PowerDensityUnit.NanowattPerCubicInch, "NanowattPerCubicInch", "NanowattsPerCubicInch", BaseUnits.Undefined); + yield return new (PowerDensityUnit.NanowattPerCubicMeter, "NanowattPerCubicMeter", "NanowattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Microgram, time: DurationUnit.Second)); + yield return new (PowerDensityUnit.NanowattPerLiter, "NanowattPerLiter", "NanowattsPerLiter", BaseUnits.Undefined); + yield return new (PowerDensityUnit.PicowattPerCubicFoot, "PicowattPerCubicFoot", "PicowattsPerCubicFoot", BaseUnits.Undefined); + yield return new (PowerDensityUnit.PicowattPerCubicInch, "PicowattPerCubicInch", "PicowattsPerCubicInch", BaseUnits.Undefined); + yield return new (PowerDensityUnit.PicowattPerCubicMeter, "PicowattPerCubicMeter", "PicowattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Nanogram, time: DurationUnit.Second)); + yield return new (PowerDensityUnit.PicowattPerLiter, "PicowattPerLiter", "PicowattsPerLiter", BaseUnits.Undefined); + yield return new (PowerDensityUnit.TerawattPerCubicFoot, "TerawattPerCubicFoot", "TerawattsPerCubicFoot", BaseUnits.Undefined); + yield return new (PowerDensityUnit.TerawattPerCubicInch, "TerawattPerCubicInch", "TerawattsPerCubicInch", BaseUnits.Undefined); + yield return new (PowerDensityUnit.TerawattPerCubicMeter, "TerawattPerCubicMeter", "TerawattsPerCubicMeter", new BaseUnits(length: LengthUnit.Picometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PowerDensityUnit.TerawattPerLiter, "TerawattPerLiter", "TerawattsPerLiter", BaseUnits.Undefined); + yield return new (PowerDensityUnit.WattPerCubicFoot, "WattPerCubicFoot", "WattsPerCubicFoot", BaseUnits.Undefined); + yield return new (PowerDensityUnit.WattPerCubicInch, "WattPerCubicInch", "WattsPerCubicInch", BaseUnits.Undefined); + yield return new (PowerDensityUnit.WattPerCubicMeter, "WattPerCubicMeter", "WattsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PowerDensityUnit.WattPerLiter, "WattPerLiter", "WattsPerLiter", BaseUnits.Undefined); + } + } + + static PowerDensity() + { + Info = PowerDensityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -156,27 +203,27 @@ public PowerDensity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of PowerDensity, which is WattPerCubicMeter. All conversions go via this value. /// - public static PowerDensityUnit BaseUnit { get; } + public static PowerDensityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the PowerDensity quantity. /// - public static PowerDensityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit WattPerCubicMeter. /// - public static PowerDensity Zero { get; } + public static PowerDensity Zero => Info.Zero; /// public static PowerDensity AdditiveIdentity => Zero; @@ -194,7 +241,7 @@ public PowerDensity(double value, UnitSystem unitSystem) public PowerDensityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -212,6 +259,9 @@ public PowerDensity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs b/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs index 71a896abfa..cee0d2f72e 100644 --- a/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PowerRatio.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,20 +59,71 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly PowerRatioUnit? _unit; - static PowerRatio() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class PowerRatioInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = PowerRatioUnit.DecibelWatt; - Units = Enum.GetValues(typeof(PowerRatioUnit)).Cast().ToArray(); - Zero = new PowerRatio(0, BaseUnit); - Info = new QuantityInfo("PowerRatio", - new UnitInfo[] - { - new UnitInfo(PowerRatioUnit.DecibelMilliwatt, "DecibelMilliwatts", BaseUnits.Undefined, "PowerRatio"), - new UnitInfo(PowerRatioUnit.DecibelWatt, "DecibelWatts", BaseUnits.Undefined, "PowerRatio"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public PowerRatioInfo(string name, PowerRatioUnit baseUnit, IEnumerable> unitMappings, PowerRatio zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public PowerRatioInfo(string name, PowerRatioUnit baseUnit, IEnumerable> unitMappings, PowerRatio zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, PowerRatio.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.PowerRatio", typeof(PowerRatio).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the PowerRatio quantity. + /// + /// A new instance of the class with the default settings. + public static PowerRatioInfo CreateDefault() + { + return new PowerRatioInfo(nameof(PowerRatio), DefaultBaseUnit, GetDefaultMappings(), new PowerRatio(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the PowerRatio quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static PowerRatioInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new PowerRatioInfo(nameof(PowerRatio), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new PowerRatio(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of PowerRatio is DecibelWatt. All conversions, as defined in the , go via this value. + /// + public static PowerRatioUnit DefaultBaseUnit { get; } = PowerRatioUnit.DecibelWatt; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for PowerRatio. + public static IEnumerable> GetDefaultMappings() + { + yield return new (PowerRatioUnit.DecibelMilliwatt, "DecibelMilliwatt", "DecibelMilliwatts", BaseUnits.Undefined); + yield return new (PowerRatioUnit.DecibelWatt, "DecibelWatt", "DecibelWatts", BaseUnits.Undefined); + } + } + + static PowerRatio() + { + Info = PowerRatioInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -100,27 +147,27 @@ public PowerRatio(double value, PowerRatioUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of PowerRatio, which is DecibelWatt. All conversions go via this value. /// - public static PowerRatioUnit BaseUnit { get; } + public static PowerRatioUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the PowerRatio quantity. /// - public static PowerRatioUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit DecibelWatt. /// - public static PowerRatio Zero { get; } + public static PowerRatio Zero => Info.Zero; /// public static PowerRatio AdditiveIdentity => Zero; @@ -138,7 +185,7 @@ public PowerRatio(double value, PowerRatioUnit unit) public PowerRatioUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -156,6 +203,9 @@ public PowerRatio(double value, PowerRatioUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs index 12bdbf77df..d470ef6f24 100644 --- a/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Pressure.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -75,65 +71,116 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly PressureUnit? _unit; - static Pressure() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class PressureInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-1, 1, -2, 0, 0, 0, 0); - BaseUnit = PressureUnit.Pascal; - Units = Enum.GetValues(typeof(PressureUnit)).Cast().ToArray(); - Zero = new Pressure(0, BaseUnit); - Info = new QuantityInfo("Pressure", - new UnitInfo[] - { - new UnitInfo(PressureUnit.Atmosphere, "Atmospheres", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Bar, "Bars", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Centibar, "Centibars", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.CentimeterOfWaterColumn, "CentimetersOfWaterColumn", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Decapascal, "Decapascals", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.Decibar, "Decibars", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.DynePerSquareCentimeter, "DynesPerSquareCentimeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.FootOfHead, "FeetOfHead", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Gigapascal, "Gigapascals", new BaseUnits(length: LengthUnit.Nanometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.Hectopascal, "Hectopascals", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.InchOfMercury, "InchesOfMercury", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.InchOfWaterColumn, "InchesOfWaterColumn", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Kilobar, "Kilobars", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.KilogramForcePerSquareCentimeter, "KilogramsForcePerSquareCentimeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.KilogramForcePerSquareMeter, "KilogramsForcePerSquareMeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.KilogramForcePerSquareMillimeter, "KilogramsForcePerSquareMillimeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.KilonewtonPerSquareCentimeter, "KilonewtonsPerSquareCentimeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.KilonewtonPerSquareMeter, "KilonewtonsPerSquareMeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.KilonewtonPerSquareMillimeter, "KilonewtonsPerSquareMillimeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Kilopascal, "Kilopascals", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.KilopoundForcePerSquareFoot, "KilopoundsForcePerSquareFoot", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.KilopoundForcePerSquareInch, "KilopoundsForcePerSquareInch", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.KilopoundForcePerSquareMil, "KilopoundsForcePerSquareMil", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Megabar, "Megabars", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.MeganewtonPerSquareMeter, "MeganewtonsPerSquareMeter", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.Megapascal, "Megapascals", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.MeterOfHead, "MetersOfHead", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.MeterOfWaterColumn, "MetersOfWaterColumn", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Microbar, "Microbars", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Micropascal, "Micropascals", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.Millibar, "Millibars", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.MillimeterOfMercury, "MillimetersOfMercury", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.MillimeterOfWaterColumn, "MillimetersOfWaterColumn", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Millipascal, "Millipascals", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.NewtonPerSquareCentimeter, "NewtonsPerSquareCentimeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.NewtonPerSquareMeter, "NewtonsPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.NewtonPerSquareMillimeter, "NewtonsPerSquareMillimeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Pascal, "Pascals", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Pressure"), - new UnitInfo(PressureUnit.PoundForcePerSquareFoot, "PoundsForcePerSquareFoot", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.PoundForcePerSquareInch, "PoundsForcePerSquareInch", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.PoundForcePerSquareMil, "PoundsForcePerSquareMil", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.PoundPerInchSecondSquared, "PoundsPerInchSecondSquared", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.TechnicalAtmosphere, "TechnicalAtmospheres", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.TonneForcePerSquareCentimeter, "TonnesForcePerSquareCentimeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.TonneForcePerSquareMeter, "TonnesForcePerSquareMeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.TonneForcePerSquareMillimeter, "TonnesForcePerSquareMillimeter", BaseUnits.Undefined, "Pressure"), - new UnitInfo(PressureUnit.Torr, "Torrs", BaseUnits.Undefined, "Pressure"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public PressureInfo(string name, PressureUnit baseUnit, IEnumerable> unitMappings, Pressure zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public PressureInfo(string name, PressureUnit baseUnit, IEnumerable> unitMappings, Pressure zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Pressure.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Pressure", typeof(Pressure).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Pressure quantity. + /// + /// A new instance of the class with the default settings. + public static PressureInfo CreateDefault() + { + return new PressureInfo(nameof(Pressure), DefaultBaseUnit, GetDefaultMappings(), new Pressure(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Pressure quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static PressureInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new PressureInfo(nameof(Pressure), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Pressure(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^-1][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-1, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of Pressure is Pascal. All conversions, as defined in the , go via this value. + /// + public static PressureUnit DefaultBaseUnit { get; } = PressureUnit.Pascal; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Pressure. + public static IEnumerable> GetDefaultMappings() + { + yield return new (PressureUnit.Atmosphere, "Atmosphere", "Atmospheres", BaseUnits.Undefined); + yield return new (PressureUnit.Bar, "Bar", "Bars", BaseUnits.Undefined); + yield return new (PressureUnit.Centibar, "Centibar", "Centibars", BaseUnits.Undefined); + yield return new (PressureUnit.CentimeterOfWaterColumn, "CentimeterOfWaterColumn", "CentimetersOfWaterColumn", BaseUnits.Undefined); + yield return new (PressureUnit.Decapascal, "Decapascal", "Decapascals", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureUnit.Decibar, "Decibar", "Decibars", BaseUnits.Undefined); + yield return new (PressureUnit.DynePerSquareCentimeter, "DynePerSquareCentimeter", "DynesPerSquareCentimeter", BaseUnits.Undefined); + yield return new (PressureUnit.FootOfHead, "FootOfHead", "FeetOfHead", BaseUnits.Undefined); + yield return new (PressureUnit.Gigapascal, "Gigapascal", "Gigapascals", new BaseUnits(length: LengthUnit.Nanometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureUnit.Hectopascal, "Hectopascal", "Hectopascals", new BaseUnits(length: LengthUnit.Centimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureUnit.InchOfMercury, "InchOfMercury", "InchesOfMercury", BaseUnits.Undefined); + yield return new (PressureUnit.InchOfWaterColumn, "InchOfWaterColumn", "InchesOfWaterColumn", BaseUnits.Undefined); + yield return new (PressureUnit.Kilobar, "Kilobar", "Kilobars", BaseUnits.Undefined); + yield return new (PressureUnit.KilogramForcePerSquareCentimeter, "KilogramForcePerSquareCentimeter", "KilogramsForcePerSquareCentimeter", BaseUnits.Undefined); + yield return new (PressureUnit.KilogramForcePerSquareMeter, "KilogramForcePerSquareMeter", "KilogramsForcePerSquareMeter", BaseUnits.Undefined); + yield return new (PressureUnit.KilogramForcePerSquareMillimeter, "KilogramForcePerSquareMillimeter", "KilogramsForcePerSquareMillimeter", BaseUnits.Undefined); + yield return new (PressureUnit.KilonewtonPerSquareCentimeter, "KilonewtonPerSquareCentimeter", "KilonewtonsPerSquareCentimeter", BaseUnits.Undefined); + yield return new (PressureUnit.KilonewtonPerSquareMeter, "KilonewtonPerSquareMeter", "KilonewtonsPerSquareMeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureUnit.KilonewtonPerSquareMillimeter, "KilonewtonPerSquareMillimeter", "KilonewtonsPerSquareMillimeter", BaseUnits.Undefined); + yield return new (PressureUnit.Kilopascal, "Kilopascal", "Kilopascals", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureUnit.KilopoundForcePerSquareFoot, "KilopoundForcePerSquareFoot", "KilopoundsForcePerSquareFoot", BaseUnits.Undefined); + yield return new (PressureUnit.KilopoundForcePerSquareInch, "KilopoundForcePerSquareInch", "KilopoundsForcePerSquareInch", BaseUnits.Undefined); + yield return new (PressureUnit.KilopoundForcePerSquareMil, "KilopoundForcePerSquareMil", "KilopoundsForcePerSquareMil", BaseUnits.Undefined); + yield return new (PressureUnit.Megabar, "Megabar", "Megabars", BaseUnits.Undefined); + yield return new (PressureUnit.MeganewtonPerSquareMeter, "MeganewtonPerSquareMeter", "MeganewtonsPerSquareMeter", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureUnit.Megapascal, "Megapascal", "Megapascals", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureUnit.MeterOfHead, "MeterOfHead", "MetersOfHead", BaseUnits.Undefined); + yield return new (PressureUnit.MeterOfWaterColumn, "MeterOfWaterColumn", "MetersOfWaterColumn", BaseUnits.Undefined); + yield return new (PressureUnit.Microbar, "Microbar", "Microbars", BaseUnits.Undefined); + yield return new (PressureUnit.Micropascal, "Micropascal", "Micropascals", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Milligram, time: DurationUnit.Second)); + yield return new (PressureUnit.Millibar, "Millibar", "Millibars", BaseUnits.Undefined); + yield return new (PressureUnit.MillimeterOfMercury, "MillimeterOfMercury", "MillimetersOfMercury", BaseUnits.Undefined); + yield return new (PressureUnit.MillimeterOfWaterColumn, "MillimeterOfWaterColumn", "MillimetersOfWaterColumn", BaseUnits.Undefined); + yield return new (PressureUnit.Millipascal, "Millipascal", "Millipascals", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Gram, time: DurationUnit.Second)); + yield return new (PressureUnit.NewtonPerSquareCentimeter, "NewtonPerSquareCentimeter", "NewtonsPerSquareCentimeter", BaseUnits.Undefined); + yield return new (PressureUnit.NewtonPerSquareMeter, "NewtonPerSquareMeter", "NewtonsPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureUnit.NewtonPerSquareMillimeter, "NewtonPerSquareMillimeter", "NewtonsPerSquareMillimeter", BaseUnits.Undefined); + yield return new (PressureUnit.Pascal, "Pascal", "Pascals", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureUnit.PoundForcePerSquareFoot, "PoundForcePerSquareFoot", "PoundsForcePerSquareFoot", BaseUnits.Undefined); + yield return new (PressureUnit.PoundForcePerSquareInch, "PoundForcePerSquareInch", "PoundsForcePerSquareInch", BaseUnits.Undefined); + yield return new (PressureUnit.PoundForcePerSquareMil, "PoundForcePerSquareMil", "PoundsForcePerSquareMil", BaseUnits.Undefined); + yield return new (PressureUnit.PoundPerInchSecondSquared, "PoundPerInchSecondSquared", "PoundsPerInchSecondSquared", BaseUnits.Undefined); + yield return new (PressureUnit.TechnicalAtmosphere, "TechnicalAtmosphere", "TechnicalAtmospheres", BaseUnits.Undefined); + yield return new (PressureUnit.TonneForcePerSquareCentimeter, "TonneForcePerSquareCentimeter", "TonnesForcePerSquareCentimeter", BaseUnits.Undefined); + yield return new (PressureUnit.TonneForcePerSquareMeter, "TonneForcePerSquareMeter", "TonnesForcePerSquareMeter", BaseUnits.Undefined); + yield return new (PressureUnit.TonneForcePerSquareMillimeter, "TonneForcePerSquareMillimeter", "TonnesForcePerSquareMillimeter", BaseUnits.Undefined); + yield return new (PressureUnit.Torr, "Torr", "Torrs", BaseUnits.Undefined); + } + } + + static Pressure() + { + Info = PressureInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -171,27 +218,27 @@ public Pressure(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Pressure, which is Pascal. All conversions go via this value. /// - public static PressureUnit BaseUnit { get; } + public static PressureUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Pressure quantity. /// - public static PressureUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Pascal. /// - public static Pressure Zero { get; } + public static Pressure Zero => Info.Zero; /// public static Pressure AdditiveIdentity => Zero; @@ -209,7 +256,7 @@ public Pressure(double value, UnitSystem unitSystem) public PressureUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -227,6 +274,9 @@ public Pressure(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs index 38533f3058..c2527912ea 100644 --- a/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/PressureChangeRate.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,36 +62,87 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly PressureChangeRateUnit? _unit; - static PressureChangeRate() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class PressureChangeRateInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-1, 1, -3, 0, 0, 0, 0); - BaseUnit = PressureChangeRateUnit.PascalPerSecond; - Units = Enum.GetValues(typeof(PressureChangeRateUnit)).Cast().ToArray(); - Zero = new PressureChangeRate(0, BaseUnit); - Info = new QuantityInfo("PressureChangeRate", - new UnitInfo[] - { - new UnitInfo(PressureChangeRateUnit.AtmospherePerSecond, "AtmospheresPerSecond", BaseUnits.Undefined, "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.BarPerMinute, "BarsPerMinute", BaseUnits.Undefined, "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.BarPerSecond, "BarsPerSecond", BaseUnits.Undefined, "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.KilopascalPerMinute, "KilopascalsPerMinute", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Minute), "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.KilopascalPerSecond, "KilopascalsPerSecond", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, "KilopoundsForcePerSquareInchPerMinute", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Kilopound, time: DurationUnit.Minute), "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, "KilopoundsForcePerSquareInchPerSecond", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Kilopound, time: DurationUnit.Second), "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.MegapascalPerMinute, "MegapascalsPerMinute", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Minute), "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.MegapascalPerSecond, "MegapascalsPerSecond", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, "MegapoundsForcePerSquareInchPerMinute", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Megapound, time: DurationUnit.Minute), "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, "MegapoundsForcePerSquareInchPerSecond", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Megapound, time: DurationUnit.Second), "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.MillibarPerMinute, "MillibarsPerMinute", BaseUnits.Undefined, "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.MillibarPerSecond, "MillibarsPerSecond", BaseUnits.Undefined, "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.MillimeterOfMercuryPerSecond, "MillimetersOfMercuryPerSecond", BaseUnits.Undefined, "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.PascalPerMinute, "PascalsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute), "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.PascalPerSecond, "PascalsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, "PoundsForcePerSquareInchPerMinute", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound, time: DurationUnit.Minute), "PressureChangeRate"), - new UnitInfo(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, "PoundsForcePerSquareInchPerSecond", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound, time: DurationUnit.Second), "PressureChangeRate"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public PressureChangeRateInfo(string name, PressureChangeRateUnit baseUnit, IEnumerable> unitMappings, PressureChangeRate zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public PressureChangeRateInfo(string name, PressureChangeRateUnit baseUnit, IEnumerable> unitMappings, PressureChangeRate zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, PressureChangeRate.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.PressureChangeRate", typeof(PressureChangeRate).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the PressureChangeRate quantity. + /// + /// A new instance of the class with the default settings. + public static PressureChangeRateInfo CreateDefault() + { + return new PressureChangeRateInfo(nameof(PressureChangeRate), DefaultBaseUnit, GetDefaultMappings(), new PressureChangeRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the PressureChangeRate quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static PressureChangeRateInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new PressureChangeRateInfo(nameof(PressureChangeRate), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new PressureChangeRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^-1][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-1, 1, -3, 0, 0, 0, 0); + + /// + /// The default base unit of PressureChangeRate is PascalPerSecond. All conversions, as defined in the , go via this value. + /// + public static PressureChangeRateUnit DefaultBaseUnit { get; } = PressureChangeRateUnit.PascalPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for PressureChangeRate. + public static IEnumerable> GetDefaultMappings() + { + yield return new (PressureChangeRateUnit.AtmospherePerSecond, "AtmospherePerSecond", "AtmospheresPerSecond", BaseUnits.Undefined); + yield return new (PressureChangeRateUnit.BarPerMinute, "BarPerMinute", "BarsPerMinute", BaseUnits.Undefined); + yield return new (PressureChangeRateUnit.BarPerSecond, "BarPerSecond", "BarsPerSecond", BaseUnits.Undefined); + yield return new (PressureChangeRateUnit.KilopascalPerMinute, "KilopascalPerMinute", "KilopascalsPerMinute", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Minute)); + yield return new (PressureChangeRateUnit.KilopascalPerSecond, "KilopascalPerSecond", "KilopascalsPerSecond", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, "KilopoundForcePerSquareInchPerMinute", "KilopoundsForcePerSquareInchPerMinute", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Kilopound, time: DurationUnit.Minute)); + yield return new (PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, "KilopoundForcePerSquareInchPerSecond", "KilopoundsForcePerSquareInchPerSecond", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Kilopound, time: DurationUnit.Second)); + yield return new (PressureChangeRateUnit.MegapascalPerMinute, "MegapascalPerMinute", "MegapascalsPerMinute", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Minute)); + yield return new (PressureChangeRateUnit.MegapascalPerSecond, "MegapascalPerSecond", "MegapascalsPerSecond", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, "MegapoundForcePerSquareInchPerMinute", "MegapoundsForcePerSquareInchPerMinute", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Megapound, time: DurationUnit.Minute)); + yield return new (PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, "MegapoundForcePerSquareInchPerSecond", "MegapoundsForcePerSquareInchPerSecond", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Megapound, time: DurationUnit.Second)); + yield return new (PressureChangeRateUnit.MillibarPerMinute, "MillibarPerMinute", "MillibarsPerMinute", BaseUnits.Undefined); + yield return new (PressureChangeRateUnit.MillibarPerSecond, "MillibarPerSecond", "MillibarsPerSecond", BaseUnits.Undefined); + yield return new (PressureChangeRateUnit.MillimeterOfMercuryPerSecond, "MillimeterOfMercuryPerSecond", "MillimetersOfMercuryPerSecond", BaseUnits.Undefined); + yield return new (PressureChangeRateUnit.PascalPerMinute, "PascalPerMinute", "PascalsPerMinute", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Minute)); + yield return new (PressureChangeRateUnit.PascalPerSecond, "PascalPerSecond", "PascalsPerSecond", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, "PoundForcePerSquareInchPerMinute", "PoundsForcePerSquareInchPerMinute", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound, time: DurationUnit.Minute)); + yield return new (PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, "PoundForcePerSquareInchPerSecond", "PoundsForcePerSquareInchPerSecond", new BaseUnits(length: LengthUnit.Inch, mass: MassUnit.Pound, time: DurationUnit.Second)); + } + } + + static PressureChangeRate() + { + Info = PressureChangeRateInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -133,27 +180,27 @@ public PressureChangeRate(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of PressureChangeRate, which is PascalPerSecond. All conversions go via this value. /// - public static PressureChangeRateUnit BaseUnit { get; } + public static PressureChangeRateUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the PressureChangeRate quantity. /// - public static PressureChangeRateUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit PascalPerSecond. /// - public static PressureChangeRate Zero { get; } + public static PressureChangeRate Zero => Info.Zero; /// public static PressureChangeRate AdditiveIdentity => Zero; @@ -171,7 +218,7 @@ public PressureChangeRate(double value, UnitSystem unitSystem) public PressureChangeRateUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -189,6 +236,9 @@ public PressureChangeRate(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDose.g.cs b/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDose.g.cs index b57f0adb9e..4da0980f57 100644 --- a/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDose.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDose.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -67,24 +63,75 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly RadiationEquivalentDoseUnit? _unit; - static RadiationEquivalentDose() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class RadiationEquivalentDoseInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 0, -2, 0, 0, 0, 0); - BaseUnit = RadiationEquivalentDoseUnit.Sievert; - Units = Enum.GetValues(typeof(RadiationEquivalentDoseUnit)).Cast().ToArray(); - Zero = new RadiationEquivalentDose(0, BaseUnit); - Info = new QuantityInfo("RadiationEquivalentDose", - new UnitInfo[] - { - new UnitInfo(RadiationEquivalentDoseUnit.Microsievert, "Microsieverts", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second), "RadiationEquivalentDose"), - new UnitInfo(RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan, "MilliroentgensEquivalentMan", BaseUnits.Undefined, "RadiationEquivalentDose"), - new UnitInfo(RadiationEquivalentDoseUnit.Millisievert, "Millisieverts", BaseUnits.Undefined, "RadiationEquivalentDose"), - new UnitInfo(RadiationEquivalentDoseUnit.Nanosievert, "Nanosieverts", BaseUnits.Undefined, "RadiationEquivalentDose"), - new UnitInfo(RadiationEquivalentDoseUnit.RoentgenEquivalentMan, "RoentgensEquivalentMan", BaseUnits.Undefined, "RadiationEquivalentDose"), - new UnitInfo(RadiationEquivalentDoseUnit.Sievert, "Sieverts", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "RadiationEquivalentDose"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public RadiationEquivalentDoseInfo(string name, RadiationEquivalentDoseUnit baseUnit, IEnumerable> unitMappings, RadiationEquivalentDose zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public RadiationEquivalentDoseInfo(string name, RadiationEquivalentDoseUnit baseUnit, IEnumerable> unitMappings, RadiationEquivalentDose zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, RadiationEquivalentDose.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.RadiationEquivalentDose", typeof(RadiationEquivalentDose).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the RadiationEquivalentDose quantity. + /// + /// A new instance of the class with the default settings. + public static RadiationEquivalentDoseInfo CreateDefault() + { + return new RadiationEquivalentDoseInfo(nameof(RadiationEquivalentDose), DefaultBaseUnit, GetDefaultMappings(), new RadiationEquivalentDose(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the RadiationEquivalentDose quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static RadiationEquivalentDoseInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new RadiationEquivalentDoseInfo(nameof(RadiationEquivalentDose), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new RadiationEquivalentDose(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 0, -2, 0, 0, 0, 0); + + /// + /// The default base unit of RadiationEquivalentDose is Sievert. All conversions, as defined in the , go via this value. + /// + public static RadiationEquivalentDoseUnit DefaultBaseUnit { get; } = RadiationEquivalentDoseUnit.Sievert; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for RadiationEquivalentDose. + public static IEnumerable> GetDefaultMappings() + { + yield return new (RadiationEquivalentDoseUnit.Microsievert, "Microsievert", "Microsieverts", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second)); + yield return new (RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan, "MilliroentgenEquivalentMan", "MilliroentgensEquivalentMan", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseUnit.Millisievert, "Millisievert", "Millisieverts", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseUnit.Nanosievert, "Nanosievert", "Nanosieverts", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseUnit.RoentgenEquivalentMan, "RoentgenEquivalentMan", "RoentgensEquivalentMan", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseUnit.Sievert, "Sievert", "Sieverts", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + } + } + + static RadiationEquivalentDose() + { + Info = RadiationEquivalentDoseInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -122,27 +169,27 @@ public RadiationEquivalentDose(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of RadiationEquivalentDose, which is Sievert. All conversions go via this value. /// - public static RadiationEquivalentDoseUnit BaseUnit { get; } + public static RadiationEquivalentDoseUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the RadiationEquivalentDose quantity. /// - public static RadiationEquivalentDoseUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Sievert. /// - public static RadiationEquivalentDose Zero { get; } + public static RadiationEquivalentDose Zero => Info.Zero; /// public static RadiationEquivalentDose AdditiveIdentity => Zero; @@ -160,7 +207,7 @@ public RadiationEquivalentDose(double value, UnitSystem unitSystem) public RadiationEquivalentDoseUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -178,6 +225,9 @@ public RadiationEquivalentDose(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDoseRate.g.cs b/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDoseRate.g.cs index 5899e3d517..097d64df63 100644 --- a/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDoseRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RadiationEquivalentDoseRate.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,28 +62,79 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly RadiationEquivalentDoseRateUnit? _unit; - static RadiationEquivalentDoseRate() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class RadiationEquivalentDoseRateInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 0, -3, 0, 0, 0, 0); - BaseUnit = RadiationEquivalentDoseRateUnit.SievertPerSecond; - Units = Enum.GetValues(typeof(RadiationEquivalentDoseRateUnit)).Cast().ToArray(); - Zero = new RadiationEquivalentDoseRate(0, BaseUnit); - Info = new QuantityInfo("RadiationEquivalentDoseRate", - new UnitInfo[] - { - new UnitInfo(RadiationEquivalentDoseRateUnit.MicrosievertPerHour, "MicrosievertsPerHour", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), - new UnitInfo(RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, "MicrosievertsPerSecond", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second), "RadiationEquivalentDoseRate"), - new UnitInfo(RadiationEquivalentDoseRateUnit.MilliroentgenEquivalentManPerHour, "MilliroentgensEquivalentManPerHour", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), - new UnitInfo(RadiationEquivalentDoseRateUnit.MillisievertPerHour, "MillisievertsPerHour", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), - new UnitInfo(RadiationEquivalentDoseRateUnit.MillisievertPerSecond, "MillisievertsPerSecond", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), - new UnitInfo(RadiationEquivalentDoseRateUnit.NanosievertPerHour, "NanosievertsPerHour", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), - new UnitInfo(RadiationEquivalentDoseRateUnit.NanosievertPerSecond, "NanosievertsPerSecond", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), - new UnitInfo(RadiationEquivalentDoseRateUnit.RoentgenEquivalentManPerHour, "RoentgensEquivalentManPerHour", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), - new UnitInfo(RadiationEquivalentDoseRateUnit.SievertPerHour, "SievertsPerHour", BaseUnits.Undefined, "RadiationEquivalentDoseRate"), - new UnitInfo(RadiationEquivalentDoseRateUnit.SievertPerSecond, "SievertsPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "RadiationEquivalentDoseRate"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public RadiationEquivalentDoseRateInfo(string name, RadiationEquivalentDoseRateUnit baseUnit, IEnumerable> unitMappings, RadiationEquivalentDoseRate zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public RadiationEquivalentDoseRateInfo(string name, RadiationEquivalentDoseRateUnit baseUnit, IEnumerable> unitMappings, RadiationEquivalentDoseRate zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, RadiationEquivalentDoseRate.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.RadiationEquivalentDoseRate", typeof(RadiationEquivalentDoseRate).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the RadiationEquivalentDoseRate quantity. + /// + /// A new instance of the class with the default settings. + public static RadiationEquivalentDoseRateInfo CreateDefault() + { + return new RadiationEquivalentDoseRateInfo(nameof(RadiationEquivalentDoseRate), DefaultBaseUnit, GetDefaultMappings(), new RadiationEquivalentDoseRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the RadiationEquivalentDoseRate quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static RadiationEquivalentDoseRateInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new RadiationEquivalentDoseRateInfo(nameof(RadiationEquivalentDoseRate), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new RadiationEquivalentDoseRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 0, -3, 0, 0, 0, 0); + + /// + /// The default base unit of RadiationEquivalentDoseRate is SievertPerSecond. All conversions, as defined in the , go via this value. + /// + public static RadiationEquivalentDoseRateUnit DefaultBaseUnit { get; } = RadiationEquivalentDoseRateUnit.SievertPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for RadiationEquivalentDoseRate. + public static IEnumerable> GetDefaultMappings() + { + yield return new (RadiationEquivalentDoseRateUnit.MicrosievertPerHour, "MicrosievertPerHour", "MicrosievertsPerHour", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseRateUnit.MicrosievertPerSecond, "MicrosievertPerSecond", "MicrosievertsPerSecond", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second)); + yield return new (RadiationEquivalentDoseRateUnit.MilliroentgenEquivalentManPerHour, "MilliroentgenEquivalentManPerHour", "MilliroentgensEquivalentManPerHour", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseRateUnit.MillisievertPerHour, "MillisievertPerHour", "MillisievertsPerHour", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseRateUnit.MillisievertPerSecond, "MillisievertPerSecond", "MillisievertsPerSecond", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseRateUnit.NanosievertPerHour, "NanosievertPerHour", "NanosievertsPerHour", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseRateUnit.NanosievertPerSecond, "NanosievertPerSecond", "NanosievertsPerSecond", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseRateUnit.RoentgenEquivalentManPerHour, "RoentgenEquivalentManPerHour", "RoentgensEquivalentManPerHour", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseRateUnit.SievertPerHour, "SievertPerHour", "SievertsPerHour", BaseUnits.Undefined); + yield return new (RadiationEquivalentDoseRateUnit.SievertPerSecond, "SievertPerSecond", "SievertsPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + } + } + + static RadiationEquivalentDoseRate() + { + Info = RadiationEquivalentDoseRateInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -125,27 +172,27 @@ public RadiationEquivalentDoseRate(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of RadiationEquivalentDoseRate, which is SievertPerSecond. All conversions go via this value. /// - public static RadiationEquivalentDoseRateUnit BaseUnit { get; } + public static RadiationEquivalentDoseRateUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the RadiationEquivalentDoseRate quantity. /// - public static RadiationEquivalentDoseRateUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit SievertPerSecond. /// - public static RadiationEquivalentDoseRate Zero { get; } + public static RadiationEquivalentDoseRate Zero => Info.Zero; /// public static RadiationEquivalentDoseRate AdditiveIdentity => Zero; @@ -163,7 +210,7 @@ public RadiationEquivalentDoseRate(double value, UnitSystem unitSystem) public RadiationEquivalentDoseRateUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -181,6 +228,9 @@ public RadiationEquivalentDoseRate(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs b/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs index 01761c4a4b..d765092f99 100644 --- a/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RadiationExposure.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,26 +59,77 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly RadiationExposureUnit? _unit; - static RadiationExposure() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class RadiationExposureInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, -1, 1, 1, 0, 0, 0); - BaseUnit = RadiationExposureUnit.CoulombPerKilogram; - Units = Enum.GetValues(typeof(RadiationExposureUnit)).Cast().ToArray(); - Zero = new RadiationExposure(0, BaseUnit); - Info = new QuantityInfo("RadiationExposure", - new UnitInfo[] - { - new UnitInfo(RadiationExposureUnit.CoulombPerKilogram, "CoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "RadiationExposure"), - new UnitInfo(RadiationExposureUnit.MicrocoulombPerKilogram, "MicrocoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere), "RadiationExposure"), - new UnitInfo(RadiationExposureUnit.Microroentgen, "Microroentgens", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere), "RadiationExposure"), - new UnitInfo(RadiationExposureUnit.MillicoulombPerKilogram, "MillicoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere), "RadiationExposure"), - new UnitInfo(RadiationExposureUnit.Milliroentgen, "Milliroentgens", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere), "RadiationExposure"), - new UnitInfo(RadiationExposureUnit.NanocoulombPerKilogram, "NanocoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Nanoampere), "RadiationExposure"), - new UnitInfo(RadiationExposureUnit.PicocoulombPerKilogram, "PicocoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Picoampere), "RadiationExposure"), - new UnitInfo(RadiationExposureUnit.Roentgen, "Roentgens", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere), "RadiationExposure"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public RadiationExposureInfo(string name, RadiationExposureUnit baseUnit, IEnumerable> unitMappings, RadiationExposure zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public RadiationExposureInfo(string name, RadiationExposureUnit baseUnit, IEnumerable> unitMappings, RadiationExposure zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, RadiationExposure.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.RadiationExposure", typeof(RadiationExposure).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the RadiationExposure quantity. + /// + /// A new instance of the class with the default settings. + public static RadiationExposureInfo CreateDefault() + { + return new RadiationExposureInfo(nameof(RadiationExposure), DefaultBaseUnit, GetDefaultMappings(), new RadiationExposure(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the RadiationExposure quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static RadiationExposureInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new RadiationExposureInfo(nameof(RadiationExposure), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new RadiationExposure(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T][M^-1][I]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, -1, 1, 1, 0, 0, 0); + + /// + /// The default base unit of RadiationExposure is CoulombPerKilogram. All conversions, as defined in the , go via this value. + /// + public static RadiationExposureUnit DefaultBaseUnit { get; } = RadiationExposureUnit.CoulombPerKilogram; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for RadiationExposure. + public static IEnumerable> GetDefaultMappings() + { + yield return new (RadiationExposureUnit.CoulombPerKilogram, "CoulombPerKilogram", "CoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + yield return new (RadiationExposureUnit.MicrocoulombPerKilogram, "MicrocoulombPerKilogram", "MicrocoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere)); + yield return new (RadiationExposureUnit.Microroentgen, "Microroentgen", "Microroentgens", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Microampere)); + yield return new (RadiationExposureUnit.MillicoulombPerKilogram, "MillicoulombPerKilogram", "MillicoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere)); + yield return new (RadiationExposureUnit.Milliroentgen, "Milliroentgen", "Milliroentgens", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Milliampere)); + yield return new (RadiationExposureUnit.NanocoulombPerKilogram, "NanocoulombPerKilogram", "NanocoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Nanoampere)); + yield return new (RadiationExposureUnit.PicocoulombPerKilogram, "PicocoulombPerKilogram", "PicocoulombsPerKilogram", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Picoampere)); + yield return new (RadiationExposureUnit.Roentgen, "Roentgen", "Roentgens", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, current: ElectricCurrentUnit.Ampere)); + } + } + + static RadiationExposure() + { + Info = RadiationExposureInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -120,27 +167,27 @@ public RadiationExposure(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of RadiationExposure, which is CoulombPerKilogram. All conversions go via this value. /// - public static RadiationExposureUnit BaseUnit { get; } + public static RadiationExposureUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the RadiationExposure quantity. /// - public static RadiationExposureUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit CoulombPerKilogram. /// - public static RadiationExposure Zero { get; } + public static RadiationExposure Zero => Info.Zero; /// public static RadiationExposure AdditiveIdentity => Zero; @@ -158,7 +205,7 @@ public RadiationExposure(double value, UnitSystem unitSystem) public RadiationExposureUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -176,6 +223,9 @@ public RadiationExposure(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Radioactivity.g.cs b/UnitsNet/GeneratedCode/Quantities/Radioactivity.g.cs index 14f51a39b3..360da26396 100644 --- a/UnitsNet/GeneratedCode/Quantities/Radioactivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Radioactivity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,47 +59,98 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly RadioactivityUnit? _unit; - static Radioactivity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class RadioactivityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, -1, 0, 0, 0, 0); - BaseUnit = RadioactivityUnit.Becquerel; - Units = Enum.GetValues(typeof(RadioactivityUnit)).Cast().ToArray(); - Zero = new Radioactivity(0, BaseUnit); - Info = new QuantityInfo("Radioactivity", - new UnitInfo[] - { - new UnitInfo(RadioactivityUnit.Becquerel, "Becquerels", new BaseUnits(time: DurationUnit.Second), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Curie, "Curies", new BaseUnits(time: DurationUnit.Second), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Exabecquerel, "Exabecquerels", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Gigabecquerel, "Gigabecquerels", new BaseUnits(time: DurationUnit.Nanosecond), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Gigacurie, "Gigacuries", new BaseUnits(time: DurationUnit.Nanosecond), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Gigarutherford, "Gigarutherfords", new BaseUnits(time: DurationUnit.Nanosecond), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Kilobecquerel, "Kilobecquerels", new BaseUnits(time: DurationUnit.Millisecond), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Kilocurie, "Kilocuries", new BaseUnits(time: DurationUnit.Millisecond), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Kilorutherford, "Kilorutherfords", new BaseUnits(time: DurationUnit.Millisecond), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Megabecquerel, "Megabecquerels", new BaseUnits(time: DurationUnit.Microsecond), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Megacurie, "Megacuries", new BaseUnits(time: DurationUnit.Microsecond), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Megarutherford, "Megarutherfords", new BaseUnits(time: DurationUnit.Microsecond), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Microbecquerel, "Microbecquerels", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Microcurie, "Microcuries", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Microrutherford, "Microrutherfords", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Millibecquerel, "Millibecquerels", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Millicurie, "Millicuries", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Millirutherford, "Millirutherfords", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Nanobecquerel, "Nanobecquerels", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Nanocurie, "Nanocuries", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Nanorutherford, "Nanorutherfords", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Petabecquerel, "Petabecquerels", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Picobecquerel, "Picobecquerels", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Picocurie, "Picocuries", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Picorutherford, "Picorutherfords", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Rutherford, "Rutherfords", new BaseUnits(time: DurationUnit.Second), "Radioactivity"), - new UnitInfo(RadioactivityUnit.Terabecquerel, "Terabecquerels", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Teracurie, "Teracuries", BaseUnits.Undefined, "Radioactivity"), - new UnitInfo(RadioactivityUnit.Terarutherford, "Terarutherfords", BaseUnits.Undefined, "Radioactivity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public RadioactivityInfo(string name, RadioactivityUnit baseUnit, IEnumerable> unitMappings, Radioactivity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public RadioactivityInfo(string name, RadioactivityUnit baseUnit, IEnumerable> unitMappings, Radioactivity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Radioactivity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Radioactivity", typeof(Radioactivity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Radioactivity quantity. + /// + /// A new instance of the class with the default settings. + public static RadioactivityInfo CreateDefault() + { + return new RadioactivityInfo(nameof(Radioactivity), DefaultBaseUnit, GetDefaultMappings(), new Radioactivity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Radioactivity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static RadioactivityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new RadioactivityInfo(nameof(Radioactivity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Radioactivity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, -1, 0, 0, 0, 0); + + /// + /// The default base unit of Radioactivity is Becquerel. All conversions, as defined in the , go via this value. + /// + public static RadioactivityUnit DefaultBaseUnit { get; } = RadioactivityUnit.Becquerel; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Radioactivity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (RadioactivityUnit.Becquerel, "Becquerel", "Becquerels", new BaseUnits(time: DurationUnit.Second)); + yield return new (RadioactivityUnit.Curie, "Curie", "Curies", new BaseUnits(time: DurationUnit.Second)); + yield return new (RadioactivityUnit.Exabecquerel, "Exabecquerel", "Exabecquerels", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Gigabecquerel, "Gigabecquerel", "Gigabecquerels", new BaseUnits(time: DurationUnit.Nanosecond)); + yield return new (RadioactivityUnit.Gigacurie, "Gigacurie", "Gigacuries", new BaseUnits(time: DurationUnit.Nanosecond)); + yield return new (RadioactivityUnit.Gigarutherford, "Gigarutherford", "Gigarutherfords", new BaseUnits(time: DurationUnit.Nanosecond)); + yield return new (RadioactivityUnit.Kilobecquerel, "Kilobecquerel", "Kilobecquerels", new BaseUnits(time: DurationUnit.Millisecond)); + yield return new (RadioactivityUnit.Kilocurie, "Kilocurie", "Kilocuries", new BaseUnits(time: DurationUnit.Millisecond)); + yield return new (RadioactivityUnit.Kilorutherford, "Kilorutherford", "Kilorutherfords", new BaseUnits(time: DurationUnit.Millisecond)); + yield return new (RadioactivityUnit.Megabecquerel, "Megabecquerel", "Megabecquerels", new BaseUnits(time: DurationUnit.Microsecond)); + yield return new (RadioactivityUnit.Megacurie, "Megacurie", "Megacuries", new BaseUnits(time: DurationUnit.Microsecond)); + yield return new (RadioactivityUnit.Megarutherford, "Megarutherford", "Megarutherfords", new BaseUnits(time: DurationUnit.Microsecond)); + yield return new (RadioactivityUnit.Microbecquerel, "Microbecquerel", "Microbecquerels", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Microcurie, "Microcurie", "Microcuries", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Microrutherford, "Microrutherford", "Microrutherfords", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Millibecquerel, "Millibecquerel", "Millibecquerels", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Millicurie, "Millicurie", "Millicuries", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Millirutherford, "Millirutherford", "Millirutherfords", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Nanobecquerel, "Nanobecquerel", "Nanobecquerels", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Nanocurie, "Nanocurie", "Nanocuries", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Nanorutherford, "Nanorutherford", "Nanorutherfords", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Petabecquerel, "Petabecquerel", "Petabecquerels", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Picobecquerel, "Picobecquerel", "Picobecquerels", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Picocurie, "Picocurie", "Picocuries", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Picorutherford, "Picorutherford", "Picorutherfords", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Rutherford, "Rutherford", "Rutherfords", new BaseUnits(time: DurationUnit.Second)); + yield return new (RadioactivityUnit.Terabecquerel, "Terabecquerel", "Terabecquerels", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Teracurie, "Teracurie", "Teracuries", BaseUnits.Undefined); + yield return new (RadioactivityUnit.Terarutherford, "Terarutherford", "Terarutherfords", BaseUnits.Undefined); + } + } + + static Radioactivity() + { + Info = RadioactivityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -141,27 +188,27 @@ public Radioactivity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Radioactivity, which is Becquerel. All conversions go via this value. /// - public static RadioactivityUnit BaseUnit { get; } + public static RadioactivityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Radioactivity quantity. /// - public static RadioactivityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Becquerel. /// - public static Radioactivity Zero { get; } + public static Radioactivity Zero => Info.Zero; /// public static Radioactivity AdditiveIdentity => Zero; @@ -179,7 +226,7 @@ public Radioactivity(double value, UnitSystem unitSystem) public RadioactivityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -197,6 +244,9 @@ public Radioactivity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs index 71dfdab69d..b5a7b3c735 100644 --- a/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Ratio.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,24 +59,75 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly RatioUnit? _unit; - static Ratio() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class RatioInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = RatioUnit.DecimalFraction; - Units = Enum.GetValues(typeof(RatioUnit)).Cast().ToArray(); - Zero = new Ratio(0, BaseUnit); - Info = new QuantityInfo("Ratio", - new UnitInfo[] - { - new UnitInfo(RatioUnit.DecimalFraction, "DecimalFractions", BaseUnits.Undefined, "Ratio"), - new UnitInfo(RatioUnit.PartPerBillion, "PartsPerBillion", BaseUnits.Undefined, "Ratio"), - new UnitInfo(RatioUnit.PartPerMillion, "PartsPerMillion", BaseUnits.Undefined, "Ratio"), - new UnitInfo(RatioUnit.PartPerThousand, "PartsPerThousand", BaseUnits.Undefined, "Ratio"), - new UnitInfo(RatioUnit.PartPerTrillion, "PartsPerTrillion", BaseUnits.Undefined, "Ratio"), - new UnitInfo(RatioUnit.Percent, "Percent", BaseUnits.Undefined, "Ratio"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public RatioInfo(string name, RatioUnit baseUnit, IEnumerable> unitMappings, Ratio zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public RatioInfo(string name, RatioUnit baseUnit, IEnumerable> unitMappings, Ratio zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Ratio.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Ratio", typeof(Ratio).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Ratio quantity. + /// + /// A new instance of the class with the default settings. + public static RatioInfo CreateDefault() + { + return new RatioInfo(nameof(Ratio), DefaultBaseUnit, GetDefaultMappings(), new Ratio(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Ratio quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static RatioInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new RatioInfo(nameof(Ratio), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Ratio(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of Ratio is DecimalFraction. All conversions, as defined in the , go via this value. + /// + public static RatioUnit DefaultBaseUnit { get; } = RatioUnit.DecimalFraction; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Ratio. + public static IEnumerable> GetDefaultMappings() + { + yield return new (RatioUnit.DecimalFraction, "DecimalFraction", "DecimalFractions", BaseUnits.Undefined); + yield return new (RatioUnit.PartPerBillion, "PartPerBillion", "PartsPerBillion", BaseUnits.Undefined); + yield return new (RatioUnit.PartPerMillion, "PartPerMillion", "PartsPerMillion", BaseUnits.Undefined); + yield return new (RatioUnit.PartPerThousand, "PartPerThousand", "PartsPerThousand", BaseUnits.Undefined); + yield return new (RatioUnit.PartPerTrillion, "PartPerTrillion", "PartsPerTrillion", BaseUnits.Undefined); + yield return new (RatioUnit.Percent, "Percent", "Percent", BaseUnits.Undefined); + } + } + + static Ratio() + { + Info = RatioInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -104,27 +151,27 @@ public Ratio(double value, RatioUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Ratio, which is DecimalFraction. All conversions go via this value. /// - public static RatioUnit BaseUnit { get; } + public static RatioUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Ratio quantity. /// - public static RatioUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit DecimalFraction. /// - public static Ratio Zero { get; } + public static Ratio Zero => Info.Zero; /// public static Ratio AdditiveIdentity => Zero; @@ -142,7 +189,7 @@ public Ratio(double value, RatioUnit unit) public RatioUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -160,6 +207,9 @@ public Ratio(double value, RatioUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs index 5c9c658d66..2d5c963626 100644 --- a/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RatioChangeRate.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,20 +59,71 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly RatioChangeRateUnit? _unit; - static RatioChangeRate() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class RatioChangeRateInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, -1, 0, 0, 0, 0); - BaseUnit = RatioChangeRateUnit.DecimalFractionPerSecond; - Units = Enum.GetValues(typeof(RatioChangeRateUnit)).Cast().ToArray(); - Zero = new RatioChangeRate(0, BaseUnit); - Info = new QuantityInfo("RatioChangeRate", - new UnitInfo[] - { - new UnitInfo(RatioChangeRateUnit.DecimalFractionPerSecond, "DecimalFractionsPerSecond", new BaseUnits(time: DurationUnit.Second), "RatioChangeRate"), - new UnitInfo(RatioChangeRateUnit.PercentPerSecond, "PercentsPerSecond", BaseUnits.Undefined, "RatioChangeRate"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public RatioChangeRateInfo(string name, RatioChangeRateUnit baseUnit, IEnumerable> unitMappings, RatioChangeRate zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public RatioChangeRateInfo(string name, RatioChangeRateUnit baseUnit, IEnumerable> unitMappings, RatioChangeRate zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, RatioChangeRate.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.RatioChangeRate", typeof(RatioChangeRate).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the RatioChangeRate quantity. + /// + /// A new instance of the class with the default settings. + public static RatioChangeRateInfo CreateDefault() + { + return new RatioChangeRateInfo(nameof(RatioChangeRate), DefaultBaseUnit, GetDefaultMappings(), new RatioChangeRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the RatioChangeRate quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static RatioChangeRateInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new RatioChangeRateInfo(nameof(RatioChangeRate), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new RatioChangeRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, -1, 0, 0, 0, 0); + + /// + /// The default base unit of RatioChangeRate is DecimalFractionPerSecond. All conversions, as defined in the , go via this value. + /// + public static RatioChangeRateUnit DefaultBaseUnit { get; } = RatioChangeRateUnit.DecimalFractionPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for RatioChangeRate. + public static IEnumerable> GetDefaultMappings() + { + yield return new (RatioChangeRateUnit.DecimalFractionPerSecond, "DecimalFractionPerSecond", "DecimalFractionsPerSecond", new BaseUnits(time: DurationUnit.Second)); + yield return new (RatioChangeRateUnit.PercentPerSecond, "PercentPerSecond", "PercentsPerSecond", BaseUnits.Undefined); + } + } + + static RatioChangeRate() + { + Info = RatioChangeRateInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -114,27 +161,27 @@ public RatioChangeRate(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of RatioChangeRate, which is DecimalFractionPerSecond. All conversions go via this value. /// - public static RatioChangeRateUnit BaseUnit { get; } + public static RatioChangeRateUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the RatioChangeRate quantity. /// - public static RatioChangeRateUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit DecimalFractionPerSecond. /// - public static RatioChangeRate Zero { get; } + public static RatioChangeRate Zero => Info.Zero; /// public static RatioChangeRate AdditiveIdentity => Zero; @@ -152,7 +199,7 @@ public RatioChangeRate(double value, UnitSystem unitSystem) public RatioChangeRateUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -170,6 +217,9 @@ public RatioChangeRate(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs index 0e8f6a6ca7..c219c6232b 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalArea.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -73,29 +69,80 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ReciprocalAreaUnit? _unit; - static ReciprocalArea() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ReciprocalAreaInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, 0, 0, 0, 0, 0, 0); - BaseUnit = ReciprocalAreaUnit.InverseSquareMeter; - Units = Enum.GetValues(typeof(ReciprocalAreaUnit)).Cast().ToArray(); - Zero = new ReciprocalArea(0, BaseUnit); - Info = new QuantityInfo("ReciprocalArea", - new UnitInfo[] - { - new UnitInfo(ReciprocalAreaUnit.InverseSquareCentimeter, "InverseSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter), "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareDecimeter, "InverseSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter), "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareFoot, "InverseSquareFeet", new BaseUnits(length: LengthUnit.Foot), "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareInch, "InverseSquareInches", new BaseUnits(length: LengthUnit.Inch), "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareKilometer, "InverseSquareKilometers", new BaseUnits(length: LengthUnit.Kilometer), "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareMeter, "InverseSquareMeters", new BaseUnits(length: LengthUnit.Meter), "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareMicrometer, "InverseSquareMicrometers", new BaseUnits(length: LengthUnit.Micrometer), "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareMile, "InverseSquareMiles", new BaseUnits(length: LengthUnit.Mile), "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareMillimeter, "InverseSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter), "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseSquareYard, "InverseSquareYards", new BaseUnits(length: LengthUnit.Yard), "ReciprocalArea"), - new UnitInfo(ReciprocalAreaUnit.InverseUsSurveySquareFoot, "InverseUsSurveySquareFeet", new BaseUnits(length: LengthUnit.UsSurveyFoot), "ReciprocalArea"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ReciprocalAreaInfo(string name, ReciprocalAreaUnit baseUnit, IEnumerable> unitMappings, ReciprocalArea zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ReciprocalAreaInfo(string name, ReciprocalAreaUnit baseUnit, IEnumerable> unitMappings, ReciprocalArea zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ReciprocalArea.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ReciprocalArea", typeof(ReciprocalArea).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ReciprocalArea quantity. + /// + /// A new instance of the class with the default settings. + public static ReciprocalAreaInfo CreateDefault() + { + return new ReciprocalAreaInfo(nameof(ReciprocalArea), DefaultBaseUnit, GetDefaultMappings(), new ReciprocalArea(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ReciprocalArea quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ReciprocalAreaInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ReciprocalAreaInfo(nameof(ReciprocalArea), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ReciprocalArea(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, 0, 0, 0, 0, 0, 0); + + /// + /// The default base unit of ReciprocalArea is InverseSquareMeter. All conversions, as defined in the , go via this value. + /// + public static ReciprocalAreaUnit DefaultBaseUnit { get; } = ReciprocalAreaUnit.InverseSquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ReciprocalArea. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ReciprocalAreaUnit.InverseSquareCentimeter, "InverseSquareCentimeter", "InverseSquareCentimeters", new BaseUnits(length: LengthUnit.Centimeter)); + yield return new (ReciprocalAreaUnit.InverseSquareDecimeter, "InverseSquareDecimeter", "InverseSquareDecimeters", new BaseUnits(length: LengthUnit.Decimeter)); + yield return new (ReciprocalAreaUnit.InverseSquareFoot, "InverseSquareFoot", "InverseSquareFeet", new BaseUnits(length: LengthUnit.Foot)); + yield return new (ReciprocalAreaUnit.InverseSquareInch, "InverseSquareInch", "InverseSquareInches", new BaseUnits(length: LengthUnit.Inch)); + yield return new (ReciprocalAreaUnit.InverseSquareKilometer, "InverseSquareKilometer", "InverseSquareKilometers", new BaseUnits(length: LengthUnit.Kilometer)); + yield return new (ReciprocalAreaUnit.InverseSquareMeter, "InverseSquareMeter", "InverseSquareMeters", new BaseUnits(length: LengthUnit.Meter)); + yield return new (ReciprocalAreaUnit.InverseSquareMicrometer, "InverseSquareMicrometer", "InverseSquareMicrometers", new BaseUnits(length: LengthUnit.Micrometer)); + yield return new (ReciprocalAreaUnit.InverseSquareMile, "InverseSquareMile", "InverseSquareMiles", new BaseUnits(length: LengthUnit.Mile)); + yield return new (ReciprocalAreaUnit.InverseSquareMillimeter, "InverseSquareMillimeter", "InverseSquareMillimeters", new BaseUnits(length: LengthUnit.Millimeter)); + yield return new (ReciprocalAreaUnit.InverseSquareYard, "InverseSquareYard", "InverseSquareYards", new BaseUnits(length: LengthUnit.Yard)); + yield return new (ReciprocalAreaUnit.InverseUsSurveySquareFoot, "InverseUsSurveySquareFoot", "InverseUsSurveySquareFeet", new BaseUnits(length: LengthUnit.UsSurveyFoot)); + } + } + + static ReciprocalArea() + { + Info = ReciprocalAreaInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -133,27 +180,27 @@ public ReciprocalArea(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ReciprocalArea, which is InverseSquareMeter. All conversions go via this value. /// - public static ReciprocalAreaUnit BaseUnit { get; } + public static ReciprocalAreaUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ReciprocalArea quantity. /// - public static ReciprocalAreaUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit InverseSquareMeter. /// - public static ReciprocalArea Zero { get; } + public static ReciprocalArea Zero => Info.Zero; /// public static ReciprocalArea AdditiveIdentity => Zero; @@ -171,7 +218,7 @@ public ReciprocalArea(double value, UnitSystem unitSystem) public ReciprocalAreaUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -189,6 +236,9 @@ public ReciprocalArea(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs index e6065e26fb..63ee2ab91b 100644 --- a/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ReciprocalLength.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -75,28 +71,79 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ReciprocalLengthUnit? _unit; - static ReciprocalLength() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ReciprocalLengthInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-1, 0, 0, 0, 0, 0, 0); - BaseUnit = ReciprocalLengthUnit.InverseMeter; - Units = Enum.GetValues(typeof(ReciprocalLengthUnit)).Cast().ToArray(); - Zero = new ReciprocalLength(0, BaseUnit); - Info = new QuantityInfo("ReciprocalLength", - new UnitInfo[] - { - new UnitInfo(ReciprocalLengthUnit.InverseCentimeter, "InverseCentimeters", new BaseUnits(length: LengthUnit.Centimeter), "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseFoot, "InverseFeet", new BaseUnits(length: LengthUnit.Foot), "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseInch, "InverseInches", new BaseUnits(length: LengthUnit.Inch), "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseMeter, "InverseMeters", new BaseUnits(length: LengthUnit.Meter), "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseMicroinch, "InverseMicroinches", new BaseUnits(length: LengthUnit.Microinch), "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseMil, "InverseMils", new BaseUnits(length: LengthUnit.Mil), "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseMile, "InverseMiles", new BaseUnits(length: LengthUnit.Mile), "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseMillimeter, "InverseMillimeters", new BaseUnits(length: LengthUnit.Millimeter), "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseUsSurveyFoot, "InverseUsSurveyFeet", new BaseUnits(length: LengthUnit.UsSurveyFoot), "ReciprocalLength"), - new UnitInfo(ReciprocalLengthUnit.InverseYard, "InverseYards", new BaseUnits(length: LengthUnit.Yard), "ReciprocalLength"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ReciprocalLengthInfo(string name, ReciprocalLengthUnit baseUnit, IEnumerable> unitMappings, ReciprocalLength zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ReciprocalLengthInfo(string name, ReciprocalLengthUnit baseUnit, IEnumerable> unitMappings, ReciprocalLength zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ReciprocalLength.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ReciprocalLength", typeof(ReciprocalLength).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ReciprocalLength quantity. + /// + /// A new instance of the class with the default settings. + public static ReciprocalLengthInfo CreateDefault() + { + return new ReciprocalLengthInfo(nameof(ReciprocalLength), DefaultBaseUnit, GetDefaultMappings(), new ReciprocalLength(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ReciprocalLength quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ReciprocalLengthInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ReciprocalLengthInfo(nameof(ReciprocalLength), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ReciprocalLength(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-1, 0, 0, 0, 0, 0, 0); + + /// + /// The default base unit of ReciprocalLength is InverseMeter. All conversions, as defined in the , go via this value. + /// + public static ReciprocalLengthUnit DefaultBaseUnit { get; } = ReciprocalLengthUnit.InverseMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ReciprocalLength. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ReciprocalLengthUnit.InverseCentimeter, "InverseCentimeter", "InverseCentimeters", new BaseUnits(length: LengthUnit.Centimeter)); + yield return new (ReciprocalLengthUnit.InverseFoot, "InverseFoot", "InverseFeet", new BaseUnits(length: LengthUnit.Foot)); + yield return new (ReciprocalLengthUnit.InverseInch, "InverseInch", "InverseInches", new BaseUnits(length: LengthUnit.Inch)); + yield return new (ReciprocalLengthUnit.InverseMeter, "InverseMeter", "InverseMeters", new BaseUnits(length: LengthUnit.Meter)); + yield return new (ReciprocalLengthUnit.InverseMicroinch, "InverseMicroinch", "InverseMicroinches", new BaseUnits(length: LengthUnit.Microinch)); + yield return new (ReciprocalLengthUnit.InverseMil, "InverseMil", "InverseMils", new BaseUnits(length: LengthUnit.Mil)); + yield return new (ReciprocalLengthUnit.InverseMile, "InverseMile", "InverseMiles", new BaseUnits(length: LengthUnit.Mile)); + yield return new (ReciprocalLengthUnit.InverseMillimeter, "InverseMillimeter", "InverseMillimeters", new BaseUnits(length: LengthUnit.Millimeter)); + yield return new (ReciprocalLengthUnit.InverseUsSurveyFoot, "InverseUsSurveyFoot", "InverseUsSurveyFeet", new BaseUnits(length: LengthUnit.UsSurveyFoot)); + yield return new (ReciprocalLengthUnit.InverseYard, "InverseYard", "InverseYards", new BaseUnits(length: LengthUnit.Yard)); + } + } + + static ReciprocalLength() + { + Info = ReciprocalLengthInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -134,27 +181,27 @@ public ReciprocalLength(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ReciprocalLength, which is InverseMeter. All conversions go via this value. /// - public static ReciprocalLengthUnit BaseUnit { get; } + public static ReciprocalLengthUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ReciprocalLength quantity. /// - public static ReciprocalLengthUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit InverseMeter. /// - public static ReciprocalLength Zero { get; } + public static ReciprocalLength Zero => Info.Zero; /// public static ReciprocalLength AdditiveIdentity => Zero; @@ -172,7 +219,7 @@ public ReciprocalLength(double value, UnitSystem unitSystem) public ReciprocalLengthUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -190,6 +237,9 @@ public ReciprocalLength(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs b/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs index 45620d538a..ed97458af0 100644 --- a/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RelativeHumidity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,19 +59,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly RelativeHumidityUnit? _unit; - static RelativeHumidity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class RelativeHumidityInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = RelativeHumidityUnit.Percent; - Units = Enum.GetValues(typeof(RelativeHumidityUnit)).Cast().ToArray(); - Zero = new RelativeHumidity(0, BaseUnit); - Info = new QuantityInfo("RelativeHumidity", - new UnitInfo[] - { - new UnitInfo(RelativeHumidityUnit.Percent, "Percent", BaseUnits.Undefined, "RelativeHumidity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public RelativeHumidityInfo(string name, RelativeHumidityUnit baseUnit, IEnumerable> unitMappings, RelativeHumidity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public RelativeHumidityInfo(string name, RelativeHumidityUnit baseUnit, IEnumerable> unitMappings, RelativeHumidity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, RelativeHumidity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.RelativeHumidity", typeof(RelativeHumidity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the RelativeHumidity quantity. + /// + /// A new instance of the class with the default settings. + public static RelativeHumidityInfo CreateDefault() + { + return new RelativeHumidityInfo(nameof(RelativeHumidity), DefaultBaseUnit, GetDefaultMappings(), new RelativeHumidity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the RelativeHumidity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static RelativeHumidityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new RelativeHumidityInfo(nameof(RelativeHumidity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new RelativeHumidity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of RelativeHumidity is Percent. All conversions, as defined in the , go via this value. + /// + public static RelativeHumidityUnit DefaultBaseUnit { get; } = RelativeHumidityUnit.Percent; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for RelativeHumidity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (RelativeHumidityUnit.Percent, "Percent", "Percent", BaseUnits.Undefined); + } + } + + static RelativeHumidity() + { + Info = RelativeHumidityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -99,27 +146,27 @@ public RelativeHumidity(double value, RelativeHumidityUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of RelativeHumidity, which is Percent. All conversions go via this value. /// - public static RelativeHumidityUnit BaseUnit { get; } + public static RelativeHumidityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the RelativeHumidity quantity. /// - public static RelativeHumidityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Percent. /// - public static RelativeHumidity Zero { get; } + public static RelativeHumidity Zero => Info.Zero; /// public static RelativeHumidity AdditiveIdentity => Zero; @@ -137,7 +184,7 @@ public RelativeHumidity(double value, RelativeHumidityUnit unit) public RelativeHumidityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -155,6 +202,9 @@ public RelativeHumidity(double value, RelativeHumidityUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs index 03fd744cf7..0405fafe95 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalAcceleration.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,22 +59,73 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly RotationalAccelerationUnit? _unit; - static RotationalAcceleration() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class RotationalAccelerationInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, -2, 0, 0, 0, 0); - BaseUnit = RotationalAccelerationUnit.RadianPerSecondSquared; - Units = Enum.GetValues(typeof(RotationalAccelerationUnit)).Cast().ToArray(); - Zero = new RotationalAcceleration(0, BaseUnit); - Info = new QuantityInfo("RotationalAcceleration", - new UnitInfo[] - { - new UnitInfo(RotationalAccelerationUnit.DegreePerSecondSquared, "DegreesPerSecondSquared", BaseUnits.Undefined, "RotationalAcceleration"), - new UnitInfo(RotationalAccelerationUnit.RadianPerSecondSquared, "RadiansPerSecondSquared", new BaseUnits(time: DurationUnit.Second), "RotationalAcceleration"), - new UnitInfo(RotationalAccelerationUnit.RevolutionPerMinutePerSecond, "RevolutionsPerMinutePerSecond", BaseUnits.Undefined, "RotationalAcceleration"), - new UnitInfo(RotationalAccelerationUnit.RevolutionPerSecondSquared, "RevolutionsPerSecondSquared", BaseUnits.Undefined, "RotationalAcceleration"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public RotationalAccelerationInfo(string name, RotationalAccelerationUnit baseUnit, IEnumerable> unitMappings, RotationalAcceleration zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public RotationalAccelerationInfo(string name, RotationalAccelerationUnit baseUnit, IEnumerable> unitMappings, RotationalAcceleration zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, RotationalAcceleration.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.RotationalAcceleration", typeof(RotationalAcceleration).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the RotationalAcceleration quantity. + /// + /// A new instance of the class with the default settings. + public static RotationalAccelerationInfo CreateDefault() + { + return new RotationalAccelerationInfo(nameof(RotationalAcceleration), DefaultBaseUnit, GetDefaultMappings(), new RotationalAcceleration(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the RotationalAcceleration quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static RotationalAccelerationInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new RotationalAccelerationInfo(nameof(RotationalAcceleration), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new RotationalAcceleration(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, -2, 0, 0, 0, 0); + + /// + /// The default base unit of RotationalAcceleration is RadianPerSecondSquared. All conversions, as defined in the , go via this value. + /// + public static RotationalAccelerationUnit DefaultBaseUnit { get; } = RotationalAccelerationUnit.RadianPerSecondSquared; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for RotationalAcceleration. + public static IEnumerable> GetDefaultMappings() + { + yield return new (RotationalAccelerationUnit.DegreePerSecondSquared, "DegreePerSecondSquared", "DegreesPerSecondSquared", BaseUnits.Undefined); + yield return new (RotationalAccelerationUnit.RadianPerSecondSquared, "RadianPerSecondSquared", "RadiansPerSecondSquared", new BaseUnits(time: DurationUnit.Second)); + yield return new (RotationalAccelerationUnit.RevolutionPerMinutePerSecond, "RevolutionPerMinutePerSecond", "RevolutionsPerMinutePerSecond", BaseUnits.Undefined); + yield return new (RotationalAccelerationUnit.RevolutionPerSecondSquared, "RevolutionPerSecondSquared", "RevolutionsPerSecondSquared", BaseUnits.Undefined); + } + } + + static RotationalAcceleration() + { + Info = RotationalAccelerationInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -116,27 +163,27 @@ public RotationalAcceleration(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of RotationalAcceleration, which is RadianPerSecondSquared. All conversions go via this value. /// - public static RotationalAccelerationUnit BaseUnit { get; } + public static RotationalAccelerationUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the RotationalAcceleration quantity. /// - public static RotationalAccelerationUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit RadianPerSecondSquared. /// - public static RotationalAcceleration Zero { get; } + public static RotationalAcceleration Zero => Info.Zero; /// public static RotationalAcceleration AdditiveIdentity => Zero; @@ -154,7 +201,7 @@ public RotationalAcceleration(double value, UnitSystem unitSystem) public RotationalAccelerationUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -172,6 +219,9 @@ public RotationalAcceleration(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs index 353f25359f..65ccfd6020 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalSpeed.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -67,31 +63,82 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly RotationalSpeedUnit? _unit; - static RotationalSpeed() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class RotationalSpeedInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, -1, 0, 0, 0, 0); - BaseUnit = RotationalSpeedUnit.RadianPerSecond; - Units = Enum.GetValues(typeof(RotationalSpeedUnit)).Cast().ToArray(); - Zero = new RotationalSpeed(0, BaseUnit); - Info = new QuantityInfo("RotationalSpeed", - new UnitInfo[] - { - new UnitInfo(RotationalSpeedUnit.CentiradianPerSecond, "CentiradiansPerSecond", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.DeciradianPerSecond, "DeciradiansPerSecond", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.DegreePerMinute, "DegreesPerMinute", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.DegreePerSecond, "DegreesPerSecond", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.MicrodegreePerSecond, "MicrodegreesPerSecond", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.MicroradianPerSecond, "MicroradiansPerSecond", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.MillidegreePerSecond, "MillidegreesPerSecond", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.MilliradianPerSecond, "MilliradiansPerSecond", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.NanodegreePerSecond, "NanodegreesPerSecond", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.NanoradianPerSecond, "NanoradiansPerSecond", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.RadianPerSecond, "RadiansPerSecond", new BaseUnits(time: DurationUnit.Second), "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.RevolutionPerMinute, "RevolutionsPerMinute", BaseUnits.Undefined, "RotationalSpeed"), - new UnitInfo(RotationalSpeedUnit.RevolutionPerSecond, "RevolutionsPerSecond", BaseUnits.Undefined, "RotationalSpeed"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public RotationalSpeedInfo(string name, RotationalSpeedUnit baseUnit, IEnumerable> unitMappings, RotationalSpeed zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public RotationalSpeedInfo(string name, RotationalSpeedUnit baseUnit, IEnumerable> unitMappings, RotationalSpeed zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, RotationalSpeed.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.RotationalSpeed", typeof(RotationalSpeed).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the RotationalSpeed quantity. + /// + /// A new instance of the class with the default settings. + public static RotationalSpeedInfo CreateDefault() + { + return new RotationalSpeedInfo(nameof(RotationalSpeed), DefaultBaseUnit, GetDefaultMappings(), new RotationalSpeed(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the RotationalSpeed quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static RotationalSpeedInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new RotationalSpeedInfo(nameof(RotationalSpeed), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new RotationalSpeed(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, -1, 0, 0, 0, 0); + + /// + /// The default base unit of RotationalSpeed is RadianPerSecond. All conversions, as defined in the , go via this value. + /// + public static RotationalSpeedUnit DefaultBaseUnit { get; } = RotationalSpeedUnit.RadianPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for RotationalSpeed. + public static IEnumerable> GetDefaultMappings() + { + yield return new (RotationalSpeedUnit.CentiradianPerSecond, "CentiradianPerSecond", "CentiradiansPerSecond", BaseUnits.Undefined); + yield return new (RotationalSpeedUnit.DeciradianPerSecond, "DeciradianPerSecond", "DeciradiansPerSecond", BaseUnits.Undefined); + yield return new (RotationalSpeedUnit.DegreePerMinute, "DegreePerMinute", "DegreesPerMinute", BaseUnits.Undefined); + yield return new (RotationalSpeedUnit.DegreePerSecond, "DegreePerSecond", "DegreesPerSecond", BaseUnits.Undefined); + yield return new (RotationalSpeedUnit.MicrodegreePerSecond, "MicrodegreePerSecond", "MicrodegreesPerSecond", BaseUnits.Undefined); + yield return new (RotationalSpeedUnit.MicroradianPerSecond, "MicroradianPerSecond", "MicroradiansPerSecond", BaseUnits.Undefined); + yield return new (RotationalSpeedUnit.MillidegreePerSecond, "MillidegreePerSecond", "MillidegreesPerSecond", BaseUnits.Undefined); + yield return new (RotationalSpeedUnit.MilliradianPerSecond, "MilliradianPerSecond", "MilliradiansPerSecond", BaseUnits.Undefined); + yield return new (RotationalSpeedUnit.NanodegreePerSecond, "NanodegreePerSecond", "NanodegreesPerSecond", BaseUnits.Undefined); + yield return new (RotationalSpeedUnit.NanoradianPerSecond, "NanoradianPerSecond", "NanoradiansPerSecond", BaseUnits.Undefined); + yield return new (RotationalSpeedUnit.RadianPerSecond, "RadianPerSecond", "RadiansPerSecond", new BaseUnits(time: DurationUnit.Second)); + yield return new (RotationalSpeedUnit.RevolutionPerMinute, "RevolutionPerMinute", "RevolutionsPerMinute", BaseUnits.Undefined); + yield return new (RotationalSpeedUnit.RevolutionPerSecond, "RevolutionPerSecond", "RevolutionsPerSecond", BaseUnits.Undefined); + } + } + + static RotationalSpeed() + { + Info = RotationalSpeedInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -129,27 +176,27 @@ public RotationalSpeed(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of RotationalSpeed, which is RadianPerSecond. All conversions go via this value. /// - public static RotationalSpeedUnit BaseUnit { get; } + public static RotationalSpeedUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the RotationalSpeed quantity. /// - public static RotationalSpeedUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit RadianPerSecond. /// - public static RotationalSpeed Zero { get; } + public static RotationalSpeed Zero => Info.Zero; /// public static RotationalSpeed AdditiveIdentity => Zero; @@ -167,7 +214,7 @@ public RotationalSpeed(double value, UnitSystem unitSystem) public RotationalSpeedUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -185,6 +232,9 @@ public RotationalSpeed(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs index a035083f0f..55a716a999 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffness.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -68,51 +64,102 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly RotationalStiffnessUnit? _unit; - static RotationalStiffness() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class RotationalStiffnessInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); - BaseUnit = RotationalStiffnessUnit.NewtonMeterPerRadian; - Units = Enum.GetValues(typeof(RotationalStiffnessUnit)).Cast().ToArray(); - Zero = new RotationalStiffness(0, BaseUnit); - Info = new QuantityInfo("RotationalStiffness", - new UnitInfo[] - { - new UnitInfo(RotationalStiffnessUnit.CentinewtonMeterPerDegree, "CentinewtonMetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, "CentinewtonMillimetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, "CentinewtonMillimetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.DecanewtonMeterPerDegree, "DecanewtonMetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, "DecanewtonMillimetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, "DecanewtonMillimetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.DecinewtonMeterPerDegree, "DecinewtonMetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, "DecinewtonMillimetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, "DecinewtonMillimetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.KilonewtonMeterPerDegree, "KilonewtonMetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.KilonewtonMeterPerRadian, "KilonewtonMetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, "KilonewtonMillimetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, "KilonewtonMillimetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, "KilopoundForceFeetPerDegrees", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.MeganewtonMeterPerDegree, "MeganewtonMetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.MeganewtonMeterPerRadian, "MeganewtonMetersPerRadian", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, "MeganewtonMillimetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.MeganewtonMillimeterPerRadian, "MeganewtonMillimetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.MicronewtonMeterPerDegree, "MicronewtonMetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, "MicronewtonMillimetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, "MicronewtonMillimetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.MillinewtonMeterPerDegree, "MillinewtonMetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, "MillinewtonMillimetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.MillinewtonMillimeterPerRadian, "MillinewtonMillimetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.NanonewtonMeterPerDegree, "NanonewtonMetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, "NanonewtonMillimetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, "NanonewtonMillimetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.NewtonMeterPerDegree, "NewtonMetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.NewtonMeterPerRadian, "NewtonMetersPerRadian", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.NewtonMillimeterPerDegree, "NewtonMillimetersPerDegree", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.NewtonMillimeterPerRadian, "NewtonMillimetersPerRadian", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.PoundForceFeetPerRadian, "PoundForceFeetPerRadian", BaseUnits.Undefined, "RotationalStiffness"), - new UnitInfo(RotationalStiffnessUnit.PoundForceFootPerDegrees, "PoundForceFeetPerDegrees", BaseUnits.Undefined, "RotationalStiffness"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public RotationalStiffnessInfo(string name, RotationalStiffnessUnit baseUnit, IEnumerable> unitMappings, RotationalStiffness zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public RotationalStiffnessInfo(string name, RotationalStiffnessUnit baseUnit, IEnumerable> unitMappings, RotationalStiffness zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, RotationalStiffness.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.RotationalStiffness", typeof(RotationalStiffness).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the RotationalStiffness quantity. + /// + /// A new instance of the class with the default settings. + public static RotationalStiffnessInfo CreateDefault() + { + return new RotationalStiffnessInfo(nameof(RotationalStiffness), DefaultBaseUnit, GetDefaultMappings(), new RotationalStiffness(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the RotationalStiffness quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static RotationalStiffnessInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new RotationalStiffnessInfo(nameof(RotationalStiffness), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new RotationalStiffness(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of RotationalStiffness is NewtonMeterPerRadian. All conversions, as defined in the , go via this value. + /// + public static RotationalStiffnessUnit DefaultBaseUnit { get; } = RotationalStiffnessUnit.NewtonMeterPerRadian; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for RotationalStiffness. + public static IEnumerable> GetDefaultMappings() + { + yield return new (RotationalStiffnessUnit.CentinewtonMeterPerDegree, "CentinewtonMeterPerDegree", "CentinewtonMetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, "CentinewtonMillimeterPerDegree", "CentinewtonMillimetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, "CentinewtonMillimeterPerRadian", "CentinewtonMillimetersPerRadian", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.DecanewtonMeterPerDegree, "DecanewtonMeterPerDegree", "DecanewtonMetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, "DecanewtonMillimeterPerDegree", "DecanewtonMillimetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, "DecanewtonMillimeterPerRadian", "DecanewtonMillimetersPerRadian", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.DecinewtonMeterPerDegree, "DecinewtonMeterPerDegree", "DecinewtonMetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, "DecinewtonMillimeterPerDegree", "DecinewtonMillimetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, "DecinewtonMillimeterPerRadian", "DecinewtonMillimetersPerRadian", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.KilonewtonMeterPerDegree, "KilonewtonMeterPerDegree", "KilonewtonMetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.KilonewtonMeterPerRadian, "KilonewtonMeterPerRadian", "KilonewtonMetersPerRadian", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, "KilonewtonMillimeterPerDegree", "KilonewtonMillimetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, "KilonewtonMillimeterPerRadian", "KilonewtonMillimetersPerRadian", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.KilopoundForceFootPerDegrees, "KilopoundForceFootPerDegrees", "KilopoundForceFeetPerDegrees", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.MeganewtonMeterPerDegree, "MeganewtonMeterPerDegree", "MeganewtonMetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.MeganewtonMeterPerRadian, "MeganewtonMeterPerRadian", "MeganewtonMetersPerRadian", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, "MeganewtonMillimeterPerDegree", "MeganewtonMillimetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.MeganewtonMillimeterPerRadian, "MeganewtonMillimeterPerRadian", "MeganewtonMillimetersPerRadian", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.MicronewtonMeterPerDegree, "MicronewtonMeterPerDegree", "MicronewtonMetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, "MicronewtonMillimeterPerDegree", "MicronewtonMillimetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, "MicronewtonMillimeterPerRadian", "MicronewtonMillimetersPerRadian", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.MillinewtonMeterPerDegree, "MillinewtonMeterPerDegree", "MillinewtonMetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, "MillinewtonMillimeterPerDegree", "MillinewtonMillimetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.MillinewtonMillimeterPerRadian, "MillinewtonMillimeterPerRadian", "MillinewtonMillimetersPerRadian", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.NanonewtonMeterPerDegree, "NanonewtonMeterPerDegree", "NanonewtonMetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, "NanonewtonMillimeterPerDegree", "NanonewtonMillimetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, "NanonewtonMillimeterPerRadian", "NanonewtonMillimetersPerRadian", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.NewtonMeterPerDegree, "NewtonMeterPerDegree", "NewtonMetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.NewtonMeterPerRadian, "NewtonMeterPerRadian", "NewtonMetersPerRadian", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (RotationalStiffnessUnit.NewtonMillimeterPerDegree, "NewtonMillimeterPerDegree", "NewtonMillimetersPerDegree", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.NewtonMillimeterPerRadian, "NewtonMillimeterPerRadian", "NewtonMillimetersPerRadian", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.PoundForceFeetPerRadian, "PoundForceFeetPerRadian", "PoundForceFeetPerRadian", BaseUnits.Undefined); + yield return new (RotationalStiffnessUnit.PoundForceFootPerDegrees, "PoundForceFootPerDegrees", "PoundForceFeetPerDegrees", BaseUnits.Undefined); + } + } + + static RotationalStiffness() + { + Info = RotationalStiffnessInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -150,27 +197,27 @@ public RotationalStiffness(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of RotationalStiffness, which is NewtonMeterPerRadian. All conversions go via this value. /// - public static RotationalStiffnessUnit BaseUnit { get; } + public static RotationalStiffnessUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the RotationalStiffness quantity. /// - public static RotationalStiffnessUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit NewtonMeterPerRadian. /// - public static RotationalStiffness Zero { get; } + public static RotationalStiffness Zero => Info.Zero; /// public static RotationalStiffness AdditiveIdentity => Zero; @@ -188,7 +235,7 @@ public RotationalStiffness(double value, UnitSystem unitSystem) public RotationalStiffnessUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -206,6 +253,9 @@ public RotationalStiffness(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs index 1c61d270bf..7d712ffa4c 100644 --- a/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/RotationalStiffnessPerLength.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,23 +62,74 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly RotationalStiffnessPerLengthUnit? _unit; - static RotationalStiffnessPerLength() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class RotationalStiffnessPerLengthInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 1, -2, 0, 0, 0, 0); - BaseUnit = RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter; - Units = Enum.GetValues(typeof(RotationalStiffnessPerLengthUnit)).Cast().ToArray(); - Zero = new RotationalStiffnessPerLength(0, BaseUnit); - Info = new QuantityInfo("RotationalStiffnessPerLength", - new UnitInfo[] - { - new UnitInfo(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, "KilonewtonMetersPerRadianPerMeter", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "RotationalStiffnessPerLength"), - new UnitInfo(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, "KilopoundForceFeetPerDegreesPerFeet", BaseUnits.Undefined, "RotationalStiffnessPerLength"), - new UnitInfo(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, "MeganewtonMetersPerRadianPerMeter", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "RotationalStiffnessPerLength"), - new UnitInfo(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, "NewtonMetersPerRadianPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "RotationalStiffnessPerLength"), - new UnitInfo(RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot, "PoundForceFeetPerDegreesPerFeet", BaseUnits.Undefined, "RotationalStiffnessPerLength"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public RotationalStiffnessPerLengthInfo(string name, RotationalStiffnessPerLengthUnit baseUnit, IEnumerable> unitMappings, RotationalStiffnessPerLength zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public RotationalStiffnessPerLengthInfo(string name, RotationalStiffnessPerLengthUnit baseUnit, IEnumerable> unitMappings, RotationalStiffnessPerLength zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, RotationalStiffnessPerLength.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.RotationalStiffnessPerLength", typeof(RotationalStiffnessPerLength).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the RotationalStiffnessPerLength quantity. + /// + /// A new instance of the class with the default settings. + public static RotationalStiffnessPerLengthInfo CreateDefault() + { + return new RotationalStiffnessPerLengthInfo(nameof(RotationalStiffnessPerLength), DefaultBaseUnit, GetDefaultMappings(), new RotationalStiffnessPerLength(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the RotationalStiffnessPerLength quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static RotationalStiffnessPerLengthInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new RotationalStiffnessPerLengthInfo(nameof(RotationalStiffnessPerLength), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new RotationalStiffnessPerLength(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of RotationalStiffnessPerLength is NewtonMeterPerRadianPerMeter. All conversions, as defined in the , go via this value. + /// + public static RotationalStiffnessPerLengthUnit DefaultBaseUnit { get; } = RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for RotationalStiffnessPerLength. + public static IEnumerable> GetDefaultMappings() + { + yield return new (RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, "KilonewtonMeterPerRadianPerMeter", "KilonewtonMetersPerRadianPerMeter", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, "KilopoundForceFootPerDegreesPerFoot", "KilopoundForceFeetPerDegreesPerFeet", BaseUnits.Undefined); + yield return new (RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, "MeganewtonMeterPerRadianPerMeter", "MeganewtonMetersPerRadianPerMeter", new BaseUnits(length: LengthUnit.Megameter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, "NewtonMeterPerRadianPerMeter", "NewtonMetersPerRadianPerMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot, "PoundForceFootPerDegreesPerFoot", "PoundForceFeetPerDegreesPerFeet", BaseUnits.Undefined); + } + } + + static RotationalStiffnessPerLength() + { + Info = RotationalStiffnessPerLengthInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -120,27 +167,27 @@ public RotationalStiffnessPerLength(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of RotationalStiffnessPerLength, which is NewtonMeterPerRadianPerMeter. All conversions go via this value. /// - public static RotationalStiffnessPerLengthUnit BaseUnit { get; } + public static RotationalStiffnessPerLengthUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the RotationalStiffnessPerLength quantity. /// - public static RotationalStiffnessPerLengthUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit NewtonMeterPerRadianPerMeter. /// - public static RotationalStiffnessPerLength Zero { get; } + public static RotationalStiffnessPerLength Zero => Info.Zero; /// public static RotationalStiffnessPerLength AdditiveIdentity => Zero; @@ -158,7 +205,7 @@ public RotationalStiffnessPerLength(double value, UnitSystem unitSystem) public RotationalStiffnessPerLengthUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -176,6 +223,9 @@ public RotationalStiffnessPerLength(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs b/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs index 168d57fd09..dcd5d5c813 100644 --- a/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Scalar.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,19 +59,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ScalarUnit? _unit; - static Scalar() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ScalarInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = ScalarUnit.Amount; - Units = Enum.GetValues(typeof(ScalarUnit)).Cast().ToArray(); - Zero = new Scalar(0, BaseUnit); - Info = new QuantityInfo("Scalar", - new UnitInfo[] - { - new UnitInfo(ScalarUnit.Amount, "Amount", BaseUnits.Undefined, "Scalar"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ScalarInfo(string name, ScalarUnit baseUnit, IEnumerable> unitMappings, Scalar zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ScalarInfo(string name, ScalarUnit baseUnit, IEnumerable> unitMappings, Scalar zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Scalar.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Scalar", typeof(Scalar).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Scalar quantity. + /// + /// A new instance of the class with the default settings. + public static ScalarInfo CreateDefault() + { + return new ScalarInfo(nameof(Scalar), DefaultBaseUnit, GetDefaultMappings(), new Scalar(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Scalar quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ScalarInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ScalarInfo(nameof(Scalar), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Scalar(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of Scalar is Amount. All conversions, as defined in the , go via this value. + /// + public static ScalarUnit DefaultBaseUnit { get; } = ScalarUnit.Amount; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Scalar. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ScalarUnit.Amount, "Amount", "Amount", BaseUnits.Undefined); + } + } + + static Scalar() + { + Info = ScalarInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -99,27 +146,27 @@ public Scalar(double value, ScalarUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Scalar, which is Amount. All conversions go via this value. /// - public static ScalarUnit BaseUnit { get; } + public static ScalarUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Scalar quantity. /// - public static ScalarUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Amount. /// - public static Scalar Zero { get; } + public static Scalar Zero => Info.Zero; /// public static Scalar AdditiveIdentity => Zero; @@ -137,7 +184,7 @@ public Scalar(double value, ScalarUnit unit) public ScalarUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -155,6 +202,9 @@ public Scalar(double value, ScalarUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs b/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs index ce4f4cf588..6d6308066e 100644 --- a/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SolidAngle.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,19 +62,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly SolidAngleUnit? _unit; - static SolidAngle() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class SolidAngleInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = SolidAngleUnit.Steradian; - Units = Enum.GetValues(typeof(SolidAngleUnit)).Cast().ToArray(); - Zero = new SolidAngle(0, BaseUnit); - Info = new QuantityInfo("SolidAngle", - new UnitInfo[] - { - new UnitInfo(SolidAngleUnit.Steradian, "Steradians", BaseUnits.Undefined, "SolidAngle"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public SolidAngleInfo(string name, SolidAngleUnit baseUnit, IEnumerable> unitMappings, SolidAngle zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public SolidAngleInfo(string name, SolidAngleUnit baseUnit, IEnumerable> unitMappings, SolidAngle zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, SolidAngle.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.SolidAngle", typeof(SolidAngle).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the SolidAngle quantity. + /// + /// A new instance of the class with the default settings. + public static SolidAngleInfo CreateDefault() + { + return new SolidAngleInfo(nameof(SolidAngle), DefaultBaseUnit, GetDefaultMappings(), new SolidAngle(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the SolidAngle quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static SolidAngleInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new SolidAngleInfo(nameof(SolidAngle), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new SolidAngle(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of SolidAngle is Steradian. All conversions, as defined in the , go via this value. + /// + public static SolidAngleUnit DefaultBaseUnit { get; } = SolidAngleUnit.Steradian; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for SolidAngle. + public static IEnumerable> GetDefaultMappings() + { + yield return new (SolidAngleUnit.Steradian, "Steradian", "Steradians", BaseUnits.Undefined); + } + } + + static SolidAngle() + { + Info = SolidAngleInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -102,27 +149,27 @@ public SolidAngle(double value, SolidAngleUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of SolidAngle, which is Steradian. All conversions go via this value. /// - public static SolidAngleUnit BaseUnit { get; } + public static SolidAngleUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the SolidAngle quantity. /// - public static SolidAngleUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Steradian. /// - public static SolidAngle Zero { get; } + public static SolidAngle Zero => Info.Zero; /// public static SolidAngle AdditiveIdentity => Zero; @@ -140,7 +187,7 @@ public SolidAngle(double value, SolidAngleUnit unit) public SolidAngleUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -158,6 +205,9 @@ public SolidAngle(double value, SolidAngleUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs index ca20c24014..25a218451f 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEnergy.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -74,48 +70,99 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly SpecificEnergyUnit? _unit; - static SpecificEnergy() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class SpecificEnergyInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 0, -2, 0, 0, 0, 0); - BaseUnit = SpecificEnergyUnit.JoulePerKilogram; - Units = Enum.GetValues(typeof(SpecificEnergyUnit)).Cast().ToArray(); - Zero = new SpecificEnergy(0, BaseUnit); - Info = new QuantityInfo("SpecificEnergy", - new UnitInfo[] - { - new UnitInfo(SpecificEnergyUnit.BtuPerPound, "BtuPerPound", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.CaloriePerGram, "CaloriesPerGram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.GigawattDayPerKilogram, "GigawattDaysPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.GigawattDayPerShortTon, "GigawattDaysPerShortTon", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.GigawattDayPerTonne, "GigawattDaysPerTonne", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.GigawattHourPerKilogram, "GigawattHoursPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.GigawattHourPerPound, "GigawattHoursPerPound", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.JoulePerKilogram, "JoulesPerKilogram", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.KilocaloriePerGram, "KilocaloriesPerGram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.KilojoulePerKilogram, "KilojoulesPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.KilowattDayPerKilogram, "KilowattDaysPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.KilowattDayPerShortTon, "KilowattDaysPerShortTon", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.KilowattDayPerTonne, "KilowattDaysPerTonne", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.KilowattHourPerKilogram, "KilowattHoursPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.KilowattHourPerPound, "KilowattHoursPerPound", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.MegajoulePerKilogram, "MegajoulesPerKilogram", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second), "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.MegaJoulePerTonne, "MegaJoulesPerTonne", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.MegawattDayPerKilogram, "MegawattDaysPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.MegawattDayPerShortTon, "MegawattDaysPerShortTon", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.MegawattDayPerTonne, "MegawattDaysPerTonne", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.MegawattHourPerKilogram, "MegawattHoursPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.MegawattHourPerPound, "MegawattHoursPerPound", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.TerawattDayPerKilogram, "TerawattDaysPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.TerawattDayPerShortTon, "TerawattDaysPerShortTon", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.TerawattDayPerTonne, "TerawattDaysPerTonne", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.WattDayPerKilogram, "WattDaysPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.WattDayPerShortTon, "WattDaysPerShortTon", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.WattDayPerTonne, "WattDaysPerTonne", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.WattHourPerKilogram, "WattHoursPerKilogram", BaseUnits.Undefined, "SpecificEnergy"), - new UnitInfo(SpecificEnergyUnit.WattHourPerPound, "WattHoursPerPound", BaseUnits.Undefined, "SpecificEnergy"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public SpecificEnergyInfo(string name, SpecificEnergyUnit baseUnit, IEnumerable> unitMappings, SpecificEnergy zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public SpecificEnergyInfo(string name, SpecificEnergyUnit baseUnit, IEnumerable> unitMappings, SpecificEnergy zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, SpecificEnergy.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.SpecificEnergy", typeof(SpecificEnergy).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the SpecificEnergy quantity. + /// + /// A new instance of the class with the default settings. + public static SpecificEnergyInfo CreateDefault() + { + return new SpecificEnergyInfo(nameof(SpecificEnergy), DefaultBaseUnit, GetDefaultMappings(), new SpecificEnergy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the SpecificEnergy quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static SpecificEnergyInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new SpecificEnergyInfo(nameof(SpecificEnergy), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new SpecificEnergy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 0, -2, 0, 0, 0, 0); + + /// + /// The default base unit of SpecificEnergy is JoulePerKilogram. All conversions, as defined in the , go via this value. + /// + public static SpecificEnergyUnit DefaultBaseUnit { get; } = SpecificEnergyUnit.JoulePerKilogram; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for SpecificEnergy. + public static IEnumerable> GetDefaultMappings() + { + yield return new (SpecificEnergyUnit.BtuPerPound, "BtuPerPound", "BtuPerPound", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.CaloriePerGram, "CaloriePerGram", "CaloriesPerGram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.GigawattDayPerKilogram, "GigawattDayPerKilogram", "GigawattDaysPerKilogram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.GigawattDayPerShortTon, "GigawattDayPerShortTon", "GigawattDaysPerShortTon", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.GigawattDayPerTonne, "GigawattDayPerTonne", "GigawattDaysPerTonne", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.GigawattHourPerKilogram, "GigawattHourPerKilogram", "GigawattHoursPerKilogram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.GigawattHourPerPound, "GigawattHourPerPound", "GigawattHoursPerPound", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.JoulePerKilogram, "JoulePerKilogram", "JoulesPerKilogram", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + yield return new (SpecificEnergyUnit.KilocaloriePerGram, "KilocaloriePerGram", "KilocaloriesPerGram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.KilojoulePerKilogram, "KilojoulePerKilogram", "KilojoulesPerKilogram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.KilowattDayPerKilogram, "KilowattDayPerKilogram", "KilowattDaysPerKilogram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.KilowattDayPerShortTon, "KilowattDayPerShortTon", "KilowattDaysPerShortTon", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.KilowattDayPerTonne, "KilowattDayPerTonne", "KilowattDaysPerTonne", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.KilowattHourPerKilogram, "KilowattHourPerKilogram", "KilowattHoursPerKilogram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.KilowattHourPerPound, "KilowattHourPerPound", "KilowattHoursPerPound", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.MegajoulePerKilogram, "MegajoulePerKilogram", "MegajoulesPerKilogram", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second)); + yield return new (SpecificEnergyUnit.MegaJoulePerTonne, "MegaJoulePerTonne", "MegaJoulesPerTonne", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.MegawattDayPerKilogram, "MegawattDayPerKilogram", "MegawattDaysPerKilogram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.MegawattDayPerShortTon, "MegawattDayPerShortTon", "MegawattDaysPerShortTon", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.MegawattDayPerTonne, "MegawattDayPerTonne", "MegawattDaysPerTonne", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.MegawattHourPerKilogram, "MegawattHourPerKilogram", "MegawattHoursPerKilogram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.MegawattHourPerPound, "MegawattHourPerPound", "MegawattHoursPerPound", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.TerawattDayPerKilogram, "TerawattDayPerKilogram", "TerawattDaysPerKilogram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.TerawattDayPerShortTon, "TerawattDayPerShortTon", "TerawattDaysPerShortTon", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.TerawattDayPerTonne, "TerawattDayPerTonne", "TerawattDaysPerTonne", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.WattDayPerKilogram, "WattDayPerKilogram", "WattDaysPerKilogram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.WattDayPerShortTon, "WattDayPerShortTon", "WattDaysPerShortTon", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.WattDayPerTonne, "WattDayPerTonne", "WattDaysPerTonne", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.WattHourPerKilogram, "WattHourPerKilogram", "WattHoursPerKilogram", BaseUnits.Undefined); + yield return new (SpecificEnergyUnit.WattHourPerPound, "WattHourPerPound", "WattHoursPerPound", BaseUnits.Undefined); + } + } + + static SpecificEnergy() + { + Info = SpecificEnergyInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -153,27 +200,27 @@ public SpecificEnergy(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of SpecificEnergy, which is JoulePerKilogram. All conversions go via this value. /// - public static SpecificEnergyUnit BaseUnit { get; } + public static SpecificEnergyUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the SpecificEnergy quantity. /// - public static SpecificEnergyUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerKilogram. /// - public static SpecificEnergy Zero { get; } + public static SpecificEnergy Zero => Info.Zero; /// public static SpecificEnergy AdditiveIdentity => Zero; @@ -191,7 +238,7 @@ public SpecificEnergy(double value, UnitSystem unitSystem) public SpecificEnergyUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -209,6 +256,9 @@ public SpecificEnergy(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs index b27dc303be..9ed000d513 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificEntropy.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -67,27 +63,78 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly SpecificEntropyUnit? _unit; - static SpecificEntropy() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class SpecificEntropyInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 0, -2, 0, -1, 0, 0); - BaseUnit = SpecificEntropyUnit.JoulePerKilogramKelvin; - Units = Enum.GetValues(typeof(SpecificEntropyUnit)).Cast().ToArray(); - Zero = new SpecificEntropy(0, BaseUnit); - Info = new QuantityInfo("SpecificEntropy", - new UnitInfo[] - { - new UnitInfo(SpecificEntropyUnit.BtuPerPoundFahrenheit, "BtusPerPoundFahrenheit", BaseUnits.Undefined, "SpecificEntropy"), - new UnitInfo(SpecificEntropyUnit.CaloriePerGramKelvin, "CaloriesPerGramKelvin", BaseUnits.Undefined, "SpecificEntropy"), - new UnitInfo(SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, "JoulesPerKilogramDegreeCelsius", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "SpecificEntropy"), - new UnitInfo(SpecificEntropyUnit.JoulePerKilogramKelvin, "JoulesPerKilogramKelvin", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "SpecificEntropy"), - new UnitInfo(SpecificEntropyUnit.KilocaloriePerGramKelvin, "KilocaloriesPerGramKelvin", BaseUnits.Undefined, "SpecificEntropy"), - new UnitInfo(SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius, "KilojoulesPerKilogramDegreeCelsius", BaseUnits.Undefined, "SpecificEntropy"), - new UnitInfo(SpecificEntropyUnit.KilojoulePerKilogramKelvin, "KilojoulesPerKilogramKelvin", BaseUnits.Undefined, "SpecificEntropy"), - new UnitInfo(SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius, "MegajoulesPerKilogramDegreeCelsius", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "SpecificEntropy"), - new UnitInfo(SpecificEntropyUnit.MegajoulePerKilogramKelvin, "MegajoulesPerKilogramKelvin", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "SpecificEntropy"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public SpecificEntropyInfo(string name, SpecificEntropyUnit baseUnit, IEnumerable> unitMappings, SpecificEntropy zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public SpecificEntropyInfo(string name, SpecificEntropyUnit baseUnit, IEnumerable> unitMappings, SpecificEntropy zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, SpecificEntropy.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.SpecificEntropy", typeof(SpecificEntropy).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the SpecificEntropy quantity. + /// + /// A new instance of the class with the default settings. + public static SpecificEntropyInfo CreateDefault() + { + return new SpecificEntropyInfo(nameof(SpecificEntropy), DefaultBaseUnit, GetDefaultMappings(), new SpecificEntropy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the SpecificEntropy quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static SpecificEntropyInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new SpecificEntropyInfo(nameof(SpecificEntropy), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new SpecificEntropy(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2][Θ^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 0, -2, 0, -1, 0, 0); + + /// + /// The default base unit of SpecificEntropy is JoulePerKilogramKelvin. All conversions, as defined in the , go via this value. + /// + public static SpecificEntropyUnit DefaultBaseUnit { get; } = SpecificEntropyUnit.JoulePerKilogramKelvin; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for SpecificEntropy. + public static IEnumerable> GetDefaultMappings() + { + yield return new (SpecificEntropyUnit.BtuPerPoundFahrenheit, "BtuPerPoundFahrenheit", "BtusPerPoundFahrenheit", BaseUnits.Undefined); + yield return new (SpecificEntropyUnit.CaloriePerGramKelvin, "CaloriePerGramKelvin", "CaloriesPerGramKelvin", BaseUnits.Undefined); + yield return new (SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, "JoulePerKilogramDegreeCelsius", "JoulesPerKilogramDegreeCelsius", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (SpecificEntropyUnit.JoulePerKilogramKelvin, "JoulePerKilogramKelvin", "JoulesPerKilogramKelvin", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin)); + yield return new (SpecificEntropyUnit.KilocaloriePerGramKelvin, "KilocaloriePerGramKelvin", "KilocaloriesPerGramKelvin", BaseUnits.Undefined); + yield return new (SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius, "KilojoulePerKilogramDegreeCelsius", "KilojoulesPerKilogramDegreeCelsius", BaseUnits.Undefined); + yield return new (SpecificEntropyUnit.KilojoulePerKilogramKelvin, "KilojoulePerKilogramKelvin", "KilojoulesPerKilogramKelvin", BaseUnits.Undefined); + yield return new (SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius, "MegajoulePerKilogramDegreeCelsius", "MegajoulesPerKilogramDegreeCelsius", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (SpecificEntropyUnit.MegajoulePerKilogramKelvin, "MegajoulePerKilogramKelvin", "MegajoulesPerKilogramKelvin", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin)); + } + } + + static SpecificEntropy() + { + Info = SpecificEntropyInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -125,27 +172,27 @@ public SpecificEntropy(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of SpecificEntropy, which is JoulePerKilogramKelvin. All conversions go via this value. /// - public static SpecificEntropyUnit BaseUnit { get; } + public static SpecificEntropyUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the SpecificEntropy quantity. /// - public static SpecificEntropyUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerKilogramKelvin. /// - public static SpecificEntropy Zero { get; } + public static SpecificEntropy Zero => Info.Zero; /// public static SpecificEntropy AdditiveIdentity => Zero; @@ -163,7 +210,7 @@ public SpecificEntropy(double value, UnitSystem unitSystem) public SpecificEntropyUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -181,6 +228,9 @@ public SpecificEntropy(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs index d824513537..e401943e42 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificFuelConsumption.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,22 +62,73 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly SpecificFuelConsumptionUnit? _unit; - static SpecificFuelConsumption() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class SpecificFuelConsumptionInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-1, 0, 1, 0, 0, 0, 0); - BaseUnit = SpecificFuelConsumptionUnit.GramPerKilonewtonSecond; - Units = Enum.GetValues(typeof(SpecificFuelConsumptionUnit)).Cast().ToArray(); - Zero = new SpecificFuelConsumption(0, BaseUnit); - Info = new QuantityInfo("SpecificFuelConsumption", - new UnitInfo[] - { - new UnitInfo(SpecificFuelConsumptionUnit.GramPerKilonewtonSecond, "GramsPerKilonewtonSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "SpecificFuelConsumption"), - new UnitInfo(SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, "KilogramsPerKilogramForceHour", BaseUnits.Undefined, "SpecificFuelConsumption"), - new UnitInfo(SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond, "KilogramsPerKilonewtonSecond", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second), "SpecificFuelConsumption"), - new UnitInfo(SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour, "PoundsMassPerPoundForceHour", BaseUnits.Undefined, "SpecificFuelConsumption"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public SpecificFuelConsumptionInfo(string name, SpecificFuelConsumptionUnit baseUnit, IEnumerable> unitMappings, SpecificFuelConsumption zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public SpecificFuelConsumptionInfo(string name, SpecificFuelConsumptionUnit baseUnit, IEnumerable> unitMappings, SpecificFuelConsumption zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, SpecificFuelConsumption.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.SpecificFuelConsumption", typeof(SpecificFuelConsumption).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the SpecificFuelConsumption quantity. + /// + /// A new instance of the class with the default settings. + public static SpecificFuelConsumptionInfo CreateDefault() + { + return new SpecificFuelConsumptionInfo(nameof(SpecificFuelConsumption), DefaultBaseUnit, GetDefaultMappings(), new SpecificFuelConsumption(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the SpecificFuelConsumption quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static SpecificFuelConsumptionInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new SpecificFuelConsumptionInfo(nameof(SpecificFuelConsumption), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new SpecificFuelConsumption(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T][L^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-1, 0, 1, 0, 0, 0, 0); + + /// + /// The default base unit of SpecificFuelConsumption is GramPerKilonewtonSecond. All conversions, as defined in the , go via this value. + /// + public static SpecificFuelConsumptionUnit DefaultBaseUnit { get; } = SpecificFuelConsumptionUnit.GramPerKilonewtonSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for SpecificFuelConsumption. + public static IEnumerable> GetDefaultMappings() + { + yield return new (SpecificFuelConsumptionUnit.GramPerKilonewtonSecond, "GramPerKilonewtonSecond", "GramsPerKilonewtonSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + yield return new (SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, "KilogramPerKilogramForceHour", "KilogramsPerKilogramForceHour", BaseUnits.Undefined); + yield return new (SpecificFuelConsumptionUnit.KilogramPerKilonewtonSecond, "KilogramPerKilonewtonSecond", "KilogramsPerKilonewtonSecond", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second)); + yield return new (SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour, "PoundMassPerPoundForceHour", "PoundsMassPerPoundForceHour", BaseUnits.Undefined); + } + } + + static SpecificFuelConsumption() + { + Info = SpecificFuelConsumptionInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -119,27 +166,27 @@ public SpecificFuelConsumption(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of SpecificFuelConsumption, which is GramPerKilonewtonSecond. All conversions go via this value. /// - public static SpecificFuelConsumptionUnit BaseUnit { get; } + public static SpecificFuelConsumptionUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the SpecificFuelConsumption quantity. /// - public static SpecificFuelConsumptionUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit GramPerKilonewtonSecond. /// - public static SpecificFuelConsumption Zero { get; } + public static SpecificFuelConsumption Zero => Info.Zero; /// public static SpecificFuelConsumption AdditiveIdentity => Zero; @@ -157,7 +204,7 @@ public SpecificFuelConsumption(double value, UnitSystem unitSystem) public SpecificFuelConsumptionUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -175,6 +222,9 @@ public SpecificFuelConsumption(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs index 07f1994a8a..cd4d24d793 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificVolume.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,21 +62,72 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly SpecificVolumeUnit? _unit; - static SpecificVolume() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class SpecificVolumeInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(3, -1, 0, 0, 0, 0, 0); - BaseUnit = SpecificVolumeUnit.CubicMeterPerKilogram; - Units = Enum.GetValues(typeof(SpecificVolumeUnit)).Cast().ToArray(); - Zero = new SpecificVolume(0, BaseUnit); - Info = new QuantityInfo("SpecificVolume", - new UnitInfo[] - { - new UnitInfo(SpecificVolumeUnit.CubicFootPerPound, "CubicFeetPerPound", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound), "SpecificVolume"), - new UnitInfo(SpecificVolumeUnit.CubicMeterPerKilogram, "CubicMetersPerKilogram", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram), "SpecificVolume"), - new UnitInfo(SpecificVolumeUnit.MillicubicMeterPerKilogram, "MillicubicMetersPerKilogram", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram), "SpecificVolume"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public SpecificVolumeInfo(string name, SpecificVolumeUnit baseUnit, IEnumerable> unitMappings, SpecificVolume zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public SpecificVolumeInfo(string name, SpecificVolumeUnit baseUnit, IEnumerable> unitMappings, SpecificVolume zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, SpecificVolume.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.SpecificVolume", typeof(SpecificVolume).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the SpecificVolume quantity. + /// + /// A new instance of the class with the default settings. + public static SpecificVolumeInfo CreateDefault() + { + return new SpecificVolumeInfo(nameof(SpecificVolume), DefaultBaseUnit, GetDefaultMappings(), new SpecificVolume(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the SpecificVolume quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static SpecificVolumeInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new SpecificVolumeInfo(nameof(SpecificVolume), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new SpecificVolume(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^3][M^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(3, -1, 0, 0, 0, 0, 0); + + /// + /// The default base unit of SpecificVolume is CubicMeterPerKilogram. All conversions, as defined in the , go via this value. + /// + public static SpecificVolumeUnit DefaultBaseUnit { get; } = SpecificVolumeUnit.CubicMeterPerKilogram; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for SpecificVolume. + public static IEnumerable> GetDefaultMappings() + { + yield return new (SpecificVolumeUnit.CubicFootPerPound, "CubicFootPerPound", "CubicFeetPerPound", new BaseUnits(length: LengthUnit.Foot, mass: MassUnit.Pound)); + yield return new (SpecificVolumeUnit.CubicMeterPerKilogram, "CubicMeterPerKilogram", "CubicMetersPerKilogram", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram)); + yield return new (SpecificVolumeUnit.MillicubicMeterPerKilogram, "MillicubicMeterPerKilogram", "MillicubicMetersPerKilogram", new BaseUnits(length: LengthUnit.Decimeter, mass: MassUnit.Kilogram)); + } + } + + static SpecificVolume() + { + Info = SpecificVolumeInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -118,27 +165,27 @@ public SpecificVolume(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of SpecificVolume, which is CubicMeterPerKilogram. All conversions go via this value. /// - public static SpecificVolumeUnit BaseUnit { get; } + public static SpecificVolumeUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the SpecificVolume quantity. /// - public static SpecificVolumeUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit CubicMeterPerKilogram. /// - public static SpecificVolume Zero { get; } + public static SpecificVolume Zero => Info.Zero; /// public static SpecificVolume AdditiveIdentity => Zero; @@ -156,7 +203,7 @@ public SpecificVolume(double value, UnitSystem unitSystem) public SpecificVolumeUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -174,6 +221,9 @@ public SpecificVolume(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs index d8551976b7..caf4515533 100644 --- a/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/SpecificWeight.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -72,35 +68,86 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly SpecificWeightUnit? _unit; - static SpecificWeight() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class SpecificWeightInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-2, 1, -2, 0, 0, 0, 0); - BaseUnit = SpecificWeightUnit.NewtonPerCubicMeter; - Units = Enum.GetValues(typeof(SpecificWeightUnit)).Cast().ToArray(); - Zero = new SpecificWeight(0, BaseUnit); - Info = new QuantityInfo("SpecificWeight", - new UnitInfo[] - { - new UnitInfo(SpecificWeightUnit.KilogramForcePerCubicCentimeter, "KilogramsForcePerCubicCentimeter", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.KilogramForcePerCubicMeter, "KilogramsForcePerCubicMeter", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.KilogramForcePerCubicMillimeter, "KilogramsForcePerCubicMillimeter", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.KilonewtonPerCubicCentimeter, "KilonewtonsPerCubicCentimeter", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.KilonewtonPerCubicMeter, "KilonewtonsPerCubicMeter", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.KilonewtonPerCubicMillimeter, "KilonewtonsPerCubicMillimeter", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.KilopoundForcePerCubicFoot, "KilopoundsForcePerCubicFoot", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.KilopoundForcePerCubicInch, "KilopoundsForcePerCubicInch", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.MeganewtonPerCubicMeter, "MeganewtonsPerCubicMeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.NewtonPerCubicCentimeter, "NewtonsPerCubicCentimeter", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.NewtonPerCubicMeter, "NewtonsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.NewtonPerCubicMillimeter, "NewtonsPerCubicMillimeter", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.PoundForcePerCubicFoot, "PoundsForcePerCubicFoot", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.PoundForcePerCubicInch, "PoundsForcePerCubicInch", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.TonneForcePerCubicCentimeter, "TonnesForcePerCubicCentimeter", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.TonneForcePerCubicMeter, "TonnesForcePerCubicMeter", BaseUnits.Undefined, "SpecificWeight"), - new UnitInfo(SpecificWeightUnit.TonneForcePerCubicMillimeter, "TonnesForcePerCubicMillimeter", BaseUnits.Undefined, "SpecificWeight"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public SpecificWeightInfo(string name, SpecificWeightUnit baseUnit, IEnumerable> unitMappings, SpecificWeight zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public SpecificWeightInfo(string name, SpecificWeightUnit baseUnit, IEnumerable> unitMappings, SpecificWeight zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, SpecificWeight.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.SpecificWeight", typeof(SpecificWeight).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the SpecificWeight quantity. + /// + /// A new instance of the class with the default settings. + public static SpecificWeightInfo CreateDefault() + { + return new SpecificWeightInfo(nameof(SpecificWeight), DefaultBaseUnit, GetDefaultMappings(), new SpecificWeight(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the SpecificWeight quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static SpecificWeightInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new SpecificWeightInfo(nameof(SpecificWeight), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new SpecificWeight(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^-2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-2, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of SpecificWeight is NewtonPerCubicMeter. All conversions, as defined in the , go via this value. + /// + public static SpecificWeightUnit DefaultBaseUnit { get; } = SpecificWeightUnit.NewtonPerCubicMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for SpecificWeight. + public static IEnumerable> GetDefaultMappings() + { + yield return new (SpecificWeightUnit.KilogramForcePerCubicCentimeter, "KilogramForcePerCubicCentimeter", "KilogramsForcePerCubicCentimeter", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.KilogramForcePerCubicMeter, "KilogramForcePerCubicMeter", "KilogramsForcePerCubicMeter", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.KilogramForcePerCubicMillimeter, "KilogramForcePerCubicMillimeter", "KilogramsForcePerCubicMillimeter", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.KilonewtonPerCubicCentimeter, "KilonewtonPerCubicCentimeter", "KilonewtonsPerCubicCentimeter", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.KilonewtonPerCubicMeter, "KilonewtonPerCubicMeter", "KilonewtonsPerCubicMeter", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.KilonewtonPerCubicMillimeter, "KilonewtonPerCubicMillimeter", "KilonewtonsPerCubicMillimeter", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.KilopoundForcePerCubicFoot, "KilopoundForcePerCubicFoot", "KilopoundsForcePerCubicFoot", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.KilopoundForcePerCubicInch, "KilopoundForcePerCubicInch", "KilopoundsForcePerCubicInch", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.MeganewtonPerCubicMeter, "MeganewtonPerCubicMeter", "MeganewtonsPerCubicMeter", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (SpecificWeightUnit.NewtonPerCubicCentimeter, "NewtonPerCubicCentimeter", "NewtonsPerCubicCentimeter", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.NewtonPerCubicMeter, "NewtonPerCubicMeter", "NewtonsPerCubicMeter", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (SpecificWeightUnit.NewtonPerCubicMillimeter, "NewtonPerCubicMillimeter", "NewtonsPerCubicMillimeter", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.PoundForcePerCubicFoot, "PoundForcePerCubicFoot", "PoundsForcePerCubicFoot", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.PoundForcePerCubicInch, "PoundForcePerCubicInch", "PoundsForcePerCubicInch", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.TonneForcePerCubicCentimeter, "TonneForcePerCubicCentimeter", "TonnesForcePerCubicCentimeter", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.TonneForcePerCubicMeter, "TonneForcePerCubicMeter", "TonnesForcePerCubicMeter", BaseUnits.Undefined); + yield return new (SpecificWeightUnit.TonneForcePerCubicMillimeter, "TonneForcePerCubicMillimeter", "TonnesForcePerCubicMillimeter", BaseUnits.Undefined); + } + } + + static SpecificWeight() + { + Info = SpecificWeightInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -138,27 +185,27 @@ public SpecificWeight(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of SpecificWeight, which is NewtonPerCubicMeter. All conversions go via this value. /// - public static SpecificWeightUnit BaseUnit { get; } + public static SpecificWeightUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the SpecificWeight quantity. /// - public static SpecificWeightUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit NewtonPerCubicMeter. /// - public static SpecificWeight Zero { get; } + public static SpecificWeight Zero => Info.Zero; /// public static SpecificWeight AdditiveIdentity => Zero; @@ -176,7 +223,7 @@ public SpecificWeight(double value, UnitSystem unitSystem) public SpecificWeightUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -194,6 +241,9 @@ public SpecificWeight(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs index 73885a877c..4787388e20 100644 --- a/UnitsNet/GeneratedCode/Quantities/Speed.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Speed.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -73,51 +69,102 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly SpeedUnit? _unit; - static Speed() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class SpeedInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 0, -1, 0, 0, 0, 0); - BaseUnit = SpeedUnit.MeterPerSecond; - Units = Enum.GetValues(typeof(SpeedUnit)).Cast().ToArray(); - Zero = new Speed(0, BaseUnit); - Info = new QuantityInfo("Speed", - new UnitInfo[] - { - new UnitInfo(SpeedUnit.CentimeterPerHour, "CentimetersPerHour", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Hour), "Speed"), - new UnitInfo(SpeedUnit.CentimeterPerMinute, "CentimetersPerMinute", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Minute), "Speed"), - new UnitInfo(SpeedUnit.CentimeterPerSecond, "CentimetersPerSecond", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Second), "Speed"), - new UnitInfo(SpeedUnit.DecimeterPerMinute, "DecimetersPerMinute", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Minute), "Speed"), - new UnitInfo(SpeedUnit.DecimeterPerSecond, "DecimetersPerSecond", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Second), "Speed"), - new UnitInfo(SpeedUnit.FootPerHour, "FeetPerHour", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Hour), "Speed"), - new UnitInfo(SpeedUnit.FootPerMinute, "FeetPerMinute", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Minute), "Speed"), - new UnitInfo(SpeedUnit.FootPerSecond, "FeetPerSecond", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second), "Speed"), - new UnitInfo(SpeedUnit.InchPerHour, "InchesPerHour", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Hour), "Speed"), - new UnitInfo(SpeedUnit.InchPerMinute, "InchesPerMinute", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Minute), "Speed"), - new UnitInfo(SpeedUnit.InchPerSecond, "InchesPerSecond", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Second), "Speed"), - new UnitInfo(SpeedUnit.KilometerPerHour, "KilometersPerHour", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Hour), "Speed"), - new UnitInfo(SpeedUnit.KilometerPerMinute, "KilometersPerMinute", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Minute), "Speed"), - new UnitInfo(SpeedUnit.KilometerPerSecond, "KilometersPerSecond", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second), "Speed"), - new UnitInfo(SpeedUnit.Knot, "Knots", new BaseUnits(length: LengthUnit.NauticalMile, time: DurationUnit.Hour), "Speed"), - new UnitInfo(SpeedUnit.Mach, "Mach", BaseUnits.Undefined, "Speed"), - new UnitInfo(SpeedUnit.MeterPerHour, "MetersPerHour", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Hour), "Speed"), - new UnitInfo(SpeedUnit.MeterPerMinute, "MetersPerMinute", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Minute), "Speed"), - new UnitInfo(SpeedUnit.MeterPerSecond, "MetersPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "Speed"), - new UnitInfo(SpeedUnit.MicrometerPerMinute, "MicrometersPerMinute", new BaseUnits(length: LengthUnit.Micrometer, time: DurationUnit.Minute), "Speed"), - new UnitInfo(SpeedUnit.MicrometerPerSecond, "MicrometersPerSecond", new BaseUnits(length: LengthUnit.Micrometer, time: DurationUnit.Second), "Speed"), - new UnitInfo(SpeedUnit.MilePerHour, "MilesPerHour", new BaseUnits(length: LengthUnit.Mile, time: DurationUnit.Hour), "Speed"), - new UnitInfo(SpeedUnit.MillimeterPerHour, "MillimetersPerHour", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Hour), "Speed"), - new UnitInfo(SpeedUnit.MillimeterPerMinute, "MillimetersPerMinute", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Minute), "Speed"), - new UnitInfo(SpeedUnit.MillimeterPerSecond, "MillimetersPerSecond", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second), "Speed"), - new UnitInfo(SpeedUnit.NanometerPerMinute, "NanometersPerMinute", new BaseUnits(length: LengthUnit.Nanometer, time: DurationUnit.Minute), "Speed"), - new UnitInfo(SpeedUnit.NanometerPerSecond, "NanometersPerSecond", new BaseUnits(length: LengthUnit.Nanometer, time: DurationUnit.Second), "Speed"), - new UnitInfo(SpeedUnit.UsSurveyFootPerHour, "UsSurveyFeetPerHour", new BaseUnits(length: LengthUnit.UsSurveyFoot, time: DurationUnit.Hour), "Speed"), - new UnitInfo(SpeedUnit.UsSurveyFootPerMinute, "UsSurveyFeetPerMinute", new BaseUnits(length: LengthUnit.UsSurveyFoot, time: DurationUnit.Minute), "Speed"), - new UnitInfo(SpeedUnit.UsSurveyFootPerSecond, "UsSurveyFeetPerSecond", new BaseUnits(length: LengthUnit.UsSurveyFoot, time: DurationUnit.Second), "Speed"), - new UnitInfo(SpeedUnit.YardPerHour, "YardsPerHour", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Hour), "Speed"), - new UnitInfo(SpeedUnit.YardPerMinute, "YardsPerMinute", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Minute), "Speed"), - new UnitInfo(SpeedUnit.YardPerSecond, "YardsPerSecond", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Second), "Speed"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public SpeedInfo(string name, SpeedUnit baseUnit, IEnumerable> unitMappings, Speed zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public SpeedInfo(string name, SpeedUnit baseUnit, IEnumerable> unitMappings, Speed zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Speed.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Speed", typeof(Speed).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Speed quantity. + /// + /// A new instance of the class with the default settings. + public static SpeedInfo CreateDefault() + { + return new SpeedInfo(nameof(Speed), DefaultBaseUnit, GetDefaultMappings(), new Speed(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Speed quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static SpeedInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new SpeedInfo(nameof(Speed), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Speed(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][L]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 0, -1, 0, 0, 0, 0); + + /// + /// The default base unit of Speed is MeterPerSecond. All conversions, as defined in the , go via this value. + /// + public static SpeedUnit DefaultBaseUnit { get; } = SpeedUnit.MeterPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Speed. + public static IEnumerable> GetDefaultMappings() + { + yield return new (SpeedUnit.CentimeterPerHour, "CentimeterPerHour", "CentimetersPerHour", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Hour)); + yield return new (SpeedUnit.CentimeterPerMinute, "CentimeterPerMinute", "CentimetersPerMinute", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Minute)); + yield return new (SpeedUnit.CentimeterPerSecond, "CentimeterPerSecond", "CentimetersPerSecond", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Second)); + yield return new (SpeedUnit.DecimeterPerMinute, "DecimeterPerMinute", "DecimetersPerMinute", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Minute)); + yield return new (SpeedUnit.DecimeterPerSecond, "DecimeterPerSecond", "DecimetersPerSecond", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Second)); + yield return new (SpeedUnit.FootPerHour, "FootPerHour", "FeetPerHour", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Hour)); + yield return new (SpeedUnit.FootPerMinute, "FootPerMinute", "FeetPerMinute", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Minute)); + yield return new (SpeedUnit.FootPerSecond, "FootPerSecond", "FeetPerSecond", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second)); + yield return new (SpeedUnit.InchPerHour, "InchPerHour", "InchesPerHour", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Hour)); + yield return new (SpeedUnit.InchPerMinute, "InchPerMinute", "InchesPerMinute", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Minute)); + yield return new (SpeedUnit.InchPerSecond, "InchPerSecond", "InchesPerSecond", new BaseUnits(length: LengthUnit.Inch, time: DurationUnit.Second)); + yield return new (SpeedUnit.KilometerPerHour, "KilometerPerHour", "KilometersPerHour", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Hour)); + yield return new (SpeedUnit.KilometerPerMinute, "KilometerPerMinute", "KilometersPerMinute", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Minute)); + yield return new (SpeedUnit.KilometerPerSecond, "KilometerPerSecond", "KilometersPerSecond", new BaseUnits(length: LengthUnit.Kilometer, time: DurationUnit.Second)); + yield return new (SpeedUnit.Knot, "Knot", "Knots", new BaseUnits(length: LengthUnit.NauticalMile, time: DurationUnit.Hour)); + yield return new (SpeedUnit.Mach, "Mach", "Mach", BaseUnits.Undefined); + yield return new (SpeedUnit.MeterPerHour, "MeterPerHour", "MetersPerHour", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Hour)); + yield return new (SpeedUnit.MeterPerMinute, "MeterPerMinute", "MetersPerMinute", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Minute)); + yield return new (SpeedUnit.MeterPerSecond, "MeterPerSecond", "MetersPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + yield return new (SpeedUnit.MicrometerPerMinute, "MicrometerPerMinute", "MicrometersPerMinute", new BaseUnits(length: LengthUnit.Micrometer, time: DurationUnit.Minute)); + yield return new (SpeedUnit.MicrometerPerSecond, "MicrometerPerSecond", "MicrometersPerSecond", new BaseUnits(length: LengthUnit.Micrometer, time: DurationUnit.Second)); + yield return new (SpeedUnit.MilePerHour, "MilePerHour", "MilesPerHour", new BaseUnits(length: LengthUnit.Mile, time: DurationUnit.Hour)); + yield return new (SpeedUnit.MillimeterPerHour, "MillimeterPerHour", "MillimetersPerHour", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Hour)); + yield return new (SpeedUnit.MillimeterPerMinute, "MillimeterPerMinute", "MillimetersPerMinute", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Minute)); + yield return new (SpeedUnit.MillimeterPerSecond, "MillimeterPerSecond", "MillimetersPerSecond", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second)); + yield return new (SpeedUnit.NanometerPerMinute, "NanometerPerMinute", "NanometersPerMinute", new BaseUnits(length: LengthUnit.Nanometer, time: DurationUnit.Minute)); + yield return new (SpeedUnit.NanometerPerSecond, "NanometerPerSecond", "NanometersPerSecond", new BaseUnits(length: LengthUnit.Nanometer, time: DurationUnit.Second)); + yield return new (SpeedUnit.UsSurveyFootPerHour, "UsSurveyFootPerHour", "UsSurveyFeetPerHour", new BaseUnits(length: LengthUnit.UsSurveyFoot, time: DurationUnit.Hour)); + yield return new (SpeedUnit.UsSurveyFootPerMinute, "UsSurveyFootPerMinute", "UsSurveyFeetPerMinute", new BaseUnits(length: LengthUnit.UsSurveyFoot, time: DurationUnit.Minute)); + yield return new (SpeedUnit.UsSurveyFootPerSecond, "UsSurveyFootPerSecond", "UsSurveyFeetPerSecond", new BaseUnits(length: LengthUnit.UsSurveyFoot, time: DurationUnit.Second)); + yield return new (SpeedUnit.YardPerHour, "YardPerHour", "YardsPerHour", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Hour)); + yield return new (SpeedUnit.YardPerMinute, "YardPerMinute", "YardsPerMinute", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Minute)); + yield return new (SpeedUnit.YardPerSecond, "YardPerSecond", "YardsPerSecond", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Second)); + } + } + + static Speed() + { + Info = SpeedInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -155,27 +202,27 @@ public Speed(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Speed, which is MeterPerSecond. All conversions go via this value. /// - public static SpeedUnit BaseUnit { get; } + public static SpeedUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Speed quantity. /// - public static SpeedUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit MeterPerSecond. /// - public static Speed Zero { get; } + public static Speed Zero => Info.Zero; /// public static Speed AdditiveIdentity => Zero; @@ -193,7 +240,7 @@ public Speed(double value, UnitSystem unitSystem) public SpeedUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -211,6 +258,9 @@ public Speed(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs index eab2b96bb1..4c6878e713 100644 --- a/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/StandardVolumeFlow.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,27 +59,78 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly StandardVolumeFlowUnit? _unit; - static StandardVolumeFlow() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class StandardVolumeFlowInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 1, -1, 0, 0, 0, 0); - BaseUnit = StandardVolumeFlowUnit.StandardCubicMeterPerSecond; - Units = Enum.GetValues(typeof(StandardVolumeFlowUnit)).Cast().ToArray(); - Zero = new StandardVolumeFlow(0, BaseUnit); - Info = new QuantityInfo("StandardVolumeFlow", - new UnitInfo[] - { - new UnitInfo(StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, "StandardCubicCentimetersPerMinute", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Minute), "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicFootPerHour, "StandardCubicFeetPerHour", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Hour), "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicFootPerMinute, "StandardCubicFeetPerMinute", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Minute), "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicFootPerSecond, "StandardCubicFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second), "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerDay, "StandardCubicMetersPerDay", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Day), "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerHour, "StandardCubicMetersPerHour", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Hour), "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerMinute, "StandardCubicMetersPerMinute", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Minute), "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardCubicMeterPerSecond, "StandardCubicMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "StandardVolumeFlow"), - new UnitInfo(StandardVolumeFlowUnit.StandardLiterPerMinute, "StandardLitersPerMinute", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Minute), "StandardVolumeFlow"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public StandardVolumeFlowInfo(string name, StandardVolumeFlowUnit baseUnit, IEnumerable> unitMappings, StandardVolumeFlow zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public StandardVolumeFlowInfo(string name, StandardVolumeFlowUnit baseUnit, IEnumerable> unitMappings, StandardVolumeFlow zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, StandardVolumeFlow.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.StandardVolumeFlow", typeof(StandardVolumeFlow).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the StandardVolumeFlow quantity. + /// + /// A new instance of the class with the default settings. + public static StandardVolumeFlowInfo CreateDefault() + { + return new StandardVolumeFlowInfo(nameof(StandardVolumeFlow), DefaultBaseUnit, GetDefaultMappings(), new StandardVolumeFlow(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the StandardVolumeFlow quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static StandardVolumeFlowInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new StandardVolumeFlowInfo(nameof(StandardVolumeFlow), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new StandardVolumeFlow(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 1, -1, 0, 0, 0, 0); + + /// + /// The default base unit of StandardVolumeFlow is StandardCubicMeterPerSecond. All conversions, as defined in the , go via this value. + /// + public static StandardVolumeFlowUnit DefaultBaseUnit { get; } = StandardVolumeFlowUnit.StandardCubicMeterPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for StandardVolumeFlow. + public static IEnumerable> GetDefaultMappings() + { + yield return new (StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, "StandardCubicCentimeterPerMinute", "StandardCubicCentimetersPerMinute", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Minute)); + yield return new (StandardVolumeFlowUnit.StandardCubicFootPerHour, "StandardCubicFootPerHour", "StandardCubicFeetPerHour", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Hour)); + yield return new (StandardVolumeFlowUnit.StandardCubicFootPerMinute, "StandardCubicFootPerMinute", "StandardCubicFeetPerMinute", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Minute)); + yield return new (StandardVolumeFlowUnit.StandardCubicFootPerSecond, "StandardCubicFootPerSecond", "StandardCubicFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second)); + yield return new (StandardVolumeFlowUnit.StandardCubicMeterPerDay, "StandardCubicMeterPerDay", "StandardCubicMetersPerDay", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Day)); + yield return new (StandardVolumeFlowUnit.StandardCubicMeterPerHour, "StandardCubicMeterPerHour", "StandardCubicMetersPerHour", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Hour)); + yield return new (StandardVolumeFlowUnit.StandardCubicMeterPerMinute, "StandardCubicMeterPerMinute", "StandardCubicMetersPerMinute", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Minute)); + yield return new (StandardVolumeFlowUnit.StandardCubicMeterPerSecond, "StandardCubicMeterPerSecond", "StandardCubicMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + yield return new (StandardVolumeFlowUnit.StandardLiterPerMinute, "StandardLiterPerMinute", "StandardLitersPerMinute", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Minute)); + } + } + + static StandardVolumeFlow() + { + Info = StandardVolumeFlowInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -121,27 +168,27 @@ public StandardVolumeFlow(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of StandardVolumeFlow, which is StandardCubicMeterPerSecond. All conversions go via this value. /// - public static StandardVolumeFlowUnit BaseUnit { get; } + public static StandardVolumeFlowUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the StandardVolumeFlow quantity. /// - public static StandardVolumeFlowUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit StandardCubicMeterPerSecond. /// - public static StandardVolumeFlow Zero { get; } + public static StandardVolumeFlow Zero => Info.Zero; /// public static StandardVolumeFlow AdditiveIdentity => Zero; @@ -159,7 +206,7 @@ public StandardVolumeFlow(double value, UnitSystem unitSystem) public StandardVolumeFlowUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -177,6 +224,9 @@ public StandardVolumeFlow(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs b/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs index 6fadae50c4..032983398f 100644 --- a/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Temperature.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,28 +59,79 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly TemperatureUnit? _unit; - static Temperature() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class TemperatureInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, 0, 0, 1, 0, 0); - BaseUnit = TemperatureUnit.Kelvin; - Units = Enum.GetValues(typeof(TemperatureUnit)).Cast().ToArray(); - Zero = new Temperature(0, BaseUnit); - Info = new QuantityInfo("Temperature", - new UnitInfo[] - { - new UnitInfo(TemperatureUnit.DegreeCelsius, "DegreesCelsius", new BaseUnits(temperature: TemperatureUnit.DegreeCelsius), "Temperature"), - new UnitInfo(TemperatureUnit.DegreeDelisle, "DegreesDelisle", new BaseUnits(temperature: TemperatureUnit.DegreeDelisle), "Temperature"), - new UnitInfo(TemperatureUnit.DegreeFahrenheit, "DegreesFahrenheit", new BaseUnits(temperature: TemperatureUnit.DegreeFahrenheit), "Temperature"), - new UnitInfo(TemperatureUnit.DegreeNewton, "DegreesNewton", new BaseUnits(temperature: TemperatureUnit.DegreeNewton), "Temperature"), - new UnitInfo(TemperatureUnit.DegreeRankine, "DegreesRankine", new BaseUnits(temperature: TemperatureUnit.DegreeRankine), "Temperature"), - new UnitInfo(TemperatureUnit.DegreeReaumur, "DegreesReaumur", new BaseUnits(temperature: TemperatureUnit.DegreeReaumur), "Temperature"), - new UnitInfo(TemperatureUnit.DegreeRoemer, "DegreesRoemer", new BaseUnits(temperature: TemperatureUnit.DegreeRoemer), "Temperature"), - new UnitInfo(TemperatureUnit.Kelvin, "Kelvins", new BaseUnits(temperature: TemperatureUnit.Kelvin), "Temperature"), - new UnitInfo(TemperatureUnit.MillidegreeCelsius, "MillidegreesCelsius", new BaseUnits(temperature: TemperatureUnit.MillidegreeCelsius), "Temperature"), - new UnitInfo(TemperatureUnit.SolarTemperature, "SolarTemperatures", new BaseUnits(temperature: TemperatureUnit.SolarTemperature), "Temperature"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public TemperatureInfo(string name, TemperatureUnit baseUnit, IEnumerable> unitMappings, Temperature zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public TemperatureInfo(string name, TemperatureUnit baseUnit, IEnumerable> unitMappings, Temperature zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Temperature.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Temperature", typeof(Temperature).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Temperature quantity. + /// + /// A new instance of the class with the default settings. + public static TemperatureInfo CreateDefault() + { + return new TemperatureInfo(nameof(Temperature), DefaultBaseUnit, GetDefaultMappings(), new Temperature(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Temperature quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static TemperatureInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new TemperatureInfo(nameof(Temperature), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Temperature(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [Θ]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, 0, 0, 1, 0, 0); + + /// + /// The default base unit of Temperature is Kelvin. All conversions, as defined in the , go via this value. + /// + public static TemperatureUnit DefaultBaseUnit { get; } = TemperatureUnit.Kelvin; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Temperature. + public static IEnumerable> GetDefaultMappings() + { + yield return new (TemperatureUnit.DegreeCelsius, "DegreeCelsius", "DegreesCelsius", new BaseUnits(temperature: TemperatureUnit.DegreeCelsius)); + yield return new (TemperatureUnit.DegreeDelisle, "DegreeDelisle", "DegreesDelisle", new BaseUnits(temperature: TemperatureUnit.DegreeDelisle)); + yield return new (TemperatureUnit.DegreeFahrenheit, "DegreeFahrenheit", "DegreesFahrenheit", new BaseUnits(temperature: TemperatureUnit.DegreeFahrenheit)); + yield return new (TemperatureUnit.DegreeNewton, "DegreeNewton", "DegreesNewton", new BaseUnits(temperature: TemperatureUnit.DegreeNewton)); + yield return new (TemperatureUnit.DegreeRankine, "DegreeRankine", "DegreesRankine", new BaseUnits(temperature: TemperatureUnit.DegreeRankine)); + yield return new (TemperatureUnit.DegreeReaumur, "DegreeReaumur", "DegreesReaumur", new BaseUnits(temperature: TemperatureUnit.DegreeReaumur)); + yield return new (TemperatureUnit.DegreeRoemer, "DegreeRoemer", "DegreesRoemer", new BaseUnits(temperature: TemperatureUnit.DegreeRoemer)); + yield return new (TemperatureUnit.Kelvin, "Kelvin", "Kelvins", new BaseUnits(temperature: TemperatureUnit.Kelvin)); + yield return new (TemperatureUnit.MillidegreeCelsius, "MillidegreeCelsius", "MillidegreesCelsius", new BaseUnits(temperature: TemperatureUnit.MillidegreeCelsius)); + yield return new (TemperatureUnit.SolarTemperature, "SolarTemperature", "SolarTemperatures", new BaseUnits(temperature: TemperatureUnit.SolarTemperature)); + } + } + + static Temperature() + { + Info = TemperatureInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -122,27 +169,27 @@ public Temperature(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Temperature, which is Kelvin. All conversions go via this value. /// - public static TemperatureUnit BaseUnit { get; } + public static TemperatureUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Temperature quantity. /// - public static TemperatureUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Kelvin. /// - public static Temperature Zero { get; } + public static Temperature Zero => Info.Zero; #endregion @@ -157,7 +204,7 @@ public Temperature(double value, UnitSystem unitSystem) public TemperatureUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -175,6 +222,9 @@ public Temperature(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs index e0a101b12a..5a954fe69b 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureChangeRate.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,35 +62,86 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly TemperatureChangeRateUnit? _unit; - static TemperatureChangeRate() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class TemperatureChangeRateInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, -1, 0, 1, 0, 0); - BaseUnit = TemperatureChangeRateUnit.DegreeCelsiusPerSecond; - Units = Enum.GetValues(typeof(TemperatureChangeRateUnit)).Cast().ToArray(); - Zero = new TemperatureChangeRate(0, BaseUnit); - Info = new QuantityInfo("TemperatureChangeRate", - new UnitInfo[] - { - new UnitInfo(TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, "CentidegreesCelsiusPerSecond", BaseUnits.Undefined, "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, "DecadegreesCelsiusPerSecond", BaseUnits.Undefined, "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, "DecidegreesCelsiusPerSecond", BaseUnits.Undefined, "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DegreeCelsiusPerHour, "DegreesCelsiusPerHour", new BaseUnits(time: DurationUnit.Hour, temperature: TemperatureUnit.DegreeCelsius), "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DegreeCelsiusPerMinute, "DegreesCelsiusPerMinute", new BaseUnits(time: DurationUnit.Minute, temperature: TemperatureUnit.DegreeCelsius), "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DegreeCelsiusPerSecond, "DegreesCelsiusPerSecond", new BaseUnits(time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DegreeFahrenheitPerHour, "DegreesFahrenheitPerHour", new BaseUnits(time: DurationUnit.Hour, temperature: TemperatureUnit.DegreeFahrenheit), "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DegreeFahrenheitPerMinute, "DegreesFahrenheitPerMinute", new BaseUnits(time: DurationUnit.Minute, temperature: TemperatureUnit.DegreeFahrenheit), "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DegreeFahrenheitPerSecond, "DegreesFahrenheitPerSecond", new BaseUnits(time: DurationUnit.Second, temperature: TemperatureUnit.DegreeFahrenheit), "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DegreeKelvinPerHour, "DegreesKelvinPerHour", new BaseUnits(time: DurationUnit.Hour, temperature: TemperatureUnit.Kelvin), "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DegreeKelvinPerMinute, "DegreesKelvinPerMinute", new BaseUnits(time: DurationUnit.Minute, temperature: TemperatureUnit.Kelvin), "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.DegreeKelvinPerSecond, "DegreesKelvinPerSecond", new BaseUnits(time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond, "HectodegreesCelsiusPerSecond", BaseUnits.Undefined, "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond, "KilodegreesCelsiusPerSecond", new BaseUnits(time: DurationUnit.Millisecond, temperature: TemperatureUnit.DegreeCelsius), "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond, "MicrodegreesCelsiusPerSecond", BaseUnits.Undefined, "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond, "MillidegreesCelsiusPerSecond", BaseUnits.Undefined, "TemperatureChangeRate"), - new UnitInfo(TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, "NanodegreesCelsiusPerSecond", BaseUnits.Undefined, "TemperatureChangeRate"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public TemperatureChangeRateInfo(string name, TemperatureChangeRateUnit baseUnit, IEnumerable> unitMappings, TemperatureChangeRate zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public TemperatureChangeRateInfo(string name, TemperatureChangeRateUnit baseUnit, IEnumerable> unitMappings, TemperatureChangeRate zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, TemperatureChangeRate.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.TemperatureChangeRate", typeof(TemperatureChangeRate).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the TemperatureChangeRate quantity. + /// + /// A new instance of the class with the default settings. + public static TemperatureChangeRateInfo CreateDefault() + { + return new TemperatureChangeRateInfo(nameof(TemperatureChangeRate), DefaultBaseUnit, GetDefaultMappings(), new TemperatureChangeRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the TemperatureChangeRate quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static TemperatureChangeRateInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new TemperatureChangeRateInfo(nameof(TemperatureChangeRate), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new TemperatureChangeRate(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][Θ]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, -1, 0, 1, 0, 0); + + /// + /// The default base unit of TemperatureChangeRate is DegreeCelsiusPerSecond. All conversions, as defined in the , go via this value. + /// + public static TemperatureChangeRateUnit DefaultBaseUnit { get; } = TemperatureChangeRateUnit.DegreeCelsiusPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for TemperatureChangeRate. + public static IEnumerable> GetDefaultMappings() + { + yield return new (TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, "CentidegreeCelsiusPerSecond", "CentidegreesCelsiusPerSecond", BaseUnits.Undefined); + yield return new (TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, "DecadegreeCelsiusPerSecond", "DecadegreesCelsiusPerSecond", BaseUnits.Undefined); + yield return new (TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, "DecidegreeCelsiusPerSecond", "DecidegreesCelsiusPerSecond", BaseUnits.Undefined); + yield return new (TemperatureChangeRateUnit.DegreeCelsiusPerHour, "DegreeCelsiusPerHour", "DegreesCelsiusPerHour", new BaseUnits(time: DurationUnit.Hour, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (TemperatureChangeRateUnit.DegreeCelsiusPerMinute, "DegreeCelsiusPerMinute", "DegreesCelsiusPerMinute", new BaseUnits(time: DurationUnit.Minute, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (TemperatureChangeRateUnit.DegreeCelsiusPerSecond, "DegreeCelsiusPerSecond", "DegreesCelsiusPerSecond", new BaseUnits(time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (TemperatureChangeRateUnit.DegreeFahrenheitPerHour, "DegreeFahrenheitPerHour", "DegreesFahrenheitPerHour", new BaseUnits(time: DurationUnit.Hour, temperature: TemperatureUnit.DegreeFahrenheit)); + yield return new (TemperatureChangeRateUnit.DegreeFahrenheitPerMinute, "DegreeFahrenheitPerMinute", "DegreesFahrenheitPerMinute", new BaseUnits(time: DurationUnit.Minute, temperature: TemperatureUnit.DegreeFahrenheit)); + yield return new (TemperatureChangeRateUnit.DegreeFahrenheitPerSecond, "DegreeFahrenheitPerSecond", "DegreesFahrenheitPerSecond", new BaseUnits(time: DurationUnit.Second, temperature: TemperatureUnit.DegreeFahrenheit)); + yield return new (TemperatureChangeRateUnit.DegreeKelvinPerHour, "DegreeKelvinPerHour", "DegreesKelvinPerHour", new BaseUnits(time: DurationUnit.Hour, temperature: TemperatureUnit.Kelvin)); + yield return new (TemperatureChangeRateUnit.DegreeKelvinPerMinute, "DegreeKelvinPerMinute", "DegreesKelvinPerMinute", new BaseUnits(time: DurationUnit.Minute, temperature: TemperatureUnit.Kelvin)); + yield return new (TemperatureChangeRateUnit.DegreeKelvinPerSecond, "DegreeKelvinPerSecond", "DegreesKelvinPerSecond", new BaseUnits(time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin)); + yield return new (TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond, "HectodegreeCelsiusPerSecond", "HectodegreesCelsiusPerSecond", BaseUnits.Undefined); + yield return new (TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond, "KilodegreeCelsiusPerSecond", "KilodegreesCelsiusPerSecond", new BaseUnits(time: DurationUnit.Millisecond, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond, "MicrodegreeCelsiusPerSecond", "MicrodegreesCelsiusPerSecond", BaseUnits.Undefined); + yield return new (TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond, "MillidegreeCelsiusPerSecond", "MillidegreesCelsiusPerSecond", BaseUnits.Undefined); + yield return new (TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, "NanodegreeCelsiusPerSecond", "NanodegreesCelsiusPerSecond", BaseUnits.Undefined); + } + } + + static TemperatureChangeRate() + { + Info = TemperatureChangeRateInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -132,27 +179,27 @@ public TemperatureChangeRate(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of TemperatureChangeRate, which is DegreeCelsiusPerSecond. All conversions go via this value. /// - public static TemperatureChangeRateUnit BaseUnit { get; } + public static TemperatureChangeRateUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the TemperatureChangeRate quantity. /// - public static TemperatureChangeRateUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit DegreeCelsiusPerSecond. /// - public static TemperatureChangeRate Zero { get; } + public static TemperatureChangeRate Zero => Info.Zero; /// public static TemperatureChangeRate AdditiveIdentity => Zero; @@ -170,7 +217,7 @@ public TemperatureChangeRate(double value, UnitSystem unitSystem) public TemperatureChangeRateUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -188,6 +235,9 @@ public TemperatureChangeRate(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs index c72a69624b..bc13dac5db 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureDelta.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -72,27 +68,78 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly TemperatureDeltaUnit? _unit; - static TemperatureDelta() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class TemperatureDeltaInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, 0, 0, 0, 1, 0, 0); - BaseUnit = TemperatureDeltaUnit.Kelvin; - Units = Enum.GetValues(typeof(TemperatureDeltaUnit)).Cast().ToArray(); - Zero = new TemperatureDelta(0, BaseUnit); - Info = new QuantityInfo("TemperatureDelta", - new UnitInfo[] - { - new UnitInfo(TemperatureDeltaUnit.DegreeCelsius, "DegreesCelsius", new BaseUnits(temperature: TemperatureUnit.DegreeCelsius), "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeDelisle, "DegreesDelisle", new BaseUnits(temperature: TemperatureUnit.DegreeDelisle), "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeFahrenheit, "DegreesFahrenheit", new BaseUnits(temperature: TemperatureUnit.DegreeFahrenheit), "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeNewton, "DegreesNewton", new BaseUnits(temperature: TemperatureUnit.DegreeNewton), "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeRankine, "DegreesRankine", new BaseUnits(temperature: TemperatureUnit.DegreeRankine), "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeReaumur, "DegreesReaumur", new BaseUnits(temperature: TemperatureUnit.DegreeReaumur), "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.DegreeRoemer, "DegreesRoemer", new BaseUnits(temperature: TemperatureUnit.DegreeRoemer), "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.Kelvin, "Kelvins", new BaseUnits(temperature: TemperatureUnit.Kelvin), "TemperatureDelta"), - new UnitInfo(TemperatureDeltaUnit.MillidegreeCelsius, "MillidegreesCelsius", BaseUnits.Undefined, "TemperatureDelta"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public TemperatureDeltaInfo(string name, TemperatureDeltaUnit baseUnit, IEnumerable> unitMappings, TemperatureDelta zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public TemperatureDeltaInfo(string name, TemperatureDeltaUnit baseUnit, IEnumerable> unitMappings, TemperatureDelta zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, TemperatureDelta.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.TemperatureDelta", typeof(TemperatureDelta).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the TemperatureDelta quantity. + /// + /// A new instance of the class with the default settings. + public static TemperatureDeltaInfo CreateDefault() + { + return new TemperatureDeltaInfo(nameof(TemperatureDelta), DefaultBaseUnit, GetDefaultMappings(), new TemperatureDelta(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the TemperatureDelta quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static TemperatureDeltaInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new TemperatureDeltaInfo(nameof(TemperatureDelta), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new TemperatureDelta(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [Θ]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, 0, 0, 0, 1, 0, 0); + + /// + /// The default base unit of TemperatureDelta is Kelvin. All conversions, as defined in the , go via this value. + /// + public static TemperatureDeltaUnit DefaultBaseUnit { get; } = TemperatureDeltaUnit.Kelvin; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for TemperatureDelta. + public static IEnumerable> GetDefaultMappings() + { + yield return new (TemperatureDeltaUnit.DegreeCelsius, "DegreeCelsius", "DegreesCelsius", new BaseUnits(temperature: TemperatureUnit.DegreeCelsius)); + yield return new (TemperatureDeltaUnit.DegreeDelisle, "DegreeDelisle", "DegreesDelisle", new BaseUnits(temperature: TemperatureUnit.DegreeDelisle)); + yield return new (TemperatureDeltaUnit.DegreeFahrenheit, "DegreeFahrenheit", "DegreesFahrenheit", new BaseUnits(temperature: TemperatureUnit.DegreeFahrenheit)); + yield return new (TemperatureDeltaUnit.DegreeNewton, "DegreeNewton", "DegreesNewton", new BaseUnits(temperature: TemperatureUnit.DegreeNewton)); + yield return new (TemperatureDeltaUnit.DegreeRankine, "DegreeRankine", "DegreesRankine", new BaseUnits(temperature: TemperatureUnit.DegreeRankine)); + yield return new (TemperatureDeltaUnit.DegreeReaumur, "DegreeReaumur", "DegreesReaumur", new BaseUnits(temperature: TemperatureUnit.DegreeReaumur)); + yield return new (TemperatureDeltaUnit.DegreeRoemer, "DegreeRoemer", "DegreesRoemer", new BaseUnits(temperature: TemperatureUnit.DegreeRoemer)); + yield return new (TemperatureDeltaUnit.Kelvin, "Kelvin", "Kelvins", new BaseUnits(temperature: TemperatureUnit.Kelvin)); + yield return new (TemperatureDeltaUnit.MillidegreeCelsius, "MillidegreeCelsius", "MillidegreesCelsius", BaseUnits.Undefined); + } + } + + static TemperatureDelta() + { + Info = TemperatureDeltaInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -130,27 +177,27 @@ public TemperatureDelta(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of TemperatureDelta, which is Kelvin. All conversions go via this value. /// - public static TemperatureDeltaUnit BaseUnit { get; } + public static TemperatureDeltaUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the TemperatureDelta quantity. /// - public static TemperatureDeltaUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit Kelvin. /// - public static TemperatureDelta Zero { get; } + public static TemperatureDelta Zero => Info.Zero; /// public static TemperatureDelta AdditiveIdentity => Zero; @@ -168,7 +215,7 @@ public TemperatureDelta(double value, UnitSystem unitSystem) public TemperatureDeltaUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -186,6 +233,9 @@ public TemperatureDelta(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs b/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs index 11d64354e1..ac19efea86 100644 --- a/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/TemperatureGradient.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,22 +62,73 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly TemperatureGradientUnit? _unit; - static TemperatureGradient() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class TemperatureGradientInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-1, 0, 0, 0, 1, 0, 0); - BaseUnit = TemperatureGradientUnit.KelvinPerMeter; - Units = Enum.GetValues(typeof(TemperatureGradientUnit)).Cast().ToArray(); - Zero = new TemperatureGradient(0, BaseUnit); - Info = new QuantityInfo("TemperatureGradient", - new UnitInfo[] - { - new UnitInfo(TemperatureGradientUnit.DegreeCelsiusPerKilometer, "DegreesCelsiusPerKilometer", new BaseUnits(length: LengthUnit.Kilometer, temperature: TemperatureUnit.DegreeCelsius), "TemperatureGradient"), - new UnitInfo(TemperatureGradientUnit.DegreeCelsiusPerMeter, "DegreesCelsiusPerMeter", new BaseUnits(length: LengthUnit.Meter, temperature: TemperatureUnit.DegreeCelsius), "TemperatureGradient"), - new UnitInfo(TemperatureGradientUnit.DegreeFahrenheitPerFoot, "DegreesFahrenheitPerFoot", new BaseUnits(length: LengthUnit.Foot, temperature: TemperatureUnit.DegreeFahrenheit), "TemperatureGradient"), - new UnitInfo(TemperatureGradientUnit.KelvinPerMeter, "KelvinsPerMeter", new BaseUnits(length: LengthUnit.Meter, temperature: TemperatureUnit.Kelvin), "TemperatureGradient"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public TemperatureGradientInfo(string name, TemperatureGradientUnit baseUnit, IEnumerable> unitMappings, TemperatureGradient zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public TemperatureGradientInfo(string name, TemperatureGradientUnit baseUnit, IEnumerable> unitMappings, TemperatureGradient zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, TemperatureGradient.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.TemperatureGradient", typeof(TemperatureGradient).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the TemperatureGradient quantity. + /// + /// A new instance of the class with the default settings. + public static TemperatureGradientInfo CreateDefault() + { + return new TemperatureGradientInfo(nameof(TemperatureGradient), DefaultBaseUnit, GetDefaultMappings(), new TemperatureGradient(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the TemperatureGradient quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static TemperatureGradientInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new TemperatureGradientInfo(nameof(TemperatureGradient), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new TemperatureGradient(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^-1][Θ]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-1, 0, 0, 0, 1, 0, 0); + + /// + /// The default base unit of TemperatureGradient is KelvinPerMeter. All conversions, as defined in the , go via this value. + /// + public static TemperatureGradientUnit DefaultBaseUnit { get; } = TemperatureGradientUnit.KelvinPerMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for TemperatureGradient. + public static IEnumerable> GetDefaultMappings() + { + yield return new (TemperatureGradientUnit.DegreeCelsiusPerKilometer, "DegreeCelsiusPerKilometer", "DegreesCelsiusPerKilometer", new BaseUnits(length: LengthUnit.Kilometer, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (TemperatureGradientUnit.DegreeCelsiusPerMeter, "DegreeCelsiusPerMeter", "DegreesCelsiusPerMeter", new BaseUnits(length: LengthUnit.Meter, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (TemperatureGradientUnit.DegreeFahrenheitPerFoot, "DegreeFahrenheitPerFoot", "DegreesFahrenheitPerFoot", new BaseUnits(length: LengthUnit.Foot, temperature: TemperatureUnit.DegreeFahrenheit)); + yield return new (TemperatureGradientUnit.KelvinPerMeter, "KelvinPerMeter", "KelvinsPerMeter", new BaseUnits(length: LengthUnit.Meter, temperature: TemperatureUnit.Kelvin)); + } + } + + static TemperatureGradient() + { + Info = TemperatureGradientInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -119,27 +166,27 @@ public TemperatureGradient(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of TemperatureGradient, which is KelvinPerMeter. All conversions go via this value. /// - public static TemperatureGradientUnit BaseUnit { get; } + public static TemperatureGradientUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the TemperatureGradient quantity. /// - public static TemperatureGradientUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit KelvinPerMeter. /// - public static TemperatureGradient Zero { get; } + public static TemperatureGradient Zero => Info.Zero; /// public static TemperatureGradient AdditiveIdentity => Zero; @@ -157,7 +204,7 @@ public TemperatureGradient(double value, UnitSystem unitSystem) public TemperatureGradientUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -175,6 +222,9 @@ public TemperatureGradient(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs index e31ec01384..959b86fb6c 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalConductivity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,20 +62,71 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ThermalConductivityUnit? _unit; - static ThermalConductivity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ThermalConductivityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 1, -3, 0, -1, 0, 0); - BaseUnit = ThermalConductivityUnit.WattPerMeterKelvin; - Units = Enum.GetValues(typeof(ThermalConductivityUnit)).Cast().ToArray(); - Zero = new ThermalConductivity(0, BaseUnit); - Info = new QuantityInfo("ThermalConductivity", - new UnitInfo[] - { - new UnitInfo(ThermalConductivityUnit.BtuPerHourFootFahrenheit, "BtusPerHourFootFahrenheit", BaseUnits.Undefined, "ThermalConductivity"), - new UnitInfo(ThermalConductivityUnit.WattPerMeterKelvin, "WattsPerMeterKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "ThermalConductivity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ThermalConductivityInfo(string name, ThermalConductivityUnit baseUnit, IEnumerable> unitMappings, ThermalConductivity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ThermalConductivityInfo(string name, ThermalConductivityUnit baseUnit, IEnumerable> unitMappings, ThermalConductivity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ThermalConductivity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ThermalConductivity", typeof(ThermalConductivity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ThermalConductivity quantity. + /// + /// A new instance of the class with the default settings. + public static ThermalConductivityInfo CreateDefault() + { + return new ThermalConductivityInfo(nameof(ThermalConductivity), DefaultBaseUnit, GetDefaultMappings(), new ThermalConductivity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ThermalConductivity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ThermalConductivityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ThermalConductivityInfo(nameof(ThermalConductivity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ThermalConductivity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-3][L][M][Θ^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 1, -3, 0, -1, 0, 0); + + /// + /// The default base unit of ThermalConductivity is WattPerMeterKelvin. All conversions, as defined in the , go via this value. + /// + public static ThermalConductivityUnit DefaultBaseUnit { get; } = ThermalConductivityUnit.WattPerMeterKelvin; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ThermalConductivity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ThermalConductivityUnit.BtuPerHourFootFahrenheit, "BtuPerHourFootFahrenheit", "BtusPerHourFootFahrenheit", BaseUnits.Undefined); + yield return new (ThermalConductivityUnit.WattPerMeterKelvin, "WattPerMeterKelvin", "WattsPerMeterKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin)); + } + } + + static ThermalConductivity() + { + Info = ThermalConductivityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -117,27 +164,27 @@ public ThermalConductivity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ThermalConductivity, which is WattPerMeterKelvin. All conversions go via this value. /// - public static ThermalConductivityUnit BaseUnit { get; } + public static ThermalConductivityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ThermalConductivity quantity. /// - public static ThermalConductivityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit WattPerMeterKelvin. /// - public static ThermalConductivity Zero { get; } + public static ThermalConductivity Zero => Info.Zero; /// public static ThermalConductivity AdditiveIdentity => Zero; @@ -155,7 +202,7 @@ public ThermalConductivity(double value, UnitSystem unitSystem) public ThermalConductivityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -173,6 +220,9 @@ public ThermalConductivity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/ThermalInsulance.g.cs b/UnitsNet/GeneratedCode/Quantities/ThermalInsulance.g.cs index 0133fcd6fa..e0ada0562b 100644 --- a/UnitsNet/GeneratedCode/Quantities/ThermalInsulance.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/ThermalInsulance.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,24 +59,75 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly ThermalInsulanceUnit? _unit; - static ThermalInsulance() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class ThermalInsulanceInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(0, -1, 3, 0, 1, 0, 0); - BaseUnit = ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt; - Units = Enum.GetValues(typeof(ThermalInsulanceUnit)).Cast().ToArray(); - Zero = new ThermalInsulance(0, BaseUnit); - Info = new QuantityInfo("ThermalInsulance", - new UnitInfo[] - { - new UnitInfo(ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, "HourSquareFeetDegreesFahrenheitPerBtu", BaseUnits.Undefined, "ThermalInsulance"), - new UnitInfo(ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie, "SquareCentimeterHourDegreesCelsiusPerKilocalorie", BaseUnits.Undefined, "ThermalInsulance"), - new UnitInfo(ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt, "SquareCentimeterKelvinsPerWatt", BaseUnits.Undefined, "ThermalInsulance"), - new UnitInfo(ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt, "SquareMeterDegreesCelsiusPerWatt", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "ThermalInsulance"), - new UnitInfo(ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt, "SquareMeterKelvinsPerKilowatt", BaseUnits.Undefined, "ThermalInsulance"), - new UnitInfo(ThermalInsulanceUnit.SquareMeterKelvinPerWatt, "SquareMeterKelvinsPerWatt", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "ThermalInsulance"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public ThermalInsulanceInfo(string name, ThermalInsulanceUnit baseUnit, IEnumerable> unitMappings, ThermalInsulance zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public ThermalInsulanceInfo(string name, ThermalInsulanceUnit baseUnit, IEnumerable> unitMappings, ThermalInsulance zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, ThermalInsulance.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.ThermalInsulance", typeof(ThermalInsulance).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the ThermalInsulance quantity. + /// + /// A new instance of the class with the default settings. + public static ThermalInsulanceInfo CreateDefault() + { + return new ThermalInsulanceInfo(nameof(ThermalInsulance), DefaultBaseUnit, GetDefaultMappings(), new ThermalInsulance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the ThermalInsulance quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static ThermalInsulanceInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new ThermalInsulanceInfo(nameof(ThermalInsulance), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new ThermalInsulance(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^3][M^-1][Θ]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(0, -1, 3, 0, 1, 0, 0); + + /// + /// The default base unit of ThermalInsulance is SquareMeterKelvinPerKilowatt. All conversions, as defined in the , go via this value. + /// + public static ThermalInsulanceUnit DefaultBaseUnit { get; } = ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for ThermalInsulance. + public static IEnumerable> GetDefaultMappings() + { + yield return new (ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, "HourSquareFeetDegreeFahrenheitPerBtu", "HourSquareFeetDegreesFahrenheitPerBtu", BaseUnits.Undefined); + yield return new (ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie, "SquareCentimeterHourDegreeCelsiusPerKilocalorie", "SquareCentimeterHourDegreesCelsiusPerKilocalorie", BaseUnits.Undefined); + yield return new (ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt, "SquareCentimeterKelvinPerWatt", "SquareCentimeterKelvinsPerWatt", BaseUnits.Undefined); + yield return new (ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt, "SquareMeterDegreeCelsiusPerWatt", "SquareMeterDegreesCelsiusPerWatt", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt, "SquareMeterKelvinPerKilowatt", "SquareMeterKelvinsPerKilowatt", BaseUnits.Undefined); + yield return new (ThermalInsulanceUnit.SquareMeterKelvinPerWatt, "SquareMeterKelvinPerWatt", "SquareMeterKelvinsPerWatt", new BaseUnits(mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin)); + } + } + + static ThermalInsulance() + { + Info = ThermalInsulanceInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -118,27 +165,27 @@ public ThermalInsulance(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of ThermalInsulance, which is SquareMeterKelvinPerKilowatt. All conversions go via this value. /// - public static ThermalInsulanceUnit BaseUnit { get; } + public static ThermalInsulanceUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the ThermalInsulance quantity. /// - public static ThermalInsulanceUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit SquareMeterKelvinPerKilowatt. /// - public static ThermalInsulance Zero { get; } + public static ThermalInsulance Zero => Info.Zero; /// public static ThermalInsulance AdditiveIdentity => Zero; @@ -156,7 +203,7 @@ public ThermalInsulance(double value, UnitSystem unitSystem) public ThermalInsulanceUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -174,6 +221,9 @@ public ThermalInsulance(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs index 7632fb2fdd..2e4392c923 100644 --- a/UnitsNet/GeneratedCode/Quantities/Torque.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Torque.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -72,43 +68,94 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly TorqueUnit? _unit; - static Torque() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class TorqueInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); - BaseUnit = TorqueUnit.NewtonMeter; - Units = Enum.GetValues(typeof(TorqueUnit)).Cast().ToArray(); - Zero = new Torque(0, BaseUnit); - Info = new QuantityInfo("Torque", - new UnitInfo[] - { - new UnitInfo(TorqueUnit.GramForceCentimeter, "GramForceCentimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.GramForceMeter, "GramForceMeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.GramForceMillimeter, "GramForceMillimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.KilogramForceCentimeter, "KilogramForceCentimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.KilogramForceMeter, "KilogramForceMeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.KilogramForceMillimeter, "KilogramForceMillimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.KilonewtonCentimeter, "KilonewtonCentimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.KilonewtonMeter, "KilonewtonMeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.KilonewtonMillimeter, "KilonewtonMillimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.KilopoundForceFoot, "KilopoundForceFeet", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.KilopoundForceInch, "KilopoundForceInches", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.MeganewtonCentimeter, "MeganewtonCentimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.MeganewtonMeter, "MeganewtonMeters", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Torque"), - new UnitInfo(TorqueUnit.MeganewtonMillimeter, "MeganewtonMillimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.MegapoundForceFoot, "MegapoundForceFeet", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.MegapoundForceInch, "MegapoundForceInches", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.NewtonCentimeter, "NewtonCentimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.NewtonMeter, "NewtonMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second), "Torque"), - new UnitInfo(TorqueUnit.NewtonMillimeter, "NewtonMillimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.PoundalFoot, "PoundalFeet", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.PoundForceFoot, "PoundForceFeet", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.PoundForceInch, "PoundForceInches", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.TonneForceCentimeter, "TonneForceCentimeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.TonneForceMeter, "TonneForceMeters", BaseUnits.Undefined, "Torque"), - new UnitInfo(TorqueUnit.TonneForceMillimeter, "TonneForceMillimeters", BaseUnits.Undefined, "Torque"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public TorqueInfo(string name, TorqueUnit baseUnit, IEnumerable> unitMappings, Torque zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public TorqueInfo(string name, TorqueUnit baseUnit, IEnumerable> unitMappings, Torque zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Torque.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Torque", typeof(Torque).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Torque quantity. + /// + /// A new instance of the class with the default settings. + public static TorqueInfo CreateDefault() + { + return new TorqueInfo(nameof(Torque), DefaultBaseUnit, GetDefaultMappings(), new Torque(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Torque quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static TorqueInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new TorqueInfo(nameof(Torque), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Torque(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^2][M]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 1, -2, 0, 0, 0, 0); + + /// + /// The default base unit of Torque is NewtonMeter. All conversions, as defined in the , go via this value. + /// + public static TorqueUnit DefaultBaseUnit { get; } = TorqueUnit.NewtonMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Torque. + public static IEnumerable> GetDefaultMappings() + { + yield return new (TorqueUnit.GramForceCentimeter, "GramForceCentimeter", "GramForceCentimeters", BaseUnits.Undefined); + yield return new (TorqueUnit.GramForceMeter, "GramForceMeter", "GramForceMeters", BaseUnits.Undefined); + yield return new (TorqueUnit.GramForceMillimeter, "GramForceMillimeter", "GramForceMillimeters", BaseUnits.Undefined); + yield return new (TorqueUnit.KilogramForceCentimeter, "KilogramForceCentimeter", "KilogramForceCentimeters", BaseUnits.Undefined); + yield return new (TorqueUnit.KilogramForceMeter, "KilogramForceMeter", "KilogramForceMeters", BaseUnits.Undefined); + yield return new (TorqueUnit.KilogramForceMillimeter, "KilogramForceMillimeter", "KilogramForceMillimeters", BaseUnits.Undefined); + yield return new (TorqueUnit.KilonewtonCentimeter, "KilonewtonCentimeter", "KilonewtonCentimeters", BaseUnits.Undefined); + yield return new (TorqueUnit.KilonewtonMeter, "KilonewtonMeter", "KilonewtonMeters", BaseUnits.Undefined); + yield return new (TorqueUnit.KilonewtonMillimeter, "KilonewtonMillimeter", "KilonewtonMillimeters", BaseUnits.Undefined); + yield return new (TorqueUnit.KilopoundForceFoot, "KilopoundForceFoot", "KilopoundForceFeet", BaseUnits.Undefined); + yield return new (TorqueUnit.KilopoundForceInch, "KilopoundForceInch", "KilopoundForceInches", BaseUnits.Undefined); + yield return new (TorqueUnit.MeganewtonCentimeter, "MeganewtonCentimeter", "MeganewtonCentimeters", BaseUnits.Undefined); + yield return new (TorqueUnit.MeganewtonMeter, "MeganewtonMeter", "MeganewtonMeters", new BaseUnits(length: LengthUnit.Kilometer, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (TorqueUnit.MeganewtonMillimeter, "MeganewtonMillimeter", "MeganewtonMillimeters", BaseUnits.Undefined); + yield return new (TorqueUnit.MegapoundForceFoot, "MegapoundForceFoot", "MegapoundForceFeet", BaseUnits.Undefined); + yield return new (TorqueUnit.MegapoundForceInch, "MegapoundForceInch", "MegapoundForceInches", BaseUnits.Undefined); + yield return new (TorqueUnit.NewtonCentimeter, "NewtonCentimeter", "NewtonCentimeters", BaseUnits.Undefined); + yield return new (TorqueUnit.NewtonMeter, "NewtonMeter", "NewtonMeters", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second)); + yield return new (TorqueUnit.NewtonMillimeter, "NewtonMillimeter", "NewtonMillimeters", BaseUnits.Undefined); + yield return new (TorqueUnit.PoundalFoot, "PoundalFoot", "PoundalFeet", BaseUnits.Undefined); + yield return new (TorqueUnit.PoundForceFoot, "PoundForceFoot", "PoundForceFeet", BaseUnits.Undefined); + yield return new (TorqueUnit.PoundForceInch, "PoundForceInch", "PoundForceInches", BaseUnits.Undefined); + yield return new (TorqueUnit.TonneForceCentimeter, "TonneForceCentimeter", "TonneForceCentimeters", BaseUnits.Undefined); + yield return new (TorqueUnit.TonneForceMeter, "TonneForceMeter", "TonneForceMeters", BaseUnits.Undefined); + yield return new (TorqueUnit.TonneForceMillimeter, "TonneForceMillimeter", "TonneForceMillimeters", BaseUnits.Undefined); + } + } + + static Torque() + { + Info = TorqueInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -146,27 +193,27 @@ public Torque(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Torque, which is NewtonMeter. All conversions go via this value. /// - public static TorqueUnit BaseUnit { get; } + public static TorqueUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Torque quantity. /// - public static TorqueUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit NewtonMeter. /// - public static Torque Zero { get; } + public static Torque Zero => Info.Zero; /// public static Torque AdditiveIdentity => Zero; @@ -184,7 +231,7 @@ public Torque(double value, UnitSystem unitSystem) public TorqueUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -202,6 +249,9 @@ public Torque(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs b/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs index ec02d68ebb..c2b4a0bdcd 100644 --- a/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Turbidity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,19 +62,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly TurbidityUnit? _unit; - static Turbidity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class TurbidityInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = TurbidityUnit.NTU; - Units = Enum.GetValues(typeof(TurbidityUnit)).Cast().ToArray(); - Zero = new Turbidity(0, BaseUnit); - Info = new QuantityInfo("Turbidity", - new UnitInfo[] - { - new UnitInfo(TurbidityUnit.NTU, "NTU", BaseUnits.Undefined, "Turbidity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public TurbidityInfo(string name, TurbidityUnit baseUnit, IEnumerable> unitMappings, Turbidity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public TurbidityInfo(string name, TurbidityUnit baseUnit, IEnumerable> unitMappings, Turbidity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Turbidity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Turbidity", typeof(Turbidity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Turbidity quantity. + /// + /// A new instance of the class with the default settings. + public static TurbidityInfo CreateDefault() + { + return new TurbidityInfo(nameof(Turbidity), DefaultBaseUnit, GetDefaultMappings(), new Turbidity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Turbidity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static TurbidityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new TurbidityInfo(nameof(Turbidity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Turbidity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of Turbidity is NTU. All conversions, as defined in the , go via this value. + /// + public static TurbidityUnit DefaultBaseUnit { get; } = TurbidityUnit.NTU; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Turbidity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (TurbidityUnit.NTU, "NTU", "NTU", BaseUnits.Undefined); + } + } + + static Turbidity() + { + Info = TurbidityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -102,27 +149,27 @@ public Turbidity(double value, TurbidityUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Turbidity, which is NTU. All conversions go via this value. /// - public static TurbidityUnit BaseUnit { get; } + public static TurbidityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Turbidity quantity. /// - public static TurbidityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit NTU. /// - public static Turbidity Zero { get; } + public static Turbidity Zero => Info.Zero; /// public static Turbidity AdditiveIdentity => Zero; @@ -140,7 +187,7 @@ public Turbidity(double value, TurbidityUnit unit) public TurbidityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -158,6 +205,9 @@ public Turbidity(double value, TurbidityUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs b/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs index 143f790aa5..0d1f3d65cd 100644 --- a/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VitaminA.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,19 +59,70 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly VitaminAUnit? _unit; - static VitaminA() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class VitaminAInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = VitaminAUnit.InternationalUnit; - Units = Enum.GetValues(typeof(VitaminAUnit)).Cast().ToArray(); - Zero = new VitaminA(0, BaseUnit); - Info = new QuantityInfo("VitaminA", - new UnitInfo[] - { - new UnitInfo(VitaminAUnit.InternationalUnit, "InternationalUnits", BaseUnits.Undefined, "VitaminA"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public VitaminAInfo(string name, VitaminAUnit baseUnit, IEnumerable> unitMappings, VitaminA zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public VitaminAInfo(string name, VitaminAUnit baseUnit, IEnumerable> unitMappings, VitaminA zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, VitaminA.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.VitaminA", typeof(VitaminA).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the VitaminA quantity. + /// + /// A new instance of the class with the default settings. + public static VitaminAInfo CreateDefault() + { + return new VitaminAInfo(nameof(VitaminA), DefaultBaseUnit, GetDefaultMappings(), new VitaminA(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the VitaminA quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static VitaminAInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new VitaminAInfo(nameof(VitaminA), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new VitaminA(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of VitaminA is InternationalUnit. All conversions, as defined in the , go via this value. + /// + public static VitaminAUnit DefaultBaseUnit { get; } = VitaminAUnit.InternationalUnit; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for VitaminA. + public static IEnumerable> GetDefaultMappings() + { + yield return new (VitaminAUnit.InternationalUnit, "InternationalUnit", "InternationalUnits", BaseUnits.Undefined); + } + } + + static VitaminA() + { + Info = VitaminAInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -99,27 +146,27 @@ public VitaminA(double value, VitaminAUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of VitaminA, which is InternationalUnit. All conversions go via this value. /// - public static VitaminAUnit BaseUnit { get; } + public static VitaminAUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the VitaminA quantity. /// - public static VitaminAUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit InternationalUnit. /// - public static VitaminA Zero { get; } + public static VitaminA Zero => Info.Zero; /// public static VitaminA AdditiveIdentity => Zero; @@ -137,7 +184,7 @@ public VitaminA(double value, VitaminAUnit unit) public VitaminAUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -155,6 +202,9 @@ public VitaminA(double value, VitaminAUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs index 711534ca4a..0c53394e4b 100644 --- a/UnitsNet/GeneratedCode/Quantities/Volume.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/Volume.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -78,72 +74,123 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly VolumeUnit? _unit; - static Volume() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class VolumeInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(3, 0, 0, 0, 0, 0, 0); - BaseUnit = VolumeUnit.CubicMeter; - Units = Enum.GetValues(typeof(VolumeUnit)).Cast().ToArray(); - Zero = new Volume(0, BaseUnit); - Info = new QuantityInfo("Volume", - new UnitInfo[] - { - new UnitInfo(VolumeUnit.AcreFoot, "AcreFeet", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.AuTablespoon, "AuTablespoons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.BoardFoot, "BoardFeet", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.Centiliter, "Centiliters", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.CubicCentimeter, "CubicCentimeters", new BaseUnits(length: LengthUnit.Centimeter), "Volume"), - new UnitInfo(VolumeUnit.CubicDecimeter, "CubicDecimeters", new BaseUnits(length: LengthUnit.Decimeter), "Volume"), - new UnitInfo(VolumeUnit.CubicFoot, "CubicFeet", new BaseUnits(length: LengthUnit.Foot), "Volume"), - new UnitInfo(VolumeUnit.CubicHectometer, "CubicHectometers", new BaseUnits(length: LengthUnit.Hectometer), "Volume"), - new UnitInfo(VolumeUnit.CubicInch, "CubicInches", new BaseUnits(length: LengthUnit.Inch), "Volume"), - new UnitInfo(VolumeUnit.CubicKilometer, "CubicKilometers", new BaseUnits(length: LengthUnit.Kilometer), "Volume"), - new UnitInfo(VolumeUnit.CubicMeter, "CubicMeters", new BaseUnits(length: LengthUnit.Meter), "Volume"), - new UnitInfo(VolumeUnit.CubicMicrometer, "CubicMicrometers", new BaseUnits(length: LengthUnit.Micrometer), "Volume"), - new UnitInfo(VolumeUnit.CubicMile, "CubicMiles", new BaseUnits(length: LengthUnit.Mile), "Volume"), - new UnitInfo(VolumeUnit.CubicMillimeter, "CubicMillimeters", new BaseUnits(length: LengthUnit.Millimeter), "Volume"), - new UnitInfo(VolumeUnit.CubicYard, "CubicYards", new BaseUnits(length: LengthUnit.Yard), "Volume"), - new UnitInfo(VolumeUnit.Decaliter, "Decaliters", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.DecausGallon, "DecausGallons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.Deciliter, "Deciliters", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.DeciusGallon, "DeciusGallons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.HectocubicFoot, "HectocubicFeet", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.HectocubicMeter, "HectocubicMeters", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.Hectoliter, "Hectoliters", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.HectousGallon, "HectousGallons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.ImperialBeerBarrel, "ImperialBeerBarrels", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.ImperialGallon, "ImperialGallons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.ImperialOunce, "ImperialOunces", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.ImperialPint, "ImperialPints", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.ImperialQuart, "ImperialQuarts", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.KilocubicFoot, "KilocubicFeet", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.KilocubicMeter, "KilocubicMeters", new BaseUnits(length: LengthUnit.Decameter), "Volume"), - new UnitInfo(VolumeUnit.KiloimperialGallon, "KiloimperialGallons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.Kiloliter, "Kiloliters", new BaseUnits(length: LengthUnit.Meter), "Volume"), - new UnitInfo(VolumeUnit.KilousGallon, "KilousGallons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.Liter, "Liters", new BaseUnits(length: LengthUnit.Decimeter), "Volume"), - new UnitInfo(VolumeUnit.MegacubicFoot, "MegacubicFeet", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.MegaimperialGallon, "MegaimperialGallons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.Megaliter, "Megaliters", new BaseUnits(length: LengthUnit.Decameter), "Volume"), - new UnitInfo(VolumeUnit.MegausGallon, "MegausGallons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.MetricCup, "MetricCups", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.MetricTeaspoon, "MetricTeaspoons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.Microliter, "Microliters", new BaseUnits(length: LengthUnit.Millimeter), "Volume"), - new UnitInfo(VolumeUnit.Milliliter, "Milliliters", new BaseUnits(length: LengthUnit.Centimeter), "Volume"), - new UnitInfo(VolumeUnit.Nanoliter, "Nanoliters", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.OilBarrel, "OilBarrels", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.UkTablespoon, "UkTablespoons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.UsBeerBarrel, "UsBeerBarrels", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.UsCustomaryCup, "UsCustomaryCups", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.UsGallon, "UsGallons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.UsLegalCup, "UsLegalCups", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.UsOunce, "UsOunces", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.UsPint, "UsPints", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.UsQuart, "UsQuarts", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.UsTablespoon, "UsTablespoons", BaseUnits.Undefined, "Volume"), - new UnitInfo(VolumeUnit.UsTeaspoon, "UsTeaspoons", BaseUnits.Undefined, "Volume"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public VolumeInfo(string name, VolumeUnit baseUnit, IEnumerable> unitMappings, Volume zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public VolumeInfo(string name, VolumeUnit baseUnit, IEnumerable> unitMappings, Volume zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, Volume.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.Volume", typeof(Volume).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the Volume quantity. + /// + /// A new instance of the class with the default settings. + public static VolumeInfo CreateDefault() + { + return new VolumeInfo(nameof(Volume), DefaultBaseUnit, GetDefaultMappings(), new Volume(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the Volume quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static VolumeInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new VolumeInfo(nameof(Volume), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new Volume(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^3]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(3, 0, 0, 0, 0, 0, 0); + + /// + /// The default base unit of Volume is CubicMeter. All conversions, as defined in the , go via this value. + /// + public static VolumeUnit DefaultBaseUnit { get; } = VolumeUnit.CubicMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for Volume. + public static IEnumerable> GetDefaultMappings() + { + yield return new (VolumeUnit.AcreFoot, "AcreFoot", "AcreFeet", BaseUnits.Undefined); + yield return new (VolumeUnit.AuTablespoon, "AuTablespoon", "AuTablespoons", BaseUnits.Undefined); + yield return new (VolumeUnit.BoardFoot, "BoardFoot", "BoardFeet", BaseUnits.Undefined); + yield return new (VolumeUnit.Centiliter, "Centiliter", "Centiliters", BaseUnits.Undefined); + yield return new (VolumeUnit.CubicCentimeter, "CubicCentimeter", "CubicCentimeters", new BaseUnits(length: LengthUnit.Centimeter)); + yield return new (VolumeUnit.CubicDecimeter, "CubicDecimeter", "CubicDecimeters", new BaseUnits(length: LengthUnit.Decimeter)); + yield return new (VolumeUnit.CubicFoot, "CubicFoot", "CubicFeet", new BaseUnits(length: LengthUnit.Foot)); + yield return new (VolumeUnit.CubicHectometer, "CubicHectometer", "CubicHectometers", new BaseUnits(length: LengthUnit.Hectometer)); + yield return new (VolumeUnit.CubicInch, "CubicInch", "CubicInches", new BaseUnits(length: LengthUnit.Inch)); + yield return new (VolumeUnit.CubicKilometer, "CubicKilometer", "CubicKilometers", new BaseUnits(length: LengthUnit.Kilometer)); + yield return new (VolumeUnit.CubicMeter, "CubicMeter", "CubicMeters", new BaseUnits(length: LengthUnit.Meter)); + yield return new (VolumeUnit.CubicMicrometer, "CubicMicrometer", "CubicMicrometers", new BaseUnits(length: LengthUnit.Micrometer)); + yield return new (VolumeUnit.CubicMile, "CubicMile", "CubicMiles", new BaseUnits(length: LengthUnit.Mile)); + yield return new (VolumeUnit.CubicMillimeter, "CubicMillimeter", "CubicMillimeters", new BaseUnits(length: LengthUnit.Millimeter)); + yield return new (VolumeUnit.CubicYard, "CubicYard", "CubicYards", new BaseUnits(length: LengthUnit.Yard)); + yield return new (VolumeUnit.Decaliter, "Decaliter", "Decaliters", BaseUnits.Undefined); + yield return new (VolumeUnit.DecausGallon, "DecausGallon", "DecausGallons", BaseUnits.Undefined); + yield return new (VolumeUnit.Deciliter, "Deciliter", "Deciliters", BaseUnits.Undefined); + yield return new (VolumeUnit.DeciusGallon, "DeciusGallon", "DeciusGallons", BaseUnits.Undefined); + yield return new (VolumeUnit.HectocubicFoot, "HectocubicFoot", "HectocubicFeet", BaseUnits.Undefined); + yield return new (VolumeUnit.HectocubicMeter, "HectocubicMeter", "HectocubicMeters", BaseUnits.Undefined); + yield return new (VolumeUnit.Hectoliter, "Hectoliter", "Hectoliters", BaseUnits.Undefined); + yield return new (VolumeUnit.HectousGallon, "HectousGallon", "HectousGallons", BaseUnits.Undefined); + yield return new (VolumeUnit.ImperialBeerBarrel, "ImperialBeerBarrel", "ImperialBeerBarrels", BaseUnits.Undefined); + yield return new (VolumeUnit.ImperialGallon, "ImperialGallon", "ImperialGallons", BaseUnits.Undefined); + yield return new (VolumeUnit.ImperialOunce, "ImperialOunce", "ImperialOunces", BaseUnits.Undefined); + yield return new (VolumeUnit.ImperialPint, "ImperialPint", "ImperialPints", BaseUnits.Undefined); + yield return new (VolumeUnit.ImperialQuart, "ImperialQuart", "ImperialQuarts", BaseUnits.Undefined); + yield return new (VolumeUnit.KilocubicFoot, "KilocubicFoot", "KilocubicFeet", BaseUnits.Undefined); + yield return new (VolumeUnit.KilocubicMeter, "KilocubicMeter", "KilocubicMeters", new BaseUnits(length: LengthUnit.Decameter)); + yield return new (VolumeUnit.KiloimperialGallon, "KiloimperialGallon", "KiloimperialGallons", BaseUnits.Undefined); + yield return new (VolumeUnit.Kiloliter, "Kiloliter", "Kiloliters", new BaseUnits(length: LengthUnit.Meter)); + yield return new (VolumeUnit.KilousGallon, "KilousGallon", "KilousGallons", BaseUnits.Undefined); + yield return new (VolumeUnit.Liter, "Liter", "Liters", new BaseUnits(length: LengthUnit.Decimeter)); + yield return new (VolumeUnit.MegacubicFoot, "MegacubicFoot", "MegacubicFeet", BaseUnits.Undefined); + yield return new (VolumeUnit.MegaimperialGallon, "MegaimperialGallon", "MegaimperialGallons", BaseUnits.Undefined); + yield return new (VolumeUnit.Megaliter, "Megaliter", "Megaliters", new BaseUnits(length: LengthUnit.Decameter)); + yield return new (VolumeUnit.MegausGallon, "MegausGallon", "MegausGallons", BaseUnits.Undefined); + yield return new (VolumeUnit.MetricCup, "MetricCup", "MetricCups", BaseUnits.Undefined); + yield return new (VolumeUnit.MetricTeaspoon, "MetricTeaspoon", "MetricTeaspoons", BaseUnits.Undefined); + yield return new (VolumeUnit.Microliter, "Microliter", "Microliters", new BaseUnits(length: LengthUnit.Millimeter)); + yield return new (VolumeUnit.Milliliter, "Milliliter", "Milliliters", new BaseUnits(length: LengthUnit.Centimeter)); + yield return new (VolumeUnit.Nanoliter, "Nanoliter", "Nanoliters", BaseUnits.Undefined); + yield return new (VolumeUnit.OilBarrel, "OilBarrel", "OilBarrels", BaseUnits.Undefined); + yield return new (VolumeUnit.UkTablespoon, "UkTablespoon", "UkTablespoons", BaseUnits.Undefined); + yield return new (VolumeUnit.UsBeerBarrel, "UsBeerBarrel", "UsBeerBarrels", BaseUnits.Undefined); + yield return new (VolumeUnit.UsCustomaryCup, "UsCustomaryCup", "UsCustomaryCups", BaseUnits.Undefined); + yield return new (VolumeUnit.UsGallon, "UsGallon", "UsGallons", BaseUnits.Undefined); + yield return new (VolumeUnit.UsLegalCup, "UsLegalCup", "UsLegalCups", BaseUnits.Undefined); + yield return new (VolumeUnit.UsOunce, "UsOunce", "UsOunces", BaseUnits.Undefined); + yield return new (VolumeUnit.UsPint, "UsPint", "UsPints", BaseUnits.Undefined); + yield return new (VolumeUnit.UsQuart, "UsQuart", "UsQuarts", BaseUnits.Undefined); + yield return new (VolumeUnit.UsTablespoon, "UsTablespoon", "UsTablespoons", BaseUnits.Undefined); + yield return new (VolumeUnit.UsTeaspoon, "UsTeaspoon", "UsTeaspoons", BaseUnits.Undefined); + } + } + + static Volume() + { + Info = VolumeInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -181,27 +228,27 @@ public Volume(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of Volume, which is CubicMeter. All conversions go via this value. /// - public static VolumeUnit BaseUnit { get; } + public static VolumeUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the Volume quantity. /// - public static VolumeUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit CubicMeter. /// - public static Volume Zero { get; } + public static Volume Zero => Info.Zero; /// public static Volume AdditiveIdentity => Zero; @@ -219,7 +266,7 @@ public Volume(double value, UnitSystem unitSystem) public VolumeUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -237,6 +284,9 @@ public Volume(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs index 5130c4b829..0d9590e781 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeConcentration.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -70,38 +66,89 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly VolumeConcentrationUnit? _unit; - static VolumeConcentration() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class VolumeConcentrationInfo: QuantityInfo { - BaseDimensions = BaseDimensions.Dimensionless; - BaseUnit = VolumeConcentrationUnit.DecimalFraction; - Units = Enum.GetValues(typeof(VolumeConcentrationUnit)).Cast().ToArray(); - Zero = new VolumeConcentration(0, BaseUnit); - Info = new QuantityInfo("VolumeConcentration", - new UnitInfo[] - { - new UnitInfo(VolumeConcentrationUnit.CentiliterPerLiter, "CentilitersPerLiter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.CentiliterPerMilliliter, "CentilitersPerMilliliter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.DeciliterPerLiter, "DecilitersPerLiter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.DeciliterPerMilliliter, "DecilitersPerMilliliter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.DecimalFraction, "DecimalFractions", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.LiterPerLiter, "LitersPerLiter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.LiterPerMilliliter, "LitersPerMilliliter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.MicroliterPerLiter, "MicrolitersPerLiter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.MicroliterPerMilliliter, "MicrolitersPerMilliliter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.MilliliterPerLiter, "MillilitersPerLiter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.MilliliterPerMilliliter, "MillilitersPerMilliliter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.NanoliterPerLiter, "NanolitersPerLiter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.NanoliterPerMilliliter, "NanolitersPerMilliliter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.PartPerBillion, "PartsPerBillion", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.PartPerMillion, "PartsPerMillion", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.PartPerThousand, "PartsPerThousand", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.PartPerTrillion, "PartsPerTrillion", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.Percent, "Percent", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.PicoliterPerLiter, "PicolitersPerLiter", BaseUnits.Undefined, "VolumeConcentration"), - new UnitInfo(VolumeConcentrationUnit.PicoliterPerMilliliter, "PicolitersPerMilliliter", BaseUnits.Undefined, "VolumeConcentration"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public VolumeConcentrationInfo(string name, VolumeConcentrationUnit baseUnit, IEnumerable> unitMappings, VolumeConcentration zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public VolumeConcentrationInfo(string name, VolumeConcentrationUnit baseUnit, IEnumerable> unitMappings, VolumeConcentration zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, VolumeConcentration.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.VolumeConcentration", typeof(VolumeConcentration).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the VolumeConcentration quantity. + /// + /// A new instance of the class with the default settings. + public static VolumeConcentrationInfo CreateDefault() + { + return new VolumeConcentrationInfo(nameof(VolumeConcentration), DefaultBaseUnit, GetDefaultMappings(), new VolumeConcentration(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the VolumeConcentration quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static VolumeConcentrationInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new VolumeConcentrationInfo(nameof(VolumeConcentration), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new VolumeConcentration(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is . + /// + public static BaseDimensions DefaultBaseDimensions { get; } = BaseDimensions.Dimensionless; + + /// + /// The default base unit of VolumeConcentration is DecimalFraction. All conversions, as defined in the , go via this value. + /// + public static VolumeConcentrationUnit DefaultBaseUnit { get; } = VolumeConcentrationUnit.DecimalFraction; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for VolumeConcentration. + public static IEnumerable> GetDefaultMappings() + { + yield return new (VolumeConcentrationUnit.CentiliterPerLiter, "CentiliterPerLiter", "CentilitersPerLiter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.CentiliterPerMilliliter, "CentiliterPerMilliliter", "CentilitersPerMilliliter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.DeciliterPerLiter, "DeciliterPerLiter", "DecilitersPerLiter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.DeciliterPerMilliliter, "DeciliterPerMilliliter", "DecilitersPerMilliliter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.DecimalFraction, "DecimalFraction", "DecimalFractions", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.LiterPerLiter, "LiterPerLiter", "LitersPerLiter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.LiterPerMilliliter, "LiterPerMilliliter", "LitersPerMilliliter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.MicroliterPerLiter, "MicroliterPerLiter", "MicrolitersPerLiter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.MicroliterPerMilliliter, "MicroliterPerMilliliter", "MicrolitersPerMilliliter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.MilliliterPerLiter, "MilliliterPerLiter", "MillilitersPerLiter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.MilliliterPerMilliliter, "MilliliterPerMilliliter", "MillilitersPerMilliliter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.NanoliterPerLiter, "NanoliterPerLiter", "NanolitersPerLiter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.NanoliterPerMilliliter, "NanoliterPerMilliliter", "NanolitersPerMilliliter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.PartPerBillion, "PartPerBillion", "PartsPerBillion", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.PartPerMillion, "PartPerMillion", "PartsPerMillion", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.PartPerThousand, "PartPerThousand", "PartsPerThousand", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.PartPerTrillion, "PartPerTrillion", "PartsPerTrillion", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.Percent, "Percent", "Percent", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.PicoliterPerLiter, "PicoliterPerLiter", "PicolitersPerLiter", BaseUnits.Undefined); + yield return new (VolumeConcentrationUnit.PicoliterPerMilliliter, "PicoliterPerMilliliter", "PicolitersPerMilliliter", BaseUnits.Undefined); + } + } + + static VolumeConcentration() + { + Info = VolumeConcentrationInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -125,27 +172,27 @@ public VolumeConcentration(double value, VolumeConcentrationUnit unit) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of VolumeConcentration, which is DecimalFraction. All conversions go via this value. /// - public static VolumeConcentrationUnit BaseUnit { get; } + public static VolumeConcentrationUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the VolumeConcentration quantity. /// - public static VolumeConcentrationUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit DecimalFraction. /// - public static VolumeConcentration Zero { get; } + public static VolumeConcentration Zero => Info.Zero; /// public static VolumeConcentration AdditiveIdentity => Zero; @@ -163,7 +210,7 @@ public VolumeConcentration(double value, VolumeConcentrationUnit unit) public VolumeConcentrationUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -181,6 +228,9 @@ public VolumeConcentration(double value, VolumeConcentrationUnit unit) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs index b160969e5f..3579d0aef2 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlow.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -70,93 +66,144 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly VolumeFlowUnit? _unit; - static VolumeFlow() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class VolumeFlowInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(3, 0, -1, 0, 0, 0, 0); - BaseUnit = VolumeFlowUnit.CubicMeterPerSecond; - Units = Enum.GetValues(typeof(VolumeFlowUnit)).Cast().ToArray(); - Zero = new VolumeFlow(0, BaseUnit); - Info = new QuantityInfo("VolumeFlow", - new UnitInfo[] - { - new UnitInfo(VolumeFlowUnit.AcreFootPerDay, "AcreFeetPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.AcreFootPerHour, "AcreFeetPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.AcreFootPerMinute, "AcreFeetPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.AcreFootPerSecond, "AcreFeetPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CentiliterPerDay, "CentilitersPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CentiliterPerHour, "CentilitersPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CentiliterPerMinute, "CentilitersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CentiliterPerSecond, "CentilitersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicCentimeterPerMinute, "CubicCentimetersPerMinute", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Minute), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicDecimeterPerMinute, "CubicDecimetersPerMinute", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Minute), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicFootPerHour, "CubicFeetPerHour", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Hour), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicFootPerMinute, "CubicFeetPerMinute", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Minute), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicFootPerSecond, "CubicFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicMeterPerDay, "CubicMetersPerDay", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Day), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicMeterPerHour, "CubicMetersPerHour", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Hour), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicMeterPerMinute, "CubicMetersPerMinute", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Minute), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicMeterPerSecond, "CubicMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicMillimeterPerSecond, "CubicMillimetersPerSecond", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicYardPerDay, "CubicYardsPerDay", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Day), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicYardPerHour, "CubicYardsPerHour", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Hour), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicYardPerMinute, "CubicYardsPerMinute", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Minute), "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.CubicYardPerSecond, "CubicYardsPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.DecaliterPerDay, "DecalitersPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.DecaliterPerHour, "DecalitersPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.DecaliterPerMinute, "DecalitersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.DecaliterPerSecond, "DecalitersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.DeciliterPerDay, "DecilitersPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.DeciliterPerHour, "DecilitersPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.DeciliterPerMinute, "DecilitersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.DeciliterPerSecond, "DecilitersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.HectoliterPerDay, "HectolitersPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.HectoliterPerHour, "HectolitersPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.HectoliterPerMinute, "HectolitersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.HectoliterPerSecond, "HectolitersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.KiloliterPerDay, "KilolitersPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.KiloliterPerHour, "KilolitersPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.KiloliterPerMinute, "KilolitersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.KiloliterPerSecond, "KilolitersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.KilousGallonPerMinute, "KilousGallonsPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.LiterPerDay, "LitersPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.LiterPerHour, "LitersPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.LiterPerMinute, "LitersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.LiterPerSecond, "LitersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MegaliterPerDay, "MegalitersPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MegaliterPerHour, "MegalitersPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MegaliterPerMinute, "MegalitersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MegaliterPerSecond, "MegalitersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MegaukGallonPerDay, "MegaukGallonsPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MegaukGallonPerSecond, "MegaukGallonsPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MegausGallonPerDay, "MegausGallonsPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MicroliterPerDay, "MicrolitersPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MicroliterPerHour, "MicrolitersPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MicroliterPerMinute, "MicrolitersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MicroliterPerSecond, "MicrolitersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MilliliterPerDay, "MillilitersPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MilliliterPerHour, "MillilitersPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MilliliterPerMinute, "MillilitersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MilliliterPerSecond, "MillilitersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.MillionUsGallonPerDay, "MillionUsGallonsPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.NanoliterPerDay, "NanolitersPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.NanoliterPerHour, "NanolitersPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.NanoliterPerMinute, "NanolitersPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.NanoliterPerSecond, "NanolitersPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.OilBarrelPerDay, "OilBarrelsPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.OilBarrelPerHour, "OilBarrelsPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.OilBarrelPerMinute, "OilBarrelsPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.OilBarrelPerSecond, "OilBarrelsPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.UkGallonPerDay, "UkGallonsPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.UkGallonPerHour, "UkGallonsPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.UkGallonPerMinute, "UkGallonsPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.UkGallonPerSecond, "UkGallonsPerSecond", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.UsGallonPerDay, "UsGallonsPerDay", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.UsGallonPerHour, "UsGallonsPerHour", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.UsGallonPerMinute, "UsGallonsPerMinute", BaseUnits.Undefined, "VolumeFlow"), - new UnitInfo(VolumeFlowUnit.UsGallonPerSecond, "UsGallonsPerSecond", BaseUnits.Undefined, "VolumeFlow"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public VolumeFlowInfo(string name, VolumeFlowUnit baseUnit, IEnumerable> unitMappings, VolumeFlow zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public VolumeFlowInfo(string name, VolumeFlowUnit baseUnit, IEnumerable> unitMappings, VolumeFlow zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, VolumeFlow.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.VolumeFlow", typeof(VolumeFlow).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the VolumeFlow quantity. + /// + /// A new instance of the class with the default settings. + public static VolumeFlowInfo CreateDefault() + { + return new VolumeFlowInfo(nameof(VolumeFlow), DefaultBaseUnit, GetDefaultMappings(), new VolumeFlow(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the VolumeFlow quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static VolumeFlowInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new VolumeFlowInfo(nameof(VolumeFlow), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new VolumeFlow(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][L^3]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(3, 0, -1, 0, 0, 0, 0); + + /// + /// The default base unit of VolumeFlow is CubicMeterPerSecond. All conversions, as defined in the , go via this value. + /// + public static VolumeFlowUnit DefaultBaseUnit { get; } = VolumeFlowUnit.CubicMeterPerSecond; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for VolumeFlow. + public static IEnumerable> GetDefaultMappings() + { + yield return new (VolumeFlowUnit.AcreFootPerDay, "AcreFootPerDay", "AcreFeetPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.AcreFootPerHour, "AcreFootPerHour", "AcreFeetPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.AcreFootPerMinute, "AcreFootPerMinute", "AcreFeetPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.AcreFootPerSecond, "AcreFootPerSecond", "AcreFeetPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.CentiliterPerDay, "CentiliterPerDay", "CentilitersPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.CentiliterPerHour, "CentiliterPerHour", "CentilitersPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.CentiliterPerMinute, "CentiliterPerMinute", "CentilitersPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.CentiliterPerSecond, "CentiliterPerSecond", "CentilitersPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.CubicCentimeterPerMinute, "CubicCentimeterPerMinute", "CubicCentimetersPerMinute", new BaseUnits(length: LengthUnit.Centimeter, time: DurationUnit.Minute)); + yield return new (VolumeFlowUnit.CubicDecimeterPerMinute, "CubicDecimeterPerMinute", "CubicDecimetersPerMinute", new BaseUnits(length: LengthUnit.Decimeter, time: DurationUnit.Minute)); + yield return new (VolumeFlowUnit.CubicFootPerHour, "CubicFootPerHour", "CubicFeetPerHour", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Hour)); + yield return new (VolumeFlowUnit.CubicFootPerMinute, "CubicFootPerMinute", "CubicFeetPerMinute", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Minute)); + yield return new (VolumeFlowUnit.CubicFootPerSecond, "CubicFootPerSecond", "CubicFeetPerSecond", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Second)); + yield return new (VolumeFlowUnit.CubicMeterPerDay, "CubicMeterPerDay", "CubicMetersPerDay", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Day)); + yield return new (VolumeFlowUnit.CubicMeterPerHour, "CubicMeterPerHour", "CubicMetersPerHour", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Hour)); + yield return new (VolumeFlowUnit.CubicMeterPerMinute, "CubicMeterPerMinute", "CubicMetersPerMinute", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Minute)); + yield return new (VolumeFlowUnit.CubicMeterPerSecond, "CubicMeterPerSecond", "CubicMetersPerSecond", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + yield return new (VolumeFlowUnit.CubicMillimeterPerSecond, "CubicMillimeterPerSecond", "CubicMillimetersPerSecond", new BaseUnits(length: LengthUnit.Millimeter, time: DurationUnit.Second)); + yield return new (VolumeFlowUnit.CubicYardPerDay, "CubicYardPerDay", "CubicYardsPerDay", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Day)); + yield return new (VolumeFlowUnit.CubicYardPerHour, "CubicYardPerHour", "CubicYardsPerHour", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Hour)); + yield return new (VolumeFlowUnit.CubicYardPerMinute, "CubicYardPerMinute", "CubicYardsPerMinute", new BaseUnits(length: LengthUnit.Yard, time: DurationUnit.Minute)); + yield return new (VolumeFlowUnit.CubicYardPerSecond, "CubicYardPerSecond", "CubicYardsPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.DecaliterPerDay, "DecaliterPerDay", "DecalitersPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.DecaliterPerHour, "DecaliterPerHour", "DecalitersPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.DecaliterPerMinute, "DecaliterPerMinute", "DecalitersPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.DecaliterPerSecond, "DecaliterPerSecond", "DecalitersPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.DeciliterPerDay, "DeciliterPerDay", "DecilitersPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.DeciliterPerHour, "DeciliterPerHour", "DecilitersPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.DeciliterPerMinute, "DeciliterPerMinute", "DecilitersPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.DeciliterPerSecond, "DeciliterPerSecond", "DecilitersPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.HectoliterPerDay, "HectoliterPerDay", "HectolitersPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.HectoliterPerHour, "HectoliterPerHour", "HectolitersPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.HectoliterPerMinute, "HectoliterPerMinute", "HectolitersPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.HectoliterPerSecond, "HectoliterPerSecond", "HectolitersPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.KiloliterPerDay, "KiloliterPerDay", "KilolitersPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.KiloliterPerHour, "KiloliterPerHour", "KilolitersPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.KiloliterPerMinute, "KiloliterPerMinute", "KilolitersPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.KiloliterPerSecond, "KiloliterPerSecond", "KilolitersPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.KilousGallonPerMinute, "KilousGallonPerMinute", "KilousGallonsPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.LiterPerDay, "LiterPerDay", "LitersPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.LiterPerHour, "LiterPerHour", "LitersPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.LiterPerMinute, "LiterPerMinute", "LitersPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.LiterPerSecond, "LiterPerSecond", "LitersPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MegaliterPerDay, "MegaliterPerDay", "MegalitersPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MegaliterPerHour, "MegaliterPerHour", "MegalitersPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MegaliterPerMinute, "MegaliterPerMinute", "MegalitersPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MegaliterPerSecond, "MegaliterPerSecond", "MegalitersPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MegaukGallonPerDay, "MegaukGallonPerDay", "MegaukGallonsPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MegaukGallonPerSecond, "MegaukGallonPerSecond", "MegaukGallonsPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MegausGallonPerDay, "MegausGallonPerDay", "MegausGallonsPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MicroliterPerDay, "MicroliterPerDay", "MicrolitersPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MicroliterPerHour, "MicroliterPerHour", "MicrolitersPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MicroliterPerMinute, "MicroliterPerMinute", "MicrolitersPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MicroliterPerSecond, "MicroliterPerSecond", "MicrolitersPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MilliliterPerDay, "MilliliterPerDay", "MillilitersPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MilliliterPerHour, "MilliliterPerHour", "MillilitersPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MilliliterPerMinute, "MilliliterPerMinute", "MillilitersPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MilliliterPerSecond, "MilliliterPerSecond", "MillilitersPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.MillionUsGallonPerDay, "MillionUsGallonPerDay", "MillionUsGallonsPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.NanoliterPerDay, "NanoliterPerDay", "NanolitersPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.NanoliterPerHour, "NanoliterPerHour", "NanolitersPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.NanoliterPerMinute, "NanoliterPerMinute", "NanolitersPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.NanoliterPerSecond, "NanoliterPerSecond", "NanolitersPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.OilBarrelPerDay, "OilBarrelPerDay", "OilBarrelsPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.OilBarrelPerHour, "OilBarrelPerHour", "OilBarrelsPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.OilBarrelPerMinute, "OilBarrelPerMinute", "OilBarrelsPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.OilBarrelPerSecond, "OilBarrelPerSecond", "OilBarrelsPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.UkGallonPerDay, "UkGallonPerDay", "UkGallonsPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.UkGallonPerHour, "UkGallonPerHour", "UkGallonsPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.UkGallonPerMinute, "UkGallonPerMinute", "UkGallonsPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.UkGallonPerSecond, "UkGallonPerSecond", "UkGallonsPerSecond", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.UsGallonPerDay, "UsGallonPerDay", "UsGallonsPerDay", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.UsGallonPerHour, "UsGallonPerHour", "UsGallonsPerHour", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.UsGallonPerMinute, "UsGallonPerMinute", "UsGallonsPerMinute", BaseUnits.Undefined); + yield return new (VolumeFlowUnit.UsGallonPerSecond, "UsGallonPerSecond", "UsGallonsPerSecond", BaseUnits.Undefined); + } + } + + static VolumeFlow() + { + Info = VolumeFlowInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -194,27 +241,27 @@ public VolumeFlow(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of VolumeFlow, which is CubicMeterPerSecond. All conversions go via this value. /// - public static VolumeFlowUnit BaseUnit { get; } + public static VolumeFlowUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the VolumeFlow quantity. /// - public static VolumeFlowUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit CubicMeterPerSecond. /// - public static VolumeFlow Zero { get; } + public static VolumeFlow Zero => Info.Zero; /// public static VolumeFlow AdditiveIdentity => Zero; @@ -232,7 +279,7 @@ public VolumeFlow(double value, UnitSystem unitSystem) public VolumeFlowUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -250,6 +297,9 @@ public VolumeFlow(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs index 903b1ab63b..bcd8e7c5c5 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumeFlowPerArea.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,20 +59,71 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly VolumeFlowPerAreaUnit? _unit; - static VolumeFlowPerArea() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class VolumeFlowPerAreaInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(1, 0, -1, 0, 0, 0, 0); - BaseUnit = VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter; - Units = Enum.GetValues(typeof(VolumeFlowPerAreaUnit)).Cast().ToArray(); - Zero = new VolumeFlowPerArea(0, BaseUnit); - Info = new QuantityInfo("VolumeFlowPerArea", - new UnitInfo[] - { - new UnitInfo(VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot, "CubicFeetPerMinutePerSquareFoot", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Minute), "VolumeFlowPerArea"), - new UnitInfo(VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, "CubicMetersPerSecondPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second), "VolumeFlowPerArea"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public VolumeFlowPerAreaInfo(string name, VolumeFlowPerAreaUnit baseUnit, IEnumerable> unitMappings, VolumeFlowPerArea zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public VolumeFlowPerAreaInfo(string name, VolumeFlowPerAreaUnit baseUnit, IEnumerable> unitMappings, VolumeFlowPerArea zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, VolumeFlowPerArea.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.VolumeFlowPerArea", typeof(VolumeFlowPerArea).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the VolumeFlowPerArea quantity. + /// + /// A new instance of the class with the default settings. + public static VolumeFlowPerAreaInfo CreateDefault() + { + return new VolumeFlowPerAreaInfo(nameof(VolumeFlowPerArea), DefaultBaseUnit, GetDefaultMappings(), new VolumeFlowPerArea(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the VolumeFlowPerArea quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static VolumeFlowPerAreaInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new VolumeFlowPerAreaInfo(nameof(VolumeFlowPerArea), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new VolumeFlowPerArea(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-1][L]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(1, 0, -1, 0, 0, 0, 0); + + /// + /// The default base unit of VolumeFlowPerArea is CubicMeterPerSecondPerSquareMeter. All conversions, as defined in the , go via this value. + /// + public static VolumeFlowPerAreaUnit DefaultBaseUnit { get; } = VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for VolumeFlowPerArea. + public static IEnumerable> GetDefaultMappings() + { + yield return new (VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot, "CubicFootPerMinutePerSquareFoot", "CubicFeetPerMinutePerSquareFoot", new BaseUnits(length: LengthUnit.Foot, time: DurationUnit.Minute)); + yield return new (VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, "CubicMeterPerSecondPerSquareMeter", "CubicMetersPerSecondPerSquareMeter", new BaseUnits(length: LengthUnit.Meter, time: DurationUnit.Second)); + } + } + + static VolumeFlowPerArea() + { + Info = VolumeFlowPerAreaInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -114,27 +161,27 @@ public VolumeFlowPerArea(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of VolumeFlowPerArea, which is CubicMeterPerSecondPerSquareMeter. All conversions go via this value. /// - public static VolumeFlowPerAreaUnit BaseUnit { get; } + public static VolumeFlowPerAreaUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the VolumeFlowPerArea quantity. /// - public static VolumeFlowPerAreaUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit CubicMeterPerSecondPerSquareMeter. /// - public static VolumeFlowPerArea Zero { get; } + public static VolumeFlowPerArea Zero => Info.Zero; /// public static VolumeFlowPerArea AdditiveIdentity => Zero; @@ -152,7 +199,7 @@ public VolumeFlowPerArea(double value, UnitSystem unitSystem) public VolumeFlowPerAreaUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -170,6 +217,9 @@ public VolumeFlowPerArea(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs index 49a17c2b03..f0a52c2401 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumePerLength.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,27 +59,78 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly VolumePerLengthUnit? _unit; - static VolumePerLength() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class VolumePerLengthInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(2, 0, 0, 0, 0, 0, 0); - BaseUnit = VolumePerLengthUnit.CubicMeterPerMeter; - Units = Enum.GetValues(typeof(VolumePerLengthUnit)).Cast().ToArray(); - Zero = new VolumePerLength(0, BaseUnit); - Info = new QuantityInfo("VolumePerLength", - new UnitInfo[] - { - new UnitInfo(VolumePerLengthUnit.CubicMeterPerMeter, "CubicMetersPerMeter", new BaseUnits(length: LengthUnit.Meter), "VolumePerLength"), - new UnitInfo(VolumePerLengthUnit.CubicYardPerFoot, "CubicYardsPerFoot", BaseUnits.Undefined, "VolumePerLength"), - new UnitInfo(VolumePerLengthUnit.CubicYardPerUsSurveyFoot, "CubicYardsPerUsSurveyFoot", BaseUnits.Undefined, "VolumePerLength"), - new UnitInfo(VolumePerLengthUnit.ImperialGallonPerMile, "ImperialGallonsPerMile", BaseUnits.Undefined, "VolumePerLength"), - new UnitInfo(VolumePerLengthUnit.LiterPerKilometer, "LitersPerKilometer", BaseUnits.Undefined, "VolumePerLength"), - new UnitInfo(VolumePerLengthUnit.LiterPerMeter, "LitersPerMeter", new BaseUnits(length: LengthUnit.Decimeter), "VolumePerLength"), - new UnitInfo(VolumePerLengthUnit.LiterPerMillimeter, "LitersPerMillimeter", BaseUnits.Undefined, "VolumePerLength"), - new UnitInfo(VolumePerLengthUnit.OilBarrelPerFoot, "OilBarrelsPerFoot", BaseUnits.Undefined, "VolumePerLength"), - new UnitInfo(VolumePerLengthUnit.UsGallonPerMile, "UsGallonsPerMile", BaseUnits.Undefined, "VolumePerLength"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public VolumePerLengthInfo(string name, VolumePerLengthUnit baseUnit, IEnumerable> unitMappings, VolumePerLength zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public VolumePerLengthInfo(string name, VolumePerLengthUnit baseUnit, IEnumerable> unitMappings, VolumePerLength zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, VolumePerLength.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.VolumePerLength", typeof(VolumePerLength).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the VolumePerLength quantity. + /// + /// A new instance of the class with the default settings. + public static VolumePerLengthInfo CreateDefault() + { + return new VolumePerLengthInfo(nameof(VolumePerLength), DefaultBaseUnit, GetDefaultMappings(), new VolumePerLength(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the VolumePerLength quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static VolumePerLengthInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new VolumePerLengthInfo(nameof(VolumePerLength), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new VolumePerLength(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^2]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(2, 0, 0, 0, 0, 0, 0); + + /// + /// The default base unit of VolumePerLength is CubicMeterPerMeter. All conversions, as defined in the , go via this value. + /// + public static VolumePerLengthUnit DefaultBaseUnit { get; } = VolumePerLengthUnit.CubicMeterPerMeter; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for VolumePerLength. + public static IEnumerable> GetDefaultMappings() + { + yield return new (VolumePerLengthUnit.CubicMeterPerMeter, "CubicMeterPerMeter", "CubicMetersPerMeter", new BaseUnits(length: LengthUnit.Meter)); + yield return new (VolumePerLengthUnit.CubicYardPerFoot, "CubicYardPerFoot", "CubicYardsPerFoot", BaseUnits.Undefined); + yield return new (VolumePerLengthUnit.CubicYardPerUsSurveyFoot, "CubicYardPerUsSurveyFoot", "CubicYardsPerUsSurveyFoot", BaseUnits.Undefined); + yield return new (VolumePerLengthUnit.ImperialGallonPerMile, "ImperialGallonPerMile", "ImperialGallonsPerMile", BaseUnits.Undefined); + yield return new (VolumePerLengthUnit.LiterPerKilometer, "LiterPerKilometer", "LitersPerKilometer", BaseUnits.Undefined); + yield return new (VolumePerLengthUnit.LiterPerMeter, "LiterPerMeter", "LitersPerMeter", new BaseUnits(length: LengthUnit.Decimeter)); + yield return new (VolumePerLengthUnit.LiterPerMillimeter, "LiterPerMillimeter", "LitersPerMillimeter", BaseUnits.Undefined); + yield return new (VolumePerLengthUnit.OilBarrelPerFoot, "OilBarrelPerFoot", "OilBarrelsPerFoot", BaseUnits.Undefined); + yield return new (VolumePerLengthUnit.UsGallonPerMile, "UsGallonPerMile", "UsGallonsPerMile", BaseUnits.Undefined); + } + } + + static VolumePerLength() + { + Info = VolumePerLengthInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -121,27 +168,27 @@ public VolumePerLength(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of VolumePerLength, which is CubicMeterPerMeter. All conversions go via this value. /// - public static VolumePerLengthUnit BaseUnit { get; } + public static VolumePerLengthUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the VolumePerLength quantity. /// - public static VolumePerLengthUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit CubicMeterPerMeter. /// - public static VolumePerLength Zero { get; } + public static VolumePerLength Zero => Info.Zero; /// public static VolumePerLength AdditiveIdentity => Zero; @@ -159,7 +206,7 @@ public VolumePerLength(double value, UnitSystem unitSystem) public VolumePerLengthUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -177,6 +224,9 @@ public VolumePerLength(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs b/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs index e1888a5ac6..0f551da1ff 100644 --- a/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/VolumetricHeatCapacity.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -66,27 +62,78 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly VolumetricHeatCapacityUnit? _unit; - static VolumetricHeatCapacity() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class VolumetricHeatCapacityInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(-1, 1, -2, 0, -1, 0, 0); - BaseUnit = VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin; - Units = Enum.GetValues(typeof(VolumetricHeatCapacityUnit)).Cast().ToArray(); - Zero = new VolumetricHeatCapacity(0, BaseUnit); - Info = new QuantityInfo("VolumetricHeatCapacity", - new UnitInfo[] - { - new UnitInfo(VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, "BtusPerCubicFootDegreeFahrenheit", BaseUnits.Undefined, "VolumetricHeatCapacity"), - new UnitInfo(VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius, "CaloriesPerCubicCentimeterDegreeCelsius", BaseUnits.Undefined, "VolumetricHeatCapacity"), - new UnitInfo(VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius, "JoulesPerCubicMeterDegreeCelsius", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "VolumetricHeatCapacity"), - new UnitInfo(VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, "JoulesPerCubicMeterKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "VolumetricHeatCapacity"), - new UnitInfo(VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius, "KilocaloriesPerCubicCentimeterDegreeCelsius", BaseUnits.Undefined, "VolumetricHeatCapacity"), - new UnitInfo(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius, "KilojoulesPerCubicMeterDegreeCelsius", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "VolumetricHeatCapacity"), - new UnitInfo(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin, "KilojoulesPerCubicMeterKelvin", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "VolumetricHeatCapacity"), - new UnitInfo(VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius, "MegajoulesPerCubicMeterDegreeCelsius", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius), "VolumetricHeatCapacity"), - new UnitInfo(VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin, "MegajoulesPerCubicMeterKelvin", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin), "VolumetricHeatCapacity"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public VolumetricHeatCapacityInfo(string name, VolumetricHeatCapacityUnit baseUnit, IEnumerable> unitMappings, VolumetricHeatCapacity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public VolumetricHeatCapacityInfo(string name, VolumetricHeatCapacityUnit baseUnit, IEnumerable> unitMappings, VolumetricHeatCapacity zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, VolumetricHeatCapacity.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.VolumetricHeatCapacity", typeof(VolumetricHeatCapacity).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the VolumetricHeatCapacity quantity. + /// + /// A new instance of the class with the default settings. + public static VolumetricHeatCapacityInfo CreateDefault() + { + return new VolumetricHeatCapacityInfo(nameof(VolumetricHeatCapacity), DefaultBaseUnit, GetDefaultMappings(), new VolumetricHeatCapacity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the VolumetricHeatCapacity quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static VolumetricHeatCapacityInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new VolumetricHeatCapacityInfo(nameof(VolumetricHeatCapacity), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new VolumetricHeatCapacity(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [T^-2][L^-1][M][Θ^-1]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(-1, 1, -2, 0, -1, 0, 0); + + /// + /// The default base unit of VolumetricHeatCapacity is JoulePerCubicMeterKelvin. All conversions, as defined in the , go via this value. + /// + public static VolumetricHeatCapacityUnit DefaultBaseUnit { get; } = VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for VolumetricHeatCapacity. + public static IEnumerable> GetDefaultMappings() + { + yield return new (VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, "BtuPerCubicFootDegreeFahrenheit", "BtusPerCubicFootDegreeFahrenheit", BaseUnits.Undefined); + yield return new (VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius, "CaloriePerCubicCentimeterDegreeCelsius", "CaloriesPerCubicCentimeterDegreeCelsius", BaseUnits.Undefined); + yield return new (VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius, "JoulePerCubicMeterDegreeCelsius", "JoulesPerCubicMeterDegreeCelsius", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, "JoulePerCubicMeterKelvin", "JoulesPerCubicMeterKelvin", new BaseUnits(length: LengthUnit.Meter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin)); + yield return new (VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius, "KilocaloriePerCubicCentimeterDegreeCelsius", "KilocaloriesPerCubicCentimeterDegreeCelsius", BaseUnits.Undefined); + yield return new (VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius, "KilojoulePerCubicMeterDegreeCelsius", "KilojoulesPerCubicMeterDegreeCelsius", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin, "KilojoulePerCubicMeterKelvin", "KilojoulesPerCubicMeterKelvin", new BaseUnits(length: LengthUnit.Millimeter, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin)); + yield return new (VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius, "MegajoulePerCubicMeterDegreeCelsius", "MegajoulesPerCubicMeterDegreeCelsius", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.DegreeCelsius)); + yield return new (VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin, "MegajoulePerCubicMeterKelvin", "MegajoulesPerCubicMeterKelvin", new BaseUnits(length: LengthUnit.Micrometer, mass: MassUnit.Kilogram, time: DurationUnit.Second, temperature: TemperatureUnit.Kelvin)); + } + } + + static VolumetricHeatCapacity() + { + Info = VolumetricHeatCapacityInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -124,27 +171,27 @@ public VolumetricHeatCapacity(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of VolumetricHeatCapacity, which is JoulePerCubicMeterKelvin. All conversions go via this value. /// - public static VolumetricHeatCapacityUnit BaseUnit { get; } + public static VolumetricHeatCapacityUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the VolumetricHeatCapacity quantity. /// - public static VolumetricHeatCapacityUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit JoulePerCubicMeterKelvin. /// - public static VolumetricHeatCapacity Zero { get; } + public static VolumetricHeatCapacity Zero => Info.Zero; /// public static VolumetricHeatCapacity AdditiveIdentity => Zero; @@ -162,7 +209,7 @@ public VolumetricHeatCapacity(double value, UnitSystem unitSystem) public VolumetricHeatCapacityUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -180,6 +227,9 @@ public VolumetricHeatCapacity(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs b/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs index 6426a72417..71770b9a68 100644 --- a/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs +++ b/UnitsNet/GeneratedCode/Quantities/WarpingMomentOfInertia.g.cs @@ -17,13 +17,9 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; -using System.Linq; +using System.Resources; using System.Runtime.Serialization; -using UnitsNet.Units; #if NET using System.Numerics; #endif @@ -63,24 +59,75 @@ namespace UnitsNet [DataMember(Name = "Unit", Order = 2)] private readonly WarpingMomentOfInertiaUnit? _unit; - static WarpingMomentOfInertia() + /// + /// Provides detailed information about the quantity, including its name, base unit, unit mappings, base dimensions, and conversion functions. + /// + public sealed class WarpingMomentOfInertiaInfo: QuantityInfo { - BaseDimensions = new BaseDimensions(6, 0, 0, 0, 0, 0, 0); - BaseUnit = WarpingMomentOfInertiaUnit.MeterToTheSixth; - Units = Enum.GetValues(typeof(WarpingMomentOfInertiaUnit)).Cast().ToArray(); - Zero = new WarpingMomentOfInertia(0, BaseUnit); - Info = new QuantityInfo("WarpingMomentOfInertia", - new UnitInfo[] - { - new UnitInfo(WarpingMomentOfInertiaUnit.CentimeterToTheSixth, "CentimetersToTheSixth", new BaseUnits(length: LengthUnit.Centimeter), "WarpingMomentOfInertia"), - new UnitInfo(WarpingMomentOfInertiaUnit.DecimeterToTheSixth, "DecimetersToTheSixth", new BaseUnits(length: LengthUnit.Decimeter), "WarpingMomentOfInertia"), - new UnitInfo(WarpingMomentOfInertiaUnit.FootToTheSixth, "FeetToTheSixth", new BaseUnits(length: LengthUnit.Foot), "WarpingMomentOfInertia"), - new UnitInfo(WarpingMomentOfInertiaUnit.InchToTheSixth, "InchesToTheSixth", new BaseUnits(length: LengthUnit.Inch), "WarpingMomentOfInertia"), - new UnitInfo(WarpingMomentOfInertiaUnit.MeterToTheSixth, "MetersToTheSixth", new BaseUnits(length: LengthUnit.Meter), "WarpingMomentOfInertia"), - new UnitInfo(WarpingMomentOfInertiaUnit.MillimeterToTheSixth, "MillimetersToTheSixth", new BaseUnits(length: LengthUnit.Millimeter), "WarpingMomentOfInertia"), - }, - BaseUnit, Zero, BaseDimensions); + /// + public WarpingMomentOfInertiaInfo(string name, WarpingMomentOfInertiaUnit baseUnit, IEnumerable> unitMappings, WarpingMomentOfInertia zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations) + : base(name, baseUnit, unitMappings, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + public WarpingMomentOfInertiaInfo(string name, WarpingMomentOfInertiaUnit baseUnit, IEnumerable> unitMappings, WarpingMomentOfInertia zero, BaseDimensions baseDimensions) + : this(name, baseUnit, unitMappings, zero, baseDimensions, WarpingMomentOfInertia.From, new ResourceManager("UnitsNet.GeneratedCode.Resources.WarpingMomentOfInertia", typeof(WarpingMomentOfInertia).Assembly)) + { + } + + /// + /// Creates a new instance of the class with the default settings for the WarpingMomentOfInertia quantity. + /// + /// A new instance of the class with the default settings. + public static WarpingMomentOfInertiaInfo CreateDefault() + { + return new WarpingMomentOfInertiaInfo(nameof(WarpingMomentOfInertia), DefaultBaseUnit, GetDefaultMappings(), new WarpingMomentOfInertia(0, DefaultBaseUnit), DefaultBaseDimensions); + } + /// + /// Creates a new instance of the class with the default settings for the WarpingMomentOfInertia quantity and a callback for customizing the default unit mappings. + /// + /// + /// A callback function for customizing the default unit mappings. + /// + /// + /// A new instance of the class with the default settings. + /// + public static WarpingMomentOfInertiaInfo CreateDefault(Func>, IEnumerable>> customizeUnits) + { + return new WarpingMomentOfInertiaInfo(nameof(WarpingMomentOfInertia), DefaultBaseUnit, customizeUnits(GetDefaultMappings()), new WarpingMomentOfInertia(0, DefaultBaseUnit), DefaultBaseDimensions); + } + + /// + /// The for is [L^6]. + /// + public static BaseDimensions DefaultBaseDimensions { get; } = new BaseDimensions(6, 0, 0, 0, 0, 0, 0); + + /// + /// The default base unit of WarpingMomentOfInertia is MeterToTheSixth. All conversions, as defined in the , go via this value. + /// + public static WarpingMomentOfInertiaUnit DefaultBaseUnit { get; } = WarpingMomentOfInertiaUnit.MeterToTheSixth; + + /// + /// Retrieves the default mappings for . + /// + /// An of representing the default unit mappings for WarpingMomentOfInertia. + public static IEnumerable> GetDefaultMappings() + { + yield return new (WarpingMomentOfInertiaUnit.CentimeterToTheSixth, "CentimeterToTheSixth", "CentimetersToTheSixth", new BaseUnits(length: LengthUnit.Centimeter)); + yield return new (WarpingMomentOfInertiaUnit.DecimeterToTheSixth, "DecimeterToTheSixth", "DecimetersToTheSixth", new BaseUnits(length: LengthUnit.Decimeter)); + yield return new (WarpingMomentOfInertiaUnit.FootToTheSixth, "FootToTheSixth", "FeetToTheSixth", new BaseUnits(length: LengthUnit.Foot)); + yield return new (WarpingMomentOfInertiaUnit.InchToTheSixth, "InchToTheSixth", "InchesToTheSixth", new BaseUnits(length: LengthUnit.Inch)); + yield return new (WarpingMomentOfInertiaUnit.MeterToTheSixth, "MeterToTheSixth", "MetersToTheSixth", new BaseUnits(length: LengthUnit.Meter)); + yield return new (WarpingMomentOfInertiaUnit.MillimeterToTheSixth, "MillimeterToTheSixth", "MillimetersToTheSixth", new BaseUnits(length: LengthUnit.Millimeter)); + } + } + + static WarpingMomentOfInertia() + { + Info = WarpingMomentOfInertiaInfo.CreateDefault(); DefaultConversionFunctions = new UnitConverter(); RegisterDefaultConversions(DefaultConversionFunctions); } @@ -118,27 +165,27 @@ public WarpingMomentOfInertia(double value, UnitSystem unitSystem) public static UnitConverter DefaultConversionFunctions { get; } /// - public static QuantityInfo Info { get; } + public static QuantityInfo Info { get; } /// /// The of this quantity. /// - public static BaseDimensions BaseDimensions { get; } + public static BaseDimensions BaseDimensions => Info.BaseDimensions; /// /// The base unit of WarpingMomentOfInertia, which is MeterToTheSixth. All conversions go via this value. /// - public static WarpingMomentOfInertiaUnit BaseUnit { get; } + public static WarpingMomentOfInertiaUnit BaseUnit => Info.BaseUnitInfo.Value; /// /// All units of measurement for the WarpingMomentOfInertia quantity. /// - public static WarpingMomentOfInertiaUnit[] Units { get; } + public static IReadOnlyCollection Units => Info.Units; /// /// Gets an instance of this quantity with a value of 0 in the base unit MeterToTheSixth. /// - public static WarpingMomentOfInertia Zero { get; } + public static WarpingMomentOfInertia Zero => Info.Zero; /// public static WarpingMomentOfInertia AdditiveIdentity => Zero; @@ -156,7 +203,7 @@ public WarpingMomentOfInertia(double value, UnitSystem unitSystem) public WarpingMomentOfInertiaUnit Unit => _unit.GetValueOrDefault(BaseUnit); /// - public QuantityInfo QuantityInfo => Info; + public QuantityInfo QuantityInfo => Info; /// /// The of this quantity. @@ -174,6 +221,9 @@ public WarpingMomentOfInertia(double value, UnitSystem unitSystem) [DebuggerBrowsable(DebuggerBrowsableState.Never)] QuantityInfo IQuantity.QuantityInfo => Info; + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + QuantityInfo IQuantity.QuantityInfo => Info; + #endregion #endregion diff --git a/UnitsNet/GeneratedCode/Quantity.g.cs b/UnitsNet/GeneratedCode/Quantity.g.cs index bbd4d73463..403d455522 100644 --- a/UnitsNet/GeneratedCode/Quantity.g.cs +++ b/UnitsNet/GeneratedCode/Quantity.g.cs @@ -17,720 +17,152 @@ // 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 UnitsNet.Units; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; - #nullable enable -namespace UnitsNet +namespace UnitsNet; + +/// +/// Dynamically parse or construct quantities when types are only known at runtime. +/// +public partial class Quantity { /// - /// Dynamically parse or construct quantities when types are only known at runtime. + /// Serves as a repository for predefined quantity conversion mappings, facilitating the automatic generation and retrieval of unit conversions in the UnitsNet library. /// - public partial class Quantity + internal static class Provider { /// - /// All QuantityInfo instances mapped by quantity name that are present in UnitsNet by default. + /// All QuantityInfo instances that are present in UnitsNet by default. /// - public static readonly IDictionary ByName = new Dictionary + internal static IReadOnlyList DefaultQuantities => new QuantityInfo[] { - { "AbsorbedDoseOfIonizingRadiation", AbsorbedDoseOfIonizingRadiation.Info }, - { "Acceleration", Acceleration.Info }, - { "AmountOfSubstance", AmountOfSubstance.Info }, - { "AmplitudeRatio", AmplitudeRatio.Info }, - { "Angle", Angle.Info }, - { "Area", Area.Info }, - { "AreaDensity", AreaDensity.Info }, - { "AreaMomentOfInertia", AreaMomentOfInertia.Info }, - { "BitRate", BitRate.Info }, - { "BrakeSpecificFuelConsumption", BrakeSpecificFuelConsumption.Info }, - { "CoefficientOfThermalExpansion", CoefficientOfThermalExpansion.Info }, - { "Compressibility", Compressibility.Info }, - { "Density", Density.Info }, - { "DoseAreaProduct", DoseAreaProduct.Info }, - { "Duration", Duration.Info }, - { "DynamicViscosity", DynamicViscosity.Info }, - { "ElectricAdmittance", ElectricAdmittance.Info }, - { "ElectricApparentEnergy", ElectricApparentEnergy.Info }, - { "ElectricApparentPower", ElectricApparentPower.Info }, - { "ElectricCapacitance", ElectricCapacitance.Info }, - { "ElectricCharge", ElectricCharge.Info }, - { "ElectricChargeDensity", ElectricChargeDensity.Info }, - { "ElectricConductance", ElectricConductance.Info }, - { "ElectricConductivity", ElectricConductivity.Info }, - { "ElectricCurrent", ElectricCurrent.Info }, - { "ElectricCurrentDensity", ElectricCurrentDensity.Info }, - { "ElectricCurrentGradient", ElectricCurrentGradient.Info }, - { "ElectricField", ElectricField.Info }, - { "ElectricImpedance", ElectricImpedance.Info }, - { "ElectricInductance", ElectricInductance.Info }, - { "ElectricPotential", ElectricPotential.Info }, - { "ElectricPotentialChangeRate", ElectricPotentialChangeRate.Info }, - { "ElectricReactance", ElectricReactance.Info }, - { "ElectricReactiveEnergy", ElectricReactiveEnergy.Info }, - { "ElectricReactivePower", ElectricReactivePower.Info }, - { "ElectricResistance", ElectricResistance.Info }, - { "ElectricResistivity", ElectricResistivity.Info }, - { "ElectricSurfaceChargeDensity", ElectricSurfaceChargeDensity.Info }, - { "ElectricSusceptance", ElectricSusceptance.Info }, - { "Energy", Energy.Info }, - { "EnergyDensity", EnergyDensity.Info }, - { "Entropy", Entropy.Info }, - { "FluidResistance", FluidResistance.Info }, - { "Force", Force.Info }, - { "ForceChangeRate", ForceChangeRate.Info }, - { "ForcePerLength", ForcePerLength.Info }, - { "Frequency", Frequency.Info }, - { "FuelEfficiency", FuelEfficiency.Info }, - { "HeatFlux", HeatFlux.Info }, - { "HeatTransferCoefficient", HeatTransferCoefficient.Info }, - { "Illuminance", Illuminance.Info }, - { "Impulse", Impulse.Info }, - { "Information", Information.Info }, - { "Irradiance", Irradiance.Info }, - { "Irradiation", Irradiation.Info }, - { "Jerk", Jerk.Info }, - { "KinematicViscosity", KinematicViscosity.Info }, - { "LeakRate", LeakRate.Info }, - { "Length", Length.Info }, - { "Level", Level.Info }, - { "LinearDensity", LinearDensity.Info }, - { "LinearPowerDensity", LinearPowerDensity.Info }, - { "Luminance", Luminance.Info }, - { "Luminosity", Luminosity.Info }, - { "LuminousFlux", LuminousFlux.Info }, - { "LuminousIntensity", LuminousIntensity.Info }, - { "MagneticField", MagneticField.Info }, - { "MagneticFlux", MagneticFlux.Info }, - { "Magnetization", Magnetization.Info }, - { "Mass", Mass.Info }, - { "MassConcentration", MassConcentration.Info }, - { "MassFlow", MassFlow.Info }, - { "MassFlux", MassFlux.Info }, - { "MassFraction", MassFraction.Info }, - { "MassMomentOfInertia", MassMomentOfInertia.Info }, - { "Molality", Molality.Info }, - { "MolarEnergy", MolarEnergy.Info }, - { "MolarEntropy", MolarEntropy.Info }, - { "MolarFlow", MolarFlow.Info }, - { "Molarity", Molarity.Info }, - { "MolarMass", MolarMass.Info }, - { "Permeability", Permeability.Info }, - { "Permittivity", Permittivity.Info }, - { "PorousMediumPermeability", PorousMediumPermeability.Info }, - { "Power", Power.Info }, - { "PowerDensity", PowerDensity.Info }, - { "PowerRatio", PowerRatio.Info }, - { "Pressure", Pressure.Info }, - { "PressureChangeRate", PressureChangeRate.Info }, - { "RadiationEquivalentDose", RadiationEquivalentDose.Info }, - { "RadiationEquivalentDoseRate", RadiationEquivalentDoseRate.Info }, - { "RadiationExposure", RadiationExposure.Info }, - { "Radioactivity", Radioactivity.Info }, - { "Ratio", Ratio.Info }, - { "RatioChangeRate", RatioChangeRate.Info }, - { "ReciprocalArea", ReciprocalArea.Info }, - { "ReciprocalLength", ReciprocalLength.Info }, - { "RelativeHumidity", RelativeHumidity.Info }, - { "RotationalAcceleration", RotationalAcceleration.Info }, - { "RotationalSpeed", RotationalSpeed.Info }, - { "RotationalStiffness", RotationalStiffness.Info }, - { "RotationalStiffnessPerLength", RotationalStiffnessPerLength.Info }, - { "Scalar", Scalar.Info }, - { "SolidAngle", SolidAngle.Info }, - { "SpecificEnergy", SpecificEnergy.Info }, - { "SpecificEntropy", SpecificEntropy.Info }, - { "SpecificFuelConsumption", SpecificFuelConsumption.Info }, - { "SpecificVolume", SpecificVolume.Info }, - { "SpecificWeight", SpecificWeight.Info }, - { "Speed", Speed.Info }, - { "StandardVolumeFlow", StandardVolumeFlow.Info }, - { "Temperature", Temperature.Info }, - { "TemperatureChangeRate", TemperatureChangeRate.Info }, - { "TemperatureDelta", TemperatureDelta.Info }, - { "TemperatureGradient", TemperatureGradient.Info }, - { "ThermalConductivity", ThermalConductivity.Info }, - { "ThermalInsulance", ThermalInsulance.Info }, - { "Torque", Torque.Info }, - { "Turbidity", Turbidity.Info }, - { "VitaminA", VitaminA.Info }, - { "Volume", Volume.Info }, - { "VolumeConcentration", VolumeConcentration.Info }, - { "VolumeFlow", VolumeFlow.Info }, - { "VolumeFlowPerArea", VolumeFlowPerArea.Info }, - { "VolumePerLength", VolumePerLength.Info }, - { "VolumetricHeatCapacity", VolumetricHeatCapacity.Info }, - { "WarpingMomentOfInertia", WarpingMomentOfInertia.Info }, + AbsorbedDoseOfIonizingRadiation.Info, + Acceleration.Info, + AmountOfSubstance.Info, + AmplitudeRatio.Info, + Angle.Info, + Area.Info, + AreaDensity.Info, + AreaMomentOfInertia.Info, + BitRate.Info, + BrakeSpecificFuelConsumption.Info, + CoefficientOfThermalExpansion.Info, + Compressibility.Info, + Density.Info, + DoseAreaProduct.Info, + Duration.Info, + DynamicViscosity.Info, + ElectricAdmittance.Info, + ElectricApparentEnergy.Info, + ElectricApparentPower.Info, + ElectricCapacitance.Info, + ElectricCharge.Info, + ElectricChargeDensity.Info, + ElectricConductance.Info, + ElectricConductivity.Info, + ElectricCurrent.Info, + ElectricCurrentDensity.Info, + ElectricCurrentGradient.Info, + ElectricField.Info, + ElectricImpedance.Info, + ElectricInductance.Info, + ElectricPotential.Info, + ElectricPotentialChangeRate.Info, + ElectricReactance.Info, + ElectricReactiveEnergy.Info, + ElectricReactivePower.Info, + ElectricResistance.Info, + ElectricResistivity.Info, + ElectricSurfaceChargeDensity.Info, + ElectricSusceptance.Info, + Energy.Info, + EnergyDensity.Info, + Entropy.Info, + FluidResistance.Info, + Force.Info, + ForceChangeRate.Info, + ForcePerLength.Info, + Frequency.Info, + FuelEfficiency.Info, + HeatFlux.Info, + HeatTransferCoefficient.Info, + Illuminance.Info, + Impulse.Info, + Information.Info, + Irradiance.Info, + Irradiation.Info, + Jerk.Info, + KinematicViscosity.Info, + LeakRate.Info, + Length.Info, + Level.Info, + LinearDensity.Info, + LinearPowerDensity.Info, + Luminance.Info, + Luminosity.Info, + LuminousFlux.Info, + LuminousIntensity.Info, + MagneticField.Info, + MagneticFlux.Info, + Magnetization.Info, + Mass.Info, + MassConcentration.Info, + MassFlow.Info, + MassFlux.Info, + MassFraction.Info, + MassMomentOfInertia.Info, + Molality.Info, + MolarEnergy.Info, + MolarEntropy.Info, + MolarFlow.Info, + Molarity.Info, + MolarMass.Info, + Permeability.Info, + Permittivity.Info, + PorousMediumPermeability.Info, + Power.Info, + PowerDensity.Info, + PowerRatio.Info, + Pressure.Info, + PressureChangeRate.Info, + RadiationEquivalentDose.Info, + RadiationEquivalentDoseRate.Info, + RadiationExposure.Info, + Radioactivity.Info, + Ratio.Info, + RatioChangeRate.Info, + ReciprocalArea.Info, + ReciprocalLength.Info, + RelativeHumidity.Info, + RotationalAcceleration.Info, + RotationalSpeed.Info, + RotationalStiffness.Info, + RotationalStiffnessPerLength.Info, + Scalar.Info, + SolidAngle.Info, + SpecificEnergy.Info, + SpecificEntropy.Info, + SpecificFuelConsumption.Info, + SpecificVolume.Info, + SpecificWeight.Info, + Speed.Info, + StandardVolumeFlow.Info, + Temperature.Info, + TemperatureChangeRate.Info, + TemperatureDelta.Info, + TemperatureGradient.Info, + ThermalConductivity.Info, + ThermalInsulance.Info, + Torque.Info, + Turbidity.Info, + VitaminA.Info, + Volume.Info, + VolumeConcentration.Info, + VolumeFlow.Info, + VolumeFlowPerArea.Info, + VolumePerLength.Info, + VolumetricHeatCapacity.Info, + WarpingMomentOfInertia.Info, }; - - /// - /// Dynamically constructs a quantity of the given with the value in the quantity's base units. - /// - /// The of the quantity to create. - /// The value to construct the quantity with. - /// The created quantity. - public static IQuantity FromQuantityInfo(QuantityInfo quantityInfo, double value) - { - return quantityInfo.Name switch - { - "AbsorbedDoseOfIonizingRadiation" => AbsorbedDoseOfIonizingRadiation.From(value, AbsorbedDoseOfIonizingRadiation.BaseUnit), - "Acceleration" => Acceleration.From(value, Acceleration.BaseUnit), - "AmountOfSubstance" => AmountOfSubstance.From(value, AmountOfSubstance.BaseUnit), - "AmplitudeRatio" => AmplitudeRatio.From(value, AmplitudeRatio.BaseUnit), - "Angle" => Angle.From(value, Angle.BaseUnit), - "Area" => Area.From(value, Area.BaseUnit), - "AreaDensity" => AreaDensity.From(value, AreaDensity.BaseUnit), - "AreaMomentOfInertia" => AreaMomentOfInertia.From(value, AreaMomentOfInertia.BaseUnit), - "BitRate" => BitRate.From(value, BitRate.BaseUnit), - "BrakeSpecificFuelConsumption" => BrakeSpecificFuelConsumption.From(value, BrakeSpecificFuelConsumption.BaseUnit), - "CoefficientOfThermalExpansion" => CoefficientOfThermalExpansion.From(value, CoefficientOfThermalExpansion.BaseUnit), - "Compressibility" => Compressibility.From(value, Compressibility.BaseUnit), - "Density" => Density.From(value, Density.BaseUnit), - "DoseAreaProduct" => DoseAreaProduct.From(value, DoseAreaProduct.BaseUnit), - "Duration" => Duration.From(value, Duration.BaseUnit), - "DynamicViscosity" => DynamicViscosity.From(value, DynamicViscosity.BaseUnit), - "ElectricAdmittance" => ElectricAdmittance.From(value, ElectricAdmittance.BaseUnit), - "ElectricApparentEnergy" => ElectricApparentEnergy.From(value, ElectricApparentEnergy.BaseUnit), - "ElectricApparentPower" => ElectricApparentPower.From(value, ElectricApparentPower.BaseUnit), - "ElectricCapacitance" => ElectricCapacitance.From(value, ElectricCapacitance.BaseUnit), - "ElectricCharge" => ElectricCharge.From(value, ElectricCharge.BaseUnit), - "ElectricChargeDensity" => ElectricChargeDensity.From(value, ElectricChargeDensity.BaseUnit), - "ElectricConductance" => ElectricConductance.From(value, ElectricConductance.BaseUnit), - "ElectricConductivity" => ElectricConductivity.From(value, ElectricConductivity.BaseUnit), - "ElectricCurrent" => ElectricCurrent.From(value, ElectricCurrent.BaseUnit), - "ElectricCurrentDensity" => ElectricCurrentDensity.From(value, ElectricCurrentDensity.BaseUnit), - "ElectricCurrentGradient" => ElectricCurrentGradient.From(value, ElectricCurrentGradient.BaseUnit), - "ElectricField" => ElectricField.From(value, ElectricField.BaseUnit), - "ElectricImpedance" => ElectricImpedance.From(value, ElectricImpedance.BaseUnit), - "ElectricInductance" => ElectricInductance.From(value, ElectricInductance.BaseUnit), - "ElectricPotential" => ElectricPotential.From(value, ElectricPotential.BaseUnit), - "ElectricPotentialChangeRate" => ElectricPotentialChangeRate.From(value, ElectricPotentialChangeRate.BaseUnit), - "ElectricReactance" => ElectricReactance.From(value, ElectricReactance.BaseUnit), - "ElectricReactiveEnergy" => ElectricReactiveEnergy.From(value, ElectricReactiveEnergy.BaseUnit), - "ElectricReactivePower" => ElectricReactivePower.From(value, ElectricReactivePower.BaseUnit), - "ElectricResistance" => ElectricResistance.From(value, ElectricResistance.BaseUnit), - "ElectricResistivity" => ElectricResistivity.From(value, ElectricResistivity.BaseUnit), - "ElectricSurfaceChargeDensity" => ElectricSurfaceChargeDensity.From(value, ElectricSurfaceChargeDensity.BaseUnit), - "ElectricSusceptance" => ElectricSusceptance.From(value, ElectricSusceptance.BaseUnit), - "Energy" => Energy.From(value, Energy.BaseUnit), - "EnergyDensity" => EnergyDensity.From(value, EnergyDensity.BaseUnit), - "Entropy" => Entropy.From(value, Entropy.BaseUnit), - "FluidResistance" => FluidResistance.From(value, FluidResistance.BaseUnit), - "Force" => Force.From(value, Force.BaseUnit), - "ForceChangeRate" => ForceChangeRate.From(value, ForceChangeRate.BaseUnit), - "ForcePerLength" => ForcePerLength.From(value, ForcePerLength.BaseUnit), - "Frequency" => Frequency.From(value, Frequency.BaseUnit), - "FuelEfficiency" => FuelEfficiency.From(value, FuelEfficiency.BaseUnit), - "HeatFlux" => HeatFlux.From(value, HeatFlux.BaseUnit), - "HeatTransferCoefficient" => HeatTransferCoefficient.From(value, HeatTransferCoefficient.BaseUnit), - "Illuminance" => Illuminance.From(value, Illuminance.BaseUnit), - "Impulse" => Impulse.From(value, Impulse.BaseUnit), - "Information" => Information.From(value, Information.BaseUnit), - "Irradiance" => Irradiance.From(value, Irradiance.BaseUnit), - "Irradiation" => Irradiation.From(value, Irradiation.BaseUnit), - "Jerk" => Jerk.From(value, Jerk.BaseUnit), - "KinematicViscosity" => KinematicViscosity.From(value, KinematicViscosity.BaseUnit), - "LeakRate" => LeakRate.From(value, LeakRate.BaseUnit), - "Length" => Length.From(value, Length.BaseUnit), - "Level" => Level.From(value, Level.BaseUnit), - "LinearDensity" => LinearDensity.From(value, LinearDensity.BaseUnit), - "LinearPowerDensity" => LinearPowerDensity.From(value, LinearPowerDensity.BaseUnit), - "Luminance" => Luminance.From(value, Luminance.BaseUnit), - "Luminosity" => Luminosity.From(value, Luminosity.BaseUnit), - "LuminousFlux" => LuminousFlux.From(value, LuminousFlux.BaseUnit), - "LuminousIntensity" => LuminousIntensity.From(value, LuminousIntensity.BaseUnit), - "MagneticField" => MagneticField.From(value, MagneticField.BaseUnit), - "MagneticFlux" => MagneticFlux.From(value, MagneticFlux.BaseUnit), - "Magnetization" => Magnetization.From(value, Magnetization.BaseUnit), - "Mass" => Mass.From(value, Mass.BaseUnit), - "MassConcentration" => MassConcentration.From(value, MassConcentration.BaseUnit), - "MassFlow" => MassFlow.From(value, MassFlow.BaseUnit), - "MassFlux" => MassFlux.From(value, MassFlux.BaseUnit), - "MassFraction" => MassFraction.From(value, MassFraction.BaseUnit), - "MassMomentOfInertia" => MassMomentOfInertia.From(value, MassMomentOfInertia.BaseUnit), - "Molality" => Molality.From(value, Molality.BaseUnit), - "MolarEnergy" => MolarEnergy.From(value, MolarEnergy.BaseUnit), - "MolarEntropy" => MolarEntropy.From(value, MolarEntropy.BaseUnit), - "MolarFlow" => MolarFlow.From(value, MolarFlow.BaseUnit), - "Molarity" => Molarity.From(value, Molarity.BaseUnit), - "MolarMass" => MolarMass.From(value, MolarMass.BaseUnit), - "Permeability" => Permeability.From(value, Permeability.BaseUnit), - "Permittivity" => Permittivity.From(value, Permittivity.BaseUnit), - "PorousMediumPermeability" => PorousMediumPermeability.From(value, PorousMediumPermeability.BaseUnit), - "Power" => Power.From(value, Power.BaseUnit), - "PowerDensity" => PowerDensity.From(value, PowerDensity.BaseUnit), - "PowerRatio" => PowerRatio.From(value, PowerRatio.BaseUnit), - "Pressure" => Pressure.From(value, Pressure.BaseUnit), - "PressureChangeRate" => PressureChangeRate.From(value, PressureChangeRate.BaseUnit), - "RadiationEquivalentDose" => RadiationEquivalentDose.From(value, RadiationEquivalentDose.BaseUnit), - "RadiationEquivalentDoseRate" => RadiationEquivalentDoseRate.From(value, RadiationEquivalentDoseRate.BaseUnit), - "RadiationExposure" => RadiationExposure.From(value, RadiationExposure.BaseUnit), - "Radioactivity" => Radioactivity.From(value, Radioactivity.BaseUnit), - "Ratio" => Ratio.From(value, Ratio.BaseUnit), - "RatioChangeRate" => RatioChangeRate.From(value, RatioChangeRate.BaseUnit), - "ReciprocalArea" => ReciprocalArea.From(value, ReciprocalArea.BaseUnit), - "ReciprocalLength" => ReciprocalLength.From(value, ReciprocalLength.BaseUnit), - "RelativeHumidity" => RelativeHumidity.From(value, RelativeHumidity.BaseUnit), - "RotationalAcceleration" => RotationalAcceleration.From(value, RotationalAcceleration.BaseUnit), - "RotationalSpeed" => RotationalSpeed.From(value, RotationalSpeed.BaseUnit), - "RotationalStiffness" => RotationalStiffness.From(value, RotationalStiffness.BaseUnit), - "RotationalStiffnessPerLength" => RotationalStiffnessPerLength.From(value, RotationalStiffnessPerLength.BaseUnit), - "Scalar" => Scalar.From(value, Scalar.BaseUnit), - "SolidAngle" => SolidAngle.From(value, SolidAngle.BaseUnit), - "SpecificEnergy" => SpecificEnergy.From(value, SpecificEnergy.BaseUnit), - "SpecificEntropy" => SpecificEntropy.From(value, SpecificEntropy.BaseUnit), - "SpecificFuelConsumption" => SpecificFuelConsumption.From(value, SpecificFuelConsumption.BaseUnit), - "SpecificVolume" => SpecificVolume.From(value, SpecificVolume.BaseUnit), - "SpecificWeight" => SpecificWeight.From(value, SpecificWeight.BaseUnit), - "Speed" => Speed.From(value, Speed.BaseUnit), - "StandardVolumeFlow" => StandardVolumeFlow.From(value, StandardVolumeFlow.BaseUnit), - "Temperature" => Temperature.From(value, Temperature.BaseUnit), - "TemperatureChangeRate" => TemperatureChangeRate.From(value, TemperatureChangeRate.BaseUnit), - "TemperatureDelta" => TemperatureDelta.From(value, TemperatureDelta.BaseUnit), - "TemperatureGradient" => TemperatureGradient.From(value, TemperatureGradient.BaseUnit), - "ThermalConductivity" => ThermalConductivity.From(value, ThermalConductivity.BaseUnit), - "ThermalInsulance" => ThermalInsulance.From(value, ThermalInsulance.BaseUnit), - "Torque" => Torque.From(value, Torque.BaseUnit), - "Turbidity" => Turbidity.From(value, Turbidity.BaseUnit), - "VitaminA" => VitaminA.From(value, VitaminA.BaseUnit), - "Volume" => Volume.From(value, Volume.BaseUnit), - "VolumeConcentration" => VolumeConcentration.From(value, VolumeConcentration.BaseUnit), - "VolumeFlow" => VolumeFlow.From(value, VolumeFlow.BaseUnit), - "VolumeFlowPerArea" => VolumeFlowPerArea.From(value, VolumeFlowPerArea.BaseUnit), - "VolumePerLength" => VolumePerLength.From(value, VolumePerLength.BaseUnit), - "VolumetricHeatCapacity" => VolumetricHeatCapacity.From(value, VolumetricHeatCapacity.BaseUnit), - "WarpingMomentOfInertia" => WarpingMomentOfInertia.From(value, WarpingMomentOfInertia.BaseUnit), - _ => throw new ArgumentException($"{quantityInfo.Name} is not a supported quantity.") - }; - } - - /// - /// Try to dynamically construct a quantity. - /// - /// Numeric value. - /// Unit enum value. - /// The resulting quantity if successful, otherwise default. - /// True if successful with assigned the value, otherwise false. - public static bool TryFrom(double value, Enum? unit, [NotNullWhen(true)] out IQuantity? quantity) - { - quantity = unit switch - { - AbsorbedDoseOfIonizingRadiationUnit absorbedDoseOfIonizingRadiationUnit => AbsorbedDoseOfIonizingRadiation.From(value, absorbedDoseOfIonizingRadiationUnit), - AccelerationUnit accelerationUnit => Acceleration.From(value, accelerationUnit), - AmountOfSubstanceUnit amountOfSubstanceUnit => AmountOfSubstance.From(value, amountOfSubstanceUnit), - AmplitudeRatioUnit amplitudeRatioUnit => AmplitudeRatio.From(value, amplitudeRatioUnit), - AngleUnit angleUnit => Angle.From(value, angleUnit), - AreaUnit areaUnit => Area.From(value, areaUnit), - AreaDensityUnit areaDensityUnit => AreaDensity.From(value, areaDensityUnit), - AreaMomentOfInertiaUnit areaMomentOfInertiaUnit => AreaMomentOfInertia.From(value, areaMomentOfInertiaUnit), - BitRateUnit bitRateUnit => BitRate.From(value, bitRateUnit), - BrakeSpecificFuelConsumptionUnit brakeSpecificFuelConsumptionUnit => BrakeSpecificFuelConsumption.From(value, brakeSpecificFuelConsumptionUnit), - CoefficientOfThermalExpansionUnit coefficientOfThermalExpansionUnit => CoefficientOfThermalExpansion.From(value, coefficientOfThermalExpansionUnit), - CompressibilityUnit compressibilityUnit => Compressibility.From(value, compressibilityUnit), - DensityUnit densityUnit => Density.From(value, densityUnit), - DoseAreaProductUnit doseAreaProductUnit => DoseAreaProduct.From(value, doseAreaProductUnit), - DurationUnit durationUnit => Duration.From(value, durationUnit), - DynamicViscosityUnit dynamicViscosityUnit => DynamicViscosity.From(value, dynamicViscosityUnit), - ElectricAdmittanceUnit electricAdmittanceUnit => ElectricAdmittance.From(value, electricAdmittanceUnit), - ElectricApparentEnergyUnit electricApparentEnergyUnit => ElectricApparentEnergy.From(value, electricApparentEnergyUnit), - ElectricApparentPowerUnit electricApparentPowerUnit => ElectricApparentPower.From(value, electricApparentPowerUnit), - ElectricCapacitanceUnit electricCapacitanceUnit => ElectricCapacitance.From(value, electricCapacitanceUnit), - ElectricChargeUnit electricChargeUnit => ElectricCharge.From(value, electricChargeUnit), - ElectricChargeDensityUnit electricChargeDensityUnit => ElectricChargeDensity.From(value, electricChargeDensityUnit), - ElectricConductanceUnit electricConductanceUnit => ElectricConductance.From(value, electricConductanceUnit), - ElectricConductivityUnit electricConductivityUnit => ElectricConductivity.From(value, electricConductivityUnit), - ElectricCurrentUnit electricCurrentUnit => ElectricCurrent.From(value, electricCurrentUnit), - ElectricCurrentDensityUnit electricCurrentDensityUnit => ElectricCurrentDensity.From(value, electricCurrentDensityUnit), - ElectricCurrentGradientUnit electricCurrentGradientUnit => ElectricCurrentGradient.From(value, electricCurrentGradientUnit), - ElectricFieldUnit electricFieldUnit => ElectricField.From(value, electricFieldUnit), - ElectricImpedanceUnit electricImpedanceUnit => ElectricImpedance.From(value, electricImpedanceUnit), - ElectricInductanceUnit electricInductanceUnit => ElectricInductance.From(value, electricInductanceUnit), - ElectricPotentialUnit electricPotentialUnit => ElectricPotential.From(value, electricPotentialUnit), - ElectricPotentialChangeRateUnit electricPotentialChangeRateUnit => ElectricPotentialChangeRate.From(value, electricPotentialChangeRateUnit), - ElectricReactanceUnit electricReactanceUnit => ElectricReactance.From(value, electricReactanceUnit), - ElectricReactiveEnergyUnit electricReactiveEnergyUnit => ElectricReactiveEnergy.From(value, electricReactiveEnergyUnit), - ElectricReactivePowerUnit electricReactivePowerUnit => ElectricReactivePower.From(value, electricReactivePowerUnit), - ElectricResistanceUnit electricResistanceUnit => ElectricResistance.From(value, electricResistanceUnit), - ElectricResistivityUnit electricResistivityUnit => ElectricResistivity.From(value, electricResistivityUnit), - ElectricSurfaceChargeDensityUnit electricSurfaceChargeDensityUnit => ElectricSurfaceChargeDensity.From(value, electricSurfaceChargeDensityUnit), - ElectricSusceptanceUnit electricSusceptanceUnit => ElectricSusceptance.From(value, electricSusceptanceUnit), - EnergyUnit energyUnit => Energy.From(value, energyUnit), - EnergyDensityUnit energyDensityUnit => EnergyDensity.From(value, energyDensityUnit), - EntropyUnit entropyUnit => Entropy.From(value, entropyUnit), - FluidResistanceUnit fluidResistanceUnit => FluidResistance.From(value, fluidResistanceUnit), - ForceUnit forceUnit => Force.From(value, forceUnit), - ForceChangeRateUnit forceChangeRateUnit => ForceChangeRate.From(value, forceChangeRateUnit), - ForcePerLengthUnit forcePerLengthUnit => ForcePerLength.From(value, forcePerLengthUnit), - FrequencyUnit frequencyUnit => Frequency.From(value, frequencyUnit), - FuelEfficiencyUnit fuelEfficiencyUnit => FuelEfficiency.From(value, fuelEfficiencyUnit), - HeatFluxUnit heatFluxUnit => HeatFlux.From(value, heatFluxUnit), - HeatTransferCoefficientUnit heatTransferCoefficientUnit => HeatTransferCoefficient.From(value, heatTransferCoefficientUnit), - IlluminanceUnit illuminanceUnit => Illuminance.From(value, illuminanceUnit), - ImpulseUnit impulseUnit => Impulse.From(value, impulseUnit), - InformationUnit informationUnit => Information.From(value, informationUnit), - IrradianceUnit irradianceUnit => Irradiance.From(value, irradianceUnit), - IrradiationUnit irradiationUnit => Irradiation.From(value, irradiationUnit), - JerkUnit jerkUnit => Jerk.From(value, jerkUnit), - KinematicViscosityUnit kinematicViscosityUnit => KinematicViscosity.From(value, kinematicViscosityUnit), - LeakRateUnit leakRateUnit => LeakRate.From(value, leakRateUnit), - LengthUnit lengthUnit => Length.From(value, lengthUnit), - LevelUnit levelUnit => Level.From(value, levelUnit), - LinearDensityUnit linearDensityUnit => LinearDensity.From(value, linearDensityUnit), - LinearPowerDensityUnit linearPowerDensityUnit => LinearPowerDensity.From(value, linearPowerDensityUnit), - LuminanceUnit luminanceUnit => Luminance.From(value, luminanceUnit), - LuminosityUnit luminosityUnit => Luminosity.From(value, luminosityUnit), - LuminousFluxUnit luminousFluxUnit => LuminousFlux.From(value, luminousFluxUnit), - LuminousIntensityUnit luminousIntensityUnit => LuminousIntensity.From(value, luminousIntensityUnit), - MagneticFieldUnit magneticFieldUnit => MagneticField.From(value, magneticFieldUnit), - MagneticFluxUnit magneticFluxUnit => MagneticFlux.From(value, magneticFluxUnit), - MagnetizationUnit magnetizationUnit => Magnetization.From(value, magnetizationUnit), - MassUnit massUnit => Mass.From(value, massUnit), - MassConcentrationUnit massConcentrationUnit => MassConcentration.From(value, massConcentrationUnit), - MassFlowUnit massFlowUnit => MassFlow.From(value, massFlowUnit), - MassFluxUnit massFluxUnit => MassFlux.From(value, massFluxUnit), - MassFractionUnit massFractionUnit => MassFraction.From(value, massFractionUnit), - MassMomentOfInertiaUnit massMomentOfInertiaUnit => MassMomentOfInertia.From(value, massMomentOfInertiaUnit), - MolalityUnit molalityUnit => Molality.From(value, molalityUnit), - MolarEnergyUnit molarEnergyUnit => MolarEnergy.From(value, molarEnergyUnit), - MolarEntropyUnit molarEntropyUnit => MolarEntropy.From(value, molarEntropyUnit), - MolarFlowUnit molarFlowUnit => MolarFlow.From(value, molarFlowUnit), - MolarityUnit molarityUnit => Molarity.From(value, molarityUnit), - MolarMassUnit molarMassUnit => MolarMass.From(value, molarMassUnit), - PermeabilityUnit permeabilityUnit => Permeability.From(value, permeabilityUnit), - PermittivityUnit permittivityUnit => Permittivity.From(value, permittivityUnit), - PorousMediumPermeabilityUnit porousMediumPermeabilityUnit => PorousMediumPermeability.From(value, porousMediumPermeabilityUnit), - PowerUnit powerUnit => Power.From(value, powerUnit), - PowerDensityUnit powerDensityUnit => PowerDensity.From(value, powerDensityUnit), - PowerRatioUnit powerRatioUnit => PowerRatio.From(value, powerRatioUnit), - PressureUnit pressureUnit => Pressure.From(value, pressureUnit), - PressureChangeRateUnit pressureChangeRateUnit => PressureChangeRate.From(value, pressureChangeRateUnit), - RadiationEquivalentDoseUnit radiationEquivalentDoseUnit => RadiationEquivalentDose.From(value, radiationEquivalentDoseUnit), - RadiationEquivalentDoseRateUnit radiationEquivalentDoseRateUnit => RadiationEquivalentDoseRate.From(value, radiationEquivalentDoseRateUnit), - RadiationExposureUnit radiationExposureUnit => RadiationExposure.From(value, radiationExposureUnit), - RadioactivityUnit radioactivityUnit => Radioactivity.From(value, radioactivityUnit), - RatioUnit ratioUnit => Ratio.From(value, ratioUnit), - RatioChangeRateUnit ratioChangeRateUnit => RatioChangeRate.From(value, ratioChangeRateUnit), - ReciprocalAreaUnit reciprocalAreaUnit => ReciprocalArea.From(value, reciprocalAreaUnit), - ReciprocalLengthUnit reciprocalLengthUnit => ReciprocalLength.From(value, reciprocalLengthUnit), - RelativeHumidityUnit relativeHumidityUnit => RelativeHumidity.From(value, relativeHumidityUnit), - RotationalAccelerationUnit rotationalAccelerationUnit => RotationalAcceleration.From(value, rotationalAccelerationUnit), - RotationalSpeedUnit rotationalSpeedUnit => RotationalSpeed.From(value, rotationalSpeedUnit), - RotationalStiffnessUnit rotationalStiffnessUnit => RotationalStiffness.From(value, rotationalStiffnessUnit), - RotationalStiffnessPerLengthUnit rotationalStiffnessPerLengthUnit => RotationalStiffnessPerLength.From(value, rotationalStiffnessPerLengthUnit), - ScalarUnit scalarUnit => Scalar.From(value, scalarUnit), - SolidAngleUnit solidAngleUnit => SolidAngle.From(value, solidAngleUnit), - SpecificEnergyUnit specificEnergyUnit => SpecificEnergy.From(value, specificEnergyUnit), - SpecificEntropyUnit specificEntropyUnit => SpecificEntropy.From(value, specificEntropyUnit), - SpecificFuelConsumptionUnit specificFuelConsumptionUnit => SpecificFuelConsumption.From(value, specificFuelConsumptionUnit), - SpecificVolumeUnit specificVolumeUnit => SpecificVolume.From(value, specificVolumeUnit), - SpecificWeightUnit specificWeightUnit => SpecificWeight.From(value, specificWeightUnit), - SpeedUnit speedUnit => Speed.From(value, speedUnit), - StandardVolumeFlowUnit standardVolumeFlowUnit => StandardVolumeFlow.From(value, standardVolumeFlowUnit), - TemperatureUnit temperatureUnit => Temperature.From(value, temperatureUnit), - TemperatureChangeRateUnit temperatureChangeRateUnit => TemperatureChangeRate.From(value, temperatureChangeRateUnit), - TemperatureDeltaUnit temperatureDeltaUnit => TemperatureDelta.From(value, temperatureDeltaUnit), - TemperatureGradientUnit temperatureGradientUnit => TemperatureGradient.From(value, temperatureGradientUnit), - ThermalConductivityUnit thermalConductivityUnit => ThermalConductivity.From(value, thermalConductivityUnit), - ThermalInsulanceUnit thermalInsulanceUnit => ThermalInsulance.From(value, thermalInsulanceUnit), - TorqueUnit torqueUnit => Torque.From(value, torqueUnit), - TurbidityUnit turbidityUnit => Turbidity.From(value, turbidityUnit), - VitaminAUnit vitaminAUnit => VitaminA.From(value, vitaminAUnit), - VolumeUnit volumeUnit => Volume.From(value, volumeUnit), - VolumeConcentrationUnit volumeConcentrationUnit => VolumeConcentration.From(value, volumeConcentrationUnit), - VolumeFlowUnit volumeFlowUnit => VolumeFlow.From(value, volumeFlowUnit), - VolumeFlowPerAreaUnit volumeFlowPerAreaUnit => VolumeFlowPerArea.From(value, volumeFlowPerAreaUnit), - VolumePerLengthUnit volumePerLengthUnit => VolumePerLength.From(value, volumePerLengthUnit), - VolumetricHeatCapacityUnit volumetricHeatCapacityUnit => VolumetricHeatCapacity.From(value, volumetricHeatCapacityUnit), - WarpingMomentOfInertiaUnit warpingMomentOfInertiaUnit => WarpingMomentOfInertia.From(value, warpingMomentOfInertiaUnit), - _ => null - }; - - return quantity is not null; - } - - /// - /// Try to dynamically parse a quantity string representation. - /// - /// The format provider to use for lookup. Defaults to if null. - /// Type of quantity, such as . - /// Quantity string representation, such as "1.5 kg". Must be compatible with given quantity type. - /// The resulting quantity if successful, otherwise default. - /// The parsed quantity. - public static bool TryParse(IFormatProvider? formatProvider, Type quantityType, [NotNullWhen(true)] string? quantityString, [NotNullWhen(true)] out IQuantity? quantity) - { - quantity = default(IQuantity); - - if (!typeof(IQuantity).IsAssignableFrom(quantityType)) - return false; - - var parser = UnitsNetSetup.Default.QuantityParser; - - return quantityType switch - { - Type _ when quantityType == typeof(AbsorbedDoseOfIonizingRadiation) => parser.TryParse(quantityString, formatProvider, AbsorbedDoseOfIonizingRadiation.From, out quantity), - Type _ when quantityType == typeof(Acceleration) => parser.TryParse(quantityString, formatProvider, Acceleration.From, out quantity), - Type _ when quantityType == typeof(AmountOfSubstance) => parser.TryParse(quantityString, formatProvider, AmountOfSubstance.From, out quantity), - Type _ when quantityType == typeof(AmplitudeRatio) => parser.TryParse(quantityString, formatProvider, AmplitudeRatio.From, out quantity), - Type _ when quantityType == typeof(Angle) => parser.TryParse(quantityString, formatProvider, Angle.From, out quantity), - Type _ when quantityType == typeof(Area) => parser.TryParse(quantityString, formatProvider, Area.From, out quantity), - Type _ when quantityType == typeof(AreaDensity) => parser.TryParse(quantityString, formatProvider, AreaDensity.From, out quantity), - Type _ when quantityType == typeof(AreaMomentOfInertia) => parser.TryParse(quantityString, formatProvider, AreaMomentOfInertia.From, out quantity), - Type _ when quantityType == typeof(BitRate) => parser.TryParse(quantityString, formatProvider, BitRate.From, out quantity), - Type _ when quantityType == typeof(BrakeSpecificFuelConsumption) => parser.TryParse(quantityString, formatProvider, BrakeSpecificFuelConsumption.From, out quantity), - Type _ when quantityType == typeof(CoefficientOfThermalExpansion) => parser.TryParse(quantityString, formatProvider, CoefficientOfThermalExpansion.From, out quantity), - Type _ when quantityType == typeof(Compressibility) => parser.TryParse(quantityString, formatProvider, Compressibility.From, out quantity), - Type _ when quantityType == typeof(Density) => parser.TryParse(quantityString, formatProvider, Density.From, out quantity), - Type _ when quantityType == typeof(DoseAreaProduct) => parser.TryParse(quantityString, formatProvider, DoseAreaProduct.From, out quantity), - Type _ when quantityType == typeof(Duration) => parser.TryParse(quantityString, formatProvider, Duration.From, out quantity), - Type _ when quantityType == typeof(DynamicViscosity) => parser.TryParse(quantityString, formatProvider, DynamicViscosity.From, out quantity), - Type _ when quantityType == typeof(ElectricAdmittance) => parser.TryParse(quantityString, formatProvider, ElectricAdmittance.From, out quantity), - Type _ when quantityType == typeof(ElectricApparentEnergy) => parser.TryParse(quantityString, formatProvider, ElectricApparentEnergy.From, out quantity), - Type _ when quantityType == typeof(ElectricApparentPower) => parser.TryParse(quantityString, formatProvider, ElectricApparentPower.From, out quantity), - Type _ when quantityType == typeof(ElectricCapacitance) => parser.TryParse(quantityString, formatProvider, ElectricCapacitance.From, out quantity), - Type _ when quantityType == typeof(ElectricCharge) => parser.TryParse(quantityString, formatProvider, ElectricCharge.From, out quantity), - Type _ when quantityType == typeof(ElectricChargeDensity) => parser.TryParse(quantityString, formatProvider, ElectricChargeDensity.From, out quantity), - Type _ when quantityType == typeof(ElectricConductance) => parser.TryParse(quantityString, formatProvider, ElectricConductance.From, out quantity), - Type _ when quantityType == typeof(ElectricConductivity) => parser.TryParse(quantityString, formatProvider, ElectricConductivity.From, out quantity), - Type _ when quantityType == typeof(ElectricCurrent) => parser.TryParse(quantityString, formatProvider, ElectricCurrent.From, out quantity), - Type _ when quantityType == typeof(ElectricCurrentDensity) => parser.TryParse(quantityString, formatProvider, ElectricCurrentDensity.From, out quantity), - Type _ when quantityType == typeof(ElectricCurrentGradient) => parser.TryParse(quantityString, formatProvider, ElectricCurrentGradient.From, out quantity), - Type _ when quantityType == typeof(ElectricField) => parser.TryParse(quantityString, formatProvider, ElectricField.From, out quantity), - Type _ when quantityType == typeof(ElectricImpedance) => parser.TryParse(quantityString, formatProvider, ElectricImpedance.From, out quantity), - Type _ when quantityType == typeof(ElectricInductance) => parser.TryParse(quantityString, formatProvider, ElectricInductance.From, out quantity), - Type _ when quantityType == typeof(ElectricPotential) => parser.TryParse(quantityString, formatProvider, ElectricPotential.From, out quantity), - Type _ when quantityType == typeof(ElectricPotentialChangeRate) => parser.TryParse(quantityString, formatProvider, ElectricPotentialChangeRate.From, out quantity), - Type _ when quantityType == typeof(ElectricReactance) => parser.TryParse(quantityString, formatProvider, ElectricReactance.From, out quantity), - Type _ when quantityType == typeof(ElectricReactiveEnergy) => parser.TryParse(quantityString, formatProvider, ElectricReactiveEnergy.From, out quantity), - Type _ when quantityType == typeof(ElectricReactivePower) => parser.TryParse(quantityString, formatProvider, ElectricReactivePower.From, out quantity), - Type _ when quantityType == typeof(ElectricResistance) => parser.TryParse(quantityString, formatProvider, ElectricResistance.From, out quantity), - Type _ when quantityType == typeof(ElectricResistivity) => parser.TryParse(quantityString, formatProvider, ElectricResistivity.From, out quantity), - Type _ when quantityType == typeof(ElectricSurfaceChargeDensity) => parser.TryParse(quantityString, formatProvider, ElectricSurfaceChargeDensity.From, out quantity), - Type _ when quantityType == typeof(ElectricSusceptance) => parser.TryParse(quantityString, formatProvider, ElectricSusceptance.From, out quantity), - Type _ when quantityType == typeof(Energy) => parser.TryParse(quantityString, formatProvider, Energy.From, out quantity), - Type _ when quantityType == typeof(EnergyDensity) => parser.TryParse(quantityString, formatProvider, EnergyDensity.From, out quantity), - Type _ when quantityType == typeof(Entropy) => parser.TryParse(quantityString, formatProvider, Entropy.From, out quantity), - Type _ when quantityType == typeof(FluidResistance) => parser.TryParse(quantityString, formatProvider, FluidResistance.From, out quantity), - Type _ when quantityType == typeof(Force) => parser.TryParse(quantityString, formatProvider, Force.From, out quantity), - Type _ when quantityType == typeof(ForceChangeRate) => parser.TryParse(quantityString, formatProvider, ForceChangeRate.From, out quantity), - Type _ when quantityType == typeof(ForcePerLength) => parser.TryParse(quantityString, formatProvider, ForcePerLength.From, out quantity), - Type _ when quantityType == typeof(Frequency) => parser.TryParse(quantityString, formatProvider, Frequency.From, out quantity), - Type _ when quantityType == typeof(FuelEfficiency) => parser.TryParse(quantityString, formatProvider, FuelEfficiency.From, out quantity), - Type _ when quantityType == typeof(HeatFlux) => parser.TryParse(quantityString, formatProvider, HeatFlux.From, out quantity), - Type _ when quantityType == typeof(HeatTransferCoefficient) => parser.TryParse(quantityString, formatProvider, HeatTransferCoefficient.From, out quantity), - Type _ when quantityType == typeof(Illuminance) => parser.TryParse(quantityString, formatProvider, Illuminance.From, out quantity), - Type _ when quantityType == typeof(Impulse) => parser.TryParse(quantityString, formatProvider, Impulse.From, out quantity), - Type _ when quantityType == typeof(Information) => parser.TryParse(quantityString, formatProvider, Information.From, out quantity), - Type _ when quantityType == typeof(Irradiance) => parser.TryParse(quantityString, formatProvider, Irradiance.From, out quantity), - Type _ when quantityType == typeof(Irradiation) => parser.TryParse(quantityString, formatProvider, Irradiation.From, out quantity), - Type _ when quantityType == typeof(Jerk) => parser.TryParse(quantityString, formatProvider, Jerk.From, out quantity), - Type _ when quantityType == typeof(KinematicViscosity) => parser.TryParse(quantityString, formatProvider, KinematicViscosity.From, out quantity), - Type _ when quantityType == typeof(LeakRate) => parser.TryParse(quantityString, formatProvider, LeakRate.From, out quantity), - Type _ when quantityType == typeof(Length) => parser.TryParse(quantityString, formatProvider, Length.From, out quantity), - Type _ when quantityType == typeof(Level) => parser.TryParse(quantityString, formatProvider, Level.From, out quantity), - Type _ when quantityType == typeof(LinearDensity) => parser.TryParse(quantityString, formatProvider, LinearDensity.From, out quantity), - Type _ when quantityType == typeof(LinearPowerDensity) => parser.TryParse(quantityString, formatProvider, LinearPowerDensity.From, out quantity), - Type _ when quantityType == typeof(Luminance) => parser.TryParse(quantityString, formatProvider, Luminance.From, out quantity), - Type _ when quantityType == typeof(Luminosity) => parser.TryParse(quantityString, formatProvider, Luminosity.From, out quantity), - Type _ when quantityType == typeof(LuminousFlux) => parser.TryParse(quantityString, formatProvider, LuminousFlux.From, out quantity), - Type _ when quantityType == typeof(LuminousIntensity) => parser.TryParse(quantityString, formatProvider, LuminousIntensity.From, out quantity), - Type _ when quantityType == typeof(MagneticField) => parser.TryParse(quantityString, formatProvider, MagneticField.From, out quantity), - Type _ when quantityType == typeof(MagneticFlux) => parser.TryParse(quantityString, formatProvider, MagneticFlux.From, out quantity), - Type _ when quantityType == typeof(Magnetization) => parser.TryParse(quantityString, formatProvider, Magnetization.From, out quantity), - Type _ when quantityType == typeof(Mass) => parser.TryParse(quantityString, formatProvider, Mass.From, out quantity), - Type _ when quantityType == typeof(MassConcentration) => parser.TryParse(quantityString, formatProvider, MassConcentration.From, out quantity), - Type _ when quantityType == typeof(MassFlow) => parser.TryParse(quantityString, formatProvider, MassFlow.From, out quantity), - Type _ when quantityType == typeof(MassFlux) => parser.TryParse(quantityString, formatProvider, MassFlux.From, out quantity), - Type _ when quantityType == typeof(MassFraction) => parser.TryParse(quantityString, formatProvider, MassFraction.From, out quantity), - Type _ when quantityType == typeof(MassMomentOfInertia) => parser.TryParse(quantityString, formatProvider, MassMomentOfInertia.From, out quantity), - Type _ when quantityType == typeof(Molality) => parser.TryParse(quantityString, formatProvider, Molality.From, out quantity), - Type _ when quantityType == typeof(MolarEnergy) => parser.TryParse(quantityString, formatProvider, MolarEnergy.From, out quantity), - Type _ when quantityType == typeof(MolarEntropy) => parser.TryParse(quantityString, formatProvider, MolarEntropy.From, out quantity), - Type _ when quantityType == typeof(MolarFlow) => parser.TryParse(quantityString, formatProvider, MolarFlow.From, out quantity), - Type _ when quantityType == typeof(Molarity) => parser.TryParse(quantityString, formatProvider, Molarity.From, out quantity), - Type _ when quantityType == typeof(MolarMass) => parser.TryParse(quantityString, formatProvider, MolarMass.From, out quantity), - Type _ when quantityType == typeof(Permeability) => parser.TryParse(quantityString, formatProvider, Permeability.From, out quantity), - Type _ when quantityType == typeof(Permittivity) => parser.TryParse(quantityString, formatProvider, Permittivity.From, out quantity), - Type _ when quantityType == typeof(PorousMediumPermeability) => parser.TryParse(quantityString, formatProvider, PorousMediumPermeability.From, out quantity), - Type _ when quantityType == typeof(Power) => parser.TryParse(quantityString, formatProvider, Power.From, out quantity), - Type _ when quantityType == typeof(PowerDensity) => parser.TryParse(quantityString, formatProvider, PowerDensity.From, out quantity), - Type _ when quantityType == typeof(PowerRatio) => parser.TryParse(quantityString, formatProvider, PowerRatio.From, out quantity), - Type _ when quantityType == typeof(Pressure) => parser.TryParse(quantityString, formatProvider, Pressure.From, out quantity), - Type _ when quantityType == typeof(PressureChangeRate) => parser.TryParse(quantityString, formatProvider, PressureChangeRate.From, out quantity), - Type _ when quantityType == typeof(RadiationEquivalentDose) => parser.TryParse(quantityString, formatProvider, RadiationEquivalentDose.From, out quantity), - Type _ when quantityType == typeof(RadiationEquivalentDoseRate) => parser.TryParse(quantityString, formatProvider, RadiationEquivalentDoseRate.From, out quantity), - Type _ when quantityType == typeof(RadiationExposure) => parser.TryParse(quantityString, formatProvider, RadiationExposure.From, out quantity), - Type _ when quantityType == typeof(Radioactivity) => parser.TryParse(quantityString, formatProvider, Radioactivity.From, out quantity), - Type _ when quantityType == typeof(Ratio) => parser.TryParse(quantityString, formatProvider, Ratio.From, out quantity), - Type _ when quantityType == typeof(RatioChangeRate) => parser.TryParse(quantityString, formatProvider, RatioChangeRate.From, out quantity), - Type _ when quantityType == typeof(ReciprocalArea) => parser.TryParse(quantityString, formatProvider, ReciprocalArea.From, out quantity), - Type _ when quantityType == typeof(ReciprocalLength) => parser.TryParse(quantityString, formatProvider, ReciprocalLength.From, out quantity), - Type _ when quantityType == typeof(RelativeHumidity) => parser.TryParse(quantityString, formatProvider, RelativeHumidity.From, out quantity), - Type _ when quantityType == typeof(RotationalAcceleration) => parser.TryParse(quantityString, formatProvider, RotationalAcceleration.From, out quantity), - Type _ when quantityType == typeof(RotationalSpeed) => parser.TryParse(quantityString, formatProvider, RotationalSpeed.From, out quantity), - Type _ when quantityType == typeof(RotationalStiffness) => parser.TryParse(quantityString, formatProvider, RotationalStiffness.From, out quantity), - Type _ when quantityType == typeof(RotationalStiffnessPerLength) => parser.TryParse(quantityString, formatProvider, RotationalStiffnessPerLength.From, out quantity), - Type _ when quantityType == typeof(Scalar) => parser.TryParse(quantityString, formatProvider, Scalar.From, out quantity), - Type _ when quantityType == typeof(SolidAngle) => parser.TryParse(quantityString, formatProvider, SolidAngle.From, out quantity), - Type _ when quantityType == typeof(SpecificEnergy) => parser.TryParse(quantityString, formatProvider, SpecificEnergy.From, out quantity), - Type _ when quantityType == typeof(SpecificEntropy) => parser.TryParse(quantityString, formatProvider, SpecificEntropy.From, out quantity), - Type _ when quantityType == typeof(SpecificFuelConsumption) => parser.TryParse(quantityString, formatProvider, SpecificFuelConsumption.From, out quantity), - Type _ when quantityType == typeof(SpecificVolume) => parser.TryParse(quantityString, formatProvider, SpecificVolume.From, out quantity), - Type _ when quantityType == typeof(SpecificWeight) => parser.TryParse(quantityString, formatProvider, SpecificWeight.From, out quantity), - Type _ when quantityType == typeof(Speed) => parser.TryParse(quantityString, formatProvider, Speed.From, out quantity), - Type _ when quantityType == typeof(StandardVolumeFlow) => parser.TryParse(quantityString, formatProvider, StandardVolumeFlow.From, out quantity), - Type _ when quantityType == typeof(Temperature) => parser.TryParse(quantityString, formatProvider, Temperature.From, out quantity), - Type _ when quantityType == typeof(TemperatureChangeRate) => parser.TryParse(quantityString, formatProvider, TemperatureChangeRate.From, out quantity), - Type _ when quantityType == typeof(TemperatureDelta) => parser.TryParse(quantityString, formatProvider, TemperatureDelta.From, out quantity), - Type _ when quantityType == typeof(TemperatureGradient) => parser.TryParse(quantityString, formatProvider, TemperatureGradient.From, out quantity), - Type _ when quantityType == typeof(ThermalConductivity) => parser.TryParse(quantityString, formatProvider, ThermalConductivity.From, out quantity), - Type _ when quantityType == typeof(ThermalInsulance) => parser.TryParse(quantityString, formatProvider, ThermalInsulance.From, out quantity), - Type _ when quantityType == typeof(Torque) => parser.TryParse(quantityString, formatProvider, Torque.From, out quantity), - Type _ when quantityType == typeof(Turbidity) => parser.TryParse(quantityString, formatProvider, Turbidity.From, out quantity), - Type _ when quantityType == typeof(VitaminA) => parser.TryParse(quantityString, formatProvider, VitaminA.From, out quantity), - Type _ when quantityType == typeof(Volume) => parser.TryParse(quantityString, formatProvider, Volume.From, out quantity), - Type _ when quantityType == typeof(VolumeConcentration) => parser.TryParse(quantityString, formatProvider, VolumeConcentration.From, out quantity), - Type _ when quantityType == typeof(VolumeFlow) => parser.TryParse(quantityString, formatProvider, VolumeFlow.From, out quantity), - Type _ when quantityType == typeof(VolumeFlowPerArea) => parser.TryParse(quantityString, formatProvider, VolumeFlowPerArea.From, out quantity), - Type _ when quantityType == typeof(VolumePerLength) => parser.TryParse(quantityString, formatProvider, VolumePerLength.From, out quantity), - Type _ when quantityType == typeof(VolumetricHeatCapacity) => parser.TryParse(quantityString, formatProvider, VolumetricHeatCapacity.From, out quantity), - Type _ when quantityType == typeof(WarpingMomentOfInertia) => parser.TryParse(quantityString, formatProvider, WarpingMomentOfInertia.From, out quantity), - _ => false - }; - } - - internal static IEnumerable GetQuantityTypes() - { - yield return typeof(AbsorbedDoseOfIonizingRadiation); - yield return typeof(Acceleration); - yield return typeof(AmountOfSubstance); - yield return typeof(AmplitudeRatio); - yield return typeof(Angle); - yield return typeof(Area); - yield return typeof(AreaDensity); - yield return typeof(AreaMomentOfInertia); - yield return typeof(BitRate); - yield return typeof(BrakeSpecificFuelConsumption); - yield return typeof(CoefficientOfThermalExpansion); - yield return typeof(Compressibility); - yield return typeof(Density); - yield return typeof(DoseAreaProduct); - yield return typeof(Duration); - yield return typeof(DynamicViscosity); - yield return typeof(ElectricAdmittance); - yield return typeof(ElectricApparentEnergy); - yield return typeof(ElectricApparentPower); - yield return typeof(ElectricCapacitance); - yield return typeof(ElectricCharge); - yield return typeof(ElectricChargeDensity); - yield return typeof(ElectricConductance); - yield return typeof(ElectricConductivity); - yield return typeof(ElectricCurrent); - yield return typeof(ElectricCurrentDensity); - yield return typeof(ElectricCurrentGradient); - yield return typeof(ElectricField); - yield return typeof(ElectricImpedance); - yield return typeof(ElectricInductance); - yield return typeof(ElectricPotential); - yield return typeof(ElectricPotentialChangeRate); - yield return typeof(ElectricReactance); - yield return typeof(ElectricReactiveEnergy); - yield return typeof(ElectricReactivePower); - yield return typeof(ElectricResistance); - yield return typeof(ElectricResistivity); - yield return typeof(ElectricSurfaceChargeDensity); - yield return typeof(ElectricSusceptance); - yield return typeof(Energy); - yield return typeof(EnergyDensity); - yield return typeof(Entropy); - yield return typeof(FluidResistance); - yield return typeof(Force); - yield return typeof(ForceChangeRate); - yield return typeof(ForcePerLength); - yield return typeof(Frequency); - yield return typeof(FuelEfficiency); - yield return typeof(HeatFlux); - yield return typeof(HeatTransferCoefficient); - yield return typeof(Illuminance); - yield return typeof(Impulse); - yield return typeof(Information); - yield return typeof(Irradiance); - yield return typeof(Irradiation); - yield return typeof(Jerk); - yield return typeof(KinematicViscosity); - yield return typeof(LeakRate); - yield return typeof(Length); - yield return typeof(Level); - yield return typeof(LinearDensity); - yield return typeof(LinearPowerDensity); - yield return typeof(Luminance); - yield return typeof(Luminosity); - yield return typeof(LuminousFlux); - yield return typeof(LuminousIntensity); - yield return typeof(MagneticField); - yield return typeof(MagneticFlux); - yield return typeof(Magnetization); - yield return typeof(Mass); - yield return typeof(MassConcentration); - yield return typeof(MassFlow); - yield return typeof(MassFlux); - yield return typeof(MassFraction); - yield return typeof(MassMomentOfInertia); - yield return typeof(Molality); - yield return typeof(MolarEnergy); - yield return typeof(MolarEntropy); - yield return typeof(MolarFlow); - yield return typeof(Molarity); - yield return typeof(MolarMass); - yield return typeof(Permeability); - yield return typeof(Permittivity); - yield return typeof(PorousMediumPermeability); - yield return typeof(Power); - yield return typeof(PowerDensity); - yield return typeof(PowerRatio); - yield return typeof(Pressure); - yield return typeof(PressureChangeRate); - yield return typeof(RadiationEquivalentDose); - yield return typeof(RadiationEquivalentDoseRate); - yield return typeof(RadiationExposure); - yield return typeof(Radioactivity); - yield return typeof(Ratio); - yield return typeof(RatioChangeRate); - yield return typeof(ReciprocalArea); - yield return typeof(ReciprocalLength); - yield return typeof(RelativeHumidity); - yield return typeof(RotationalAcceleration); - yield return typeof(RotationalSpeed); - yield return typeof(RotationalStiffness); - yield return typeof(RotationalStiffnessPerLength); - yield return typeof(Scalar); - yield return typeof(SolidAngle); - yield return typeof(SpecificEnergy); - yield return typeof(SpecificEntropy); - yield return typeof(SpecificFuelConsumption); - yield return typeof(SpecificVolume); - yield return typeof(SpecificWeight); - yield return typeof(Speed); - yield return typeof(StandardVolumeFlow); - yield return typeof(Temperature); - yield return typeof(TemperatureChangeRate); - yield return typeof(TemperatureDelta); - yield return typeof(TemperatureGradient); - yield return typeof(ThermalConductivity); - yield return typeof(ThermalInsulance); - yield return typeof(Torque); - yield return typeof(Turbidity); - yield return typeof(VitaminA); - yield return typeof(Volume); - yield return typeof(VolumeConcentration); - yield return typeof(VolumeFlow); - yield return typeof(VolumeFlowPerArea); - yield return typeof(VolumePerLength); - yield return typeof(VolumetricHeatCapacity); - yield return typeof(WarpingMomentOfInertia); - } } } diff --git a/UnitsNet/IQuantity.cs b/UnitsNet/IQuantity.cs index 6fa31d6d51..231014b224 100644 --- a/UnitsNet/IQuantity.cs +++ b/UnitsNet/IQuantity.cs @@ -1,12 +1,7 @@ // 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; -#if NET7_0_OR_GREATER -using System.Numerics; -#endif -using UnitsNet.Units; namespace UnitsNet { @@ -149,6 +144,24 @@ public interface IQuantity : IQuantity /// The to convert the quantity to. /// A new quantity with the determined unit. new IQuantity ToUnit(UnitSystem unitSystem); + +#if NET + + #region Implementation of IQuantity + + QuantityInfo IQuantity.QuantityInfo + { + get => QuantityInfo; + } + + Enum IQuantity.Unit + { + get => Unit; + } + + #endregion + +#endif } /// @@ -156,7 +169,7 @@ public interface IQuantity : IQuantity /// /// The type itself, for the CRT pattern. /// The underlying unit enum type. - public interface IQuantity : IQuantity + public interface IQuantity : IQuantity where TSelf : IQuantity where TUnitType : struct, Enum { @@ -181,5 +194,19 @@ public interface IQuantity : IQuantity /// The absolute tolerance value. Must be greater than or equal to zero. /// True if the absolute difference between the two values is not greater than the specified tolerance. bool Equals(TSelf? other, TSelf tolerance); + + /// + new QuantityInfo QuantityInfo { get; } + +#if NET7_0_OR_GREATER + /// + /// Creates an instance of the quantity from a specified value and unit. + /// + /// The numerical value of the quantity. + /// The unit of the quantity. + /// An instance of the quantity with the specified value and unit. + static abstract TSelf From(double value, TUnitType unit); + +#endif } } diff --git a/UnitsNet/IQuantityInfo.cs b/UnitsNet/IQuantityInfo.cs new file mode 100644 index 0000000000..6035e6b934 --- /dev/null +++ b/UnitsNet/IQuantityInfo.cs @@ -0,0 +1,217 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Resources; +using UnitsNet.Units; + +namespace UnitsNet; + +/// +/// Information about the quantity, such as names, unit values and zero quantity. +/// This is useful to enumerate units and present names with quantities and units +/// chose dynamically at runtime, such as unit conversion apps or allowing the user to change the +/// unit representation. +/// +/// +/// Typically you obtain this by looking it up via . +/// +public interface IQuantityInfo +{ + /// + /// Quantity name, such as "Length" or "Mass". + /// + string Name { get; } + + /// + /// The units for this quantity. + /// + IReadOnlyList UnitInfos { get; } + + /// + /// The base unit of this quantity. + /// + UnitInfo BaseUnitInfo { get; } + + /// + /// Zero value of quantity, such as . + /// + IQuantity Zero { get; } + + /// + /// Quantity value type, such as or . + /// + Type QuantityType { get; } + + /// + /// Unit enum type, such as or . + /// + Type UnitType { get; } + + /// + /// The for a quantity. + /// + BaseDimensions BaseDimensions { get; } + + /// + /// Used for loading the localization resources associated with the current quantity. + /// + ResourceManager? UnitAbbreviations { get; } + + /// + /// Gets the associated with the specified unit. + /// + /// The unit for which to get the . + /// The associated with the specified unit. + /// Thrown if the specified unit is not found. + /// + /// Thrown when the type of > does not match the type of the current . + /// + UnitInfo this[UnitKey unit] { get; } + + // /// + // /// Attempts to retrieve the unit information for the specified unit. + // /// + // /// The unit for which to retrieve information. + // /// + // /// When this method returns, contains the unit information associated with the specified unit, + // /// if the unit is found; otherwise, null. This parameter is passed uninitialized. + // /// + // /// + // /// true if the unit information was found; otherwise, false. + // /// + // bool TryGetUnitInfo(UnitKey unit, [NotNullWhen(true)] out UnitInfo? unitInfo); + + /// + /// Gets the whose is a subset of . + /// + /// + /// Length.Info.GetUnitInfoFor(unitSystemWithFootAsLengthUnit) returns for + /// . + /// + /// The to check against. + /// + /// The that has that is a subset of + /// . + /// + /// is null. + /// No unit was found that is a subset of . + /// + /// More than one unit was found that is a subset of + /// . + /// + UnitInfo GetUnitInfoFor(BaseUnits baseUnits); + + /// + /// Gets an of that have that is a + /// subset of . + /// + /// The to check against. + /// + /// An of that have that is a + /// subset of . + /// + /// is null. + IEnumerable GetUnitInfosFor(BaseUnits baseUnits); + + // /// + // /// Creates an instance of from the specified value and unit. + // /// + // /// The numerical value of the quantity. + // /// The unit of the quantity, represented as an enumeration. + // /// An instance of representing the specified value and unit. + // /// Thrown when is null. + // /// Thrown when is not a valid unit for this quantity. + // IQuantity From(QuantityValue value, Enum unit); +} + +// /// +// /// +// /// This is a specialization of , for when the unit type is known. +// /// Typically, you obtain this by looking it up statically from or +// /// , or dynamically via . +// /// +// /// The unit enum type, such as . +// public interface IQuantityInfo : IQuantityInfo +// where TUnit : struct, Enum +// { +// /// +// new IQuantity Zero { get; } +// +// /// +// new IReadOnlyCollection> UnitInfos { get; } +// +// /// +// new UnitInfo BaseUnitInfo { get; } +// +// /// +// UnitInfo this[TUnit unit] { get; } +// +// /// +// bool TryGetUnitInfo(TUnit unit, [NotNullWhen(true)] out UnitInfo? unitInfo); +// +// /// +// new UnitInfo GetUnitInfoFor(BaseUnits baseUnits); +// +// /// +// new IEnumerable> GetUnitInfosFor(BaseUnits baseUnits); +// +// /// +// IQuantity From(QuantityValue value, TUnit unit); +// } + +/// +/// +/// This is a specialization of that is used (internally) for constraining certain +/// methods, without having to include the unit type as additional generic parameter. +/// +public interface IQuantityInstanceInfo : IQuantityInfo + where TQuantity : IQuantity +{ + /// + new TQuantity Zero { get; } + + internal TQuantity Create(double value, UnitKey unitKey); +} + +// /// +// public interface IQuantityInfo : IQuantityInfo, IQuantityInstanceInfo +// where TQuantity : IQuantity +// where TUnit : struct, Enum +// { +// /// +// new TQuantity Zero { get; } +// +// /// +// new IReadOnlyCollection> UnitInfos { get; } +// +// /// +// new UnitInfo BaseUnitInfo { get; } +// +// /// +// new UnitInfo this[TUnit unit] { get; } +// +// /// +// new UnitInfo GetUnitInfoFor(BaseUnits baseUnits); +// +// /// +// new IEnumerable> GetUnitInfosFor(BaseUnits baseUnits); +// +// /// +// new TQuantity From(QuantityValue value, TUnit unit); +// +// // #if NET +// // +// // #region Implementation of IQuantityInstanceInfo +// // +// // TQuantity IQuantityInstanceInfo.Create(QuantityValue value, UnitKey unitKey) +// // { +// // return From(value, unitKey.ToUnit()); +// // } +// // +// // #endregion +// // +// // #endif +// } diff --git a/UnitsNet/IUnitDefinition.cs b/UnitsNet/IUnitDefinition.cs new file mode 100644 index 0000000000..5e31ffe554 --- /dev/null +++ b/UnitsNet/IUnitDefinition.cs @@ -0,0 +1,42 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using UnitsNet.Units; + +namespace UnitsNet; + +/// +/// Defines the configuration for mapping units, including their name, plural name, base units, +/// and conversion expressions to and from the base units. +/// +public interface IUnitDefinition +{ + /// + /// The singular name of the unit, such as "Centimeter". + /// + string Name { get; } + + /// + /// The plural name of the unit, such as "Centimeters". + /// + string PluralName { get; } + + /// + /// Gets the for this unit. + /// + BaseUnits BaseUnits { get; } +} + +/// +/// Defines the configuration for mapping units, including their value, name, plural name, and base units. +/// +/// The type of the unit enumeration. +public interface IUnitDefinition : IUnitDefinition + where TUnit : struct, Enum +{ + /// + /// The enum value of the unit, such as . + /// + TUnit Value { get; } +} diff --git a/UnitsNet/QuantityInfo.cs b/UnitsNet/QuantityInfo.cs index d50bf8ce69..1a17079e10 100644 --- a/UnitsNet/QuantityInfo.cs +++ b/UnitsNet/QuantityInfo.cs @@ -1,178 +1,647 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -using System; -using System.Collections.Generic; -using System.Diagnostics; using System.Linq; -using UnitsNet.Units; +using System.Resources; -namespace UnitsNet +namespace UnitsNet; + +/// +[DebuggerDisplay("{Name} ({QuantityType.FullName})")] +public abstract class QuantityInfo : IQuantityInfo { /// - /// Information about the quantity, such as names, unit values and zero quantity. - /// This is useful to enumerate units and present names with quantities and units - /// chose dynamically at runtime, such as unit conversion apps or allowing the user to change the - /// unit representation. + /// Initializes a new instance of the class. /// - /// - /// Typically you obtain this by looking it up via . - /// - public class QuantityInfo - { - /// - /// Constructs an instance. - /// - /// Name of the quantity. - /// The unit enum type, such as . - /// The information about the units for this quantity. - /// The base unit enum value. - /// The zero quantity. - /// The base dimensions of the quantity. - /// Quantity type can not be undefined. - /// If units -or- baseUnit -or- zero -or- baseDimensions is null. - public QuantityInfo(string name, Type unitType, UnitInfo[] unitInfos, Enum baseUnit, IQuantity zero, BaseDimensions baseDimensions) - { - if (baseUnit == null) throw new ArgumentNullException(nameof(baseUnit)); + /// The name of the quantity. + /// The type representing the quantity. + /// The base dimensions of the quantity. + /// + /// When provided, the resource manager used for localizing the quantity's unit abbreviations. + /// + /// + /// Thrown if , , or is + /// null. + /// + protected QuantityInfo(string name, Type quantityType, BaseDimensions baseDimensions, ResourceManager? unitAbbreviations) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + QuantityType = quantityType ?? throw new ArgumentNullException(nameof(quantityType)); + BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions)); + UnitAbbreviations = unitAbbreviations; + } - BaseDimensions = baseDimensions ?? throw new ArgumentNullException(nameof(baseDimensions)); - Zero = zero ?? throw new ArgumentNullException(nameof(zero)); - Name = name ?? throw new ArgumentNullException(nameof(name)); - UnitType = unitType ?? throw new ArgumentNullException(nameof(unitType)); - UnitInfos = unitInfos ?? throw new ArgumentNullException(nameof(unitInfos)); + /// + public string Name { get; } - BaseUnitInfo = UnitInfos.First(unitInfo => unitInfo.Value.Equals(baseUnit)); - QuantityType = zero.GetType(); - } + /// + public Type QuantityType { get; } - /// - /// Quantity name, such as "Length" or "Mass". - /// - public string Name { get; } - - /// - /// The units for this quantity. - /// - public UnitInfo[] UnitInfos { get; } - - /// - /// The base unit of this quantity. - /// - public UnitInfo BaseUnitInfo { get; } - - /// - /// Zero value of quantity, such as . - /// - public IQuantity Zero { get; } - - /// - /// Unit enum type, such as or . - /// - public Type UnitType { get; } - - /// - /// Quantity value type, such as or . - /// - public Type QuantityType { get; } - - /// - [Obsolete("Replaced by the QuantityType property.")] - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public Type ValueType - { - get => QuantityType; - } + /// + [Obsolete("Replaced by the QuantityType property.")] + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + public Type ValueType + { + get => QuantityType; + } - /// - /// The for a quantity. - /// - public BaseDimensions BaseDimensions { get; } - - /// - /// Gets the whose is a subset of . - /// - /// Length.Info.GetUnitInfoFor(unitSystemWithFootAsLengthUnit) returns for . - /// The to check against. - /// The that has that is a subset of . - /// is null. - /// No unit was found that is a subset of . - /// More than one unit was found that is a subset of . - public UnitInfo GetUnitInfoFor(BaseUnits baseUnits) - { - if (baseUnits is null) - throw new ArgumentNullException(nameof(baseUnits)); + /// + public abstract Type UnitType { get; } - var matchingUnitInfos = GetUnitInfosFor(baseUnits) - .Take(2) - .ToArray(); + /// + public BaseDimensions BaseDimensions { get; } - var firstUnitInfo = matchingUnitInfos.FirstOrDefault(); - if (firstUnitInfo == null) - throw new InvalidOperationException($"No unit was found that is a subset of {nameof(baseUnits)}"); + /// + public ResourceManager? UnitAbbreviations { get; } - if (matchingUnitInfos.Length > 1) - throw new InvalidOperationException($"More than one unit was found that is a subset of {nameof(baseUnits)}"); + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + public IQuantity Zero + { + get => GetGenericZero(); + } - return firstUnitInfo; - } + /// + protected internal abstract IQuantity GetGenericZero(); - /// - /// Gets an of that have that is a subset of . - /// - /// The to check against. - /// An of that have that is a subset of . - /// is null. - public IEnumerable GetUnitInfosFor(BaseUnits baseUnits) - { - if (baseUnits is null) - throw new ArgumentNullException(nameof(baseUnits)); + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + public UnitInfo BaseUnitInfo + { + get => GetGenericBaseUnitInfo(); + } + + /// + protected internal abstract UnitInfo GetGenericBaseUnitInfo(); - return UnitInfos.Where(unitInfo => unitInfo.BaseUnits.IsSubsetOf(baseUnits)); - } + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + public IReadOnlyList UnitInfos + { + get => GetGenericUnitInfos(); } - /// - /// - /// This is a specialization of , for when the unit type is known. - /// Typically you obtain this by looking it up statically from or - /// , or dynamically via . - /// - /// The unit enum type, such as . - public class QuantityInfo : QuantityInfo - where TUnit : struct, Enum + /// + protected internal abstract IReadOnlyList GetGenericUnitInfos(); + + /// + public abstract UnitInfo this[UnitKey unit] { get; } + + // /// + // public abstract bool TryGetUnitInfo(UnitKey unit, [NotNullWhen(true)] out UnitInfo? unitInfo); + + /// + public UnitInfo GetUnitInfoFor(BaseUnits baseUnits) { - /// - public QuantityInfo(string name, UnitInfo[] unitInfos, TUnit baseUnit, IQuantity zero, BaseDimensions baseDimensions) - : base(name, typeof(TUnit), unitInfos.ToArray(), baseUnit, zero, baseDimensions) - { - Zero = zero; - UnitInfos = unitInfos ?? throw new ArgumentNullException(nameof(unitInfos)); - BaseUnitInfo = UnitInfos.First(unitInfo => unitInfo.Value.Equals(baseUnit)); - UnitType = baseUnit; - } + return UnitInfos.GetUnitInfoFor(baseUnits); + } + + /// + public IEnumerable GetUnitInfosFor(BaseUnits baseUnits) + { + return UnitInfos.GetUnitInfosFor(baseUnits); + } + + /// + /// Creates an instance of from the specified value and unit. + /// + /// The numerical value of the quantity. + /// The unit of the quantity, represented as an enumeration. + /// An instance of representing the specified value and unit. + /// Thrown when is null. + /// Thrown when is not a valid unit for this quantity. + internal abstract IQuantity From(double value, UnitKey unitKey); + + /// + public override string ToString() + { + return Name; + } +} + +/// +/// +/// This is a specialization of , for when the unit type is known. +/// Typically, you obtain this by looking it up statically from or +/// , or dynamically via . +/// +/// The unit enum type, such as . +public abstract class QuantityInfo : QuantityInfo//, IQuantityInfo + where TUnit : struct, Enum +{ + /// + protected QuantityInfo(string name, Type quantityType, BaseDimensions baseDimensions, ResourceManager? unitAbbreviations = null) + : base(name, quantityType, baseDimensions, unitAbbreviations) + { + } + + #region Implementation of IQuantityInfo + + /// + public new UnitInfo BaseUnitInfo + { + get => GetBaseUnitInfo(); + } + + /// + protected internal abstract UnitInfo GetBaseUnitInfo(); + + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + public new IQuantity Zero + { + get => GetZero(); + } + + /// + protected internal abstract IQuantity GetZero(); + + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + public new IReadOnlyList> UnitInfos + { + get => GetUnitInfos(); + } + + /// + protected internal abstract IReadOnlyList> GetUnitInfos(); + + /// + public UnitInfo this[TUnit unit] + { + get => GetUnitInfo(unit); + } + + /// + /// Retrieves the unit information for the specified unit. + /// + /// The unit for which to retrieve information. + /// An instance containing information about the specified unit. + /// Thrown if the specified unit is not valid for this quantity. + protected internal abstract UnitInfo GetUnitInfo(TUnit unit); + + // /// + // public abstract bool TryGetUnitInfo(TUnit unit, [NotNullWhen(true)] out UnitInfo? unitInfo); + + /// + public new UnitInfo GetUnitInfoFor(BaseUnits baseUnits) + { + return UnitInfos.GetUnitInfoFor(baseUnits); + } + + /// + public new IEnumerable> GetUnitInfosFor(BaseUnits baseUnits) + { + return UnitInfos.GetUnitInfosFor(baseUnits); + } + + /// + public IQuantity From(double value, TUnit unit) + { + return CreateGenericQuantity(value, unit); + } + + /// + protected internal abstract IQuantity CreateGenericQuantity(double value, TUnit unit); + + #endregion + + #region Overrides of QuantityInfo + + /// + public override Type UnitType + { + get => typeof(TUnit); + } + + /// + protected internal override IQuantity GetGenericZero() + { + return Zero; + } + + /// + protected internal override UnitInfo GetGenericBaseUnitInfo() + { + return BaseUnitInfo; + } + + /// + protected internal override IReadOnlyList GetGenericUnitInfos() + { + return UnitInfos; + } + + /// + public override UnitInfo this[UnitKey unit] + { + get => this[unit.ToUnit()]; + } + + // /// + // public override bool TryGetUnitInfo(UnitKey unit, [NotNullWhen(true)] out UnitInfo? unitInfo) + // { + // if (unit.UnitType == typeof(TUnit) && TryGetUnitInfo(unit.ToUnit(), out UnitInfo? unitMapping)) + // { + // unitInfo = unitMapping; + // return true; + // } + // + // unitInfo = null; + // return false; + // } + + /// + internal override IQuantity From(double value, UnitKey unitKey) + { + return From(value, unitKey.ToUnit()); + } + + #endregion +} + +/// +public abstract class QuantityInfoBase : QuantityInfo, IQuantityInstanceInfo + where TQuantity : IQuantity + where TUnit : struct, Enum + where TUnitInfo : UnitInfo +{ + /// + /// Initializes a new instance of the class. + /// + /// The name of the quantity. + /// The zero value of the quantity. + /// The base dimensions of the quantity. + /// The delegate for creating a quantity from a value and unit. + /// + /// When provided, the resource manager used for localizing the quantity's unit abbreviations. + /// + protected QuantityInfoBase(string name, TQuantity zero, BaseDimensions baseDimensions, QuantityFromDelegate fromDelegate, + ResourceManager? unitAbbreviations) + : base(name, zero.GetType(), baseDimensions, unitAbbreviations) + { + Zero = zero; + FromDelegate = fromDelegate; + } + + private QuantityFromDelegate FromDelegate { get; } + + + #region Implementation of IQuantityInfo - /// - public new UnitInfo[] UnitInfos { get; } + /// + public new TQuantity Zero { get; } - /// - public new UnitInfo BaseUnitInfo { get; } + /// + public new abstract IReadOnlyList UnitInfos { get; } - /// - public new IQuantity Zero { get; } + /// + public new abstract TUnitInfo BaseUnitInfo { get; } - /// - public new TUnit UnitType { get; } + /// + public new abstract TUnitInfo this[TUnit unit] { get; } - /// - public new UnitInfo GetUnitInfoFor(BaseUnits baseUnits) + /// + public abstract bool TryGetUnitInfo(TUnit unit, [NotNullWhen(true)] out TUnitInfo? unitInfo); + + /// + public new IEnumerable GetUnitInfosFor(BaseUnits baseUnits) + { + return UnitInfos.GetUnitInfosFor(baseUnits); + } + + /// + public new TUnitInfo GetUnitInfoFor(BaseUnits baseUnits) + { + return UnitInfos.GetUnitInfoFor(baseUnits); + } + + /// + /// Creates an instance of the quantity from the specified value and unit. + /// + /// The numerical value of the quantity. + /// The unit of the quantity. + /// An instance of representing the specified value and unit. + public new TQuantity From(double value, TUnit unit) + { + return FromDelegate(value, unit); + } + + /// + TQuantity IQuantityInstanceInfo.Create(double value, UnitKey unitKey) + { + return From(value, unitKey.ToUnit()); + } + + #endregion + + #region Overrides of QuantityInfo + + /// + protected internal override IQuantity GetZero() + { + return Zero; + } + + /// + protected internal override UnitInfo GetBaseUnitInfo() + { + return BaseUnitInfo; + } + + /// + protected internal override IReadOnlyList> GetUnitInfos() + { + return UnitInfos; + } + + /// + protected internal override UnitInfo GetUnitInfo(TUnit unit) + { + return this[unit]; + } + + // /// + // public override bool TryGetUnitInfo(TUnit unit, [NotNullWhen(true)] out UnitInfo? unitInfo) + // { + // if (TryGetUnitInfo(unit, out TUnitInfo? unitMapping)) + // { + // unitInfo = unitMapping; + // return true; + // } + // + // unitInfo = null; + // return false; + // } + + /// + protected internal override IQuantity CreateGenericQuantity(double value, TUnit unit) + { + return From(value, unit); + } + + #endregion +} + +/// +public class QuantityInfo : QuantityInfoBase>//, IQuantityInfo + where TQuantity : IQuantity + where TUnit : struct, Enum +{ + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private readonly Dictionary> _unitMappings; + + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private readonly UnitInfo[] _unitInfos; + + #if NET + + /// + /// Initializes a new instance of the class using the default quantity name. + /// + /// A collection of unit mapping configurations. + /// The base unit of the quantity. + /// The base dimensions of the quantity. + /// + /// When provided, the resource manager used for localizing the quantity's unit abbreviations. + /// + /// Thrown when is null. + /// + /// Thrown when no unit mapping configuration is found for the specified . + /// + public QuantityInfo(TUnit baseUnit, IEnumerable> unitMappings, BaseDimensions baseDimensions, ResourceManager? unitAbbreviations = null) + : this(typeof(TQuantity).Name, baseUnit, unitMappings, baseDimensions, TQuantity.From, unitAbbreviations) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The name of the quantity. + /// A collection of unit mapping configurations. + /// The base unit of the quantity. + /// The base dimensions of the quantity. + /// + /// When provided, the resource manager used for localizing the quantity's unit abbreviations. + /// + /// Thrown when is null. + /// + /// Thrown when no unit mapping configuration is found for the specified . + /// + public QuantityInfo(string name, TUnit baseUnit, IEnumerable> unitMappings, BaseDimensions baseDimensions, ResourceManager? unitAbbreviations = null) + : this(name, baseUnit, unitMappings, TQuantity.From(0, baseUnit), baseDimensions, TQuantity.From, unitAbbreviations) + { + } + + #endif + + /// + /// Initializes a new instance of the class using the default quantity name. + /// + /// A collection of unit mapping configurations. + /// The base unit of the quantity. + /// The base dimensions of the quantity. + /// A delegate to create a quantity from a value and unit. + /// + /// When provided, the resource manager used for localizing the quantity's unit abbreviations. + /// + /// Thrown when is null. + /// + /// Thrown when no unit mapping configuration is found for the specified . + /// + public QuantityInfo(TUnit baseUnit, IEnumerable> unitMappings, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations = null) + : this(typeof(TQuantity).Name, baseUnit, unitMappings, baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The name of the quantity. + /// A collection of unit mapping configurations. + /// The base unit of the quantity. + /// The base dimensions of the quantity. + /// A delegate to create a quantity from a value and unit. + /// + /// When provided, the resource manager used for localizing the quantity's unit abbreviations. + /// + /// Thrown when is null. + /// + /// Thrown when no unit mapping configuration is found for the specified . + /// + public QuantityInfo(string name, TUnit baseUnit, IEnumerable> unitMappings, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations = null) + : this(name, baseUnit, unitMappings, fromDelegate(0, baseUnit), baseDimensions, fromDelegate, unitAbbreviations) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The name of the quantity. + /// The base unit of the quantity. + /// A collection of unit mapping configurations. + /// The zero value of the quantity. + /// The base dimensions of the quantity. + /// A delegate to create a quantity from a value and unit. + /// + /// When provided, the resource manager used for localizing the quantity's unit abbreviations. + /// + /// Thrown when is null. + /// + /// Thrown when no unit mapping configuration is found for the specified . + /// + public QuantityInfo(string name, TUnit baseUnit, IEnumerable> unitMappings, TQuantity zero, BaseDimensions baseDimensions, + QuantityFromDelegate fromDelegate, ResourceManager? unitAbbreviations = null) + : base(name, zero, baseDimensions, fromDelegate, unitAbbreviations) + { + if (unitMappings == null) { - return (UnitInfo)base.GetUnitInfoFor(baseUnits); + throw new ArgumentNullException(nameof(unitMappings)); } - - /// - public new IEnumerable> GetUnitInfosFor(BaseUnits baseUnits) +#if NET + _unitInfos = unitMappings.Select(unit => new UnitInfo(this, unit)).ToArray(); + _unitMappings = _unitInfos.ToDictionary(info => info.Value); +#else + _unitMappings = unitMappings.ToDictionary(unit => unit.Value, unit => new UnitInfo(this, unit), UnitEqualityComparer.Default); + _unitInfos = _unitMappings.Values.ToArray(); +#endif + if (!_unitMappings.TryGetValue(baseUnit, out UnitInfo? baseUnitInfo)) { - return base.GetUnitInfosFor(baseUnits).Cast>(); + throw new UnitNotFoundException($"No unit mapping configuration found for the specified base unit: {baseUnit}"); } + + BaseUnitInfo = baseUnitInfo; + } + + /// + /// Gets a read-only collection of the units associated with this quantity. + /// + /// + /// A collection of units of type . + /// + public IReadOnlyCollection Units + { + get => _unitMappings.Keys; + } + + #region Overrides of QuantityInfoBase> + + /// + [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] + public override UnitInfo BaseUnitInfo { get; } + + /// + public override UnitInfo this[TUnit unit] + { + get => _unitMappings[unit]; } + + /// + public override bool TryGetUnitInfo(TUnit unit, [NotNullWhen(true)] out UnitInfo? unitInfo) + { + return _unitMappings.TryGetValue(unit, out unitInfo); + } + + /// + [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] + public sealed override IReadOnlyList> UnitInfos + { + get => _unitInfos; + } + + #endregion + + #region Explicit implementation of IQuantityInfo + + // [DebuggerBrowsable(DebuggerBrowsableState.Never)] + // IReadOnlyCollection> IQuantityInfo.UnitInfos + // { + // get => UnitInfos; + // } + + // [DebuggerBrowsable(DebuggerBrowsableState.Never)] + // UnitInfo IQuantityInfo.BaseUnitInfo + // { + // get => BaseUnitInfo; + // } + + // IUnitInfo IQuantityInfo.this[TUnit unit] + // { + // get => this[unit]; + // } + + // bool IQuantityInfo.TryGetUnitInfo(TUnit unit, [NotNullWhen(true)] out IUnitInfo? unitInfo) + // { + // if (TryGetUnitInfo(unit, out UnitInfo? info)) + // { + // unitInfo = info; + // return true; + // } + // + // unitInfo = null; + // return false; + // } + + // IUnitInfo IQuantityInfo.GetUnitInfoFor(BaseUnits baseUnits) + // { + // return GetUnitInfoFor(baseUnits); + // } + + // IEnumerable> IQuantityInfo.GetUnitInfosFor(BaseUnits baseUnits) + // { + // return GetUnitInfosFor(baseUnits); + // } + + // IQuantity IQuantityInfo.From(QuantityValue value, TUnit unit) + // { + // return From(value, unit); + // } + + // [DebuggerBrowsable(DebuggerBrowsableState.Never)] + // IQuantity IQuantityInfo.Zero + // { + // get => Zero; + // } + + + // /// + // TQuantity IQuantityInstanceInfo.Create(QuantityValue value, UnitKey unitKey) + // { + // return From(value, unitKey.ToUnit()); + // } + + #endregion + + #region Implementation of IQuantityInfo + + // [DebuggerBrowsable(DebuggerBrowsableState.Never)] + // IReadOnlyCollection> IQuantityInfo.UnitInfos + // { + // get => UnitInfos; + // } + + // [DebuggerBrowsable(DebuggerBrowsableState.Never)] + // IUnitInfo IQuantityInfo.BaseUnitInfo + // { + // get => BaseUnitInfo; + // } + + // UnitInfo IQuantityInfo.this[TUnit unit] + // { + // get => this[unit]; + // } + + // UnitInfo IQuantityInfo.GetUnitInfoFor(BaseUnits baseUnits) + // { + // return GetUnitInfoFor(baseUnits); + // } + + // IEnumerable> IQuantityInfo.GetUnitInfosFor(BaseUnits baseUnits) + // { + // return GetUnitInfosFor(baseUnits); + // } + + #endregion } diff --git a/UnitsNet/QuantityInfoLookup.cs b/UnitsNet/QuantityInfoLookup.cs index 2c3dc302ad..8a9dc0a6c2 100644 --- a/UnitsNet/QuantityInfoLookup.cs +++ b/UnitsNet/QuantityInfoLookup.cs @@ -6,11 +6,12 @@ using System.Collections.Frozen; using QuantityByTypeLookupDictionary = System.Collections.Frozen.FrozenDictionary; using QuantityByNameLookupDictionary = System.Collections.Frozen.FrozenDictionary; +using UnitByKeyLookupDictionary = System.Collections.Frozen.FrozenDictionary; #else using QuantityByTypeLookupDictionary = System.Collections.Generic.Dictionary; using QuantityByNameLookupDictionary = System.Collections.Generic.Dictionary; -#endif using UnitByKeyLookupDictionary = System.Collections.Generic.Dictionary; +#endif namespace UnitsNet; @@ -24,6 +25,7 @@ internal class QuantityInfoLookup { private readonly QuantityInfo[] _quantities; private readonly Lazy _quantitiesByName; + private readonly Lazy _quantitiesByType; private readonly Lazy _quantitiesByUnitType; private readonly Lazy _unitsByKey; @@ -36,6 +38,15 @@ private QuantityByNameLookupDictionary GroupQuantitiesByName() #endif } + private QuantityByTypeLookupDictionary GroupQuantitiesByType() + { +#if NET8_0_OR_GREATER + return _quantities.ToFrozenDictionary(info => info.QuantityType); +#else + return _quantities.ToDictionary(info => info.QuantityType); +#endif + } + private QuantityByTypeLookupDictionary GroupQuantitiesByUnitType() { #if NET8_0_OR_GREATER @@ -47,7 +58,11 @@ private QuantityByTypeLookupDictionary GroupQuantitiesByUnitType() private UnitByKeyLookupDictionary GroupUnitsByKey() { +#if NET8_0_OR_GREATER + return _quantities.SelectMany(quantityInfo => quantityInfo.UnitInfos).ToFrozenDictionary(x => x.UnitKey); +#else return _quantities.SelectMany(quantityInfo => quantityInfo.UnitInfos).ToDictionary(x => x.UnitKey); +#endif } /// @@ -67,12 +82,13 @@ public QuantityInfoLookup(IEnumerable quantityInfos) { _quantities = quantityInfos.ToArray(); _quantitiesByName = new Lazy(GroupQuantitiesByName); + _quantitiesByType = new Lazy(GroupQuantitiesByType); _quantitiesByUnitType = new Lazy(GroupQuantitiesByUnitType); _unitsByKey = new Lazy(GroupUnitsByKey); } /// - /// All enum value names of , such as "Length" and "Mass". + /// All quantity names, such as "Length" and "Mass". /// public IReadOnlyCollection Names => _quantitiesByName.Value.Keys; @@ -86,6 +102,40 @@ public QuantityInfoLookup(IEnumerable quantityInfos) /// public IReadOnlyList Infos => _quantities; + /// + /// Retrieves the associated with the specified quantity type. + /// + /// The type of the quantity to retrieve information for. + /// The for the specified quantity type. + /// + /// Thrown when the is not of type . + /// + /// + /// Thrown when the specified quantity type is not registered in the current configuration. + /// + public QuantityInfo GetQuantityInfo(Type quantityType) + { + if (TryGetQuantityInfo(quantityType, out QuantityInfo? quantityInfo)) + { + return quantityInfo; + } + + if (!typeof(IQuantity).IsAssignableFrom(quantityType)) + { + throw new ArgumentException($"Type {quantityType} must be of type UnitsNet.IQuantity."); + } + + throw new QuantityNotFoundException($"The specified quantity type is not registered in the current configuration: '{quantityType}'."); + } + + /// + /// Try to get the for a given quantity type. + /// + public bool TryGetQuantityInfo(Type quantityType, [NotNullWhen(true)] out QuantityInfo? quantityInfo) + { + return _quantitiesByType.Value.TryGetValue(quantityType, out quantityInfo); + } + /// /// Retrieves the for a specified . /// @@ -112,16 +162,7 @@ public bool TryGetUnitInfo(UnitKey unitKey, [NotNullWhen(true)] out UnitInfo? un { return _unitsByKey.Value.TryGetValue(unitKey, out unitInfo); } - - /// - /// - /// - /// - public void AddUnitInfo(UnitInfo unitInfo) - { - _unitsByKey.Value.Add(unitInfo.UnitKey, unitInfo); - } - + /// /// Dynamically construct a quantity. /// @@ -131,10 +172,7 @@ public void AddUnitInfo(UnitInfo unitInfo) /// Unit value is not a know unit enum type. public IQuantity From(double value, UnitKey unit) { - // TODO Support custom units, currently only hardcoded built-in quantities are supported. - return Quantity.TryFrom(value, (Enum)unit, out IQuantity? quantity) - ? quantity - : throw new UnitNotFoundException($"Unit value {unit} of type {unit.GetType()} is not a known unit enum type. Expected types like UnitsNet.Units.LengthUnit. Did you pass in a custom enum type defined outside the UnitsNet library?"); + return GetUnitInfo(unit).From(value); } /// @@ -151,8 +189,20 @@ public IQuantity From(double value, UnitKey unit) /// public bool TryFrom(double value, [NotNullWhen(true)] Enum? unit, [NotNullWhen(true)] out IQuantity? quantity) { - // TODO Support custom units, currently only hardcoded built-in quantities are supported. - return Quantity.TryFrom(value, unit, out quantity); + if (unit == null) + { + quantity = null; + return false; + } + + if (!TryGetUnitInfo(unit, out UnitInfo? unitInfo)) + { + quantity = null; + return false; + } + + quantity = unitInfo.From(value); + return true; } /// @@ -163,7 +213,7 @@ public bool TryFrom(double value, [NotNullWhen(true)] Enum? unit, [NotNullWhen(t /// /// Thrown when no quantity information is found for the specified quantity name. /// - internal QuantityInfo GetQuantityByName(string quantityName) + public QuantityInfo GetQuantityByName(string quantityName) { if (!ByName.TryGetValue(quantityName, out QuantityInfo? quantityInfo)) { @@ -187,7 +237,7 @@ internal QuantityInfo GetQuantityByName(string quantityName) /// /// true if the quantity name was found; otherwise, false. /// - internal bool TryGetQuantityByName(string quantityName, [NotNullWhen(true)] out QuantityInfo? quantityInfo) + public bool TryGetQuantityByName(string quantityName, [NotNullWhen(true)] out QuantityInfo? quantityInfo) { return ByName.TryGetValue(quantityName, out quantityInfo); } @@ -210,7 +260,7 @@ internal bool TryGetQuantityByName(string quantityName, [NotNullWhen(true)] out /// /// Thrown when no unit is found for the specified quantity name and unit name. /// - internal UnitInfo GetUnitByName(string quantityName, string unitName) + public UnitInfo GetUnitByName(string quantityName, string unitName) { QuantityInfo quantityInfo = GetQuantityByName(quantityName); UnitInfo? unitInfo = quantityInfo.UnitInfos.FirstOrDefault(unit => string.Equals(unit.Name, unitName, StringComparison.OrdinalIgnoreCase)); @@ -231,7 +281,7 @@ internal UnitInfo GetUnitByName(string quantityName, string unitName) /// parsing failed. /// /// true if the unit information was successfully parsed; otherwise, false. - internal bool TryGetUnitByName(string quantityName, string unitName, [NotNullWhen(true)] out UnitInfo? unitInfo) + public bool TryGetUnitByName(string quantityName, string unitName, [NotNullWhen(true)] out UnitInfo? unitInfo) { if (!TryGetQuantityByName(quantityName, out QuantityInfo? quantityInfo)) { @@ -243,12 +293,32 @@ internal bool TryGetUnitByName(string quantityName, string unitName, [NotNullWhe return unitInfo is not null; } - + /// + /// Attempts to retrieve the associated with the specified unit type. + /// + /// The of the unit to look up. + /// + /// When this method returns, contains the associated with the specified unit type, + /// if the lookup was successful; otherwise, null. + /// + /// + /// true if a associated with the specified unit type was found; otherwise, + /// false. + /// public bool TryGetQuantityByUnitType(Type unitType, [NotNullWhen(true)] out QuantityInfo? quantityInfo) { return _quantitiesByUnitType.Value.TryGetValue(unitType, out quantityInfo); } + /// + /// Retrieves the associated with the specified unit type. + /// + /// The of the unit for which the quantity information is requested. + /// The corresponding to the specified unit type. + /// + /// Thrown when no quantity is found for the specified unit type. + /// The exception includes additional data with the key "unitType" containing the name of the unit type. + /// public QuantityInfo GetQuantityByUnitType(Type unitType) { if (TryGetQuantityByUnitType(unitType, out QuantityInfo? quantityInfo)) diff --git a/UnitsNet/UnitConverter.cs b/UnitsNet/UnitConverter.cs index 0815506966..76f7fdff17 100644 --- a/UnitsNet/UnitConverter.cs +++ b/UnitsNet/UnitConverter.cs @@ -85,9 +85,9 @@ public static void RegisterDefaultConversions(UnitConverter unitConverter) if (unitConverter is null) throw new ArgumentNullException(nameof(unitConverter)); - foreach(var quantity in Quantity.GetQuantityTypes()) + foreach(var quantity in Quantity.Provider.DefaultQuantities) { - var registerMethod = quantity.GetMethod(nameof(Length.RegisterDefaultConversions), BindingFlags.NonPublic | BindingFlags.Static); + var registerMethod = quantity.QuantityType.GetMethod(nameof(Length.RegisterDefaultConversions), BindingFlags.NonPublic | BindingFlags.Static); registerMethod?.Invoke(null, new object[]{unitConverter}); } } diff --git a/UnitsNet/UnitInfo.cs b/UnitsNet/UnitInfo.cs index 7a7adc6819..6bd85235d9 100644 --- a/UnitsNet/UnitInfo.cs +++ b/UnitsNet/UnitInfo.cs @@ -5,118 +5,232 @@ using System.Diagnostics; using UnitsNet.Units; -namespace UnitsNet +namespace UnitsNet; + +/// +/// Information about the unit, such as its name and value. +/// This is useful to enumerate units and present names with quantities and units +/// chosen dynamically at runtime, such as unit conversion apps or allowing the user to change the +/// unit representation. +/// +/// +/// Typically you obtain this by looking it up via . +/// +public abstract class UnitInfo : IUnitDefinition { /// - /// Information about the unit, such as its name and value. - /// This is useful to enumerate units and present names with quantities and units - /// chosen dynamically at runtime, such as unit conversion apps or allowing the user to change the - /// unit representation. + /// Initializes a new instance of the class using the specified unit definition. /// - /// - /// Typically you obtain this by looking it up via . - /// - public class UnitInfo + /// + /// The unit definition containing details such as name, plural name, base units, and conversion + /// expressions. + /// + /// Thrown when the is null. + protected internal UnitInfo(IUnitDefinition mapping) { - /// - /// Creates an instance of the UnitInfo class. - /// - /// The enum value for this class, for example . - /// The plural name of the unit, such as "Centimeters". - /// The for this unit. - [Obsolete("Use the constructor that also takes a quantityName parameter.")] - public UnitInfo(Enum value, string pluralName, BaseUnits baseUnits) + if (mapping == null) { - Value = value ?? throw new ArgumentNullException(nameof(value)); - Name = value.ToString(); - PluralName = pluralName ?? throw new ArgumentNullException(nameof(pluralName)); - BaseUnits = baseUnits ?? throw new ArgumentNullException(nameof(baseUnits)); + throw new ArgumentNullException(nameof(mapping)); } - /// - /// Creates an instance of the UnitInfo class. - /// - /// The enum value for this class, for example . - /// The plural name of the unit, such as "Centimeters". - /// The for this unit. - /// The quantity name that this unit is for. - public UnitInfo(Enum value, string pluralName, BaseUnits baseUnits, string quantityName) - { - Value = value ?? throw new ArgumentNullException(nameof(value)); - Name = value.ToString(); - PluralName = pluralName ?? throw new ArgumentNullException(nameof(pluralName)); - BaseUnits = baseUnits ?? throw new ArgumentNullException(nameof(baseUnits)); - QuantityName = quantityName ?? throw new ArgumentNullException(nameof(quantityName)); - } + Name = mapping.Name; + PluralName = mapping.PluralName; + BaseUnits = mapping.BaseUnits; + } + + /// + public override string ToString() + { + return Name; + } + + #region Implementation of IUnitDefinition + + /// + public string Name { get; } + + /// + public string PluralName { get; } - /// - /// The enum value of the unit, such as . - /// - public Enum Value { get; } - - /// - /// The singular name of the unit, such as "Centimeter". - /// - public string Name { get; } - - /// - /// The plural name of the unit, such as "Centimeters". - /// - public string PluralName { get; } - - /// - /// Gets the for this unit. - /// - public BaseUnits BaseUnits { get; } - - /// - /// Name of the quantity this unit belongs to. May be null for custom units. - /// - public string? QuantityName { get; } - - /// - /// Gets the unique key representing the unit type and its corresponding value. - /// - /// - /// This key is particularly useful when using an enum-based unit in a hash-based collection, - /// as it avoids the boxing that would normally occur when casting the enum to . - /// - public virtual UnitKey UnitKey => Value; + /// + public BaseUnits BaseUnits { get; } + + #endregion + + #region Implementation of IUnitInfo + + /// + /// The enum value of the unit, such as . + /// + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + public Enum Value + { + get => GetUnitValue(); } - /// + /// + protected abstract Enum GetUnitValue(); + + /// + /// Get the parent quantity information. + /// /// - /// This is a specialization of , for when the unit type is known. - /// Typically you obtain this by looking it up statically from or - /// or dynamically via . + /// This property provides detailed information about the quantity to which this unit belongs, + /// including its name, unit values, and zero quantity. It is useful for enumerating units and + /// presenting names with quantities and units chosen dynamically at runtime. /// - /// The unit enum type, such as . - [DebuggerDisplay("{Name} ({Value})")] - public class UnitInfo : UnitInfo - where TUnit : struct, Enum + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + public QuantityInfo QuantityInfo { - /// - [Obsolete("Use the constructor that also takes a quantityName parameter.")] - public UnitInfo(TUnit value, string pluralName, BaseUnits baseUnits) : - base(value, pluralName, baseUnits) - { - Value = value; - } + get => GetGenericInfo(); + } + + /// + protected internal abstract QuantityInfo GetGenericInfo(); + + /// + /// Gets the unique key representing the unit type and its corresponding value. + /// + /// + /// This key is particularly useful when using an enum-based unit in a hash-based collection, + /// as it avoids the boxing that would normally occur when casting the enum to . + /// + public abstract UnitKey UnitKey { get; } + + /// + /// Name of the quantity this unit belongs to. + /// + [Obsolete("Please use the QuantityInfo.Name instead.")] + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + public string QuantityName + { + get => QuantityInfo.Name; + } + + /// + /// Creates an instance of from the specified . + /// + /// The quantity value to convert. + /// An instance of representing the specified . + /// + /// This method utilizes the associated with this unit to create the quantity. + /// + public IQuantity From(double value) + { + return CreateGenericQuantity(value); + } - /// - public UnitInfo(TUnit value, string pluralName, BaseUnits baseUnits, string quantityName) : - base(value, pluralName, baseUnits, quantityName) - { - Value = value; - } + /// + protected internal abstract IQuantity CreateGenericQuantity(double value); - /// - public new TUnit Value { get; } - - /// - public override UnitKey UnitKey - { - get => UnitKey.ForUnit(Value); - } + #endregion +} + +/// /> +/// +/// Typically you obtain this by looking it up via . +/// +public abstract class UnitInfo : UnitInfo, IUnitDefinition //, IUnitInfo, IUnitDefinition + where TUnit : struct, Enum +{ + /// + /// Initializes a new instance of the class using the specified unit definition. + /// + /// + /// The unit definition containing details such as the unit value, name, plural name, base units, and conversion + /// expressions. + /// + /// Thrown when the is null. + protected UnitInfo(IUnitDefinition mapping) + : base(mapping) + { + Value = mapping.Value; + } + + /// + [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] + public new TUnit Value { get; } +} + +/// +/// Represents information about a specific unit of measurement for a given quantity type. +/// +/// The type of the quantity information associated with this unit. +/// The type of the quantity associated with this unit. +/// The enumeration type representing the unit. +[DebuggerDisplay("{Name} ({Value})")] +public abstract class UnitInfoBase : UnitInfo + where TQuantityInfo : QuantityInfo + where TQuantity : IQuantity + where TUnit : struct, Enum +{ + /// + /// Initializes a new instance of the class + /// using the specified quantity information and unit mapping configuration. + /// + /// The quantity information associated with this unit. + /// The unit mapping configuration containing unit details. + /// Thrown when the is null. + protected UnitInfoBase(TQuantityInfo quantityInfo, IUnitDefinition mapping) + : base(mapping) + { + QuantityInfo = quantityInfo; + } + + /// + [DebuggerBrowsable(DebuggerBrowsableState.Collapsed)] + public new TQuantityInfo QuantityInfo { get; } + + /// + public override UnitKey UnitKey + { + get => UnitKey.ForUnit(Value); + } + + /// + /// Converts a given to an instance of the quantity type associated with this unit. + /// + /// The value to convert. + /// An instance of the quantity type associated with this unit. + public new abstract TQuantity From(double value); + + #region Overrides of UnitInfo + + /// + protected internal sealed override IQuantity CreateGenericQuantity(double value) + { + return From(value); + } + + /// + protected internal sealed override QuantityInfo GetGenericInfo() + { + return QuantityInfo; + } + + /// + protected override Enum GetUnitValue() + { + return Value; + } + + #endregion +} + +/// +public sealed class UnitInfo : UnitInfoBase, TQuantity, TUnit> + where TQuantity : IQuantity + where TUnit : struct, Enum +{ + /// + internal UnitInfo(QuantityInfo quantityInfo, IUnitDefinition unitDefinition) + : base(quantityInfo, unitDefinition) + { + } + + /// + public override TQuantity From(double value) + { + return QuantityInfo.From(value, Value); } } diff --git a/UnitsNet/UnitsNet.csproj b/UnitsNet/UnitsNet.csproj index 8c7d8299a7..3371269ab5 100644 --- a/UnitsNet/UnitsNet.csproj +++ b/UnitsNet/UnitsNet.csproj @@ -56,4 +56,12 @@ + + + + + + + + diff --git a/UnitsNet/UnitsNet.csproj.DotSettings b/UnitsNet/UnitsNet.csproj.DotSettings index a60c20895b..99fb414ae9 100644 --- a/UnitsNet/UnitsNet.csproj.DotSettings +++ b/UnitsNet/UnitsNet.csproj.DotSettings @@ -1,4 +1,5 @@  True True - True \ No newline at end of file + True + True \ No newline at end of file