public CSharpSyntaxNode Convert(CaseClause node) { SwitchSectionSyntax csSwitchSection = SyntaxFactory.SwitchSection(); csSwitchSection = csSwitchSection.AddLabels(SyntaxFactory.CaseSwitchLabel(node.Expression.ToCsNode <ExpressionSyntax>())); csSwitchSection = csSwitchSection.AddStatements(node.Statements.ToCsNodes <StatementSyntax>()); return(csSwitchSection); }
public CSharpSyntaxNode Convert(DefaultClause node) { SwitchSectionSyntax csSwitchSection = SyntaxFactory.SwitchSection(); csSwitchSection = csSwitchSection.AddLabels(SyntaxFactory.DefaultSwitchLabel()); csSwitchSection = csSwitchSection.AddStatements(node.Statements.ToCsNodes <StatementSyntax>()); return(csSwitchSection); }
public static Task <Document> RefactorAsync( Document document, SwitchSectionSyntax switchSection, CancellationToken cancellationToken) { SwitchSectionSyntax newNode = switchSection; SyntaxList <StatementSyntax> statements = switchSection.Statements; if (statements.Count == 1 && statements.First().IsKind(SyntaxKind.Block)) { var block = (BlockSyntax)statements.First(); newNode = newNode.ReplaceNode(block, block.AddStatements(BreakStatement())); } else { newNode = switchSection.AddStatements(BreakStatement()); } return(document.ReplaceNodeAsync(switchSection, newNode, cancellationToken)); }