- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.9k
[XSG] simplify OnPlatform #31421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[XSG] simplify OnPlatform #31421
Conversation
There was a problem hiding this 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 implements OnPlatform simplification in the XAML source generator (XSG) when the target platform is known at build time. The change removes OnPlatform markup extensions and replaces them with the appropriate platform-specific values during compilation, which should resolve most remaining issues with XSG and OnPlatform handling.
- Extracts XmlType class to its own file and adds IsOfAnyType helper method
- Adds SimplifyOnPlatformVisitor to the source generation pipeline to replace OnPlatform with platform-specific values
- Updates test infrastructure to support target framework specification for testing platform-specific scenarios
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description | 
|---|---|
| src/Controls/tests/SourceGen.UnitTests/InitializeComponent/SourceGenXamlInitializeComponentTests.cs | Adds targetFramework parameter to RunGenerator method for testing platform-specific code generation | 
| src/Controls/tests/SourceGen.UnitTests/InitializeComponent/SimplifyOnPlatform.cs | New test file validating OnPlatform simplification behavior for Android target | 
| src/Controls/src/Xaml/XmlType.cs | Extracted XmlType class with added IsOfAnyType helper method for type checking | 
| src/Controls/src/Xaml/XamlNode.cs | Removes XmlType class definition (moved to separate file) | 
| src/Controls/src/Xaml/SimplifyOnPlatformVisitor.cs | Updates visitor to use string literals instead of reflection and improves property matching | 
| src/Controls/src/SourceGen/SourceGenContext.cs | Adds TargetPlatform property and modernizes collection initialization | 
| src/Controls/src/SourceGen/NodeSGExtensions.cs | Removes duplicate IsOfAnyType method and uses XmlType.IsOfAnyType instead | 
| src/Controls/src/SourceGen/InitializeComponentCodeWriter.cs | Integrates SimplifyOnPlatformVisitor into the source generation pipeline | 
| src/Controls/src/SourceGen/Controls.SourceGen.csproj | Adds references to SimplifyOnPlatformVisitor and XmlType files | 
| src/Controls/src/Build.Tasks/CompiledConverters/BindablePropertyConverter.cs | Updates to use XmlType.IsOfAnyType method and improves variable declarations | 
        
          
                src/Controls/tests/SourceGen.UnitTests/InitializeComponent/SimplifyOnPlatform.cs
          
            Show resolved
            Hide resolved
        
      c4249ac    to
    02da791      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
02da791    to
    48f3134      
    Compare
  
    
Description of Change
when the target platform is known at build time (always, unless you use net standard), remove the OnPlatform by the actual value.
Issues Fixed
this should fix most of the remaining issues with XSG and OnPlat, but unfortunately we test that on netstandard. so an additional fix is required