Uh oh!
There was an error while loading. Please reload this page.
Make Options source gen support Validation attributes having constructor with params Parameter - #91915
Conversation
…tor with params Parameter
ghost
commented
Sep 12, 2023
Tagging subscribers to this area: @dotnet/area-extensions-options Issue DetailsThis change is to support the validation attributes having constructor with This fix need to be ported to rc2.
|
tarekgh
commented
Sep 12, 2023
| { | ||
| validationAttr.ConstructorArguments.Add(GetArgumentExpression(constructorArgument.Type!, constructorArgument.Value)); | ||
| TypedConstant argument = arguments[i]; | ||
| if (argument.Kind == TypedConstantKind.Array) |
There was a problem hiding this comment.
Probably too much of a niche scenario to consider here, but could this logic be tripped up by something like the following?
newMyValidationAttribute(newint[]{1,2,3});publicclassMyValidationAttribute(paramsint[][]values):ValidationAttribute{}There was a problem hiding this comment.
We can consider that in .NET 9.0 as I want to limit the changes, we are porting to .NET 8.0.
There was a problem hiding this comment.
That's actually not a valid attribute parameter type if you want to apply the attribute (could be interesting for testing, but I gather this generator only observes applied attributes).
https://sharplab.io/#v2:D4AQTAjAsAUCDMACciCyBPAagQwDYEsATbAF3wHsA7AQRJICd8AjAVxIFNEAuRWh5tpwDesRGORIMOAsTJU+jVhwAUAB2z1sAWwDOifJRIBtALqnEANzwt2OgJSIhiAL6xXMWEal4ipCjTpFQWVKdgB3fUNzJwgAGkQwePhnOxNYBGQwNHQAFXRVdlgRGHcgA===
error CS0181: Attribute constructor parameter 'values' has type 'int[][]', which is not a valid attribute parameter type
Attribute's parameters need to be represented in metadata and can only take a very limited set of types.
There was a problem hiding this comment.
Good point. I did recall that it's possible to nest arrays in attribute declarations, but it looks like it's only possible for object[] parameters:
I think that case would work fine with the logic as-is, but maybe a test is in order?
There was a problem hiding this comment.
I see this was brought up here as well: #91934 (comment)
tarekgh
commented
Sep 12, 2023
@dotnet-policy-service rerun |
tarekgh
commented
Sep 12, 2023
/backport to release/8.0 |
Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6161762714 |
This change is to support the validation attributes having constructor with
paramskeyword parameter likeDeniedValuesAttributeandAllowedValuesAttribute.This fix need to be ported to rc2.