Пример #1
0
        public static StatementSyntax GetBlockOrEmbeddedStatement(SyntaxNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            switch (node.Kind())
            {
            case SyntaxKind.IfStatement:
                return(((IfStatementSyntax)node).Statement);

            case SyntaxKind.ForEachStatement:
            case SyntaxKind.ForEachVariableStatement:
                return(((CommonForEachStatementSyntax)node).Statement);

            case SyntaxKind.ForStatement:
                return(((ForStatementSyntax)node).Statement);

            case SyntaxKind.WhileStatement:
                return(((WhileStatementSyntax)node).Statement);

            case SyntaxKind.DoStatement:
                return(((DoStatementSyntax)node).Statement);

            case SyntaxKind.LockStatement:
                return(((LockStatementSyntax)node).Statement);

            case SyntaxKind.FixedStatement:
                return(((FixedStatementSyntax)node).Statement);

            case SyntaxKind.UsingStatement:
            {
                StatementSyntax statement = ((UsingStatementSyntax)node).Statement;
                if (statement?.IsKind(SyntaxKind.UsingStatement) != true)
                {
                    return(statement);
                }

                break;
            }

            case SyntaxKind.ElseClause:
            {
                var elseClause = (ElseClauseSyntax)node;

                if (IfElseChain.IsEndOfChain(elseClause))
                {
                    return(elseClause.Statement);
                }

                break;
            }
            }

            return(null);
        }
Пример #2
0
        public static StatementSyntax GetBlockOrEmbeddedStatement(SyntaxNode node)
        {
            switch (node.Kind())
            {
            case SyntaxKind.IfStatement:
                return(((IfStatementSyntax)node).Statement);

            case SyntaxKind.ForEachStatement:
                return(((ForEachStatementSyntax)node).Statement);

            case SyntaxKind.ForStatement:
                return(((ForStatementSyntax)node).Statement);

            case SyntaxKind.WhileStatement:
                return(((WhileStatementSyntax)node).Statement);

            case SyntaxKind.DoStatement:
                return(((DoStatementSyntax)node).Statement);

            case SyntaxKind.LockStatement:
                return(((LockStatementSyntax)node).Statement);

            case SyntaxKind.FixedStatement:
                return(((FixedStatementSyntax)node).Statement);

            case SyntaxKind.UsingStatement:
            {
                StatementSyntax statement = ((UsingStatementSyntax)node).Statement;
                if (statement?.IsKind(SyntaxKind.UsingStatement) != true)
                {
                    return(statement);
                }

                break;
            }

            case SyntaxKind.ElseClause:
            {
                var elseClause = (ElseClauseSyntax)node;

                if (IfElseChain.IsEndOfChain(elseClause))
                {
                    return(elseClause.Statement);
                }

                break;
            }
            }

            return(null);
        }