I have read a number of other related questions, but still can't quite figure out how to do what we need to do. Use of generics isn't a must, but seems to be the only way we can potentially get what we need. We are in .net 3.5 so we can't use the new .net 4.0 stuff that I believe is related. Assume we have a base class Parent that has some properties and methods. We also have a ParentCollection which currently implements IEnumerable. We have also added additional properties and methods on this class as well.

We now need to inherit from Parent to create a ChildA. However we also need to Inherit from ParentCollection to create ChildACollection. We would then have peer classes to ChildA as ChildB and ChildBCollection.

The ChildACollection and ChildBCollection and their items are the only things that are actually instantiated. The Parent stuff is abstract.

There are methods on the ParentCollection as well as Parent that could return subsets of items that meet criteria and also might have been manipulated.

The issue is since these methods are working with items in the collection, we would like the collection returned to be of the type of the descendant. e.g. Call method SomeMethod() that is defined in ParentCollection through an instance of a ChildACollection so the subset return is of type List instead of a List.

Basically I want to take advantage of inheritence but not make the user of the ChildACollection have to constantly cast an object ref returned in the list to a ChildA object. I mean that the internal list will have actual ChildA objects and not Parent objects but since the method is in the ParentCollection class it only know that it is an object of Parent or descendant class. Hope this makes sense.

Help?

FOLLOW UP QUESTION :
I need to take this heirarchy 1 more level deep (Grandchild) and add a Add method on Parent that will create and Add the approprate object type to the list, i.e. if Add is called on a ChildCollection reference, it should create and add a type of Child and return a reference to that newly created object that is in the list. Possilbe?

protected List<Parent> _list = new List<Parent>(); you know you are already inhering from IEnumerable<Parent>, this is actually a list so you don't need a _list element to be part of the class.
–
Sergei GolosMar 23 '11 at 15:59

You may also consider inheriting from System.Collections.ObjectModel.Collection so you don't have to implement IEnumerable.

For the follow up:

My understanding is that you would like to have a parameterless method Add() on the parent collection which creates an instance of type T, adds it to the collection and returns it. One way to do this would be to add an additional constraint on T: