Beispiel #1
0
        /// <summary>
        /// Adds the item to this list.
        /// </summary>
        /// <param name="item">The item to add.</param>
        public void Add(NefsItem item)
        {
            // Create a container for the item
            var container = new ItemContainer(item);

            // Check if in the root directory
            if (item.DirectoryId == item.Id)
            {
                // Add to root list
                this.rootItems.Add(item.FileName, container);
            }
            else
            {
                // Find parent
                if (!this.itemsById.ContainsKey(item.DirectoryId))
                {
                    throw new ArgumentException($"The item's parent id {item.DirectoryId} does not exist. The parent must be added to the list before the child.");
                }

                var parentContainer = this.itemsById[item.DirectoryId];
                parentContainer.Children.Add(item.FileName, container);
                container.Parent = parentContainer;
            }

            // Add to master list
            this.itemsById.Add(item.Id, container);
        }
Beispiel #2
0
 public ItemContainer(NefsItem item)
 {
     this.Item = item;
 }
 public ItemContainer(NefsItem item)
 {
     this.Items = new List <NefsItem> {
         item
     };
 }