委托System.Action< dynamic,int>不接受"1"参数 [英] Delegate System.Action<dynamic,int> does not take `1' arguments
问题描述
我正在尝试从此存储库构建 PostgreSqlGeneration
代码在单声道上.不幸的是,我收到一个我不明白的错误.
I am trying to build the PostgreSqlGeneration
code from this repository on Mono. Unfortunately I get an error I do not understand.
在 PostgreSqlMigrationSqlGenerator 中类中,以下方法给出了构建错误委托System.Action不带'1'参数":
In the PostgreSqlMigrationSqlGenerator class the following method gives the build error "delegate System.Action does not take `1' arguments":
private void GenerateStatements(IEnumerable<MigrationOperation> migrationOperations)
{
Check.NotNull(migrationOperations, "migrationOperations");
DetectHistoryRebuild(migrationOperations).Each<dynamic>(o => Generate(o)); // <=here!
}
/edit扩展方法的签名如下:
/edit The signature of the extension method is as follows:
/edit 2.这是 Generate
方法的声明:
/edit 2. Here is the declaration for Generate
method:
private void Generate(HistoryOperation migration)
{
//migration
Check.NotNull(migration, "historyOperation");
using (var writer = Writer())
{
migration.CommandTrees.Each(
commandTree =>
{
switch (commandTree.CommandTreeKind)
{
case DbCommandTreeKind.Insert:
writer.Write(GetInsertHistorySql((DbInsertCommandTree)commandTree));
break;
}
});
Statement(writer);
}
}
我不知道为什么会这样,因为 Each
仅具有 dynamic
类型,没有整数.但是我对这种lambda表达式的经验并不丰富.为了了解更多信息并使迁移工作,我希望有人可以解释为什么会发生错误以及如何解决该错误.
I do not know why that happens since the Each
only has a dynamic
type and no integer one. But I am not that experienced with such lambda expressions. To learn more and to get the migrations to work I hope someone can explain why the error happens and how it can be fixed.
推荐答案
免责声明:我真的很遗憾,找不到任何能解释为何此操作无效的任何内容.如果有人知道请告诉我.Google在这里失败了.
Disclaimer: I feel really bad that I cannot find anything that explains why this isn't working. If someone knows; please tell me. Google has failed here.
很显然,编译器为 Each
选择了错误的重载.库中有两种,一种采用 Action< T>
,另一种采用 Action< T,int>
.
Clearly the compiler is picking the wrong overload for Each
. There are two in the library, one that takes an Action<T>
and another that takes an Action<T, int>
.
如果您不使用 dynamic
,它会很好地工作(如果我不得不猜测的话);但是 dynamic
会引起各种奇怪的问题; plus 您正在使用Mono.
If you weren't using dynamic
it would work fine (if I had to guess); but dynamic
causes all sorts of weird issues; plus you are using Mono.
由于编译器坚持要求您使用其他重载,因此该解决方案非常简单.只需使用它!
Since the compiler insists you use the other overload, the solution is simple enough. Just use it!
DetectHistoryRebuild(migrationOperations).Each<dynamic>((o, i) => Generate(o));
您使用了一个额外的参数,并且没有使用它.这不是世界末日.
You took an extra parameter and didn't use it. Its not the end of the world.
您还可以显式实例化 Action
,这样编译器就不必选择:
You could also just explicitly instantiate the Action
so the compiler doesn't have to choose:
DetectHistoryRebuild(migrationOperations).Each<dynamic>(new Action(o => Generate(o)));
这篇关于委托System.Action< dynamic,int>不接受"1"参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!