Skip to content

Filter out non-public types in TextColorToGenerator assembly scanning#3161

Merged
TheCodeTraveler merged 2 commits intoCommunityToolkit:mainfrom
jfversluis:fix/textcolorto-filter-internal-types
Mar 18, 2026
Merged

Filter out non-public types in TextColorToGenerator assembly scanning#3161
TheCodeTraveler merged 2 commits intoCommunityToolkit:mainfrom
jfversluis:fix/textcolorto-filter-internal-types

Conversation

@jfversluis
Copy link
Copy Markdown
Member

Description

The GetMauiInterfaceImplementors method in TextColorToGenerator scans all namespace-level types in the Microsoft.Maui.Controls assembly that implement ITextStyle and IAnimatable, but does not filter by DeclaredAccessibility. This causes it to pick up internal types (e.g., ContentLabel) and generate extension methods referencing them — resulting in CS0122 compile errors in consuming projects.

Changes

Added a DeclaredAccessibility == Accessibility.Public filter to GetMauiInterfaceImplementors so 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

Fixes #3160

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>
Copilot AI review requested due to automatic review settings March 18, 2026 10:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Public before considering them for code generation.

You can also share your feedback on Copilot code review. Take the survey.

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>
@TheCodeTraveler TheCodeTraveler merged commit df82e31 into CommunityToolkit:main Mar 18, 2026
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextColorToGenerator generates code referencing internal types from Microsoft.Maui.Controls, causing CS0122

4 participants