Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codegen): Adjust mvvm toolkit properties discovery (backport #18326) #18334

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"""
<Page x:Class="TestRepro.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">

<StackPanel>
<ToggleSwitch IsOn="{x:Bind ViewModel.IsEnabled, Mode=TwoWay}" OnContent="Enabled" OffContent="Disabled"/>
</StackPanel>
</Page>
""");

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",
"""
<Page x:Class="TestRepro.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">

<StackPanel>
<ToggleSwitch IsOn="{x:Bind ViewModel.SubModel.IsEnabled, Mode=TwoWay}" OnContent="Enabled" OffContent="Disabled"/>
</StackPanel>
</Page>
""");

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()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace TestRepro
{
/// <inheritdoc/>
partial class MyViewModel
{
/// <inheritdoc cref="_isEnabled"/>
[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<bool>.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);
}
}
}

/// <summary>Executes the logic for when <see cref="IsEnabled"/> is changing.</summary>
/// <param name="value">The new property value being set.</param>
/// <remarks>This method is invoked right before the value of <see cref="IsEnabled"/> is changed.</remarks>
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")]
partial void OnIsEnabledChanging(bool value);
/// <summary>Executes the logic for when <see cref="IsEnabled"/> is changing.</summary>
/// <param name="oldValue">The previous property value that is being replaced.</param>
/// <param name="newValue">The new property value being set.</param>
/// <remarks>This method is invoked right before the value of <see cref="IsEnabled"/> is changed.</remarks>
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")]
partial void OnIsEnabledChanging(bool oldValue, bool newValue);
/// <summary>Executes the logic for when <see cref="IsEnabled"/> just changed.</summary>
/// <param name="value">The new property value that was set.</param>
/// <remarks>This method is invoked right after the value of <see cref="IsEnabled"/> is changed.</remarks>
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")]
partial void OnIsEnabledChanged(bool value);
/// <summary>Executes the logic for when <see cref="IsEnabled"/> just changed.</summary>
/// <param name="oldValue">The previous property value that was replaced.</param>
/// <param name="newValue">The new property value that was set.</param>
/// <remarks>This method is invoked right after the value of <see cref="IsEnabled"/> is changed.</remarks>
[global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.2.0.0")]
partial void OnIsEnabledChanged(bool oldValue, bool newValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace CommunityToolkit.Mvvm.ComponentModel.__Internals
{
/// <summary>
/// A helper type providing cached, reusable <see cref="global::System.ComponentModel.PropertyChangedEventArgs"/> instances
/// for all properties generated with <see cref="global::CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute"/>.
/// </summary>
[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
{
/// <summary>The cached <see cref="global::System.ComponentModel.PropertyChangedEventArgs"/> instance for all "IsEnabled" generated properties.</summary>
[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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// <auto-generated/>
#pragma warning disable
#nullable enable
namespace CommunityToolkit.Mvvm.ComponentModel.__Internals
{
/// <summary>
/// A helper type providing cached, reusable <see cref="global::System.ComponentModel.PropertyChangingEventArgs"/> instances
/// for all properties generated with <see cref="global::CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute"/>.
/// </summary>
[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
{
/// <summary>The cached <see cref="global::System.ComponentModel.PropertyChangingEventArgs"/> instance for all "IsEnabled" generated properties.</summary>
[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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// <autogenerated />
namespace MyProject
{
/// <summary>
/// Contains all the static resources defined for the application
/// </summary>
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();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// <auto-generated />
[assembly: global::System.Reflection.AssemblyMetadata("UnoHasLocalizationResources", "False")]
Loading
Loading