/// <summary> /// Remove a child element from this element /// </summary> /// <param name="element"></param> public void Remove(Element element) { if (children != null && element != null && element.parent == this) { children.Remove(element); ResetParent(element); } }
/// <summary> /// Set parent to null /// </summary> /// <param name="element"></param> protected void ResetParent(Element element) { element.parent = null; }
/// <summary> /// Add a child element to this element /// </summary> /// <param name="element"></param> public void Add(Element element) { if (element == null) throw new ArgumentNullException(); if (element.parent != null) throw new InvalidOperationException("element.parent"); SetParentToThis(element); if (children == null) children = new List<Element>(); children.Add(element); }
/// <summary> /// Set the parent of <paramref name="element"/> to this /// </summary> /// <param name="element"></param> protected void SetParentToThis(Element element) { element.parent = this; }