-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Surrogate argument list in Minimal APIs #41325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Surrogate argument list in Minimal APIs #41325
Conversation
src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
Outdated
Show resolved
Hide resolved
BrennanConroy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens with multiple [AsParameters] like
void TestMethod([AsParameters] One, [AsParameters] Two) { }Should a test be added for it?
It will work but I think I missed a test for it. Let me add it. |
Co-authored-by: Brennan <[email protected]>
|
Really good job on this. The PR looks super clean. |
davidfowl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

Closes #40712
This PR will introduce a support for the
[Parameters]attribute. The parameter will be created, based on the on the constructor parameters and/or writable properties, and thenewexpression will be similar to:Parameterless constructor
Where all writable properties will be initialized and included as endpoint parameter.
Parameterized constructor
Where all constructor argument will be included as endpoint parameter. Also, in this case the arguments attributes will be used as primary source for
attributesand fallback to the matching property when nothing defined.Fo all parameters detected the same Bind rules, currently available, will be applied.
Constructor detection mechanism
I have tried to match as much as possible the rules described in spec but some behavior diverges from it. With that, here is how the [Parameter] type constructor is detected.
classinsensitive) public property.InvalidOperationExceptionwill be thrown if deserialization is attempted.InvalidOperationExceptionwhen more than one parameterized is declared and the parameterless constructor is not present.InvalidOperationExceptionif not able to find a correct constructor.structinsensitive) public property.InvalidOperationExceptionwill be thrown if deserialization is attempted.structalways has a default constructor, the default constructor will be used if it is the only one present or more than one parameterized constructor is present.The same rules applied for
records.Examples
Valid
Invalid
Benchmark
Results here: https://gist.github.com/brunolins16/901f351f4db7b14e69e1c58677922dd0