Esempio n. 1
0
 /// <summary>
 /// Simplifies the target <paramref name="expression"/>.
 /// </summary>
 /// <param name="expression">The <see cref="LambdaExpression"/> to simplify.</param>
 /// <returns>A simplified version of the target <paramref name="expression"/></returns>
 public static LambdaExpression Simplify(this LambdaExpression expression)
 {            
     expression = new MatchExpressionRewriter().Rewrite(expression);
     
     return
         (LambdaExpression)expression.PartialEval(
             e => e.NodeType != ExpressionType.Parameter && e.NodeType != ExpressionType.Lambda);
 }
Esempio n. 2
0
        /// <summary>
        /// Simplifies the target <paramref name="expression"/>.
        /// </summary>
        /// <param name="expression">The <see cref="LambdaExpression"/> to simplify.</param>
        /// <returns>A simplified version of the target <paramref name="expression"/></returns>
        public static LambdaExpression?Simplify(this LambdaExpression expression)
        {
            expression = MatchExpressionRewriter.Rewrite(expression);

            return
                ((LambdaExpression?)expression.PartialEval(
                     e => e.NodeType != ExpressionType.Parameter && e.NodeType != ExpressionType.Lambda));
        }
Esempio n. 3
0
        /// <summary>
        /// Replaces references to the <see cref="The{TValue}.IsAnyValue"/> with a <see cref="MethodCallExpression"/>
        /// that represents calling the <see cref="The{TValue}.Is"/> method.
        /// </summary>
        /// <param name="expression">The <see cref="LambdaExpression"/> to visit.</param>
        /// <returns><see cref="Expression"/>.</returns>
        public static LambdaExpression Rewrite(LambdaExpression expression)
        {
            var @this = new MatchExpressionRewriter();

            return((LambdaExpression)@this.Visit(expression));
        }