Exemple #1
0
        protected override SequenceConvertInfo Convert(
            ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo, ParameterExpression param)
        {
            var predicate = (LambdaExpression)ExpressionBuilder.GetPredicate(methodCall.Arguments[1]);
            var info      = builder.ConvertSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]), predicate.Parameters[0]);

            if (info != null)
            {
                info.Expression = methodCall.Convert(ex => ConvertMethod(methodCall, 0, info, predicate.Parameters[0], ex));

                if (param != null)
                {
                    if (param.Type != info.Parameter.Type)
                    {
                        param = Expression.Parameter(info.Parameter.Type, param.Name);
                    }

                    if (info.ExpressionsToReplace != null)
                    {
                        foreach (var path in info.ExpressionsToReplace)
                        {
                            path.Path = path.Path.Convert(e => e == info.Parameter ? param : e);
                            path.Expr = path.Expr.Convert(e => e == info.Parameter ? param : e);
                        }
                    }
                }

                info.Parameter = param;

                return(info);
            }

            return(null);
        }
        protected override SequenceConvertInfo Convert(
            ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo, ParameterExpression param)
        {
            if (methodCall.Arguments.Count == 2)
            {
                var predicate = (LambdaExpression)ExpressionBuilder.GetPredicate(methodCall.Arguments[1]);
                var info      = builder.ConvertSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]), predicate.Parameters[0]);

                if (info != null)
                {
                    info.Expression = methodCall.Convert(ex => ConvertMethod(methodCall, 0, info, predicate.Parameters[0], ex));
                    info.Parameter  = param;

                    return(info);
                }
            }
            else
            {
                var info = builder.ConvertSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]), null);

                if (info != null)
                {
                    info.Expression = methodCall.Convert(ex => ConvertMethod(methodCall, 0, info, null, ex));
                    info.Parameter  = param;

                    return(info);
                }
            }

            return(null);
        }
Exemple #3
0
        protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
        {
            var sequence  = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0]));
            var condition = (LambdaExpression)ExpressionBuilder.GetPredicate(methodCall.Arguments[1]);
            var result    = builder.BuildWhere(buildInfo.Parent, sequence, condition, true);

            result.SetAlias(condition.Parameters[0].Name);

            return(result);
        }
Exemple #4
0
        protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
        {
            var sequence = builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0])
            {
                CopyTable = true
            });

            if (methodCall.Arguments.Count == 2)
            {
                var condition = (LambdaExpression)ExpressionBuilder.GetPredicate(methodCall.Arguments[1]);

                if (methodCall.Method.Name == "All")
#if FW4 || SILVERLIGHT
                { condition = Expression.Lambda(Expression.Not(condition.Body), condition.Name, condition.Parameters); }
#else
                { condition = Expression.Lambda(Expression.Not(condition.Body), condition.Parameters.ToArray()); }
#endif

                sequence = builder.BuildWhere(buildInfo.Parent, sequence, condition, true);
                sequence.SetAlias(condition.Parameters[0].Name);
            }

            return(new AllAnyContext(buildInfo.Parent, methodCall, sequence));
        }