Esempio n. 1
0
        /// <summary>
        /// Extracts all constants from an expression (including closures) and returns a lambda expression that takes all these constants as parameters.
        /// </summary>
        public static ExtractionResult ExtractConstants(Expression expression)
        {
            var visitor          = new ConstantExtractor(rewriteTree: true);
            var constantFreeBody = visitor.Visit(expression);

            return(new ExtractionResult(Expression.Lambda(constantFreeBody, visitor.parameters), visitor.constants));
        }
Esempio n. 2
0
        /// <summary>
        /// Extracts all constants from an expression (including closures) without rewriting the expression tree.
        /// </summary>
        public static IReadOnlyList <object> ExtractConstantsOnly(Expression expression)
        {
            var visitor = new ConstantExtractor(rewriteTree: false);

            visitor.Visit(expression);
            return(visitor.constants);
        }