@@ -32,62 +32,65 @@ private static void Handle(SyntaxNodeAnalysisContext context)
3232 {
3333 if ( EventManager . RegisterClassHandler . Match ( invocation , context . SemanticModel , context . CancellationToken ) is { } registerClassHandler )
3434 {
35- if ( ShouldRename ( registerClassHandler . Target , registerClassHandler . EventArgument , registerClassHandler . DelegateArgument ) is var ( location , properties , expectedName ) )
35+ if ( ShouldRename ( registerClassHandler . Target , registerClassHandler . EventArgument , registerClassHandler . DelegateArgument ) is var ( location , nameProperties , expectedName ) )
3636 {
3737 context . ReportDiagnostic (
3838 Diagnostic . Create (
3939 Descriptors . WPF0090RegisterClassHandlerCallbackNameShouldMatchEvent ,
4040 location ,
41- properties ,
41+ nameProperties ,
4242 expectedName ) ) ;
4343 }
4444
45- if ( WrongType ( registerClassHandler . EventArgument , registerClassHandler . DelegateArgument ) )
45+ if ( WrongType ( registerClassHandler . EventArgument , registerClassHandler . DelegateArgument ) is { } typeProperties )
4646 {
4747 context . ReportDiagnostic (
4848 Diagnostic . Create (
4949 Descriptors . WPF0092WrongDelegateType ,
50- registerClassHandler . DelegateArgument . GetLocation ( ) ) ) ;
50+ registerClassHandler . DelegateArgument . GetLocation ( ) ,
51+ typeProperties ) ) ;
5152 }
5253 }
5354 else if ( EventManager . AddHandler . Match ( invocation , context . SemanticModel , context . CancellationToken ) is { } addHandler )
5455 {
55- if ( ShouldRename ( addHandler . Target , addHandler . EventArgument , addHandler . DelegateArgument ) is var ( location , properties , expectedName ) )
56+ if ( ShouldRename ( addHandler . Target , addHandler . EventArgument , addHandler . DelegateArgument ) is var ( location , nameProperties , expectedName ) )
5657 {
5758 context . ReportDiagnostic (
5859 Diagnostic . Create (
5960 Descriptors . WPF0091AddAndRemoveHandlerCallbackNameShouldMatchEvent ,
6061 location ,
61- properties ,
62+ nameProperties ,
6263 expectedName ) ) ;
6364 }
6465
65- if ( WrongType ( addHandler . EventArgument , addHandler . DelegateArgument ) )
66+ if ( WrongType ( addHandler . EventArgument , addHandler . DelegateArgument ) is { } typeProperties )
6667 {
6768 context . ReportDiagnostic (
6869 Diagnostic . Create (
6970 Descriptors . WPF0092WrongDelegateType ,
70- addHandler . DelegateArgument . GetLocation ( ) ) ) ;
71+ addHandler . DelegateArgument . GetLocation ( ) ,
72+ typeProperties ) ) ;
7173 }
7274 }
7375 else if ( EventManager . RemoveHandler . Match ( invocation , context . SemanticModel , context . CancellationToken ) is { } removeHandler )
7476 {
75- if ( ShouldRename ( removeHandler . Target , removeHandler . EventArgument , removeHandler . DelegateArgument ) is var ( location , properties , expectedName ) )
77+ if ( ShouldRename ( removeHandler . Target , removeHandler . EventArgument , removeHandler . DelegateArgument ) is var ( location , nameProperties , expectedName ) )
7678 {
7779 context . ReportDiagnostic (
7880 Diagnostic . Create (
7981 Descriptors . WPF0091AddAndRemoveHandlerCallbackNameShouldMatchEvent ,
8082 location ,
81- properties ,
83+ nameProperties ,
8284 expectedName ) ) ;
8385 }
8486
85- if ( WrongType ( removeHandler . EventArgument , removeHandler . DelegateArgument ) )
87+ if ( WrongType ( removeHandler . EventArgument , removeHandler . DelegateArgument ) is { } typeProperties )
8688 {
8789 context . ReportDiagnostic (
8890 Diagnostic . Create (
8991 Descriptors . WPF0092WrongDelegateType ,
90- removeHandler . DelegateArgument . GetLocation ( ) ) ) ;
92+ removeHandler . DelegateArgument . GetLocation ( ) ,
93+ typeProperties ) ) ;
9194 }
9295 }
9396
@@ -132,17 +135,18 @@ private static void Handle(SyntaxNodeAnalysisContext context)
132135 }
133136 }
134137
135- bool WrongType ( ArgumentSyntax eventArgument , ArgumentSyntax callbackArg )
138+ ImmutableDictionary < string , string ? > ? WrongType ( ArgumentSyntax eventArgument , ArgumentSyntax callbackArg )
136139 {
137140 if ( context . SemanticModel . GetSymbolSafe ( eventArgument . Expression , context . CancellationToken ) is { } routedSymbol &&
138141 routedSymbol . Name . EndsWith ( "Event" , StringComparison . Ordinal ) &&
139142 routedSymbol . ContainingType . TryFindEvent ( routedSymbol . Name . Substring ( 0 , routedSymbol . Name . Length - 5 ) , out var accessor ) &&
140- context . SemanticModel . GetType ( callbackArg . Expression , context . CancellationToken ) is { } actualType )
143+ context . SemanticModel . GetType ( callbackArg . Expression , context . CancellationToken ) is { } actualType &&
144+ ! TypeSymbolComparer . Equal ( actualType , accessor . Type ) )
141145 {
142- return ! TypeSymbolComparer . Equal ( actualType , accessor . Type ) ;
146+ return ImmutableDictionary < string , string ? > . Empty . Add ( nameof ( ITypeSymbol ) , accessor . Type . MetadataName ) ;
143147 }
144148
145- return false ;
149+ return null ;
146150 }
147151 }
148152 }
0 commit comments