-
Notifications
You must be signed in to change notification settings - Fork 192
Introduce StringValues to replace string[] usage. #378
Conversation
@Tratcher note aspnet/Mvc@6331a9c needs to be updated now that @rynowak has pushed aspnet/Mvc@6d365e9 |
{ | ||
myString = new string('a', 40); | ||
myArray = new[] { myString }; | ||
// myValues = new StringValues(myString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??
@dougbu updated: aspnet/Mvc@b42d501 |
@@ -11,7 +11,7 @@ public abstract class WebSocketManager | |||
{ | |||
public abstract bool IsWebSocketRequest { get; } | |||
|
|||
public abstract IList<string> WebSocketRequestedProtocols { get; } | |||
public abstract StringValues WebSocketRequestedProtocols { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an http header with 0-many values.
Offline review notes: Rename AspNet.Primitives -> Framework.Primitives Add StringValues.ToArray() for explicit typing (instead of casting), mirrors ToString IHeaderDictionary:
|
var values = headers.GetValues(name); | ||
if (values == null || !values.Any()) | ||
var values = headers[name]; | ||
if (StringValues.IsNullOrEmpty(values)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this usage shows some of the benefits of the API. Checking for null or !any is pretty annoying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ IsNullOrEmpty
Updated. |
@davidfowl @lodejard Can we get this wrapped up today so we can start pushing it through the other repos? |
|
||
private string[] GetArrayValue() | ||
{ | ||
if (_value != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should probably check for _values == null instead of _value != null. In all of the other methods the _values being null or not is the decision maker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case you still need to check if _value != null because you don't want to do return new[] { _value }; with a null _value:
if (_values == null)
{
if (_value != null)
{
return new[] { _value };
}
}
return _values;
or
if (_value == null)
{
return _values;
}
return new[] { _value };
or
if (_value != null)
{
return new[] { _value };
}
return _values;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dunno, I'd be really nervous about having one method with a different logical order to determine state. It's if values !=null then values, else if value!=null then string[1]{value}, else string[0]
. See also Count property. A comment next to the fields would have been nice, sorry about that :/
Tbh that means the string ctor could really detect "null" and assign values to a string[1]{null}
instead.
That said, it can be refined after the merge, so treat this like a followup remark and keep running with the shipit
Offline from @lodejard |
it is time |
ce4587a
to
59b44a4
Compare
Finally found some cellular data! |
#361
Open issues:
Related breaking changes:
Here are some of the necessary changes in downstream repos. Please use them only as references to evaluate this PR, lets avoid full reviews on them until we have settled open issues on this one.
@lodejard @davidfowl @muratg @rynowak @halter73 @Eilon