Skip to content

Commit

Permalink
Merge pull request #342 from MariaSolOs/cleaner-command-attr-check
Browse files Browse the repository at this point in the history
Add cleaner command attribute check
  • Loading branch information
madskristensen authored Jun 1, 2022
2 parents fe666b2 + a171332 commit 9c32305
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,9 +34,7 @@ public static async Task<T> InitializeAsync(AsyncPackage package)
{
BaseCommand<T> instance = (BaseCommand<T>)(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}");
}
Expand Down

0 comments on commit 9c32305

Please sign in to comment.