You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Get the [ObservableProperty] and [GeneratedCode] symbols
36
+
if(context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute")is not INamedTypeSymbolobservablePropertySymbol||
37
+
context.Compilation.GetTypeByMetadataName("System.CodeDom.Compiler.GeneratedCodeAttribute")is not {}generatedCodeAttributeSymbol)
38
+
{
39
+
return;
40
+
}
41
+
42
+
context.RegisterSymbolAction(context =>
43
+
{
44
+
// Ensure that we have some target property to analyze (also skip implementation parts)
45
+
if(context.Symbolis not IPropertySymbol{PartialDefinitionPart:null}propertySymbol)
46
+
{
47
+
return;
48
+
}
49
+
50
+
// If the property is not using [ObservableProperty], there's nothing to do
Copy file name to clipboardExpand all lines: src/CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs
+51-3Lines changed: 51 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -718,17 +718,17 @@ internal static class DiagnosticDescriptors
718
718
/// <summary>
719
719
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when <c>[ObservableProperty]</c> is applied to a property with an invalid declaration.
720
720
/// <para>
721
-
/// Format: <c>"The property {0}.{1} cannot be used to generate an observable property, as its declaration is not valid (it must be a partial property with a getter and a setter that is not init-only)"</c>.
721
+
/// Format: <c>"The property {0}.{1} cannot be used to generate an observable property, as its declaration is not valid (it must be an instance (non static) partial property with a getter and a setter that is not init-only)"</c>.
title:"Invalid property declaration for [ObservableProperty]",
727
-
messageFormat:"The property {0}.{1} cannot be used to generate an observable property, as its declaration is not valid (it must be a partial property with a getter and a setter that is not init-only)",
727
+
messageFormat:"The property {0}.{1} cannot be used to generate an observable property, as its declaration is not valid (it must be an instance (non static) partial property with a getter and a setter that is not init-only)",
description:"Properties annotated with [ObservableProperty] must be partial properties with a getter and a setter that is not init-only.",
731
+
description:"Properties annotated with [ObservableProperty] must be instance (non static) partial properties with a getter and a setter that is not init-only.",
@@ -859,4 +859,52 @@ internal static class DiagnosticDescriptors
859
859
description:"This project producing one or more 'MVVMTK0045' warnings due to [ObservableProperty] being used on fields, which is not AOT compatible in WinRT scenarios, should set 'LangVersion' to 'preview' to enable partial properties and the associated code fixer (setting 'LangVersion=preview' is required to use [ObservableProperty] on partial properties and address these warnings).",
/// Gets a <see cref="DiagnosticDescriptor"/> for when <c>[ObservableProperty]</c> is used on a property that is not an incomplete partial definition.
865
+
/// <para>
866
+
/// Format: <c>"The property {0}.{1} is not an incomplete partial definition ([ObservableProperty] must be used on partial property definitions with no implementation part)"</c>.
title:"Using [ObservableProperty] on an invalid property declaration (not incomplete partial definition)",
872
+
messageFormat:"""The property {0}.{1} is not an incomplete partial definition ([ObservableProperty] must be used on partial property definitions with no implementation part)""",
description:"A property using [ObservableProperty] is not a partial implementation part ([ObservableProperty] must be used on partial property definitions with no implementation part).",
description:"A property using [ObservableProperty] returns a value by reference ([ObservableProperty] must be used on properties returning a type by value).",
description:"A property using [ObservableProperty] returns a byref-like value ([ObservableProperty] must be used on properties of a non byref-like type).",
0 commit comments