本文介绍了如何使用 out 参数调用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想公开 WebClient.DownloadDataInternal 方法,如下所示:
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 有一个 out 参数,我不知道如何调用它.帮助!
WebClient.DownloadDataInternal has a out parameter, I don't know how to invoke it.Help!
推荐答案
public class MyWebClient : WebClient
{
delegate byte[] DownloadDataInternal(Uri address, out WebRequest request);
DownloadDataInternal downloadDataInternal;
public MyWebClient()
{
downloadDataInternal = (DownloadDataInternal)Delegate.CreateDelegate(
typeof(DownloadDataInternal),
this,
typeof(WebClient).GetMethod(
"DownloadDataInternal",
BindingFlags.NonPublic | BindingFlags.Instance));
}
public byte[] DownloadDataInternal(Uri address, out WebRequest request)
{
return downloadDataInternal(address, out request);
}
}
这篇关于如何使用 out 参数调用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!