Beispiel #1
0
 CaseBlockSyntax ConvertSwitchSection(CSS.SwitchSectionSyntax section)
 {
     if (IsDefaultSwitchStatement(section))
     {
         return(SyntaxFactory.CaseElseBlock(SyntaxFactory.CaseElseStatement(SyntaxFactory.ElseCaseClause()), ConvertSwitchSectionBlock(section)));
     }
     return(SyntaxFactory.CaseBlock(SyntaxFactory.CaseStatement(SyntaxFactory.SeparatedList(section.Labels.OfType <CSS.CaseSwitchLabelSyntax>().Select(ConvertSwitchLabel))), ConvertSwitchSectionBlock(section)));
 }
Beispiel #2
0
        CaseBlockSyntax ConvertSwitchSection(CSS.SwitchSectionSyntax section)
        {
            if (IsDefaultSwitchStatement(section))
            {
                return(SyntaxFactory.CaseElseBlock(SyntaxFactory.CaseElseStatement(SyntaxFactory.ElseCaseClause()), ConvertSwitchSectionBlock(section)));
            }
            var caseClauseSyntaxes  = section.Labels.Select(l => l.Accept(_nodesVisitor));
            var caseStatementSyntax = SyntaxFactory.CaseStatement(SyntaxFactory.SeparatedList(caseClauseSyntaxes.Cast <CaseClauseSyntax>()));

            return(SyntaxFactory.CaseBlock(caseStatementSyntax, ConvertSwitchSectionBlock(section)));
        }
Beispiel #3
0
        SyntaxList <StatementSyntax> ConvertSwitchSectionBlock(CSS.SwitchSectionSyntax section)
        {
            List <StatementSyntax> statements = new List <StatementSyntax>();
            var lastStatement = section.Statements.LastOrDefault();

            foreach (var s in section.Statements)
            {
                if (s == lastStatement && s is CSS.BreakStatementSyntax)
                {
                    continue;
                }
                statements.AddRange(ConvertBlock(s));
            }
            return(SyntaxFactory.List(statements));
        }
Beispiel #4
0
 private static bool IsDefaultSwitchStatement(CSS.SwitchSectionSyntax c)
 {
     return(c.Labels.OfType <CSS.DefaultSwitchLabelSyntax>().Any());
 }