Skip to content

Add MethodInfo.CreateDelegate<TDelegate> polyfills - #144

Merged
Tyrrrz merged 5 commits into
primefrom
copilot/add-polyfill-for-create-delegate
Oct 3, 2026
Merged

Tyrrrz merged 5 commits into
primefrom
copilot/add-polyfill-for-create-delegate

Conversation

Copilot AI commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

.NET 5 introduced generic overloads for MethodInfo.CreateDelegate<TDelegate>() and MethodInfo.CreateDelegate<TDelegate>(object?), which were missing from the polyfill set.

Polyfill

  • Added PolyShim/Net50/MethodInfo.cs with extension members CreateDelegate<TDelegate>() and CreateDelegate<TDelegate>(object? target) on MethodInfo, constrained to where TDelegate : Delegate.
  • Delegates to the instance CreateDelegate(Type[, object]) methods on frameworks that support them, and falls back to the static Delegate.CreateDelegate overloads on .NET Framework versions prior to 4.5, which lack the instance methods.

Tests

  • Added PolyShim.Tests/Net50/MethodInfoTests.cs covering both the parameterless and the object-target overloads.

Docs

  • Regenerated Signatures.md to include the new MethodInfo entries.
var method = typeof(Math).GetMethod(nameof(Math.Max), [typeof(int), typeof(int)])!;
var max = method.CreateDelegate<Func<int, int, int>>();
max(2, 3); // 3

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@Tyrrrz Tyrrrz added the enhancement New feature or request label Oct 3, 2026
@Tyrrrz
Tyrrrz marked this pull request as ready for review October 3, 2026 10:12
Copilot AI balanced review requested due to automatic review settings October 3, 2026 10:12
Comment thread PolyShim/Net50/MethodInfo.cs Outdated
@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.71%. Comparing base (8af065d) to head (a1ebe73).
⚠️ Report is 1 commits behind head on prime.

Additional details and impacted files
@@            Coverage Diff             @@
##            prime     #144      +/-   ##
==========================================
+ Coverage   87.65%   87.71%   +0.05%     
==========================================
  Files         339      341       +2     
  Lines        7389     7406      +17     
  Branches      539      539              
==========================================
+ Hits         6477     6496      +19     
+ Misses        744      742       -2     
  Partials      168      168              

☔ View full report in Codecov by Harness.
📢 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The tests lack the namespace import required to compile against the polyfill on net472.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Adds .NET 5 generic MethodInfo.CreateDelegate<TDelegate> polyfills for older targets.

Changes:

  • Implements both generic delegate-creation overloads.
  • Adds tests and updates generated signatures.
File Description
Signatures.md Documents the new members.
PolyShim/​Net50/​MethodInfo.cs Implements the polyfills.
PolyShim.Tests/​Net50/​MethodInfoTests.cs Tests both overloads.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread PolyShim.Tests/Net50/MethodInfoTests.cs
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot AI requested a review from Tyrrrz October 3, 2026 10:20
Comment thread PolyShim/Net50/MethodInfo.cs Outdated
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot AI requested a review from Tyrrrz October 3, 2026 10:24
@Tyrrrz

Tyrrrz commented Oct 3, 2026

Copy link
Copy Markdown
Owner

@copilot remove namespace declarations from both polyfill files. They should not need a using directive to use. Update the test file accordingly.

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

Copilot AI commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot remove namespace declarations from both polyfill files. They should not need a using directive to use. Update the test file accordingly.

Removed the namespace declarations, added the source-level reflection imports needed to resolve MethodInfo, and removed using System.Reflection from the test file in a1ebe73.

Copilot AI requested a review from Tyrrrz October 3, 2026 10:43
@Tyrrrz
Tyrrrz merged commit 17e32b3 into prime Oct 3, 2026
7 checks passed
@Tyrrrz
Tyrrrz deleted the copilot/add-polyfill-for-create-delegate branch October 3, 2026 10:48
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