Skip to content

Conversation

@samtrion
Copy link
Contributor

@samtrion samtrion commented Jan 11, 2026

Summary by CodeRabbit

  • New Features

    • Enhanced exception handling for object disposal scenarios across supported .NET versions.
  • Tests

    • Added comprehensive unit test coverage for exception handling validation.

✏️ Tip: You can customize this high-level summary in your review settings.

@samtrion samtrion self-assigned this Jan 11, 2026
@samtrion samtrion added state:ready for merge Indicates that a pull request has been reviewed and approved, and is ready to be merged into the mai type:feature Indicates a new feature or enhancement to be added. labels Jan 11, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 11, 2026

Walkthrough

This PR introduces a conditional polyfill for ObjectDisposedException.ThrowIf methods targeting .NET versions earlier than 7.0, along with comprehensive unit tests validating the implementation's behavior with object instances, Type parameters, and null inputs.

Changes

Cohort / File(s) Summary
Polyfill Implementation
src/NetEvolve.Arguments/ObjectDisposedExceptionPolyfills.cs
New conditional polyfill class guarded by #if !NET7_0_OR_GREATER providing two ThrowIf overloads: one accepting an object instance and another accepting a Type parameter, both annotated with [DoesNotReturnIf(true)]
Unit Tests
tests/NetEvolve.Arguments.Tests.Unit/ObjectDisposedExceptionPolyfillsTests.cs
New test class with eight test methods covering ThrowIf behavior across object instances, Type parameters, null inputs, and disposed flags; includes a private DisposableTestClass fixture

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A polyfill hops into place,
For older .NET targets' space,
Exception helpers, swift and true,
Tests confirm the whole thing through,
Disposal safety, version-aware! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a polyfill for ObjectDisposedException with ThrowIf methods, which matches the new public class and methods introduced in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/NetEvolve.Arguments.Tests.Unit/ObjectDisposedExceptionPolyfillsTests.cs (1)

71-90: Disposed flag tests demonstrate real-world usage pattern.

These tests effectively show the intended usage of ThrowIf with an IsDisposed property.

Note: In line 84, using var combined with an explicit Dispose() call results in double-disposal. This is safe here since DisposableTestClass.Dispose() is idempotent, but you could alternatively remove the using keyword in this specific test since the explicit Dispose() is the intent.

Optional: Remove `using` to avoid double-dispose
     [Test]
     public void ThrowIf_WithDisposedFlag_WhenDisposed_ThrowsObjectDisposedException()
     {
-        using var disposable = new DisposableTestClass();
+        var disposable = new DisposableTestClass();
         disposable.Dispose();

         void Act() => ObjectDisposedException.ThrowIf(disposable.IsDisposed, disposable);

         _ = Assert.Throws<ObjectDisposedException>(Act);
     }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 3d45cb7 and 0cc130c.

📒 Files selected for processing (2)
  • src/NetEvolve.Arguments/ObjectDisposedExceptionPolyfills.cs
  • tests/NetEvolve.Arguments.Tests.Unit/ObjectDisposedExceptionPolyfillsTests.cs
🔇 Additional comments (9)
src/NetEvolve.Arguments/ObjectDisposedExceptionPolyfills.cs (4)

1-12: File setup and class declaration look correct.

The preprocessor guard for !NET7_0_OR_GREATER correctly limits this polyfill to older .NET versions. The System namespace placement is intentional to mirror the native API.

One minor observation: the CA1034 suppression for "Nested types should not be visible" may be unnecessary since the C# 13 extension block is not a traditional nested type. Consider verifying if this suppression is actually triggered by analyzers.


14-27: ThrowIf with object instance implementation is correct.

The logic properly checks the condition and delegates to the helper method. The [DoesNotReturnIf(true)] attribute correctly informs the compiler about the control flow.


29-40: ThrowIf with Type implementation is correct.

Mirrors the object overload appropriately. The implementation matches the .NET 7+ API behavior.


42-55: Private helper methods handle null correctly.

The null-conditional operators (instance?.GetType().FullName and type?.FullName) ensure graceful handling when null is passed, matching the native .NET behavior where ObjectDisposedException.ObjectName returns an empty string for null object names.

tests/NetEvolve.Arguments.Tests.Unit/ObjectDisposedExceptionPolyfillsTests.cs (5)

7-16: Test correctly validates exception throwing with object instance.

The test properly verifies that ObjectDisposedException is thrown and that ObjectName contains the full type name.


18-26: Test validates non-throwing path.

Correctly verifies that when condition is false, no exception is thrown and the instance remains valid.


28-47: Type overload tests are comprehensive.

Both true and false condition paths are properly tested for the Type parameter overload.


49-69: Null input tests correctly verify edge case behavior.

These tests validate that passing null for either instance or type results in ObjectName being an empty string, which matches the .NET runtime behavior for ObjectDisposedException constructed with a null object name.


92-97: DisposableTestClass is a clean, minimal test helper.

The implementation is appropriately simple for testing purposes. The IsDisposed property correctly tracks disposal state.

@codecov
Copy link

codecov bot commented Jan 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3d45cb7) to head (0cc130c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #499   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        13    +1     
  Lines           92       100    +8     
  Branches        22        26    +4     
=========================================
+ Hits            92       100    +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samtrion samtrion merged commit 89a45b1 into main Jan 11, 2026
11 checks passed
@samtrion samtrion deleted the feature/objectdisposedexception-throwif branch January 11, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:ready for merge Indicates that a pull request has been reviewed and approved, and is ready to be merged into the mai type:feature Indicates a new feature or enhancement to be added.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants