Skip to content

Commit 91a7798

Browse files
committed
Rename [NotifyCanExecuteChangedFor] attribute
1 parent e7527d7 commit 91a7798

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ bool IsCommandNameValidWithGeneratedMembers(string commandName)
374374
return false;
375375
}
376376

377-
if (attributeData.AttributeClass?.HasFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoNotifyCanExecuteForAttribute") == true)
377+
if (attributeData.AttributeClass?.HasFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyCanExecuteChangedForAttribute") == true)
378378
{
379379
foreach (string? commandName in attributeData.GetConstructorArguments<string>())
380380
{
@@ -390,7 +390,7 @@ bool IsCommandNameValidWithGeneratedMembers(string commandName)
390390
else
391391
{
392392
diagnostics.Add(
393-
AlsoNotifyCanExecuteForInvalidTargetError,
393+
NotifyCanExecuteChangedForInvalidTargetError,
394394
fieldSymbol,
395395
commandName ?? "",
396396
fieldSymbol.ContainingType);

CommunityToolkit.Mvvm.SourceGenerators/ComponentModel/ObservablePropertyGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ 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 [NotifyPropertyChangedFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty], but not [ObservableProperty]
41+
// Get diagnostics for fields using [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [AlsoValidateProperty], but not [ObservableProperty]
4242
IncrementalValuesProvider<Diagnostic> fieldSymbolsWithOrphanedDependentAttributeWithErrors =
4343
fieldSymbols
4444
.Where(static item =>
4545
(item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyPropertyChangedForAttribute") ||
46-
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoNotifyCanExecuteForAttribute") ||
46+
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyCanExecuteChangedForAttribute") ||
4747
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoBroadcastChangeAttribute") ||
4848
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoValidatePropertyAttribute")) &&
4949
!item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute"))

CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs

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

255255
/// <summary>
256-
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when the specified target for <c>[AlsoNotifyCanExecuteFor]</c> is not valid.
256+
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when the specified target for <c>[NotifyCanExecuteChangedFor]</c> is not valid.
257257
/// <para>
258-
/// Format: <c>"The target(s) of [AlsoNotifyCanExecuteFor] must be an accessible <c>IRelayCommand</c> property, but "{0}" has no matches in type {1}</c>.
258+
/// Format: <c>"The target(s) of [NotifyCanExecuteChangedFor] must be an accessible <c>IRelayCommand</c> property, but "{0}" has no matches in type {1}</c>.
259259
/// </para>
260260
/// </summary>
261-
public static readonly DiagnosticDescriptor AlsoNotifyCanExecuteForInvalidTargetError = new DiagnosticDescriptor(
261+
public static readonly DiagnosticDescriptor NotifyCanExecuteChangedForInvalidTargetError = new DiagnosticDescriptor(
262262
id: "MVVMTK0016",
263-
title: "Invalid target name for [AlsoNotifyCanExecuteFor]",
264-
messageFormat: "The target(s) of [AlsoNotifyCanExecuteFor] must be an accessible IRelayCommand property, but \"{0}\" has no matches in type {1}",
263+
title: "Invalid target name for [NotifyCanExecuteChangedFor]",
264+
messageFormat: "The target(s) of [NotifyCanExecuteChangedFor] must be an accessible IRelayCommand property, but \"{0}\" has no matches in type {1}",
265265
category: typeof(ObservablePropertyGenerator).FullName,
266266
defaultSeverity: DiagnosticSeverity.Error,
267267
isEnabledByDefault: true,
268-
description: "The target(s) of [AlsoNotifyCanExecuteFor] must be an accessible IRelayCommand property in its parent type.",
268+
description: "The target(s) of [NotifyCanExecuteChangedFor] must be an accessible IRelayCommand property in its parent type.",
269269
helpLinkUri: "https://aka.ms/mvvmtoolkit");
270270

271271
/// <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 [NotifyPropertyChangedFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty]"</c>.
322+
/// Format: <c>"The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [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 [NotifyPropertyChangedFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty]",
328+
messageFormat: "The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [AlsoValidateProperty]",
329329
category: typeof(ObservablePropertyGenerator).FullName,
330330
defaultSeverity: DiagnosticSeverity.Error,
331331
isEnabledByDefault: true,
332-
description: "Fields not annotated with [ObservableProperty] cannot use [NotifyPropertyChangedFor], [AlsoNotifyCanExecuteFor], [AlsoBroadcastChange] and [AlsoValidateProperty].",
332+
description: "Fields not annotated with [ObservableProperty] cannot use [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [AlsoValidateProperty].",
333333
helpLinkUri: "https://aka.ms/mvvmtoolkit");
334334

335335
/// <summary>

CommunityToolkit.Mvvm/ComponentModel/Attributes/AlsoNotifyCanExecuteForAttribute.cs renamed to CommunityToolkit.Mvvm/ComponentModel/Attributes/NotifyCanExecuteChangedForAttribute.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
2323
/// partial class MyViewModel : ObservableObject
2424
/// {
2525
/// [ObservableProperty]
26-
/// [AlsoNotifyCanExecuteFor(nameof(GreetUserCommand))]
26+
/// [NotifyCanExecuteChangedFor(nameof(GreetUserCommand))]
2727
/// private string name;
2828
///
2929
/// public IRelayCommand GreetUserCommand { get; }
@@ -49,26 +49,26 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
4949
/// </code>
5050
/// </summary>
5151
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
52-
public sealed class AlsoNotifyCanExecuteForAttribute : Attribute
52+
public sealed class NotifyCanExecuteChangedForAttribute : Attribute
5353
{
5454
/// <summary>
55-
/// Initializes a new instance of the <see cref="AlsoNotifyCanExecuteForAttribute"/> class.
55+
/// Initializes a new instance of the <see cref="NotifyCanExecuteChangedForAttribute"/> class.
5656
/// </summary>
5757
/// <param name="commandName">The name of the command to also notify when the annotated property changes.</param>
58-
public AlsoNotifyCanExecuteForAttribute(string commandName)
58+
public NotifyCanExecuteChangedForAttribute(string commandName)
5959
{
6060
CommandNames = new[] { commandName };
6161
}
6262

6363
/// <summary>
64-
/// Initializes a new instance of the <see cref="AlsoNotifyCanExecuteForAttribute"/> class.
64+
/// Initializes a new instance of the <see cref="NotifyCanExecuteChangedForAttribute"/> class.
6565
/// </summary>
6666
/// <param name="commandName">The name of the property to also notify when the annotated property changes.</param>
6767
/// <param name="otherCommandNames">
6868
/// The other command names to also notify when the annotated property changes. This parameter can optionally
6969
/// be used to indicate a series of dependent commands from the same attribute, to keep the code more compact.
7070
/// </param>
71-
public AlsoNotifyCanExecuteForAttribute(string commandName, params string[] otherCommandNames)
71+
public NotifyCanExecuteChangedForAttribute(string commandName, params string[] otherCommandNames)
7272
{
7373
CommandNames = new[] { commandName }.Concat(otherCommandNames).ToArray();
7474
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ public void Foo()
715715
}
716716

717717
[TestMethod]
718-
public void AlsoNotifyCanExecuteForInvalidTargetError_Null()
718+
public void NotifyCanExecuteChangedForInvalidTargetError_Null()
719719
{
720720
string source = @"
721721
using CommunityToolkit.Mvvm.ComponentModel;
@@ -725,7 +725,7 @@ namespace MyApp
725725
public partial class SampleViewModel : ObservableObject
726726
{
727727
[ObservableProperty]
728-
[AlsoNotifyCanExecuteFor(null)]
728+
[NotifyCanExecuteChangedFor(null)]
729729
private string name;
730730
}
731731
}";
@@ -734,7 +734,7 @@ public partial class SampleViewModel : ObservableObject
734734
}
735735

736736
[TestMethod]
737-
public void AlsoNotifyCanExecuteForInvalidTargetError_Missing()
737+
public void NotifyCanExecuteChangedForInvalidTargetError_Missing()
738738
{
739739
string source = @"
740740
using CommunityToolkit.Mvvm.ComponentModel;
@@ -744,7 +744,7 @@ namespace MyApp
744744
public partial class SampleViewModel : ObservableObject
745745
{
746746
[ObservableProperty]
747-
[AlsoNotifyCanExecuteFor(""FooBar"")]
747+
[NotifyCanExecuteChangedFor(""FooBar"")]
748748
private string name;
749749
}
750750
}";
@@ -753,7 +753,7 @@ public partial class SampleViewModel : ObservableObject
753753
}
754754

755755
[TestMethod]
756-
public void AlsoNotifyCanExecuteForInvalidTargetError_InvalidMemberType()
756+
public void NotifyCanExecuteChangedForInvalidTargetError_InvalidMemberType()
757757
{
758758
string source = @"
759759
using CommunityToolkit.Mvvm.ComponentModel;
@@ -763,7 +763,7 @@ namespace MyApp
763763
public partial class SampleViewModel : ObservableObject
764764
{
765765
[ObservableProperty]
766-
[AlsoNotifyCanExecuteFor(nameof(Foo))]
766+
[NotifyCanExecuteChangedFor(nameof(Foo))]
767767
private string name;
768768
769769
public void Foo()
@@ -776,7 +776,7 @@ public void Foo()
776776
}
777777

778778
[TestMethod]
779-
public void AlsoNotifyCanExecuteForInvalidTargetError_InvalidPropertyType()
779+
public void NotifyCanExecuteChangedForInvalidTargetError_InvalidPropertyType()
780780
{
781781
string source = @"
782782
using CommunityToolkit.Mvvm.ComponentModel;
@@ -786,7 +786,7 @@ namespace MyApp
786786
public partial class SampleViewModel : ObservableObject
787787
{
788788
[ObservableProperty]
789-
[AlsoNotifyCanExecuteFor(nameof(Foo))]
789+
[NotifyCanExecuteChangedFor(nameof(Foo))]
790790
private string name;
791791
792792
public string Foo { get; }
@@ -797,7 +797,7 @@ public partial class SampleViewModel : ObservableObject
797797
}
798798

799799
[TestMethod]
800-
public void AlsoNotifyCanExecuteForInvalidTargetError_InvalidCommandType()
800+
public void NotifyCanExecuteChangedForInvalidTargetError_InvalidCommandType()
801801
{
802802
string source = @"
803803
using CommunityToolkit.Mvvm.ComponentModel;
@@ -808,7 +808,7 @@ namespace MyApp
808808
public partial class SampleViewModel : ObservableObject
809809
{
810810
[ObservableProperty]
811-
[AlsoNotifyCanExecuteFor(nameof(FooCommand))]
811+
[NotifyCanExecuteChangedFor(nameof(FooCommand))]
812812
private string name;
813813
814814
public ICommand FooCommand { get; }
@@ -981,7 +981,7 @@ public partial class MyViewModel
981981
}
982982

983983
[TestMethod]
984-
public void FieldWithOrphanedDependentObservablePropertyAttributesError_AlsoNotifyCanExecuteFor()
984+
public void FieldWithOrphanedDependentObservablePropertyAttributesError_NotifyCanExecuteChangedFor()
985985
{
986986
string source = @"
987987
using CommunityToolkit.Mvvm.ComponentModel;
@@ -990,7 +990,7 @@ namespace MyApp
990990
{
991991
public partial class MyViewModel
992992
{
993-
[AlsoNotifyCanExecuteFor("")]
993+
[NotifyCanExecuteChangedFor("")]
994994
public int number;
995995
}
996996
}";
@@ -1029,8 +1029,8 @@ public partial class MyViewModel
10291029
[NotifyPropertyChangedFor("")]
10301030
[NotifyPropertyChangedFor("")]
10311031
[NotifyPropertyChangedFor("")]
1032-
[AlsoNotifyCanExecuteFor("")]
1033-
[AlsoNotifyCanExecuteFor("")]
1032+
[NotifyCanExecuteChangedFor("")]
1033+
[NotifyCanExecuteChangedFor("")]
10341034
[AlsoBroadcastChange]
10351035
public int number;
10361036
}

tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservablePropertyAttribute.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -794,12 +794,12 @@ public partial class ConcreteViewModel : BaseViewModel
794794

795795
// Inherited generated command
796796
[ObservableProperty]
797-
[AlsoNotifyCanExecuteFor(nameof(DoSomethingCommand))]
797+
[NotifyCanExecuteChangedFor(nameof(DoSomethingCommand))]
798798
private string? _c;
799799

800800
// Inherited manual command
801801
[ObservableProperty]
802-
[AlsoNotifyCanExecuteFor(nameof(ManualCommand))]
802+
[NotifyCanExecuteChangedFor(nameof(ManualCommand))]
803803
private string? _d;
804804
}
805805

@@ -832,7 +832,7 @@ public sealed partial class DependentPropertyModel
832832

833833
[ObservableProperty]
834834
[NotifyPropertyChangedFor(nameof(FullName), nameof(Alias))]
835-
[AlsoNotifyCanExecuteFor(nameof(MyCommand))]
835+
[NotifyCanExecuteChangedFor(nameof(MyCommand))]
836836
private string? surname;
837837

838838
public string FullName => $"{Name} {Surname}";
@@ -847,7 +847,7 @@ public sealed partial class DependentPropertyModel2
847847
{
848848
[ObservableProperty]
849849
[NotifyPropertyChangedFor(nameof(FullName), nameof(Alias))]
850-
[AlsoNotifyCanExecuteFor(nameof(TestFromMethodCommand))]
850+
[NotifyCanExecuteChangedFor(nameof(TestFromMethodCommand))]
851851
private string? text;
852852

853853
public string FullName => "";
@@ -867,7 +867,7 @@ public sealed partial class DependentPropertyModel3
867867
{
868868
[ObservableProperty]
869869
[NotifyPropertyChangedFor(nameof(FullName), nameof(Alias))]
870-
[AlsoNotifyCanExecuteFor(nameof(MyCommand))]
870+
[NotifyCanExecuteChangedFor(nameof(MyCommand))]
871871
private string? text;
872872

873873
public string FullName => "";
@@ -882,7 +882,7 @@ public sealed partial class DependentPropertyModel4
882882
{
883883
[ObservableProperty]
884884
[NotifyPropertyChangedFor(nameof(FullName), nameof(Alias))]
885-
[AlsoNotifyCanExecuteFor(nameof(MyCommand))]
885+
[NotifyCanExecuteChangedFor(nameof(MyCommand))]
886886
private string? text;
887887

888888
public string FullName => "";

0 commit comments

Comments
 (0)