2015-06-16 60 views
-2

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

在C#的静态主营:

((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) 
+0

哪一部分在谷歌的几十个C#到VB代码转换器未能为您翻译? – Mystra007

+0

这是我尝试的第一件事。它转换为:DirectCast(syncOrchestrator.LocalProvider,SqlSyncProvider).ApplyChangeFailed + =新的EventHandler(的DbApplyChangeFailedEventArgs)(Program_ApplyChangeFailed)但是,这给出了一个错误。 –

+0

错误是什么? AddHandler/AdressOf方法应该正常工作。 – Mystra007

回答

0

终于得到它一起工作:

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