Example #1
0
        /// <summary>
        /// Generates System.CodeDom.CodeExpression from the given expression.
        /// </summary>
        /// <param name="expression">Expression from which System.CodeDom.CodeExpression is generated.</param>
        /// <returns>Generated System.CodeDom.CodeExpression.</returns>
        public override CodeExpression Visit(LinqWhereExpression expression)
        {
            CodeExpression source = this.GenerateCode(expression.Source);
            var            lambda = this.GenerateCode(expression.Lambda) as CodeLambdaExpression;

            return(source.Call("Where", lambda));
        }
 /// <summary>
 /// Evaluates the specified expression.
 /// </summary>
 /// <param name="expression">The expression to evaluate.</param>
 /// <returns>Value of the expression.</returns>
 public virtual QueryValue Visit(LinqWhereExpression expression)
 {
     return(this.EvaluateQueryMethodWithLambdaExpression <QueryScalarValue>(
                expression,
                null,
                (c, l) => c.Where(l)));
 }
        /// <summary>
        /// Resolves types for the specified expression.
        /// </summary>
        /// <param name="expression">The expression to resolve types for.</param>
        /// <returns>Expression with resolved types.</returns>
        public QueryExpression Visit(LinqWhereExpression expression)
        {
            var source     = this.ResolveTypes(expression.Source);
            var sourceType = ValidateSourceIsACollection(source);
            var lambda     = this.ResolveLambdaTypes(expression.Lambda, sourceType);

            return(new LinqWhereExpression(source, lambda, sourceType));
        }
Example #4
0
 /// <summary>
 /// Evaluates the specified expression.
 /// </summary>
 /// <param name="expression">The expression to evaluate.</param>
 /// <returns>Value of the expression.</returns>
 public override QueryValue Visit(LinqWhereExpression expression)
 {
     return(this.VisitCollectionElementPrimitiveOrComplexTypeError(
                expression,
                delegate
     {
         return base.Visit(expression);
     }));
 }
Example #5
0
        /// <summary>
        /// Visits a QueryExpression tree whose root node is the LinqWhereExpression.
        /// </summary>
        /// <param name="expression">The root node of the expression tree being visited.</param>
        /// <returns>Uri query string representing the expression.</returns>
        public override string Visit(LinqWhereExpression expression)
        {
            string source = this.ComputeUriInternal(expression.Source);
            var    lambda = this.ExpressionConverter.Convert(expression.Lambda);

            this.SetFilterQueryOption(lambda);
            this.hasQueryOption = true;
            return(source);
        }
Example #6
0
 /// <summary>
 /// Filters the specified expression. Skip where expression.
 /// </summary>
 /// <param name="expression">The expression to filter.</param>
 /// <returns>The filtered expression</returns>
 public override QueryExpression Visit(LinqWhereExpression expression)
 {
     return(expression.Source.Accept(this));
 }
Example #7
0
 /// <summary>
 /// Visits a QueryExpression tree whose root node is the LinqWhereExpression.
 /// </summary>
 /// <param name="expression">The root node of the expression tree being visited.</param>
 /// <returns>Uri query string representing the expression.</returns>
 public override string Visit(LinqWhereExpression expression)
 {
     string source = this.ComputeUriInternal(expression.Source);
     var lambda = this.ExpressionConverter.Convert(expression.Lambda);
     this.SetFilterQueryOption(lambda);
     this.hasQueryOption = true;
     return source;
 }
Example #8
0
 /// <summary>
 /// Visits a QueryExpression tree whose root node is the LinqWhereExpression.
 /// </summary>
 /// <param name="expression">The root node of the expression tree being visited.</param>
 /// <returns>Uri query string representing the expression.</returns>
 public virtual string Visit(LinqWhereExpression expression)
 {
     throw new TaupoNotSupportedException("Not supported");
 }
