gpt4 book ai didi

c# - 如何从 VB.NET 中的事件中获取实际的 EventHandler 委托(delegate)实例?

转载 作者:太空狗 更新时间:2023-10-29 23:11:06 25 4
gpt4 key购买 nike

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

EventHandler handler = this.SomeEvent;

...这将允许我,例如,做:

Delegate[] attachedHandlers = handler.GetInvocationList();

在 VB.NET 中,我似乎不知道如何做类似的事情。

这行不通:

Dim handler As EventHandler = Me.SomeEvent

...由于以下错误:

Public Event SomeEvent(sender As Object, e As EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

但这也不起作用:

Dim handler As EventHandler = AddressOf Me.SomeEvent

...因为:

'AddressOf' operand must be the name of a method (without parentheses).

那么我怎样才能从 VB.NET 中的事件中实际获取 EventHandler 呢?立即想到的唯一想法是使用反射,但这似乎很荒谬。

最佳答案

   Private Event MyEvent()
Private delegates() As System.Delegate = MyEventEvent.GetInvocationList()

未记录,已找到 here

关于c# - 如何从 VB.NET 中的事件中获取实际的 EventHandler 委托(delegate)实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4108163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com