List of objects inheriting a generic class?

You could do with just a simple empty manager interface to create the list and intersections based on the OfType extension method, like this public interface IGenericManager { } public class GenericManager : IGenericManager where T : Updateable { } public class EntityManager : GenericManager { } var list = new List(); var entityManagers = list.OfType().

Declare IGenericManager interface, let GenericManager : IGenericManager and you can use List. The only drawback is that the methods exposed cannot be generic. UPDATE: interface IGenericManager { Type ManagerType { get; } } GenericManager : IGenericManager { public Type ManagerType { get { return typeof(T) ; } } }.

Lets say I am searching for my entitymanager in my list of managers. Would there be a way to distinguish which object is which? – Prodigga Nov 1 at 13:45 Updated answer - you can now do (pseudo-code): List().

Single(x => x. ManagerType == myType) – Jakub Konecki Nov 1 at 13:48 3 how about List().OfType()? – mtijn Nov 1 at 14:03 @mtijn - that's good!

– Jakub Konecki Nov 1 at 14:05 That is good :) – Prodigga Nov 1 at 14:20.

You can extract generic interface for you base generic manager and make it covariant: public class GenericManager :IGenericManager where T : Updatable { } public interface IGenericManager where T : Updatable { } public class Updatable { } class UpdatableX : Updatable {} class UpdatableY : Updatable {} After that you'll be able to put all your stuff into the List>: var list = new List> {new GenericManager(), new GenericManager()}; UPDATE: Forgot to mention, it's possible only in . NET framework 4, because in previous versions generics couldn't be covariant or contravariant.

Must do some poking around but will get back to this shortly..think this is more what I am after, even though Jakub's solution was nice. – Prodigga Nov 1 at 13:59 is the interface really necessary? Why not directly apply covariance to the template argument of GenericManager?

– mtijn Nov 2 at 8:36 It is. You can't use variant parameters in a class, only in interface or delegate. – invisible Nov 2 at 10:01.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions