Skip to content

Add polyfills for System.Collections.Generic.CollectionExtensions#113

Merged
Tyrrrz merged 14 commits intoprimefrom
copilot/add-polyfills-for-collectionextensions
Apr 17, 2026
Merged

Add polyfills for System.Collections.Generic.CollectionExtensions#113
Tyrrrz merged 14 commits intoprimefrom
copilot/add-polyfills-for-collectionextensions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

Adds polyfills covering the missing members of CollectionExtensions across .NET versions.

New polyfills

.NET Core 2.0 (NetCore20/CollectionExtensions.cs)

  • IDictionary<TKey,TValue>.TryAdd(key, value)
  • IDictionary<TKey,TValue>.Remove(key, out value)

.NET 5.0 (Net50/IReadOnlySet.cs)

  • IReadOnlySet<T> interface

.NET 7.0 (Net70/CollectionExtensions.cs)

  • IList<T>.AsReadOnly()ReadOnlyCollection<T>
  • IDictionary<TKey,TValue>.AsReadOnly()ReadOnlyDictionary<TKey,TValue>

.NET 8.0 (Net80/CollectionExtensions.cs)

  • List<T>.AddRange(ReadOnlySpan<T>)
  • List<T>.InsertRange(int, ReadOnlySpan<T>) — delegates to List<T>.InsertRange(IEnumerable<T>) for O(n) complexity
  • List<T>.CopyTo(Span<T>)

.NET 9.0 (Net90/ReadOnlySet.cs)

  • ReadOnlySet<T> — wraps ISet<T>, implements IReadOnlySet<T>

.NET 10.0 (Net100/CollectionExtensions.cs)

  • ISet<T>.AsReadOnly()ReadOnlySet<T>

Copilot AI and others added 2 commits April 17, 2026 06:58
…nlySet, AddRange, InsertRange, CopyTo)

Agent-Logs-Url: https://github.com/Tyrrrz/PolyShim/sessions/9885706c-31a6-4c46-9b44-82b59b776ef5

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 17, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 17, 2026 07:02
Copilot AI review requested due to automatic review settings April 17, 2026 07:02
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 17, 2026

@copilot getting build errors

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 17, 2026

@copilot getting build errors

Fixed in 75889a5[ExcludeFromCodeCoverage] is not valid on interface declarations in older C# language versions (CS0592). Removed it from IReadOnlySet<T>, matching the pattern used by other interface polyfills in the repo (e.g. IAsyncDisposable, IValueTaskSource).

Copilot AI requested a review from Tyrrrz April 17, 2026 07:09
Copy link
Copy Markdown
Contributor

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

