Passing parameter(s) to method using Reflection

Hello. I am having trouble finding the solution to my problem. I created instances of two classes using Activator.CreateInstance and Reflection. The first class contains properties that are filled with values from code. The second class saves the class in it by using the "Insert" method. For some reason, I keep getting an error. How would I go about accomplishing this? This is what I have, but it does not seem to work.

Code Snippet

MethodInfo myMethod = t2.GetMethod("Insert"); //Gets the insert method in the 2nd class

myMethod.Invoke(Class2Object,Class1Object);

It gives me the error: "Cannot convert object to object[]." Is there a way around this?

[1107 byte] By [OIsaac] at [2008-1-6]
# 1

You pass Parameters via an Object[] { }

I would take a guess and determine that

Code Snippet

myMethod.Invoke(t2, new Object[] { Class2Object, Class1Object } );

Is what you are looking for. This assumes that the method takes 2 parameters and that class2object and class1object are and that t2 is the instance to the class that you wish to execute the method for.

Hope this helps.

MarcD at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Thank you, that solved my problem. I appreciate the help.
OIsaac at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified