Skip to content

Commit 31f5c95

Browse files
committed
Improve diagnostics for [ObservableProperty] with invalid validation
1 parent 840e7a5 commit 31f5c95

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ public static PropertyInfo GetInfo(IFieldSymbol fieldSymbol, out ImmutableArray<
9797
fieldSymbol.ContainingType,
9898
fieldSymbol.Name,
9999
validationAttributes.Count);
100+
101+
// Remove all validation attributes so that the generated code doesn't cause a build error about the
102+
// "ValidateProperty" method not existing (as the type doesn't inherit from ObservableValidator). The
103+
// compilation will still fail due to this diagnostics, but with just this easier to understand error.
104+
validationAttributes.Clear();
100105
}
101106

102107
diagnostics = builder.ToImmutable();

0 commit comments

Comments
 (0)