|
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Runtime.CompilerServices
Namespace Common.Helpers
Public MustInherit Class CollectionWithEvents
Inherits CollectionBase
Private _suspendCount As Integer = 0
<Browsable(False)> _
Public Event Cleared As CollectionClear
<Browsable(False)> _
Public Event Clearing As CollectionClear
<Browsable(False)> _
Public Event Inserted As CollectionChange
<Browsable(False)> _
Public Event Inserting As CollectionChange
<Browsable(False)> _
Public Event Removed As CollectionChange
<Browsable(False)> _
Public Event Removing As CollectionChange
Protected Function IndexOf(ByVal value As Object) As Integer
Return MyBase.List.IndexOf(value)
End Function
Protected Overrides Sub OnClear()
If (Not Me.IsSuspended) AndAlso (Me.ClearingEvent IsNot Nothing) Then
RaiseEvent Clearing()
End If
End Sub
Protected Overrides Sub OnClearComplete()
If (Not Me.IsSuspended) AndAlso (Me.ClearedEvent IsNot Nothing) Then
RaiseEvent Cleared()
End If
End Sub
Protected Overrides Sub OnInsert(ByVal index As Integer, ByVal value As Object)
If (Not Me.IsSuspended) AndAlso (Me.InsertingEvent IsNot Nothing) Then
RaiseEvent Inserting(index, value)
End If
End Sub
Protected Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal value As Object)
If (Not Me.IsSuspended) AndAlso (Me.InsertedEvent IsNot Nothing) Then
RaiseEvent Inserted(index, value)
End If
End Sub
Protected Overrides Sub OnRemove(ByVal index As Integer, ByVal value As Object)
If (Not Me.IsSuspended) AndAlso (Me.RemovingEvent IsNot Nothing) Then
RaiseEvent Removing(index, value)
End If
End Sub
Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal value As Object)
If (Not Me.IsSuspended) AndAlso (Me.RemovedEvent IsNot Nothing) Then
RaiseEvent Removed(index, value)
End If
End Sub
Public Sub ResumeEvents()
Me._suspendCount -= 1
End Sub
Public Sub SuspendEvents()
Me._suspendCount += 1
End Sub
<Browsable(False)> _
Public ReadOnly Property IsSuspended() As Boolean
Get
Return (Me._suspendCount > 0)
End Get
End Property
End Class
End Namespace
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
MS, BBA, software developer, consultant, and trainer. Specializing in building data-centric applications designed for business, university, community & faith based organizations. Started developing Excel VBA macros and never looked back. Freelance developer utilizing VB.Net, SQL Server, Microsoft Access, and ASP.Net.