-
Notifications
You must be signed in to change notification settings - Fork 393
Add unit converter WPF sample app #380
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
Conversation
To illustrate how to enumerate quantities, units and to convert between them without hard coding any quantities. This sample also illustrates that there is currently need for reflection in order to enumerate units for a selected quantity, as well as getting the abbreviation for a unit, since the library does not provide the means to retrieve these generically.
@eriove @ferittuncer @JKSnd for input. Also, this sample app pretty much sums up the current limitation of UnitsNet that currently requires reflection to do conversions without hard coded quantity types. @YektaMirkan Since you asked about #354 Getting abbreviation list of a quantity |
Need null checking here?
|
I just started to examine this sample. I got an exception just after a clicking to a quantity.
|
Thanks for testing it, I've added the null checks. I was not able to reproduce this behavior so likely a racing condition. |
Working flawlessly now. I wonder why you didn't make result textbox editable like Google's converter. |
Ah, that was just me being lazy and trying to the the least amount of work :-) I'm merging in this since the bug is fixed. If anyone wants to improve this app, that is awesome too! |
To illustrate how to enumerate quantities, units and to convert between them without hard coding any quantities.
The app lists all quantities (Length, Mass etc), and when you select one, it then lists all units for that quantity (if Length was chosen; meters, centimeters etc). Then it converts the numeric value from one selected unit to another.
This sample also highlights a limitation in the library that requires reflection in order to enumerate units for a selected quantity and to get the abbreviation for a unit, since the library does not provide a generic means to retrieve these without referencing types like
Length
andLengthUnit
directly. There is definitely room for improvement in the library here, as previously discussed in #371 #354 #353 #308.Fixes #274