Skip to content

Commit e7527d7

Browse files
committed
Rename [NotifyPropertyChangedFor] attribute
1 parent 157436d commit e7527d7

File tree

7 files changed

+47
-47
lines changed

7 files changed

+47
-47
lines changed

CommunityToolkit.Mvvm.SourceGenerators/ComponentModel/ObservablePropertyGenerator.Execute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ bool IsPropertyNameValidWithGeneratedMembers(string propertyName)
285285
return false;
286286
}
287287

288-
if (attributeData.AttributeClass?.HasFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoNotifyChangeForAttribute") == true)
288+
if (attributeData.AttributeClass?.HasFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyPropertyChangedForAttribute") == true)
289289
{
290290
foreach (string? dependentPropertyName in attributeData.GetConstructorArguments<string>())
291291
{
@@ -300,7 +300,7 @@ bool IsPropertyNameValidWithGeneratedMembers(string propertyName)
300300
else
301301
{
302302
diagnostics.Add(
303-
AlsoNotifyChangeForInvalidTargetError,
303+
NotifyPropertyChangedForInvalidTargetError,
304304
fieldSymbol,
305305
dependentPropertyName ?? "",
306306
fieldSymbol.ContainingType);

CommunityToolkit.Mvvm.SourceGenerators/ComponentModel/ObservablePropertyGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
3838
fieldSymbols
3939
.Where(static item => item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute"));
4040

41-
// Get diagnostics for fields using [AlsoNotifyChangeFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty], but not [ObservableProperty]
41+
// Get diagnostics for fields using [NotifyPropertyChangedFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty], but not [ObservableProperty]
4242
IncrementalValuesProvider<Diagnostic> fieldSymbolsWithOrphanedDependentAttributeWithErrors =
4343
fieldSymbols
4444
.Where(static item =>
45-
(item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoNotifyChangeForAttribute") ||
45+
(item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyPropertyChangedForAttribute") ||
4646
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoNotifyCanExecuteForAttribute") ||
4747
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoBroadcastChangeAttribute") ||
4848
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoValidatePropertyAttribute")) &&

CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,19 @@ internal static class DiagnosticDescriptors
237237
helpLinkUri: "https://aka.ms/mvvmtoolkit");
238238

239239
/// <summary>
240-
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when the specified target for <c>[AlsoNotifyChangeFor]</c> is not valid.
240+
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when the specified target for <c>[NotifyPropertyChangedFor]</c> is not valid.
241241
/// <para>
242-
/// Format: <c>"The target(s) of [AlsoNotifyChangeFor] must be a (different) accessible property, but "{0}" has no (other) matches in type {1}</c>.
242+
/// Format: <c>"The target(s) of [NotifyPropertyChangedFor] must be a (different) accessible property, but "{0}" has no (other) matches in type {1}</c>.
243243
/// </para>
244244
/// </summary>
245-
public static readonly DiagnosticDescriptor AlsoNotifyChangeForInvalidTargetError = new DiagnosticDescriptor(
245+
public static readonly DiagnosticDescriptor NotifyPropertyChangedForInvalidTargetError = new DiagnosticDescriptor(
246246
id: "MVVMTK0015",
247-
title: "Invalid target name for [AlsoNotifyChangeFor]",
248-
messageFormat: "The target(s) of [AlsoNotifyChangeFor] must be a (different) accessible property, but \"{0}\" has no (other) matches in type {1}",
247+
title: "Invalid target name for [NotifyPropertyChangedFor]",
248+
messageFormat: "The target(s) of [NotifyPropertyChangedFor] must be a (different) accessible property, but \"{0}\" has no (other) matches in type {1}",
249249
category: typeof(ObservablePropertyGenerator).FullName,
250250
defaultSeverity: DiagnosticSeverity.Error,
251251
isEnabledByDefault: true,
252-
description: "The target(s) of [AlsoNotifyChangeFor] must be a (different) accessible property in its parent type.",
252+
description: "The target(s) of [NotifyPropertyChangedFor] must be a (different) accessible property in its parent type.",
253253
helpLinkUri: "https://aka.ms/mvvmtoolkit");
254254

255255
/// <summary>
@@ -319,17 +319,17 @@ internal static class DiagnosticDescriptors
319319
/// <summary>
320320
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when <c>[ObservableProperty]</c> is applied to a field in an invalid type.
321321
/// <para>
322-
/// Format: <c>"The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [AlsoNotifyChangeFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty]"</c>.
322+
/// Format: <c>"The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [NotifyPropertyChangedFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty]"</c>.
323323
/// </para>
324324
/// </summary>
325325
public static readonly DiagnosticDescriptor FieldWithOrphanedDependentObservablePropertyAttributesError = new DiagnosticDescriptor(
326326
id: "MVVMTK0020",
327327
title: "Invalid use of attributes dependent on [ObservableProperty]",
328-
messageFormat: "The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [AlsoNotifyChangeFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty]",
328+
messageFormat: "The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [NotifyPropertyChangedFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty]",
329329
category: typeof(ObservablePropertyGenerator).FullName,
330330
defaultSeverity: DiagnosticSeverity.Error,
331331
isEnabledByDefault: true,
332-
description: "Fields not annotated with [ObservableProperty] cannot use [AlsoNotifyChangeFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty].",
332+
description: "Fields not annotated with [ObservableProperty] cannot use [NotifyPropertyChangedFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty].",
333333
helpLinkUri: "https://aka.ms/mvvmtoolkit");
334334

335335
/// <summary>

CommunityToolkit.Mvvm/ComponentModel/Attributes/AlsoNotifyCanExecuteForAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
1313
/// used, the generated property setter will also call <see cref="IRelayCommand.NotifyCanExecuteChanged"/> for the properties specified
1414
/// in the attribute data, causing the validation logic for the command to be executed again. This can be useful to keep the code compact
1515
/// when there are one or more dependent commands that should also be notified when a property is updated. If this attribute is used in
16-
/// a field without <see cref="ObservablePropertyAttribute"/>, it is ignored (just like <see cref="AlsoNotifyChangeForAttribute"/>).
16+
/// a field without <see cref="ObservablePropertyAttribute"/>, it is ignored (just like <see cref="NotifyPropertyChangedForAttribute"/>).
1717
/// <para>
1818
/// In order to use this attribute, the target property has to implement the <see cref="IRelayCommand"/> interface.
1919
/// </para>

CommunityToolkit.Mvvm/ComponentModel/Attributes/AlsoNotifyChangeForAttribute.cs renamed to CommunityToolkit.Mvvm/ComponentModel/Attributes/NotifyPropertyChangedForAttribute.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
2626
/// partial class MyViewModel : ObservableObject
2727
/// {
2828
/// [ObservableProperty]
29-
/// [AlsoNotifyChangeFor(nameof(FullName))]
29+
/// [NotifyPropertyChangedFor(nameof(FullName))]
3030
/// private string name;
3131
///
3232
/// [ObservableProperty]
33-
/// [AlsoNotifyChangeFor(nameof(FullName))]
33+
/// [NotifyPropertyChangedFor(nameof(FullName))]
3434
/// private string surname;
3535
///
3636
/// public string FullName => $"{Name} {Surname}";
@@ -68,26 +68,26 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
6868
/// </code>
6969
/// </summary>
7070
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
71-
public sealed class AlsoNotifyChangeForAttribute : Attribute
71+
public sealed class NotifyPropertyChangedForAttribute : Attribute
7272
{
7373
/// <summary>
74-
/// Initializes a new instance of the <see cref="AlsoNotifyChangeForAttribute"/> class.
74+
/// Initializes a new instance of the <see cref="NotifyPropertyChangedForAttribute"/> class.
7575
/// </summary>
7676
/// <param name="propertyName">The name of the property to also notify when the annotated property changes.</param>
77-
public AlsoNotifyChangeForAttribute(string propertyName)
77+
public NotifyPropertyChangedForAttribute(string propertyName)
7878
{
7979
PropertyNames = new[] { propertyName };
8080
}
8181

8282
/// <summary>
83-
/// Initializes a new instance of the <see cref="AlsoNotifyChangeForAttribute"/> class.
83+
/// Initializes a new instance of the <see cref="NotifyPropertyChangedForAttribute"/> class.
8484
/// </summary>
8585
/// <param name="propertyName">The name of the property to also notify when the annotated property changes.</param>
8686
/// <param name="otherPropertyNames">
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, params string[] otherPropertyNames)
90+
public NotifyPropertyChangedForAttribute(string propertyName, params string[] otherPropertyNames)
9191
{
9292
PropertyNames = new[] { propertyName }.Concat(otherPropertyNames).ToArray();
9393
}

tests/CommunityToolkit.Mvvm.SourceGenerators.UnitTests/Test_SourceGeneratorsDiagnostics.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ public partial class SampleViewModel : ObservableObject
635635
}
636636

637637
[TestMethod]
638-
public void AlsoNotifyChangeForInvalidTargetError_Null()
638+
public void NotifyPropertyChangedForInvalidTargetError_Null()
639639
{
640640
string source = @"
641641
using CommunityToolkit.Mvvm.ComponentModel;
@@ -645,7 +645,7 @@ namespace MyApp
645645
public partial class SampleViewModel : ObservableObject
646646
{
647647
[ObservableProperty]
648-
[AlsoNotifyChangeFor(null)]
648+
[NotifyPropertyChangedFor(null)]
649649
private string name;
650650
}
651651
}";
@@ -654,7 +654,7 @@ public partial class SampleViewModel : ObservableObject
654654
}
655655

656656
[TestMethod]
657-
public void AlsoNotifyChangeForInvalidTargetError_SamePropertyAsGeneratedOneFromSelf()
657+
public void NotifyPropertyChangedForInvalidTargetError_SamePropertyAsGeneratedOneFromSelf()
658658
{
659659
string source = @"
660660
using CommunityToolkit.Mvvm.ComponentModel;
@@ -664,7 +664,7 @@ namespace MyApp
664664
public partial class SampleViewModel : ObservableObject
665665
{
666666
[ObservableProperty]
667-
[AlsoNotifyChangeFor(nameof(Name))]
667+
[NotifyPropertyChangedFor(nameof(Name))]
668668
private string name;
669669
}
670670
}";
@@ -673,7 +673,7 @@ public partial class SampleViewModel : ObservableObject
673673
}
674674

675675
[TestMethod]
676-
public void AlsoNotifyChangeForInvalidTargetError_Missing()
676+
public void NotifyPropertyChangedForInvalidTargetError_Missing()
677677
{
678678
string source = @"
679679
using CommunityToolkit.Mvvm.ComponentModel;
@@ -683,7 +683,7 @@ namespace MyApp
683683
public partial class SampleViewModel : ObservableObject
684684
{
685685
[ObservableProperty]
686-
[AlsoNotifyChangeFor(""FooBar"")]
686+
[NotifyPropertyChangedFor(""FooBar"")]
687687
private string name;
688688
}
689689
}";
@@ -692,7 +692,7 @@ public partial class SampleViewModel : ObservableObject
692692
}
693693

694694
[TestMethod]
695-
public void AlsoNotifyChangeForInvalidTargetError_InvalidType()
695+
public void NotifyPropertyChangedForInvalidTargetError_InvalidType()
696696
{
697697
string source = @"
698698
using CommunityToolkit.Mvvm.ComponentModel;
@@ -702,7 +702,7 @@ namespace MyApp
702702
public partial class SampleViewModel : ObservableObject
703703
{
704704
[ObservableProperty]
705-
[AlsoNotifyChangeFor(nameof(Foo))]
705+
[NotifyPropertyChangedFor(nameof(Foo))]
706706
private string name;
707707
708708
public void Foo()
@@ -963,7 +963,7 @@ public partial class MyViewModel : INotifyPropertyChanged
963963
}
964964

965965
[TestMethod]
966-
public void FieldWithOrphanedDependentObservablePropertyAttributesError_AlsoNotifyChangeFor()
966+
public void FieldWithOrphanedDependentObservablePropertyAttributesError_NotifyPropertyChangedFor()
967967
{
968968
string source = @"
969969
using CommunityToolkit.Mvvm.ComponentModel;
@@ -972,7 +972,7 @@ namespace MyApp
972972
{
973973
public partial class MyViewModel
974974
{
975-
[AlsoNotifyChangeFor("")]
975+
[NotifyPropertyChangedFor("")]
976976
public int number;
977977
}
978978
}";
@@ -1026,9 +1026,9 @@ namespace MyApp
10261026
{
10271027
public partial class MyViewModel
10281028
{
1029-
[AlsoNotifyChangeFor("")]
1030-
[AlsoNotifyChangeFor("")]
1031-
[AlsoNotifyChangeFor("")]
1029+
[NotifyPropertyChangedFor("")]
1030+
[NotifyPropertyChangedFor("")]
1031+
[NotifyPropertyChangedFor("")]
10321032
[AlsoNotifyCanExecuteFor("")]
10331033
[AlsoNotifyCanExecuteFor("")]
10341034
[AlsoBroadcastChange]

tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservablePropertyAttribute.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void Test_ObservablePropertyAttributeRightBelowRegion_Events()
139139
}
140140

141141
[TestMethod]
142-
public void Test_AlsoNotifyChangeForAttribute_Events()
142+
public void Test_NotifyPropertyChangedForAttribute_Events()
143143
{
144144
DependentPropertyModel model = new();
145145

@@ -294,7 +294,7 @@ public void Test_GeneratedPropertiesWithValidationAttributesOverFields()
294294
}
295295

296296
[TestMethod]
297-
public void Test_AlsoNotifyChangeFor()
297+
public void Test_NotifyPropertyChangedFor()
298298
{
299299
DependentPropertyModel model = new();
300300

@@ -312,7 +312,7 @@ public void Test_AlsoNotifyChangeFor()
312312
}
313313

314314
[TestMethod]
315-
public void Test_AlsoNotifyChangeFor_GeneratedCommand()
315+
public void Test_NotifyPropertyChangedFor_GeneratedCommand()
316316
{
317317
DependentPropertyModel2 model = new();
318318

@@ -330,7 +330,7 @@ public void Test_AlsoNotifyChangeFor_GeneratedCommand()
330330
}
331331

332332
[TestMethod]
333-
public void Test_AlsoNotifyChangeFor_IRelayCommandProperty()
333+
public void Test_NotifyPropertyChangedFor_IRelayCommandProperty()
334334
{
335335
DependentPropertyModel3 model = new();
336336

@@ -348,7 +348,7 @@ public void Test_AlsoNotifyChangeFor_IRelayCommandProperty()
348348
}
349349

350350
[TestMethod]
351-
public void Test_AlsoNotifyChangeFor_IAsyncRelayCommandOfTProperty()
351+
public void Test_NotifyPropertyChangedFor_IAsyncRelayCommandOfTProperty()
352352
{
353353
DependentPropertyModel4 model = new();
354354

@@ -784,12 +784,12 @@ public partial class ConcreteViewModel : BaseViewModel
784784
{
785785
// Inherited property
786786
[ObservableProperty]
787-
[AlsoNotifyChangeFor(nameof(Content))]
787+
[NotifyPropertyChangedFor(nameof(Content))]
788788
private string? _a;
789789

790790
// Inherited generated property
791791
[ObservableProperty]
792-
[AlsoNotifyChangeFor(nameof(SomeGeneratedProperty))]
792+
[NotifyPropertyChangedFor(nameof(SomeGeneratedProperty))]
793793
private string? _b;
794794

795795
// Inherited generated command
@@ -826,12 +826,12 @@ public partial class SampleModel : ObservableObject
826826
public sealed partial class DependentPropertyModel
827827
{
828828
[ObservableProperty]
829-
[AlsoNotifyChangeFor(nameof(FullName))]
830-
[AlsoNotifyChangeFor(nameof(Alias))]
829+
[NotifyPropertyChangedFor(nameof(FullName))]
830+
[NotifyPropertyChangedFor(nameof(Alias))]
831831
private string? name;
832832

833833
[ObservableProperty]
834-
[AlsoNotifyChangeFor(nameof(FullName), nameof(Alias))]
834+
[NotifyPropertyChangedFor(nameof(FullName), nameof(Alias))]
835835
[AlsoNotifyCanExecuteFor(nameof(MyCommand))]
836836
private string? surname;
837837

@@ -846,7 +846,7 @@ public sealed partial class DependentPropertyModel
846846
public sealed partial class DependentPropertyModel2
847847
{
848848
[ObservableProperty]
849-
[AlsoNotifyChangeFor(nameof(FullName), nameof(Alias))]
849+
[NotifyPropertyChangedFor(nameof(FullName), nameof(Alias))]
850850
[AlsoNotifyCanExecuteFor(nameof(TestFromMethodCommand))]
851851
private string? text;
852852

@@ -866,7 +866,7 @@ private void TestFromMethod()
866866
public sealed partial class DependentPropertyModel3
867867
{
868868
[ObservableProperty]
869-
[AlsoNotifyChangeFor(nameof(FullName), nameof(Alias))]
869+
[NotifyPropertyChangedFor(nameof(FullName), nameof(Alias))]
870870
[AlsoNotifyCanExecuteFor(nameof(MyCommand))]
871871
private string? text;
872872

@@ -881,7 +881,7 @@ public sealed partial class DependentPropertyModel3
881881
public sealed partial class DependentPropertyModel4
882882
{
883883
[ObservableProperty]
884-
[AlsoNotifyChangeFor(nameof(FullName), nameof(Alias))]
884+
[NotifyPropertyChangedFor(nameof(FullName), nameof(Alias))]
885885
[AlsoNotifyCanExecuteFor(nameof(MyCommand))]
886886
private string? text;
887887

0 commit comments

Comments
 (0)