-
Notifications
You must be signed in to change notification settings - Fork 1k
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
positional record can't accept Attribute. #3644
Comments
Perhaps there should be a |
@YairHalberstadt , |
@moh-hassan, you seem to be confusing nominal and positional records. This syntax is a nominal record: record Point
{
[Option]
public int X { get; }
[Option]
public int Y { get; }
} This is a positional record: record Point(int X, int Y); Yair is proposing an additional attribute scope, presumably something like record Point([property: Option]int X, [property: Option]int Y); for the positional case. |
Thanks @333fred for clarification. |
See dotnet/roslyn#44691. I believe the expectation is that attributes will go on the parameter by default but if a |
Net 5 version 5.0.100-rc.1.20452.10 is now supporting positional record with attributes as described by @YairHalberstadt public record Test(
[field: A]
[property: B]
[param: C]
[D]
[property: Option]
int P1
)
{
} |
@moh-hassan is there anything else you were requesting? Or can this be closed? |
@333fred , |
I can confirm that attributes for positional record are implemented in 5.0.100-rc.1.20452.10. No compilation warning in VScode and I can access the attributes at runtime:
@333fred |
Records with attributes can be declared as
Nominal record can be declared as:
Trying to add attribute, like
Compiler raise an exception:
As I see from this doc, there is no limitation on the nominal record.
I'm using Net 5 Preview 5.
How to define attributes for the nominal record?
The text was updated successfully, but these errors were encountered: