Ejemplo n.º 1
0
        /// <summary>Builds the Uri for the expression passed in.</summary>
        /// <param name="e">The expression to translate into a Uri</param>
        /// <returns>Query components</returns>
        internal QueryComponents Translate(Expression e)
        {
            Uri     uri;
            Version version;
            bool    addTrailingParens = false;
            Dictionary <Expression, Expression> normalizerRewrites = null;

            // short cut analysis if just a resource set
            // note - to be backwards compatible with V1, will only append trailing () for queries
            // that include more then just a resource set.
            if (!(e is ResourceSetExpression))
            {
                normalizerRewrites = new Dictionary <Expression, Expression>(ReferenceEqualityComparer <Expression> .Instance);
                e = Evaluator.PartialEval(e);
                e = ExpressionNormalizer.Normalize(e, normalizerRewrites);
                e = ResourceBinder.Bind(e);
                addTrailingParens = true;
            }

            UriWriter.Translate(this.Context, addTrailingParens, e, out uri, out version);
            ResourceExpression re            = e as ResourceExpression;
            Type             lastSegmentType = re.Projection == null ? re.ResourceType : re.Projection.Selector.Parameters[0].Type;
            LambdaExpression selector        = re.Projection == null ? null : re.Projection.Selector;

            return(new QueryComponents(uri, version, lastSegmentType, selector, normalizerRewrites));
        }
Ejemplo n.º 2
0
        internal QueryComponents Translate(Expression e)
        {
            Uri     uri;
            Version version;
            bool    addTrailingParens = false;
            Dictionary <Expression, Expression> rewrites = null;

            if (!(e is ResourceSetExpression))
            {
                rewrites          = new Dictionary <Expression, Expression>(ReferenceEqualityComparer <Expression> .Instance);
                e                 = Evaluator.PartialEval(e);
                e                 = ExpressionNormalizer.Normalize(e, rewrites);
                e                 = ResourceBinder.Bind(e, this.Context);
                addTrailingParens = true;
            }
            UriWriter.Translate(this.Context, addTrailingParens, e, out uri, out version);
            ResourceExpression expression = e as ResourceExpression;
            Type lastSegmentType          = (expression.Projection == null) ? expression.ResourceType : expression.Projection.Selector.Parameters[0].Type;

            return(new QueryComponents(uri, version, lastSegmentType, (expression.Projection == null) ? null : expression.Projection.Selector, rewrites));
        }