當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。