I'm writing a custom binder that delegates most of the work to the
DefaultBinder. In my BindToMethod impl, I'm remapping one or more of the
method's parameters under certain conditions with code similiar to this:

public override MethodBase BindToMethod(BindingFlags bindingAttr,
                                        MethodBase[] match,
                                        ref object[] args,
                                        ParameterModifier[] modifiers,
                                        System.Globalization.CultureInfo
culture,
                                        string[] names,
                                        out object state)
{
    MethodBase mb = null;
    try
    {
        // since the typical case is no remapping, go ahead and take the
occasional exception hit
        mb = Type.DefaultBinder.BindToMethod(bindingAttr, match, ref args,
modifiers, culture, names, out state);
    }
    catch (MissingMethodException)
    {
        for (int i = 0; i < args.Length; ++i)
        {
            if (ShouldRemapParam(args[i]))
            {
                args[i] = RemapParam(args[i]);
            }
        }
        // re-bind with the new param types
        mb = Type.DefaultBinder.BindToMethod(bindingAttr, match, ref args,
modifiers, culture, names, out state);
    }

    return (mb);
}

This works fine, provided none of the parameters are passed by reference.
If a param is passed by-ref and I remap it, the call to
Type.DefaultBinder.BindToMethod succeeds, but the outer InvokeMember call
fails - apparently because the original param type was by ref but my
remapped param type is not. How do I tell reflection that the remapped param
(s) should be by-ref? Am I just missing something really simple here or is
this a limitation?

Thanks

Reply via email to