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


C# ForEachStatementSyntax.GetLeadingTrivia方法代码示例

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


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

示例1: TraverseForEachStatements

        private Decisions TraverseForEachStatements(ForEachStatementSyntax fes, ref int exitPoints, bool nested = false)
        {
            Decisions retDecision = new Decisions();
            ForEachStatement retForEach = new ForEachStatement();

            if (fes.HasLeadingTrivia)
            {
                SetOuterComments(retForEach, fes.GetLeadingTrivia().ToFullString());
            }

            if (fes.HasTrailingTrivia)
            {
                SetInnerComments(retForEach, fes.GetTrailingTrivia().ToFullString());
            }

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


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