Skip to content

Commit 464f47f

Browse files
authored
Fix construction of AsParameters with default constructor (#51582)
1 parent 82ff924 commit 464f47f

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/Http/Http.Extensions/gen/StaticRouteHandlerModel/EndpointParameter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Type is not INamedTypeSymbol namedTypeSymbol ||
171171
EndpointParameters = matchedProperties.Select(matchedParameter => new EndpointParameter(endpoint, matchedParameter.Property, matchedParameter.Parameter, wellKnownTypes));
172172
if (isDefaultConstructor == true)
173173
{
174-
var parameterList = string.Join(", ", EndpointParameters.Select(p => $"{p.LookupName} = {p.EmitHandlerArgument()}"));
174+
var parameterList = string.Join(", ", EndpointParameters.Select(p => $"{p.SymbolName} = {p.EmitHandlerArgument()}"));
175175
AssigningCode = $"new {namedTypeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)} {{ {parameterList} }}";
176176
}
177177
else

src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTests.AsParameters.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ static void TestAction([AsParameters] ParameterListFromQuery args)
7474
Assert.Equal(originalAnotherCustomQueryParam, httpContext.Items["anotherCustomInput"]);
7575
}
7676

77-
[Fact]
78-
public async Task RequestDelegatePopulatesFromHeaderParameter_FromParameterList()
77+
[Theory]
78+
[InlineData("ParameterListFromHeader")]
79+
[InlineData("ParameterListFromHeaderWithProperties")]
80+
public async Task RequestDelegatePopulatesFromHeaderParameter_FromParameterList(string type)
7981
{
8082
const string customHeaderName = "X-Custom-Header";
8183
const int originalHeaderParam = 42;
8284

83-
var source = """
84-
static void TestAction([AsParameters] ParameterListFromHeader args)
85+
var source = $$"""
86+
static void TestAction([AsParameters] {{type}} args)
8587
{
8688
args.HttpContext.Items.Add("input", args.Value);
8789
}

src/Http/Http.Extensions/test/RequestDelegateGenerator/SharedTypes.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,14 @@ public record ParameterListFromQuery(HttpContext HttpContext,
698698
[property: FromQuery(Name = "anotherCustomQuery")] int? AnotherCustomValue = null);
699699
public record ParameterListFromRoute(HttpContext HttpContext, int Value);
700700
public record ParameterListFromHeader(HttpContext HttpContext, [FromHeader(Name = "X-Custom-Header")] int Value);
701+
702+
public record ParameterListFromHeaderWithProperties
703+
{
704+
public HttpContext HttpContext { get; set; }
705+
[FromHeader(Name = "X-Custom-Header")]
706+
public int Value { get; set; }
707+
}
708+
701709
public record ParametersListWithImplicitFromBody(HttpContext HttpContext, TodoStruct Todo);
702710
public record struct TodoStruct(int Id, string Name, bool IsComplete, TodoStatus Status) : ITodo;
703711
public record ParametersListWithExplicitFromBody(HttpContext HttpContext, [FromBody] Todo Todo);

0 commit comments

Comments
 (0)