Skip to content

Conversation

@halter73
Copy link
Member

@halter73 halter73 commented Mar 4, 2023

Fixes #46338

halter73 added 2 commits March 3, 2023 18:51
# Conflicts:
#	src/Http/Http.Extensions/gen/RequestDelegateGenerator.cs
#	src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs
#	src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitSource_SimpleReturn_Snapshot.generated.txt
#	src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleComplexTypeParam_StringReturn.generated.txt
#	src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleEnumParam_StringReturn.generated.txt
#	src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_SingleTimeOnlyParam_StringReturn.generated.txt
#	src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/Multiple_MapAction_NoParam_StringReturn.generated.txt
#	src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateGeneratorTests.cs
Copy link
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, although the analyzer seems to have now lost its support to warn about not implementing BindAsync as an alternative to TryParse ... seems intentional though - interested to understand the reasoning behind that.

public class Customer
{
public async static Task<Customer> BindAsync(HttpContext context)
public async static ValueTask<Customer> BindAsync(HttpContext context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the intention for this test was to fail due to the return type of BindAsync being Task<T> and not ValueTask<T>

return parameterTypeSymbol;
}

static DiagnosticDescriptor SelectDescriptor(Parsability parsability, Bindability bindability)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you introducing a new analyzer here? I thought that we wanted to cover parsability and bindability detection in that analyzer?

{
// Change this to true and run tests in development to regenerate baseline files.
// Then: cp artifacts/bin/Microsoft.AspNetCore.Http.Extensions.Tests/Debug/net8.0/RequestDelegateGenerator/Baselines/* src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines
public bool RegenerateBaselines => false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good addition. In the CompareLines(...) method we should probably add logic ignore lines with the code analysis attribute so that when folks follow the instruction above they then don't need to do a regex/replace on the attributes with the %%...%%.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... I see you've taken care of this below :)

using System.Text;

namespace Microsoft.AspNetCore.Analyzers.Infrastructure;
internal enum Parsability
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete file?

SymbolEqualityComparer.Default.Equals(methodSymbol.Parameters[1].Type, wellKnownTypes.Get(WellKnownType.System_Reflection_ParameterInfo)) &&
methodSymbol.ReturnType is INamedTypeSymbol returnType &&
IsReturningValueTaskOfT(returnType, typeSymbol, wellKnownTypes);
IsReturningValueTaskOfTOrNullableT(returnType, typeSymbol, wellKnownTypes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about this! :)

@captainsafia captainsafia merged commit 46a3d2b into main Mar 6, 2023
@captainsafia captainsafia deleted the halter73/46338 branch March 6, 2023 22:26
@ghost ghost added this to the 8.0-preview3 milestone Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support parameter binding for types that implement BindAsync

4 participants