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


C# IfStatementSyntax.GetTrailingTrivia方法代码示例

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


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

示例1: MergeIfs

 private static SyntaxNode MergeIfs(IfStatementSyntax ifStatement, SyntaxNode root)
 {
     var nestedIf = (IfStatementSyntax)ifStatement.Statement.GetSingleStatementFromPossibleBlock();
     var newIf = ifStatement
         .WithCondition(SyntaxFactory.BinaryExpression(SyntaxKind.LogicalAndExpression, ifStatement.Condition, nestedIf.Condition))
         .WithStatement(nestedIf.Statement)
         .WithLeadingTrivia(ifStatement.GetLeadingTrivia().AddRange(nestedIf.GetLeadingTrivia()))
         .WithAdditionalAnnotations(Formatter.Annotation);
     if (ifStatement.HasTrailingTrivia && nestedIf.HasTrailingTrivia && !ifStatement.GetTrailingTrivia().Equals(nestedIf.GetTrailingTrivia()))
         newIf = newIf.WithTrailingTrivia(ifStatement.GetTrailingTrivia().AddRange(nestedIf.GetTrailingTrivia()));
     var newRoot = root.ReplaceNode(ifStatement, newIf);
     return newRoot;
 }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:13,代码来源:MergeNestedIfCodeFixProvider.cs

示例2: GetMatch

        static bool GetMatch(IfStatementSyntax node, out ExpressionSyntax c, out ReturnStatementSyntax e1, out ReturnStatementSyntax e2, out ReturnStatementSyntax rs)
        {
            rs = e1 = e2 = null;
            c = node.Condition;
            //attempt to match if(condition) return else return
            e1 = ConvertIfStatementToNullCoalescingExpressionAction.GetSimpleStatement(node.Statement) as ReturnStatementSyntax;
            if (e1 == null)
                return false;
            e2 = node.Else != null ? ConvertIfStatementToNullCoalescingExpressionAction.GetSimpleStatement(node.Else.Statement) as ReturnStatementSyntax : null;
            //match
            if (e1 != null && e2 != null)
            {
                return true;
            }

            //attempt to match if(condition) return
            if (e1 != null)
            {
                rs = node.Parent.ChildThatContainsPosition(node.GetTrailingTrivia().Max(t => t.FullSpan.End) + 1).AsNode() as ReturnStatementSyntax;
                if (rs != null)
                {
                    e2 = rs;
                    return true;
                }
            }
            return false;
        }
开发者ID:Kavignon,项目名称:RefactoringEssentials,代码行数:27,代码来源:ConvertIfStatementToReturnStatementAction.cs

示例3: UseExistenceOperatorAsyncWithReturnAsync

 private static async Task<Document> UseExistenceOperatorAsyncWithReturnAsync(Document document, IfStatementSyntax ifStatement, CancellationToken cancellationToken, ReturnStatementSyntax returnIf)
 {
     var newMemberAccess = ((MemberAccessExpressionSyntax)returnIf.Expression).ToConditionalAccessExpression();
     var newReturn = SyntaxFactory.ReturnStatement(newMemberAccess)
         .WithLeadingTrivia(ifStatement.GetLeadingTrivia())
         .WithTrailingTrivia(ifStatement.GetTrailingTrivia())
         .WithAdditionalAnnotations(Formatter.Annotation);
     var root = await document.GetSyntaxRootAsync(cancellationToken);
     var newRoot = root.ReplaceNode(ifStatement, newReturn);
     var newDocument = document.WithSyntaxRoot(newRoot);
     return newDocument;
 }
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:12,代码来源:ExistenceOperatorCodeFixProvider.cs

示例4: UseExistenceOperatorAsyncWithAssignmentAsync

 private static async Task<Document> UseExistenceOperatorAsyncWithAssignmentAsync(Document document, IfStatementSyntax ifStatement, CancellationToken cancellationToken, ExpressionStatementSyntax expressionIf)
 {
     var memberAccessAssignment = (AssignmentExpressionSyntax)expressionIf.Expression;
     var newMemberAccess = ((MemberAccessExpressionSyntax)memberAccessAssignment.Right).ToConditionalAccessExpression();
     var newExpressionStatement = SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, memberAccessAssignment.Left, newMemberAccess))
         .WithLeadingTrivia(ifStatement.GetLeadingTrivia())
         .WithTrailingTrivia(ifStatement.GetTrailingTrivia())
         .WithAdditionalAnnotations(Formatter.Annotation);
     var root = await document.GetSyntaxRootAsync(cancellationToken);
     var newRoot = root.ReplaceNode(ifStatement, newExpressionStatement);
     var newDocument = document.WithSyntaxRoot(newRoot);
     return newDocument;
 }
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:13,代码来源:ExistenceOperatorCodeFixProvider.cs

