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


C# BinaryExpressionSyntax.ChildNodes方法代码示例

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


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

示例1: GetInvocationExpressionsThatHaveToStringCall

 private static IEnumerable<InvocationExpressionSyntax> GetInvocationExpressionsThatHaveToStringCall(BinaryExpressionSyntax addExpression)
 {
     return addExpression.ChildNodes().OfType<InvocationExpressionSyntax>()
         //Only default call to ToString method must be accepted
         .Where(x => x.Expression.ToString().EndsWith(@".ToString") && !x.ArgumentList.Arguments.Any());
 }
开发者ID:julianosaless,项目名称:code-cracker,代码行数:6,代码来源:UnnecessaryToStringInStringConcatenationAnalyzer.cs

示例2: TraverseBinaryExpression

        private Method TraverseBinaryExpression(BinaryExpressionSyntax bes)
        {
            var variables = from aVariable in bes.ChildNodes().OfType<IdentifierNameSyntax>() select aVariable;
            Method retMethod = new Method();

            if (bes.HasLeadingTrivia)
            {
                SetOuterComments(retMethod, bes.GetLeadingTrivia().ToFullString());
            }

            if (bes.HasTrailingTrivia)
            {
                SetInnerComments(retMethod, bes.GetTrailingTrivia().ToFullString());
            }

            //Casting on the back end....ex:
            // abc = def as double ------- def as double is the binary expression
            if (bes.OperatorToken.IsKind(SyntaxKind.AsKeyword))
            {
                if (bes.Left is IdentifierNameSyntax)
                {
                    IdentifierNameSyntax ins = bes.Left as IdentifierNameSyntax;
                    Variables tempVar = new Variables();
                    tempVar.Name = ins.Identifier.ValueText;
                    if (bes.Right is PredefinedTypeSyntax)
                    {
                        PredefinedTypeSyntax pts = bes.Right as PredefinedTypeSyntax;
                        Model.Type tempType = new Model.Type();
                        tempType.Name = pts.ToString();
                        tempType.IsKnownType = true;
                        tempType.IsNotUserDefined = true;
                        tempVar.Type = tempType;
                    }
                    retMethod.AccessedVariables.Add(tempVar);
                }
                else if (bes.Left is MemberAccessExpressionSyntax)
                {
                    MemberAccessExpressionSyntax maes = bes.Left as MemberAccessExpressionSyntax;
                    Variables tempVar = new Variables();
                    tempVar.Name = maes.ToString();
                    tempVar.IsReferenced = true;
                    retMethod.AccessedVariables.Add(tempVar);
                }
            }
            else
            {
                foreach (IdentifierNameSyntax ins in variables)
                {
                    //TODO put a bp here and test if this adds method names (bad) or just var names(good)
                    Variables vars = new Variables();
                    vars.Name = ins.Identifier.ValueText;
                    vars.IsReferenced = true;
                    retMethod.AccessedVariables.Add(vars);
                    //TODO variable types
                }
                var binaryExprs = from aBinaryExpr in bes.ChildNodes().OfType<BinaryExpressionSyntax>() select aBinaryExpr;
                foreach (BinaryExpressionSyntax bes2 in binaryExprs)
                {
                    Method retMethod2 = TraverseBinaryExpression(bes2);
                    retMethod.AccessedVariables.AddRange(retMethod2.AccessedVariables);
                    retMethod.InvokedMethods.AddRange(retMethod2.InvokedMethods);
                }
                var invokedMethods = from aInvokedMethod in bes.ChildNodes().OfType<InvocationExpressionSyntax>() select aInvokedMethod;
                foreach (InvocationExpressionSyntax ies in invokedMethods)
                {
                    Method tempMethod = TraverseInvocationExpression(ies);
                    retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                    retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables);
                }
                var castExprs = from aCastExpr in bes.ChildNodes().OfType<CastExpressionSyntax>() select aCastExpr;
                foreach (CastExpressionSyntax ces in castExprs)
                {
                    Method retMethod3 = TraverseCastExpressions(ces);
                    retMethod.AccessedVariables.AddRange(retMethod3.AccessedVariables);
                    retMethod.InvokedMethods.AddRange(retMethod3.InvokedMethods);
                }
            }
            return retMethod;
        }
开发者ID:Zenoware,项目名称:RoslynParser,代码行数:79,代码来源:RoslynCSharpParser.cs


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