Skip to content

Commit 52e5ebf

Browse files
committed
Rename [NotifyRecipients] attribute
1 parent 29f94a4 commit 52e5ebf

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

CommunityToolkit.Mvvm.SourceGenerators/ComponentModel/Models/PropertyInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace CommunityToolkit.Mvvm.SourceGenerators.ComponentModel.Models;
2020
/// <param name="PropertyChangingNames">The sequence of property changing properties to notify.</param>
2121
/// <param name="PropertyChangedNames">The sequence of property changed properties to notify.</param>
2222
/// <param name="NotifiedCommandNames">The sequence of commands to notify.</param>
23-
/// <param name="AlsoBroadcastChange">Whether or not the generated property also broadcasts changes.</param>
23+
/// <param name="NotifyRecipients">Whether or not the generated property also broadcasts changes.</param>
2424
/// <param name="NotifyDataErrorInfo">Whether or not the generated property also validates its value.</param>
2525
/// <param name="ForwardedAttributes">The sequence of forwarded attributes for the generated property.</param>
2626
internal sealed record PropertyInfo(
@@ -30,7 +30,7 @@ internal sealed record PropertyInfo(
3030
ImmutableArray<string> PropertyChangingNames,
3131
ImmutableArray<string> PropertyChangedNames,
3232
ImmutableArray<string> NotifiedCommandNames,
33-
bool AlsoBroadcastChange,
33+
bool NotifyRecipients,
3434
bool NotifyDataErrorInfo,
3535
ImmutableArray<AttributeInfo> ForwardedAttributes)
3636
{
@@ -48,7 +48,7 @@ protected override void AddToHashCode(ref HashCode hashCode, PropertyInfo obj)
4848
hashCode.AddRange(obj.PropertyChangingNames);
4949
hashCode.AddRange(obj.PropertyChangedNames);
5050
hashCode.AddRange(obj.NotifiedCommandNames);
51-
hashCode.Add(obj.AlsoBroadcastChange);
51+
hashCode.Add(obj.NotifyRecipients);
5252
hashCode.Add(obj.NotifyDataErrorInfo);
5353
hashCode.AddRange(obj.ForwardedAttributes, AttributeInfo.Comparer.Default);
5454
}
@@ -63,7 +63,7 @@ protected override bool AreEqual(PropertyInfo x, PropertyInfo y)
6363
x.PropertyChangingNames.SequenceEqual(y.PropertyChangingNames) &&
6464
x.PropertyChangedNames.SequenceEqual(y.PropertyChangedNames) &&
6565
x.NotifiedCommandNames.SequenceEqual(y.NotifiedCommandNames) &&
66-
x.AlsoBroadcastChange == y.AlsoBroadcastChange &&
66+
x.NotifyRecipients == y.NotifyRecipients &&
6767
x.NotifyDataErrorInfo == y.NotifyDataErrorInfo &&
6868
x.ForwardedAttributes.SequenceEqual(y.ForwardedAttributes, AttributeInfo.Comparer.Default);
6969
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,14 @@ bool IsCommandNameValidWithGeneratedMembers(string commandName)
410410
/// <param name="attributeData">The <see cref="AttributeData"/> instance for <paramref name="fieldSymbol"/>.</param>
411411
/// <param name="diagnostics">The current collection of gathered diagnostics.</param>
412412
/// <param name="isBroadcastTargetValid">Whether or not the the property is in a valid target that can broadcast changes.</param>
413-
/// <returns>Whether or not the generated property for <paramref name="fieldSymbol"/> used <c>[AlsoBroadcastChange]</c>.</returns>
413+
/// <returns>Whether or not the generated property for <paramref name="fieldSymbol"/> used <c>[NotifyRecipients]</c>.</returns>
414414
private static bool TryGetIsBroadcastingChanges(
415415
IFieldSymbol fieldSymbol,
416416
AttributeData attributeData,
417417
ImmutableArray<Diagnostic>.Builder diagnostics,
418418
out bool isBroadcastTargetValid)
419419
{
420-
if (attributeData.AttributeClass?.HasFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoBroadcastChangeAttribute") == true)
420+
if (attributeData.AttributeClass?.HasFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyRecipientsAttribute") == true)
421421
{
422422
// If the containing type is valid, track it
423423
if (fieldSymbol.ContainingType.InheritsFromFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.ObservableRecipient") ||
@@ -430,7 +430,7 @@ private static bool TryGetIsBroadcastingChanges(
430430

431431
// Otherwise just emit the diagnostic and then ignore the attribute
432432
diagnostics.Add(
433-
InvalidContainingTypeForAlsoBroadcastChangeFieldError,
433+
InvalidContainingTypeForNotifyRecipientsFieldError,
434434
fieldSymbol,
435435
fieldSymbol.ContainingType,
436436
fieldSymbol.Name);
@@ -532,7 +532,7 @@ public static MemberDeclarationSyntax GetPropertySyntax(PropertyInfo propertyInf
532532
string name => IdentifierName(name)
533533
};
534534

535-
if (propertyInfo.AlsoBroadcastChange)
535+
if (propertyInfo.NotifyRecipients)
536536
{
537537
// If broadcasting changes are required, also store the old value.
538538
// This code generates a statement as follows:
@@ -630,7 +630,7 @@ public static MemberDeclarationSyntax GetPropertySyntax(PropertyInfo propertyInf
630630
}
631631

632632
// Also broadcast the change, if requested
633-
if (propertyInfo.AlsoBroadcastChange)
633+
if (propertyInfo.NotifyRecipients)
634634
{
635635
// This code generates a statement as follows:
636636
//

CommunityToolkit.Mvvm.SourceGenerators/ComponentModel/ObservablePropertyGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ 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], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [NotifyDataErrorInfo], but not [ObservableProperty]
41+
// Get diagnostics for fields using [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [NotifyRecipients] and [NotifyDataErrorInfo], but not [ObservableProperty]
4242
IncrementalValuesProvider<Diagnostic> fieldSymbolsWithOrphanedDependentAttributeWithErrors =
4343
fieldSymbols
4444
.Where(static item =>
4545
(item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyPropertyChangedForAttribute") ||
4646
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyCanExecuteChangedForAttribute") ||
47-
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoBroadcastChangeAttribute") ||
47+
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyRecipientsAttribute") ||
4848
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyDataErrorInfoAttribute")) &&
4949
!item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute"))
5050
.Select(static (item, _) => Execute.GetDiagnosticForFieldWithOrphanedDependentAttributes(item));

CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs

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

335335
/// <summary>
@@ -349,19 +349,19 @@ internal static class DiagnosticDescriptors
349349
helpLinkUri: "https://aka.ms/mvvmtoolkit");
350350

351351
/// <summary>
352-
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when <c>[AlsoBroadcastChange]</c> is applied to a field in an invalid type.
352+
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when <c>[NotifyRecipients]</c> is applied to a field in an invalid type.
353353
/// <para>
354-
/// Format: <c>"The field {0}.{1} cannot be annotated with [AlsoBroadcastChange], as its containing type doesn't inherit from ObservableRecipient, nor does it use [ObservableRecipient]"</c>.
354+
/// Format: <c>"The field {0}.{1} cannot be annotated with [NotifyRecipients], as its containing type doesn't inherit from ObservableRecipient, nor does it use [ObservableRecipient]"</c>.
355355
/// </para>
356356
/// </summary>
357-
public static readonly DiagnosticDescriptor InvalidContainingTypeForAlsoBroadcastChangeFieldError = new DiagnosticDescriptor(
357+
public static readonly DiagnosticDescriptor InvalidContainingTypeForNotifyRecipientsFieldError = new DiagnosticDescriptor(
358358
id: "MVVMTK0022",
359359
title: "Invalid containing type for [ObservableProperty] field",
360-
messageFormat: "The field {0}.{1} cannot be annotated with [AlsoBroadcastChange], as its containing type doesn't inherit from ObservableRecipient, nor does it use [ObservableRecipient]",
360+
messageFormat: "The field {0}.{1} cannot be annotated with [NotifyRecipients], as its containing type doesn't inherit from ObservableRecipient, nor does it use [ObservableRecipient]",
361361
category: typeof(ObservablePropertyGenerator).FullName,
362362
defaultSeverity: DiagnosticSeverity.Error,
363363
isEnabledByDefault: true,
364-
description: "Fields annotated with [AlsoBroadcastChange] must be contained in a type that inherits from ObservableRecipient or that is annotated with [ObservableRecipient] (including base types).",
364+
description: "Fields annotated with [NotifyRecipients] must be contained in a type that inherits from ObservableRecipient or that is annotated with [ObservableRecipient] (including base types).",
365365
helpLinkUri: "https://aka.ms/mvvmtoolkit");
366366

367367
/// <summary>

CommunityToolkit.Mvvm/ComponentModel/Attributes/AlsoBroadcastChangeAttribute.cs renamed to CommunityToolkit.Mvvm/ComponentModel/Attributes/NotifyRecipientsAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
1717
/// partial class MyViewModel : ObservableRecipient
1818
/// {
1919
/// [ObservableProperty]
20-
/// [AlsoBroadcastChange]
20+
/// [NotifyRecipients]
2121
/// private string username;
2222
/// }
2323
/// </code>
@@ -35,6 +35,6 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
3535
/// </code>
3636
/// </summary>
3737
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
38-
public sealed class AlsoBroadcastChangeAttribute : Attribute
38+
public sealed class NotifyRecipientsAttribute : Attribute
3939
{
4040
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ public partial class MyViewModel
999999
}
10001000

10011001
[TestMethod]
1002-
public void FieldWithOrphanedDependentObservablePropertyAttributesError_AlsoBroadcastChange()
1002+
public void FieldWithOrphanedDependentObservablePropertyAttributesError_NotifyRecipients()
10031003
{
10041004
string source = @"
10051005
using CommunityToolkit.Mvvm.ComponentModel;
@@ -1008,7 +1008,7 @@ namespace MyApp
10081008
{
10091009
public partial class MyViewModel
10101010
{
1011-
[AlsoBroadcastChange]
1011+
[NotifyRecipients]
10121012
public int number;
10131013
}
10141014
}";
@@ -1031,7 +1031,7 @@ public partial class MyViewModel
10311031
[NotifyPropertyChangedFor("")]
10321032
[NotifyCanExecuteChangedFor("")]
10331033
[NotifyCanExecuteChangedFor("")]
1034-
[AlsoBroadcastChange]
1034+
[NotifyRecipients]
10351035
public int number;
10361036
}
10371037
}";
@@ -1062,7 +1062,7 @@ public partial class B : A
10621062
}
10631063

10641064
[TestMethod]
1065-
public void InvalidContainingTypeForAlsoBroadcastChangeFieldError_ObservableObject()
1065+
public void InvalidContainingTypeForNotifyRecipientsFieldError_ObservableObject()
10661066
{
10671067
string source = @"
10681068
using CommunityToolkit.Mvvm.ComponentModel;
@@ -1072,7 +1072,7 @@ namespace MyApp
10721072
public partial class MyViewModel : ObservableObject
10731073
{
10741074
[ObservableProperty]
1075-
[AlsoBroadcastChange]
1075+
[NotifyRecipients]
10761076
public int number;
10771077
}
10781078
}";

tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservablePropertyAttribute.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -398,33 +398,33 @@ public void Test_OnPropertyChangingAndChangedPartialMethodWithAdditionalValidati
398398
}
399399

400400
[TestMethod]
401-
public void Test_AlsoBroadcastChange_WithObservableObject()
401+
public void Test_NotifyRecipients_WithObservableObject()
402402
{
403-
Test_AlsoBroadcastChange_Test(
403+
Test_NotifyRecipients_Test(
404404
factory: static messenger => new BroadcastingViewModel(messenger),
405405
setter: static (model, value) => model.Name = value,
406406
propertyName: nameof(BroadcastingViewModel.Name));
407407
}
408408

409409
[TestMethod]
410-
public void Test_AlsoBroadcastChange_WithObservableRecipientAttribute()
410+
public void Test_NotifyRecipients_WithObservableRecipientAttribute()
411411
{
412-
Test_AlsoBroadcastChange_Test(
412+
Test_NotifyRecipients_Test(
413413
factory: static messenger => new BroadcastingViewModelWithAttribute(messenger),
414414
setter: static (model, value) => model.Name = value,
415415
propertyName: nameof(BroadcastingViewModelWithAttribute.Name));
416416
}
417417

418418
[TestMethod]
419-
public void Test_AlsoBroadcastChange_WithInheritedObservableRecipientAttribute()
419+
public void Test_NotifyRecipients_WithInheritedObservableRecipientAttribute()
420420
{
421-
Test_AlsoBroadcastChange_Test(
421+
Test_NotifyRecipients_Test(
422422
factory: static messenger => new BroadcastingViewModelWithInheritedAttribute(messenger),
423423
setter: static (model, value) => model.Name2 = value,
424424
propertyName: nameof(BroadcastingViewModelWithInheritedAttribute.Name2));
425425
}
426426

427-
private void Test_AlsoBroadcastChange_Test<T>(Func<IMessenger, T> factory, Action<T, string?> setter, string propertyName)
427+
private void Test_NotifyRecipients_Test<T>(Func<IMessenger, T> factory, Action<T, string?> setter, string propertyName)
428428
where T : notnull
429429
{
430430
IMessenger messenger = new StrongReferenceMessenger();
@@ -643,10 +643,10 @@ public void Test_ObservableProperty_ModelWithCultureAwarePropertyName()
643643

644644
// See https://github.com/CommunityToolkit/dotnet/issues/242
645645
[TestMethod]
646-
public void Test_ObservableProperty_ModelWithAlsoBroadcastChangeAndDisplayAttributeLast()
646+
public void Test_ObservableProperty_ModelWithNotifyRecipientsAndDisplayAttributeLast()
647647
{
648648
IMessenger messenger = new StrongReferenceMessenger();
649-
ModelWithAlsoBroadcastChangeAndDisplayAttributeLast model = new(messenger);
649+
ModelWithNotifyRecipientsAndDisplayAttributeLast model = new(messenger);
650650

651651
List<string?> propertyNames = new();
652652

@@ -1076,15 +1076,15 @@ public BroadcastingViewModel(IMessenger messenger)
10761076
}
10771077

10781078
[ObservableProperty]
1079-
[AlsoBroadcastChange]
1079+
[NotifyRecipients]
10801080
private string? name;
10811081
}
10821082

10831083
[ObservableRecipient]
10841084
partial class BroadcastingViewModelWithAttribute : ObservableObject
10851085
{
10861086
[ObservableProperty]
1087-
[AlsoBroadcastChange]
1087+
[NotifyRecipients]
10881088
private string? name;
10891089
}
10901090

@@ -1096,7 +1096,7 @@ public BroadcastingViewModelWithInheritedAttribute(IMessenger messenger)
10961096
}
10971097

10981098
[ObservableProperty]
1099-
[AlsoBroadcastChange]
1099+
[NotifyRecipients]
11001100
private string? name2;
11011101
}
11021102

@@ -1159,10 +1159,10 @@ partial class ModelWithCultureAwarePropertyName
11591159
}
11601160

11611161
[ObservableRecipient]
1162-
public sealed partial class ModelWithAlsoBroadcastChangeAndDisplayAttributeLast : ObservableValidator
1162+
public sealed partial class ModelWithNotifyRecipientsAndDisplayAttributeLast : ObservableValidator
11631163
{
11641164
[ObservableProperty]
1165-
[AlsoBroadcastChange]
1165+
[NotifyRecipients]
11661166
[Display(Name = "Foo bar baz")]
11671167
private object? _someProperty;
11681168
}

0 commit comments

Comments
 (0)