List (Of T) & HashSet (Of T) Provides Notifications When Items Added or Removed
Public Class ObservableList(Of T) Inherits List(Of T) #Region " Constructor " Public Sub New() End Sub #End Region #Region " Property " Public ReadOnly Property InnerList As IEnumerable(Of T) Get Return
MyBase.ToList.AsReadOnly End Get End Property #End Region #Region " Method " Public Overloads Sub Add(item As T) If Not Me.InnerList.Contains(item) Then MyBase.Add(item) Me.OnChanged(item,
ObservableChangeAction.Add) End If End Sub Public Overloads Sub Remove(item As T) If Me.InnerList.Contains(item) Then MyBase.Remove(item) Me.OnChanged(item,
ObservableChangeAction.Remove) End If End Sub Protected Sub OnChanged(item As T, action As
ObservableChangeAction) RaiseEvent Changed(Me, New
ObservableEventArgs(CType(item, Object), action)) End Sub #End Region #Region " Event " Public Event Changed As EventHandler(Of
ObservableEventArgs) #End Region End Class ' ObservableList(Of T( |
Public Class ObservableHashSet(Of T) Inherits HashSet(Of T) #Region " Constructor " Public Sub New() End Sub #End Region #Region " Property " Public ReadOnly Property InnerList As IEnumerable(Of T) Get Return
MyBase.ToList.AsReadOnly End Get End Property #End Region #Region " Method " Public Overloads Sub Add(item As T) If MyBase.Add(item) Then Me.OnChanged(item,
ObservableChangeAction.Add) End If End Sub Public Overloads Sub Remove(item As T) If MyBase.Remove(item) Then Me.OnChanged(item, ObservableChangeAction.Remove) End If End Sub Protected Sub OnChanged(item As T, action As
ObservableChangeAction) RaiseEvent Changed(Me, New
ObservableEventArgs(CType(item, Object), action)) End Sub #End Region #Region " Event " Public Event Changed As EventHandler(Of
ObservableEventArgs) #End Region End Class ' ObservableHashSet(Of T( |
Public Class ObservableEventArgs Inherits EventArgs Public Sub New(item As Object, changeAction As
ObservableChangeAction) Me.Item = item Me.ChangeAction = changeAction End Sub Public Property Item As Object Public Property ChangeAction As ObservableChangeAction End Class ' ObservableEventArgs |
Public Enum ObservableChangeAction Add Remove End Enum |
Comments
Post a Comment