CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2008
    Posts
    29

    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

  2. #2
    Join Date
    Dec 2008
    Posts
    29

    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
  •  





Click Here to Expand Forum to Full Width

Featured