private void DeleteChild(CacheNode root) { // if we're not the root, delete this from the parent if (root.Parent != null) { if (root.Parent?.Children.TryRemove(root.Name, out _) ?? false) {//exists eventHandler.HandleValueRemoved(PathFromRoot(root)); } } else { // we just cleared out the root - so delete all // the children one-by-one (so events fire in proper order) // we're modifying the collection, so ToArray foreach (var child in root.Children.Values.ToArray()) { child.Parent?.Children.TryRemove(child.Name, out _); eventHandler.HandleValueRemoved(PathFromRoot(child)); } } }
public CacheNode(CacheNode parent = null, string name = null, bool created = false) { this.Parent = parent; this.Name = name; this.Created = created; }