I am trying to use postsharp modify the return values of async methods. Is it possible to get the result of a Task at runtime without knowing T?
i.e.
public void OnSuccess(MethodExecutionArgs args)
{
var returnValue = args.ReturnValue;
// returnType is Task<T>
var returnType = returnValue.GetType();
// Is it possible to access the result of the task?
// If T was known then I could cast:
// ((Task<T>) returnValue).ContinueWith(t => t.Result ...)
}
Without reflection, you'd need to use and interface. Also with PostSharp 5.0, you get the result itself there in the
OnSuccess
method instead of theTask<>
.This example works with PostSharp 5.0: