Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

BindingTypeConverters EqualityTypeConverter.DoReferenceCast doesn't handle nullable values #131

Closed
robhorvath opened this Issue Dec 3, 2012 · 6 comments

Comments

Projects
None yet
2 participants
Contributor

robhorvath commented Dec 3, 2012

I ran into a problem where I had a numeric up/down control that had a double? property, which wouldn't bind to the double? property on my viewmodel. I would receive an error like:

"Invalid cast from 'System.Double' to 'System.Nullable`1[[System.Double"

I changed the DoReferenceCast to use an implementation from here, and my problem was solved:

http://stackoverflow.com/questions/793714/how-can-i-fix-this-up-to-do-generic-conversion-to-nullablet

I don't have any experience with WinRT, so I'm not sure if this works for that platform.

public static object DoReferenceCast<T>(object from)
        {
            var t = typeof(T);
            var u = Nullable.GetUnderlyingType(t);

            if (u == null) {
                return (T) Convert.ChangeType(@from, t);
            }

            if (@from == null) {
                return default(T);
            }

            return (T) Convert.ChangeType(@from, u);
        }
Owner

paulcbetts commented Dec 3, 2012

Can you make a pull request to fix this? If you're not sure how to do this, GTalk paul.betts@gmail.com and I can walk you through it. Extra bonus points if you put a test in! Open ReactiveUI_Net4Only.sln to get started

Contributor

robhorvath commented Dec 3, 2012

Sure, I can do that. I just need to find the time in the next couple of
days.

On Mon, Dec 3, 2012 at 2:37 PM, Paul Betts notifications@github.com wrote:

Can you make a pull request to fix this? If you're not sure how to do
this, GTalk paul.betts@gmail.com and I can walk you through it. Extra
bonus points if you put a test in! Open ReactiveUI_Net4Only.sln to get
started


Reply to this email directly or view it on GitHubhttps://github.com/reactiveui/ReactiveUI/issues/131#issuecomment-10967872.

Owner

paulcbetts commented Dec 3, 2012

Hi @robhorvath, check out the CONTRIBUTING.md file in the root directory, it'll give you some help on how to get started

Contributor

robhorvath commented Dec 3, 2012

I submitted a pull request and test for the issue, but I'm unable to test the other platforms on my current setup. Do you mind running the ReactiveUI.sln?

Also - I noticed there was another broken unit test here: ReactiveCommandTest.TheCreateCommandMethod.CreatesCommandThatHandlesThrownExceptions
(I didn't break it!)

Owner

paulcbetts commented Dec 4, 2012

Don't worry about that test, I forgot to fix it - you're good.

@paulcbetts paulcbetts added a commit that referenced this issue Dec 5, 2012

@robhorvath @paulcbetts robhorvath + paulcbetts Fix for Issue #131
BindingTypeConverters EqualityTypeConverter.DoReferenceCast doesn't
handle nullable values
56af287
Owner

paulcbetts commented Dec 6, 2012

Fixed this in #133. Thanks for the help @robhorvath!

@paulcbetts paulcbetts closed this Dec 6, 2012

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