@@ -36,15 +36,13 @@ context.Node is PropertyDeclarationSyntax propertyDeclaration &&
3636 {
3737 if ( ClrProperty . Match ( property , context . SemanticModel , context . CancellationToken ) is { SetValue : { } setValue , BackingSet : { } backingSet , GetValue : { } getValue , BackingGet : { } backingGet } )
3838 {
39- if ( getter . Body is { Statements : { } getStatements } &&
40- getStatements . Count > 1 &&
39+ if ( getter . Body is { Statements : { Count : > 1 } getStatements } &&
4140 getStatements . TryFirst ( x => ! x . Contains ( getValue ) , out var statement ) )
4241 {
4342 context . ReportDiagnostic ( Diagnostic . Create ( Descriptors . WPF0036AvoidSideEffectsInClrAccessors , statement . GetLocation ( ) ) ) ;
4443 }
4544
46- if ( setter . Body is { Statements : { } setStatements } &&
47- setStatements . Count > 1 &&
45+ if ( setter . Body is { Statements : { Count : > 1 } setStatements } &&
4846 setStatements . TryFirst ( x => ! x . Contains ( setValue ) , out var sideEffect ) )
4947 {
5048 context . ReportDiagnostic ( Diagnostic . Create ( Descriptors . WPF0036AvoidSideEffectsInClrAccessors , sideEffect . GetLocation ( ) ) ) ;
@@ -73,7 +71,7 @@ context.Node is PropertyDeclarationSyntax propertyDeclaration &&
7371
7472 if ( backingGet . RegisteredType ( context . SemanticModel , context . CancellationToken ) is { Value : { } registeredType } )
7573 {
76- if ( ! TypeSymbolComparer . Equal ( property . Type , registeredType ) )
74+ if ( ! MatchesRegisteredType ( property . Type , registeredType ) )
7775 {
7876 context . ReportDiagnostic (
7977 Diagnostic . Create (
@@ -85,7 +83,7 @@ context.Node is PropertyDeclarationSyntax propertyDeclaration &&
8583 }
8684 else if ( getValue is { Parent : CastExpressionSyntax { Type : { } type } } &&
8785 context . SemanticModel . GetType ( type , context . CancellationToken ) is { } castType &&
88- ! TypeSymbolComparer . Equal ( registeredType , castType ) )
86+ ! MatchesRegisteredType ( castType , registeredType ) )
8987 {
9088 context . ReportDiagnostic (
9189 Diagnostic . Create (
@@ -95,6 +93,22 @@ context.Node is PropertyDeclarationSyntax propertyDeclaration &&
9593 property ,
9694 registeredType ) ) ;
9795 }
96+
97+ static bool MatchesRegisteredType ( ITypeSymbol candidate , ITypeSymbol registeredType )
98+ {
99+ if ( TypeSymbolComparer . Equal ( candidate , registeredType ) )
100+ {
101+ return true ;
102+ }
103+
104+ if ( candidate . NullableAnnotation == NullableAnnotation . Annotated &&
105+ registeredType . NullableAnnotation == NullableAnnotation . NotAnnotated )
106+ {
107+ return TypeSymbolComparer . Equal ( candidate . OriginalDefinition , registeredType ) ;
108+ }
109+
110+ return false ;
111+ }
98112 }
99113
100114 bool IsGettingAndSettingDifferent ( )
0 commit comments