lundi 22 mai 2017

C# Resolving a Type as generic type [duplicate]

This question already has an answer here:

I'm using reflection to dynamically create objects

var type = Type.GetType("Demo.Namespace.AnimalViewModel, Demo.Assembly", true);
var fooType = Type.GetType("Demo.Namespace.Foo, Demo.Assembly", true);
Activator.CreateInstance(type) as AnimalViewModel<fooType>;

Getting a compile error:

'fooType' is a variable but is used like a Type.

How can I set the type for AnimalViewModel , with the fooType variable? fooType -> Foo





Aucun commentaire:

Enregistrer un commentaire