-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
Better collection type for dictionary-like things where duplicate keys are possible #541
Comments
After the official version 3.0 is released, will you update the new document on https://flurl.dev? |
@mincasoft yes, docs will be updated with the full release. |
As of 3.0-pre4, this is now used for a couple things:
I considered using it for |
As noted in #553, headers names are case-insensitive (https://stackoverflow.com/a/5259004/62600) but names in this collection aren't. Since the new collection type is also used for query strings (#555) and internally for cookies, both of which should be case-sensitive, let's add a constructor arg to make the type work either way. |
Collection type updated with case-sensitivity switch, applied as follows:
This is in 3.0 prerelease 6. |
A common problem has arisen with things like query parameters, request/response headers, and cookies:
IDictionary<string, T>
feels like the perfect interface, except that duplicate keys, while uncommon, are technically allowed in all cases. That's a bummer, because it could mean replacing something simple like:with something more messy like:
Flurl is all about reducing keystrokes so I want to do something better than this, and standardize on it throughout the library where it seems appropriate. After scanning the collections landscape, nothing fit quite right out of the box, so I've arrived at something custom based on
IList<ValueTuple>
with a few additional methods optimized for the most common case.IReadOnlyNameValuleList<TValue>
Inherits from
IReadOnlyList<(string Name, TValue Value)>
and adds the following methods:INameValuleList<TValue>
Inherits from
IList<(string Name, TValue Value)>
, includes all methods above, and adds the following methods:In the test suite and actual library code, these interfaces seemed to pass the "feel test" of being about as easy to use as dictionaries for the common cases while not hiding the fact that you're dealing with the "first" item of a given name, not necessarily the only one.
I'm experimenting with these types for headers and cookies first; query params may come later. Once things are a little more set in stone, I'll update this issue with the specific breaking changes, which should be expected in the final 3.0 release.
The text was updated successfully, but these errors were encountered: