Необходимо определить, какой метод Вы хотите:
class SomeType
{
void Foo(int size, string bar) { }
void Foo() { }
}
SomeType obj = new SomeType();
// call with int and string arguments
obj.GetType()
.GetMethod("Foo", new Type[] { typeof(int), typeof(string) })
.Invoke(obj, new object[] { 42, "Hello" });
// call without arguments
obj.GetType()
.GetMethod("Foo", new Type[0])
.Invoke(obj, new object[0]);
Используйте перегрузку GetMethod, которая берет Систему. Введите [] и передайте пустой Тип [];
typeof ( Class ).GetMethod ( "Method", new Type [ 0 ] { } ).Invoke ( instance, null );
Да. Когда Вы вызываете передачу метода параметры, которые соответствуют перегрузке, которую Вы хотите.
, Например:
Type tp = myInstance.GetType();
//call parameter-free overload
tp.InvokeMember( "methodName", BindingFlags.InvokeMethod,
Type.DefaultBinder, myInstance, new object[0] );
//call parameter-ed overload
tp.InvokeMember( "methodName", BindingFlags.InvokeMethod,
Type.DefaultBinder, myInstance, new { param1, param2 } );
, Если Вы делаете это наоборот (т.е. путем нахождения MemberInfo и вызова Вызывают) быть осторожной, что Вы получаете правильный - перегрузка без параметров могла быть найденным первым.