如何从VB.NET中的事件中获取实际的EventHandler委托实例?

Dan*_*Tao 5 .net c# vb.net events event-handling

在C#中,我可以这样做:

EventHandler handler = this.SomeEvent;
Run Code Online (Sandbox Code Playgroud)

......这会让我做,例如,做:

Delegate[] attachedHandlers = handler.GetInvocationList();
Run Code Online (Sandbox Code Playgroud)

在VB.NET中,我似乎无法弄清楚如何做类似的事情.

这不起作用:

Dim handler As EventHandler = Me.SomeEvent
Run Code Online (Sandbox Code Playgroud)

...由于以下错误:

公共事件SomeEvent(sender As Object,e As EventArgs)'是一个事件,不能直接调用.使用'RaiseEvent'语句来引发事件.

但这也不起作用:

Dim handler As EventHandler = AddressOf Me.SomeEvent
Run Code Online (Sandbox Code Playgroud)

...因为:

'AddressOf'操作数必须是方法的名称(没有括号).

那么我怎样才能真正EventHandler从VB.NET中获取一个事件呢?立刻浮现在脑海中的唯一想法是使用反射,但这看起来非常荒谬.

Tim*_*ter 6

   Private Event MyEvent()
   Private delegates() As System.Delegate = MyEventEvent.GetInvocationList()
Run Code Online (Sandbox Code Playgroud)

没有证件,在这里找到