代码之家  ›  专栏  ›  技术社区  ›  Dan Tao

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

  •  5
  • Dan Tao  · 技术社区  · 14 年前

    EventHandler handler = this.SomeEvent;
    

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

    Delegate[] attachedHandlers = handler.GetInvocationList();
    

    这不起作用:

    Dim handler As EventHandler = Me.SomeEvent
    

    …由于以下错误:

    Object,e As EventArgs)“是一个事件, 不能直接调用。使用 事件。

    但这也不管用:

    Dim handler As EventHandler = AddressOf Me.SomeEvent
    

    …因为:

    “AddressOf”操作数必须是方法的名称(不带括号)。

    EventHandler 从VB.NET中的一个事件?唯一一个马上想到的想法是使用反射,但这看起来很荒谬。

    2 回复  |  直到 14 年前
        1
  •  6
  •   Tim Schmelter    14 年前
       Private Event MyEvent()
       Private delegates() As System.Delegate = MyEventEvent.GetInvocationList()
    

    无证,发现 here

        2
  •  0
  •   Community CDub    8 年前

    How to Attach the Events of an Original Object to a Deep Copied Clone 我有一个关于如何通过反射获取事件委托的代码示例。据我所知,这是在VB中实现的唯一方法。