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


C# IfStatementSyntax.ChildNodes方法代码示例

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


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

示例1: CheckIfStatementNotEmpty

        internal SyntaxNode CheckIfStatementNotEmpty(IfStatementSyntax firstIfStatement)
        {
            if (reportedIssue) { return null; }
            var ifAppliedNode = firstIfStatement.ChildNodes().Where(node => node as BlockSyntax != null).FirstOrDefault();
            if (ifAppliedNode == null)
            {
                ReportIssue( "empty if block");
            }

            return ifAppliedNode;
        }
开发者ID:peterstevens130561,项目名称:sonarlint-vs,代码行数:11,代码来源:LockChecks.cs

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