[OT] C# can do all the interpolated strings now

Steven Schveighoffer schveiguy at gmail.com
Wed Dec 8 14:57:55 UTC 2021


On 12/8/21 5:46 AM, WebFreak001 wrote:
> https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated#compilation-of-interpolated-strings 
> 
> 
>> Beginning with C# 10, when an interpolated string is used, the 
>> compiler checks if the interpolated string is assigned to a type that 
>> satisfies the interpolated string handler pattern
> 
> Usage example: 
> https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/interpolated-string-handler 
> 
> 
> What do you think of these extended interpolated string expressions? I 
> think these would fit well into D, and could give some new motivation 
> now that we have had our interpolated strings DIPs rejected once and 
> withdrawn once.

No, I think the interpolation tuples that Adam and I proposed, and the 
proposal from John and Andrei are much simpler and straightforward.

Just look at the C# requirements!

"We introduce a new handler pattern that can represent an interpolated 
string passed as an argument to a method. The simple English of the 
pattern is as follows:

When an interpolated_string_expression is passed as an argument to a 
method, we look at the type of the parameter. If the parameter type has 
a constructor that can be invoked with 2 int parameters, literalLength 
and formattedCount, optionally takes additional parameters specified by 
an attribute on the original parameter, optionally has an out boolean 
trailing parameter, and the type of the original parameter has instance 
AppendLiteral and AppendFormatted methods that can be invoked for every 
part of the interpolated string, then we lower the interpolation using 
that, instead of into a traditional call to string.Format(formatStr, args)."

Ugh...

-Steve


More information about the Digitalmars-d mailing list