From a171332df1a5b8e41d20cf5b74df1f894fa6782b Mon Sep 17 00:00:00 2001 From: Maria Solano Date: Tue, 31 May 2022 16:52:29 -0700 Subject: [PATCH] Add cleaner attribute check --- .../Commands/BaseCommand.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Commands/BaseCommand.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Commands/BaseCommand.cs index 4102f4a..699e933 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Commands/BaseCommand.cs +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Commands/BaseCommand.cs @@ -1,6 +1,6 @@ using System; using System.ComponentModel.Design; -using System.Linq; +using System.Reflection; using System.Threading.Tasks; using Microsoft; using Microsoft.VisualStudio.Shell; @@ -34,9 +34,7 @@ public static async Task InitializeAsync(AsyncPackage package) { BaseCommand instance = (BaseCommand)(object)new T(); - CommandAttribute? attr = (CommandAttribute)instance.GetType().GetCustomAttributes(typeof(CommandAttribute), true).FirstOrDefault(); - - if (attr is null) + if (instance.GetType().GetCustomAttribute(typeof(CommandAttribute)) is not CommandAttribute attr) { throw new InvalidOperationException($"No [Command(GUID, ID)] attribute was added to {typeof(T).Name}"); }