public bool MoveNext() {
switch (this.state) {
case IteratorState.HaveCurrent:
this.state = IteratorState.NeedCurrent;
return true;
case IteratorState.NeedCurrent:
// Move to next following node which matches
if (!this.filter.MoveToFollowing(this.navCurrent, this.navEnd)) {
// No more nodes unless ending node matches
if (filter.IsFiltered(this.navEnd)) {
this.state = IteratorState.NoNext;
return false;
}
this.navCurrent.MoveTo(this.navEnd);
this.state = IteratorState.NoNext;
}
return true;
case IteratorState.HaveCurrentNoNext:
this.state = IteratorState.NoNext;
return true;
}
Debug.Assert(this.state == IteratorState.NoNext, "Illegal state: " + this.state);
return false;
}