Parameter count mismatch.
その行で別のクラスのメソッドを呼び出そうとすると、エラーが発生しますval = (bool)method.Invoke(instance, args);
メソッドには単一の引数しかなく、(私は思うに)単一の引数をオブジェクトとして渡しているので、なぜエラーが発生するのかわかりません。
誰かが私のコードの何が問題なのか教えてください。
class firstClass
{
public bool MethodXYZ(System.Windows.Forms.WebBrowser Wb,
string debug_selectedOption)
{
object[] args = new object[] { Wb, debug_selectedOption };
string methodToInvoke = System.Reflection.MethodBase.GetCurrentMethod().Name;
return runGenericMethod(methodToInvoke, args);
}
private bool runGenericMethod(string methodToInvoke, object[] args)
{
bool val = false;
string anotherClass = args[1].ToString();
Type t = Type.GetType("ProjectXYZ." + anotherClass);
MethodInfo method = t.GetMethod(methodToInvoke);
var constructorInfo = t.GetConstructor(new Type[0]);
if (constructorInfo != null)
{
object instance = Activator.CreateInstance(t);
val = (bool)method.Invoke(instance, args);
}
//........
return val;
}
}
class anotherClass
{
public bool MethodXYZ(object[] args)
{
return true;
}
}