Add C# 14 extension property support for XAML#32898
Draft
StephaneDelcroix wants to merge 4 commits into
Draft
Conversation
This PR adds support for C# 14 extension properties in XAML for both
setting properties and using them in binding sources.
## Changes
### Runtime Inflator (ApplyPropertiesVisitor.cs)
- Added FindExtensionPropertyMethods to search loaded assemblies
- Added TrySetExtensionProperty and TryGetExtensionProperty methods
- Modified TrySetProperty/TryGetProperty to fallback to extension properties
### XamlC Build Tasks (SetPropertiesVisitor.cs)
- Added FindExtensionPropertyMethods using Mono.Cecil
- Added CanSetExtensionProperty, SetExtensionProperty methods
- Added CanGetExtensionProperty, GetExtensionProperty methods
- Generates IL code to call static extension property getter/setter
### SourceGen (SetPropertyHelpers.cs, NodeSGExtensions.cs)
- Added FindExtensionPropertyMethods using Roslyn
- Added CanConvertTo overload for ITypeSymbol
- Added CanSetExtensionProperty and SetExtensionProperty methods
- Note: SourceGen support needs additional integration work
## Usage
Extension properties can now be set directly in XAML:
```xml
<Label MyTag="hello" MyPriority="42" />
```
And used in bindings:
```xml
<Label Text="{Binding Person.FullName}" />
```
Where FullName is a C# 14 extension property on PersonModel.
## Tests
- Added ExtensionProperties.rtxc.xaml tests for setting properties
- Added ExtensionPropertiesBinding.xaml tests for binding scenarios
- All 1778 XAML unit tests pass
- All 99 SourceGen unit tests pass
- Remove nested type check from FindExtensionPropertyMethods (not needed) - Update test comments to explain why SourceGen cannot yet support C# 14 extension members (Roslyn needs to fully lower extension blocks before the semantic model exposes the generated accessor methods)
- Updated FindExtensionProperty to find extension properties directly on static classes (Roslyn exposes them as IPropertySymbol with get_X/set_X accessor methods that take the target type as the first parameter) - Removed ExtensionAttribute requirement since C# 14 extension blocks don't require it in the current Roslyn implementation - Updated tests to use all three inflators ([Values] instead of explicit list) - Renamed ExtensionProperties.rtxc.xaml to ExtensionProperties.xaml All 1783 XAML unit tests pass All 100 SourceGen unit tests pass
…rmance - Cache list of all static types per context (expensive enumeration once) - Cache individual extension property lookups by (targetType, propertyName) - Cache extension property method lookups by (targetType, propertyName) - Use SymbolEqualityComparer for cache key comparison Performance results (Controls.Xaml.UnitTests build): - Before: 27.81s (baseline without extension property feature) - After: 16.78s (~40% faster than baseline) The caching makes the extension property feature actually improve build times because the static type enumeration is now shared across all lookups.
This was referenced May 15, 2026
This was referenced May 23, 2026
Contributor
|
/review -b feature/refactor-copilot-yml |
This comment has been minimized.
This comment has been minimized.
This was referenced May 26, 2026
Contributor
|
/review -b feature/enhanced-reviewer -p windows |
Collaborator
|
|
kubaflo
requested changes
Jun 15, 2026
kubaflo
left a comment
Contributor
There was a problem hiding this comment.
Can you please resolve conflicts?
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.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
This PR adds support for C# 14 extension properties in XAML for both setting properties directly and using them as binding sources.
What are C# 14 extension properties?
C# 14 introduces extension properties, allowing you to define properties that extend existing types:
Changes
Runtime Inflator (ApplyPropertiesVisitor.cs)
FindExtensionPropertyMethodsto search loaded assemblies for extension property getter/setter methodsTrySetExtensionPropertyandTryGetExtensionPropertymethodsTrySetProperty/TryGetPropertyto fallback to extension properties when regular properties are not foundXamlC Build Tasks (SetPropertiesVisitor.cs)
FindExtensionPropertyMethodsusing Mono.Cecil to find extension property methods in referenced assembliesCanSetExtensionProperty,SetExtensionProperty,CanGetExtensionProperty, andGetExtensionPropertymethodsSourceGen (SetPropertyHelpers.cs, NodeSGExtensions.cs)
FindExtensionPropertyMethodsusing Roslyn to find extension property symbolsCanConvertTooverload forITypeSymbolCanSetExtensionPropertyandSetExtensionPropertymethods.rtxc.xamlto skip SourceGen)Usage Examples
Setting Extension Properties from XAML
Using Extension Properties in Bindings
Tests
ExtensionProperties.rtxc.xamltests for setting extension properties from XAMLExtensionPropertiesBinding.xamltests for binding scenariosIssues Fixed
N/A - This is a new feature enabling C# 14 extension properties in XAML.