Skip to content

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

Merged
merged 12 commits into from
Jan 24, 2018

Conversation

angularsen
Copy link
Owner

To illustrate how to enumerate quantities, units and to convert between them without hard coding any quantities.

image

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 and LengthUnit directly. There is definitely room for improvement in the library here, as previously discussed in #371 #354 #353 #308.

Fixes #274

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.
@angularsen angularsen requested a review from eriove January 14, 2018 22:03
@angularsen
Copy link
Owner Author

angularsen commented Jan 14, 2018

@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
@dayewah Since you made a sample app and have been doing this dance already, this may be of interest to you.

@gojanpaolo
Copy link
Contributor

gojanpaolo commented Jan 15, 2018

Need null checking here?

public string FromHeader => $"Value [{SelectedFromUnit.Abbreviation}]";
public string ToHeader => $"Result [{SelectedToUnit.Abbreviation}]";

@0xferit
Copy link
Contributor

0xferit commented Jan 15, 2018

I just started to examine this sample. I got an exception just after a clicking to a quantity.

NullPointerException at line 85 in MainWindowVm.cs.

@angularsen
Copy link
Owner Author

Thanks for testing it, I've added the null checks. I was not able to reproduce this behavior so likely a racing condition.

@0xferit
Copy link
Contributor

0xferit commented Jan 23, 2018

Working flawlessly now.

I wonder why you didn't make result textbox editable like Google's converter.

@angularsen
Copy link
Owner Author

angularsen commented Jan 24, 2018

Ah, that was just me being lazy and trying to the the least amount of work :-)
I guess I just foresaw some issue with infinite cycles of one field change updating the other, which again updates the first one and so on. It's obviously solvable, I just avoided it the lazy bum that I am 😆

I'm merging in this since the bug is fixed. If anyone wants to improve this app, that is awesome too!

@angularsen angularsen merged commit 82eed32 into master Jan 24, 2018
@angularsen angularsen deleted the angularsen/add-converter-sample-app branch January 24, 2018 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants