-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[API Proposal]: HttpRequestOptions should implement IReadOnlyDictionary #68149
Comments
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsBackground and motivationMethods and extension methods that don't modify a dictionary often expect a parameter of API Proposalnamespace System.Net.Http
{
public class HttpRequestOptions : IReadOnlyDictionary<string,object>
{
[...]
}
} API Usagevar dic = (IReadOnlyDictionary<string,object>)request.Options; Alternative DesignsNo response RisksIn rare circumstances, a method will have an overload for IDictionary and another overload for IReadOnlyDictionary. This would be ambiguous for HttpRequestOptions, as it is for other dictionaries.
|
Tagging subscribers to this area: @dotnet/ncl Issue DetailsBackground and motivationMethods and extension methods that don't modify a dictionary often expect a parameter of API Proposalnamespace System.Net.Http
{
public class HttpRequestOptions : IReadOnlyDictionary<string,object>
{
[...]
}
} API Usagevar dic = (IReadOnlyDictionary<string,object>)request.Options; Alternative DesignsNo response RisksIn rare circumstances, a method will have an overload for IDictionary and another overload for IReadOnlyDictionary. This would be ambiguous for HttpRequestOptions, as it is for other dictionaries.
|
Triage: |
Looks good as proposed. We discussed the risks inherent to being both IDictionary and IReadOnlyDictionary (namely, being an ambiguous target for overloading). But we generally think that the risk is low, and the workaround (casting to one of the two interfaces) is easy. namespace System.Net.Http
{
public class HttpRequestOptions :
+ IReadOnlyDictionary<string,object>,
IDictionary<string, object>
{
}
} |
* Added IReadOnlyDictionary to HttpRequestOptions Closes #68149 * Added test for new methods * Added negative scenario to HttpRequestOptionsTest Co-authored-by: Stephen Toub <stoub@microsoft.com> --------- Co-authored-by: Stephen Toub <stoub@microsoft.com>
Background and motivation
Methods and extension methods that don't modify a dictionary often expect a parameter of
IReadOnlyDictionary
instead ofIDictionary
.API Proposal
API Usage
Alternative Designs
No response
Risks
In rare circumstances, a method will have an overload for IDictionary and another overload for IReadOnlyDictionary. This would be ambiguous for HttpRequestOptions, as it is for other dictionaries.
The text was updated successfully, but these errors were encountered: