Ejemplo n.º 1
0
        protected override VfpExpressionBinding VisitVfpExpressionBinding(VfpExpressionBinding binding)
        {
            binding = base.VisitVfpExpressionBinding(binding);

            var filterExpression = binding.Expression as VfpFilterExpression;

            if (filterExpression == null)
            {
                return(binding);
            }

            var project = filterExpression.Input.Expression as VfpProjectExpression;

            if (project == null)
            {
                return(binding);
            }

            var scan = project.Input.Expression as VfpScanExpression;

            if (scan == null)
            {
                return(binding);
            }

            var newInstance = project.Projection as VfpNewInstanceExpression;

            if (newInstance == null)
            {
                return(binding);
            }

            var properties = newInstance.Arguments.OfType <VfpPropertyExpression>().ToList().AsReadOnly();

            if (!properties.Any())
            {
                return(binding);
            }

            if (!VfpPropertyExpressionChecker.CanRewrite(filterExpression.Predicate))
            {
                return(binding);
            }

            var newFilterPredicate   = VfpPropertyExpressionRewriter.Rewrite(filterExpression.Predicate, properties);
            var newFilterExpression  = project.Input.Filter(newFilterPredicate);
            var newFilterBinding     = newFilterExpression.BindAs(binding.Variable.VariableName);
            var newProjection        = VfpVariableReferenceExpressionRewriter.Rewrite(project.Projection, binding.Variable);
            var newProjectExpression = newFilterBinding.Project(newProjection);
            var newBinding           = newProjectExpression.BindAs(binding.Variable.VariableName);

            return(newBinding);
        }
Ejemplo n.º 2
0
            public static VfpExpression Rewrite(VfpExpression expression, ReadOnlyCollection <VfpPropertyExpression> properties)
            {
                var rewriter = new VfpPropertyExpressionRewriter(properties);

                return(rewriter.Visit(expression));
            }