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

Add the possibility to instantiate a QuantityParser #1447

Open
lipchev opened this issue Dec 10, 2024 · 1 comment
Open

Add the possibility to instantiate a QuantityParser #1447

lipchev opened this issue Dec 10, 2024 · 1 comment

Comments

@lipchev
Copy link
Collaborator

lipchev commented Dec 10, 2024

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.

@angularsen
Copy link
Owner

Sounds good.

Regarding static methods, I don't think QuantityFormatter.Format() is something many do, it feels more of an internal component to me, so I vote for instance methods only and require users to go via UnitsNetSetup.Default.QuantityFormatter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants