@@ -86,11 +86,17 @@ private static void HandleBaseTypeLikeDeclaration(SyntaxNodeAnalysisContext cont
8686 DocumentationCommentTriviaSyntax documentation = context . Node . GetDocumentationCommentTriviaSyntax ( ) ;
8787
8888 XmlNodeSyntax inheritDocElement = documentation ? . Content . GetFirstXmlElement ( XmlCommentHelper . InheritdocXmlTag ) ;
89+ if ( inheritDocElement == null )
90+ {
91+ return ;
92+ }
8993
90- if ( inheritDocElement != null )
94+ if ( HasXmlCrefAttribute ( inheritDocElement ) )
9195 {
92- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , inheritDocElement . GetLocation ( ) ) ) ;
96+ return ;
9397 }
98+
99+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , inheritDocElement . GetLocation ( ) ) ) ;
94100 }
95101
96102 private static void HandleMemberDeclaration ( SyntaxNodeAnalysisContext context )
@@ -107,27 +113,50 @@ private static void HandleMemberDeclaration(SyntaxNodeAnalysisContext context)
107113 DocumentationCommentTriviaSyntax documentation = memberSyntax . GetDocumentationCommentTriviaSyntax ( ) ;
108114
109115 XmlNodeSyntax inheritDocElement = documentation ? . Content . GetFirstXmlElement ( XmlCommentHelper . InheritdocXmlTag ) ;
116+ if ( inheritDocElement == null )
117+ {
118+ return ;
119+ }
110120
111- if ( inheritDocElement != null )
121+ if ( HasXmlCrefAttribute ( inheritDocElement ) )
112122 {
113- ISymbol declaredSymbol = context . SemanticModel . GetDeclaredSymbol ( memberSyntax , context . CancellationToken ) ;
114- if ( declaredSymbol == null && memberSyntax . IsKind ( SyntaxKind . EventFieldDeclaration ) )
115- {
116- var eventFieldDeclarationSyntax = ( EventFieldDeclarationSyntax ) memberSyntax ;
117- VariableDeclaratorSyntax firstVariable = eventFieldDeclarationSyntax . Declaration ? . Variables . FirstOrDefault ( ) ;
118- if ( firstVariable != null )
119- {
120- declaredSymbol = context . SemanticModel . GetDeclaredSymbol ( firstVariable , context . CancellationToken ) ;
121- }
122- }
123+ return ;
124+ }
123125
124- // If we don't have a declared symbol we have some kind of field declaration. A field can not override or
125- // implement anything so we want to report a diagnostic.
126- if ( declaredSymbol == null || ! NamedTypeHelpers . IsImplementingAnInterfaceMember ( declaredSymbol ) )
126+ ISymbol declaredSymbol = context . SemanticModel . GetDeclaredSymbol ( memberSyntax , context . CancellationToken ) ;
127+ if ( declaredSymbol == null && memberSyntax . IsKind ( SyntaxKind . EventFieldDeclaration ) )
128+ {
129+ var eventFieldDeclarationSyntax = ( EventFieldDeclarationSyntax ) memberSyntax ;
130+ VariableDeclaratorSyntax firstVariable = eventFieldDeclarationSyntax . Declaration ? . Variables . FirstOrDefault ( ) ;
131+ if ( firstVariable != null )
127132 {
128- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , inheritDocElement . GetLocation ( ) ) ) ;
133+ declaredSymbol = context . SemanticModel . GetDeclaredSymbol ( firstVariable , context . CancellationToken ) ;
129134 }
130135 }
136+
137+ // If we don't have a declared symbol we have some kind of field declaration. A field can not override or
138+ // implement anything so we want to report a diagnostic.
139+ if ( declaredSymbol == null || ! NamedTypeHelpers . IsImplementingAnInterfaceMember ( declaredSymbol ) )
140+ {
141+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , inheritDocElement . GetLocation ( ) ) ) ;
142+ }
143+ }
144+
145+ private static bool HasXmlCrefAttribute ( XmlNodeSyntax inheritDocElement )
146+ {
147+ XmlElementSyntax xmlElementSyntax = inheritDocElement as XmlElementSyntax ;
148+ if ( xmlElementSyntax ? . StartTag ? . Attributes . Any ( SyntaxKind . XmlCrefAttribute ) ?? false )
149+ {
150+ return true ;
151+ }
152+
153+ XmlEmptyElementSyntax xmlEmptyElementSyntax = inheritDocElement as XmlEmptyElementSyntax ;
154+ if ( xmlEmptyElementSyntax ? . Attributes . Any ( SyntaxKind . XmlCrefAttribute ) ?? false )
155+ {
156+ return true ;
157+ }
158+
159+ return false ;
131160 }
132161 }
133162}
0 commit comments