From e94127fa47d90ffd7413618071d62efee776232a Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Fri, 27 Sep 2024 15:12:10 -0400 Subject: [PATCH] fix(codegen): Adjust mvvm toolkit properties discovery --- .../Given_MvvmGeneratedMembers.cs | 112 ++++++++++ ...rtyGenerator_TestRepro.MySubViewModel.g.cs | 53 +++++ ...opertyGenerator_TestRepro.MyViewModel.g.cs | 53 +++++ ...tor___KnownINotifyPropertyChangedArgs.g.cs | 22 ++ ...or___KnownINotifyPropertyChangingArgs.g.cs | 22 ++ ...XamlCodeGenerator_GlobalStaticResources.cs | 55 +++++ ...XamlCodeGenerator_LocalizationResources.cs | 2 + ...inPage_d6cd66944958ced0c513e0a04797b51d.cs | 195 ++++++++++++++++++ ...rtyGenerator_TestRepro.MySubViewModel.g.cs | 53 +++++ ...opertyGenerator_TestRepro.MyViewModel.g.cs | 54 +++++ ...tor___KnownINotifyPropertyChangedArgs.g.cs | 26 +++ ...or___KnownINotifyPropertyChangingArgs.g.cs | 26 +++ ...XamlCodeGenerator_GlobalStaticResources.cs | 55 +++++ ...XamlCodeGenerator_LocalizationResources.cs | 2 + ...inPage_d6cd66944958ced0c513e0a04797b51d.cs | 195 ++++++++++++++++++ .../XamlGenerator/XamlFileGenerator.cs | 32 ++- 16 files changed, 949 insertions(+), 8 deletions(-) create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator_TestRepro.MySubViewModel.g.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator_TestRepro.MyViewModel.g.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangedArgs.g.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangingArgs.g.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_GlobalStaticResources.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_LocalizationResources.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator_TestRepro.MySubViewModel.g.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator_TestRepro.MyViewModel.g.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangedArgs.g.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangingArgs.g.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_GlobalStaticResources.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_LocalizationResources.cs create mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_MvvmGeneratedMembers.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_MvvmGeneratedMembers.cs index cef10559aa99..2749d697dc55 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_MvvmGeneratedMembers.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_MvvmGeneratedMembers.cs @@ -97,6 +97,118 @@ public void MyBindBack(string s) { } await test.RunAsync(); } + [TestMethod] + public async Task When_Boolean_Observable_Property() + { + var xamlFile = new XamlFile( + "MainPage.xaml", + """ + + + + + + + """); + + var test = new MvvmTest(xamlFile, $"WBOP") + { + TestState = + { + Sources = + { + $$""" + using Microsoft.UI.Xaml.Controls; + using CommunityToolkit.Mvvm.ComponentModel; + + namespace TestRepro + { + public sealed partial class MainPage : Page + { + public MyViewModel ViewModel = new MyViewModel(); + + public MainPage() + { + this.InitializeComponent(); + } + } + + public partial class MyViewModel : ObservableObject + { + [ObservableProperty] + private bool _isEnabled; + } + } + """ + } + } + }.AddGeneratedSources(); + + await test.RunAsync(); + } + + [TestMethod] + public async Task When_Nested_Boolean_Observable_Property() + { + var xamlFile = new XamlFile( + "MainPage.xaml", + """ + + + + + + + """); + + var test = new MvvmTest(xamlFile, $"WNBOP") + { + TestState = + { + Sources = + { + $$""" + using Microsoft.UI.Xaml.Controls; + using CommunityToolkit.Mvvm.ComponentModel; + + namespace TestRepro + { + public sealed partial class MainPage : Page + { + public MyViewModel ViewModel = new MyViewModel(); + + public MainPage() + { + this.InitializeComponent(); + } + } + + public partial class MyViewModel : ObservableObject + { + [ObservableProperty] + private MySubViewModel _subModel; + } + + public partial class MySubViewModel : ObservableObject + { + [ObservableProperty] + private bool _isEnabled; + } + } + """ + } + } + }.AddGeneratedSources(); + + await test.RunAsync(); + } + [TestMethod] public async Task When_ObservableProperty_AttributeDoesNotExists() { diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator_TestRepro.MySubViewModel.g.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator_TestRepro.MySubViewModel.g.cs new file mode 100644 index 000000000000..a3db86042d08 --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator_TestRepro.MySubViewModel.g.cs @@ -0,0 +1,53 @@ +// +#pragma warning disable +#nullable enable +namespace TestRepro +{ + /// + partial class MySubViewModel + { + /// + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public bool IsEnabled + { + get => _isEnabled; + set + { + if (!global::System.Collections.Generic.EqualityComparer.Default.Equals(_isEnabled, value)) + { + OnIsEnabledChanging(value); + OnIsEnabledChanging(default, value); + OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.IsEnabled); + _isEnabled = value; + OnIsEnabledChanged(value); + OnIsEnabledChanged(default, value); + OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.IsEnabled); + } + } + } + + /// Executes the logic for when is changing. + /// The new property value being set. + /// This method is invoked right before the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanging(bool value); + /// Executes the logic for when is changing. + /// The previous property value that is being replaced. + /// The new property value being set. + /// This method is invoked right before the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanging(bool oldValue, bool newValue); + /// Executes the logic for when just changed. + /// The new property value that was set. + /// This method is invoked right after the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanged(bool value); + /// Executes the logic for when just changed. + /// The previous property value that was replaced. + /// The new property value that was set. + /// This method is invoked right after the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanged(bool oldValue, bool newValue); + } +} \ No newline at end of file diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator_TestRepro.MyViewModel.g.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator_TestRepro.MyViewModel.g.cs new file mode 100644 index 000000000000..5919e40ee078 --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator_TestRepro.MyViewModel.g.cs @@ -0,0 +1,53 @@ +// +#pragma warning disable +#nullable enable +namespace TestRepro +{ + /// + partial class MyViewModel + { + /// + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public bool IsEnabled + { + get => _isEnabled; + set + { + if (!global::System.Collections.Generic.EqualityComparer.Default.Equals(_isEnabled, value)) + { + OnIsEnabledChanging(value); + OnIsEnabledChanging(default, value); + OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.IsEnabled); + _isEnabled = value; + OnIsEnabledChanged(value); + OnIsEnabledChanged(default, value); + OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.IsEnabled); + } + } + } + + /// Executes the logic for when is changing. + /// The new property value being set. + /// This method is invoked right before the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanging(bool value); + /// Executes the logic for when is changing. + /// The previous property value that is being replaced. + /// The new property value being set. + /// This method is invoked right before the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanging(bool oldValue, bool newValue); + /// Executes the logic for when just changed. + /// The new property value that was set. + /// This method is invoked right after the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanged(bool value); + /// Executes the logic for when just changed. + /// The previous property value that was replaced. + /// The new property value that was set. + /// This method is invoked right after the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanged(bool oldValue, bool newValue); + } +} \ No newline at end of file diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangedArgs.g.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangedArgs.g.cs new file mode 100644 index 000000000000..68365f49d5f9 --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangedArgs.g.cs @@ -0,0 +1,22 @@ +// +#pragma warning disable +#nullable enable +namespace CommunityToolkit.Mvvm.ComponentModel.__Internals +{ + /// + /// A helper type providing cached, reusable instances + /// for all properties generated with . + /// + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Obsolete("This type is not intended to be used directly by user code")] + internal static class __KnownINotifyPropertyChangedArgs + { + /// The cached instance for all "IsEnabled" generated properties. + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Obsolete("This field is not intended to be referenced directly by user code")] + public static readonly global::System.ComponentModel.PropertyChangedEventArgs IsEnabled = new global::System.ComponentModel.PropertyChangedEventArgs("IsEnabled"); + } +} \ No newline at end of file diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangingArgs.g.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangingArgs.g.cs new file mode 100644 index 000000000000..c2ab21597faf --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangingArgs.g.cs @@ -0,0 +1,22 @@ +// +#pragma warning disable +#nullable enable +namespace CommunityToolkit.Mvvm.ComponentModel.__Internals +{ + /// + /// A helper type providing cached, reusable instances + /// for all properties generated with . + /// + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Obsolete("This type is not intended to be used directly by user code")] + internal static class __KnownINotifyPropertyChangingArgs + { + /// The cached instance for all "IsEnabled" generated properties. + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Obsolete("This field is not intended to be referenced directly by user code")] + public static readonly global::System.ComponentModel.PropertyChangingEventArgs IsEnabled = new global::System.ComponentModel.PropertyChangingEventArgs("IsEnabled"); + } +} \ No newline at end of file diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_GlobalStaticResources.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_GlobalStaticResources.cs new file mode 100644 index 000000000000..ad59ff1058b5 --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_GlobalStaticResources.cs @@ -0,0 +1,55 @@ +// +namespace MyProject +{ + /// + /// Contains all the static resources defined for the application + /// + public sealed partial class GlobalStaticResources + { + static bool _initialized; + private static bool _stylesRegistered; + private static bool _dictionariesRegistered; + internal static global::Uno.UI.Xaml.XamlParseContext __ParseContext_ { get; } = new global::Uno.UI.Xaml.XamlParseContext() + { + AssemblyName = "TestProject", + } + ; + + static GlobalStaticResources() + { + Initialize(); + } + public static void Initialize() + { + if (!_initialized) + { + _initialized = true; + global::Uno.UI.GlobalStaticResources.Initialize(); + global::Uno.UI.GlobalStaticResources.RegisterDefaultStyles(); + global::Uno.UI.GlobalStaticResources.RegisterResourceDictionariesBySource(); + } + } + public static void RegisterDefaultStyles() + { + if(!_stylesRegistered) + { + _stylesRegistered = true; + RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d(); + } + } + // Register ResourceDictionaries using ms-appx:/// syntax, this is called for external resources + public static void RegisterResourceDictionariesBySource() + { + if(!_dictionariesRegistered) + { + _dictionariesRegistered = true; + } + } + // Register ResourceDictionaries using ms-resource:/// syntax, this is called for local resources + internal static void RegisterResourceDictionariesBySourceLocal() + { + } + static partial void RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d(); + + } +} diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_LocalizationResources.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_LocalizationResources.cs new file mode 100644 index 000000000000..115ce87c0105 --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_LocalizationResources.cs @@ -0,0 +1,2 @@ +// +[assembly: global::System.Reflection.AssemblyMetadata("UnoHasLocalizationResources", "False")] \ No newline at end of file diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs new file mode 100644 index 000000000000..d3f808e05a2f --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WBOP/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs @@ -0,0 +1,195 @@ +// +#pragma warning disable CS0114 +#pragma warning disable CS0108 +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Uno.UI; +using Uno.UI.Xaml; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Documents; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Media.Animation; +using Microsoft.UI.Xaml.Shapes; +using Windows.UI.Text; +using Uno.Extensions; +using Uno; +using Uno.UI.Helpers; +using Uno.UI.Helpers.Xaml; +using MyProject; + +#if __ANDROID__ +using _View = Android.Views.View; +#elif __IOS__ +using _View = UIKit.UIView; +#elif __MACOS__ +using _View = AppKit.NSView; +#else +using _View = Microsoft.UI.Xaml.UIElement; +#endif + +namespace TestRepro +{ + partial class MainPage : global::Microsoft.UI.Xaml.Controls.Page + { + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/"; + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/"; + private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope(); + private void InitializeComponent() + { + NameScope.SetNameScope(this, __nameScope); + var __that = this; + base.IsParsing = true; + // Source 0\MainPage.xaml (Line 1:2) + base.Content = + new global::Microsoft.UI.Xaml.Controls.StackPanel + { + IsParsing = true, + // Source 0\MainPage.xaml (Line 6:3) + Children = + { + new global::Microsoft.UI.Xaml.Controls.ToggleSwitch + { + IsParsing = true, + OnContent = @"Enabled", + OffContent = @"Disabled", + // Source 0\MainPage.xaml (Line 7:4) + } + .MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply((MainPage_d6cd66944958ced0c513e0a04797b51dXamlApplyExtensions.XamlApplyHandler0)(c0 => + { + /* _isTopLevelDictionary:False */ + __that._component_0 = c0; + c0.SetBinding( + global::Microsoft.UI.Xaml.Controls.ToggleSwitch.IsOnProperty, + new Microsoft.UI.Xaml.Data.Binding() + { + Mode = global::Microsoft.UI.Xaml.Data.BindingMode.TwoWay, + } + .BindingApply(___b => /*defaultBindModeOneTime ViewModel.SubModel.IsEnabled*/ global::Uno.UI.Xaml.BindingHelper.SetBindingXBindProvider(___b, __that, ___ctx => ___ctx is global::TestRepro.MainPage ___tctx ? ((true, ___tctx.ViewModel.SubModel.IsEnabled)) : (false, default), (___ctx, __value) => { if(___ctx is global::TestRepro.MainPage ___tctx) ___tctx.ViewModel.SubModel.IsEnabled = (bool)global::Microsoft.UI.Xaml.Markup.XamlBindingHelper.ConvertValue(typeof(bool), __value); } , new [] {"ViewModel.SubModel.IsEnabled"})) + ); + global::Uno.UI.FrameworkElementHelper.SetBaseUri(c0, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d); + c0.CreationComplete(); + } + )) + , + } + } + .MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply((MainPage_d6cd66944958ced0c513e0a04797b51dXamlApplyExtensions.XamlApplyHandler1)(c1 => + { + global::Uno.UI.FrameworkElementHelper.SetBaseUri(c1, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d); + c1.CreationComplete(); + } + )) + ; + + this + .GenericApply(((c2) => + { + // Source 0\MainPage.xaml (Line 1:2) + + // WARNING Property c2.base does not exist on {http://schemas.microsoft.com/winfx/2006/xaml/presentation}Page, the namespace is http://www.w3.org/XML/1998/namespace. This error was considered irrelevant by the XamlFileGenerator + } + )) + .GenericApply(((c3) => + { + // Class TestRepro.MainPage + global::Uno.UI.FrameworkElementHelper.SetBaseUri(c3, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d); + c3.CreationComplete(); + } + )) + ; + OnInitializeCompleted(); + + Bindings = new MainPage_Bindings(this); + ((global::Microsoft.UI.Xaml.FrameworkElement)this).Loading += (s, e) => + { + __that.Bindings.Update(); + __that.Bindings.UpdateResources(); + } + ; + } + partial void OnInitializeCompleted(); + private global::Microsoft.UI.Xaml.Markup.ComponentHolder _component_0_Holder = new global::Microsoft.UI.Xaml.Markup.ComponentHolder(isWeak: true); + private global::Microsoft.UI.Xaml.Controls.ToggleSwitch _component_0 + { + get + { + return (global::Microsoft.UI.Xaml.Controls.ToggleSwitch)_component_0_Holder.Instance; + } + set + { + _component_0_Holder.Instance = value; + } + } + private interface IMainPage_Bindings + { + void Initialize(); + void Update(); + void UpdateResources(); + void StopTracking(); + void NotifyXLoad(string name); + } + #pragma warning disable 0169 // Suppress unused field warning in case Bindings is not used. + private IMainPage_Bindings Bindings; + #pragma warning restore 0169 + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + private class MainPage_Bindings : IMainPage_Bindings + { + #if UNO_HAS_UIELEMENT_IMPLICIT_PINNING + private global::System.WeakReference _ownerReference; + private global::TestRepro.MainPage Owner { get => (global::TestRepro.MainPage)_ownerReference?.Target; set => _ownerReference = new global::System.WeakReference(value); } + #else + private global::TestRepro.MainPage Owner { get; set; } + #endif + public MainPage_Bindings(global::TestRepro.MainPage owner) + { + Owner = owner; + } + void IMainPage_Bindings.NotifyXLoad(string name) + { + } + void IMainPage_Bindings.Initialize() + { + } + void IMainPage_Bindings.Update() + { + var owner = Owner; + owner._component_0.ApplyXBind(); + } + void IMainPage_Bindings.UpdateResources() + { + var owner = Owner; + owner._component_0.UpdateResourceBindings(resourceContextProvider: null); + } + void IMainPage_Bindings.StopTracking() + { + } + } + } +} +namespace MyProject +{ + static class MainPage_d6cd66944958ced0c513e0a04797b51dXamlApplyExtensions + { + public delegate void XamlApplyHandler0(global::Microsoft.UI.Xaml.Controls.ToggleSwitch instance); + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public static global::Microsoft.UI.Xaml.Controls.ToggleSwitch MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply(this global::Microsoft.UI.Xaml.Controls.ToggleSwitch instance, XamlApplyHandler0 handler) + { + handler(instance); + return instance; + } + public delegate void XamlApplyHandler1(global::Microsoft.UI.Xaml.Controls.StackPanel instance); + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public static global::Microsoft.UI.Xaml.Controls.StackPanel MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply(this global::Microsoft.UI.Xaml.Controls.StackPanel instance, XamlApplyHandler1 handler) + { + handler(instance); + return instance; + } + } +} diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator_TestRepro.MySubViewModel.g.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator_TestRepro.MySubViewModel.g.cs new file mode 100644 index 000000000000..a3db86042d08 --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator_TestRepro.MySubViewModel.g.cs @@ -0,0 +1,53 @@ +// +#pragma warning disable +#nullable enable +namespace TestRepro +{ + /// + partial class MySubViewModel + { + /// + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public bool IsEnabled + { + get => _isEnabled; + set + { + if (!global::System.Collections.Generic.EqualityComparer.Default.Equals(_isEnabled, value)) + { + OnIsEnabledChanging(value); + OnIsEnabledChanging(default, value); + OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.IsEnabled); + _isEnabled = value; + OnIsEnabledChanged(value); + OnIsEnabledChanged(default, value); + OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.IsEnabled); + } + } + } + + /// Executes the logic for when is changing. + /// The new property value being set. + /// This method is invoked right before the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanging(bool value); + /// Executes the logic for when is changing. + /// The previous property value that is being replaced. + /// The new property value being set. + /// This method is invoked right before the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanging(bool oldValue, bool newValue); + /// Executes the logic for when just changed. + /// The new property value that was set. + /// This method is invoked right after the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanged(bool value); + /// Executes the logic for when just changed. + /// The previous property value that was replaced. + /// The new property value that was set. + /// This method is invoked right after the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnIsEnabledChanged(bool oldValue, bool newValue); + } +} \ No newline at end of file diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator_TestRepro.MyViewModel.g.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator_TestRepro.MyViewModel.g.cs new file mode 100644 index 000000000000..78475357d86c --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator_TestRepro.MyViewModel.g.cs @@ -0,0 +1,54 @@ +// +#pragma warning disable +#nullable enable +namespace TestRepro +{ + /// + partial class MyViewModel + { + /// + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + public global::TestRepro.MySubViewModel SubModel + { + get => _subModel; + [global::System.Diagnostics.CodeAnalysis.MemberNotNull("_subModel")] + set + { + if (!global::System.Collections.Generic.EqualityComparer.Default.Equals(_subModel, value)) + { + OnSubModelChanging(value); + OnSubModelChanging(default, value); + OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.SubModel); + _subModel = value; + OnSubModelChanged(value); + OnSubModelChanged(default, value); + OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.SubModel); + } + } + } + + /// Executes the logic for when is changing. + /// The new property value being set. + /// This method is invoked right before the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnSubModelChanging(global::TestRepro.MySubViewModel value); + /// Executes the logic for when is changing. + /// The previous property value that is being replaced. + /// The new property value being set. + /// This method is invoked right before the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnSubModelChanging(global::TestRepro.MySubViewModel? oldValue, global::TestRepro.MySubViewModel newValue); + /// Executes the logic for when just changed. + /// The new property value that was set. + /// This method is invoked right after the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnSubModelChanged(global::TestRepro.MySubViewModel value); + /// Executes the logic for when just changed. + /// The previous property value that was replaced. + /// The new property value that was set. + /// This method is invoked right after the value of is changed. + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + partial void OnSubModelChanged(global::TestRepro.MySubViewModel? oldValue, global::TestRepro.MySubViewModel newValue); + } +} \ No newline at end of file diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangedArgs.g.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangedArgs.g.cs new file mode 100644 index 000000000000..203b9e3f05f8 --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangedArgs.g.cs @@ -0,0 +1,26 @@ +// +#pragma warning disable +#nullable enable +namespace CommunityToolkit.Mvvm.ComponentModel.__Internals +{ + /// + /// A helper type providing cached, reusable instances + /// for all properties generated with . + /// + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Obsolete("This type is not intended to be used directly by user code")] + internal static class __KnownINotifyPropertyChangedArgs + { + /// The cached instance for all "SubModel" generated properties. + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Obsolete("This field is not intended to be referenced directly by user code")] + public static readonly global::System.ComponentModel.PropertyChangedEventArgs SubModel = new global::System.ComponentModel.PropertyChangedEventArgs("SubModel"); + /// The cached instance for all "IsEnabled" generated properties. + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Obsolete("This field is not intended to be referenced directly by user code")] + public static readonly global::System.ComponentModel.PropertyChangedEventArgs IsEnabled = new global::System.ComponentModel.PropertyChangedEventArgs("IsEnabled"); + } +} \ No newline at end of file diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangingArgs.g.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangingArgs.g.cs new file mode 100644 index 000000000000..7a809f4aecb1 --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/ObservablePropertyGenerator___KnownINotifyPropertyChangingArgs.g.cs @@ -0,0 +1,26 @@ +// +#pragma warning disable +#nullable enable +namespace CommunityToolkit.Mvvm.ComponentModel.__Internals +{ + /// + /// A helper type providing cached, reusable instances + /// for all properties generated with . + /// + [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")] + [global::System.Diagnostics.DebuggerNonUserCode] + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Obsolete("This type is not intended to be used directly by user code")] + internal static class __KnownINotifyPropertyChangingArgs + { + /// The cached instance for all "SubModel" generated properties. + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Obsolete("This field is not intended to be referenced directly by user code")] + public static readonly global::System.ComponentModel.PropertyChangingEventArgs SubModel = new global::System.ComponentModel.PropertyChangingEventArgs("SubModel"); + /// The cached instance for all "IsEnabled" generated properties. + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + [global::System.Obsolete("This field is not intended to be referenced directly by user code")] + public static readonly global::System.ComponentModel.PropertyChangingEventArgs IsEnabled = new global::System.ComponentModel.PropertyChangingEventArgs("IsEnabled"); + } +} \ No newline at end of file diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_GlobalStaticResources.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_GlobalStaticResources.cs new file mode 100644 index 000000000000..ad59ff1058b5 --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_GlobalStaticResources.cs @@ -0,0 +1,55 @@ +// +namespace MyProject +{ + /// + /// Contains all the static resources defined for the application + /// + public sealed partial class GlobalStaticResources + { + static bool _initialized; + private static bool _stylesRegistered; + private static bool _dictionariesRegistered; + internal static global::Uno.UI.Xaml.XamlParseContext __ParseContext_ { get; } = new global::Uno.UI.Xaml.XamlParseContext() + { + AssemblyName = "TestProject", + } + ; + + static GlobalStaticResources() + { + Initialize(); + } + public static void Initialize() + { + if (!_initialized) + { + _initialized = true; + global::Uno.UI.GlobalStaticResources.Initialize(); + global::Uno.UI.GlobalStaticResources.RegisterDefaultStyles(); + global::Uno.UI.GlobalStaticResources.RegisterResourceDictionariesBySource(); + } + } + public static void RegisterDefaultStyles() + { + if(!_stylesRegistered) + { + _stylesRegistered = true; + RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d(); + } + } + // Register ResourceDictionaries using ms-appx:/// syntax, this is called for external resources + public static void RegisterResourceDictionariesBySource() + { + if(!_dictionariesRegistered) + { + _dictionariesRegistered = true; + } + } + // Register ResourceDictionaries using ms-resource:/// syntax, this is called for local resources + internal static void RegisterResourceDictionariesBySourceLocal() + { + } + static partial void RegisterDefaultStyles_MainPage_d6cd66944958ced0c513e0a04797b51d(); + + } +} diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_LocalizationResources.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_LocalizationResources.cs new file mode 100644 index 000000000000..115ce87c0105 --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_LocalizationResources.cs @@ -0,0 +1,2 @@ +// +[assembly: global::System.Reflection.AssemblyMetadata("UnoHasLocalizationResources", "False")] \ No newline at end of file diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs new file mode 100644 index 000000000000..d3f808e05a2f --- /dev/null +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/WNBOP/XamlCodeGenerator_MainPage_d6cd66944958ced0c513e0a04797b51d.cs @@ -0,0 +1,195 @@ +// +#pragma warning disable CS0114 +#pragma warning disable CS0108 +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Uno.UI; +using Uno.UI.Xaml; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Documents; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Media.Animation; +using Microsoft.UI.Xaml.Shapes; +using Windows.UI.Text; +using Uno.Extensions; +using Uno; +using Uno.UI.Helpers; +using Uno.UI.Helpers.Xaml; +using MyProject; + +#if __ANDROID__ +using _View = Android.Views.View; +#elif __IOS__ +using _View = UIKit.UIView; +#elif __MACOS__ +using _View = AppKit.NSView; +#else +using _View = Microsoft.UI.Xaml.UIElement; +#endif + +namespace TestRepro +{ + partial class MainPage : global::Microsoft.UI.Xaml.Controls.Page + { + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + private const string __baseUri_prefix_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/"; + [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] + private const string __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d = "ms-appx:///TestProject/"; + private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope(); + private void InitializeComponent() + { + NameScope.SetNameScope(this, __nameScope); + var __that = this; + base.IsParsing = true; + // Source 0\MainPage.xaml (Line 1:2) + base.Content = + new global::Microsoft.UI.Xaml.Controls.StackPanel + { + IsParsing = true, + // Source 0\MainPage.xaml (Line 6:3) + Children = + { + new global::Microsoft.UI.Xaml.Controls.ToggleSwitch + { + IsParsing = true, + OnContent = @"Enabled", + OffContent = @"Disabled", + // Source 0\MainPage.xaml (Line 7:4) + } + .MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply((MainPage_d6cd66944958ced0c513e0a04797b51dXamlApplyExtensions.XamlApplyHandler0)(c0 => + { + /* _isTopLevelDictionary:False */ + __that._component_0 = c0; + c0.SetBinding( + global::Microsoft.UI.Xaml.Controls.ToggleSwitch.IsOnProperty, + new Microsoft.UI.Xaml.Data.Binding() + { + Mode = global::Microsoft.UI.Xaml.Data.BindingMode.TwoWay, + } + .BindingApply(___b => /*defaultBindModeOneTime ViewModel.SubModel.IsEnabled*/ global::Uno.UI.Xaml.BindingHelper.SetBindingXBindProvider(___b, __that, ___ctx => ___ctx is global::TestRepro.MainPage ___tctx ? ((true, ___tctx.ViewModel.SubModel.IsEnabled)) : (false, default), (___ctx, __value) => { if(___ctx is global::TestRepro.MainPage ___tctx) ___tctx.ViewModel.SubModel.IsEnabled = (bool)global::Microsoft.UI.Xaml.Markup.XamlBindingHelper.ConvertValue(typeof(bool), __value); } , new [] {"ViewModel.SubModel.IsEnabled"})) + ); + global::Uno.UI.FrameworkElementHelper.SetBaseUri(c0, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d); + c0.CreationComplete(); + } + )) + , + } + } + .MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply((MainPage_d6cd66944958ced0c513e0a04797b51dXamlApplyExtensions.XamlApplyHandler1)(c1 => + { + global::Uno.UI.FrameworkElementHelper.SetBaseUri(c1, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d); + c1.CreationComplete(); + } + )) + ; + + this + .GenericApply(((c2) => + { + // Source 0\MainPage.xaml (Line 1:2) + + // WARNING Property c2.base does not exist on {http://schemas.microsoft.com/winfx/2006/xaml/presentation}Page, the namespace is http://www.w3.org/XML/1998/namespace. This error was considered irrelevant by the XamlFileGenerator + } + )) + .GenericApply(((c3) => + { + // Class TestRepro.MainPage + global::Uno.UI.FrameworkElementHelper.SetBaseUri(c3, __baseUri_MainPage_d6cd66944958ced0c513e0a04797b51d); + c3.CreationComplete(); + } + )) + ; + OnInitializeCompleted(); + + Bindings = new MainPage_Bindings(this); + ((global::Microsoft.UI.Xaml.FrameworkElement)this).Loading += (s, e) => + { + __that.Bindings.Update(); + __that.Bindings.UpdateResources(); + } + ; + } + partial void OnInitializeCompleted(); + private global::Microsoft.UI.Xaml.Markup.ComponentHolder _component_0_Holder = new global::Microsoft.UI.Xaml.Markup.ComponentHolder(isWeak: true); + private global::Microsoft.UI.Xaml.Controls.ToggleSwitch _component_0 + { + get + { + return (global::Microsoft.UI.Xaml.Controls.ToggleSwitch)_component_0_Holder.Instance; + } + set + { + _component_0_Holder.Instance = value; + } + } + private interface IMainPage_Bindings + { + void Initialize(); + void Update(); + void UpdateResources(); + void StopTracking(); + void NotifyXLoad(string name); + } + #pragma warning disable 0169 // Suppress unused field warning in case Bindings is not used. + private IMainPage_Bindings Bindings; + #pragma warning restore 0169 + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + private class MainPage_Bindings : IMainPage_Bindings + { + #if UNO_HAS_UIELEMENT_IMPLICIT_PINNING + private global::System.WeakReference _ownerReference; + private global::TestRepro.MainPage Owner { get => (global::TestRepro.MainPage)_ownerReference?.Target; set => _ownerReference = new global::System.WeakReference(value); } + #else + private global::TestRepro.MainPage Owner { get; set; } + #endif + public MainPage_Bindings(global::TestRepro.MainPage owner) + { + Owner = owner; + } + void IMainPage_Bindings.NotifyXLoad(string name) + { + } + void IMainPage_Bindings.Initialize() + { + } + void IMainPage_Bindings.Update() + { + var owner = Owner; + owner._component_0.ApplyXBind(); + } + void IMainPage_Bindings.UpdateResources() + { + var owner = Owner; + owner._component_0.UpdateResourceBindings(resourceContextProvider: null); + } + void IMainPage_Bindings.StopTracking() + { + } + } + } +} +namespace MyProject +{ + static class MainPage_d6cd66944958ced0c513e0a04797b51dXamlApplyExtensions + { + public delegate void XamlApplyHandler0(global::Microsoft.UI.Xaml.Controls.ToggleSwitch instance); + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public static global::Microsoft.UI.Xaml.Controls.ToggleSwitch MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply(this global::Microsoft.UI.Xaml.Controls.ToggleSwitch instance, XamlApplyHandler0 handler) + { + handler(instance); + return instance; + } + public delegate void XamlApplyHandler1(global::Microsoft.UI.Xaml.Controls.StackPanel instance); + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public static global::Microsoft.UI.Xaml.Controls.StackPanel MainPage_d6cd66944958ced0c513e0a04797b51d_XamlApply(this global::Microsoft.UI.Xaml.Controls.StackPanel instance, XamlApplyHandler1 handler) + { + handler(instance); + return instance; + } + } +} diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs index 1b715a61074e..41a93b95a595 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs @@ -4423,16 +4423,14 @@ private ITypeSymbol GetXBindPropertyPathType(string propertyPath, INamedTypeSymb // We can't find the type. It could be something that is source-generated, or it could be a user error. // For source-generated members, it's not possible to reliably get this information due to https://github.com/dotnet/roslyn/issues/57239 // However, we do a best effort to handle the common scenario, which is code generated by CommunityToolkit.Mvvm. - foreach (var typeProvider in Generation.TypeProviders) + if (!TryFindThirdPartyType(currentType, part, out var thirdPartyType)) { - if (typeProvider.TryGetType(currentType, part) is { } thirdPartyType) - { - currentType = thirdPartyType; - break; - } + throw new InvalidOperationException($"Unable to find member [{part}] on type [{currentType}]"); + } + else + { + currentType = thirdPartyType; } - - throw new InvalidOperationException($"Unable to find member [{part}] on type [{currentType}]"); } if (isIndexer) @@ -4444,6 +4442,24 @@ private ITypeSymbol GetXBindPropertyPathType(string propertyPath, INamedTypeSymb return currentType; } + private bool TryFindThirdPartyType( + ITypeSymbol type, + string memberName, + [NotNullWhen(true)] out ITypeSymbol? thirdPartyType) + { + foreach (var typeProvider in Generation.TypeProviders) + { + if (typeProvider.TryGetType(type, memberName) is { } foundType) + { + thirdPartyType = foundType; + return true; + } + } + + thirdPartyType = null; + return false; + } + private string RewriteNamespaces(string xamlString) { foreach (var ns in _fileDefinition.Namespaces)