@@ -89,7 +89,7 @@ internal static class Execute
89
89
ImmutableArray < string > . Builder propertyChangingNames = ImmutableArray . CreateBuilder < string > ( ) ;
90
90
ImmutableArray < string > . Builder notifiedCommandNames = ImmutableArray . CreateBuilder < string > ( ) ;
91
91
ImmutableArray < AttributeInfo > . Builder forwardedAttributes = ImmutableArray . CreateBuilder < AttributeInfo > ( ) ;
92
- bool alsoBroadcastChange = false ;
92
+ bool notifyRecipients = false ;
93
93
bool alsoValidateProperty = false ;
94
94
bool hasAnyValidationAttributes = false ;
95
95
@@ -102,6 +102,12 @@ internal static class Execute
102
102
// The current property is always notified
103
103
propertyChangedNames . Add ( propertyName ) ;
104
104
105
+ // Get the class-level [NotifyRecipients] setting, if any
106
+ if ( TryGetIsNotifyingRecipients ( fieldSymbol , out bool isBroadcastTargetValid ) )
107
+ {
108
+ notifyRecipients = isBroadcastTargetValid ;
109
+ }
110
+
105
111
// Gather attributes info
106
112
foreach ( AttributeData attributeData in fieldSymbol . GetAttributes ( ) )
107
113
{
@@ -112,10 +118,10 @@ internal static class Execute
112
118
continue ;
113
119
}
114
120
115
- // Check whether the property should also broadcast changes
116
- if ( TryGetIsBroadcastingChanges ( fieldSymbol , attributeData , builder , out bool isBroadcastTargetValid ) )
121
+ // Check whether the property should also notify recipients
122
+ if ( TryGetIsNotifyingRecipients ( fieldSymbol , attributeData , builder , out isBroadcastTargetValid ) )
117
123
{
118
- alsoBroadcastChange = isBroadcastTargetValid ;
124
+ notifyRecipients = isBroadcastTargetValid ;
119
125
120
126
continue ;
121
127
}
@@ -183,7 +189,7 @@ internal static class Execute
183
189
propertyChangingNames . ToImmutable ( ) ,
184
190
propertyChangedNames . ToImmutable ( ) ,
185
191
notifiedCommandNames . ToImmutable ( ) ,
186
- alsoBroadcastChange ,
192
+ notifyRecipients ,
187
193
alsoValidateProperty ,
188
194
forwardedAttributes . ToImmutable ( ) ) ;
189
195
}
@@ -404,14 +410,45 @@ bool IsCommandNameValidWithGeneratedMembers(string commandName)
404
410
}
405
411
406
412
/// <summary>
407
- /// Checks whether a given generated property should also broadcast changes.
413
+ /// Checks whether a given generated property should also notify recipients.
414
+ /// </summary>
415
+ /// <param name="fieldSymbol">The input <see cref="IFieldSymbol"/> instance to process.</param>
416
+ /// <param name="isBroadcastTargetValid">Whether or not the the property is in a valid target that can notify recipients.</param>
417
+ /// <returns>Whether or not the generated property for <paramref name="fieldSymbol"/> is in a type annotated with <c>[NotifyRecipients]</c>.</returns>
418
+ private static bool TryGetIsNotifyingRecipients ( IFieldSymbol fieldSymbol , out bool isBroadcastTargetValid )
419
+ {
420
+ if ( fieldSymbol . ContainingType ? . HasOrInheritsAttributeWithFullyQualifiedName ( "global::CommunityToolkit.Mvvm.ComponentModel.NotifyRecipientsAttribute" ) == true )
421
+ {
422
+ // If the containing type is valid, track it
423
+ if ( fieldSymbol . ContainingType . InheritsFromFullyQualifiedName ( "global::CommunityToolkit.Mvvm.ComponentModel.ObservableRecipient" ) ||
424
+ fieldSymbol . ContainingType . HasOrInheritsAttributeWithFullyQualifiedName ( "global::CommunityToolkit.Mvvm.ComponentModel.ObservableRecipientAttribute" ) )
425
+ {
426
+ isBroadcastTargetValid = true ;
427
+
428
+ return true ;
429
+ }
430
+
431
+ // Otherwise, ignore the attribute but don't emit a diagnostic.
432
+ // The diagnostic for class-level attributes is handled separately.
433
+ isBroadcastTargetValid = false ;
434
+
435
+ return true ;
436
+ }
437
+
438
+ isBroadcastTargetValid = false ;
439
+
440
+ return false ;
441
+ }
442
+
443
+ /// <summary>
444
+ /// Checks whether a given generated property should also notify recipients.
408
445
/// </summary>
409
446
/// <param name="fieldSymbol">The input <see cref="IFieldSymbol"/> instance to process.</param>
410
447
/// <param name="attributeData">The <see cref="AttributeData"/> instance for <paramref name="fieldSymbol"/>.</param>
411
448
/// <param name="diagnostics">The current collection of gathered diagnostics.</param>
412
- /// <param name="isBroadcastTargetValid">Whether or not the the property is in a valid target that can broadcast changes .</param>
449
+ /// <param name="isBroadcastTargetValid">Whether or not the the property is in a valid target that can notify recipients .</param>
413
450
/// <returns>Whether or not the generated property for <paramref name="fieldSymbol"/> used <c>[NotifyRecipients]</c>.</returns>
414
- private static bool TryGetIsBroadcastingChanges (
451
+ private static bool TryGetIsNotifyingRecipients (
415
452
IFieldSymbol fieldSymbol ,
416
453
AttributeData attributeData ,
417
454
ImmutableArray < Diagnostic > . Builder diagnostics ,
0 commit comments