-
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
Add ToString and PrintMembers to records #3762
Conversation
} | ||
} | ||
``` | ||
|
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.
Extra newline.
Co-authored-by: Fred Silberberg <[email protected]>
Co-authored-by: Fred Silberberg <[email protected]>
Co-authored-by: Fred Silberberg <[email protected]>
proposals/csharp-9.0/records.md
Outdated
It is an error if the method is declared explicitly. | ||
|
||
The method: | ||
1. appends a separator ", " to `builder` if `includeSeparator` is true and the record has public fields or properties, |
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.
this feels unneeded. why not just always include a trailing comma. then you have the consistent, copyable:
Person
{
Name = "Julien",
Age = 99,
}
THat's extremely ick. Should we be taking a page from Go's book here: |
proposals/csharp-9.0/records.md
Outdated
|
||
The record includes a synthesized method equivalent to a method declared as follows: | ||
```C# | ||
public override string ToString(); | ||
``` | ||
|
||
The method can be declared explicitly. It is an error if the explicit declaration does not match the expected signature or accessibility, or if the explicit declaration doesn't allow overiding it in a derived type and the record type is not `sealed`. It is an error if the method doesn't override a method with this signature in the record `Base` (for example, if the method is missing in the `Base`, or sealed, or not virtual, etc.). | ||
The method can be declared explicitly. It is an error if the explicit declaration does not match the expected signature or accessibility, or if the explicit declaration doesn't allow overiding it in a derived type and the record type is not `sealed`. It is an error if either synthesized, or explicitly declared method doesn't override `object.ToString()` (for example, due to shadowing in intermediate base types, etc.). |
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.
The method can be declared explicitly. It is an error if the explicit declaration does not match the expected signature or accessibility, or if the explicit declaration doesn't allow overiding it in a derived type and the record type is not `sealed`. It is an error if either synthesized, or explicitly declared method doesn't override `object.ToString()` (for example, due to shadowing in intermediate base types, etc.). | |
The method can be declared explicitly. It is an error if the explicit declaration does not match the expected signature or accessibility, or if the explicit declaration doesn't allow overiding it in a derived type and the record type is not `sealed`. It is an error if either synthesized or explicitly declared method doesn't override `object.ToString()` (for example, due to shadowing in intermediate base types, etc.). |
FYI, I'm going to revert to a speakable print method. Unspeakable print methods would throw a big wrench in our ability to derive records from classes. That seems unnecessary. I'll update the spec this afternoon. Tagging @dotnet/roslyn-compiler |
That's a very good point, thanks Julien. |
I'll merge this spec change shortly. The unresolved follow-up questions were added to the records test plan. Thanks for the review
|
@dotnet/roslyn-compiler for review. This is a proposal for shape of ToString synthesized members.