Skip to content

[C#] Deduplicate OnDisposeCall and improve implementation#626

Merged
stephentoub merged 2 commits intomainfrom
copilot/deduplicate-ondisposecall
Mar 2, 2026
Merged

[C#] Deduplicate OnDisposeCall and improve implementation#626
stephentoub merged 2 commits intomainfrom
copilot/deduplicate-ondisposecall

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

  • Explore both ActionDisposable in Client.cs and OnDisposeCall in Session.cs
  • Verify build/test baseline
  • Create ActionDisposable.cs as a standalone file with the better implementation from Client.cs
  • Remove ActionDisposable class definition from Client.cs
  • Replace OnDisposeCall usage in Session.cs with ActionDisposable
  • Build and test — build passes; all test failures are pre-existing (missing tsx in sandbox)
  • Code review and security scan — no issues found

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…t.cs and Session.cs

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
@stephentoub stephentoub changed the title [WIP] Deduplicate OnDisposeCall and improve implementation [C#] Deduplicate OnDisposeCall and improve implementation Mar 2, 2026
@stephentoub stephentoub marked this pull request as ready for review March 2, 2026 14:01
@stephentoub stephentoub requested a review from a team as a code owner March 2, 2026 14:01
Copilot AI review requested due to automatic review settings March 2, 2026 14:01
Copy link
Contributor

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 deduplicates disposable-helper implementations in the .NET SDK by centralizing the “run an action on dispose” pattern into a single reusable type, and switching Session’s event unsubscription to use it.

Changes:

  • Introduced a standalone ActionDisposable helper with a thread-safe, idempotent Dispose() implementation.
  • Removed the duplicated ActionDisposable implementation from Client.cs.
  • Replaced Session’s private OnDisposeCall with ActionDisposable for handler unsubscription.

Reviewed changes

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

File Description
dotnet/src/Session.cs Uses ActionDisposable to unsubscribe event handlers and removes the now-redundant private disposable type.
dotnet/src/Client.cs Removes the inline ActionDisposable definition now that it’s centralized.
dotnet/src/ActionDisposable.cs Adds the shared ActionDisposable implementation for use across the .NET SDK.

@stephentoub stephentoub enabled auto-merge March 2, 2026 14:10
@stephentoub stephentoub added this pull request to the merge queue Mar 2, 2026
Merged via the queue into main with commit cb94df9 Mar 2, 2026
30 checks passed
@stephentoub stephentoub deleted the copilot/deduplicate-ondisposecall branch March 2, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants