Reputation: 318
In .Net 6
I have a controller with the following method signature
public async Task<ActionResult<MyClass>> Method() {...}
Using reflection, how do I extract the type (MyClass in this example)?
I tried using the Type.GetGenericType method but it doesn't work
Thank you
Upvotes: 0
Views: 558
Reputation: 9993
You can use ReturnType
and GetGenericArguments
to extract the type.
//......
var methodinfo = t.GetMethod("Method");
var result = methodinfo.ReturnType;
var resultType = result.GetGenericArguments()[0].GetGenericArguments();
Now the resultType
is what you want to get.
Upvotes: 1