|
-
January 8th, 2009, 03:27 AM
#1
using InvokeMembre to call a method with out parameters
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.
Code:
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
-
January 8th, 2009, 03:45 AM
#2
Re: using InvokeMembre to call a method with out parameters
Please ignore this question I worked it out.
Code:
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]);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|