MA0110: Remove field/variable when generating partial property code fix#1011
Merged
MA0110: Remove field/variable when generating partial property code fix#1011
Conversation
…erty Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix MA0110 to handle variable and field initializers
MA0110: Remove field/variable when code fix generates partial property (C# 14)
Feb 18, 2026
Owner
|
@copilot Some tests are failing |
…for partial property - Use Roslyn Renamer API to rename field/variable to match property name - Add field/variable removal logic for partial property code fix - Only apply removal to fields/variables initialized with new Regex() - Update tests to expect field removal behavior - Fix InvalidCastException from overlapping syntax tree modifications Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Contributor
Author
... Fixed the InvalidCastException in commit ca14f67. The issue was trying to add annotations to overlapping syntax nodes. I've implemented the field/variable removal feature using Roslyn's Renamer API. Currently:
The failing tests involve single-character field names (like |
- Only rename field/variable if it has references outside the declaration - Check if reference nodes are within the declarator before determining rename necessity - Update test expectations to match actual whitespace output (no blank line after field removal) - All 42 MA0110 tests now pass Co-authored-by: meziantou <509220+meziantou@users.noreply.github.com>
Copilot
AI
changed the title
MA0110: Remove field/variable when code fix generates partial property (C# 14)
MA0110: Remove field/variable when generating partial property code fix
Feb 18, 2026
meziantou
approved these changes
Feb 18, 2026
This was referenced Feb 18, 2026
Closed
Closed
This was referenced Feb 27, 2026
Closed
Merged
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When MA0110 applies to a field or variable initialized with
new Regex(), the partial property code fix now removes the declaration and updates all references to use the generated property.Changes
Renamer.RenameSymbolAsyncto update all references when field/variable name differs from generated property nameSyntaxAnnotationto track nodes through tree transformations, fixing previousInvalidCastExceptionIObjectCreationOperation(e.g.,new Regex()), not static method calls likeRegex.IsMatch()Example
Before:
After applying "Use Regex Source Generator (partial property)":
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.