Code translation VB to C# in a Sync Framework 2.1 sample

278 views Asked by At

I followed a walkthrough of a sync framework 2.1 sample and it works fine. But it's written in C# and I want to port it to VB. I came to the following line which I have had a hard time translating:

in the static Main of c#:

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

later on there is a handler written as:

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

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

how should I translate the first line to VB?

I tried the auto translators which give me two results (both fail to compile)

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

and

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

There are 1 answers

0
Ben Quan On

Finally got it to work with:

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