views:

202

answers:

1

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

+3  A: 

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
JaredPar
Could you please expand your answer with code sample? (I will select you as a winner :)
Prankster
When you say "we" in your answer: was that a discussion you were part of or are you quoting something? If you're quoting, can you give a reference?
Joel Coehoorn
@Joel, by "we" I meant the VS Languages team. This recently came up in the context of another internal question and I had a conversation with the compiler team about the issue.
JaredPar
Sorry, I am a little slow today. And AddEvent1 should call AddHandler of the Event1 ? Isn't like, er.., endless loop?
Prankster
@prankster, what this does is allow the derived class to customize the behavior of adding and removing events. They can chose to use a plain old variable or a dynamic storage mechanism or whatever. The example would have been clearer if i made it abstract (updated)
JaredPar