我有以下属性:
public Func<EntityKey, string, Task<IList<MyProperty>>> RequestHandler { get; private set; }我在我的类上也有一个构造函数,看起来像这样:
public RequestHandlerTasks(Func<EntityKey, string, IList<MyProperty>> handler)如何操作传递给构造函数的“处理程序”,以便将其存储在“RequestHandler”属性中?
如果您还没有注意到它,那么构造函数使用“IList”,而属性需要一个IList的任务。
发布于 2012-05-09 21:47:48
它仍然不清楚语义是什么,但它可以像这样简单:
public RequestHandlerTasks(Func<EntityKey, string, IList<MyProperty>> handler)
{
// Whenever the RequestHandler delegate is called, it will start a new task.
RequestHandler = (arg1, arg2) =>
Task.Factory.StartNew(() => handler(arg1, arg2));
}这将会编译--它是否做你想要的是另一回事……
https://stackoverflow.com/questions/10517215
复制相似问题