From e6bb4ac589f1d875969e1b14eb29f0f276aaf420 Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Fri, 17 Apr 2026 11:24:45 -0700 Subject: [PATCH] chore: use ArgumentNullException.ThrowIfNull where applicable Replace pre-.NET 6 throw new ArgumentNullException(nameof(x)) patterns with ArgumentNullException.ThrowIfNull(x). Sites with custom exception messages are left unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../PatternMatchingUtility.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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; ///