如何调用带有 out 参数的方法?
我想公开 WebClient.DownloadDataInternal 方法,如下所示:
[ComVisible(true)]
public class MyWebClient : WebClient
{
private MethodInfo _DownloadDataInternal;
public MyWebClient()
{
_DownloadDataInternal = typeof(WebClient).GetMethod("DownloadDataInternal", BindingFlags.NonPublic | BindingFlags.Instance);
}
public byte[] DownloadDataInternal(Uri address, out WebRequest request)
{
_DownloadDataInternal.Invoke(this, new object[] { address, out request });
}
}
WebClient.DownloadDataInternal 有一个 out 参数,我不知道如何调用它。 帮助!
I want expose WebClient.DownloadDataInternal method like below:
[ComVisible(true)]
public class MyWebClient : WebClient
{
private MethodInfo _DownloadDataInternal;
public MyWebClient()
{
_DownloadDataInternal = typeof(WebClient).GetMethod("DownloadDataInternal", BindingFlags.NonPublic | BindingFlags.Instance);
}
public byte[] DownloadDataInternal(Uri address, out WebRequest request)
{
_DownloadDataInternal.Invoke(this, new object[] { address, out request });
}
}
WebClient.DownloadDataInternal has a out parameter, I don't know how to invoke it.
Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以像任何其他方法一样通过反射调用带有 out 参数的方法。不同之处在于,返回的值将被复制回参数数组中,以便您可以从调用函数访问它。
You invoke a method with an out parameter via reflection just like any other method. The difference is that the returned value will be copied back into the parameter array so you can access it from the calling function.