Fix Blazor [Parameter] public code fix handling of multiple access modifiers#67365
Merged
dariatiurina merged 4 commits intoJun 25, 2026
Merged
Conversation
…ifier handling ComponentParametersShouldBePublicCodeFixProvider was modifying the SyntaxTokenList while iterating, causing attempts to remove beyond the first to fail, leaving resulting code in wrong state with likely compiler errors
Contributor
|
Thanks for your PR, @damyanpetev. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the Blazor analyzer code fix (BL0004) that updates [Parameter] properties to public so it correctly handles members that have multiple access modifiers (e.g., private protected, protected internal) without leaving behind an extra access modifier that would produce invalid code.
Changes:
- Reworked the code fix modifier rewrite logic to build a fresh
SyntaxTokenListstarting withpublicand then re-add only non-access modifiers. - Added regression tests covering valid multi-access-modifier cases and a mixed-modifier case (
protected new internal) to ensure non-access modifiers are preserved. - Applied the same fix and tests in both the in-box analyzers and the SDK analyzers copies.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Components/Analyzers/src/ComponentParametersShouldBePublicCodeFixProvider.cs | Rebuilds modifier list to remove all access modifiers and insert public reliably. |
| src/Components/Analyzers/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs | Adds coverage for multi-access-modifier parameter properties and preservation of new. |
| src/Tools/SDK-Analyzers/Components/src/ComponentParametersShouldBePublicCodeFixProvider.cs | Mirrors the same modifier list rebuild fix for the SDK analyzers variant. |
| src/Tools/SDK-Analyzers/Components/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs | Mirrors the same multi-modifier regression tests for the SDK analyzers variant. |
4 tasks
dariatiurina
approved these changes
Jun 23, 2026
dariatiurina
left a comment
Contributor
There was a problem hiding this comment.
This is amazing! Thank you so much for your work! 💕
Open
3 tasks
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.
Fix Blazor
[Parameter]public code fix handling of multiple access modifiersChanged to logic to rebuild the
newModifierscollection with.Add()and filtering out existing access modifiers to avoid modification issues of the existing.Remove()use with more than one access modifier.Description
ComponentParametersShouldBePublicCodeFixProvider was modifying the SyntaxTokenList while iterating, causing attempts to remove beyond the first to fail, leaving resulting code in wrong state with likely compiler errors.
The came from looking at the comment about
private public protected int Foo { get; set; }which unfortunately, besides sitting on an IDEModifiers are not orderedIDE0036warning, is causing anMore than one protection modifierCS0107so I can't really get that scenario to even trigger the code fix. While it'll likely fix it fine, I've removed the comment since the refactored logic no longer needs the explanation.Fixes #67364