is this possible: c# collection of Type with constrains, or collection of generic type?

Posted by Jon on Stack Overflow See other posts from Stack Overflow or by Jon
Published on 2010-06-03T20:06:43Z Indexed on 2010/06/03 20:14 UTC
Read the original article Hit count: 137

Filed under:
|
|

I'm trying to store types in a collection, so that i can later instantiate objects of the types in the collection. But I'm not sure how to do this the best way.

What i have so far:

List<Type> list = new List<Type>();
list.Add(typeof(MyClass));
var obj = (MyClass)Activator.CreateInstance(list[0]);

I would like to have some constrains on the Type, or better yet, just a generic type in the collection instead of an instantiated Type object. Is this possible?

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics