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

EnumerableConditionalWeakTable and WeakEvent #74160

Merged
merged 5 commits into from
Jun 28, 2024
Merged

EnumerableConditionalWeakTable and WeakEvent #74160

merged 5 commits into from
Jun 28, 2024

Conversation

tmat
Copy link
Member

@tmat tmat commented Jun 25, 2024

Refactoring of WeakEvent. Separates a concept of enumerable ConditionalWeakTable from WeakEvent implementation. On .NET EnumerableConditionalWeakTable is just a wrapper for ConditionalWeakTable as it is already enumerable. On .NET Framework we need to implement the enumerability.

Further, because the subscriber of a WeakEvent does not necessarily hold on the target object of the event, we pass the target object to the handler so that it can conveniently access it. To do that we change the event handler delegate to WeakEventHandler that takes both sender and target (as well as args).

Renames existing WeakEventHandler static class to EventHandlerFactory to avoid name collision. The existing WeakEventHandler logic could potentially be used to achieve the same goal as WeakEvent but it imposes constraints on the delegate target to not capture any state. We do not have an analyzer that enforces such requirement. It would also make the subscribers a bit more complicated to implement.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 25, 2024
@tmat tmat marked this pull request as ready for review June 26, 2024 00:51
@tmat tmat requested a review from a team as a code owner June 26, 2024 00:51
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

this LGTM. @sharwell any remaining concerns?

@tmat tmat merged commit b71f6fd into dotnet:main Jun 28, 2024
25 checks passed
@tmat tmat deleted the WeakEvent branch June 28, 2024 19:23
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jun 28, 2024
@RikkiGibson RikkiGibson modified the milestones: Next, 17.12 P1 Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants