ParameterModifier[] argument is only used when doing late bound COM interop calls
for your purpose, you only need to do
Type[] paramTypes = new Type[] {Type.GetType("System.String&")};
MethodInfo mi = typeof(TestRef).GetMethod( "GetMessage", paramTypes );
try
using System;
using System.Reflection;
class TestRef
{
public int GetMessage(ref string Message, out int value2)
{
Console.WriteLine(Message);
Message = "123";
value2 = 100;
return 2;
}
public static void Main()
{
TestRef tr = new TestRef();
String s="";
int out2;
int i = tr.GetMessage(ref s, out out2);
Console.WriteLine("normal way: {0}:{1}:{2}", i, s, out2);
Type[] paramTypes = new Type[] {Type.GetType("System.String&"), Type.GetType("System.Int32&")};
MethodInfo mi = typeof(TestRef).GetMethod( "GetMessage", paramTypes );
if (mi != null)
{
Console.WriteLine(mi.Name);
string s2 = "abc";
object[] o = new object[2];
o[0] = s2;
int i2 = (int)mi.Invoke(tr, o);
Console.WriteLine("reflection:{0}:{1}:{2}", i2, o[0], o[1]);
}
}
}
ParameterModifier[] 使用
最新推荐文章于 2020-08-06 15:15:04 发布