I am trying to structure some utility classes to work with collections of rather similar objects. The objects all inherit from one common base class, but of course that does me no good when dealing with collections of those objects. IOW, I can't simply cast a
List<BaseObject> to List<HigherLevelObject>.
Simplified code as illustration:
class BaseObject {
int X;
int Y;
}
class HigherLevelObject : BaseObject {
...
}
class AnotherHigherLevelObject : BaseObject {
}
// collections
class HigherLevelCollection : List<HigherLevelObject> {
}
class AnotherHigherLevelCollection : List<AnotherHigherLevelObject> {
}
So both of the collections above do have commonality in their base objects. Now suppose I wanted a generalized function that would operate on both collections. I can't just designate:
public void UtilityFunction(List<BaseObject> param) {
}
and pass in collections of either type above. Is there a simple approach to this?