Skip to content
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

New collection type for Url.QueryParams #555

Closed
tmenier opened this issue Sep 29, 2020 · 0 comments
Closed

New collection type for Url.QueryParams #555

tmenier opened this issue Sep 29, 2020 · 0 comments

Comments

@tmenier
Copy link
Owner

tmenier commented Sep 29, 2020

Related to #541

Url.QueryParams has always been backed by an IDictionary<string, object>. While very handy in most cases, inevitably the problem came up of how to deal with this perfectly legitimate scenario:

x=1&x=2&x=3

In order to not introduce a breaking change at the time, I took advantage of the fact that the values are objects and simply returned an array for url.QueryParams["x"]. Checking if it's an array is not only clunky, it's also easy to forget, which could lead to bugs. The new collection types introduced in #541 are better suited for this.

What's breaking

Instead of this:

var x = url.QueryParams["x"]; // is it an array? better check!

You will now do this:

var x = url.QueryParams.FirstOrDefault("x"); // always returns a single value
var xs = url.QueryParams.GetAll("x"); // always returns a collection

With QueryParams["x"] gone it's obviously not writeable anymore either. Use QueryParams.AddOrReplace instead.

What's not breaking

The most typical action involving query params is writing them using fluent methods directly on Url:

url.SetQueryParam
url.SetQueryParams
url.RemoveQueryParam
url.RemoveQueryParams

None of these are changing in semantics or behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant