委托System.Action <dynamic,int>不需要`1&#39;参数</动态的,int>的

时间:2014-11-21 18:53:19

标签: c# entity-framework postgresql lambda mono

我正在尝试在Mono上构建来自this repositoryPostgreSqlGeneration代码。不幸的是我收到了一个我不明白的错误。

PostgreSqlMigrationSqlGenerator类中,以下方法给出了构建错误&#34;委托System.Action不会使用`1&#39;参数&#34;:

private void GenerateStatements(IEnumerable<MigrationOperation> migrationOperations)
{

    Check.NotNull(migrationOperations, "migrationOperations");
    DetectHistoryRebuild(migrationOperations).Each<dynamic>(o => Generate(o)); // <=here!

}

/ edit扩展方法的签名如下:

Signatures and error

/ edit 2.以下是Generate方法的声明:

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表达式。要了解更多信息并使迁移工作,我希望有人能够解释错误发生的原因以及如何解决错误。

2 个答案:

答案 0 :(得分:1)

免责声明:我觉得非常糟糕,我找不到任何来解释为什么这不起作用。如果有人知道;请告诉我。谷歌在这里失败了。

显然,编译器为Each选择了错误的重载。库中有两个,一个采用Action<T>,另一个采用Action<T, int>

如果你没有使用dynamic,它会正常工作(如果我不得不猜);但是dynamic引起了各种各样奇怪的问题; plus 您使用的是Mono。

由于编译器坚持使用其他重载,因此解决方案非常简单。只需使用它!

DetectHistoryRebuild(migrationOperations).Each<dynamic>((o, i) => Generate(o));

您使用了额外的参数并且没有使用它。它不是世界末日。

你也可以只显式实例化Action,这样编译器就不必选择:

DetectHistoryRebuild(migrationOperations).Each<dynamic>(new Action(o => Generate(o)));

答案 1 :(得分:0)

解决方案是添加Microsoft.Csharp.dll的缺失程序集引用。由于某些原因,在将Bradda签名从i更改为(i,j)之后,缺少的程序集引用的错误变得可见,如BradleyDotNET在其答案中所建议的那样。