public override QueryNode Trim() { // Trim depth first List<QueryNode> copy = new List<QueryNode> (Children); foreach (QueryNode child in copy) child.Trim (); if (Keyword == Keyword.Not) { if (ChildCount != 1) { if (Parent != null) { Parent.RemoveChild (this); } else { return null; } } } else { if (ChildCount <= 1) { if (Parent != null) { QueryListNode p = Parent; p.RemoveChild (this); p.TakeChildren (this); } else if (ChildCount == 1) { Children[0].Parent = null; return Children[0]; } } } return this; }