private IEnumerable<BlockSyntax> GetBlocks(SyntaxNode node) { var childBlocks = node.ChildNodes().Where(x => x.IsKind(SyntaxKind.Block)).Cast<BlockSyntax>(); var others = node.ChildNodes() .Where(x => !x.IsKind(SyntaxKind.Block)) .SelectMany(GetBlocks); return childBlocks.Concat(others); } }