Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static bool ReportFromAttributeDiagnostic(OperationAnalysisContext context, Well

// If it is nullable and we have type arguments, unwrap it.
// The length check aims to alleviate AD0001 warnings when referencing methods in external class libraries that contain parameters
if (parameterTypeSymbol!.ConstructedFrom.SpecialType == SpecialType.System_Nullable_T &&
if (parameterTypeSymbol?.ConstructedFrom.SpecialType == SpecialType.System_Nullable_T &&
parameterTypeSymbol.TypeArguments.Length > 0)
{
parameterTypeSymbol = parameterTypeSymbol.TypeArguments[0] as INamedTypeSymbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,5 +738,28 @@ public class CommercialCustomer : ICustomer
// Act
await VerifyCS.VerifyAnalyzerAsync(source);
}

[Fact]
public async Task Handler_Parameter_WithGenericTypeParameter_Works()
{
// Arrange
var source = """
using Microsoft.AspNetCore.Builder;

var webApp = WebApplication.Create();

static void UseEndpoint<TEndpointInput>(WebApplication app) where TEndpointInput : class
{
app.MapPost("/test", (TEndpointInput data) => { });
}

UseEndpoint<TestEndpointInput>(webApp);

public class TestEndpointInput { }
""";

// Act
await VerifyCS.VerifyAnalyzerAsync(source);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.InternalTesting;
Expand Down Expand Up @@ -30,7 +31,7 @@ public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
=> CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic(descriptor);

/// <inheritdoc cref="AnalyzerVerifier{TAnalyzer, TTest, TVerifier}.VerifyAnalyzerAsync(string, DiagnosticResult[])"/>
public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected)
public static async Task VerifyAnalyzerAsync([StringSyntax("C#-test")] string source, params DiagnosticResult[] expected)
{
var test = new CSharpAnalyzerTest<TAnalyzer, DefaultVerifier>
{
Expand Down
Loading