Пример #1
0
        /// <summary>
        /// Determines if the <paramref name="predicate"/> yields a match in the target <paramref name="expression"/>.
        /// </summary>
        /// <typeparam name="TExpression">The type of <see cref="Expression"/>
        /// to search for.</typeparam>
        /// <param name="expression">The <see cref="Expression"/> that represents the sub tree for which to start searching.</param>
        /// <param name="predicate">The <see cref="Func{T,TResult}"/> used to filter the result</param>
        /// <returns>A list of <see cref="Expression"/> instances that matches the given predicate.</returns>
        public static bool Contains <TExpression>(this Expression expression, Func <TExpression, bool> predicate) where TExpression : Expression
        {
            var finder = new ExpressionFinder <TExpression>();

            return(finder.Find(expression, predicate).Any());
        }
Пример #2
0
        /// <summary>
        /// Returns a list of <typeparamref name="TExpression"/> instances
        /// that matches the <paramref name="predicate"/>.
        /// </summary>
        /// <typeparam name="TExpression">The type of <see cref="Expression"/>
        /// to search for.</typeparam>
        /// <param name="expression">The <see cref="Expression"/> that represents the sub tree for which to start searching.</param>
        /// <param name="predicate">The <see cref="Func{T,TResult}"/> used to filter the result</param>
        /// <returns>A list of <see cref="Expression"/> instances that matches the given predicate.</returns>
        public static IEnumerable <TExpression> Find <TExpression>(this Expression expression, Func <TExpression, bool> predicate) where TExpression : Expression
        {
            var finder = new ExpressionFinder <TExpression>();

            return(finder.Find(expression, predicate));
        }