Skip to content

[Version 10.0] Feature support for improved interpolated strings#1552

Draft
RexJaeschke wants to merge 8 commits into
draft-v10from
v10-improved-interpolated-dtrings
Draft

[Version 10.0] Feature support for improved interpolated strings#1552
RexJaeschke wants to merge 8 commits into
draft-v10from
v10-improved-interpolated-dtrings

Conversation

@RexJaeschke

Copy link
Copy Markdown
Contributor

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 int parameters, method AppendLiteral, a ToString method to get at the built string, and three AppendFormatted methods, 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?

@RexJaeschke RexJaeschke added this to the C# 10 milestone Jan 25, 2026
@RexJaeschke RexJaeschke added type: feature This issue describes a new feature Review: pending Proposal is available for review labels Jan 25, 2026
@RexJaeschke
RexJaeschke marked this pull request as draft January 25, 2026 19:34
Comment thread standard/expressions.md

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.

Copy link
Copy Markdown
Contributor Author

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.

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,

Copy link
Copy Markdown
Contributor Author

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?

Comment thread standard/attributes.md
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:

Copy link
Copy Markdown
Contributor Author

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?

@BillWagner
BillWagner force-pushed the v10-improved-interpolated-dtrings branch 2 times, most recently from b8a0760 to 132bae5 Compare March 24, 2026 20:47
@BillWagner
BillWagner force-pushed the v10-improved-interpolated-dtrings branch 2 times, most recently from 75120e0 to 96e9bce Compare April 14, 2026 18:13
BillWagner added a commit that referenced this pull request Apr 15, 2026
@BillWagner
BillWagner force-pushed the v10-improved-interpolated-dtrings branch from 96e9bce to 3e3b2a1 Compare May 13, 2026 14:57
@BillWagner
BillWagner force-pushed the v10-improved-interpolated-dtrings branch from 3e3b2a1 to cf3a744 Compare June 24, 2026 19:49
@BillWagner

Copy link
Copy Markdown
Member

An earlier version of this feature is already present on alpha-v10 from a prior meeting. Edits made to this PR since then are not yet on alpha-v10; they will land at the next propagation. If you need them on alpha-v10 sooner, please open a separate PR targeting alpha-v10.
Thanks!

RexJaeschke and others added 8 commits July 24, 2026 15:51
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.
@BillWagner
BillWagner force-pushed the v10-improved-interpolated-dtrings branch from cf3a744 to 9f4549d Compare July 24, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review: pending Proposal is available for review type: feature This issue describes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants