-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Surrogate argument list in Minimal APIs #41325
Conversation
src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
Outdated
Show resolved
Hide resolved
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 <brecon@microsoft.com>
Really good job on this. The PR looks super clean. |
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 thenew
expression 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
attributes
and 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.
class
insensitive
) public property.InvalidOperationException
will be thrown if deserialization is attempted.InvalidOperationException
when more than one parameterized is declared and the parameterless constructor is not present.InvalidOperationException
if not able to find a correct constructor.struct
insensitive
) public property.InvalidOperationException
will be thrown if deserialization is attempted.struct
always 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