Example #1
0
        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);
        }
Example #2
0
        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());
        }
Example #3
0
        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);
        }
Example #4
0
        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);
            }
        }
Example #5
0
        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);
            }
        }