/// <summary> /// Adds a node to the list of children of this node. /// </summary> public void AddChild( Node child ) { string childName = child.Name; if ( child == this ) throw new ArgumentException( string.Format( "Node '{0}' cannot be added as a child of itself.", childName ) ); if ( childNodes.ContainsKey( childName ) ) throw new ArgumentException( string.Format( "Node '{0}' already has a child node with the name '{1}'.", this.name, childName ) ); child.RemoveFromParent(); childNodes.Add( childName, child ); child.NotifyOfNewParent( this ); }
/// <summary> /// Internal method to remove a child of this node, keeping it in the list of child nodes by option. /// Useful when enumerating the list of children while removing them too. /// </summary> /// <param name="child"></param> /// <param name="removeFromInternalList"></param> protected virtual void RemoveChild( Node child, bool removeFromInternalList ) { CancelUpdate( child ); child.NotifyOfNewParent( null ); if (removeFromInternalList) { childNodes.Remove(child.Name); } }
/// <summary> /// Removes the specifed node as a child of this node. /// </summary> /// <param name="child"></param> public virtual void RemoveChild(Node child) { if (child != null) { CancelUpdate(child); child.NotifyOfNewParent(null); } childNodes.Remove(child.Name); }