❔ How to correctly use Roslyn to parse RegionDirectiveTriviaSyntax in a project?
I would like to ask a question about parsing syntax tree for #region preprocessor directive. For example, for the simple code shown in the picture, I have tried several methods but failed to parse the SyntaxNode for the #region block. Do I need to set any special options?
Here's the parsing method I'm currently using, but it doesn't seem to be able to parse it out no matter what I try. However, the syntax analyzer that comes with Visual Studio can see the relevant Node.
5 Replies
RegionDirective
Trivia
is trivia, so it won't be a syntax nodeyou can use DescendentTrivia if you're searching: https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.syntaxnode.descendanttrivia?view=roslyn-dotnet-4.3.0
SyntaxNode.DescendantTrivia Method (Microsoft.CodeAnalysis)
Get a list of all the trivia associated with the descendant nodes and tokens.
SyntaxNode.FindTrivia Method (Microsoft.CodeAnalysis)
Finds a descendant trivia of this node whose span includes the supplied position.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.