Beispiel #1
0
        /// <summary>
        /// Visits all items in the given order
        /// </summary>
        /// <param name="item">The item to visit</param>
        /// <param name="start">The state to use</param>
        /// <returns>All items, including the start item, in the given order</returns>
        private static IEnumerable <VisitedItem> All(ParsedItem item, VisitedItem start, TraverseOrder order)
        {
            start = start ?? new VisitedItem();

            if (order == TraverseOrder.DepthFirstPostOrder)
            {
                start.Parents.Add(item);

                foreach (var n in item.Children)
                {
                    foreach (var c in All(n, start, order))
                    {
                        yield return(c);
                    }
                }

                start.Parents.RemoveAt(start.Parents.Count - 1);

                start.Current = item;
                yield return(start);
            }
            else //if (order == TraverseOrder.DepthFirstPreOrder)
            {
                start.Current = item;
                yield return(start);

                start.Parents.Add(item);

                foreach (var n in item.Children)
                {
                    foreach (var c in All(n, start, order))
                    {
                        yield return(c);
                    }
                }

                start.Parents.RemoveAt(start.Parents.Count - 1);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Constructs a new strongly type visited item
 /// </summary>
 /// <param name="parent">The item to copy</param>
 public TypedVisitedItem(VisitedItem parent)
 {
     base.Current = parent.Current;
     base.Parents = parent.Parents;
 }