Thanks for the reply Ken,
I have read this article, and it seems to be similar to what we already do
with our collections, by implementing interfaces on a base class, and
handling the objects in the collection internally, as I have shown in the
example, in my first post.
The current way we create our collections, similar to the article, is
working as we want in the windows app, however we are having problems with
these internal type collections in the ASP.NET app that uses the same
objects, which we cannot fathom, I have several posts in the ASP.NET
newsgroup regarding this.
We have converted a few of them to be implicitly inherited from
collectionbase, and the problems seem to have abated, although we think it's
too soon to say the problems are solved.
There are some of these collections that need to be key value type
collections, and they are used in loads of places, that we do not want to
change the code. So I was kind of hoping there would be a way to inherit
from one of the base collections, and retain the key value relationship, but
be able to simply For each down the collection, not the collection.values.
Regards,
Simon.
"Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message
news:OPQRpcKLGHA.3492@TK2MSFTNGP09.phx.gbl...[color=blue]
> Hi,
>
> The code is in c# but I think this article will help.
>
http://www.codeproject.com/csharp/hashlistarticle.asp
>
> Ken
> --------------------
> "Simon" <s@v.c> wrote in message
> news:43e9c74c$0$6955$ed2619ec@ptn-nntp-reader02.plus.net...[color=green]
>> 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.
>>[/color]
>
>[/color]