public static BlockType GetBlockTypeStartingAt(string[] lines, int index) { /////////////////////EARLY OUT//////////////////////// if (index >= lines.Length) { return(BlockType.None); } //////////////////END EARLY OUT////////////////////// BlockType blockType = BlockType.None; var statements = new CSharpParser().ParseStatements(lines[index]); var firstStatement = statements.FirstOrDefault(); if (firstStatement != null) { if (firstStatement is WhileStatement) { blockType = BlockType.While; } else if (firstStatement is ForeachStatement) { blockType = BlockType.Foreach; } else if (firstStatement is ForStatement) { blockType = BlockType.For; } else if (firstStatement is IfElseStatement) { string line = lines[index].Trim(); if (line.StartsWith("if")) { blockType = BlockType.If; } else if (line.StartsWith("else if")) { blockType = BlockType.ElseIf; } else { blockType = BlockType.Else; } } } return(blockType); }