【发布时间】:2020-06-22 12:51:43
【问题描述】:
我正在尝试修复一些从公共存储库中克隆的代码。这是一个缺少await 运算符的async 方法:
public async Task<IEnumerable<JsonPatchOperation>> GetRemoveAllRelationsOperations(IBatchMigrationContext batchContext, WorkItem targetWorkItem)
{
return targetWorkItem.Relations?.Select((r, index) => MigrationHelpers.GetRelationRemoveOperation(index));
}
我正在尝试这个:
public async Task<IEnumerable<JsonPatchOperation>> GetRemoveAllRelationsOperations(IBatchMigrationContext batchContext, WorkItem targetWorkItem)
{
return await Task.Run(o => targetWorkItem.Relations?.Select((r, index) => MigrationHelpers.GetRelationRemoveOperation(index)));
}
...但我在 IDE 中遇到错误:
委托 'Action' 不接受 1 个参数
我发现了一些类似的讨论,但不幸的是,它们都没有完全解决 lambda 语法:
- Delegate System.Action does not take 1 arguments
- Delegate System.Action<dynamic,int> does not take `1' arguments
- Delegate `System.Func<bool>' does not take `1' arguments
- Delegate Action does not take 3 arguments
似乎预编译器将输入解释为Action,而它应该将其视为Func。但我认为声明o => ... 可以表明两者之一。
我对 C# 不够熟悉,无法解决这个问题。有人可以帮忙吗?
如何告诉预编译器我要发送Func 而不是Action?
【问题讨论】:
标签: c# async-await action func