Example #1
0
 public static Expression Simplify(Expression expression)
 {
     if (expression.NodeType == ExpressionType.Constant)
         return expression;
     var nominator = new Nominator();
     nominator.Visit(expression);
     if (nominator.mayBeEvaluated.Count == 0) // no possible evaluations
         return expression;
     var ret = new Evaluator(nominator.mayBeEvaluated).Visit(expression);
     return ret;
 }
Example #2
0
 internal static HashSet<Expression> Nominate(Func<Expression, bool> fnCanBeEvaluated, Expression expression)
 {
     Nominator nominator = new Nominator(fnCanBeEvaluated);
     nominator.Visit(expression);
     return nominator.candidates;
 }
Example #3
0
 /// <summary>
 ///     Performs evaluation & replacement of independent sub-trees
 /// </summary>
 /// <param name="expression"> The root of the expression tree. </param>
 /// <param name="fnCanBeEvaluated"> A function that decides whether a given expression node can be part of the local function. </param>
 /// <returns> A new tree with sub-trees evaluated and replaced. </returns>
 public static Expression PartialEval(Expression expression, Func<Expression, bool> fnCanBeEvaluated) {
     var nominator = new Nominator(fnCanBeEvaluated);
     var subtreeEvaluator = new SubtreeEvaluator(nominator.Nominate(expression));
     return subtreeEvaluator.Eval(expression);
 }
Example #4
0
        public static Expression Evaluate(Expression expression)
        {
            var nominator = new Nominator(expression, exp => exp.NodeType != ExpressionType.Parameter);

            return new SubtreeEvaluator(nominator.Candidates).Visit(expression);
        }
Example #5
0
 public static Expression PartialEval(Expression expression)
 {
     Nominator nominator = new Nominator();
     SubtreeEvaluator evaluator = new SubtreeEvaluator(nominator.Nominate(expression));
     return evaluator.Eval(expression);
 }
Example #6
0
 public static HashSet<Expression> Nominate(Expression node)
 {
     var nominator = new Nominator();
     nominator.Visit(node);
     return nominator._candidates;
 }
 internal static HashSet<Expression> Nominate(QueryLanguage language, Expression expression)
 {
     Nominator nominator = new Nominator(language);
     nominator.Visit(expression);
     return nominator.candidates;
 }
Example #8
0
 /// <summary>
 /// Performs evaluation & replacement of independent sub-trees
 /// </summary>
 /// <param name="expression">The root of the expression tree.</param>
 /// <param name="fnCanBeEvaluated">A function that decides whether a given expression node can be part of the local function.</param>
 /// <returns>A new tree with sub-trees evaluated and replaced.</returns>
 public static Expression ReduceSubtrees( Expression expression, Func<Expression, bool> fnCanBeEvaluated )
 {
     HashSet<Expression> nominations = new Nominator(fnCanBeEvaluated).Nominate(expression);
     return new SubtreeEvaluator( nominations ).Eval( expression );
 }
Example #9
0
 internal static Expression PartialEval(Expression expression, Func<Expression, bool> canBeEvaluated)
 {
     Nominator nominator = new Nominator(canBeEvaluated);
     return new SubtreeEvaluator(nominator.Nominate(expression)).Eval(expression);
 }
Example #10
0
 internal FieldProjector(Func<Expression, bool> fnCanBeField)
 {
     this.nominator = new Nominator(fnCanBeField);
 }
			internal static HashSet<Expression> Nominate(Expression expression)
			{
				Nominator nominator = new Nominator();
				nominator.Visit(expression);
				return nominator.candidates;
			}
 public static HashSet<Expression> Nominate(Func<Expression, bool> canBeEvaluated, Expression expression)
 {
     Nominator nominator = new Nominator(canBeEvaluated);
     nominator.Visit(expression);
     return nominator._candidates;
 }