diff --git a/src/Immediate.Handlers.Analyzers/InvalidIHandlerAnalyzer.cs b/src/Immediate.Handlers.Analyzers/InvalidIHandlerAnalyzer.cs index 1d3b1ee7..3ea8f0f7 100644 --- a/src/Immediate.Handlers.Analyzers/InvalidIHandlerAnalyzer.cs +++ b/src/Immediate.Handlers.Analyzers/InvalidIHandlerAnalyzer.cs @@ -46,6 +46,12 @@ private void AnalyzeMethod(SymbolAnalysisContext context) if (!type.IsIHandler()) continue; + if (type.TypeArguments[0].TypeKind is TypeKind.TypeParameter + || type.TypeArguments[1].TypeKind is TypeKind.TypeParameter) + { + continue; + } + var hasConcrete = context.Compilation .GetSymbolsWithName("Handler", SymbolFilter.Type, context.CancellationToken) .Any(h => @@ -60,8 +66,8 @@ h is INamedTypeSymbol handler Diagnostic.Create( IHandlerMissingImplementation, parameter.Locations[0], - type.TypeParameters[0].ToDisplayString(), - type.TypeParameters[1].ToDisplayString() + type.TypeArguments[0].ToDisplayString(), + type.TypeArguments[1].ToDisplayString() ) ); } diff --git a/tests/Immediate.Handlers.Tests/AnalyzerTests/InvalidIHandlerAnalyzerTests.cs b/tests/Immediate.Handlers.Tests/AnalyzerTests/InvalidIHandlerAnalyzerTests.cs index 16333d70..818b3989 100644 --- a/tests/Immediate.Handlers.Tests/AnalyzerTests/InvalidIHandlerAnalyzerTests.cs +++ b/tests/Immediate.Handlers.Tests/AnalyzerTests/InvalidIHandlerAnalyzerTests.cs @@ -67,4 +67,31 @@ private static ValueTask HandleAsync( """, DriverReferenceAssemblies.Normal ).RunAsync(); + + [Fact] + public async Task AnalyzerDoesNotTriggerForGenericParameter() => + await AnalyzerTestHelpers.CreateAnalyzerTest( + """ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Net.Http; + using System.Threading; + using System.Threading.Tasks; + using Immediate.Handlers.Shared; + + public static class Test + { + public static void Method(IHandler handler) + { + } + + public static void Method(IHandler handler) + { + } + } + """, + DriverReferenceAssemblies.Normal + ).RunAsync(); }