public static AsyncFilterExpression <TSource> OrElse(AsyncFilterExpression <TSource> left, AsyncFilterExpression <TSource> right)
        {
            Contract.NotNull(left, nameof(left));
            Contract.NotNull(right, nameof(right));

            // combine two expressions into a logical OR expression.
            // Note: if the first expression returns true, the second one will NOT be evaluated

            if (left.m_filter != null)
            {             // we are async
                var f = left.m_filter;
                Contract.Assert(f != null);
                if (right.m_filter != null)
                {                 // so is the next one
                    var g = right.m_filter;
                    Contract.Assert(g != null);
                    return(new AsyncFilterExpression <TSource>((x) => f(x) || g(x)));
                }
                else
                {                 // next one is async
                    var g = right.m_asyncFilter;
                    Contract.Assert(g != null);
                    return(new AsyncFilterExpression <TSource>((x, ct) => f(x) ? TaskHelpers.True : g(x, ct)));
                }
            }
            else
            {             // we are async
                var f = left.m_asyncFilter;
                Contract.Assert(f != null);
                if (right.m_asyncFilter != null)
                {                 // so is the next one
                    var g = left.m_asyncFilter;
                    Contract.Assert(g != null);
                    return(new AsyncFilterExpression <TSource>(async(x, ct) => (await f(x, ct).ConfigureAwait(false)) || (await g(x, ct).ConfigureAwait(false))));
                }
                else
                {
                    var g = left.m_filter;
                    Contract.Assert(g != null);
                    return(new AsyncFilterExpression <TSource>(async(x, ct) => (await f(x, ct).ConfigureAwait(false)) || g(x)));
                }
            }
        }
Exemplo n.º 2
0
        public static AsyncFilterExpression <TSource> AndAlso(AsyncFilterExpression <TSource> left, AsyncFilterExpression <TSource> right)
        {
            Contract.NotNull(left);
            Contract.NotNull(right);

            // combine two expressions into a logical AND expression.
            // Note: if the first expression returns false, the second one will NOT be evaluated

            if (left.m_filter != null)
            {             // we are async
                var f = left.m_filter;
                if (right.m_filter != null)
                {                 // so is the next one
                    var g = right.m_filter;
                    return(new AsyncFilterExpression <TSource>((x) => f(x) && g(x)));
                }
                else
                {                 // next one is async
                    var g = right.m_asyncFilter;
                    return(new AsyncFilterExpression <TSource>((x, ct) => f(x) ? g !(x, ct) : TaskHelpers.False));
                }
            }
            else
            {             // we are async
                var f = left.m_asyncFilter;
                Contract.Debug.Assert(f != null);
                if (right.m_asyncFilter != null)
                {                 // so is the next one
                    var g = right.m_asyncFilter;
                    return(new AsyncFilterExpression <TSource>(async(x, ct) => (await f(x, ct).ConfigureAwait(false)) && (await g !(x, ct).ConfigureAwait(false))));
                }
                else
                {
                    var g = right.m_filter;
                    return(new AsyncFilterExpression <TSource>(async(x, ct) => (await f(x, ct).ConfigureAwait(false)) && g !(x)));
                }
            }
        }
 public AsyncFilterExpression <TSource> OrElse([NotNull] AsyncFilterExpression <TSource> expr)
 {
     return(OrElse(this, expr));
 }
 public AsyncFilterExpression <TSource> AndAlso([NotNull] AsyncFilterExpression <TSource> expr)
 {
     return(AndAlso(this, expr));
 }