The following code was taken from the ASP.NET page class (using Reflector):
Public Custom Event InitComplete As EventHandler
AddHandler(ByVal value As EventHandler)
MyBase.Events.AddHandler(Page.EventInitComplete, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)
MyBase.Events.RemoveHandler(Page.EventInitComplete, value)
End RemoveHandler
End Event
Why is there no RAISE EVENT? The following article suggests there should be a RAISE EVENT: http://msdn.microsoft.com/en-us/library/ms184583%28v=vs.90%29.aspx. I would expect to see:
Public Custom Event InitComplete As EventHandler
AddHandler(ByVal value As EventHandler)
MyBase.Events.AddHandler(Page.EventInitComplete, value)
End AddHandler
RemoveHandler(ByVal value As EventHandler)
MyBase.Events.RemoveHandler(Page.EventInitComplete, value)
End RemoveHandler
Raise Event
End Raise Event
End Event
I realise this is probably a basic question, but I am new to custom events and it is proving to be more difficult than I anticipated.
As I wrote in my answer to your previous question: this indicates that
Pagewasn’t written in VB..NET events don’t have to have “raise” accessors. C# doesn’t even have any syntax to let you specify a raise accessor.
VB, however, does make it a requirement of custom events. That’s fine – any code generated from VB with a custom event will have a raise accessor. VB can’t force its requirements onto other languages though – so any code which has an event without a raise access has no direct equivalent in VB.
Leave events out of things for a minute – suppose someone invented a new language called Humbug, which compiled to IL. It would be feasible for Humbug to specify that properties had to always have a getter and a setter. You couldn’t write a property with only a getter or only a setter. It’s fine for that to target IL, although the language would have to interoperate with code which only specified one part of a property. Any code in VB or C# which had a read-only (or write-only, though that’s rare) event would simply not be representable in Humbug.
If you can get your head round that, just apply the same logic to events and the raise accessor.