Skip to content
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

CompareAttribute won't work on records values #191

Open
Brannos1970 opened this issue Jul 11, 2023 · 1 comment
Open

CompareAttribute won't work on records values #191

Brannos1970 opened this issue Jul 11, 2023 · 1 comment

Comments

@Brannos1970
Copy link

The compare attribute when applied to a record parameter give the error message it is only valid on property or indexers.

Issue:
I was using the compare in a record to validate passwords. The error message was display. When I created a custom comparer and added the flag attributes of Parameter and Fields it resolved the issue.

Proposed Solution:

Add the attribute usage flag "AttributeTargets.Parameter". The AttributeTargets.Fields may also need to be added.

@svick
Copy link

svick commented Jul 16, 2023

This repo is not the right place to report issues, suggest improvements or ask questions about .Net.

That being said, if you want to add an attribute to the property generated from a record primary constructor, you can do it by specifying property: on the attribute, e.g.:

record R([property: Compare("J")] int I, int J);

If you still think CompareAttribute should be changed, the right place to propose that is the dotnet/runtime repo.

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

No branches or pull requests

2 participants