Skip to content

Commit

Permalink
(#2738) Update container registration for .NET 4.8
Browse files Browse the repository at this point in the history
There has been a change in how GetCustomAttribute works between .NET
4.0 and .NET 4.8. Previously, this worked without any problems, but in
.NET 4.8, it errors with a message regarding duplicate types found. In
order to work around this, we make use of GetCustomAttributes and then
filter the list from there, as/when required.
  • Loading branch information
gep13 committed Nov 7, 2022
1 parent 6b115ac commit 80f69dd
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ public void register_assembly_commands(IAssembly assembly)
try
{
var types = assembly.get_loadable_types()
.Where(t => t.IsClass && !t.IsAbstract && typeof(ICommand).IsAssignableFrom(t) && t.GetCustomAttribute<CommandForAttribute>() != null);
.Where(t => t.IsClass &&
!t.IsAbstract &&
typeof(ICommand).IsAssignableFrom(t) &&
t.GetCustomAttributes<CommandForAttribute>().Any()).ToList();

foreach (var t in types)
{
Expand Down Expand Up @@ -114,7 +117,7 @@ public void register_command(Type commandType)
return;
}

var commandForAttribute = commandType.GetCustomAttribute<CommandForAttribute>();
var commandForAttribute = commandType.GetCustomAttributes<CommandForAttribute>().FirstOrDefault();

if (commandForAttribute == null)
{
Expand Down

0 comments on commit 80f69dd

Please sign in to comment.