private static VfpExpression GetProjection(VfpFilterExpression filterExpression, string filterVariableName, VfpExpression projectionExpression)
        {
            var newInstanceExpression = projectionExpression as VfpNewInstanceExpression;

            if (newInstanceExpression == null)
            {
                return(projectionExpression);
            }

            var newInstanceVariableNames = VariableReferenceGatherer.Gather(newInstanceExpression)
                                           .Select(x => x.VariableName)
                                           .Distinct()
                                           .ToArray();

            if (newInstanceVariableNames.Length != 1)
            {
                return(projectionExpression);
            }

            if (filterVariableName != newInstanceVariableNames.First())
            {
                return(projectionExpression);
            }

            return(VariableReferenceReplacer.Replace(filterExpression.Input.Variable, newInstanceExpression));
        }
Esempio n. 2
0
        private static VfpExpression GetScanProperty(VfpVariableReferenceExpression variable, VfpExpression property)
        {
            var expression   = VariableReferenceReplacer.Replace(variable, property);
            var scanProperty = expression as VfpPropertyExpression;

            if (scanProperty == null)
            {
                return(expression);
            }

            var variables = VariableReferenceGatherer.Gather(expression);

            if (!variables.Any())
            {
                return(expression);
            }

            var scanVariable = variables.First();

            return(scanVariable.Property(scanProperty.ResultType, scanProperty.Property));
        }
Esempio n. 3
0
        public override VfpExpression Visit(VfpFilterExpression expression)
        {
            expression = (VfpFilterExpression)base.Visit(expression);

            var innerFilter = expression.Input.Expression as VfpFilterExpression;

            if (innerFilter == null)
            {
                return(expression);
            }

            var variables = VariableReferenceGatherer.Gather(innerFilter.Predicate);

            if (!variables.Any() || variables.Select(x => x.VariableName).Distinct().Count() > 1)
            {
                return(expression);
            }

            var predicate = VariableReferenceReplacer.Replace(variables.First(), expression.Predicate);

            return(innerFilter.Input.Filter(predicate.And(innerFilter.Predicate)));
        }