public IEnumerable <FileSystemInfoBase> Enumerate(string startPath) { Start?.Invoke(this, EventArgs.Empty); CheckPath(startPath); var result = _fileSystem.DirectoryInfo.FromDirectoryName(startPath).EnumerateFileSystemInfos("*", SearchOption.AllDirectories); foreach (var systemInfoBase in result) { ProcessFoundEntry(systemInfoBase); if (Filter != null && !Filter(systemInfoBase)) { continue; } var args = new FilteredFileSystemInfoFound(); //not obvious - should filtered events be raised in case of empty filter? ProcessFilteredEntry(systemInfoBase, args); if (args.IsProcessTerminated) { break; } if (!args.IsExcluded) { yield return(systemInfoBase); } } Finish?.Invoke(this, EventArgs.Empty); }
private void ProcessFilteredEntry(FileSystemInfoBase systemInfoBase, FilteredFileSystemInfoFound args) { var isDirectory = systemInfoBase.Attributes.HasFlag(FileAttributes.Directory); if (isDirectory) { FilteredDirectoryFound?.Invoke(systemInfoBase, args); } else { FilteredFileFound?.Invoke(systemInfoBase, args); } }