public static HashSet <Expression> Nominate(Expression expression) { ExpressionNominator n = new ExpressionNominator(); n.Visit(expression); return(n.candidates); }
/// <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 exp) { if (exp.NodeType == ExpressionType.Constant) { return(exp); } HashSet <Expression> candidates = ExpressionNominator.Nominate(exp); return(new ExpressionEvaluator(candidates).Visit(exp) !); }
/// <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 exp) { return(new MetaEvaluator { candidates = ExpressionNominator.Nominate(exp) }.Visit(exp)); }