-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Support for generic sender parameter in EventHandler #28289
Copy link
Copy link
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtimein-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is mergedpartner-impactThis issue impacts a partner who needs to be kept updatedThis issue impacts a partner who needs to be kept updated
Milestone
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtimein-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is mergedpartner-impactThis issue impacts a partner who needs to be kept updatedThis issue impacts a partner who needs to be kept updated
Type
Fields
Give feedbackNo fields configured for issues without a type.
When using event handlers
EventHandlerandEventHandler<TEventArgs>, it is not possible to pass a generic sender to the delegate without writing your own delegate type. There should be a event handler that has a second generic parameter to specify the type of sender.Rationale/Usage
This is a nice-to-have that would reduce the number of custom event handers (that take just a sender and args) by exposing a new delegate, such as
EventHandler<TSender, TEventArgs>.For example, say I had a class with an event that was specific to it and it's derivatives:
With a
EventHandler<TSender, TEventArgs>delegate, the above could turn into:Proposed API
Updates
EventHandlerimplementations, asTEventArgsdoes not have to be of typeEventArgs. The type constraint forTSenderremains asobject.