-
Notifications
You must be signed in to change notification settings - Fork 387
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
TypeConverter implementation for Units #189
Comments
Hi, I'm not familiar with this myself , but I think this should be safe to add and provide some value to users. I don't know if this is a showstopper or if there are workarounds, just a heads up to you for something to look into. Let me know if you want to do a pull request, I'll merge it in if you get it working. |
Closing, will reopen if there are any further discussions. |
Hey, I will have to implement this for my project eventually, so I will let you know how I end up solving the issue. For now keep it closed. Cheers, |
Hi
It wold be nice if the parse function itself could substitute the exponents. |
Hi I took inspired for this work from this places: https://stackoverflow.com/questions/14929681/how-to-pass-parameter-to-typeconverter-derived-class
|
Thanks for posting @chromhelm , would you care to do a pull request on this? Then we can give a proper review of the code too. It seems like TypeConverter is supported in netstandard2.0 so I think that should work. |
Fixed in #644 |
Hi, |
@wenndemann It depends on what you mean by default unit of a quantity. The exception is There is some work in progress for v5 in #709, but work has not continued there for some time now. |
@wenndemann Oh, my bad, I forgot you referred to type converters as in #644 . There is a new [DefaultUnit(LengthUnit.Centimeter)]
public Length MyLength {get;set;} It then affects how that property is rendered in a grid view or other Winforms/WPF GUI components. I am speculating tho, it's best if @chromhelm gives an example maybe. Then we can add it to the wiki. |
Yes please- I'm also still a little confused as to what can be achieved by using the TypeConverter + DefaultUnitAttribute - is it possible to convert to another unit or is it just for binding to string? Can I use this somehow to expose a given quantity as a specified unit (inside a view model for instance)- such that the quantity is always converted to the specified unit (not interested in binding to a string value- I only work with quantities) |
I mean it would be awesome if we could have this test succeed:
|
Well I use it to parse some old INI files into objects so wrote an ConfigurationExtension that gives a key/value pair as string. Unfortunately some of the values has no unit and so I got into these problems. I derive the
Now I just need to add the
|
Hi,
One feature I've found myself wanting in UnitsNet is the ability to edit unit types in a PropertyGrid. As of now, the property grid will display the ToString() method of the unit (which works great). However, the Unit properties may not be edited.
(See http://csharphelper.com/blog/2014/09/use-a-type-converter-with-a-propertygrid-control-in-c/)
Something like this is probably really easy to implement using the TryParse methods already present in UnitsNet.
The text was updated successfully, but these errors were encountered: