@@ -57,7 +57,8 @@ context.ContainingSymbol is { } containingSymbol &&
5757 if ( objectCreation . TryFindArgument ( nameParameter , out var nameArg ) &&
5858 nameArg . TryGetStringValue ( context . SemanticModel , context . CancellationToken , out var registeredName ) )
5959 {
60- if ( registeredName != fieldOrProperty . Name )
60+ if ( registeredName != fieldOrProperty . Name &&
61+ ! fieldOrProperty . Name . IsParts ( registeredName ?? string . Empty , "Command" ) )
6162 {
6263 context . ReportDiagnostic (
6364 Diagnostic . Create (
@@ -66,23 +67,27 @@ context.ContainingSymbol is { } containingSymbol &&
6667 ImmutableDictionary < string , string ? > . Empty . Add ( nameof ( IdentifierNameSyntax ) , fieldOrProperty . Name ) ,
6768 fieldOrProperty . Name ) ) ;
6869 }
69- else if ( nameArg . Expression . IsKind ( SyntaxKind . StringLiteralExpression ) )
70- {
71- context . ReportDiagnostic (
72- Diagnostic . Create (
73- Descriptors . WPF0150UseNameofInsteadOfLiteral ,
74- nameArg . GetLocation ( ) ,
75- ImmutableDictionary < string , string ? > . Empty . Add ( nameof ( IdentifierNameSyntax ) , fieldOrProperty . Name ) ,
76- fieldOrProperty . Name ) ) ;
77- }
78- else if ( ! nameArg . Expression . IsNameof ( ) )
70+
71+ if ( registeredName == fieldOrProperty . Name )
7972 {
80- context . ReportDiagnostic (
81- Diagnostic . Create (
82- Descriptors . WPF0151UseNameofInsteadOfConstant ,
83- nameArg . GetLocation ( ) ,
84- ImmutableDictionary < string , string ? > . Empty . Add ( nameof ( IdentifierNameSyntax ) , fieldOrProperty . Name ) ,
85- fieldOrProperty . Name ) ) ;
73+ if ( nameArg . Expression . IsKind ( SyntaxKind . StringLiteralExpression ) )
74+ {
75+ context . ReportDiagnostic (
76+ Diagnostic . Create (
77+ Descriptors . WPF0150UseNameofInsteadOfLiteral ,
78+ nameArg . GetLocation ( ) ,
79+ ImmutableDictionary < string , string ? > . Empty . Add ( nameof ( IdentifierNameSyntax ) , fieldOrProperty . Name ) ,
80+ fieldOrProperty . Name ) ) ;
81+ }
82+ else if ( ! nameArg . Expression . IsNameof ( ) )
83+ {
84+ context . ReportDiagnostic (
85+ Diagnostic . Create (
86+ Descriptors . WPF0151UseNameofInsteadOfConstant ,
87+ nameArg . GetLocation ( ) ,
88+ ImmutableDictionary < string , string ? > . Empty . Add ( nameof ( IdentifierNameSyntax ) , fieldOrProperty . Name ) ,
89+ fieldOrProperty . Name ) ) ;
90+ }
8691 }
8792 }
8893 }
0 commit comments