diff --git a/src/Scaffolding/VS.Web.CG.Core/FilesLocator.cs b/src/Scaffolding/VS.Web.CG.Core/FilesLocator.cs index 322a7d54e..7f5df746b 100644 --- a/src/Scaffolding/VS.Web.CG.Core/FilesLocator.cs +++ b/src/Scaffolding/VS.Web.CG.Core/FilesLocator.cs @@ -27,42 +27,42 @@ public string GetFilePath( string fileName, IEnumerable searchPaths) { - if (fileName == null) + if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(nameof(fileName)); } - if (searchPaths == null) + if (searchPaths?.Any() is bool any && any) { - throw new ArgumentNullException(nameof(searchPaths)); - } - - foreach (var searchPath in searchPaths) - { - if (_fileSystem.DirectoryExists(searchPath)) + foreach (var searchPath in searchPaths) { - var matchingFiles = _fileSystem.EnumerateFiles(searchPath, - searchPattern: fileName, - searchOption: SearchOption.AllDirectories).ToList(); - - if (matchingFiles.Count > 1) + if (_fileSystem.DirectoryExists(searchPath)) { - throw new InvalidOperationException(string.Format( - MessageStrings.MultipleFilesFound, - fileName, - searchPath)); - } - if (matchingFiles.Count == 1) - { - return matchingFiles.Single(); + var matchingFiles = _fileSystem.EnumerateFiles(searchPath, + searchPattern: fileName, + searchOption: SearchOption.AllDirectories).ToList(); + + if (matchingFiles.Count > 1) + { + throw new InvalidOperationException(string.Format( + MessageStrings.MultipleFilesFound, + fileName, + searchPath)); + } + if (matchingFiles.Count == 1) + { + return matchingFiles.Single(); + } } } + + throw new InvalidOperationException(string.Format( + MessageStrings.FileNotFoundInFolders, + fileName, + string.Join(";", searchPaths))); } - throw new InvalidOperationException(string.Format( - MessageStrings.FileNotFoundInFolders, - fileName, - string.Join(";", searchPaths))); + throw new ArgumentNullException(nameof(searchPaths)); } } -} \ No newline at end of file +}