private TChild TryGetNext() { if (_current != default(TChild)) { TChild localCurrent = _current; ISwagParent <TChild> composite = localCurrent as ISwagParent <TChild>; //If parent node, return first child if (composite != null && composite.Children != null && composite.Children.Count > 0) { TChild firstChild = composite.Children.OrderBy(c => c.Sequence).First(); return(firstChild); } else if (localCurrent.Parent != null) //If leaf node { TChild tempCurrent = localCurrent, nextSibling = default(TChild); ISwagParent <TChild> tempParent = localCurrent.Parent; do { //Find next sibling nextSibling = tempParent.Children.OrderBy(c => c.Sequence).Where(c => c.Sequence > tempCurrent.Sequence).FirstOrDefault(); tempCurrent = tempParent as TChild; //currentNode is now the parent tempParent = tempParent.Parent; //currenISwagParent<TChild> is now the grandParent } while (nextSibling == null && tempCurrent != null && tempParent != null); return(nextSibling); } } return(default(TChild)); }
public SwagItemPreOrderIterator(ISwagParent <TChild> root) { _root = root; }