[Version 10.0] Feature support for improved interpolated strings#1552
[Version 10.0] Feature support for improved interpolated strings#1552RexJaeschke wants to merge 8 commits into
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.
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.
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.
Re the handler constructor and the AppendLiteral and AppendFormatted methods, I’ve required that they be accessible rather than public. Is that OK?
b8a0760 to
132bae5
Compare
75120e0 to
96e9bce
Compare
96e9bce to
3e3b2a1
Compare
3e3b2a1 to
cf3a744
Compare
|
An earlier version of this feature is already present on |
In conversions, restore the IFormattable/FormattableString conversion about the new handler paragraph. Both are valie. In expression, update Better conversion bullets to prefer the handler-preference rules, then the existing rules under a "does not exactly match" bullet. Fix typo in 12.83. Add a bullet in 12.83 to target the IFormattable/Formattable string conversion around the handler.
cf3a744 to
9f4549d
Compare
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?