当前位置: 首页>>代码示例>>C#>>正文


C# BlockSyntax.Update方法代码示例

本文整理汇总了C#中BlockSyntax.Update方法的典型用法代码示例。如果您正苦于以下问题:C# BlockSyntax.Update方法的具体用法?C# BlockSyntax.Update怎么用?C# BlockSyntax.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BlockSyntax的用法示例。


在下文中一共展示了BlockSyntax.Update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReformatBodyAsMultipleLines

        private static BlockSyntax ReformatBodyAsMultipleLines(BlockSyntax body, SyntaxTrivia indentation, SyntaxTrivia indentationStatements)
        {
            SyntaxTriviaList reformattedOpenBraceTrailingTrivia;
            SyntaxTriviaList reformattedCloseBraceLeadingTrivia;

            SyntaxList<StatementSyntax> newStatements;
            if (body.Statements.Count > 0)
            {
                var statements = new List<StatementSyntax>();

                foreach (var statement in body.Statements)
                {
                    var reformattedStatement = statement
                        .WithLeadingTrivia(ReformatTriviaListNoLeadingSpace(statement.GetLeadingTrivia()).Insert(0, indentationStatements))
                        .WithTrailingTrivia(ReformatTriviaListNoTrailingSpace(statement.GetTrailingTrivia()).Add(SyntaxFactory.CarriageReturnLineFeed));
                    statements.Add(reformattedStatement);
                }

                newStatements = SyntaxFactory.List<StatementSyntax>().AddRange(statements);

                reformattedOpenBraceTrailingTrivia = ReformatTriviaListNoTrailingSpace(body.OpenBraceToken.TrailingTrivia);
                reformattedCloseBraceLeadingTrivia = ReformatTriviaListNoLeadingSpace(body.CloseBraceToken.LeadingTrivia);
            }
            else
            {
                var triviaBetweenBraces = TriviaHelper.MergeTriviaLists(body.OpenBraceToken.TrailingTrivia, body.CloseBraceToken.LeadingTrivia);
                reformattedOpenBraceTrailingTrivia = ReformatTriviaListNoTrailingSpace(triviaBetweenBraces);
                newStatements = body.Statements;
                reformattedCloseBraceLeadingTrivia = SyntaxFactory.TriviaList();
            }

            var newOpenBraceToken = body.OpenBraceToken
                .WithLeadingTrivia(ReformatTriviaListNoLeadingSpace(body.OpenBraceToken.LeadingTrivia).Insert(0, indentation))
                .WithTrailingTrivia(reformattedOpenBraceTrailingTrivia.Add(SyntaxFactory.CarriageReturnLineFeed));

            var newCloseBraceToken = body.CloseBraceToken
                .WithLeadingTrivia(reformattedCloseBraceLeadingTrivia.Insert(0, indentation))
                .WithTrailingTrivia(ReformatTriviaListNoTrailingSpace(body.CloseBraceToken.TrailingTrivia).Add(SyntaxFactory.CarriageReturnLineFeed));

            return body.Update(newOpenBraceToken, newStatements, newCloseBraceToken);
        }
开发者ID:neugenes,项目名称:StyleCopAnalyzers,代码行数:41,代码来源:SA1504CodeFixProvider.cs

