예제 #1
0
파일: Finder.cs 프로젝트: toddcoder/FGrep
        public IEnumerable <string> FilesByLine(FolderName folder, Func <FindResult, string> mapFunc, int indentLevel = 0)
        {
            var lineMatched = false;

            foreach (var file in folder.Files.Where(MatchedFile))
            {
                foreach (var result in FileLines(file))
                {
                    if (!lineMatched)
                    {
                        FolderMatched?.Invoke(this, new FolderArgs(folder));
                    }

                    var clone = result.Clone();
                    clone.File        = file;
                    clone.IndentLevel = indentLevel;

                    yield return(mapFunc(clone));
                }

                FileMatched?.Invoke(this, new FileArgs(file));
            }

            foreach (var subfolder in folder.Folders)
            {
                foreach (var result in FilesByLine(subfolder, mapFunc, indentLevel + 1))
                {
                    yield return(result);
                }
            }
        }
예제 #2
0
파일: Finder.cs 프로젝트: toddcoder/FGrep
        public IEnumerable <FindResult> MatchedFiles(FolderName sourceFolder, int indentLevel = 0)
        {
            var _folder = none <FolderName>();

            foreach (var file in sourceFolder.Files.Where(MatchedFile))
            {
                if (_folder.If(out var folder))
                {
                    if (folder == file.Folder)
                    {
                        yield return(new FindResult {
                            FileNameExtension = file.NameExtension, IndentLevel = indentLevel
                        });
                    }
                    else
                    {
                        _folder = file.Folder.Some();
                        yield return(new FindResult {
                            Folder = _folder, FileNameExtension = file.NameExtension, IndentLevel = indentLevel
                        });

                        FolderMatched?.Invoke(this, new FolderArgs(file.Folder));
                    }
                }

                FileMatched?.Invoke(this, new FileArgs(file));
            }

            foreach (var subfolder in sourceFolder.Folders)
            {
                foreach (var result in MatchedFiles(subfolder, indentLevel + 1))
                {
                    yield return(result);
                }
            }
        }