Click to See Complete Forum and Search --> : using InvokeMembre to call a method with out parameters


Otex
January 8th, 2009, 02:27 AM
I need to call a large number of methods selecting them from a dropdown box.
Rather than doing a large Switch/Case I use reflection and invokemeber, it works fine, I can send parameters and get a return parameter but I need more than one parameter back.
I can't work out a way to use out parameters with invokemembre.

Here is a working sample of my code w/o the out parameter.


Type t = machineComm.GetType();
object[] param = new object[] { Convert.ToInt16(comboBox6.Text) };
MethodInfo methodName = t.GetMethod(comboBox3.Text); // this is the Method to call
retCode = (int)t.InvokeMember(methodName.Name, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, machineComm, param);




Any help appreciated

Otex
January 8th, 2009, 02:45 AM
Please ignore this question I worked it out.


object[] param = new object[2];
Type t = machineComm.GetType();
param[0] = Convert.ToInt16(comboBox6.Text) ;
param[1] = 0;
MethodInfo methodName = t.GetMethod(comboBox3.Text);
retCode = (int)t.InvokeMember(methodName.Name, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, machineComm, param);
Console.WriteLine(param[1]);