Adds new polyfills for missing System.Collections.Generic.CollectionExtensions members across older TFMs, including span-based List<T> helpers, AsReadOnly() helpers, and ReadOnlySet<T> / IReadOnlySet<T> support (plus a C# 14 extension-resolution bridge for .NET 5–9).

Changes:

  • Add IDictionary<TKey,TValue>.TryAdd() and Remove(key, out value) polyfills for older TFMs.
  • Add .NET 5-era AsReadOnly() polyfills for IList<T> / IDictionary<TKey,TValue> and introduce IReadOnlySet<T>.
  • Add .NET 8-era span-based List<T> polyfills and .NET 9/10 ReadOnlySet<T> + ISet<T>.AsReadOnly() polyfills (with a C# 14 bridge on .NET 5+).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
PolyShim/NetCore20/CollectionExtensions.cs Adds TryAdd and Remove(key, out value) extension member polyfills for IDictionary.
PolyShim/Net80/CollectionExtensions.cs Adds span-based List<T> extension member polyfills (AddRange, InsertRange, CopyTo).
PolyShim/Net50/IReadOnlySet.cs Introduces IReadOnlySet<T> polyfill for non-.NET 5+ TFMs.
PolyShim/Net50/CollectionExtensions.cs Adds AsReadOnly() polyfills for IList<T> and IDictionary<TKey,TValue>.
PolyShim/Net90/ReadOnlySet.cs Adds ReadOnlySet<T> implementation for pre-.NET 9 TFMs.
PolyShim/Net100/CollectionExtensions.cs Adds ISet<T>.AsReadOnly() and C# 14 resolution bridge for AsReadOnly() overloads on .NET 5+.
PolyShim.Tests/NetCore20/CollectionExtensionsTests.cs Adds tests for TryAdd/Remove(key, out) behavior.
PolyShim.Tests/Net80/CollectionExtensionsTests.cs Adds tests for span-based List<T> polyfills.
PolyShim.Tests/Net50/CollectionExtensionsTests.cs Adds tests for AsReadOnly() on IList<T>/IDictionary<TKey,TValue>.
PolyShim.Tests/Net100/CollectionExtensionsTests.cs Adds tests for ISet<T>.AsReadOnly() / ReadOnlySet<T> behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PolyShim/Net70/CollectionExtensions.cs
Comment thread PolyShim/Net70/CollectionExtensions.cs
Comment thread PolyShim.Tests/Net100/CollectionExtensionsTests.cs Outdated
Comment thread PolyShim.Tests/Net70/CollectionExtensionsTests.cs
Comment thread PolyShim.Tests/Net70/CollectionExtensionsTests.cs
Copilot AI requested a review from Tyrrrz April 17, 2026 07:56
Comment thread PolyShim.Tests/Net80/CollectionExtensionsTests.cs Outdated
Comment thread PolyShim.Tests/NetCore20/CollectionExtensionsTests.cs Outdated
Comment thread PolyShim.Tests/Net70/CollectionExtensionsTests.cs Outdated
Copilot AI requested a review from Tyrrrz April 17, 2026 08:07
Comment thread PolyShim.Tests/Net80/CollectionExtensionsTests.cs Outdated
Copilot AI requested a review from Tyrrrz April 17, 2026 08:12
Comment thread PolyShim/Net100/CollectionExtensions.cs Outdated
Comment thread PolyShim/Net50/IReadOnlySet.cs Outdated
Comment thread PolyShim/Net70/CollectionExtensions.cs Outdated
…llectionExtensions.cs

Agent-Logs-Url: https://github.com/Tyrrrz/PolyShim/sessions/733dace9-cebe-4aa5-ba99-6ecf278ef2cc

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
…-bodied extension methods

Agent-Logs-Url: https://github.com/Tyrrrz/PolyShim/sessions/80f3ffae-446a-4985-bb82-99b181547214

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 95.08197% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.66%. Comparing base (8ff8470) to head (f3fa29e).
⚠️ Report is 1 commits behind head on prime.

Files with missing lines Patch % Lines
PolyShim/Net90/ReadOnlySet.cs 45.45% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            prime     #113      +/-   ##
==========================================
+ Coverage   90.64%   90.66%   +0.02%     
==========================================
  Files         275      282       +7     
  Lines        4776     4898     +122     
  Branches      394      401       +7     
==========================================
+ Hits         4329     4441     +112     
- Misses        358      367       +9     
- Partials       89       90       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 17, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/PolyShim/PolyShim/PolyShim.Tests/bin/Debug/net10.0/PolyShim.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/PolyShim/PolyShim/PolyShim.Tests/bin/Debug/net10.0/PolyShim.Tests.deps.json /home/REDACTED/work/PolyShim/PolyShim/PolyShim.Tests/bin/Debug/net10.0/testhost.dll --port 35633 --endpoint 127.0.0.1:035633 --role client --parentprocessid 4154 --datacollectionport 0 --telemetryoptedin false (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/PolyShim/PolyShim/PolyShim.Tests/bin/Debug/net10.0/PolyShim.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/PolyShim/PolyShim/PolyShim.Tests/bin/Debug/net10.0/PolyShim.Tests.deps.json /home/REDACTED/work/PolyShim/PolyShim/PolyShim.Tests/bin/Debug/net10.0/testhost.dll --port 36239 --endpoint 127.0.0.1:036239 --role client --parentprocessid 4372 --datacollectionport 0 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Tyrrrz Tyrrrz merged commit 063563c into prime Apr 17, 2026
7 checks passed
@Tyrrrz Tyrrrz deleted the copilot/add-polyfills-for-collectionextensions branch April 17, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants