Skip to content

Improve a few more IList/Collection => IReadOnlyList/Collection checks #116313

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

Merged
merged 1 commit into from
Jun 5, 2025

Conversation

stephentoub
Copy link
Member

No description provided.

@Copilot Copilot AI review requested due to automatic review settings June 4, 2025 17:01
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the type checks for collections by replacing IList/Collection usages with their corresponding IReadOnly interfaces.

  • Updated Task.WhenAll to use IReadOnlyCollection for improved clarity.
  • Modified HttpHeaders and OrderedDictionary to work with IReadOnlyList and IReadOnlyCollection respectively.
  • Added conditional compilation in ImmutableExtensions for adapting to .NET 10+ behavior.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs Changed ICollection to IReadOnlyCollection in WhenAll.
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs Updated IList<string?> to IReadOnlyList<string?> for header value validation.
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs Replaced ICollection with IReadOnlyCollection to get the count from the collection.
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableExtensions.cs Added conditional wrappers for using IList as ordered collections based on .NET version.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

@stephentoub stephentoub merged commit ba462ce into dotnet:main Jun 5, 2025
143 checks passed
@stephentoub stephentoub deleted the morereadonly branch June 5, 2025 03:31
tannergooding added a commit to tannergooding/runtime that referenced this pull request Jun 10, 2025
tannergooding added a commit that referenced this pull request Jun 11, 2025
…y collection interfaces" and related changes (#116497)

* Revert "Improve a few more IList/Collection => IReadOnlyList/Collection checks (#116313)"

This reverts commit ba462ce.

* Revert "Use throw stubs in ref assemblies for collection interfaces (#116309)"

This reverts commit 4e03c5a.

* Revert "Re-revert "Make mutable generic collection interfaces implement read-only collection interfaces (#95830)" (#115802)"

This reverts commit e55370e.
@github-actions github-actions bot locked and limited conversation to collaborators Jul 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants