public static AsyncTransformExpression <TSource, TOuter> Then <TOuter>(AsyncTransformExpression <TSource, TResult> left, AsyncTransformExpression <TResult, TOuter> right) { Contract.NotNull(left, nameof(left)); Contract.NotNull(right, nameof(right)); if (left.IsIdentity()) { // we can optimize the left expression away, since we know that TSource == TResult ! //note: fool the compiler into believing that TSource == TResult return((AsyncTransformExpression <TSource, TOuter>)(object) right); } if (right.IsIdentity()) { // we can optimize the right expression away, since we know that TResult == TOuter ! return((AsyncTransformExpression <TSource, TOuter>)(object) left); } if (left.m_transform != null) { var f = left.m_transform; Contract.Assert(f != null); if (right.m_transform != null) { var g = right.m_transform; Contract.Assert(g != null); return(new AsyncTransformExpression <TSource, TOuter>((x) => g(f(x)))); } else { var g = right.m_asyncTransform; Contract.Assert(g != null); return(new AsyncTransformExpression <TSource, TOuter>((x, ct) => g(f(x), ct))); } } else { var f = left.m_asyncTransform; Contract.Assert(f != null); if (right.m_asyncTransform != null) { var g = right.m_asyncTransform; Contract.Assert(g != null); return(new AsyncTransformExpression <TSource, TOuter>(async(x, ct) => await g(await f(x, ct).ConfigureAwait(false), ct).ConfigureAwait(false))); } else { var g = right.m_transform; Contract.Assert(g != null); return(new AsyncTransformExpression <TSource, TOuter>(async(x, ct) => g(await f(x, ct).ConfigureAwait(false)))); } } }
public AsyncTransformExpression <TSource, TOuter> Then <TOuter>(AsyncTransformExpression <TResult, TOuter> expr) { return(Then <TOuter>(this, expr)); }