我正在使用 MethodInfo 调用重载方法,该方法引发异常 TargetParameterCount 不匹配,下面是我的代码
public class Device
{
public bool Send(byte[] d, int l, int t)
{
return this.Send(d, 0, l, t);
}
public bool Send(byte[] d, int l, int t,int t)
{
return true;
}
}
我在其他班级中调用这些函数。
public class dw
{
public bool BasicFileDownload(Device device)
{
Type devType = device.GetType();
byte [] dbuf = readbuff();
MethodInfo methodSend = deviceType.GetMethods().Where(m => m.Name =="Send").Last();
object invokeSend = methodOpen.Invoke(device, new object[] {dbuf,0,10,100 });
}
}
现在我尝试使用 4 个参数调用 Send,但它抛出错误。
System.Reflection.TargetParameterCountException:参数计数不匹配。
在 System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(对象 obj、BindingFlags invokeAttr、Binder 活页夹、Object[] 参数、CultureInfo 区域性)
在System.Reflection.RuntimeMethodInfo.Invoke(对象obj,BindingFlags invokeAttr,Binder活页夹,Object []参数,CultureInfo文化)
在System.Reflection.MethodBase.Invoke(对象obj,对象[]参数)
在 e:\sample\BDw.cs 中的 Download.BasicDownload.BasicFileDownload(Device device) 处:第 146 行