I've seen very little on the topic of testing event handlers for null as in C# other than one time reading that I need to add Event to the Event. Why then does this not work. AnyEventEvent is always nothing.
Heres a the test code.
Public Class Form1
Public Event AnyEvent As AnyEventHandler
Public Delegate Sub AnyEventHandler(ByVal sender As Object, ByVal e As AnyEventArgs)
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
If Not AnyEventEvent Is Nothing Then
AnyEventEvent(Me, New AnyEventArgs(0, 0, 0))
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
Public Class AnyEventArgs
Private m_One As Integer
Private m_Two As Integer
Private m_Three As Integer
Public ReadOnly Property One() As Integer
Get
Return m_One
End Get
End Property
Public ReadOnly Property Two() As Integer
Get
Return m_Two
End Get
End Property
Public ReadOnly Property Three() As Integer
Get
Return m_Three
End Get
End Property
Public Sub New(ByVal _One As Integer, ByVal _Two As Integer, ByVal _Three As Integer)
m_One = _One
m_Two = _Two
m_Three = _Three
End Sub
End Class
Heres a the test code.
Public Class Form1
Public Event AnyEvent As AnyEventHandler
Public Delegate Sub AnyEventHandler(ByVal sender As Object, ByVal e As AnyEventArgs)
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
If Not AnyEventEvent Is Nothing Then
AnyEventEvent(Me, New AnyEventArgs(0, 0, 0))
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
Public Class AnyEventArgs
Private m_One As Integer
Private m_Two As Integer
Private m_Three As Integer
Public ReadOnly Property One() As Integer
Get
Return m_One
End Get
End Property
Public ReadOnly Property Two() As Integer
Get
Return m_Two
End Get
End Property
Public ReadOnly Property Three() As Integer
Get
Return m_Three
End Get
End Property
Public Sub New(ByVal _One As Integer, ByVal _Two As Integer, ByVal _Three As Integer)
m_One = _One
m_Two = _Two
m_Three = _Three
End Sub
End Class