當前位置: 首頁>>代碼示例>>C#>>正文


C# BinaryExpressionSyntax.GetLeadingTrivia方法代碼示例

本文整理匯總了C#中BinaryExpressionSyntax.GetLeadingTrivia方法的典型用法代碼示例。如果您正苦於以下問題:C# BinaryExpressionSyntax.GetLeadingTrivia方法的具體用法?C# BinaryExpressionSyntax.GetLeadingTrivia怎麽用?C# BinaryExpressionSyntax.GetLeadingTrivia使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BinaryExpressionSyntax的用法示例。


在下文中一共展示了BinaryExpressionSyntax.GetLeadingTrivia方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: PerformAction

        static Document PerformAction(Document document, SyntaxNode root, BinaryExpressionSyntax bop)
        {
            var nodeToReplace = bop.IsParentKind(SyntaxKind.ParenthesizedExpression) ? bop.Parent : bop;
            var castExpr = (ExpressionSyntax)SyntaxFactory.CastExpression(bop.Right as TypeSyntax, CSharpUtil.AddParensIfRequired(bop.Left.WithoutLeadingTrivia().WithoutTrailingTrivia())).WithLeadingTrivia(bop.GetLeadingTrivia()).WithTrailingTrivia(bop.GetTrailingTrivia());

            var newRoot = root.ReplaceNode((SyntaxNode)nodeToReplace, castExpr);
            return document.WithSyntaxRoot(newRoot);
        }
開發者ID:alecor191,項目名稱:RefactoringEssentials,代碼行數:8,代碼來源:ReplaceSafeCastWithDirectCastCodeRefactoringProvider.cs

示例2: VisitBinaryExpression

        public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
        {
            Tristate leftState = _expressionEvaluator.EvaluateExpression(node.Left);
            Tristate rightState = _expressionEvaluator.EvaluateExpression(node.Right);

            var left = (ExpressionSyntax)node.Left.Accept(this);
            var right = (ExpressionSyntax)node.Right.Accept(this);

            if (node.Left != left)
            {
                node = node.WithLeft(left);
            }

            if (node.Right != right)
            {
                node = node.WithRight(right);
            }

            if (leftState != Tristate.Varying && rightState != Tristate.Varying)
            {
                return node;
            }

            ExpressionSyntax newExpression = null;

            if (node.Kind() == SyntaxKind.LogicalAndExpression)
            {
                if (leftState == Tristate.True)
                {
                    // true && varying == varying
                    newExpression = right;
                }
                else if (rightState == Tristate.True)
                {
                    // varying && true == varying
                    newExpression = left;
                }
            }
            else if (node.Kind() == SyntaxKind.LogicalOrExpression)
            {
                if (leftState == Tristate.False)
                {
                    // false || varying == varying
                    newExpression = right;
                }
                else if (rightState == Tristate.False)
                {
                    // varying || false == varying
                    newExpression = left;
                }
            }

            if (newExpression != null)
            {
                return newExpression
                    .WithLeadingTrivia(node.GetLeadingTrivia())
                    .WithTrailingTrivia(node.GetTrailingTrivia());
            }

            return node;
        }
開發者ID:transformersprimeabcxyz,項目名稱:_TO-DO-codeformatter-dotnet,代碼行數:61,代碼來源:PreprocessorExpressionSimplifier.cs

示例3: 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.GetLeadingTrivia方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。