Skip to content

Conversation

@RexJaeschke
Copy link
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

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
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
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 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
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?

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