private IEnumerable <string> VisitDirectory(string root) { foreach (var file in VisitFiles(root)) { yield return(file); } foreach (var subDirectory in Directory.EnumerateDirectories(root)) { var directoryEventArgs = new DirectoryEventArgs { Path = subDirectory }; OnDirectoryFound(directoryEventArgs); if (directoryEventArgs.Stop) { yield break; } if (!directoryEventArgs.Exclude && _filter(subDirectory)) { var filteredDirectoryEventArgs = new DirectoryEventArgs { Path = subDirectory }; OnFilteredDirectoryFound(directoryEventArgs); if (filteredDirectoryEventArgs.Stop) { yield break; } if (!filteredDirectoryEventArgs.Exclude) { yield return(subDirectory); } } foreach (var item in VisitDirectory(subDirectory)) { yield return(item); } } }
protected virtual void OnFilteredDirectoryFound(DirectoryEventArgs args) { FilteredDirectoryFound?.Invoke(this, args); }