Just like the UnitParser and the QuantityParser can be created with an UnitAbbreviationsCache - the same goes for the QuantityFormatter.
This should allow for different parts of the application to use their own "defaults".
In terms of implementation - we can keep the static Format methods, but they should delegate the call to the Default instance.
There is a slight problem with the name collision- but my plan involves changing the instance member generic parameter to
public string Format<TQuantity>(TQuantity quantity, string? format, IFormatProvider? formatProvider)
where TQuantity : IQuantity
This avoids the boxing of the struct via the IQuantity<TUnit> interface which is currently used by the static Format.
Now, obviously once this is done- the two existing overloads should be deprecated, however the question arises- whether there should by a static alternative or can we simply point to the QuantityFormatter.Default? Note that should we decide to have the static TQuantity versions, then we won't be able to have both use the same name..
We should probably also take / expose an instance of the QuantityFormatter on the UnitsNetSetup, but that's not a requirement.
Just like the
UnitParserand theQuantityParsercan be created with anUnitAbbreviationsCache- the same goes for theQuantityFormatter.This should allow for different parts of the application to use their own "defaults".
In terms of implementation - we can keep the static
Formatmethods, but they should delegate the call to theDefaultinstance.There is a slight problem with the name collision- but my plan involves changing the instance member generic parameter to
This avoids the boxing of the struct via the
IQuantity<TUnit>interface which is currently used by the staticFormat.Now, obviously once this is done- the two existing overloads should be deprecated, however the question arises- whether there should by a static alternative or can we simply point to the
QuantityFormatter.Default? Note that should we decide to have the staticTQuantityversions, then we won't be able to have both use the same name..We should probably also take / expose an instance of the
QuantityFormatteron theUnitsNetSetup, but that's not a requirement.