-
Notifications
You must be signed in to change notification settings - Fork 92
[Version 10.0] Feature support for improved interpolated strings #1552
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
base: draft-10
Are you sure you want to change the base?
Conversation
|
|
||
| For example, $"Hello", $"{cs1}, world!" (given `const string cs1 = $"Hello";`), $"{"Hello," + $"world!"}", and $"xxx{(true ? $"{"X"}" : $"{$"{"Y"}"}")}yyy" are all constant interpolated strings. However, $"{123}" and $"{"abc"}{123.45}" are not. | ||
|
|
||
| For simplicity, the term *ISE* is used throughout this specification to mean either an *interpolated_string_expression* or an *additive_expression* composed entirely of *interpolated_string_expression*s and binary `+` operators. |
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.
Is there a better name than ISE? I refer to it in a number of places.
| public void AppendFormatted(scoped ReadOnlySpan<char> value); | ||
| public void AppendFormatted(string? value); | ||
| public void AppendFormatted(object? value, int alignment = 0, | ||
| string? format = default); | ||
| public void AppendFormatted(scoped ReadOnlySpan<char> value, |
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.
These signatures come from the .NET 10 docs; however, scoped isn't supported until C# V11. Is it simply a matter of removing that keyword from here and then restoring it in V11?
| - Have an accessible method with the signature `void AppendLiteral(string s)`, which is called to process a single interpolated string expression literal segment. | ||
| - Have a set of accessible overloaded methods called `AppendFormatted`, one of which is called to process a single interpolation, based on that interpolation’s content. Their signatures are, as follows: |
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.
Re the handler constructor and the AppendLiteral and AppendFormatted methods, I’ve required that they be accessible rather than public. Is that OK?
This is Rex's adaptation of the following: MS proposal and MS proposal. As the first is trivial and defines a term that is used by the second, Rex combined the two into this one PR.
Rex decided that the minimum set of members a robust handler must have are, as follows: one constructor having two
intparameters, methodAppendLiteral, aToStringmethod to get at the built string, and threeAppendFormattedmethods, so that handler can be called using all interpolated string formats a programmer might throw at it without requiring extra arguments to be passed to the constructor. That is, it can correctly handle formats with or without alignment. I’ve used the default handler member set in this decision. Is this OK?