vb.netevents

Does VB.NET support virtual events?


In continuation of this question. Does VB.NET supports virtual events?


Solution

  • Does VB support the CLR notion of a virtual event

    No. This is something we've looked into supporting but did not meet our current bar in the given language cycle.

    Does VB support the idea of a hierarchy which customizes events

    Yes. You can use the Custom event syntax to allow for hierarchy controlled eventing.

    MustInherit Class Base
        Public Custom Event Event1 As EventHandler
            AddHandler(ByVal value As EventHandler)
                AddEvent1(value)
            End AddHandler
    
            RemoveHandler(ByVal value As EventHandler)
                RemoveEvent1(value)
            End RemoveHandler
    
            RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs)
                RaiseEvent1(sender, e)
            End RaiseEvent
    
        End Event
    
        Protected MustOverride Sub AddEvent1(ByVal value As EventHandler)
        Protected MustOverride Sub RemoveEvent1(ByVal value As EventHandler)
        Protected MustOverride Sub RaiseEvent1(ByVal sender As Object, ByVal e As EventArgs)
    
    End Class