Repository navigation
[net11.0] Support C# 14 extension properties in XAML SourceGen - #32898
Conversation
|
/review -b feature/refactor-copilot-yml |
This comment has been minimized.
This comment has been minimized.
|
/review -b feature/enhanced-reviewer -p windows |
This comment has been minimized.
This comment has been minimized.
kubaflo
left a comment
There was a problem hiding this comment.
Can you please resolve conflicts?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
77b97ce to
0b3282f
Compare
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 32898Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 32898" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
A critical setter-resolution flaw can invoke a handwritten lookalike instead of rejecting a private setter, while property-resolution, resource-conversion, and Hot Reload regressions also remain unresolved.
9 open issues
Reject in-parameter lookalikes for inaccessible setters · New Apply extension-property edits during Hot Reload · New Preserve source-generator-provided interface implementations · New Accept unprefixed markup-extension property arguments · New Convert typed-string StaticResource values for extension properties · New StaticResource conversion bypasses the property's type converter String fast path skips the extension property's converter Compare all applicable setters across containers before selecting a receiver Treat interface-to-object conversion as receiver specificity
1 file not reviewed
src/Controls/src/SourceGen/xlf/MauiGResources.Designer.cs: Generated file
Review effort: Balanced
| { | ||
| if (!method.IsStatic || method.DeclaredAccessibility != Accessibility.Public || method.IsGenericMethod) | ||
| continue; | ||
| if (!method.ReturnsVoid || method.Parameters.Length != 2 || method.Parameters[0].RefKind != RefKind.None) |
| if (!asCollectionItem && !attached && !hasBindableProperty && CanSetScopedExtensionProperty(parentVar, propertyName, valueNode, context, out var scopedAccessors, out scopedReported)) | ||
| { | ||
| SetExtensionProperty(writer, parentVar, scopedAccessors!, valueNode, context, getNodeValue); |
| static IPropertySymbol? GetInstanceProperty(ITypeSymbol targetType, string name, SourceGenContext context) | ||
| => targetType.GetAllProperties(name, context) | ||
| .FirstOrDefault(property => targetType.TypeKind == TypeKind.Interface || property.ContainingType.TypeKind != TypeKind.Interface); |
| ambiguous = false; | ||
|
|
||
| //unprefixed attributes carry no namespace, the scope is the default xmlns declared for the element | ||
| if (propertyName.NamespaceURI != string.Empty || node.NamespaceResolver == null) |
| return localVar.Type.InheritsFrom(propertyType, context) | ||
| || (propertyType.IsInterface() && localVar.Type.Implements(propertyType)) | ||
| || propertyType.Equals(context.Compilation.ObjectType, SymbolEqualityComparer.Default) | ||
| || context.Compilation.HasImplicitConversion(localVar.Type, propertyType) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence. 🧪 Unit tests
📄 XAML unit tests
Execution log excerptsWithout fix With fix Without fix With fix PR head: 368d7276. Without-fix baseline: 14c3ea20. |
This comment has been minimized.
This comment has been minimized.
Tests Failure Analysis
🧪 CI Analysis — click to expand📊 maui-prNo failures found. 🧪 maui-pr-devicetestsNo failures found. 🧪 maui-pr-uitestsMatching failures predate the XAML changes; handlers/setup are unchanged. All five target histories are partial.
🧭 Follow-up — actions and refreshNext action: Compare FlexLayout/TitleBar on base/head with identical runtime/OS; inspect screenshots/generated XAML.
|
Preserve the existing MAUIX2020 namespace conflict warning and assign MAUIX2022 to extension property resolution errors, updating regression assertions to avoid a diagnostic ID collision. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Resolved the conflict with Preserved the target’s |
<!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change Adds C# 14 extension-property assignment to the XAML source generator. Extension properties can be used without qualification when their container is in the element's effective default XAML namespace: ```csharp [assembly: XmlnsDefinition( "http://schemas.microsoft.com/dotnet/2021/maui", "MyApp.Extensions")] namespace MyApp.Extensions; public static class LabelExtensions { extension(Label label) { public string MyTag { get; set; } } } ``` ```xml <Label MyTag="hello" /> ``` Containers introduced through MAUI's global XML namespace are also available to XAML documents using that namespace. Explicit qualification remains available for selection and disambiguation: ```xml <Label local:LabelExtensions.MyTag="hello" /> ``` ## Resolution rules - Ordinary events, BindableProperties, and instance properties retain precedence over extension properties. - Unqualified extension properties are discovered only in CLR namespaces mapped from the element's effective default `xmlns`; no global assembly scan is performed. - The container must be a non-generic static class containing a compiler-generated C# extension declaration. - Only the compiler-emitted setter of an actual extension property declaration is called (matching receiver and value type); a hand-written static `set_Name` method is never treated as an accessor. - An accessible instance property or field hides extension properties of the same name even when it cannot be assigned, as in C# (explicitly implemented interface properties hide nothing). - An `[XmlnsDefinition]` only brings its namespace in from the assembly it names. - All applicable setters of all in-scope containers compete together; the unique most-specific receiver wins, independent of declaration or metadata order. - Equal or unrelated applicable candidates produce `MAUIX2021`, including when the ambiguity is inside one container. - An explicitly named extension container that does not define the requested property produces `MAUIX2020` and cannot fall through to an unrelated target property. - Values can come from markup extensions such as `{StaticResource}`, and the extension property's own `[TypeConverter]` is honoured. ## Support matrix | Inflator | Support | |----------|---------| | SourceGen | Supported: unqualified namespace-scoped and explicitly qualified assignment | | XamlC | Not supported | | Runtime XAML inflation | Not supported | XamlC and Runtime retain their existing unresolved-member behavior. Their product code is unchanged by this PR. Direct binding paths such as `{Binding Person.FullName}` remain out of scope. Extension properties are static accessors rather than reflected instance properties and do not define change-notification semantics. ## Tests SourceGen coverage includes: - Default-namespace and global-namespace lookup. - Cross-assembly namespace mappings. - Instance-property precedence. - Most-specific receiver selection across two and three containers, in different declaration orders. - Ambiguous candidates and out-of-scope containers. - Explicit qualification and disambiguation. - Handwritten lookalike accessor rejection. - Qualified property-element compatibility, including `<ContentView.Resources>` on a `ContentPage`. - `{StaticResource}` values, hand-written `set_Name` lookalikes, ambiguity inside one container, unassignable and explicitly implemented instance members, and containers from an unmapped assembly sharing a mapped namespace. Validation after rebasing on `main` (macOS): - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new regression tests fail on the previous generator. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198 passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`, locale-dependent decimal parsing in `CSharpExpressions`, unrelated to this PR). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628 passed, 40 skipped. ### Issues Fixed None (new feature). --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
<!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change Adds C# 14 extension-property assignment to the XAML source generator. Extension properties can be used without qualification when their container is in the element's effective default XAML namespace: ```csharp [assembly: XmlnsDefinition( "http://schemas.microsoft.com/dotnet/2021/maui", "MyApp.Extensions")] namespace MyApp.Extensions; public static class LabelExtensions { extension(Label label) { public string MyTag { get; set; } } } ``` ```xml <Label MyTag="hello" /> ``` Containers introduced through MAUI's global XML namespace are also available to XAML documents using that namespace. Explicit qualification remains available for selection and disambiguation: ```xml <Label local:LabelExtensions.MyTag="hello" /> ``` ## Resolution rules - Ordinary events, BindableProperties, and instance properties retain precedence over extension properties. - Unqualified extension properties are discovered only in CLR namespaces mapped from the element's effective default `xmlns`; no global assembly scan is performed. - The container must be a non-generic static class containing a compiler-generated C# extension declaration. - Only the compiler-emitted setter of an actual extension property declaration is called (matching receiver and value type); a hand-written static `set_Name` method is never treated as an accessor. - An accessible instance property or field hides extension properties of the same name even when it cannot be assigned, as in C# (explicitly implemented interface properties hide nothing). - An `[XmlnsDefinition]` only brings its namespace in from the assembly it names. - All applicable setters of all in-scope containers compete together; the unique most-specific receiver wins, independent of declaration or metadata order. - Equal or unrelated applicable candidates produce `MAUIX2021`, including when the ambiguity is inside one container. - An explicitly named extension container that does not define the requested property produces `MAUIX2020` and cannot fall through to an unrelated target property. - Values can come from markup extensions such as `{StaticResource}`, and the extension property's own `[TypeConverter]` is honoured. ## Support matrix | Inflator | Support | |----------|---------| | SourceGen | Supported: unqualified namespace-scoped and explicitly qualified assignment | | XamlC | Not supported | | Runtime XAML inflation | Not supported | XamlC and Runtime retain their existing unresolved-member behavior. Their product code is unchanged by this PR. Direct binding paths such as `{Binding Person.FullName}` remain out of scope. Extension properties are static accessors rather than reflected instance properties and do not define change-notification semantics. ## Tests SourceGen coverage includes: - Default-namespace and global-namespace lookup. - Cross-assembly namespace mappings. - Instance-property precedence. - Most-specific receiver selection across two and three containers, in different declaration orders. - Ambiguous candidates and out-of-scope containers. - Explicit qualification and disambiguation. - Handwritten lookalike accessor rejection. - Qualified property-element compatibility, including `<ContentView.Resources>` on a `ContentPage`. - `{StaticResource}` values, hand-written `set_Name` lookalikes, ambiguity inside one container, unassignable and explicitly implemented instance members, and containers from an unmapped assembly sharing a mapped namespace. Validation after rebasing on `main` (macOS): - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new regression tests fail on the previous generator. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198 passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`, locale-dependent decimal parsing in `CSharpExpressions`, unrelated to this PR). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628 passed, 40 skipped. ### Issues Fixed None (new feature). --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
<!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change Adds C# 14 extension-property assignment to the XAML source generator. Extension properties can be used without qualification when their container is in the element's effective default XAML namespace: ```csharp [assembly: XmlnsDefinition( "http://schemas.microsoft.com/dotnet/2021/maui", "MyApp.Extensions")] namespace MyApp.Extensions; public static class LabelExtensions { extension(Label label) { public string MyTag { get; set; } } } ``` ```xml <Label MyTag="hello" /> ``` Containers introduced through MAUI's global XML namespace are also available to XAML documents using that namespace. Explicit qualification remains available for selection and disambiguation: ```xml <Label local:LabelExtensions.MyTag="hello" /> ``` ## Resolution rules - Ordinary events, BindableProperties, and instance properties retain precedence over extension properties. - Unqualified extension properties are discovered only in CLR namespaces mapped from the element's effective default `xmlns`; no global assembly scan is performed. - The container must be a non-generic static class containing a compiler-generated C# extension declaration. - Only the compiler-emitted setter of an actual extension property declaration is called (matching receiver and value type); a hand-written static `set_Name` method is never treated as an accessor. - An accessible instance property or field hides extension properties of the same name even when it cannot be assigned, as in C# (explicitly implemented interface properties hide nothing). - An `[XmlnsDefinition]` only brings its namespace in from the assembly it names. - All applicable setters of all in-scope containers compete together; the unique most-specific receiver wins, independent of declaration or metadata order. - Equal or unrelated applicable candidates produce `MAUIX2021`, including when the ambiguity is inside one container. - An explicitly named extension container that does not define the requested property produces `MAUIX2020` and cannot fall through to an unrelated target property. - Values can come from markup extensions such as `{StaticResource}`, and the extension property's own `[TypeConverter]` is honoured. ## Support matrix | Inflator | Support | |----------|---------| | SourceGen | Supported: unqualified namespace-scoped and explicitly qualified assignment | | XamlC | Not supported | | Runtime XAML inflation | Not supported | XamlC and Runtime retain their existing unresolved-member behavior. Their product code is unchanged by this PR. Direct binding paths such as `{Binding Person.FullName}` remain out of scope. Extension properties are static accessors rather than reflected instance properties and do not define change-notification semantics. ## Tests SourceGen coverage includes: - Default-namespace and global-namespace lookup. - Cross-assembly namespace mappings. - Instance-property precedence. - Most-specific receiver selection across two and three containers, in different declaration orders. - Ambiguous candidates and out-of-scope containers. - Explicit qualification and disambiguation. - Handwritten lookalike accessor rejection. - Qualified property-element compatibility, including `<ContentView.Resources>` on a `ContentPage`. - `{StaticResource}` values, hand-written `set_Name` lookalikes, ambiguity inside one container, unassignable and explicitly implemented instance members, and containers from an unmapped assembly sharing a mapped namespace. Validation after rebasing on `main` (macOS): - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new regression tests fail on the previous generator. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198 passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`, locale-dependent decimal parsing in `CSharpExpressions`, unrelated to this PR). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628 passed, 40 skipped. ### Issues Fixed None (new feature). --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
<!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change Adds C# 14 extension-property assignment to the XAML source generator. Extension properties can be used without qualification when their container is in the element's effective default XAML namespace: ```csharp [assembly: XmlnsDefinition( "http://schemas.microsoft.com/dotnet/2021/maui", "MyApp.Extensions")] namespace MyApp.Extensions; public static class LabelExtensions { extension(Label label) { public string MyTag { get; set; } } } ``` ```xml <Label MyTag="hello" /> ``` Containers introduced through MAUI's global XML namespace are also available to XAML documents using that namespace. Explicit qualification remains available for selection and disambiguation: ```xml <Label local:LabelExtensions.MyTag="hello" /> ``` ## Resolution rules - Ordinary events, BindableProperties, and instance properties retain precedence over extension properties. - Unqualified extension properties are discovered only in CLR namespaces mapped from the element's effective default `xmlns`; no global assembly scan is performed. - The container must be a non-generic static class containing a compiler-generated C# extension declaration. - Only the compiler-emitted setter of an actual extension property declaration is called (matching receiver and value type); a hand-written static `set_Name` method is never treated as an accessor. - An accessible instance property or field hides extension properties of the same name even when it cannot be assigned, as in C# (explicitly implemented interface properties hide nothing). - An `[XmlnsDefinition]` only brings its namespace in from the assembly it names. - All applicable setters of all in-scope containers compete together; the unique most-specific receiver wins, independent of declaration or metadata order. - Equal or unrelated applicable candidates produce `MAUIX2021`, including when the ambiguity is inside one container. - An explicitly named extension container that does not define the requested property produces `MAUIX2020` and cannot fall through to an unrelated target property. - Values can come from markup extensions such as `{StaticResource}`, and the extension property's own `[TypeConverter]` is honoured. ## Support matrix | Inflator | Support | |----------|---------| | SourceGen | Supported: unqualified namespace-scoped and explicitly qualified assignment | | XamlC | Not supported | | Runtime XAML inflation | Not supported | XamlC and Runtime retain their existing unresolved-member behavior. Their product code is unchanged by this PR. Direct binding paths such as `{Binding Person.FullName}` remain out of scope. Extension properties are static accessors rather than reflected instance properties and do not define change-notification semantics. ## Tests SourceGen coverage includes: - Default-namespace and global-namespace lookup. - Cross-assembly namespace mappings. - Instance-property precedence. - Most-specific receiver selection across two and three containers, in different declaration orders. - Ambiguous candidates and out-of-scope containers. - Explicit qualification and disambiguation. - Handwritten lookalike accessor rejection. - Qualified property-element compatibility, including `<ContentView.Resources>` on a `ContentPage`. - `{StaticResource}` values, hand-written `set_Name` lookalikes, ambiguity inside one container, unassignable and explicitly implemented instance members, and containers from an unmapped assembly sharing a mapped namespace. Validation after rebasing on `main` (macOS): - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new regression tests fail on the previous generator. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198 passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`, locale-dependent decimal parsing in `CSharpExpressions`, unrelated to this PR). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628 passed, 40 skipped. ### Issues Fixed None (new feature). --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
<!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change Adds C# 14 extension-property assignment to the XAML source generator. Extension properties can be used without qualification when their container is in the element's effective default XAML namespace: ```csharp [assembly: XmlnsDefinition( "http://schemas.microsoft.com/dotnet/2021/maui", "MyApp.Extensions")] namespace MyApp.Extensions; public static class LabelExtensions { extension(Label label) { public string MyTag { get; set; } } } ``` ```xml <Label MyTag="hello" /> ``` Containers introduced through MAUI's global XML namespace are also available to XAML documents using that namespace. Explicit qualification remains available for selection and disambiguation: ```xml <Label local:LabelExtensions.MyTag="hello" /> ``` ## Resolution rules - Ordinary events, BindableProperties, and instance properties retain precedence over extension properties. - Unqualified extension properties are discovered only in CLR namespaces mapped from the element's effective default `xmlns`; no global assembly scan is performed. - The container must be a non-generic static class containing a compiler-generated C# extension declaration. - Only the compiler-emitted setter of an actual extension property declaration is called (matching receiver and value type); a hand-written static `set_Name` method is never treated as an accessor. - An accessible instance property or field hides extension properties of the same name even when it cannot be assigned, as in C# (explicitly implemented interface properties hide nothing). - An `[XmlnsDefinition]` only brings its namespace in from the assembly it names. - All applicable setters of all in-scope containers compete together; the unique most-specific receiver wins, independent of declaration or metadata order. - Equal or unrelated applicable candidates produce `MAUIX2021`, including when the ambiguity is inside one container. - An explicitly named extension container that does not define the requested property produces `MAUIX2020` and cannot fall through to an unrelated target property. - Values can come from markup extensions such as `{StaticResource}`, and the extension property's own `[TypeConverter]` is honoured. ## Support matrix | Inflator | Support | |----------|---------| | SourceGen | Supported: unqualified namespace-scoped and explicitly qualified assignment | | XamlC | Not supported | | Runtime XAML inflation | Not supported | XamlC and Runtime retain their existing unresolved-member behavior. Their product code is unchanged by this PR. Direct binding paths such as `{Binding Person.FullName}` remain out of scope. Extension properties are static accessors rather than reflected instance properties and do not define change-notification semantics. ## Tests SourceGen coverage includes: - Default-namespace and global-namespace lookup. - Cross-assembly namespace mappings. - Instance-property precedence. - Most-specific receiver selection across two and three containers, in different declaration orders. - Ambiguous candidates and out-of-scope containers. - Explicit qualification and disambiguation. - Handwritten lookalike accessor rejection. - Qualified property-element compatibility, including `<ContentView.Resources>` on a `ContentPage`. - `{StaticResource}` values, hand-written `set_Name` lookalikes, ambiguity inside one container, unassignable and explicitly implemented instance members, and containers from an unmapped assembly sharing a mapped namespace. Validation after rebasing on `main` (macOS): - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new regression tests fail on the previous generator. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198 passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`, locale-dependent decimal parsing in `CSharpExpressions`, unrelated to this PR). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628 passed, 40 skipped. ### Issues Fixed None (new feature). --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
<!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change Adds C# 14 extension-property assignment to the XAML source generator. Extension properties can be used without qualification when their container is in the element's effective default XAML namespace: ```csharp [assembly: XmlnsDefinition( "http://schemas.microsoft.com/dotnet/2021/maui", "MyApp.Extensions")] namespace MyApp.Extensions; public static class LabelExtensions { extension(Label label) { public string MyTag { get; set; } } } ``` ```xml <Label MyTag="hello" /> ``` Containers introduced through MAUI's global XML namespace are also available to XAML documents using that namespace. Explicit qualification remains available for selection and disambiguation: ```xml <Label local:LabelExtensions.MyTag="hello" /> ``` ## Resolution rules - Ordinary events, BindableProperties, and instance properties retain precedence over extension properties. - Unqualified extension properties are discovered only in CLR namespaces mapped from the element's effective default `xmlns`; no global assembly scan is performed. - The container must be a non-generic static class containing a compiler-generated C# extension declaration. - Only the compiler-emitted setter of an actual extension property declaration is called (matching receiver and value type); a hand-written static `set_Name` method is never treated as an accessor. - An accessible instance property or field hides extension properties of the same name even when it cannot be assigned, as in C# (explicitly implemented interface properties hide nothing). - An `[XmlnsDefinition]` only brings its namespace in from the assembly it names. - All applicable setters of all in-scope containers compete together; the unique most-specific receiver wins, independent of declaration or metadata order. - Equal or unrelated applicable candidates produce `MAUIX2021`, including when the ambiguity is inside one container. - An explicitly named extension container that does not define the requested property produces `MAUIX2020` and cannot fall through to an unrelated target property. - Values can come from markup extensions such as `{StaticResource}`, and the extension property's own `[TypeConverter]` is honoured. ## Support matrix | Inflator | Support | |----------|---------| | SourceGen | Supported: unqualified namespace-scoped and explicitly qualified assignment | | XamlC | Not supported | | Runtime XAML inflation | Not supported | XamlC and Runtime retain their existing unresolved-member behavior. Their product code is unchanged by this PR. Direct binding paths such as `{Binding Person.FullName}` remain out of scope. Extension properties are static accessors rather than reflected instance properties and do not define change-notification semantics. ## Tests SourceGen coverage includes: - Default-namespace and global-namespace lookup. - Cross-assembly namespace mappings. - Instance-property precedence. - Most-specific receiver selection across two and three containers, in different declaration orders. - Ambiguous candidates and out-of-scope containers. - Explicit qualification and disambiguation. - Handwritten lookalike accessor rejection. - Qualified property-element compatibility, including `<ContentView.Resources>` on a `ContentPage`. - `{StaticResource}` values, hand-written `set_Name` lookalikes, ambiguity inside one container, unassignable and explicitly implemented instance members, and containers from an unmapped assembly sharing a mapped namespace. Validation after rebasing on `main` (macOS): - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new regression tests fail on the previous generator. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198 passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`, locale-dependent decimal parsing in `CSharpExpressions`, unrelated to this PR). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628 passed, 40 skipped. ### Issues Fixed None (new feature). --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1
<!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change Adds C# 14 extension-property assignment to the XAML source generator. Extension properties can be used without qualification when their container is in the element's effective default XAML namespace: ```csharp [assembly: XmlnsDefinition( "http://schemas.microsoft.com/dotnet/2021/maui", "MyApp.Extensions")] namespace MyApp.Extensions; public static class LabelExtensions { extension(Label label) { public string MyTag { get; set; } } } ``` ```xml <Label MyTag="hello" /> ``` Containers introduced through MAUI's global XML namespace are also available to XAML documents using that namespace. Explicit qualification remains available for selection and disambiguation: ```xml <Label local:LabelExtensions.MyTag="hello" /> ``` ## Resolution rules - Ordinary events, BindableProperties, and instance properties retain precedence over extension properties. - Unqualified extension properties are discovered only in CLR namespaces mapped from the element's effective default `xmlns`; no global assembly scan is performed. - The container must be a non-generic static class containing a compiler-generated C# extension declaration. - Only the compiler-emitted setter of an actual extension property declaration is called (matching receiver and value type); a hand-written static `set_Name` method is never treated as an accessor. - An accessible instance property or field hides extension properties of the same name even when it cannot be assigned, as in C# (explicitly implemented interface properties hide nothing). - An `[XmlnsDefinition]` only brings its namespace in from the assembly it names. - All applicable setters of all in-scope containers compete together; the unique most-specific receiver wins, independent of declaration or metadata order. - Equal or unrelated applicable candidates produce `MAUIX2021`, including when the ambiguity is inside one container. - An explicitly named extension container that does not define the requested property produces `MAUIX2020` and cannot fall through to an unrelated target property. - Values can come from markup extensions such as `{StaticResource}`, and the extension property's own `[TypeConverter]` is honoured. ## Support matrix | Inflator | Support | |----------|---------| | SourceGen | Supported: unqualified namespace-scoped and explicitly qualified assignment | | XamlC | Not supported | | Runtime XAML inflation | Not supported | XamlC and Runtime retain their existing unresolved-member behavior. Their product code is unchanged by this PR. Direct binding paths such as `{Binding Person.FullName}` remain out of scope. Extension properties are static accessors rather than reflected instance properties and do not define change-notification semantics. ## Tests SourceGen coverage includes: - Default-namespace and global-namespace lookup. - Cross-assembly namespace mappings. - Instance-property precedence. - Most-specific receiver selection across two and three containers, in different declaration orders. - Ambiguous candidates and out-of-scope containers. - Explicit qualification and disambiguation. - Handwritten lookalike accessor rejection. - Qualified property-element compatibility, including `<ContentView.Resources>` on a `ContentPage`. - `{StaticResource}` values, hand-written `set_Name` lookalikes, ambiguity inside one container, unassignable and explicitly implemented instance members, and containers from an unmapped assembly sharing a mapped namespace. Validation after rebasing on `main` (macOS): - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter FullyQualifiedName~ExtensionProperties`: 19 passed. The 5 new regression tests fail on the previous generator. - `dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj`: 2,198 passed, 8 skipped, 2 failed (`TwoWayDecimalBinding_INPC`/`_VMToUI`, locale-dependent decimal parsing in `CSharpExpressions`, unrelated to this PR). - `dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj`: 628 passed, 40 skipped. ### Issues Fixed None (new feature). --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com> Copilot-Session: c30817d7-694e-4593-8efc-dc56ecfaeba1


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 of Change
Adds C# 14 extension-property assignment to the XAML source generator.
Extension properties can be used without qualification when their container is in the element's effective default XAML namespace:
Containers introduced through MAUI's global XML namespace are also available to XAML documents using that namespace. Explicit qualification remains available for selection and disambiguation:
Resolution rules
xmlns; no global assembly scan is performed.set_Namemethod is never treated as an accessor.[XmlnsDefinition]only brings its namespace in from the assembly it names.MAUIX2021, including when the ambiguity is inside one container.MAUIX2020and cannot fall through to an unrelated target property.{StaticResource}, and the extension property's own[TypeConverter]is honoured.Support matrix
XamlC and Runtime retain their existing unresolved-member behavior. Their product code is unchanged by this PR.
Direct binding paths such as
{Binding Person.FullName}remain out of scope. Extension properties are static accessors rather than reflected instance properties and do not define change-notification semantics.Tests
SourceGen coverage includes:
<ContentView.Resources>on aContentPage.{StaticResource}values, hand-writtenset_Namelookalikes, ambiguity inside one container, unassignable and explicitly implemented instance members, and containers from an unmapped assembly sharing a mapped namespace.Validation after rebasing on
main(macOS):dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter FullyQualifiedName~ExtensionProperties: 19 passed. The 5 new regression tests fail on the previous generator.dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj: 2,198 passed, 8 skipped, 2 failed (TwoWayDecimalBinding_INPC/_VMToUI, locale-dependent decimal parsing inCSharpExpressions, unrelated to this PR).dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj: 628 passed, 40 skipped.Issues Fixed
None (new feature).