Skip to content

Commit d81898a

Browse files
authored
💥Change UnitAbbreviationsCache ctor to not load defaults (#1476)
Ref #1200 - Remove UnitAbbreviationsCache.CreateEmpty() - Change default ctor to NOT load default unit abbreviations, use `CreateDefault()` instead - Fix 2 broken test cases
1 parent a3c32b6 commit d81898a

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

Diff for: UnitsNet.Tests/UnitAbbreviationsCacheTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ public void MapUnitToAbbreviation_DoesNotAffectOtherCacheInstances()
325325
var culture = AmericanCulture;
326326
var unit = AreaUnit.SquareMeter;
327327

328-
var cache1 = new UnitAbbreviationsCache();
328+
var cache1 = UnitAbbreviationsCache.CreateDefault();
329329
cache1.MapUnitToAbbreviation(unit, culture, "m^2");
330330

331-
var cache2 = new UnitAbbreviationsCache();
331+
var cache2 = UnitAbbreviationsCache.CreateDefault();
332332
cache2.MapUnitToAbbreviation(unit, culture, "m2");
333333

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

346346
Assert.Equal("m²", cache.GetDefaultAbbreviation(AreaUnit.SquareMeter, AmericanCulture));

Diff for: UnitsNet/CustomCode/UnitAbbreviationsCache.cs

+2-14
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ public sealed class UnitAbbreviationsCache
3939
private ConcurrentDictionary<AbbreviationMapKey, IReadOnlyList<string>> AbbreviationsMap { get; } = new();
4040

4141
/// <summary>
42-
/// Create an instance of the cache and load all the abbreviations defined in the library.
42+
/// Create an empty instance of the cache, with no default abbreviations loaded.
4343
/// </summary>
44-
// TODO Change this to create an empty cache in v6: https://github.com/angularsen/UnitsNet/issues/1200
45-
[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.")]
4644
public UnitAbbreviationsCache()
47-
: this(new QuantityInfoLookup(Quantity.ByName.Values))
45+
: this(new QuantityInfoLookup([]))
4846
{
4947
}
5048

@@ -59,16 +57,6 @@ internal UnitAbbreviationsCache(QuantityInfoLookup quantityInfoLookup)
5957
QuantityInfoLookup = quantityInfoLookup;
6058
}
6159

62-
/// <summary>
63-
/// Create an instance with empty cache.
64-
/// </summary>
65-
/// <remarks>
66-
/// Workaround until v6 changes the default ctor to create an empty cache.<br/>
67-
/// </remarks>
68-
/// <returns>Instance with empty cache.</returns>
69-
// TODO Remove in v6: https://github.com/angularsen/UnitsNet/issues/1200
70-
public static UnitAbbreviationsCache CreateEmpty() => new(new QuantityInfoLookup(new List<QuantityInfo>()));
71-
7260
/// <summary>
7361
/// Create an instance of the cache and load all the built-in unit abbreviations defined in the library.
7462
/// </summary>

0 commit comments

Comments
 (0)