lundi 30 mars 2015

C# Get generic type from string

I have 3 types all from diferent dlls y can't find how to store in a string the generic type and how to create the instance:



Type type1 = GetType1();
Type type2 = GetType2();
string strClassGenericType = "Namespace.ClassName<,>, DllName";

Type template = // How to get the generic template type?

Type genericType = template.MakeGenericType(new[] { type1, type2 });
object instance = Activator.CreateInstance(genericType);


Im not sure if this fits to my requeriment.






Aucun commentaire:

Enregistrer un commentaire