protected override SyntaxNode VisitIfStatement(IfStatementSyntax node) { if (!node.DescendentNodes().OfType<BlockSyntax>().Any()) { node = node.Update (node.IfKeyword, node.OpenParenToken, node.Condition, node.CloseParenToken, Syntax.Block (statements: node.Statement), node.ElseOpt); } if (node.ElseOpt != null) { ElseClauseSyntax elseOpt = node.ElseOpt; IfStatementSyntax ifSyntax = elseOpt.Statement as IfStatementSyntax; if (ifSyntax != null) { if (!ifSyntax.DescendentNodes().OfType<BlockSyntax>().Any()) { ifSyntax = ifSyntax.Update (ifSyntax.IfKeyword, ifSyntax.OpenParenToken, ifSyntax.Condition, ifSyntax.CloseParenToken, Syntax.Block (statements: ifSyntax.Statement), ifSyntax.ElseOpt); elseOpt = elseOpt.Update (elseOpt.ElseKeyword, ifSyntax); } } else if (!elseOpt.DescendentNodes().OfType<BlockSyntax>().Any()) elseOpt = node.ElseOpt.Update (node.ElseOpt.ElseKeyword, Syntax.Block (statements: node.ElseOpt.Statement)); if (elseOpt != node.ElseOpt) node = node.Update (node.IfKeyword, node.OpenParenToken, node.Condition, node.CloseParenToken, node.Statement, elseOpt); } return base.VisitIfStatement (node); }
protected override SyntaxNode VisitIfStatement(IfStatementSyntax node) { if (!node.DescendentNodes().OfType <BlockSyntax>().Any()) { node = node.Update(node.IfKeyword, node.OpenParenToken, node.Condition, node.CloseParenToken, Syntax.Block(statements: node.Statement), node.ElseOpt); } if (node.ElseOpt != null) { ElseClauseSyntax elseOpt = node.ElseOpt; IfStatementSyntax ifSyntax = elseOpt.Statement as IfStatementSyntax; if (ifSyntax != null) { if (!ifSyntax.DescendentNodes().OfType <BlockSyntax>().Any()) { ifSyntax = ifSyntax.Update(ifSyntax.IfKeyword, ifSyntax.OpenParenToken, ifSyntax.Condition, ifSyntax.CloseParenToken, Syntax.Block(statements: ifSyntax.Statement), ifSyntax.ElseOpt); elseOpt = elseOpt.Update(elseOpt.ElseKeyword, ifSyntax); } } else if (!elseOpt.DescendentNodes().OfType <BlockSyntax>().Any()) { elseOpt = node.ElseOpt.Update(node.ElseOpt.ElseKeyword, Syntax.Block(statements: node.ElseOpt.Statement)); } if (elseOpt != node.ElseOpt) { node = node.Update(node.IfKeyword, node.OpenParenToken, node.Condition, node.CloseParenToken, node.Statement, elseOpt); } } return(base.VisitIfStatement(node)); }