-
Notifications
You must be signed in to change notification settings - Fork 382
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
Allow Override of Default Unit Conversion #1313
Comments
I'll need some time to get around to this. Not sure, but if you are able to debug to confirm this and write a unit test that fails, then passes with a fix, then that will help speed things up a lot. |
Okay, I will do that! |
This is a limitation in the current implementation- there was a similar request back-when, and I remember we initially had the In retrospect even that was probably a mistake, as the (significant!) performance impact of boxing the Unit and calling in the concurrent dictionary and all that fun stuff is affecting all conversions between non-base units (e.g. Milligram-Microgram). I've been toying with this (and the extensibility side as a whole) - here's what I got down in the sample project:
|
Our industry uses specific conversion ratios between units that are not always the standard. For example (according to my best understanding of what was explained to me), the conversion between pressure units of Pascals and Inches of Water Column is an approximation due to certain environmental factors. Therefore, we may want to adjust that conversion to slightly adjust that approximation.
I would like to be able to set a conversion function to override the default. I tried this:
However, this does not seem to work because
Pressure.TryToUnit
is called before attempting to use the unit converter to retrieve the default conversion function. I'm not sure if that is a bug, or working as intended, as it is unclear to me how you would extend the PressureUnit enum such thatPressure.TryToUnit
would fail to convert. Therefore, I also wonder how theunitConverter
argument would ever be made use of? I feel like I must be missing something very obvious. Is it terrible for performance to check the unit converter for a conversion function before callingPressure.TryToUnit
?It seems like the alternatives are to fork the code base or to define a custom Pressure unit. The latter option makes it unclear to developers which Pressure unit they should be using in the application, along with the API tradeoffs described in the documentation on custom units. Both options are pretty heavy for a slight tweak to the conversion factor.
The text was updated successfully, but these errors were encountered: