Esempio n. 1
0
        /// <summary>
        /// Internal expression resolver.
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="ce"></param>
        /// <param name="cc"></param>
        /// <param name="container"></param>
        /// <returns></returns>
        /// <remarks>
        /// Cache and do cache lookup of expressions to try to short-circuit the expression resolution.
        /// </remarks>
        public static IValue InternalGetExpression(Expression expr, IGeneratedQueryCode ce, ICodeContext cc, CompositionContainer container)
        {
            // If we are looking at a null expression, then we resolve to a null value
            if (expr == null)
            {
                return(null);
            }

            // If this is a known sub-expression, then we should return
            // the cached value.
            if (ce != null)
            {
                var v = ce.LookupSubexpression(expr);
                if (v != null)
                {
                    return(v);
                }
            }

            // We are going to do the visit. Create the resolver we are going to use
            // and configure it.
            if (cc == null)
            {
                cc = new CodeContext();
            }

            var visitor = new ExpressionToCPP(ce, cc);

            visitor.MEFContainer = container;

            if (container != null)
            {
                container.SatisfyImportsOnce(visitor);
            }

            // Do the visit
            visitor.Visit(expr);

            // Cache the result.
            if (ce != null)
            {
                ce.RememberSubexpression(expr, visitor.Result);
            }

            return(visitor.Result);
        }