Skip to content

Conversation

Sergio0694
Copy link
Contributor

Fixes #28289

Adds EventHandler<in TSender, in TEventArgs> and updates EventHandler<TEventArgs>.

@Copilot Copilot AI review requested due to automatic review settings May 13, 2025 20:53
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 13, 2025
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 updates the EventHandler delegate implementations by adding the new generic overload with dual type parameters and by enforcing a constraint for ref struct types on TEventArgs.

  • Updates EventHandler to add the constraint "where TEventArgs : allows ref struct".
  • Adds a new delegate EventHandler<TSender, TEventArgs> with corresponding constraints.

Reviewed Changes

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

File Description
src/libraries/System.Runtime/ref/System.Runtime.cs Updated delegate signatures and added the new generic overload with constraints.
src/libraries/System.Private.CoreLib/src/System/EventHandler.cs Updated delegate signatures and constraints; note the outdated comment.
Comments suppressed due to low confidence (1)

src/libraries/System.Private.CoreLib/src/System/EventHandler.cs:7

  • The comment is outdated since the updated delegate now enforces a constraint ('allows ref struct') on TEventArgs. Please update the comment to accurately reflect the current implementation.
public delegate void EventHandler<TEventArgs>(object? sender, TEventArgs e); // Removed TEventArgs constraint post-.NET 4

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 13, 2025
@Sergio0694 Sergio0694 requested a review from tannergooding May 13, 2025 22:06
Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks.

@tannergooding tannergooding merged commit 76fda4d into dotnet:main May 14, 2025
137 of 141 checks passed
@Sergio0694 Sergio0694 deleted the user/sergiopedri/event-handler`2 branch May 14, 2025 02:16
@github-actions github-actions bot locked and limited conversation to collaborators Jun 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community-contribution Indicates that the PR has been added by a community member needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for generic sender parameter in EventHandler
3 participants