Ejemplo n.º 1
0
        private static FixedStatementSyntax AddStatementWithoutEmptyStatements(this FixedStatementSyntax fixedStatement, StatementSyntax childStatement)
        {
            if (fixedStatement.Statement.IsKind(SyntaxKind.EmptyStatement))
            {
                return(fixedStatement.WithStatement(childStatement));
            }

            BlockSyntax block;

            if (fixedStatement.Statement.IsKind(SyntaxKind.Block))
            {
                block = (BlockSyntax)fixedStatement.Statement;
                if (block.Statements.Count == 0)
                {
                    return(fixedStatement.WithStatement(childStatement));
                }
            }
            else
            {
                block = SyntaxFactory.Block(fixedStatement.Statement);
            }

            if (childStatement.IsKind(SyntaxKind.Block))
            {
                block = block.WithStatements(block.Statements.AddRange(((BlockSyntax)childStatement).Statements));
            }
            else
            {
                block = block.AddStatements(childStatement);
            }

            return(fixedStatement.WithStatement(block));
        }
Ejemplo n.º 2
0
 private static FixedStatementSyntax AddStatementWithoutEmptyStatements(this FixedStatementSyntax fixedStatement, StatementSyntax childStatement)
 {
     if (fixedStatement.Statement.IsKind(SyntaxKind.EmptyStatement))
     {
         return(fixedStatement.WithStatement(childStatement));
     }
     if (fixedStatement.Statement.IsKind(SyntaxKind.Block))
     {
         var block = (BlockSyntax)fixedStatement.Statement;
         if (block.Statements.Count == 0)
         {
             return(fixedStatement.WithStatement(childStatement));
         }
         return(fixedStatement.WithStatement(block.AddStatements(childStatement)));
     }
     return(fixedStatement.WithStatement(SyntaxFactory.Block(fixedStatement.Statement, childStatement)));
 }