I am trying to get the properties of a return type of a method using reflection.
I am getting the return type of the method using MethodInfo.ReturnType
, which yields my a type of Task<T>
since my method is async
. Using GetProperties
on this type yields me with the properties belonging to Task
: Result
, Exception
, AsyncState
. However, I want to get the properties of the underlying type T.
Example for method with signature:
public async Task<MyReturnType> MyMethod()
var myMethodInfo = MyType.GetMethod("MyMethod");
var returnType = myMethodInfo.ReturnType; // Task<MyReturnType>
var myProperties = returnType.GetProperties(); // [Result, Exception, AsyncState]
How can I get the properties of the inner type T in Task in stead of the properties of Task?