How to measure the nesting level of method using C# Roslyn
问题 I want to measure a "nesting level" of a method using Roslyn, for example: if the method contains only one expression its level is 0. If the method contains nested if(cond1) if(cond2) its level is 1. I try to use Roslyn's nodes, but I don't understand how to get only the body of the while or the if construction without it's condition and other things. 回答1: You can use SyntaxVisitor for this: it recursively walks the syntax tree and executes your code for each node, depending on its type. You