-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API Proposal: C# 10 interpolated strings support, part 3 #51962
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @tannergooding Issue DetailsBackground and MotivationPart 1 and part 2 added APIs to support the improved interpolated string literal feature in C# 10. After a bit more design in the space, we want to make a few minor changes to the names and add a new attribute to help improve the authoring and usage experience for users. The general driving goal here was to standardize the names builder types use. It is expected that our guidance to API authors will be "Your interpolated string builder types should start with the words Updated API:
|
Author: | 333fred |
---|---|
Assignees: | - |
Labels: |
|
Milestone: | - |
Does |
That would be helpful, wouldn't it 😅 |
I don't really see much use in this API. The user can do all that themselves and execute the methods whenever they want. Do you have any use-case scenarios where this would be simpler or more efficient that you could share with us? |
I would suggest reading through the linked part one and two proposals, and the language feature they are here to support. Most of these apis will not be used directly by consumers. |
LDM met today, and rejected the idea of |
One thing which would be really useful to include in this proposal is some way of splitting string format into constant literals. Currently the string.Format parsing is encapsulated in ValueStringBuilder.AppendFormatHelper. If we can make it public or at least some part of it it would be beneficial. |
After a long discussion we think the best convention we'll come up with is the suffix "InterpolatedStringHandler" Therefore, the renames should be
The attribute is otherwise good as proposed namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
public sealed class InterpolatedStringHandlerAttribute : Attribute
{
public InterpolatedStringHandlerAttribute()
{
}
}
} |
For what it's worth, the |
We previously decided this was MemoryExtensions+InterpolatedTryWriteBuilder. So should it now be MemoryExtensions+TryWriteInterpolatedStringHandler, or was the switch back to "Span" intentional?
We'd already previously decided this StringBuilder+InterpolatedAppendBuilder, so, yes, it should now be StringBuilder+AppendInterpolatedStringHandler. |
If we did that's my fault, as I missed the rename. So yes, it should by TryWrite instead of Span. |
Thanks for catching the clerical errors, @stephentoub. I went ahead and updated the "AppendFormat" and "Span" entries to have their correctly agreed upon elements used with the current pattern. |
@stephentoub, could you mark this as 6.0.0 or 7.0.0 as appropriate? |
Background and Motivation
Part 1 and part 2 added APIs to support the improved interpolated string literal feature in C# 10. After a bit more design in the space, we want to make a few minor changes to the names and add a new attribute to help improve the authoring and usage experience for users.
The general driving goal here was to standardize the names builder types use. It is expected that our guidance to API authors will be "Your interpolated string builder types should start with the words
InterpolatedString
and end withBuilder
". This convention will help make it clearer for users when something is a valid builder type.Updated API:
InterpolatedStringDefaultBuilder
We rename
InterpolatedStringBuilder
toInterpolatedStringDefaultBuilder
. This is being done to avoid confusion with the new attribute.Proposed API:
InterpolatedStringBuilderAttribute
This attribute marks a type as being a valid builder type. This is a change from the existing proposal, where the validity of the conversion was being determined from doing a bunch of overload resolution. This should make errors more sane and helpful to end users.
Open question: Should we allow this on interfaces as well? With abstract statics in interfaces, it would theoretically be possible to use type parameter constrained to an interface as a builder type, but that would only be valid if the interface can be attributed with this.
We then update the structs defined in Parts 1 and 2 as follows, to add the attribute and also standardize the naming of the other struct types with the rules mentioned above:
The text was updated successfully, but these errors were encountered: