/// <summary> /// Insert <paramref name="node"/> before the <paramref name="before"/> node. /// </summary> /// <remarks> /// If previous is null then insert the node at the end of the list. /// </remarks> void InsertNode(HNode before, HNode node) { // Validate the node ValidateNode(node, this); // If the node have a parent we clone it if (node.Parent != null) { node = node.CloneNode(); } else { // If node is the parent of this container, then we clone it HNode p = this; while (p.parent != null) { p = p.Parent; } if (node == p) { node = node.CloneNode(); } } // Set the parent node.parent = this; // Content empty ? if (content == null) { node.nextNode = node; content = node; } else if (before == null) { ConvertContentTextToNode(); // Add at the end of the list node.nextNode = ((HNode)content).nextNode; ((HNode)content).nextNode = node; content = node; } else if (before == FirstNodeRef) { ConvertContentTextToNode(); // Add at the beginning of the list node.nextNode = ((HNode)content).nextNode; ((HNode)content).nextNode = node; } else { // Search the 'previous' before node var previousBefore = before; while (previousBefore.nextNode != before) { previousBefore = previousBefore.nextNode; } // Insert the node to the list node.nextNode = before; previousBefore.nextNode = node; } }
internal HContainer(HContainer other) { if (other.content is string) { this.content = other.content; } else { HNode n = (HNode)other.content; if (n != null) { do { n = n.nextNode; AppendNode(n.CloneNode()); } while (n != other.content); } } }