I'm developing a class library to be used for other developers and will be allowing them to either declare an instance of my class using WithEvents (or similar in other languages) as well as allow them to use Delegates defined in the class. Am I just being redundant here by doing it like this?
Public Delegate Sub TimerElapsedDelegate(ByVal sender As Object, ByVal e As System.EventArgs)
Public Event TimerElapsed(ByVal sender As Object, ByVal e As System.EventArgs)
Private _TimerElapsed As TimerElapsedDelegate = Nothing
Or should I just declare the events and let them do the AddHandler, etc., ?
Thanks for any advice on this ... I think I'm being redundant and don't want pointless code, not to mention avoiding the DRY principle.
{edit}Just wanted to post the remainder of the code, and stress that the "work" an instance of this class performs is done on a separate thread.{/edit}
#Region "Delegates"
Public Delegate Sub TimerElapsedDelegate(ByVal sender As Object, ByVal e As System.EventArgs)
Public Event TimerElapsed(ByVal sender As Object, ByVal e As System.EventArgs)
Private _TimerElapsed As TimerElapsedDelegate = Nothing
Public Property OnTimerElapsed() As TimerElapsedDelegate
Get
Return _TimerElapsed
End Get
Set(ByVal value As TimerElapsedDelegate)
If value Is Nothing Then
_TimerElapsed = Nothing
Else
If _TimerElapsed Is Nothing Then
_TimerElapsed = value
Else
_TimerElapsed = System.Delegate.Combine(_TimerElapsed, value)
End If
End If
End Set
End Property
Private Sub TriggerTimerElapsed()
If OnTimerElapsed IsNot Nothing Then
OnTimerElapsed.Invoke(Me, New System.EventArgs)
End If
RaiseEvent TimerElapsed(Me, New System.EventArgs)
End Sub
Public Delegate Sub ItemReadyForQueueDelegate(ByVal sender As Object, ByVal e As System.EventArgs)
Public Event ItemReadyForQueue(ByVal sender As Object, ByVal e As System.EventArgs)
Private _ItemReadyForQueue As ItemReadyForQueueDelegate = Nothing
Public Property OnItemReadyForQueue() As ItemReadyForQueueDelegate
Get
Return _ItemReadyForQueue
End Get
Set(ByVal value As ItemReadyForQueueDelegate)
If value Is Nothing Then
_ItemReadyForQueue = Nothing
Else
If _ItemReadyForQueue Is Nothing Then
_ItemReadyForQueue = value
Else
_ItemReadyForQueue = System.Delegate.Combine(_ItemReadyForQueue, value)
End If
End If
End Set
End Property
Private Sub TriggerItemReadyForQueue(ByVal oItem As h3Budgeteer.FileSystem.ReportTemplateFile.ReportTemplate)
If OnItemReadyForQueue IsNot Nothing Then
OnItemReadyForQueue.Invoke(Me, New ItemReadyForQueueEventArgs(oItem))
End If
RaiseEvent ItemReadyForQueue(Me, New ItemReadyForQueueEventArgs(oItem))
End Sub
Public Class ItemReadyForQueueEventArgs
Inherits System.EventArgs
Private _ReportTemplate As h3Budgeteer.FileSystem.ReportTemplateFile.ReportTemplate = Nothing
Public ReadOnly Property ReportTemplate() As h3Budgeteer.FileSystem.ReportTemplateFile.ReportTemplate
Get
Return _ReportTemplate
End Get
End Property
Public Sub New(ByVal oReportTemplate As h3Budgeteer.FileSystem.ReportTemplateFile.ReportTemplate)
_ReportTemplate = oReportTemplate
End Sub
End Class