Skip to content

Commit 1ee3f76

Browse files
authored
Revert "🔥Remove static Default getters, obsoleted by UnitsNetSetup (#1475)"
This reverts commit a3c32b6.
1 parent 3f1456d commit 1ee3f76

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

‎UnitsNet/CustomCode/QuantityParser.cs

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public class QuantityParser
3434
private readonly UnitAbbreviationsCache _unitAbbreviationsCache;
3535
private readonly UnitParser _unitParser;
3636

37+
/// <summary>
38+
/// The default instance of <see cref="QuantityParser"/>, which uses <see cref="UnitsNetSetup"/>.<see cref="UnitsNetSetup.Default"/>.<see cref="UnitsNetSetup.UnitAbbreviations"/>.
39+
/// </summary>
40+
[Obsolete("Use UnitsNetSetup.Default.QuantityParser instead.")]
41+
public static QuantityParser Default => UnitsNetSetup.Default.QuantityParser;
42+
3743
/// <summary>
3844
/// Creates an instance of <see cref="QuantityParser"/>, optionally specifying an <see cref="UnitAbbreviationsCache"/>
3945
/// with unit abbreviations to use when parsing.

‎UnitsNet/CustomCode/UnitAbbreviationsCache.cs

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public sealed class UnitAbbreviationsCache
3131
/// </example>
3232
internal static readonly CultureInfo FallbackCulture = CultureInfo.InvariantCulture;
3333

34+
/// <summary>
35+
/// The static instance used internally for ToString() and Parse() of quantities and units.
36+
/// </summary>
37+
[Obsolete("Use UnitsNetSetup.Default.UnitAbbreviations instead.")]
38+
public static UnitAbbreviationsCache Default => UnitsNetSetup.Default.UnitAbbreviations;
39+
3440
private QuantityInfoLookup QuantityInfoLookup { get; }
3541

3642
/// <summary>

‎UnitsNet/CustomCode/UnitParser.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ namespace UnitsNet
1313
{
1414
/// <summary>
1515
/// Parses units given a unit abbreviations cache.
16-
/// A static instance <see cref="UnitsNetSetup"/>.<see cref="UnitsNetSetup.Default"/>.<see cref="UnitsNetSetup.UnitParser"/> is used internally
17-
/// to parse quantities and units using the default abbreviations cache for all units and abbreviations defined in the library.
16+
/// The static instance <see cref="Default"/> is used internally to parse quantities and units using the
17+
/// default abbreviations cache for all units and abbreviations defined in the library.
1818
/// </summary>
1919
public sealed class UnitParser
2020
{
2121
private readonly UnitAbbreviationsCache _unitAbbreviationsCache;
2222

23+
/// <summary>
24+
/// The default static instance used internally to parse quantities and units using the
25+
/// default abbreviations cache for all units and abbreviations defined in the library.
26+
/// </summary>
27+
[Obsolete("Use UnitsNetSetup.Default.UnitParser instead.")]
28+
public static UnitParser Default => UnitsNetSetup.Default.UnitParser;
29+
2330
/// <summary>
2431
/// Create a parser using the given unit abbreviations cache.
2532
/// </summary>
@@ -198,7 +205,7 @@ public bool TryParse([NotNullWhen(true)] string? unitAbbreviation, Type unitType
198205
{
199206
return false;
200207
}
201-
208+
202209
unit = matches[0].Unit;
203210
return true;
204211
}

‎UnitsNet/UnitConverter.cs

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Concurrent;
66
using System.Diagnostics.CodeAnalysis;
7+
using System.Globalization;
78
using System.Reflection;
89
using System.Linq;
910
using UnitsNet.InternalHelpers;
@@ -34,6 +35,13 @@ public delegate TQuantity ConversionFunction<TQuantity>(TQuantity inputValue)
3435
/// </summary>
3536
public sealed class UnitConverter
3637
{
38+
/// <summary>
39+
/// The static instance used by Units.NET to convert between units. Modify this to add/remove conversion functions at runtime, such
40+
/// as adding your own third-party units and quantities to convert between.
41+
/// </summary>
42+
[Obsolete("Use UnitsNetSetup.Default.UnitConverter instead.")]
43+
public static UnitConverter Default => UnitsNetSetup.Default.UnitConverter;
44+
3745
/// <summary>
3846
/// Creates a new <see cref="UnitConverter"/> instance.
3947
/// </summary>

0 commit comments

Comments
 (0)