Esempio n. 1
0
        private HierarchyMap <T> NavigateTo(string path)
        {
            path ??= ""; // Default to empty string if null
            string[] split = path.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);

            HierarchyMap <T> current = this;

            foreach (string directory in split)
            {
                if (!current.directories.TryGetValue(directory, out current))
                {
                    throw new DirectoryNotFoundException($"No such path: {path}");
                }
            }

            return(current);
        }
Esempio n. 2
0
        // Lists all values in a directory.
        // If recursive == true, also lists values in sub-directories.
        // |path| must end with '/'
        //
        // Examples:
        //   - List("a/b/c/")
        //   - List("a/b/c/", true)
        public IEnumerable <T> List(string path, bool recursive = false)
        {
            HierarchyMap <T> current = NavigateTo(path);
            IEnumerable <T>  list    = current.values.Values;

            if (!recursive)
            {
                return(list);
            }

            foreach (HierarchyMap <T> map in current.directories.Values)
            {
                list = list.Concat(map.List(path, true));
            }

            return(list);
        }