示例5: TraverseIfStatements

        private Decisions TraverseIfStatements(IfStatementSyntax iss, ref int exitPoints, bool nested = false)
        {
            Decisions retDecision = new Decisions();
            IfStatement ifStm = new IfStatement();
            if (iss.HasLeadingTrivia)
            {
                SetOuterComments(ifStm, iss.GetLeadingTrivia().ToFullString());
            }

            if (iss.HasTrailingTrivia)
            {
                SetInnerComments(ifStm, iss.GetTrailingTrivia().ToFullString());
            }
            ifStm.IsNested = nested;
            //public int ExpressionListEndLn { get; set; }
            //public int ExpressionListStartLn { get; set; }
            //public bool IsNested { get; set; }
            ExpressionSyntax es = iss.Condition;
            var binaryExpressions = from aBinaryExpression in iss.Condition.DescendantNodesAndSelf().OfType<BinaryExpressionSyntax>() select aBinaryExpression;
            ifStm.ConditionCount = binaryExpressions.Count();
            //This area is for the conditions i.e. the stuff in the () of if ()
            foreach (BinaryExpressionSyntax bes in binaryExpressions)
            {
                Method tempMethod = TraverseBinaryExpression(bes);
                ifStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                ifStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
            }
            //TODO handle catches (if there are even catches inside if statements)
            var catches = from aCatch in iss.ChildNodes().OfType<CatchClauseSyntax>() select aCatch;
            foreach (CatchClauseSyntax ccs in catches)
            {
                Decisions tempCatch = TraverseCatchClauses(ccs, ref exitPoints, true);
                ifStm.Nested.AddRange(tempCatch.Catches);
            }
            //TODO need to handle else clauses
            var elses = from aElse in iss.ChildNodes().OfType<ElseClauseSyntax>() select aElse;
            foreach (ElseClauseSyntax ecs in elses)
            {
                //TODO
                //Traverse ElseClauseSyntax
                Decisions tempElse = TraverseElseClauses(ecs, ref exitPoints, true);
                ifStm.Nested.AddRange(tempElse.ElseStatements);
                #region old code with method return
                //ifStm.InvokedMethods.AddRange(tempElse.InvokedMethods);
                //ifStm.AccessedVars.AddRange(tempElse.AccessedVars);
                //ifStm.Nested.Add(tempElse);
                //foreach (BaseDecisions bd in ifStm.Nested)
                //{
                //    bd.IsNested = true;
                //}
                #endregion
            }
            //TODO need to find a way to return both nested
            //and invoked methods / accessedvars to the parent method
            var statements = from aStatement in iss.Statement.ChildNodes().OfType<StatementSyntax>() select aStatement;
            List<BaseDecisions> retBd = new List<BaseDecisions>();
            List<InvokedMethod> retIm = new List<InvokedMethod>();
            #region Nested and Invoked Methods and accessed vars
            foreach (StatementSyntax ss in statements)
            {

                //if (ss is BreakStatementSyntax)
                //{
                //}
                //else if (ss is CheckedStatementSyntax)
                //{
                //}
                //else if (ss is ContinueStatementSyntax)
                //{
                //}
                if (ss is DoStatementSyntax)
                {
                    Decisions dwl = TraverseDoStatements(ss as DoStatementSyntax, ref exitPoints, true);
                    ifStm.Nested.AddRange(dwl.DoWhileLoops);
                    //dwl.IsNested = true;
                    //ifStm.Nested.Add(dwl);
                }
                //else if (ss is EmptyStatementSyntax)
                //{
                //}
                else if (ss is ExpressionStatementSyntax)
                {
                    Method tempMethod = TraverseExpressionStatementSyntax(ss as ExpressionStatementSyntax);
                    ifStm.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    ifStm.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                }
                //else if (ss is FixedStatementSyntax)
                //{
                //}
                else if (ss is ForEachStatementSyntax)
                {
                    Decisions fes = TraverseForEachStatements(ss as ForEachStatementSyntax, ref exitPoints, true);
                    ifStm.Nested.AddRange(fes.ForEachStatements);
                    //fes.IsNested = true;
                    //ifStm.Nested.Add(fes);
                }
                else if (ss is ForStatementSyntax)
                {
                    Decisions fs = TraverseForStatements(ss as ForStatementSyntax, ref exitPoints, true);
                    ifStm.Nested.AddRange(fs.ForStatements);
//.........这里部分代码省略.........
开发者ID:Zenoware,项目名称:RoslynParser,代码行数:101,代码来源:RoslynCSharpParser.cs


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