vendredi 11 décembre 2015

Calling generic ambiguous method using string with qualified name of a class

Assuming that I have a third party class Foo with a signature like this:

void Execute<T>();
void Execute(string[] args);

Instead of calling

Execute<Bar>();

I need to use the qualified name of the Bar classe to invoke the generic method. Example:

Type barType = Type.GetType("Program.Bar");
Execute<barType>();

I've already tried some answers I found on other threads but all of them gave me issues. For instance, I can't use the GetMethod("Execute") since it throws an ambiguous excpetion.





Aucun commentaire:

Enregistrer un commentaire