Fix codefix behavior for partial classes with TestCleanup and Dispose in different parts#6164
Fix codefix behavior for partial classes with TestCleanup and Dispose in different parts#6164Evangelink merged 8 commits intomainfrom
Conversation
Co-authored-by: Evangelink <[email protected]>
Evangelink
left a comment
There was a problem hiding this comment.
Please add some test with partials into multiple files
Co-authored-by: Evangelink <[email protected]>
Added multi-file partial class tests in commit 5b91767. The tests cover both scenarios:
These tests validate that the fixer correctly handles partial classes split across multiple files and properly finds the existing Dispose method regardless of which file it's in. |
|
Code fixer needs to be fixed, the tests with partial in different files are failing |
…ixer Co-authored-by: Evangelink <[email protected]>
Co-authored-by: Evangelink <[email protected]>
Fixed the multi-file partial class issue in commit 97a39ad. The fixer now properly handles cases where the Dispose method is in a different file by returning a Solution with changes to both documents rather than trying to edit across files with a single DocumentEditor. |
The
PreferDisposeOverTestCleanupFixerwas incorrectly handling partial classes where aDisposemethod exists in one partial declaration and aTestCleanupmethod exists in another. This resulted in the codefix creating a duplicateDisposemethod, causing compiler error CS0111.Problem
Consider this partial class scenario:
The old fixer logic only searched for
Disposemethods within the current partial class declaration (containingType.Members), so it would not find the existingDisposemethod in the other partial declaration. This caused it to create a newDisposemethod in the second partial class, resulting in:Solution
Updated the fixer to use
typeSymbol.GetMembers("Dispose")which searches across all parts of a partial class. The fix now correctly:Disposemethod in any partial declarationTestCleanupmethod body to the existingDisposemethodTestCleanupmethodResult:
Changes
Disposemethods across all partial class declarations using semantic modelDisposemethods in the same documentFixes #4181.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.