Skip to content
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

Add support for TEventArgs without type constraints #285

Merged
merged 4 commits into from
May 22, 2019

Conversation

AArnott
Copy link
Member

@AArnott AArnott commented May 22, 2019

Add support for proxy generated clients with event handlers that take args that do not derive from EventArgs.

History lesson: From .NET 2.0 to 4.0, the EventHandler<T> delegate type had a type constraint of T : EventArgs, meaning that the second parameter that the event handler takes must derive from `EventArgs. In .NET 4.5, this type constraint was dropped. Apparently they consider this a non-breaking change. But when dealing with code gen and reflection, all bets are off. :)

Not realizing this, my event wiring code assumed that deriving from EventArgs was a guarantee. As a result, when a user defines an event typed as EventHandler<T> where T does not derive from EventArgs, we would fail.

This PR fixes it. Supporting T : class was as easy as changing EventArgs to object in my event handler. But to support T : struct required that I bring in a generic method.

Fixes #284

AArnott added 4 commits May 21, 2019 20:32
It no longer has to derive from EventArgs, but it must still be a reference type. Value types are not yet supported.
@AArnott AArnott added this to the v1.5 milestone May 22, 2019
@AArnott AArnott requested review from ikeras and jepetty May 22, 2019 03:19
@AArnott AArnott self-assigned this May 22, 2019
@AArnott AArnott merged commit 15975af into microsoft:v1.5 May 22, 2019
@AArnott AArnott deleted the fix284 branch May 22, 2019 19:17
AArnott added a commit to AArnott/vs-streamjsonrpc that referenced this pull request Jun 20, 2019
When the delegate's generic type argument is not used directly as the 2nd parameter type in the event handler delegate, a NotSupportedException was thrown starting with pull request microsoft#285.

Fixes microsoft#292
AArnott pushed a commit that referenced this pull request Oct 30, 2024
Bumps [dotnet-coverage](https://github.com/microsoft/codecoverage) from 17.11.5 to 17.12.2.
- [Commits](https://github.com/microsoft/codecoverage/commits)

---
updated-dependencies:
- dependency-name: dotnet-coverage
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants