我有两个函数的MethodBases:
public static int Add(params int[] parameters) { /* ... */ }
public static int Add(int a, int b) { /* ... */ }
Run Code Online (Sandbox Code Playgroud)
我有一个通过我制作的类调用MethodBases的函数:
MethodBase Method;
object Target;
public object call(params object[] input)
{
return Method.Invoke(Target, input);
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我AddTwoMethod.call(5, 4);工作正常.
如果我使用AddMethod.call(5, 4);它返回:
未处理的异常:System.Reflection.TargetParameterCountException:参数与签名不匹配
是否有任何方法可以使两个调用都正常工作而无需手动将参数放入数组中params int[]?