Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Introduce StringValues to replace string[] usage. #378

Merged
merged 2 commits into from
Aug 28, 2015

Conversation

Tratcher
Copy link
Member

#361

Open issues:

  • Name and location of the package containing StringValues. It needs to make sense to reference even from Microsoft.Net.Http.Server (WebListener's low level API without Asp.Net dependencies). Microsoft.AspNet.Primitives is just a placeholder.

Related breaking changes:

  • IHeaderDictionary:
    • Removal of AppendValues, Get_, and Set_
    • Append now functions like AppendValues instead of AppendCommaSeperatedValues.
  • IReadableStringCollection
    • Removal of Get*, use the indexer instead.

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

@Tratcher Tratcher self-assigned this Aug 21, 2015
@Tratcher Tratcher added this to the 1.0.0-beta8 milestone Aug 21, 2015
@dougbu
Copy link
Member

dougbu commented Aug 21, 2015

@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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

@Tratcher
Copy link
Member Author

@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; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member Author

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.

@Tratcher
Copy link
Member Author

Offline review notes:

Rename AspNet.Primitives -> Framework.Primitives

Add StringValues.ToArray() for explicit typing (instead of casting), mirrors ToString

IHeaderDictionary:

  • Move to extension methods:
    • StringValues GetCommaSeparatedValues(string key); - Return IList<string>
    • void Append(string key, StringValues value);
    • void AppendCommaSeparatedValues(string key, params string[] values);
    • void SetCommaSeparatedValues(string key, params string[] values);

var values = headers.GetValues(name);
if (values == null || !values.Any())
var values = headers[name];
if (StringValues.IsNullOrEmpty(values))
Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ IsNullOrEmpty

@Tratcher
Copy link
Member Author

Updated.

@Tratcher
Copy link
Member Author

@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)
Copy link
Contributor

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

Copy link
Member Author

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;

Copy link
Contributor

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

@Tratcher
Copy link
Member Author

Offline :shipit: from @lodejard

@davidfowl
Copy link
Member

it is time :shipit:

@Tratcher Tratcher force-pushed the tratcher/stringvalues branch from ce4587a to 59b44a4 Compare August 28, 2015 19:14
@lodejard
Copy link
Contributor

Finally found some cellular data! :shipit:

@Tratcher Tratcher merged commit 59b44a4 into dev Aug 28, 2015
@Tratcher Tratcher deleted the tratcher/stringvalues branch August 28, 2015 20:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants