public void AddItem(string path, IComposite item) { IComposite composite = this; var names = path.Split('/'); foreach (var name in names) { var child = composite.GetItem(name); if (child == null) { var itemType = item.GetType(); child = (IComposite)Activator.CreateInstance(itemType); child.Name = name; composite.AddItem(child); } composite = child; } composite.AddItem(item); }
public IList <IComposite> GetItems(string path) { IComposite inventory = this; var names = path.Split('/'); foreach (var name in names) { inventory = inventory.GetItem(name); if (inventory == null) { return(new List <IComposite>()); } } return(inventory.GetItems()); }
public void RemoveItems(string path) { IComposite inventory = this; var names = path.Split('/'); foreach (var name in names) { inventory = inventory.GetItem(name); if (inventory == null) { return; } } inventory.Clear(); prune(path); }
public void RemoveItem(string path, IComposite item) { IComposite inventory = this; var names = path.Split('/'); foreach (var name in names) { inventory = inventory.GetItem(name); if (inventory == null) { return; } } inventory.RemoveItem(item); if (inventory.Count < 1) { prune(path); } }
public void RemoveItem(string path, string name) { IComposite inventory = this; var segments = path.Split('/'); foreach (var segment in segments) { inventory = inventory.GetItem(segment); if (inventory == null) { return; } } inventory.RemoveItem(name); if (inventory.Count < 1) { prune(path); } }