public CommandTreeNode <T> Previous(CommandTreeNode <T> selection) { var pLoc = FindParentLocation(selection, Subs); var arr = pLoc?.Item1.Subs.ToArray(); return(arr?[pLoc.Item2 - 1 < 0 ? arr.Length - 1: pLoc.Item2 - 1]); }
public CommandTreeNode <T> Next(CommandTreeNode <T> selection) { var pLoc = FindParentLocation(selection, Subs); var arr = pLoc?.Item1.Subs.ToArray(); return(arr?[pLoc.Item2 + 1 >= arr.Length ? 0: pLoc.Item2 + 1]); }
private CommandTreeNode(CommandTreeNode <T> parent, T key, string value, IEnumerable <CommandTreeNode <T> > subs) { _parent = parent; Key = key; Value = value; Subs = subs?.Select(x => new CommandTreeNode <T>(this, x.Key, x.Value, x.Subs)).ToList() ?? new List <CommandTreeNode <T> >(); }
private Tuple <CommandTreeNode <T>, int> FindParentLocation(CommandTreeNode <T> selection, List <CommandTreeNode <T> > nodes) { var ns = nodes.ToArray(); for (var i = 0; i < ns.Length; i++) { if (ReferenceEquals(ns[i], selection)) { return(new Tuple <CommandTreeNode <T>, int>(ns[i]._parent, i)); } var p = FindParentLocation(selection, ns[i].Subs); if (p != null) { return(p); } } return(null); }