Skip to content

Cast value if it does not match the ParameterType #2791

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pr0s3q
Copy link

@pr0s3q pr0s3q commented Jun 22, 2025

Fix the problem if the build fails due to implicit casting of Params
#2708

@pr0s3q
Copy link
Author

pr0s3q commented Jun 22, 2025

@dotnet-policy-service agree


private ValidationError GetErrorOrDefault(ParameterInstance instance)
{
if (!instance.Definition.ParameterType.IsInstanceOfType(instance.Value))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not convinced that this is sufficient to determine assignability. Test with a property of type byte.

Copy link
Author

Choose a reason for hiding this comment

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

More tests added. All of them are passing the validation check - throwing error if the types are mixed

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a bad test. This should succeed.

[Params(0, 1, 5, 9, 10)]
public byte ParamProperty { get; set; }

This should fail.

[Params(256, -65536)]
public byte ParamProperty { get; set; }

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking the logic to get it correct is probably too complicated for our validators, and we should probably just do nothing here and let the compiler error.

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.

2 participants