/// <summary> /// Add a new empty directory node. /// </summary> /// <param name="parentNode"></param> /// <param name="directoryName"></param> public DirectoryFileTreeNode <T> AddToNode(DirectoryFileTreeNode <T> parentNode, string directoryName) { var newNode = parentNode.AddDir(directoryName); Count++; return(newNode); }
/// <summary> /// Adds a new directory based node and initializes it with the specified terminal values. /// </summary> /// <param name="parentNode"></param> /// <param name="terminalValues"></param> public DirectoryFileTreeNode <T> AddToNode(DirectoryFileTreeNode <T> parentNode, string directoryName, IEnumerable <T> terminalValues) { var newNode = parentNode.AddDirWithChildren(directoryName, terminalValues); Count += terminalValues.Count() + 1; return(newNode); }
/// <summary> /// Adds a single node to the parent node. /// </summary> /// <param name="parentNode"></param> /// <param name="value"></param> /// <param name="isDirectory"></param> public DirectoryFileTreeNode <T> AddToNode(DirectoryFileTreeNode <T> parentNode, T value) { var newNode = parentNode.AddChild(value); Count++; return(newNode); }
/// <summary> /// Adds a directory node with the specified terminal values. /// </summary> /// <param name="value"></param> /// <param name="terminalValues"></param> public DirectoryFileTreeNode <T> AddDirWithChildren(string directoryName, IEnumerable <T> terminalValues) { if (IsDirectory) { var newNode = new DirectoryFileTreeNode <T>(directoryName, terminalValues.Select(c => new DirectoryFileTreeNode <T>(c))); _children.Add(newNode); return(newNode); } else { throw new InvalidOperationException("This node is not a directory, can not add children to it!"); } }
/// <summary> /// Adds a new directory based node as a child. /// </summary> /// <param name="directoryName"></param> public DirectoryFileTreeNode <T> AddDir(string directoryName) { if (IsDirectory) { var newNode = new DirectoryFileTreeNode <T>(directoryName); _children.Add(newNode); return(newNode); } else { throw new InvalidOperationException("This node is not a directory, can not add children to it!"); } }
/// <summary> /// Add a sub tree. /// </summary> /// <param name="node"></param> public void AddTree(DirectoryFileTreeNode <T> node) { if (IsDirectory) { if (node == null) { return; } _children.Add(node); } else { throw new InvalidOperationException("This node is not a directory, can not add children to it!"); } }
/// <summary> /// Add a subtree. /// </summary> /// <param name="parentNode"></param> /// <param name="tree"></param> public void AddToNode(DirectoryFileTreeNode <T> parentNode, DirectoryFileTree <T> tree) { parentNode.AddTree(tree.Root); Count += tree.Count; }
public DirectoryFileTree(string rootName) { _root = new DirectoryFileTreeNode <T>(rootName); Count++; }