I have the following method:
public async Task Execute()
{
object previous = null;
// _delegates is of type IReadOnlyCollection<Delegate>
foreach (Delegate method in _delegates)
{
Task executing = (Task) (previous != null
? method.DynamicInvoke(_repository, previous)
: method.DynamicInvoke(_repository);
await executing;
// pseudo code here
if (executing returns something)
previous = executing.Result //<-- ?
else
previous = null;
}
}
Basically I iterate over a list of delegates that I execute in order. Each delegate receives a repository as argument, and the return value of the previous delegate (if there was any).
Some delegates return a Task
and some return a Task<TResult>
. If encountered with the latter, I want to store the TResult
value in previous
so I can pass it as an argument to the next delegate.
Is there a way to achieve this?