public override void VisitFunction(FunctionExpression functionExpression) { if (functionExpression.Function == Operators.Plus) { Visit(functionExpression[0]); } else if (functionExpression.Function == Operators.Negate) { SumAggregator aggregator = new SumAggregator(); aggregator.Visit(functionExpression[0]); Append(aggregator, true); } else if (functionExpression.Function == Operators.Add) { foreach (Expression argument in functionExpression) { Visit(argument); } } else if (functionExpression.Function == Operators.Subtract) { Visit(functionExpression[0]); SumAggregator aggregator = new SumAggregator(); aggregator.Visit(functionExpression[1]); Append(aggregator, true); } else if (functionExpression.Function == Operators.Multiply || functionExpression.Function == Operators.Divide) { ProductAggregator aggregator = new ProductAggregator(); aggregator.Visit(functionExpression); Expression expression = aggregator.ToExpression(); FunctionExpression functionExpression1 = expression as FunctionExpression; if (functionExpression1 != null && (functionExpression1.Function == Operators.Multiply || functionExpression1.Function == Operators.Divide)) { AddExpression(expression); } else { Visit(expression); } } else { AddExpression(functionExpression); } }
private void Append(SumAggregator aggregator, bool invert) { if (invert) { _value -= aggregator._value; } else { _value += aggregator._value; } IEnumerable <Addent> addents = aggregator._addents; if (invert) { addents = addents.Select(a => a.Negate()); } _addents = _addents.AddRange(addents); }