From 7e2cf0e93b028a185cb8a2f9364d944e2d11b135 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 26 Nov 2024 21:30:57 +1100 Subject: [PATCH] avoid Any call in GetCommandAttribute --- .../NuGet.CommandLine/Commands/Command.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/NuGet.Clients/NuGet.CommandLine/Commands/Command.cs b/src/NuGet.Clients/NuGet.CommandLine/Commands/Command.cs index 103b320fe8b..7892357eb45 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/Commands/Command.cs +++ b/src/NuGet.Clients/NuGet.CommandLine/Commands/Command.cs @@ -270,14 +270,16 @@ public virtual void ExecuteCommand() [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "This method does quite a bit of processing.")] public virtual CommandAttribute GetCommandAttribute() { - var attributes = GetType().GetCustomAttributes(typeof(CommandAttribute), true); - if (attributes.Any()) + var type = GetType(); + var attributes = type.GetCustomAttributes(typeof(CommandAttribute), true); + var attribute = attributes.FirstOrDefault(); + if (attribute != null) { - return (CommandAttribute)attributes.FirstOrDefault(); + return (CommandAttribute)attribute; } // Use the command name minus the suffix if present and default description - var name = GetType().Name; + var name = type.Name; var idx = name.LastIndexOf(CommandSuffix, StringComparison.OrdinalIgnoreCase); if (idx >= 0) {