protected internal void RemoveItem(FileSystemItem item) { if (item.HasHardLink) { throw new ApplicationException(String.Format("Can't remove '{0}' because there are hard links pointing to.", item.GetFullPath())); } foreach (FsLink lnk in item.GetLinks()) { ((FsContainer)lnk.Parent).RemoveItem(lnk); } if (item is FsContainer) { List <FileSystemItem> lstToRemove = new List <FileSystemItem>(); foreach (KeyValuePair <Int64, FileSystemItem> kv in ((FsContainer)item)._itemsById) { lstToRemove.Add(kv.Value); } foreach (FileSystemItem it in lstToRemove) { RemoveItem(it); } } _itemsById.Remove(item.ID); _itemsByName.Remove(item.SearchedName); Owner.UnregisterItem(item); item.Owner = null; item.Parent = null; }