C
C#17mo ago
liekong1991

❔ 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
lycian
lycian17mo ago
RegionDirectiveTrivia is trivia, so it won't be a syntax node
lycian
lycian17mo ago
SyntaxNode.DescendantTrivia Method (Microsoft.CodeAnalysis)
Get a list of all the trivia associated with the descendant nodes and tokens.
Accord
Accord17mo ago
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.