下面的代码正确地找到了类和方法,但它给出了以下错误method.Invoke(this, null);
System.Reflection.TargetException was unhandled
HResult=-2146232829
Message=Object does not match target type.
Source=mscorlib
StackTrace:.....
调用 void 方法的正确语法是什么?
using System;
using System.Reflection;
using System.Windows;
namespace ProjectXYZ
{
class NavigateOptions
{
public bool runMethod(string debug_selectedClass)
{
Type t = Type.GetType("ProjectXYZ." + debug_selectedClass);
MethodInfo method = t.GetMethod("test");
if (method.IsStatic)
method.Invoke(null, null);
else
method.Invoke(this, null);
return true;
}
}
public class Option72
{
public void test()
{
string hasItRun = "Yes";
}
}
}