Skip to content

Commit 9c32305

Browse files
Merge pull request #342 from MariaSolOs/cleaner-command-attr-check
Add cleaner command attribute check
2 parents fe666b2 + a171332 commit 9c32305

File tree

1 file changed

+2
-4
lines changed
  • src/toolkit/Community.VisualStudio.Toolkit.Shared/Commands

1 file changed

+2
-4
lines changed

src/toolkit/Community.VisualStudio.Toolkit.Shared/Commands/BaseCommand.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.ComponentModel.Design;
3-
using System.Linq;
3+
using System.Reflection;
44
using System.Threading.Tasks;
55
using Microsoft;
66
using Microsoft.VisualStudio.Shell;
@@ -34,9 +34,7 @@ public static async Task<T> InitializeAsync(AsyncPackage package)
3434
{
3535
BaseCommand<T> instance = (BaseCommand<T>)(object)new T();
3636

37-
CommandAttribute? attr = (CommandAttribute)instance.GetType().GetCustomAttributes(typeof(CommandAttribute), true).FirstOrDefault();
38-
39-
if (attr is null)
37+
if (instance.GetType().GetCustomAttribute(typeof(CommandAttribute)) is not CommandAttribute attr)
4038
{
4139
throw new InvalidOperationException($"No [Command(GUID, ID)] attribute was added to {typeof(T).Name}");
4240
}

0 commit comments

Comments
 (0)