Passing int[] to Method.Invoke

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Neil Fedin via .NET 247

    #1

    Passing int[] to Method.Invoke

    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.Creat eInstance(...);

    mInfo.Invoke(in stance,Paramete rs);

    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


    --------------------------------
    From: Neil Fedin

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>wE2rQAbOq0O jPpJrvnABtw==</Id>
  • Jon Skeet [C# MVP]

    #2
    Re: Passing int[] to Method.Invoke

    Neil Fedin via .NET 247 <anonymous@dotn et247.com> wrote:[color=blue]
    > I am writing a testing application that uses reflection to open
    > assemblies and call methods.[/color]

    <snip>

    Please see my answer in microsoft.publi c.dotnet.framew ork.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Passing int[] to Method.Invoke

      Neil Fedin via .NET 247 <anonymous@dotn et247.com> wrote:[color=blue]
      > I am writing a testing application that uses reflection to open
      > assemblies and call methods.[/color]

      <snip>

      Please see my answer in microsoft.publi c.dotnet.framew ork.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      Working...