Skip to content

Commit 02da791

Browse files
simplify on platform
1 parent 97a39e4 commit 02da791

File tree

2 files changed

+120
-7
lines changed

2 files changed

+120
-7
lines changed

src/Controls/src/Xaml/SimplifyOnPlatformVisitor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public void Visit(ElementNode node, INode parentNode)
4949
if (node.XmlType.IsOfAnyType("OnPlatformExtension"))
5050
{
5151
if ( node.Properties.TryGetValue(new XmlName("", Target), out INode targetNode)
52-
|| node.Properties.TryGetValue(new XmlName("", "Default"), out targetNode))
52+
|| node.Properties.TryGetValue(new XmlName(null, Target), out targetNode)
53+
|| node.Properties.TryGetValue(new XmlName("", "Default"), out targetNode)
54+
|| node.Properties.TryGetValue(new XmlName(null, "Default"), out targetNode))
5355
{
5456
if (!node.TryGetPropertyName(parentNode, out XmlName name))
5557
return;

src/Controls/tests/SourceGen.UnitTests/InitializeComponent/SimplifyOnPlatform.cs

Lines changed: 117 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,130 @@ public TestPage()
4545

4646
var expected =
4747
"""
48-
using System;
49-
using Microsoft.Maui.Controls;
50-
using Microsoft.Maui.Controls.Xaml;
48+
49+
//------------------------------------------------------------------------------
50+
// <auto-generated>
51+
// This code was generated by a .NET MAUI source generator.
52+
//
53+
// Changes to this file may cause incorrect behavior and will be lost if
54+
// the code is regenerated.
55+
// </auto-generated>
56+
//------------------------------------------------------------------------------
57+
#if _MAUIXAML_SG_NULLABLE_ENABLE
58+
#nullable enable
59+
#endif
5160
5261
namespace Test;
5362
54-
public partial class TestPage : ContentPage
63+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Maui.Controls.SourceGen, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null", "10.0.0.0")]
64+
public partial class TestPage
5565
{
56-
public TestPage()
66+
private partial void InitializeComponent()
5767
{
58-
InitializeComponent();
68+
var setter = new global::Microsoft.Maui.Controls.Setter();
69+
#if _MAUIXAML_SG_SOURCEINFO
70+
global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(setter!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 8, 14);
71+
#endif
72+
var setter1 = new global::Microsoft.Maui.Controls.Setter();
73+
#if _MAUIXAML_SG_SOURCEINFO
74+
global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(setter1!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 9, 14);
75+
#endif
76+
var xamlServiceProvider = new global::Microsoft.Maui.Controls.Xaml.Internals.XamlServiceProvider(this);
77+
var xmlNamespaceResolver = new global::Microsoft.Maui.Controls.Xaml.Internals.XmlNamespaceResolver();
78+
xmlNamespaceResolver.Add("__f__", "http://schemas.microsoft.com/dotnet/2021/maui");
79+
xmlNamespaceResolver.Add("__g__", "http://schemas.microsoft.com/dotnet/maui/global");
80+
xmlNamespaceResolver.Add("", "http://schemas.microsoft.com/dotnet/2021/maui");
81+
xmlNamespaceResolver.Add("x", "http://schemas.microsoft.com/winfx/2009/xaml");
82+
xamlServiceProvider.Add(typeof(global::Microsoft.Maui.Controls.Xaml.IXamlTypeResolver), new global::Microsoft.Maui.Controls.Xaml.Internals.XamlTypeResolver(xmlNamespaceResolver, typeof(global::Test.TestPage).Assembly));
83+
var style1 = new global::Microsoft.Maui.Controls.Style(((global::Microsoft.Maui.Controls.IExtendedTypeConverter)new global::Microsoft.Maui.Controls.TypeTypeConverter()).ConvertFromInvariantString("Label", xamlServiceProvider) as global::System.Type);
84+
#if _MAUIXAML_SG_SOURCEINFO
85+
global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(style1!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 7, 10);
86+
#endif
87+
var __root = this;
88+
#if _MAUIXAML_SG_SOURCEINFO
89+
global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(__root!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 2, 2);
90+
#endif
91+
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
92+
global::Microsoft.Maui.Controls.Internals.INameScope iNameScope = global::Microsoft.Maui.Controls.Internals.NameScope.GetNameScope(__root) ?? new global::Microsoft.Maui.Controls.Internals.NameScope();
93+
#endif
94+
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
95+
global::Microsoft.Maui.Controls.Internals.NameScope.SetNameScope(__root, iNameScope);
96+
#endif
97+
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
98+
global::Microsoft.Maui.Controls.Internals.INameScope iNameScope1 = new global::Microsoft.Maui.Controls.Internals.NameScope();
99+
#endif
100+
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
101+
global::Microsoft.Maui.Controls.Internals.INameScope iNameScope2 = new global::Microsoft.Maui.Controls.Internals.NameScope();
102+
#endif
103+
#line 8 "Test.xaml"
104+
var xamlServiceProvider1 = new global::Microsoft.Maui.Controls.Xaml.Internals.XamlServiceProvider(this);
105+
var iProvideValueTarget = new global::Microsoft.Maui.Controls.Xaml.Internals.SimpleValueTargetProvider(
106+
new object[] {setter, style1, __root},
107+
typeof(global::Microsoft.Maui.Controls.Setter).GetProperty("Property"),
108+
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
109+
new [] { iNameScope1 },
110+
#else
111+
null,
112+
#endif
113+
false);
114+
xamlServiceProvider1.Add(typeof(global::Microsoft.Maui.Controls.Xaml.IReferenceProvider), iProvideValueTarget);
115+
xamlServiceProvider1.Add(typeof(global::Microsoft.Maui.Controls.Xaml.IProvideValueTarget), iProvideValueTarget);
116+
var xmlNamespaceResolver1 = new global::Microsoft.Maui.Controls.Xaml.Internals.XmlNamespaceResolver();
117+
xmlNamespaceResolver1.Add("__f__", "http://schemas.microsoft.com/dotnet/2021/maui");
118+
xmlNamespaceResolver1.Add("__g__", "http://schemas.microsoft.com/dotnet/maui/global");
119+
xmlNamespaceResolver1.Add("", "http://schemas.microsoft.com/dotnet/2021/maui");
120+
xmlNamespaceResolver1.Add("x", "http://schemas.microsoft.com/winfx/2009/xaml");
121+
xamlServiceProvider1.Add(typeof(global::Microsoft.Maui.Controls.Xaml.IXamlTypeResolver), new global::Microsoft.Maui.Controls.Xaml.Internals.XamlTypeResolver(xmlNamespaceResolver1, typeof(global::Test.TestPage).Assembly));
122+
setter.Property = ((global::Microsoft.Maui.Controls.IExtendedTypeConverter)new global::Microsoft.Maui.Controls.BindablePropertyConverter()).ConvertFromInvariantString("TextColor", xamlServiceProvider1) as global::Microsoft.Maui.Controls.BindableProperty;
123+
#line default
124+
#line 8 "Test.xaml"
125+
setter.Value = "Pink";
126+
#line default
127+
var setter2 = new global::Microsoft.Maui.Controls.Setter {Property = global::Microsoft.Maui.Controls.Label.TextColorProperty, Value = global::Microsoft.Maui.Graphics.Color.Parse("Pink")};
128+
#if _MAUIXAML_SG_SOURCEINFO
129+
if (global::Microsoft.Maui.VisualDiagnostics.GetSourceInfo(setter2!) == null)
130+
global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(setter2!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 8, 14);
131+
#endif
132+
#line 8 "Test.xaml"
133+
((global::System.Collections.Generic.ICollection<global::Microsoft.Maui.Controls.Setter>)style1.Setters).Add((global::Microsoft.Maui.Controls.Setter)setter2);
134+
#line default
135+
#line 9 "Test.xaml"
136+
var xamlServiceProvider2 = new global::Microsoft.Maui.Controls.Xaml.Internals.XamlServiceProvider(this);
137+
var iProvideValueTarget1 = new global::Microsoft.Maui.Controls.Xaml.Internals.SimpleValueTargetProvider(
138+
new object[] {setter1, style1, __root},
139+
typeof(global::Microsoft.Maui.Controls.Setter).GetProperty("Property"),
140+
#if !_MAUIXAML_SG_NAMESCOPE_DISABLE
141+
new [] { iNameScope2 },
142+
#else
143+
null,
144+
#endif
145+
false);
146+
xamlServiceProvider2.Add(typeof(global::Microsoft.Maui.Controls.Xaml.IReferenceProvider), iProvideValueTarget1);
147+
xamlServiceProvider2.Add(typeof(global::Microsoft.Maui.Controls.Xaml.IProvideValueTarget), iProvideValueTarget1);
148+
var xmlNamespaceResolver2 = new global::Microsoft.Maui.Controls.Xaml.Internals.XmlNamespaceResolver();
149+
xmlNamespaceResolver2.Add("__f__", "http://schemas.microsoft.com/dotnet/2021/maui");
150+
xmlNamespaceResolver2.Add("__g__", "http://schemas.microsoft.com/dotnet/maui/global");
151+
xmlNamespaceResolver2.Add("", "http://schemas.microsoft.com/dotnet/2021/maui");
152+
xmlNamespaceResolver2.Add("x", "http://schemas.microsoft.com/winfx/2009/xaml");
153+
xamlServiceProvider2.Add(typeof(global::Microsoft.Maui.Controls.Xaml.IXamlTypeResolver), new global::Microsoft.Maui.Controls.Xaml.Internals.XamlTypeResolver(xmlNamespaceResolver2, typeof(global::Test.TestPage).Assembly));
154+
setter1.Property = ((global::Microsoft.Maui.Controls.IExtendedTypeConverter)new global::Microsoft.Maui.Controls.BindablePropertyConverter()).ConvertFromInvariantString("IsVisible", xamlServiceProvider2) as global::Microsoft.Maui.Controls.BindableProperty;
155+
#line default
156+
#line 1 "Test.xaml"
157+
setter1.Value = "True";
158+
#line default
159+
var setter3 = new global::Microsoft.Maui.Controls.Setter {Property = global::Microsoft.Maui.Controls.VisualElement.IsVisibleProperty, Value = (bool)new global::Microsoft.Maui.Controls.VisualElement.VisibilityConverter().ConvertFromInvariantString("True")!};
160+
#if _MAUIXAML_SG_SOURCEINFO
161+
if (global::Microsoft.Maui.VisualDiagnostics.GetSourceInfo(setter3!) == null)
162+
global::Microsoft.Maui.VisualDiagnostics.RegisterSourceInfo(setter3!, new global::System.Uri(@"Test.xaml;assembly=SourceGeneratorDriver.Generated", global::System.UriKind.Relative), 9, 14);
163+
#endif
164+
#line 9 "Test.xaml"
165+
((global::System.Collections.Generic.ICollection<global::Microsoft.Maui.Controls.Setter>)style1.Setters).Add((global::Microsoft.Maui.Controls.Setter)setter3);
166+
#line default
167+
var resourceDictionary = __root.Resources;
168+
resourceDictionary.Add("style", style1);
59169
}
60170
}
171+
61172
""";
62173

63174
var (result, generated) = RunGenerator(xaml, code, targetFramework: "net10.0-android");

0 commit comments

Comments
 (0)