
Having a MethodDeclarationSyntax Node, I’m trying to access its DocumentationCommentSyntax Node.
I can obtain the DocumentationComment trivia by doing this:
var firstToken = member.GetFirstToken();
var documentationTrivias = firstToken.LeadingTrivia.Where(t => t.Kind == SyntaxKind.DocumentationComment);
if(documentationTrivias.Count() != 1)
return null;
var documentationTrivia = documentationTrivias.Single();
Now, I would simply need to access the Node that is right under it in the tree. I am convinced it is simple to do, but I can’t find a way.
Any help would be very appreciated, thanks!
To access that node, you need to call
GetStructure()on theSyntaxTrivia. That will returnStructuredTriviaSyntax, but since you know you haveDocumentationComment, it will actually beDocumentationCommentSyntax, so you can cast it to that.Also, you don’t need to deal with the
FirstToken, you can useGetLeadingTrivia()instead.