protected override Expression VisitNew(NewExpression node)
        {
            var newNode = (NewExpression)base.VisitNew(node);
            if (newNode.Type.IsGenericType
                && newNode.Type.GetGenericTypeDefinition() == typeof(HashSet<>)
                && newNode.Arguments.Count == 1
                && newNode.Arguments[0] is AccumulatorExpression
                && ((AccumulatorExpression)newNode.Arguments[0]).AccumulatorType == AccumulatorType.Push)
            {
                Guid correlationId = Guid.Empty;
                if (_groupMap == null || TryGetCorrelatedGroup(node.Arguments[0], out correlationId))
                {
                    Expression accumulator = new AccumulatorExpression(
                        newNode.Type,
                        AccumulatorType.AddToSet,
                        ((AccumulatorExpression)newNode.Arguments[0]).Argument);

                    if (_groupMap != null)
                    {
                        accumulator = new CorrelatedAccumulatorExpression(
                            correlationId,
                            (AccumulatorExpression)accumulator);
                    }

                    return accumulator;
                }
            }

            return newNode;
        }
        protected internal override Expression VisitCorrelatedAccumulator(CorrelatedAccumulatorExpression node)
        {
            Expression mapped;
            if (_map.TryGetValue(node, out mapped))
            {
                return mapped;
            }

            return base.VisitCorrelatedAccumulator(node);
        }
 protected internal virtual Expression VisitCorrelatedAccumulator(CorrelatedAccumulatorExpression node)
 {
     return(node.Update(VisitAndConvert <AccumulatorExpression>(node.Accumulator, "VisitCorrelatedAccumulator")));
 }
 protected internal virtual Expression VisitCorrelatedAccumulator(CorrelatedAccumulatorExpression node)
 {
     return node.Update(VisitAndConvert<AccumulatorExpression>(node.Accumulator, "VisitCorrelatedAccumulator"));
 }
            protected internal override Expression VisitCorrelatedAccumulator(CorrelatedAccumulatorExpression node)
            {
                _accumulators.Add(node);

                // there could be nested accumulators we need to get...
                return base.VisitCorrelatedAccumulator(node);
            }
            protected internal override Expression VisitCorrelatedAccumulator(CorrelatedAccumulatorExpression node)
            {
                if(node.CorrelationId == _correlationId)
                {
                    return Visit(node.Accumulator);
                }

                return base.VisitCorrelatedAccumulator(node);
            }
        private bool TryBindAccumulatorExpression(MethodCallExpression node, out Expression accumulator)
        {
            AccumulatorType accumulatorType;
            if (TryGetAccumulatorType(node.Method.Name, out accumulatorType))
            {
                Guid correlationId = Guid.Empty;
                if (_groupMap == null || TryGetCorrelatedGroup(node.Arguments[0], out correlationId))
                {
                    accumulator = new AccumulatorExpression(node.Type,
                        accumulatorType,
                        GetAccumulatorArgument(node));

                    if (_groupMap != null)
                    {
                        accumulator = new CorrelatedAccumulatorExpression(
                            correlationId,
                            (AccumulatorExpression)accumulator);
                    }

                    return true;
                }
            }

            accumulator = null;
            return false;
        }