/// <summary> /// Walks the entire syntax tree and evaluates the maximum depth of all the nodes. /// </summary> private static int ComputeMaxDepth(SyntaxElement root) { var maxDepth = 0; var depth = 0; SyntaxElement.Walk( root, fnBefore: e => { depth++; if (depth > maxDepth) { maxDepth = depth; } }, fnAfter: e => depth--); return(maxDepth); }