[Version 10.0] Feature support for improved interpolated strings#1552
Draft
RexJaeschke wants to merge 7 commits intodraft-10from
Draft
[Version 10.0] Feature support for improved interpolated strings#1552RexJaeschke wants to merge 7 commits intodraft-10from
RexJaeschke wants to merge 7 commits intodraft-10from
Conversation
RexJaeschke
commented
Jan 25, 2026
|
|
||
| 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. |
Contributor
Author
There was a problem hiding this comment.
Is there a better name than ISE? I refer to it in a number of places.
RexJaeschke
commented
Jan 25, 2026
Comment on lines
+795
to
+799
| 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, |
Contributor
Author
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?
RexJaeschke
commented
Jan 25, 2026
Comment on lines
+1286
to
+1287
| - 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: |
Contributor
Author
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?