Filter out non-public types in TextColorToGenerator assembly scanning#3161
Merged
TheCodeTraveler merged 2 commits intoCommunityToolkit:mainfrom Mar 18, 2026
Conversation
The GetMauiInterfaceImplementors method scans all namespace-level types in the Microsoft.Maui.Controls assembly but did not filter by DeclaredAccessibility. This caused it to pick up internal types and generate extension methods referencing them, resulting in CS0122 compile errors in consuming projects. Add a DeclaredAccessibility == Accessibility.Public check so only public types are included in code generation. Fixes CommunityToolkit#3160 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the TextColorToGenerator incremental source generator to avoid generating extension methods for non-public types found while scanning the external Microsoft.Maui.Controls assembly, preventing CS0122 errors in consuming projects.
Changes:
- Filter scanned MAUI types to
DeclaredAccessibility == Accessibility.Publicbefore considering them for code generation.
You can also share your feedback on Copilot code review. Take the survey.
src/CommunityToolkit.Maui.SourceGenerators/Generators/TextColorToGenerator.cs
Show resolved
Hide resolved
Uses a synthetic Microsoft.Maui.Controls assembly with both a public and an internal type implementing ITextStyle + IAnimatable. Asserts that the generator only emits code for the public type. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bijington
approved these changes
Mar 18, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
The
GetMauiInterfaceImplementorsmethod inTextColorToGeneratorscans all namespace-level types in theMicrosoft.Maui.Controlsassembly that implementITextStyleandIAnimatable, but does not filter byDeclaredAccessibility. This causes it to pick upinternaltypes (e.g.,ContentLabel) and generate extension methods referencing them — resulting in CS0122 compile errors in consuming projects.Changes
Added a
DeclaredAccessibility == Accessibility.Publicfilter toGetMauiInterfaceImplementorsso only publicly accessible types from the Maui Controls assembly are included in code generation.This is the only place in the source generators that scans an external assembly's types without an accessibility check. The other generators (
AttachedBindablePropertyAttributeSourceGenerator,BindablePropertyAttributeSourceGenerator,AndroidMediaElementForegroundServiceConfigurationGenerator) use attribute-based targeting and are not affected.Context
ContentLabelto a nested class to hide it from namespace scansFixes #3160