Skip to content

Commit 9f887e6

Browse files
committed
Fixed [AlsoNotifyChangeFor] attribute definition
1 parent 5dfc575 commit 9f887e6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Microsoft.Toolkit.Mvvm/ComponentModel/Attributes/AlsoNotifyChangeForAttribute.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

@@ -67,7 +67,7 @@ namespace Microsoft.Toolkit.Mvvm.ComponentModel
6767
/// }
6868
/// </code>
6969
/// </summary>
70-
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
70+
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
7171
public sealed class AlsoNotifyChangeForAttribute : Attribute
7272
{
7373
/// <summary>
@@ -87,7 +87,7 @@ public AlsoNotifyChangeForAttribute(string propertyName)
8787
/// The other property names to also notify when the annotated property changes. This parameter can optionally
8888
/// be used to indicate a series of dependent properties from the same attribute, to keep the code more compact.
8989
/// </param>
90-
public AlsoNotifyChangeForAttribute(string propertyName, string[] otherPropertyNames)
90+
public AlsoNotifyChangeForAttribute(string propertyName, params string[] otherPropertyNames)
9191
{
9292
PropertyNames = new[] { propertyName }.Concat(otherPropertyNames).ToArray();
9393
}

UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void Test_AlsoNotifyChangeForAttribute_Events()
7171
model.Name = "Bob";
7272
model.Surname = "Ross";
7373

74-
CollectionAssert.AreEqual(new[] { nameof(model.Name), nameof(model.FullName), nameof(model.Surname), nameof(model.FullName) }, propertyNames);
74+
CollectionAssert.AreEqual(new[] { nameof(model.Name), nameof(model.FullName), nameof(model.Alias), nameof(model.Surname), nameof(model.FullName), nameof(model.Alias) }, propertyNames);
7575
}
7676

7777
[TestCategory("Mvvm")]
@@ -169,13 +169,16 @@ public sealed partial class DependentPropertyModel
169169
{
170170
[ObservableProperty]
171171
[AlsoNotifyChangeFor(nameof(FullName))]
172+
[AlsoNotifyChangeFor(nameof(Alias))]
172173
private string? name;
173174

174175
[ObservableProperty]
175-
[AlsoNotifyChangeFor(nameof(FullName))]
176+
[AlsoNotifyChangeFor(nameof(FullName), nameof(Alias))]
176177
private string? surname;
177178

178179
public string FullName => $"{Name} {Surname}";
180+
181+
public string Alias => $"{Name?.ToLower()}{Surname?.ToLower()}";
179182
}
180183

181184
public partial class MyFormViewModel : ObservableValidator

0 commit comments

Comments
 (0)