S
Simon
Hi all,
I am writing a windows application using vb.net on the 1.1 framework.
We have in the application, some strongly typed collections that have been
written as classes that do not inherit from collection base, but use an
internal collection, to hold the objects and then implement IEnumerator, see
example below,
Public Class AttributeCollection
Implements IEnumerable
Protected intCollection As New Collection
Public Overridable Sub Add(ByVal Attr As Attribute)
intCollection.Add(Attr, Attr.Name)
End Sub
Public Sub Remove(ByVal Attr As Attribute)
intCollection.Remove(Attr.Name)
End Sub
Public Sub Remove(ByVal AttrName As String)
intCollection.Remove(AttrName)
End Sub
Public Function Count() As Integer
Return intCollection.Count
End Function
Default ReadOnly Property Item(ByVal AttrName As String) As Attribute
Get
Return CType(intCollection.Item(AttrName), Attribute)
End Get
End Property
Default ReadOnly Property Item(ByVal index As Integer) As Attribute
Get
Return CType(intCollection.Item(index), Attribute)
End Get
End Property
Public Function GetEnumerator() As System.Collections.IEnumerator
Implements System.Collections.IEnumerable.GetEnumerator
Return intCollection.GetEnumerator
End Function
End Class
These collection allow us to do a for each loop down the collection,
For each attr as Attribute in someAttrCollection
.... code
Next
However, we are having problems with this type of collection so are moving
to inheriting our strongly typed collections from collectionbase. However
collectionbase does not use Key Value pairs. We have tried inheriting from
DictionaryBase, but that then stops all the for next loops from working as
the items it returns are dictionary entries, not the internal objects we
wish to get.
I know if we inherit from DictionaryBase we can change to a
For each attr as Attribute in someAttrCollection.Values
but there are 10's of thousands of lines of code, and we would prefer not to
have to change our for next loops if possible.
So the question, how do we create a strongly typed key value pair collection
that allows a for next down the created collection returning the objects
contained in the value part?
How the question is understood.
Thanks in advance for any help or advice.
Regards,
Simon.
I am writing a windows application using vb.net on the 1.1 framework.
We have in the application, some strongly typed collections that have been
written as classes that do not inherit from collection base, but use an
internal collection, to hold the objects and then implement IEnumerator, see
example below,
Public Class AttributeCollection
Implements IEnumerable
Protected intCollection As New Collection
Public Overridable Sub Add(ByVal Attr As Attribute)
intCollection.Add(Attr, Attr.Name)
End Sub
Public Sub Remove(ByVal Attr As Attribute)
intCollection.Remove(Attr.Name)
End Sub
Public Sub Remove(ByVal AttrName As String)
intCollection.Remove(AttrName)
End Sub
Public Function Count() As Integer
Return intCollection.Count
End Function
Default ReadOnly Property Item(ByVal AttrName As String) As Attribute
Get
Return CType(intCollection.Item(AttrName), Attribute)
End Get
End Property
Default ReadOnly Property Item(ByVal index As Integer) As Attribute
Get
Return CType(intCollection.Item(index), Attribute)
End Get
End Property
Public Function GetEnumerator() As System.Collections.IEnumerator
Implements System.Collections.IEnumerable.GetEnumerator
Return intCollection.GetEnumerator
End Function
End Class
These collection allow us to do a for each loop down the collection,
For each attr as Attribute in someAttrCollection
.... code
Next
However, we are having problems with this type of collection so are moving
to inheriting our strongly typed collections from collectionbase. However
collectionbase does not use Key Value pairs. We have tried inheriting from
DictionaryBase, but that then stops all the for next loops from working as
the items it returns are dictionary entries, not the internal objects we
wish to get.
I know if we inherit from DictionaryBase we can change to a
For each attr as Attribute in someAttrCollection.Values
but there are 10's of thousands of lines of code, and we would prefer not to
have to change our for next loops if possible.
So the question, how do we create a strongly typed key value pair collection
that allows a for next down the created collection returning the objects
contained in the value part?
How the question is understood.
Thanks in advance for any help or advice.
Regards,
Simon.