From 1e5ca5b11e377113f4e1036207b9f94c4430386e Mon Sep 17 00:00:00 2001 From: Marvin Huber Date: Wed, 2 Dec 2020 19:26:33 +0100 Subject: [PATCH] Refactored ConfigFileFinder.cs (#786) * use of array initialization * applied format and nicer if flow * added both missing nit nit: prefer braces around ifs * added compersion check for 0 Co-authored-by: John Luo --- src/Microsoft.Tye.Core/ConfigFileFinder.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.Tye.Core/ConfigFileFinder.cs b/src/Microsoft.Tye.Core/ConfigFileFinder.cs index 30b9f195..bc5a2d31 100644 --- a/src/Microsoft.Tye.Core/ConfigFileFinder.cs +++ b/src/Microsoft.Tye.Core/ConfigFileFinder.cs @@ -8,7 +8,7 @@ namespace Microsoft.Tye { public class ConfigFileFinder { - private static readonly string[] FileFormats = new[] { "tye.yaml", "tye.yml", "docker-compose.yaml", "docker-compose.yml", "*.csproj", "*.fsproj", "*.sln" }; + private static readonly string[] FileFormats = { "tye.yaml", "tye.yml", "docker-compose.yaml", "docker-compose.yml", "*.csproj", "*.fsproj", "*.sln" }; public static bool TryFindSupportedFile(string directoryPath, out string? filePath, out string? errorMessage) { @@ -16,19 +16,19 @@ namespace Microsoft.Tye { var files = Directory.GetFiles(directoryPath, format); - if (files.Length == 1) + switch (files.Length) { - errorMessage = null; - filePath = files[0]; - return true; + case 1: + errorMessage = null; + filePath = files[0]; + return true; + case 0: + continue; } - if (files.Length > 1) - { - errorMessage = $"More than one matching file was found in directory '{directoryPath}'."; - filePath = default; - return false; - } + errorMessage = $"More than one matching file was found in directory '{directoryPath}'."; + filePath = default; + return false; } errorMessage = $"No project project file or solution was found in directory '{directoryPath}'.";