/// <summary>
        ///		Creates nods that relates to children and render order
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        public static MorestachioNode CreateNodes(MorestachioNode parent, IDocumentItem document, out List <MorestachioNode> nodes)
        {
            nodes = new List <MorestachioNode>();
            var stack = new Stack <Tuple <IDocumentItem, IDocumentItem> >();

            stack.Push(new Tuple <IDocumentItem, IDocumentItem>(parent?.Item, document));
            var rootNode = new MorestachioNode(parent, document);

            nodes.Add(rootNode);
            while (stack.Any())
            {
                var item       = stack.Pop();
                var parentNode = nodes.Find(f => f.Item == item.Item2) ?? rootNode;
                foreach (var documentItem in item.Item2.Children)
                {
                    stack.Push(new Tuple <IDocumentItem, IDocumentItem>(item.Item2, documentItem));
                    var morestachioNode = new MorestachioNode(parentNode, documentItem);

                    nodes.Add(morestachioNode);
                    parentNode.Leafs.Add(morestachioNode);
                }
            }

            var prevNode = rootNode;

            foreach (var morestachioNode in nodes.Skip(1))
            {
                prevNode.Next            = morestachioNode;
                morestachioNode.Previous = prevNode;
                prevNode = morestachioNode;
            }

            return(rootNode);
        }
Beispiel #2
0
 /// <summary>
 ///		Creates a new Node
 /// </summary>
 /// <param name="ancestor"></param>
 /// <param name="item"></param>
 public MorestachioNode(MorestachioNode ancestor, IDocumentItem item)
 {
     Ancestor = ancestor;
     Item     = item;
     Leafs    = new List <MorestachioNode>();
 }