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
Add StringValues operator+
#52507
Comments
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue DetailsBackground and MotivationCurrently if appending a value to a headers.ContentLanguage = StringValues.Concat(headers.ContentLanguage, requestCulture.UICulture.Name); Overloading headers.ContentLanguage += requestCulture.UICulture.Name; Proposed APIPlease provide the specific public API signature diff that you are proposing. For example: namespace Microsoft.Extensions.Primitives
{
public readonly partial struct StringValues
{
public static StringValues operator +(StringValues left, StringValues right);
public static StringValues operator +(string left, StringValues right);
public static StringValues operator +(StringValues left, string right);
public static StringValues operator +(string[] left, StringValues right);
public static StringValues operator +(StringValues left, string[] right);
}
} RisksCurrently headers.ContentLanguage += requestCulture.UICulture.Name; Will compile; however it will implicitly convert the However; hopeful no-one is doing that as it will append the add in an incorrect way.
|
Do we have a precedent for using the |
So the following using System;
using Microsoft.Extensions.Primitives;
StringValues values = "hello";
values = StringValues.Concat(values, "world");
Console.WriteLine(values);
values += "how";
Console.WriteLine(values); Complies and outputs
Which is no use to anyone, whereas it would be better if it output
|
IMO, that's the issue with having implicit operators. They do unexpected things. I'm not sure if doing more unorthodox things is the right fix. |
Currently, it's not at all clear exactly how a new value should be added to a
Response.Headers.Vary.Append(HeaderNames.Referer); The API in this regard is in dire need of some refinement. There are even comments in the ASP.NET Core codebase itself pointing out these very same unexpected quirks when it comes to adding things to |
Background and Motivation
Currently if appending a value to a
StringValues
you need to use the staticConcat
method:Overloading
operator+
would allow it to be much cleanerProposed API
Please provide the specific public API signature diff that you are proposing. For example:
Risks
Currently
Will compile; however it will implicitly convert the
StringValues
to astring
add the twostring
s and then implictly convert back to a single valueStringValue
.However; hopefully no-one is doing that as it will append the add in an incorrect way.
The text was updated successfully, but these errors were encountered: