public IEnumerable <FileSystemEntry> EnumFileSystemEntries(string path) { Guard.IsNotNullOrEmpty(path, nameof(path)); if (platform.IsFileExists(path)) { yield return(NewFile(path)); } else if (platform.IsDirectoryExists(path)) { Queue <string> queue = new Queue <string>(256); queue.Enqueue(path); while (queue.Count != 0) { string dirPath = queue.Dequeue(); string[] subDirs = platform.EnumDirectories(dirPath).ToArray(); yield return(NewDirectory(dirPath, subDirs.Length)); foreach (string filePath in platform.EnumFiles(dirPath)) { yield return(NewFile(filePath)); } queue.Enqueue(subDirs); } } else { throw new ArgumentException(nameof(path)); } }