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


C# BinaryExpressionSyntax.CSharpKind方法代碼示例

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


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

示例1: InferTypeInBinaryExpression

            private IEnumerable<ITypeSymbol> InferTypeInBinaryExpression(BinaryExpressionSyntax binop, ExpressionSyntax expressionOpt = null, SyntaxToken? previousToken = null)
            {
                // If we got here through a token, then it must have actually been the binary
                // operator's token.
                Contract.ThrowIfTrue(previousToken.HasValue && previousToken.Value != binop.OperatorToken);

                if (binop.CSharpKind() == SyntaxKind.CoalesceExpression)
                {
                    return InferTypeInCoalesceExpression(binop, expressionOpt, previousToken);
                }

                var onRightOfToken = binop.Right == expressionOpt || previousToken.HasValue;
                switch (binop.OperatorToken.CSharpKind())
                {
                    case SyntaxKind.LessThanLessThanToken:
                    case SyntaxKind.GreaterThanGreaterThanToken:
                    case SyntaxKind.LessThanLessThanEqualsToken:
                    case SyntaxKind.GreaterThanGreaterThanEqualsToken:

                        if (onRightOfToken)
                        {
                            // x << Foo(), x >> Foo(), x <<= Foo(), x >>= Foo()
                            return SpecializedCollections.SingletonEnumerable(this.Compilation.GetSpecialType(SpecialType.System_Int32));
                        }

                        break;
                }

                // Infer operands of && and || as bool regardless of the other operand.
                if (binop.OperatorToken.CSharpKind() == SyntaxKind.AmpersandAmpersandToken ||
                    binop.OperatorToken.CSharpKind() == SyntaxKind.BarBarToken)
                {
                    return SpecializedCollections.SingletonEnumerable(this.Compilation.GetSpecialType(SpecialType.System_Boolean));
                }

                // Try to figure out what's on the other side of the binop.  If we can, then just that
                // type.  This is often a reasonable heuristics to use for most operators.  NOTE(cyrusn):
                // we could try to bind the token to see what overloaded operators it corresponds to.
                // But the gain is pretty marginal IMO.
                var otherSide = onRightOfToken ? binop.Left : binop.Right;

                var otherSideTypes = GetTypes(otherSide);
                if (otherSideTypes.Any())
                {
                    return otherSideTypes;
                }

                // For &, &=, |, |=, ^, and ^=, since we couldn't infer the type of either side, 
                // try to infer the type of the entire binary expression.
                if (binop.OperatorToken.CSharpKind() == SyntaxKind.AmpersandToken ||
                    binop.OperatorToken.CSharpKind() == SyntaxKind.AmpersandEqualsToken ||
                    binop.OperatorToken.CSharpKind() == SyntaxKind.BarToken ||
                    binop.OperatorToken.CSharpKind() == SyntaxKind.BarEqualsToken ||
                    binop.OperatorToken.CSharpKind() == SyntaxKind.CaretToken ||
                    binop.OperatorToken.CSharpKind() == SyntaxKind.CaretEqualsToken)
                {
                    var parentTypes = InferTypes(binop);
                    if (parentTypes.Any())
                    {
                        return parentTypes;
                    }
                }

                // If it's a plus operator, then do some smarts in case it might be a string or
                // delegate.
                if (binop.OperatorToken.CSharpKind() == SyntaxKind.PlusToken)
                {
                    // See Bug 6045.  Note: we've already checked the other side of the operator.  So this
                    // is the case where the other side was also unknown.  So we walk one higher and if
                    // we get a delegate or a string type, then use that type here.
                    var parentTypes = InferTypes(binop);
                    if (parentTypes.Any(parentType => parentType.SpecialType == SpecialType.System_String || parentType.TypeKind == TypeKind.Delegate))
                    {
                        return parentTypes.Where(parentType => parentType.SpecialType == SpecialType.System_String || parentType.TypeKind == TypeKind.Delegate);
                    }
                }

                // Otherwise pick some sane defaults for certain common cases.
                switch (binop.OperatorToken.CSharpKind())
                {
                    case SyntaxKind.BarToken:
                    case SyntaxKind.CaretToken:
                    case SyntaxKind.AmpersandToken:
                    case SyntaxKind.LessThanToken:
                    case SyntaxKind.LessThanEqualsToken:
                    case SyntaxKind.GreaterThanToken:
                    case SyntaxKind.GreaterThanEqualsToken:
                    case SyntaxKind.PlusToken:
                    case SyntaxKind.MinusToken:
                    case SyntaxKind.AsteriskToken:
                    case SyntaxKind.SlashToken:
                    case SyntaxKind.PercentToken:
                    case SyntaxKind.CaretEqualsToken:
                    case SyntaxKind.PlusEqualsToken:
                    case SyntaxKind.MinusEqualsToken:
                    case SyntaxKind.AsteriskEqualsToken:
                    case SyntaxKind.SlashEqualsToken:
                    case SyntaxKind.PercentEqualsToken:
                    case SyntaxKind.LessThanLessThanToken:
                    case SyntaxKind.GreaterThanGreaterThanToken:
//.........這裏部分代碼省略.........
開發者ID:jerriclynsjohn,項目名稱:roslyn,代碼行數:101,代碼來源:CSharpTypeInferenceService.TypeInferrer.cs

示例2: VisitBinaryExpression

            public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
            {
                bool isOrAsNode = node.CSharpKind() == SyntaxKind.AsExpression || node.CSharpKind() == SyntaxKind.IsExpression;

                var result = (ExpressionSyntax)base.VisitBinaryExpression(node);

                if (result != node && isOrAsNode)
                {
                    // In order to handle cases in which simplifying a name would result in code
                    // that parses different, we pre-emptively add parentheses that will be
                    // simplified away later.
                    //
                    // For example, this code...
                    //
                    //     var x = y as Nullable<int> + 1;
                    //
                    // ...should simplify as...
                    //
                    //     var x = (y as int?) + 1;
                    return result.Parenthesize().WithAdditionalAnnotations(Formatter.Annotation);
                }

                return result;
            }
開發者ID:EkardNT,項目名稱:Roslyn,代碼行數:24,代碼來源:CSharpNameReducer.Rewriter.cs

示例3: ResolveAssignmentExpression

        public FlatOperand ResolveAssignmentExpression(BinaryExpressionSyntax node, TypeInfo result_type, FlatOperand into_lvalue, FlatOperand parent_op, List<FlatStatement> instructions)
        {
            FlatOperand fop_result;
            FlatOperand lvalue_result;
            FlatOperand fop_subject;
            FlatOperand fop_type;

            if (node.Left is ElementAccessExpressionSyntax)
            {
                ElementAccessExpressionSyntax eaes = (ElementAccessExpressionSyntax)node.Left;

                fop_subject = ResolveExpression(eaes.Expression, null, instructions);

                FlatOperand fop_right = ResolveExpression(node.Right, into_lvalue, instructions);

                List<FlatOperand> args = ResolveArguments(eaes.ArgumentList, instructions);
                FlatOperand key = ArrayIndexFrom(args, instructions);

                instructions.Add(FlatStatement.ARRAYSET(fop_subject, key, fop_right));
                return fop_right;
            }

            SymbolInfo si = Model.GetSymbolInfo(node.Left);
            switch (si.Symbol.Kind)
            {
                case SymbolKind.Event:
                    {
                        fop_subject = ResolveParentExpression(si, node.Left, null, parent_op, instructions);
                        fop_type = Resolve(si.Symbol.ContainingType, null, instructions);
                            //TypeOf(fop_subject, null, null, instructions);

                        FlatOperand fop_Field;
                       // ITypeSymbol typeSymbol;
                        IEventSymbol ps = (IEventSymbol)si.Symbol;
                        {
                            /*
                            if (ps.IsStatic)
                            {
                                fop_Field = Resolve(ps, fop_type, null, instructions);
                            }
                            else/**/
                            {
                                //typeSymbol = ps.Type;
                                fop_Field = Resolve(ps, fop_type, null, instructions);
                            }
                        }

                        FlatOperand fop_right = ResolveExpression(node.Right, into_lvalue, instructions);

                        if (node.CSharpKind() == SyntaxKind.SimpleAssignmentExpression)
                        {
                            fop_result = fop_right;
                        }
                        else
                        {
                            fop_result = AllocateRegister("");
                            lvalue_result = fop_result.GetLValue(this, instructions);
                            if (ps.IsStatic)
                            {
                                instructions.Add(FlatStatement.GETSTATICFIELD(lvalue_result, fop_Field));
                            }
                            else
                            {
                                instructions.Add(FlatStatement.GETFIELD(lvalue_result, fop_Field, fop_subject));
                            }
                            ResolveBinaryExpression(node.CSharpKind(), fop_result, fop_right, lvalue_result, instructions);
                        }

                        if (ps.IsStatic)
                        {
                            instructions.Add(FlatStatement.SETSTATICFIELD(fop_Field, fop_result));
                        }
                        else
                        {
                            instructions.Add(FlatStatement.SETFIELD(fop_Field, fop_subject, fop_result));
                        }
                        return fop_result;
                    }
                    break;
                case SymbolKind.Field:
                    {
                        fop_subject = ResolveParentExpression(si, node.Left, null, parent_op, instructions);
                        fop_type = Resolve(si.Symbol.ContainingType, null, instructions);
                            //TypeOf(fop_subject, null, null, instructions);

                        FlatOperand fop_Field;
                       // ITypeSymbol typeSymbol;
                        IFieldSymbol ps = (IFieldSymbol)si.Symbol;
                        {
                            /*
                            if (ps.IsStatic)
                            {
                                fop_Field = Resolve(ps, fop_type, null, instructions);
                            }
                            else/**/
                            {
                                //typeSymbol = ps.Type;
                                fop_Field = Resolve(ps, fop_type, null, instructions);
                            }
                        }
//.........這裏部分代碼省略.........
開發者ID:LaxLacks,項目名稱:ls2csc,代碼行數:101,代碼來源:Function.cs

示例4: ResolveExpression

        public FlatOperand ResolveExpression(BinaryExpressionSyntax node, TypeInfo result_type, FlatOperand into_lvalue, FlatOperand parent_op, List<FlatStatement> instructions)
        {
            if (node.IsAssignment())
            {
                return ResolveAssignmentExpression(node, result_type, into_lvalue, parent_op, instructions);
            }

            FlatOperand left = ResolveExpression(node.Left, null, instructions);
            FlatOperand right = ResolveExpression(node.Right, null, instructions);
            return ResolveBinaryExpression(node.CSharpKind(), left, right, into_lvalue, instructions);
        }
開發者ID:LaxLacks,項目名稱:ls2csc,代碼行數:11,代碼來源:Function.cs

示例5: VisitBinaryExpression

            public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
            {
                cancellationToken.ThrowIfCancellationRequested();

                // Special case: We parenthesize to avoid a situation where inlining an
                // expression can cause code to parse differently. The canonical case is...
                //
                //     var x = 0;
                //     var y = (1 + 2);
                //     var z = new[] { x < x, x > y };
                //
                // Inlining 'y' in the code above will produce code that parses differently
                // (i.e. as a generic method invocation).
                //
                //      var z = new[] { x < x, x > (1 + 2) };

                var result = (BinaryExpressionSyntax)base.VisitBinaryExpression(node);

                if ((node.CSharpKind() == SyntaxKind.GreaterThanExpression || node.CSharpKind() == SyntaxKind.RightShiftExpression) && !node.IsParentKind(SyntaxKind.ParenthesizedExpression))
                {
                    return result.Parenthesize();
                }

                return result;
            }
開發者ID:modulexcite,項目名稱:pattern-matching-csharp,代碼行數:25,代碼來源:CSharpSimplificationService.Expander.cs


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