G
Guest
Hi,
I'm relatively new to VB.NET so I'd be grateful if someone could point out what I don't understand here...
1) Creating a strongly typed collection by inheriting CollectionBase.
This is covered in most of the books I've read. Basically you inherit CollectionBase and then add methods (say Add) that takes your types as a parameter and then calls List.Add from the base class. OK.
However CollectionBase exposes the IList interface as an explict interface. I want to be able to override the Add method in the IList interface. Why? Because if someone casts my collection to an IList, they can bypass my strongly typed implementation. (My implementation of IList.Add would check the type of the passed object and throw an exception if it was wrong).
If I try saying "Implements IList" in my subclass it's rejected since CollectionBase implements it. If I try to override or set my own method to Implement IList.Add then it's rejected because my subclass doesn't implement IList!!!
What have I missed? How can I override the implementation of the IList interface in my subclass
2) Creating a strongly typed collection using the Collection Object.
CollectionBase does not support the "key" type lookup for collections (like VB6 collections). In order to have a key-based collection I need to use the Collection object (I think).
I want to have a strongly typed collection by overriding the Collection object methods with my own typed methods. However, I can't inherit the Collection object since it's marked as NotInheritable.
So I have to implement my own class that "front-ends" the Collection object in the same way as was done in VB6.
Again, have I missed something? Is there a key-based collection class that I can inherit?
Thanks.
Ian Gore
I'm relatively new to VB.NET so I'd be grateful if someone could point out what I don't understand here...
1) Creating a strongly typed collection by inheriting CollectionBase.
This is covered in most of the books I've read. Basically you inherit CollectionBase and then add methods (say Add) that takes your types as a parameter and then calls List.Add from the base class. OK.
However CollectionBase exposes the IList interface as an explict interface. I want to be able to override the Add method in the IList interface. Why? Because if someone casts my collection to an IList, they can bypass my strongly typed implementation. (My implementation of IList.Add would check the type of the passed object and throw an exception if it was wrong).
If I try saying "Implements IList" in my subclass it's rejected since CollectionBase implements it. If I try to override or set my own method to Implement IList.Add then it's rejected because my subclass doesn't implement IList!!!
What have I missed? How can I override the implementation of the IList interface in my subclass
2) Creating a strongly typed collection using the Collection Object.
CollectionBase does not support the "key" type lookup for collections (like VB6 collections). In order to have a key-based collection I need to use the Collection object (I think).
I want to have a strongly typed collection by overriding the Collection object methods with my own typed methods. However, I can't inherit the Collection object since it's marked as NotInheritable.
So I have to implement my own class that "front-ends" the Collection object in the same way as was done in VB6.
Again, have I missed something? Is there a key-based collection class that I can inherit?
Thanks.
Ian Gore