linux-packaging-mono/mono/tests/array-invoke.cs
Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

35 lines
1013 B
C#

namespace Test
{
using System;
using System.Reflection;
class Foo
{
public static int Sum (params int[] args)
{
int ret = 0;
foreach (int a in args)
ret += a;
return ret;
}
}
class TestInvokeArray
{
public static int Main (string[] args)
{
Foo f = new Foo ();
MethodInfo m = (MethodInfo) (f.GetType ().FindMembers (MemberTypes.All, BindingFlags.Public | BindingFlags.Static, Type.FilterName, "Sum"))[0];
int[] numbers = new int[3]{4, 5, 6};
object[] parms = new object[1]{numbers};
int sum = (int)m.Invoke (f, parms);
Console.WriteLine ("sum is " + sum);
if (sum != 15)
return 1;
return 0;
}
}
}