[英]Func delegate used as a parameter
I am trying to understand what the code below actually does. 我试图了解下面的代码实际上是做什么的。
We have Submit
method that returns void
and takes two arguments: 我们有
Submit
方法,该方法返回void
并接受两个参数:
Then we call Submit
method with arguments. 然后我们使用参数调用
Submit
方法。
This part of code I do not understand. 这部分代码我听不懂。
void Submit(Delegate d, params object[] arguments)
{
ServiceQueue.Get.Submit(d, arguments);
}
Submit(new Func<BusinessMetadataQueryDataContract,
AsyncCallback,
object,
IAsyncResult>(
this.Channel.BeginBusinessMetadataGet),
contract,
new AsyncCallback(
(iar) =>
{
BusinessMetadataDataContract outContract = null;
Action<Exception, OpusReturnType> response =
(e, ort) =>
{
SilverlightClient.UIThread.Run(() =>
{
this.BusinessMetadataGetActionCompleted(this,
new ActionCompletedEventArgs<BusinessMetadataDataContract>(
ort,
outContract,
e,
false,
asyncState));
});
};
try
{
response(null,
this.Channel.EndBusinessMetadataGet(
out outContract,
iar));
}
catch (Exception e)
{
response(e,
new OpusReturnType());
}
}),
asyncState);
Func
method takes three arguments and returns value. Func
方法采用三个参数并返回值。
So we have arguments of type: 因此,我们有以下类型的参数:
and we have return type: 我们有返回类型:
Then we have: (this.Channel.BeginBusinessMetadataGet),
然后我们有:
(this.Channel.BeginBusinessMetadataGet),
I do not understand it. 我不明白。 What is it doing here?
这是在做什么 I was expecting an opening bracket
(
and a first parameter of type BusinessMetadataQueryDataContract
, instead I get (this.Channel.BeginBusinessMetadataGet)
and expected parameter is positioned on the second position. 我期待一个开括号
(
和类型为BusinessMetadataQueryDataContract
的第一个参数,相反,我得到(this.Channel.BeginBusinessMetadataGet)
并且预期的参数位于第二个位置。
I must be missing something here. 我一定在这里想念什么。
Any help? 有什么帮助吗? Thank you!
谢谢!
this.Channel.BeginBusinessMetadataGet is the actual delegate, which have the signature that you describe. this.Channel.BeginBusinessMetadataGet是实际的委托,具有您描述的签名。 So the first argument (Delegate d) is this:
因此,第一个参数(Delegate d)是这样的:
new Func<BusinessMetadataQueryDataContract,
AsyncCallback,
object,
IAsyncResult>(
this.Channel.BeginBusinessMetadataGet)
this creates a delegate from the method BeginBusinessMetadataGet. 这从BeginBusinessMetadataGet方法创建一个委托。 After this are all the parameters that will be used by the delegate.
在这之后是委托将使用的所有参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.