我需要帮助将C#转换为Vb(使用EventHandlers)

时间:2021-05-24 00:08:01

i have my code :

我有我的代码:

client.NotifyClientEnterView += (source, notification) => Console.WriteLine("ClientEnterView {0}: {1}", notification.Clid, notification.ClientNickname);

And i want to translate it in VB.NET (it's not working with a translator when i enter it)

我想在VB.NET中翻译它(当我输入它时,它不能与翻译器一起工作)

I tryed AddHandler method, but it's not working (Beceause it's a eventhandler, not a event, like this : Addhandler client.NotifyClientEnterView, adressof <mysub>)

我尝试了AddHandler方法,但它不起作用(因为它是一个事件处理程序,而不是一个事件,如下所示:Addhandler client.NotifyClientEnterView,adressof

I need to translate that for execute a sub when a client enter in the channel (in teamspeak)

当客户端进入频道时,我需要将其转换为执行sub(在teamspeak中)

My library : https://github.com/Spksh/TentacleSoftware.TeamSpeakQuery

我的库:https://github.com/Spksh/TentacleSoftware.TeamSpeakQuery

Nota : client.NotifyClientEnterView as EVENTHANDLER, not a EVENT.

Nota:client.NotifyClientEnterView as EVENTHANDLER,而不是EVENT。

I hope you understand my problem, and thank for you help.

我希望你理解我的问题,谢谢你的帮助。

1 个解决方案

#1


0  

'AddressOf' is not used for the case of wiring a lambda to an event. So, approach the problem in 2 steps: 1. Use 'AddHandler' (as you already know) 2. Replace the C# lambda with a VB lambda using the following pattern replacement: '(..) => ..code..' -> 'Sub(..) ..code..'. e.g.,

'AddressOf'不用于将lambda连接到事件的情况。因此,分两步处理问题:1。使用'AddHandler'(正如您所知)2。使用以下模式替换将C#lambda替换为VB lambda:'(..)=> ..code ..' - >'Sub(..).. code ..'。例如。,

AddHandler client.NotifyClientEnterView, Sub(source, notification) Console.WriteLine("ClientEnterView {0}: {1}", notification.Clid, notification.ClientNickname)

#1


0  

'AddressOf' is not used for the case of wiring a lambda to an event. So, approach the problem in 2 steps: 1. Use 'AddHandler' (as you already know) 2. Replace the C# lambda with a VB lambda using the following pattern replacement: '(..) => ..code..' -> 'Sub(..) ..code..'. e.g.,

'AddressOf'不用于将lambda连接到事件的情况。因此,分两步处理问题:1。使用'AddHandler'(正如您所知)2。使用以下模式替换将C#lambda替换为VB lambda:'(..)=> ..code ..' - >'Sub(..).. code ..'。例如。,

AddHandler client.NotifyClientEnterView, Sub(source, notification) Console.WriteLine("ClientEnterView {0}: {1}", notification.Clid, notification.ClientNickname)