Skip to content

Commit

Permalink
Revert "🔥Remove static Default getters, obsoleted by UnitsNetSetup (#…
Browse files Browse the repository at this point in the history
…1475)"

This reverts commit a3c32b6.
  • Loading branch information
angularsen authored Dec 29, 2024
1 parent 3f1456d commit 1ee3f76
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
6 changes: 6 additions & 0 deletions UnitsNet/CustomCode/QuantityParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public class QuantityParser
private readonly UnitAbbreviationsCache _unitAbbreviationsCache;
private readonly UnitParser _unitParser;

/// <summary>
/// The default instance of <see cref="QuantityParser"/>, which uses <see cref="UnitsNetSetup"/>.<see cref="UnitsNetSetup.Default"/>.<see cref="UnitsNetSetup.UnitAbbreviations"/>.
/// </summary>
[Obsolete("Use UnitsNetSetup.Default.QuantityParser instead.")]
public static QuantityParser Default => UnitsNetSetup.Default.QuantityParser;

Check warning on line 41 in UnitsNet/CustomCode/QuantityParser.cs

View check run for this annotation

Codecov / codecov/patch

UnitsNet/CustomCode/QuantityParser.cs#L41

Added line #L41 was not covered by tests

/// <summary>
/// Creates an instance of <see cref="QuantityParser"/>, optionally specifying an <see cref="UnitAbbreviationsCache"/>
/// with unit abbreviations to use when parsing.
Expand Down
6 changes: 6 additions & 0 deletions UnitsNet/CustomCode/UnitAbbreviationsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public sealed class UnitAbbreviationsCache
/// </example>
internal static readonly CultureInfo FallbackCulture = CultureInfo.InvariantCulture;

/// <summary>
/// The static instance used internally for ToString() and Parse() of quantities and units.
/// </summary>
[Obsolete("Use UnitsNetSetup.Default.UnitAbbreviations instead.")]
public static UnitAbbreviationsCache Default => UnitsNetSetup.Default.UnitAbbreviations;

Check warning on line 38 in UnitsNet/CustomCode/UnitAbbreviationsCache.cs

View check run for this annotation

Codecov / codecov/patch

UnitsNet/CustomCode/UnitAbbreviationsCache.cs#L38

Added line #L38 was not covered by tests

private QuantityInfoLookup QuantityInfoLookup { get; }

/// <summary>
Expand Down
13 changes: 10 additions & 3 deletions UnitsNet/CustomCode/UnitParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ namespace UnitsNet
{
/// <summary>
/// Parses units given a unit abbreviations cache.
/// A static instance <see cref="UnitsNetSetup"/>.<see cref="UnitsNetSetup.Default"/>.<see cref="UnitsNetSetup.UnitParser"/> 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 <see cref="Default"/> is used internally to parse quantities and units using the
/// default abbreviations cache for all units and abbreviations defined in the library.
/// </summary>
public sealed class UnitParser
{
private readonly UnitAbbreviationsCache _unitAbbreviationsCache;

/// <summary>
/// The default static instance used internally to parse quantities and units using the
/// default abbreviations cache for all units and abbreviations defined in the library.
/// </summary>
[Obsolete("Use UnitsNetSetup.Default.UnitParser instead.")]
public static UnitParser Default => UnitsNetSetup.Default.UnitParser;

Check warning on line 28 in UnitsNet/CustomCode/UnitParser.cs

View check run for this annotation

Codecov / codecov/patch

UnitsNet/CustomCode/UnitParser.cs#L28

Added line #L28 was not covered by tests

/// <summary>
/// Create a parser using the given unit abbreviations cache.
/// </summary>
Expand Down Expand Up @@ -198,7 +205,7 @@ public bool TryParse([NotNullWhen(true)] string? unitAbbreviation, Type unitType
{
return false;
}

unit = matches[0].Unit;
return true;
}
Expand Down
8 changes: 8 additions & 0 deletions UnitsNet/UnitConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using System.Linq;
using UnitsNet.InternalHelpers;
Expand Down Expand Up @@ -34,6 +35,13 @@ public delegate TQuantity ConversionFunction<TQuantity>(TQuantity inputValue)
/// </summary>
public sealed class UnitConverter
{
/// <summary>
/// The static instance used by Units.NET to convert between units. Modify this to add/remove conversion functions at runtime, such
/// as adding your own third-party units and quantities to convert between.
/// </summary>
[Obsolete("Use UnitsNetSetup.Default.UnitConverter instead.")]
public static UnitConverter Default => UnitsNetSetup.Default.UnitConverter;

Check warning on line 43 in UnitsNet/UnitConverter.cs

View check run for this annotation

Codecov / codecov/patch

UnitsNet/UnitConverter.cs#L43

Added line #L43 was not covered by tests

/// <summary>
/// Creates a new <see cref="UnitConverter"/> instance.
/// </summary>
Expand Down

0 comments on commit 1ee3f76

Please sign in to comment.