Sync Framework 2.1示例中的代码转换VB到C#

时间:2015-06-16 02:25:12

标签: c# vb.net microsoft-sync-framework code-translation

我跟着一个同步框架2.1示例的演练,它工作正常。但它是用C#编写的,我想把它移植到VB。我来到以下一行,我很难翻译:

在c#的静态Main中:

((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);

稍后会有一个处理程序写为:

 static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)
    {
        // display conflict type
        Console.WriteLine(e.Conflict.Type);

        // display error message 
        Console.WriteLine(e.Error);
    }

我应该如何将第一行翻译成VB?

我尝试了自动翻译器,它给了我两个结果(都无法编译)

AddHandler CType(syncOrchestrator.LocalProvider,SqlSyncProvider).ApplyChangeFailed, AddressOf Me.Program_ApplyChangeFailed

DirectCast(syncOrchestrator.LocalProvider, SqlSyncProvider).ApplyChangeFailed += New EventHandler(Of DbApplyChangeFailedEventArgs)(Program_ApplyChangeFailed)

1 个答案:

答案 0 :(得分:0)

最后得到了它:

AddHandler CType(syncOrchestrator.LocalProvider, SqlSyncProvider).ApplyChangeFailed, AddressOf Program_ApplyChangeFailed