public void InsertChildBefore <T>(JsNode nextSibling, T child, JsTreeRole <T> role) where T : JsNode { if (role == null) { throw new ArgumentNullException("role"); } if (nextSibling == null) { AddChild(child, role); return; } if (child == null) { return; } ThrowIfFrozen(); if (child.parent != null) { throw new ArgumentException("Node is already used in another tree.", "child"); } if (child.IsFrozen) { throw new ArgumentException("Cannot add a frozen node.", "child"); } if (nextSibling.parent != this) { throw new ArgumentException("NextSibling is not a child of this node.", "nextSibling"); } // No need to test for "Cannot add children to null nodes", // as there isn't any valid nextSibling in null nodes. InsertChildBeforeUnsafe(nextSibling, child, role); }
public void AddChild <T>(T child, JsTreeRole <T> role) where T : JsNode { if (role == null) { throw new ArgumentNullException("role"); } if (child == null) { return; } ThrowIfFrozen(); if (child == this) { throw new ArgumentException("Cannot add a node to itself as a child.", "child"); } if (child.parent != null) { throw new ArgumentException("Node is already used in another tree.", "child"); } if (child.IsFrozen) { throw new ArgumentException("Cannot add a frozen node.", "child"); } AddChildUnsafe(child, role); }
protected void SetChildByRole <T>(JsTreeRole <T> role, T newChild) where T : JsNode { if (GetChildByRole(role) is T oldChild) { oldChild.ReplaceWith(newChild); } else { AddChild(newChild, role); } }
public JsNodeCollection(JsNode node, JsTreeRole <T> role) { if (node == null) { throw new ArgumentNullException("node"); } if (role == null) { throw new ArgumentNullException("role"); } this.node = node; this.role = role; }
/// <summary> /// Adds a child without performing any safety checks. /// </summary> internal void AddChildUnsafe(JsNode child, JsTreeRole role) { child.parent = this; child.role = role; if (firstChild == null) { lastChild = firstChild = child; } else { lastChild.nextSibling = child; child.prevSibling = lastChild; lastChild = child; } }
/// <summary> /// Gets the first child with the specified role. /// Returns the role's null object if the child is not found. /// </summary> public T GetChildByRole <T>(JsTreeRole <T> role) where T : JsNode { if (role == null) { throw new ArgumentNullException("role"); } for (var cur = firstChild; cur != null; cur = cur.nextSibling) { if (cur.role == role) { return((T)cur); } } return(null); }
internal void InsertChildBeforeUnsafe(JsNode nextSibling, JsNode child, JsTreeRole role) { child.parent = this; child.role = role; child.nextSibling = nextSibling; child.prevSibling = nextSibling.prevSibling; if (nextSibling.prevSibling != null) { Debug.Assert(nextSibling.prevSibling.nextSibling == nextSibling); nextSibling.prevSibling.nextSibling = child; } else { Debug.Assert(firstChild == nextSibling); firstChild = child; } nextSibling.prevSibling = child; }
public void InsertChildAfter <T>(JsNode prevSibling, T child, JsTreeRole <T> role) where T : JsNode { InsertChildBefore(prevSibling == null ? firstChild : prevSibling.nextSibling, child, role); }
public JsNodeCollection <T> GetChildrenByRole <T>(JsTreeRole <T> role) where T : JsNode { return(new JsNodeCollection <T>(this, role)); }