コード例 #1
0
        /// <summary>
        /// Returns whether or not an <see cref="Expression"/> inside the given <paramref name="tree"/>
        /// matches the given <paramref name="predicate"/>.
        /// </summary>
        public static bool Exists(this Expression tree, Predicate <Expression> predicate)
        {
            bool doesExist             = false;
            ExpressionPipeline visitor = Expressive.Pipeline();

            visitor.Pipeline += expr =>
            {
                if (predicate(expr))
                {
                    doesExist = true;
                    visitor.Stop();
                }

                return(expr);
            };

            visitor.Visit(tree);

            return(doesExist);
        }
コード例 #2
0
        /// <summary>
        /// Returns all <see cref="Expression"/>s that matches
        /// the given <paramref name="predicate"/>.
        /// </summary>
        public static List <Expression> FindAll(this Expression tree, Predicate <Expression> predicate)
        {
            List <Expression>  result  = new List <Expression>();
            ExpressionPipeline visitor = Expressive.Pipeline();

            visitor.Pipeline += expr =>
            {
                if (predicate(expr))
                {
                    result.Add(expr);
                    visitor.Stop();
                }

                return(expr);
            };

            visitor.Visit(tree);

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Returns whether or not the given expression <paramref name="tree"/>
        /// contains the specified <paramref name="expression"/>.
        /// </summary>
        public static bool Contains(this Expression tree, Expression expression)
        {
            bool doesContain           = false;
            ExpressionPipeline visitor = Expressive.Pipeline();

            visitor.Pipeline += expr =>
            {
                if (expr == expression)
                {
                    doesContain = true;
                    visitor.Stop();
                }

                return(expr);
            };

            visitor.Visit(tree);

            return(doesContain);
        }
コード例 #4
0
        /// <summary>
        /// Returns the first <see cref="Expression"/> that matches
        /// the given <paramref name="predicate"/>.
        /// </summary>
        public static Expression Find(this Expression tree, Predicate <Expression> predicate)
        {
            Expression         result  = null;
            ExpressionPipeline visitor = Expressive.Pipeline();

            visitor.Pipeline += expr =>
            {
                if (predicate(expr))
                {
                    result = expr;
                    visitor.Stop();
                }

                return(expr);
            };

            visitor.Visit(tree);

            return(result);
        }