Imports System.Collections.ObjectModel
Public Class PluginsCollection
Implements IList(Of IPlugin)
Dim _list As New List(Of IPlugin)
Dim _dict As New Dictionary(Of String, IPlugin)
Public Sub Add(item As IPlugin) Implements ICollection(Of IPlugin).Add
_list.Add(item)
End Sub
Public Sub Add(item As IPlugin, key As String)
_list.Add(item)
_dict.Add(key, item)
End Sub
Public Sub Clear() Implements ICollection(Of IPlugin).Clear
_list.Clear()
_dict.Clear()
End Sub
Public Function Contains(item As IPlugin) As Boolean Implements ICollection(Of IPlugin).Contains
Return _list.Contains(item)
End Function
Public Function ContainsKey(key As String) As Boolean
Return _dict.ContainsKey(key)
End Function
Public ReadOnly Property Count As Integer Implements ICollection(Of IPlugin).Count
Get
Return _list.Count
End Get
End Property
Public Function Remove(item As IPlugin) As Boolean Implements ICollection(Of IPlugin).Remove
Try
_list.Remove(item)
If _dict.ContainsValue(item) Then
_dict.Remove(_dict.FirstOrDefault(Function(x) x.Value Is item).Key)
End If
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Function Remove(key As String)
Try
Dim j = _dict.Item(key)
_list.Remove(j)
_dict.Remove(key)
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Function GetEnumerator() As IEnumerator(Of IPlugin) Implements IEnumerable(Of IPlugin).GetEnumerator
Return _list.GetEnumerator
End Function
Default Public Property Item(index As Integer) As IPlugin Implements IList(Of IPlugin).Item
Get
Try
Return _list(index)
Catch ex As Exception
Return Nothing
End Try
End Get
Set(value As IPlugin)
' do nothing
End Set
End Property
Default Public Property Item(key As String) As IPlugin
Get
If _dict.ContainsKey(key) Then
Return _dict(key)
Else
Return Nothing
End If
End Get
Set(value As IPlugin)
' do nothing
End Set
End Property
#Region "Unused code"
Private Sub RemoveAt(index As Integer) Implements IList(Of IPlugin).RemoveAt
'_list.RemoveAt(index)
End Sub
Private Sub CopyTo(array() As IPlugin, arrayIndex As Integer) Implements ICollection(Of IPlugin).CopyTo
'
End Sub
Private Function IndexOf(item As IPlugin) As Integer Implements IList(Of IPlugin).IndexOf
Return _list.IndexOf(item)
End Function
Private Sub Insert(index As Integer, item As IPlugin) Implements IList(Of IPlugin).Insert
'
End Sub
Private Function GetEnumerator1() As IEnumerator Implements IEnumerable.GetEnumerator
Return MyClass.GetEnumerator
End Function
Private ReadOnly Property IsReadOnly As Boolean Implements ICollection(Of IPlugin).IsReadOnly
Get
Return False
End Get
End Property
#End Region
End Class