@@ -234,29 +234,37 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettin
234234
235235 if ( hasIncludedDocumentation )
236236 {
237- var declaration = context . SemanticModel . GetDeclaredSymbol ( node , context . CancellationToken ) ;
238- var rawDocumentation = declaration ? . GetDocumentationCommentXml ( expandIncludes : true , cancellationToken : context . CancellationToken ) ;
239- var completeDocumentation = XElement . Parse ( rawDocumentation , LoadOptions . None ) ;
237+ var declaration = node switch
238+ {
239+ BaseFieldDeclarationSyntax baseFieldDeclaration => baseFieldDeclaration . Declaration . Variables . FirstOrDefault ( ) ?? node ,
240+ _ => node ,
241+ } ;
240242
241- if ( this . inheritDocSuppressesWarnings &&
242- completeDocumentation . Nodes ( ) . OfType < XElement > ( ) . Any ( element => element . Name == XmlCommentHelper . InheritdocXmlTag ) )
243+ var declaredSymbol = context . SemanticModel . GetDeclaredSymbol ( declaration , context . CancellationToken ) ;
244+ if ( declaredSymbol is not null )
243245 {
244- // Ignore nodes with an <inheritdoc/> tag in the included XML.
246+ var rawDocumentation = declaredSymbol ? . GetDocumentationCommentXml ( expandIncludes : true , cancellationToken : context . CancellationToken ) ;
247+ var completeDocumentation = XElement . Parse ( rawDocumentation ?? "<doc></doc>" , LoadOptions . None ) ;
248+
249+ if ( this . inheritDocSuppressesWarnings &&
250+ completeDocumentation . Nodes ( ) . OfType < XElement > ( ) . Any ( element => element . Name == XmlCommentHelper . InheritdocXmlTag ) )
251+ {
252+ // Ignore nodes with an <inheritdoc/> tag in the included XML.
253+ return ;
254+ }
255+
256+ this . HandleCompleteDocumentation ( context , needsComment , completeDocumentation , locations ) ;
245257 return ;
246258 }
247-
248- this . HandleCompleteDocumentation ( context , needsComment , completeDocumentation , locations ) ;
249259 }
250- else
251- {
252- IEnumerable < XmlNodeSyntax > matchingXmlElements = string . IsNullOrEmpty ( this . matchElementName )
253- ? documentation . Content
254- . Where ( x => x is XmlElementSyntax || x is XmlEmptyElementSyntax )
255- . Where ( x => ! string . Equals ( x . GetName ( ) ? . ToString ( ) , XmlCommentHelper . IncludeXmlTag , StringComparison . Ordinal ) )
256- : documentation . Content . GetXmlElements ( this . matchElementName ) ;
257260
258- this . HandleXmlElement ( context , settings , needsComment , matchingXmlElements , locations ) ;
259- }
261+ IEnumerable < XmlNodeSyntax > matchingXmlElements = string . IsNullOrEmpty ( this . matchElementName )
262+ ? documentation . Content
263+ . Where ( x => x is XmlElementSyntax || x is XmlEmptyElementSyntax )
264+ . Where ( x => ! string . Equals ( x . GetName ( ) ? . ToString ( ) , XmlCommentHelper . IncludeXmlTag , StringComparison . Ordinal ) )
265+ : documentation . Content . GetXmlElements ( this . matchElementName ) ;
266+
267+ this . HandleXmlElement ( context , settings , needsComment , matchingXmlElements , locations ) ;
260268 }
261269 }
262270}
0 commit comments