public MultiTreeNode <TValue, TConnectionWay> AddChild(TValue value, TConnectionWay connectionWay) { var node = root.FindOrCreateNode(value); node.SetParent(this); ChildrenList.Add(node); ConnectionWays.Add(connectionWay); return(node); }
public override void RemoveChild(TValue value) { int index; var nodeToRemove = root.GetNode(value); var removed = false; while ((index = ChildrenList.IndexOf(nodeToRemove)) != -1) { ChildrenList.RemoveAt(index); ConnectionWays.RemoveAt(index); removed = true; } if (!removed) { throw new InvalidOperationException(string.Format("Node '{0}' does not have child '{1}'.", Value, value)); } root.GarbageCollect(); }
public void RemoveChild(TConnectionWay connectionWay, Func <TValue, bool> tester = null) { var connectionWayIndices = ConnectionWays.IndicesOf(connectionWay); var removed = false; foreach (var index in connectionWayIndices.OrderByDescending(x => x)) { if (tester != null && !tester(ChildrenList[index].Value)) { root.GarbageCollect(); return; } ChildrenList.RemoveAt(index); ConnectionWays.RemoveAt(index); removed = true; } if (!removed) { throw new InvalidOperationException(string.Format("Node '{0}' does not have child connected by '{1}'.", Value, connectionWay)); } root.GarbageCollect(); }