Add CodeFixProvider for SetPropertiesInAnyOrderAnalyzer (PH2134)#951
Add CodeFixProvider for SetPropertiesInAnyOrderAnalyzer (PH2134)#951
Conversation
…ests Co-authored-by: bcollamore <57269455+bcollamore@users.noreply.github.com>
Co-authored-by: bcollamore <57269455+bcollamore@users.noreply.github.com>
|
|
Copilot I didn't provide you enough context. There are already MS tools in the IDE to convert to auto-properties; we don't want to replicate that here. This rule is simply: if the user made a get and a set (for whatever reason), make sure they did the get first, for consistency. So the auto-fixer would simply swap the order of the 2 when there is a finding. |
I need clarification on what should be swapped. The analyzer currently detects when property setters reference other properties (creating order dependencies). When you mention "swap the order of the 2", do you mean:
Could you provide an example of the problematic code and the expected fix after swapping? This will help me implement the correct behavior. |



This PR implements a CodeFixProvider for the SetPropertiesInAnyOrderAnalyzer (PH2134) to automatically resolve property setter order dependencies.
Problem
The SetPropertiesInAnyOrderAnalyzer detects when property setters reference other properties in the same class, which creates order dependencies that users must understand to set properties correctly. Previously, developers had to manually fix these issues without automated assistance.
Solution
Added
SetPropertiesInAnyOrderCodeFixProviderthat automatically converts problematic properties to simple auto-properties, eliminating the order dependency issue.Example transformation:
Implementation Details
SingleDiagnosticCodeFixProvider<AccessorDeclarationSyntax>following the established pattern{ get; set; }Changes Made
New Files:
SetPropertiesInAnyOrderCodeFixProvider.cs- The CodeFix implementationSetPropertiesInAnyOrderCodeFixProviderTest.cs- Comprehensive test suiteUpdated Files:
PH2134.md- Updated documentation to reflect CodeFix availabilityTesting
The CodeFixer provides immediate, automated resolution for PH2134 violations, improving developer productivity and code quality.
Fixes #950.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.