File tree Expand file tree Collapse file tree 2 files changed +50
-6
lines changed Expand file tree Collapse file tree 2 files changed +50
-6
lines changed Original file line number Diff line number Diff line change @@ -138,12 +138,34 @@ private static bool TryGatherDependentPropertyChangedNames(
138
138
}
139
139
else
140
140
{
141
- diagnostics . Add (
142
- AlsoNotifyChangeForInvalidTargetError ,
143
- fieldSymbol ,
144
- dependentPropertyName ?? "" ,
145
- fieldSymbol . ContainingType ) ;
146
- }
141
+ bool isTargetValid = false ;
142
+
143
+ // Check for generated properties too
144
+ foreach ( ISymbol member in fieldSymbol . ContainingType . GetMembers ( ) )
145
+ {
146
+ if ( member is IFieldSymbol otherFieldSymbol &&
147
+ ! SymbolEqualityComparer . Default . Equals ( fieldSymbol , otherFieldSymbol ) &&
148
+ otherFieldSymbol . HasAttributeWithFullyQualifiedName ( "global::CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute" ) &&
149
+ dependentPropertyName == GetGeneratedPropertyName ( otherFieldSymbol ) )
150
+ {
151
+ propertyChangedNames . Add ( dependentPropertyName ) ;
152
+
153
+ isTargetValid = true ;
154
+
155
+ break ;
156
+ }
157
+ }
158
+
159
+ // Add the diagnostic if the target is definitely invalid
160
+ if ( ! isTargetValid )
161
+ {
162
+ diagnostics . Add (
163
+ AlsoNotifyChangeForInvalidTargetError ,
164
+ fieldSymbol ,
165
+ dependentPropertyName ?? "" ,
166
+ fieldSymbol . ContainingType ) ;
167
+ }
168
+ }
147
169
}
148
170
149
171
return true ;
Original file line number Diff line number Diff line change 2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
+ using System . Collections . Immutable ;
5
6
using Microsoft . CodeAnalysis ;
6
7
7
8
namespace CommunityToolkit . Mvvm . SourceGenerators . Extensions ;
@@ -32,6 +33,27 @@ public static bool HasFullyQualifiedName(this ISymbol symbol, string name)
32
33
return symbol . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) == name ;
33
34
}
34
35
36
+ /// <summary>
37
+ /// Checks whether or not a given symbol has an attribute with the specified full name.
38
+ /// </summary>
39
+ /// <param name="symbol">The input <see cref="ISymbol"/> instance to check.</param>
40
+ /// <param name="name">The attribute name to look for.</param>
41
+ /// <returns>Whether or not <paramref name="symbol"/> has an attribute with the specified name.</returns>
42
+ public static bool HasAttributeWithFullyQualifiedName ( this ISymbol symbol , string name )
43
+ {
44
+ ImmutableArray < AttributeData > attributes = symbol . GetAttributes ( ) ;
45
+
46
+ foreach ( AttributeData attribute in attributes )
47
+ {
48
+ if ( attribute . AttributeClass ? . HasFullyQualifiedName ( name ) == true )
49
+ {
50
+ return true ;
51
+ }
52
+ }
53
+
54
+ return false ;
55
+ }
56
+
35
57
/// <summary>
36
58
/// Calculates the effective accessibility for a given symbol.
37
59
/// </summary>
You can’t perform that action at this time.
0 commit comments