【发布时间】:2016-10-24 17:34:30
【问题描述】:
using System;
using System.Reflection;
namespace Reflection
{
class Test
{
protected void methodname(int i)
{
Console.WriteLine(("in the world of the reflection- only i"));
Console.Read();
}
protected void methodname(int i, int j)
{
Console.WriteLine(("in the world of the reflection i , j"));
Console.Read();
}
}
class Program
{
static void Main(string[] args)
{
// BindingFlags eFlags = BindingFlags.Default | BindingFlags.Instance | BindingFlags.Public|BindingFlags.NonPublic;
BindingFlags eFlags = BindingFlags.Instance|BindingFlags.NonPublic;
Test aTest = new Test();
MethodInfo mInfoMethod = typeof(Reflection.Test).GetMethod("methodname", eFlags);
mInfoMethod.Invoke(aTest, new object[] { 10 ,20});
}
}
}
我想调用两个 Getmethod() 重载方法。如果我给出方法名称,则会引发运行时错误(不明确的方法调用)。如何避免这种情况以及如何调用每个方法。
【问题讨论】:
-
你不能用一个
Invoke()调用来调用两个重载。你必须分别Invoke()每一个。 -
如何分别调用各个方法?
-
只打两次
Invoke()?
标签: c# reflection