DictionaryBase - Get specific item
I have a Class that inherits DictionaryBase. The Dictionary is <Object,
DataSources>.
Given all Key, Value pairs, there should only be one CustomClass that has
a property of isPrimary. I want to create a property that returns the
Primary object and I can't seem to find the best way to approach this:
Public Class DataSources
Inherits DictionaryBase
Friend Sub New()
MyBase.New()
End Sub
Public Sub Add(ByVal Key As Object,
ByVal NewDataSource As DataSource)
Dictionary.Add(Key, NewDataSource)
End Sub
Default Public Property Item(ByVal Key As Object) As DataSource
Get
Return CType(Dictionary.Item(Key), DataSource)
End Get
Set(ByVal Value As DataSource)
Dictionary.Item(Key) = Value
End Set
End Property
Public Shadows Function GetEnumerator() As IEnumerator
Return Dictionary.Values.GetEnumerator
End Function
Public Sub Remove(ByVal Key As Object)
Dictionary.Remove(Key)
End Sub
End Class
I'd like to do two things:
1) Prevent 2 isPrimaries. Search the dictionary and throw an error if
isPrimary already exists and we try to insert another.
2) Get the Primary Value for the Dictionary.
I cant' seem to find good examples using DictionaryBase...
No comments:
Post a Comment