Passing int[] to Method.Invoke

  • Thread starter Neil Fedin via .NET 247
  • Start date
N

Neil Fedin via .NET 247

I am writing a testing application that uses reflection to open assemblies and call methods.

I have a function that looks like this...

public void Method1 (int[] IDArray, bool SomethingElse){
...
}

When I prepare the parameters for the above function, I create and integer array and give it some values

i.e.
int[] IDArray = new int[3]{1,2,3};

Everything works fine up to this point.

I now need to create the object array that Method.Invoke requires.

object[] Parameters = new object[2];
Parameters[0] = IDArray;
Parameters[1] = true;

Now I want to invoke the method.

MethodInfo mInfo = ......
object instance = Activator.CreateInstance(...);

mInfo.Invoke(instance,Parameters);

At this point I get an error...it tells me that Object cannot implicitly convert to the parameter type(int[]).

All other data types and objects work fine. How can I implement Method.Invoke to pass an array of values(not just int, it could be any type)?

Thanks,

Neil
 
J

Jon Skeet [C# MVP]

Neil Fedin via .NET 247 said:
I am writing a testing application that uses reflection to open
assemblies and call methods.

<snip>

Please see my answer in microsoft.public.dotnet.framework.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top