Skip to content

Late Binding - Help invoking a method please.

Martyn Harris

Asked Jun 19, 2008, 9:48 AM EDT2 answers
Share
LinkedInX

Hi,

I am using reflection / late binding to invoke a method.  This all works correctly as long as my paramater types match exactly the parameter types for the method.

However I need it to attempt to parse the supplied parameters and convert their types to match that of the method being invoked.  I guess its possible through setting some flags on the Binder ??  however I cannot get this to work.

 

Here is my code so far (which will error if an incorrect paramater type is passed)

Java
object[] methodParams = { "x", "y" };
Type thisType = this.GetType();
MethodInfo methodToCall = thisType.GetMethod("MyMethod");
methodToCall.Invoke(this, methodParams);

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    I think it would help if you posted the actual method you are trying to call.
    0
  • 0

    The method is not known at design / compile time.  Hence the reason for using reflection.

    If I knew the method to be called then I would just hard code it.

    0