コード例 #1
0
ファイル: VirtualFileTree.cs プロジェクト: solari23/Aegis
        /// <summary>
        /// Retrieves the node at the directory path for the given <see cref="AegisVirtualDirectoryPath"/>.
        /// </summary>
        /// <param name="directoryPath">The directory path to follow.</param>
        /// <param name="createIfNotExists">Flag indicating we should create the node (including all intermediate nodes) if it doesn't exist.</param>
        /// <returns>The node at the directory path specified, or null if it doesn't exist and <paramref name="createIfNotExists"/> is not specified.</returns>
        /// <remarks>The node may not actually contain the file.</remarks>
        private VirtualFileTreeNode GetNodeForDirectoryPath(AegisVirtualDirectoryPath directoryPath, bool createIfNotExists = false)
        {
            var curNode = this.Root;

            int dirDepth;

            for (dirDepth = 0; dirDepth < directoryPath.Components.Length; dirDepth++)
            {
                var dir = new AegisVirtualDirectoryPath(directoryPath.Components.Take(dirDepth + 1));

                if (!curNode.Children.ContainsKey(dir))
                {
                    if (createIfNotExists)
                    {
                        var newChild = new VirtualFileTreeNode(dir, curNode);
                        curNode.Children.Add(dir, newChild);
                    }
                    else
                    {
                        break;
                    }
                }

                curNode = curNode.Children[dir];
            }

            return(dirDepth == directoryPath.Components.Length
                ? curNode
                : null);
        }
コード例 #2
0
ファイル: VirtualFileTree.cs プロジェクト: solari23/Aegis
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualFileTreeNode"/> class.
 /// </summary>
 /// <param name="directory">The virtual directory at this node.</param>
 /// <param name="parent">The parent of this node.</param>
 public VirtualFileTreeNode(AegisVirtualDirectoryPath directory, VirtualFileTreeNode parent)
 {
     this.Directory = directory;
     this.Parent    = parent;
 }