Description
Problem
If I add a custom abbreviation:
UnitAbbreviationsCache.Default.MapUnitToAbbreviation(VolumeUnit.UsCustomaryCup, "Cup");
it parses just fine. However, when I call .ToString()
, I still get the default abbreviation of ""
.
NOTE I understand that there is ambiguity between "cup" units, and that's why it's defaulted to an empty string. I'm using the code above to override this default and use US Customary Cup for my app.
Cause
The above method merely appends the abbreviation to the list of acceptable values.
UnitsNet/UnitsNet/CustomCode/UnitValueAbbreviationLookup.cs
Lines 72 to 82 in 87dc3c7
However, the .ToString()
methods on classes only use the first abbreviation in the list.
Proposal
Add a new method
void MapUnitToDefaultAbbreviation<TUnitType>(TUnitType unit, string abbreviation) where TUnitType : Enum
{
...
}
that would insert the new abbreviation at the beginning of the list rather than appending it to the end. Then when .ToString()
is called, it can still take the first abbreviation.