Beispiel #1
0
            protected void Next()
            {
                if (_resetCountersOnNext)
                {
                    _resetCountersOnNext = false;
                    _jumpCounters.Clear();
                }

                //is there a jump at this index?
                if (!_jumpList.HasJump(CurrentIndex))
                {
                    CurrentIndex = _jumpList.NextIndex(CurrentIndex, ForwardIteration);
                    return;
                }

                //have we counted and made every jump in the list?
                //if so, reset the counters
                if (_jumpList.GetNumJumps() > 0 && _jumpList.GetNumJumps() == _jumpCounters.Count)
                {
                    bool resetCounters = true;
                    foreach (var jumpCounter in _jumpCounters)
                    {
                        if (jumpCounter.Value > 0)
                        {
                            resetCounters = false;
                            break;
                        }
                    }
                    if (resetCounters)
                    {
                        _resetCountersOnNext = true;
                    }
                }

                //do we have a counter tracking the jumps yet?
                if (!_jumpCounters.ContainsKey(CurrentIndex))
                {
                    //if not, add and initialize it
                    _jumpCounters.Add(CurrentIndex, _jumpList._jumps[CurrentIndex].count);
                }

                if (_jumpCounters[CurrentIndex] > 0)
                {
                    _jumpCounters[CurrentIndex] = _jumpCounters[CurrentIndex] - 1;

                    if (_jumpList._jumps[CurrentIndex].callback != null)
                    {
                        _jumpList._jumps[CurrentIndex].callback(CurrentIndex, _jumpList._jumps[CurrentIndex].jump, _jumpCounters[CurrentIndex]);
                    }

                    CurrentIndex = _jumpList._jumps[CurrentIndex].jump;
                }
                else
                {
                    CurrentIndex = _jumpList.NextIndex(CurrentIndex, ForwardIteration);
                }
            }