16
16
using Microsoft . CodeAnalysis ;
17
17
using Microsoft . CodeAnalysis . CSharp ;
18
18
using Microsoft . CodeAnalysis . CSharp . Syntax ;
19
+ using Microsoft . CodeAnalysis . Diagnostics ;
19
20
using static CommunityToolkit . Mvvm . SourceGenerators . Diagnostics . DiagnosticDescriptors ;
20
21
using static Microsoft . CodeAnalysis . CSharp . SyntaxFactory ;
21
22
@@ -35,6 +36,7 @@ internal static class Execute
35
36
/// <param name="fieldSyntax">The <see cref="FieldDeclarationSyntax"/> instance to process.</param>
36
37
/// <param name="fieldSymbol">The input <see cref="IFieldSymbol"/> instance to process.</param>
37
38
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance for the current run.</param>
39
+ /// <param name="options">The options in use for the generator.</param>
38
40
/// <param name="token">The cancellation token for the current operation.</param>
39
41
/// <param name="propertyInfo">The resulting <see cref="PropertyInfo"/> value, if successfully retrieved.</param>
40
42
/// <param name="diagnostics">The resulting diagnostics from the processing operation.</param>
@@ -43,6 +45,7 @@ public static bool TryGetInfo(
43
45
FieldDeclarationSyntax fieldSyntax ,
44
46
IFieldSymbol fieldSymbol ,
45
47
SemanticModel semanticModel ,
48
+ AnalyzerConfigOptions options ,
46
49
CancellationToken token ,
47
50
[ NotNullWhen ( true ) ] out PropertyInfo ? propertyInfo ,
48
51
out ImmutableArray < DiagnosticInfo > diagnostics )
@@ -66,6 +69,11 @@ public static bool TryGetInfo(
66
69
67
70
token . ThrowIfCancellationRequested ( ) ;
68
71
72
+ // Override the property changing support if explicitly disabled
73
+ shouldInvokeOnPropertyChanging &= GetEnableINotifyPropertyChangingSupport ( options ) ;
74
+
75
+ token . ThrowIfCancellationRequested ( ) ;
76
+
69
77
// Get the property type and name
70
78
string typeNameWithNullabilityAnnotations = fieldSymbol . Type . GetFullyQualifiedNameWithNullabilityAnnotations ( ) ;
71
79
string fieldName = fieldSymbol . Name ;
@@ -320,6 +328,27 @@ public static bool TryGetInfo(
320
328
return true ;
321
329
}
322
330
331
+ /// <summary>
332
+ /// Gets the value for the "MvvmToolkitEnableINotifyPropertyChangingSupport" property.
333
+ /// </summary>
334
+ /// <param name="options">The options in use for the generator.</param>
335
+ /// <returns>The value for the "MvvmToolkitEnableINotifyPropertyChangingSupport" property.</returns>
336
+ public static bool GetEnableINotifyPropertyChangingSupport ( AnalyzerConfigOptions options )
337
+ {
338
+ if ( options . TryGetValue ( "build_property.MvvmToolkitEnableINotifyPropertyChangingSupport" , out string ? propertyValue ) )
339
+ {
340
+ if ( bool . TryParse ( propertyValue , out bool enableINotifyPropertyChangingSupport ) )
341
+ {
342
+ return enableINotifyPropertyChangingSupport ;
343
+ }
344
+ }
345
+
346
+ // This setting is enabled by default, for backwards compatibility.
347
+ // Note that this path should never be reached, as the default
348
+ // value is also set in a .targets file bundled in the package.
349
+ return true ;
350
+ }
351
+
323
352
/// <summary>
324
353
/// Validates the containing type for a given field being annotated.
325
354
/// </summary>
0 commit comments