From 8dc8b14491cd7946c70357e3463d3a8a46f548e0 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sat, 7 Dec 2024 14:40:58 +0100 Subject: [PATCH] Avoid repetitive string.Format call for every character of command-line options (#4264) --- .../CommandLine/CommandLineOption.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOption.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOption.cs index 398da42025..aa3cf47b5e 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOption.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOption.cs @@ -29,9 +29,10 @@ internal CommandLineOption(string name, string description, ArgumentArity arity, Guard.NotNullOrWhiteSpace(description); ArgumentGuard.Ensure(arity.Max >= arity.Min, nameof(arity), PlatformResources.CommandLineInvalidArityErrorMessage); + string errorMessage = string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineInvalidOptionName, name); for (int i = 0; i < name.Length; i++) { - ArgumentGuard.Ensure(char.IsLetterOrDigit(name[i]) || name[i] == '-' || name[i] == '?', nameof(name), string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineInvalidOptionName, name)); + ArgumentGuard.Ensure(char.IsLetterOrDigit(name[i]) || name[i] == '-' || name[i] == '?', nameof(name), errorMessage); } Name = name;