Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💥Change UnitAbbreviationsCache ctor to not load defaults #1476

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions UnitsNet.Tests/UnitAbbreviationsCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ public void MapUnitToAbbreviation_DoesNotAffectOtherCacheInstances()
var culture = AmericanCulture;
var unit = AreaUnit.SquareMeter;

var cache1 = new UnitAbbreviationsCache();
var cache1 = UnitAbbreviationsCache.CreateDefault();
cache1.MapUnitToAbbreviation(unit, culture, "m^2");

var cache2 = new UnitAbbreviationsCache();
var cache2 = UnitAbbreviationsCache.CreateDefault();
cache2.MapUnitToAbbreviation(unit, culture, "m2");

Assert.Equal(new[] { "m²", "m^2" }, cache1.GetUnitAbbreviations(unit, culture));
Expand All @@ -340,7 +340,7 @@ public void MapUnitToAbbreviation_DoesNotAffectOtherCacheInstances()
[Fact]
public void MapUnitToAbbreviation_AddCustomUnit_DoesNotOverrideDefaultAbbreviationForAlreadyMappedUnits()
{
var cache = new UnitAbbreviationsCache();
var cache = UnitAbbreviationsCache.CreateDefault();
cache.MapUnitToAbbreviation(AreaUnit.SquareMeter, AmericanCulture, "m^2");

Assert.Equal("m²", cache.GetDefaultAbbreviation(AreaUnit.SquareMeter, AmericanCulture));
Expand Down
16 changes: 2 additions & 14 deletions UnitsNet/CustomCode/UnitAbbreviationsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ public sealed class UnitAbbreviationsCache
private ConcurrentDictionary<AbbreviationMapKey, IReadOnlyList<string>> AbbreviationsMap { get; } = new();

/// <summary>
/// Create an instance of the cache and load all the abbreviations defined in the library.
/// Create an empty instance of the cache, with no default abbreviations loaded.
/// </summary>
// TODO Change this to create an empty cache in v6: https://github.com/angularsen/UnitsNet/issues/1200
[Obsolete("Use CreateDefault() instead to create an instance that loads the built-in units. The default ctor will change to create an empty cache in UnitsNet v6.")]
public UnitAbbreviationsCache()
: this(new QuantityInfoLookup(Quantity.ByName.Values))
: this(new QuantityInfoLookup([]))
{
}

Expand All @@ -59,16 +57,6 @@ internal UnitAbbreviationsCache(QuantityInfoLookup quantityInfoLookup)
QuantityInfoLookup = quantityInfoLookup;
}

/// <summary>
/// Create an instance with empty cache.
/// </summary>
/// <remarks>
/// Workaround until v6 changes the default ctor to create an empty cache.<br/>
/// </remarks>
/// <returns>Instance with empty cache.</returns>
// TODO Remove in v6: https://github.com/angularsen/UnitsNet/issues/1200
public static UnitAbbreviationsCache CreateEmpty() => new(new QuantityInfoLookup(new List<QuantityInfo>()));

/// <summary>
/// Create an instance of the cache and load all the built-in unit abbreviations defined in the library.
/// </summary>
Expand Down