0

Let's say I have a method that looks like this:

public bool Execute<T>()
 {
 }

...and I have a string variable that describes the class name of the type I need to pass in, like

string typeName = "Person"

I've naively tried

var typeDef = Type.GetType(typeName);
 Execute<typeDef>();

, but that's a no-go. Is there a programatic way of passing in a generic type parameter when all I have is the class name in a string?

0

1 Answer 1

2
var typeDef = Type.GetType(typeName);
var ret = (bool)this.GetType().GetMethod(nameof(Execute)).MakeGenericMethod(typeDef).Invoke(this, new object[0])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.