示例2: VisitBlock

        protected override SyntaxNode VisitBlock(BlockSyntax node)
        {
            var results = base.VisitBlock (node);
            node = results as BlockSyntax;
            if (node == null)
                return results;

            List<StatementSyntax> statements = new List<StatementSyntax> (node.Statements.Count + 4);

            foreach (StatementSyntax statement in node.Statements)
            {
                bool loop = statement.HasAnnotation (this.isLoop);
                if (loop)
                    statements.Add (BeginLoopStatement);

                if (this.loopLevel > 0)
                {
                    if (statement is ContinueStatementSyntax || statement is BreakStatementSyntax)
                        statements.Add (EndInsideLoopStatement);
                    else if (statement is ReturnStatementSyntax && ((ReturnStatementSyntax)statement).ExpressionOpt == null)
                        statements.Add (ReturnStatement);
                }

                statements.Add (statement);

                var es = statement as ExpressionStatementSyntax;
                if (es != null)
                {
                    var postfixUnary = es.ChildNodes().OfType<PostfixUnaryExpressionSyntax>().FirstOrDefault();
                    if (postfixUnary != null)
                    {
                        var name = postfixUnary.Operand as IdentifierNameSyntax;
                        if (name != null)
                            statements.Add (Syntax.ExpressionStatement (GetLogExpression (name.PlainName, name.PlainName)));
                    }
                }

                if (loop)
                    statements.Add (EndLoopStatement);
            }

            return node.Update (node.OpenBraceToken, Syntax.List<StatementSyntax> (statements), node.CloseBraceToken);
        }
开发者ID:Auxon,项目名称:Instant,代码行数:43,代码来源:LoggingRewriter.cs

示例3: ReformatBodyAsSingleLine

        private static BlockSyntax ReformatBodyAsSingleLine(BlockSyntax body)
        {
            var newOpenBraceToken = body.OpenBraceToken
                .WithLeadingTrivia(ReformatTriviaList(body.OpenBraceToken.LeadingTrivia))
                .WithTrailingTrivia(ReformatTriviaListNoTrailingSpace(body.OpenBraceToken.TrailingTrivia));

            SyntaxList<StatementSyntax> newStatements;
            if (body.Statements.Count > 0)
            {
                var reformattedStatement = body.Statements[0]
                    .WithLeadingTrivia(ReformatTriviaList(body.Statements[0].GetLeadingTrivia()))
                    .WithTrailingTrivia(ReformatTriviaListNoTrailingSpace(body.Statements[0].GetTrailingTrivia()));

                newStatements = SyntaxFactory.List<StatementSyntax>().Add(reformattedStatement);
            }
            else
            {
                newStatements = body.Statements;
            }

            var newCloseBraceToken = body.CloseBraceToken
                .WithLeadingTrivia(ReformatTriviaList(body.CloseBraceToken.LeadingTrivia))
                .WithTrailingTrivia(ReformatTriviaListNoTrailingSpace(body.CloseBraceToken.TrailingTrivia).Add(SyntaxFactory.CarriageReturnLineFeed));

            return body.Update(newOpenBraceToken, newStatements, newCloseBraceToken);
        }
开发者ID:neugenes,项目名称:StyleCopAnalyzers,代码行数:26,代码来源:SA1504CodeFixProvider.cs

示例4: VisitBlock

        protected override SyntaxNode VisitBlock(BlockSyntax node)
        {
            var results = base.VisitBlock (node);
            node = results as BlockSyntax;
            if (node == null)
                return results;

            List<StatementSyntax> statements = new List<StatementSyntax> (node.Statements.Count + 4);

            foreach (StatementSyntax statement in node.Statements)
            {
                bool loop = statement.HasAnnotation (this.isLoop);
                if (loop)
                    statements.Add (BeginLoopStatement);

                if (this.loopLevel > 0)
                {
                    if (statement is ContinueStatementSyntax || statement is BreakStatementSyntax)
                        statements.Add (EndInsideLoopStatement);
                    else if (statement is ReturnStatementSyntax && ((ReturnStatementSyntax)statement).ExpressionOpt == null)
                        statements.Add (ReturnStatement);
                }

                statements.Add (statement);

                if (loop)
                    statements.Add (EndLoopStatement);
            }

            return node.Update (node.OpenBraceToken, Syntax.List<StatementSyntax> (statements), node.CloseBraceToken);
        }
开发者ID:Mstrymt,项目名称:Instant,代码行数:31,代码来源:LoggingRewriter.cs


注:本文中的BlockSyntax.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。