From 804cf7e87011c703368ef19d9ffb88e90f0e8bb4 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Sun, 29 Dec 2024 02:35:00 +0100 Subject: [PATCH] =?UTF-8?q?Revert=20"=F0=9F=94=A5Remove=20static=20Default?= =?UTF-8?q?=20getters,=20obsoleted=20by=20UnitsNetSetup"=20(#1480)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reverts angularsen/UnitsNet#1475 This reverts commit a3c32b6da51336bdadeb2674e6b4821a2c7af87a. - Add back default getters - Remove obsolete message, rewrite xmldoc a bit --- UnitsNet/CustomCode/QuantityParser.cs | 8 ++++++++ UnitsNet/CustomCode/UnitAbbreviationsCache.cs | 9 +++++++++ UnitsNet/CustomCode/UnitParser.cs | 12 ++++++++++-- UnitsNet/UnitConverter.cs | 9 +++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/UnitsNet/CustomCode/QuantityParser.cs b/UnitsNet/CustomCode/QuantityParser.cs index 8b81271b9a..eb88e4f078 100644 --- a/UnitsNet/CustomCode/QuantityParser.cs +++ b/UnitsNet/CustomCode/QuantityParser.cs @@ -34,6 +34,14 @@ public class QuantityParser private readonly UnitAbbreviationsCache _unitAbbreviationsCache; private readonly UnitParser _unitParser; + /// + /// The default singleton instance for parsing quantities. + /// + /// + /// Convenience shortcut for ... + /// + public static QuantityParser Default => UnitsNetSetup.Default.QuantityParser; + /// /// Creates an instance of , optionally specifying an /// with unit abbreviations to use when parsing. diff --git a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs index 8930779be4..6cfbff7967 100644 --- a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs +++ b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs @@ -31,6 +31,15 @@ public sealed class UnitAbbreviationsCache /// internal static readonly CultureInfo FallbackCulture = CultureInfo.InvariantCulture; + /// + /// The default singleton instance with the default configured unit abbreviations, used for ToString() and parsing of quantities and units. + /// + /// + /// Convenience shortcut for ...
+ /// You can add custom unit abbreviations at runtime, and this will affect all usages globally in the application. + ///
+ public static UnitAbbreviationsCache Default => UnitsNetSetup.Default.UnitAbbreviations; + private QuantityInfoLookup QuantityInfoLookup { get; } /// diff --git a/UnitsNet/CustomCode/UnitParser.cs b/UnitsNet/CustomCode/UnitParser.cs index ec4029d7a8..e55fdaf2b6 100644 --- a/UnitsNet/CustomCode/UnitParser.cs +++ b/UnitsNet/CustomCode/UnitParser.cs @@ -13,13 +13,21 @@ namespace UnitsNet { /// /// Parses units given a unit abbreviations cache. - /// A static instance .. is used internally - /// to parse quantities and units using the default abbreviations cache for all units and abbreviations defined in the library. + /// The static instance is used internally to parse quantities and units using the + /// default abbreviations cache for all units and abbreviations defined in the library. /// public sealed class UnitParser { private readonly UnitAbbreviationsCache _unitAbbreviationsCache; + /// + /// The default singleton instance for parsing units from the default configured unit abbreviations. + /// + /// + /// Convenience shortcut for ... + /// + public static UnitParser Default => UnitsNetSetup.Default.UnitParser; + /// /// Create a parser using the given unit abbreviations cache. /// diff --git a/UnitsNet/UnitConverter.cs b/UnitsNet/UnitConverter.cs index 442a20ae86..5a8c1e917f 100644 --- a/UnitsNet/UnitConverter.cs +++ b/UnitsNet/UnitConverter.cs @@ -34,6 +34,15 @@ public delegate TQuantity ConversionFunction(TQuantity inputValue) /// public sealed class UnitConverter { + /// + /// The default singleton instance for converting values from one unit to another.
+ /// Modify this to add/remove conversion functions at runtime, such as adding your own third-party units and quantities to convert between. + ///
+ /// + /// Convenience shortcut for ... + /// + public static UnitConverter Default => UnitsNetSetup.Default.UnitConverter; + /// /// Creates a new instance. ///