Example #9
0
 /// <summary>
 /// Generates System.CodeDom.CodeExpression from the given expression.
 /// </summary>
 /// <param name="expression">Expression from which System.CodeDom.CodeExpression is generated.</param>
 /// <returns>Generated System.CodeDom.CodeExpression.</returns>
 public abstract CodeExpression Visit(LinqWhereExpression expression);
        /// <summary>
        /// Generates System.CodeDom.CodeExpression from the given expression.
        /// </summary>
        /// <param name="expression">Expression from which System.CodeDom.CodeExpression is generated.</param>
        /// <returns>Generated System.CodeDom.CodeExpression.</returns>
        public override CodeExpression Visit(LinqWhereExpression expression)
        {
            var source          = this.GenerateCode(expression.Source);
            var prm             = expression.Lambda.Parameters.Single();
            var codeQuerySource = source as CodeQueryExpression;

            string inputParameterName = this.GetInputParameterName(codeQuerySource);
            string groupParameterName = this.GetGroupParameterName(codeQuerySource);

            var newPrm = new CodeParameterDeclarationExpression();

            newPrm = new CodeParameterDeclarationExpression(new CodeImplicitTypeReference(), inputParameterName);
            this.ParameterNamesDictionary.Add(prm, newPrm);

            CodeLambdaExpression lambda;

            try
            {
                lambda = (CodeLambdaExpression)this.GenerateCode(expression.Lambda);
            }
            finally
            {
                this.ParameterNamesDictionary.Remove(prm);
            }

            if (codeQuerySource != null)
            {
                if (codeQuerySource.GroupByKeySelector == null && codeQuerySource.Select == null)
                {
                    if (codeQuerySource.Where == null)
                    {
                        return(new CodeQueryExpression(
                                   inputParameterName,
                                   groupParameterName,
                                   codeQuerySource.From,
                                   lambda.Body,
                                   codeQuerySource.OrderByKeySelectors,
                                   codeQuerySource.AreDescending,
                                   codeQuerySource.GroupByKeySelector,
                                   codeQuerySource.Select));
                    }
                    else
                    {
                        return(new CodeQueryExpression(
                                   inputParameterName,
                                   groupParameterName,
                                   codeQuerySource.From,
                                   codeQuerySource.Where.BooleanAnd(lambda.Body),
                                   codeQuerySource.OrderByKeySelectors,
                                   codeQuerySource.AreDescending,
                                   codeQuerySource.GroupByKeySelector,
                                   codeQuerySource.Select));
                    }
                }
                else
                {
                    return(new CodeQueryExpression(
                               inputParameterName,
                               groupParameterName,
                               codeQuerySource,
                               lambda.Body,
                               Enumerable.Empty <CodeExpression>(),
                               Enumerable.Empty <bool>(),
                               null,
                               null));
                }
            }
            else
            {
                return(new CodeQueryExpression(
                           inputParameterName,
                           groupParameterName,
                           source,
                           lambda.Body,
                           Enumerable.Empty <CodeExpression>(),
                           Enumerable.Empty <bool>(),
                           null,
                           null));
            }
        }
        /// <summary>
        /// Generates System.CodeDom.CodeExpression from the given expression.
        /// </summary>
        /// <param name="expression">Expression from which System.CodeDom.CodeExpression is generated.</param>
        /// <returns>Generated System.CodeDom.CodeExpression.</returns>
        public override CodeExpression Visit(LinqWhereExpression expression)
        {
            CodeExpression source = this.GenerateCode(expression.Source);
            var lambda = this.GenerateCode(expression.Lambda) as CodeLambdaExpression;

            return source.Call("Where", lambda);
        }
Example #12
0
 /// <summary>
 /// Replaces the given expression.
 /// </summary>
 /// <param name="expression">The root node of the expression tree being visited.</param>
 /// <returns>Replaced expression.</returns>
 public virtual QueryExpression Visit(LinqWhereExpression expression)
 {
     return(this.VisitQueryMethodWithLambdaExpression(expression, (s, l, t) => new LinqWhereExpression(s, l, t)));
 }
        /// <summary>
        /// Generates System.CodeDom.CodeExpression from the given expression.
        /// </summary>
        /// <param name="expression">Expression from which System.CodeDom.CodeExpression is generated.</param>
        /// <returns>Generated System.CodeDom.CodeExpression.</returns>
        public override CodeExpression Visit(LinqWhereExpression expression)
        {
            var source = this.GenerateCode(expression.Source);
            var prm = expression.Lambda.Parameters.Single();
            var codeQuerySource = source as CodeQueryExpression;

            string inputParameterName = this.GetInputParameterName(codeQuerySource);
            string groupParameterName = this.GetGroupParameterName(codeQuerySource);

            var newPrm = new CodeParameterDeclarationExpression();
            newPrm = new CodeParameterDeclarationExpression(new CodeImplicitTypeReference(), inputParameterName);
            this.ParameterNamesDictionary.Add(prm, newPrm);

            CodeLambdaExpression lambda;
            try
            {
                lambda = (CodeLambdaExpression)this.GenerateCode(expression.Lambda);
            }
            finally
            {
                this.ParameterNamesDictionary.Remove(prm);
            }

            if (codeQuerySource != null)
            {
                if (codeQuerySource.GroupByKeySelector == null && codeQuerySource.Select == null)
                {
                    if (codeQuerySource.Where == null)
                    {
                        return new CodeQueryExpression(
                            inputParameterName,
                            groupParameterName,
                            codeQuerySource.From,
                            lambda.Body,
                            codeQuerySource.OrderByKeySelectors,
                            codeQuerySource.AreDescending,
                            codeQuerySource.GroupByKeySelector,
                            codeQuerySource.Select);
                    }
                    else
                    {
                        return new CodeQueryExpression(
                            inputParameterName,
                            groupParameterName,
                            codeQuerySource.From,
                            codeQuerySource.Where.BooleanAnd(lambda.Body),
                            codeQuerySource.OrderByKeySelectors,
                            codeQuerySource.AreDescending,
                            codeQuerySource.GroupByKeySelector,
                            codeQuerySource.Select);
                    }
                }
                else
                {
                    return new CodeQueryExpression(
                        inputParameterName,
                        groupParameterName,
                        codeQuerySource,
                        lambda.Body,
                        Enumerable.Empty<CodeExpression>(),
                        Enumerable.Empty<bool>(),
                        null,
                        null);
                }
            }
            else
            {
                return new CodeQueryExpression(
                    inputParameterName,
                    groupParameterName,
                    source,
                    lambda.Body,
                    Enumerable.Empty<CodeExpression>(),
                    Enumerable.Empty<bool>(),
                    null,
                    null);
            }
        }