diff --git a/src/Microsoft.ComponentDetection.Common/PatternMatchingUtility.cs b/src/Microsoft.ComponentDetection.Common/PatternMatchingUtility.cs index dc6cda863..43d932f13 100644 --- a/src/Microsoft.ComponentDetection.Common/PatternMatchingUtility.cs +++ b/src/Microsoft.ComponentDetection.Common/PatternMatchingUtility.cs @@ -61,7 +61,7 @@ public sealed class CompiledMatcher private readonly string[] patterns; public CompiledMatcher(IEnumerable patterns) - : this(patterns is string[] arr ? arr : (patterns ?? throw new ArgumentNullException(nameof(patterns))).ToArray()) + : this(ToArray(patterns)) { } @@ -72,6 +72,12 @@ internal CompiledMatcher(string[] patterns) ValidatePatternElements(this.patterns); } + private static string[] ToArray(IEnumerable patterns) + { + ArgumentNullException.ThrowIfNull(patterns); + return patterns as string[] ?? patterns.ToArray(); + } + public bool IsMatch(ReadOnlySpan fileName) => GetFirstMatchingPattern(fileName, this.patterns) is not null; ///