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

Fixed [AlsoNotifyChangeFor] attribute definition #4242

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
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -67,7 +67,7 @@ namespace Microsoft.Toolkit.Mvvm.ComponentModel
/// }
/// </code>
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
public sealed class AlsoNotifyChangeForAttribute : Attribute
{
/// <summary>
Expand All @@ -87,7 +87,7 @@ public AlsoNotifyChangeForAttribute(string propertyName)
/// The other property names to also notify when the annotated property changes. This parameter can optionally
/// be used to indicate a series of dependent properties from the same attribute, to keep the code more compact.
/// </param>
public AlsoNotifyChangeForAttribute(string propertyName, string[] otherPropertyNames)
public AlsoNotifyChangeForAttribute(string propertyName, params string[] otherPropertyNames)
{
PropertyNames = new[] { propertyName }.Concat(otherPropertyNames).ToArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void Test_AlsoNotifyChangeForAttribute_Events()
model.Name = "Bob";
model.Surname = "Ross";

CollectionAssert.AreEqual(new[] { nameof(model.Name), nameof(model.FullName), nameof(model.Surname), nameof(model.FullName) }, propertyNames);
CollectionAssert.AreEqual(new[] { nameof(model.Name), nameof(model.FullName), nameof(model.Alias), nameof(model.Surname), nameof(model.FullName), nameof(model.Alias) }, propertyNames);
}

[TestCategory("Mvvm")]
Expand Down Expand Up @@ -169,13 +169,16 @@ public sealed partial class DependentPropertyModel
{
[ObservableProperty]
[AlsoNotifyChangeFor(nameof(FullName))]
[AlsoNotifyChangeFor(nameof(Alias))]
private string? name;

[ObservableProperty]
[AlsoNotifyChangeFor(nameof(FullName))]
[AlsoNotifyChangeFor(nameof(FullName), nameof(Alias))]
private string? surname;

public string FullName => $"{Name} {Surname}";

public string Alias => $"{Name?.ToLower()}{Surname?.ToLower()}";
}

public partial class MyFormViewModel : ObservableValidator
Expand Down