定义一个测试类
class Test
{
void Func(int id,string name)
{
Console.WriteLine("{0},{1}",id,name);
}
void Func()
{
Console.WriteLine("null");
}
}
Test test = new Test();
Type type = typeof(Test);
type.InvokeMember("Func", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder, test, null);
type.InvokeMember("Func", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder, test, new object[] { 1,"abc"});
输出结果:自动根据传入的参数,选择重载的方法