Mar 7, 2010

Nullable method parameters with FluorineFx

After upgrading to the latest version of FluorineFx, we noticed quite a few new exceptions: "Could not find a suitable method with name %". We checked the parameters, overloads, ect.  One thing was consistent, each had at least one nullable parameter.  We've already branched FluorineFx for datetime issues (TimezoneCompensation.None doesn't actually mean none, that's another post), so I took a crack at fixing this one as well.  I traced everything back to the bloated method TypeHelper.IsAssignable().  As best I can tell this tries to see if the method parameter in-hand can be assigned to the parameter type of the method.  At the heart of things, its using the .Net TypeConverter, but it won't handle nullables.  You need to use the NullableTypeConverter instead.  We added the following line of code to line 693 of the TypeHelper file:

........
if (obj != null)
{
    if (isNullable)
    {
        NullableConverter nullableConverter = new NullableConverter(targetType);
        targetType = nullableConverter.UnderlyingType;
    }

    TypeConverter typeConverter = ReflectionUtils.GetTypeConverter(obj);//TypeDescriptor.GetConverter(obj);
........

Why don't I just check this into trunk?  Well I tried to contact Zoltan, the main contributor to FluorineFx as far as I can tell, and he's completely unresponsive.  Bummer.  There a few other nitpics we'd really like to checkin.

No comments:

Post a Comment