mardi 17 novembre 2015

Calling method with generic type using class name as string

Having this class :

class ClassA{
}

and a method with this signature:

void MyMethod<T>();

All we use it on this way:

MyMethod<ClassA>();

But... exist some chance of call MyMethod having the class name as string?. I.e.:

var className = "ClassA";

MagicMethod($"MyMethod<{className}>();");

Im talking about some equivalent of Eval in JavaScript. Reflection?, Any idea?

I googled some libraries like DynamicExpresso but nothing with support for generic types.

About possible duplicates:





Aucun commentaire:

Enregistrer un commentaire