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


C# SwitchStatementSyntax.GetTrailingTrivia方法代码示例

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


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

示例1: TraverseSwitchStatements

        private Decisions TraverseSwitchStatements(SwitchStatementSyntax sss, ref int exitPoints, bool nested = false)
        {
            Decisions retDecision = new Decisions();
            SwitchStatement retSwitch = new SwitchStatement();

            if (sss.HasLeadingTrivia)
            {
                SetOuterComments(retSwitch, sss.GetLeadingTrivia().ToFullString());
            }

            if (sss.HasTrailingTrivia)
            {
                SetInnerComments(retSwitch, sss.GetTrailingTrivia().ToFullString());
            }

            ExpressionSyntax es = sss.Expression;
            var binaryExprs = from aBinaryExpr in sss.ChildNodes().OfType<BinaryExpressionSyntax>() select aBinaryExpr;
            foreach (BinaryExpressionSyntax bes in binaryExprs)
            {
                Method tempMethod = TraverseBinaryExpression(bes);
                retSwitch.AccessedVars.AddRange(tempMethod.AccessedVariables);
                retSwitch.InvokedMethods.AddRange(tempMethod.InvokedMethods);
            }
            var catches = from aCatch in sss.ChildNodes().OfType<CatchClauseSyntax>() select aCatch;
            foreach (CatchClauseSyntax ccs in catches)
            {
                Decisions tempCatch = TraverseCatchClauses(ccs, ref exitPoints, true);
                retSwitch.Nested.AddRange(tempCatch.Catches);
            }
            var statements = from aStatement in sss.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);
                    retSwitch.Nested.AddRange(dwl.DoWhileLoops);
                    //dwl.Nested.Add(TraverseDoStatements(ss as DoStatementSyntax));
                    //retSwitch.Nested.Add(dwl);
                }
                //else if (ss is EmptyStatementSyntax)
                //{
                //}
                else if (ss is ExpressionStatementSyntax)
                {
                    var vars = from aVar in ss.ChildNodes().OfType<BinaryExpressionSyntax>() select aVar;
                    foreach (BinaryExpressionSyntax bes in vars)
                    {
                        Method tempMethod = TraverseBinaryExpression(bes);
                        retSwitch.AccessedVars.AddRange(tempMethod.AccessedVariables);
                        retSwitch.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                    }
                    var invokedMethods = from aInvokedMethod in ss.ChildNodes().OfType<InvocationExpressionSyntax>() select aInvokedMethod;
                    foreach (InvocationExpressionSyntax ies in invokedMethods)
                    {
                        Method tempMethod = TraverseInvocationExpression(ies);
                        retSwitch.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                        retSwitch.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    }
                }
                //else if (ss is FixedStatementSyntax)
                //{
                //}
                else if (ss is ForEachStatementSyntax)
                {
                    Decisions fes = TraverseForEachStatements(ss as ForEachStatementSyntax, ref exitPoints, true);
                    retSwitch.Nested.AddRange(fes.ForEachStatements);
                    //fes.IsNested = true;
                    //retSwitch.Nested.Add(fes);
                }
                else if (ss is ForStatementSyntax)
                {
                    Decisions fs = TraverseForStatements(ss as ForStatementSyntax, ref exitPoints, true);
                    retSwitch.Nested.AddRange(fs.ForStatements);
                    //fs.IsNested = true;
                    //retSwitch.Nested.Add(fs);
                }
                //else if (ss is GotoStatementSyntax)
                //{
                //}
                else if (ss is IfStatementSyntax)
                {
                    Decisions ifstm = TraverseIfStatements(ss as IfStatementSyntax, ref exitPoints, true);
                    retSwitch.Nested.AddRange(ifstm.IfStatements);
                    //ifstm.IsNested = true;
                    //retSwitch.Nested.Add(ifstm);
                }
                //else if (ss is LabeledStatementSyntax)
//.........这里部分代码省略.........
开发者ID:Zenoware,项目名称:RoslynParser,代码行数:101,代码来源:RoslynCSharpParser.cs


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