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


C# BinaryOperatorExpression類代碼示例

本文整理匯總了C#中BinaryOperatorExpression的典型用法代碼示例。如果您正苦於以下問題:C# BinaryOperatorExpression類的具體用法?C# BinaryOperatorExpression怎麽用?C# BinaryOperatorExpression使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: VisitBinaryOperatorExpression

            public override void VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression)
            {
                base.VisitBinaryOperatorExpression (binaryOperatorExpression);

                if (binaryOperatorExpression.Operator != BinaryOperatorType.Equality &&
                    binaryOperatorExpression.Operator != BinaryOperatorType.InEquality)
                    return;

                string floatType;
                if (IsNaN(binaryOperatorExpression.Left, out floatType)) {
                    AddIsNaNIssue (binaryOperatorExpression, binaryOperatorExpression.Right, floatType);
                } else if (IsNaN (binaryOperatorExpression.Right, out floatType)) {
                    AddIsNaNIssue (binaryOperatorExpression, binaryOperatorExpression.Left, floatType);
                } else if (IsFloatingPoint(binaryOperatorExpression.Left) || IsFloatingPoint(binaryOperatorExpression.Right)) {
                    if (IsConstantInfinity(binaryOperatorExpression.Left) || IsConstantInfinity(binaryOperatorExpression.Right))
                        return;
                    AddIssue (binaryOperatorExpression, ctx.TranslateString ("Compare a difference with EPSILON"),
                        script => {
                            // Math.Abs(diff) op EPSILON
                            var builder = ctx.CreateTypeSytemAstBuilder(binaryOperatorExpression);
                            var diff = new BinaryOperatorExpression (binaryOperatorExpression.Left.Clone (),
                                BinaryOperatorType.Subtract, binaryOperatorExpression.Right.Clone ());
                            var abs = builder.ConvertType(new TopLevelTypeName("System", "Math")).Invoke("Abs", diff);
                            var op = binaryOperatorExpression.Operator == BinaryOperatorType.Equality ?
                                BinaryOperatorType.LessThan : BinaryOperatorType.GreaterThan;
                            var epsilon = new IdentifierExpression ("EPSILON");
                            var compare = new BinaryOperatorExpression (abs, op, epsilon);
                            script.Replace (binaryOperatorExpression, compare);
                            script.Link (epsilon);
                        });
                }
            }
開發者ID:artifexor,項目名稱:NRefactory,代碼行數:32,代碼來源:CompareFloatWithEqualityOperatorIssue.cs

示例2: VisitBinaryOperatorExpression

            public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
            {
                if (binaryOperatorExpression.Operator == BinaryOperatorType.ConditionalAnd)
                    UnlockWith(binaryOperatorExpression);

                return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);
            }
開發者ID:vlad2135,項目名稱:strokes,代碼行數:7,代碼來源:OperatorAndAchievement.cs

示例3: VisitBinaryOperatorExpression

		public override void VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression)
		{
			bool forceSpaces = false;
			switch (binaryOperatorExpression.Operator) {
				case BinaryOperatorType.Equality:
				case BinaryOperatorType.InEquality:
					forceSpaces = policy.SpaceAroundEqualityOperator;
					break;
				case BinaryOperatorType.GreaterThan:
				case BinaryOperatorType.GreaterThanOrEqual:
				case BinaryOperatorType.LessThan:
				case BinaryOperatorType.LessThanOrEqual:
					forceSpaces = policy.SpaceAroundRelationalOperator;
					break;
				case BinaryOperatorType.ConditionalAnd:
				case BinaryOperatorType.ConditionalOr:
					forceSpaces = policy.SpaceAroundLogicalOperator;
					break;
				case BinaryOperatorType.BitwiseAnd:
				case BinaryOperatorType.BitwiseOr:
				case BinaryOperatorType.ExclusiveOr:
					forceSpaces = policy.SpaceAroundBitwiseOperator;
					break;
				case BinaryOperatorType.Add:
				case BinaryOperatorType.Subtract:
					forceSpaces = policy.SpaceAroundAdditiveOperator;
					break;
				case BinaryOperatorType.Multiply:
				case BinaryOperatorType.Divide:
				case BinaryOperatorType.Modulus:
					forceSpaces = policy.SpaceAroundMultiplicativeOperator;
					break;
				case BinaryOperatorType.ShiftLeft:
				case BinaryOperatorType.ShiftRight:
					forceSpaces = policy.SpaceAroundShiftOperator;
					break;
				case BinaryOperatorType.NullCoalescing:
					forceSpaces = policy.SpaceAroundNullCoalescingOperator;
					break;
			}
			var opToken = binaryOperatorExpression.OperatorToken;
			if (opToken.PrevSibling != null && opToken.PrevSibling.Role != Roles.NewLine) {
				ForceSpacesBefore(opToken, forceSpaces);
			} else {
				ForceSpacesAfter(binaryOperatorExpression.Left, false);
				FixIndentation(opToken);
			}
			ForceSpacesAfter(opToken, opToken.NextSibling != null && opToken.NextSibling.Role != Roles.NewLine && forceSpaces);

			binaryOperatorExpression.Left.AcceptVisitor(this);
			// Handle line breaks in binary opeartor expression.
			if (binaryOperatorExpression.Left.EndLocation.Line != binaryOperatorExpression.Right.StartLocation.Line) {
				if (opToken.StartLocation.Line == binaryOperatorExpression.Right.StartLocation.Line) {
					FixStatementIndentation(opToken.StartLocation);
				} else {
					FixStatementIndentation(binaryOperatorExpression.Right.StartLocation);
				}
			}
			binaryOperatorExpression.Right.AcceptVisitor(this);
		}
開發者ID:Rpinski,項目名稱:SharpDevelop,代碼行數:60,代碼來源:FormattingVisitor_Expressions.cs

示例4: VisitAssignmentExpression

        public override void VisitAssignmentExpression(AssignmentExpression expression)
        {
            base.VisitAssignmentExpression (expression);

            Identifier identifier = expression.FindIdentifier();
            if (identifier == null)
                return;

            switch (expression.Operator)
            {
                case AssignmentOperatorType.BitwiseOr:
                case AssignmentOperatorType.BitwiseAnd:
                case AssignmentOperatorType.ExclusiveOr:
                case AssignmentOperatorType.Add:
                case AssignmentOperatorType.Subtract:
                case AssignmentOperatorType.Divide:
                case AssignmentOperatorType.Modulus:
                case AssignmentOperatorType.Multiply:
                case AssignmentOperatorType.ShiftLeft:
                case AssignmentOperatorType.ShiftRight:
                {
                    BinaryOperatorType op = GetComplexAssignOperator (expression.Operator);
                    Expression right = new BinaryOperatorExpression (new IdentifierExpression (identifier.Name), op, expression.Right.Clone());

                    expression.Operator = AssignmentOperatorType.Assign;
                    expression.Right = GetAssignmentExpression (identifier, right);

                    break;
                }

                case AssignmentOperatorType.Assign:
                    expression.Right = GetAssignmentExpression (identifier, expression.Right);
                    break;
            }
        }
開發者ID:ermau,項目名稱:Instant,代碼行數:35,代碼來源:InstrumentingRewriter.cs

示例5: OrIsShortcircuit

        public void OrIsShortcircuit()
        {
            IExpression trueexpr = new ConstantExpression(true);
            IExpression dividebyzero = new BinaryOperatorExpression(new ConstantExpression(1), new ConstantExpression(0), BinaryOperator.Divide);

            Assert.IsTrue((bool)(new BooleanExpression(trueexpr, dividebyzero, BooleanOperator.Or)).Evaluate(null));
        }
開發者ID:ajlopez,項目名稱:PythonSharp,代碼行數:7,代碼來源:BooleanExpressionTests.cs

示例6: AndIsShortcircuit

        public void AndIsShortcircuit()
        {
            IExpression falseexpr = new ConstantExpression(false);
            IExpression dividebyzero = new BinaryOperatorExpression(new ConstantExpression(1), new ConstantExpression(0), BinaryOperator.Divide);

            Assert.IsFalse((bool)(new BooleanExpression(falseexpr, dividebyzero, BooleanOperator.And)).Evaluate(null));
        }
開發者ID:ajlopez,項目名稱:PythonSharp,代碼行數:7,代碼來源:BooleanExpressionTests.cs

示例7: GenerateTarget

		Expression GenerateTarget(RefactoringContext context, BinaryOperatorExpression bOp)
		{
			var rr = context.Resolver.GetResolverStateBefore(bOp).LookupSimpleNameOrTypeName("Equals", emptyTypes, NameLookupMode.Expression) as MethodGroupResolveResult;
			if (rr == null || rr.IsError || HasDifferentEqualsMethod (rr.Methods)) {
				return new PrimitiveType ("object").Member("Equals");
			}
			return new IdentifierExpression("Equals");
		}
開發者ID:0xb1dd1e,項目名稱:NRefactory,代碼行數:8,代碼來源:ConvertEqualityOperatorToEqualsAction.cs

示例8: EvaluateSubtractExpression

        public void EvaluateSubtractExpression()
        {
            BinaryExpression expression = new BinaryOperatorExpression(new ConstantExpression(1), new ConstantExpression(2), BinaryOperator.Subtract);

            Assert.IsNotNull(expression);
            Assert.IsNotNull(expression.Left);
            Assert.IsNotNull(expression.Right);

            Assert.AreEqual(-1, expression.Evaluate(new BindingEnvironment()));
        }
開發者ID:ajlopez,項目名稱:PythonSharp,代碼行數:10,代碼來源:BinaryOperatorExpressionTest.cs

示例9: EvaluateMultiplyExpressionWithLeftString

        public void EvaluateMultiplyExpressionWithLeftString()
        {
            BinaryExpression expression = new BinaryOperatorExpression(new ConstantExpression("spam"), new ConstantExpression(3), BinaryOperator.Multiply);

            Assert.IsNotNull(expression);
            Assert.IsNotNull(expression.Left);
            Assert.IsNotNull(expression.Right);

            Assert.AreEqual("spamspamspam", expression.Evaluate(new BindingEnvironment()));
        }
開發者ID:ajlopez,項目名稱:PythonSharp,代碼行數:10,代碼來源:BinaryOperatorExpressionTest.cs

示例10: EvaluateDivideToFloatExpression

        public void EvaluateDivideToFloatExpression()
        {
            BinaryExpression expression = new BinaryOperatorExpression(new ConstantExpression(4), new ConstantExpression(5), BinaryOperator.Divide);

            Assert.IsNotNull(expression);
            Assert.IsNotNull(expression.Left);
            Assert.IsNotNull(expression.Right);

            Assert.AreEqual(0.8, expression.Evaluate(new BindingEnvironment()));
        }
開發者ID:ajlopez,項目名稱:PythonSharp,代碼行數:10,代碼來源:BinaryOperatorExpressionTest.cs

示例11: GetControlVariable

			static VariableInitializer GetControlVariable(VariableDeclarationStatement variableDecl, 
														  BinaryOperatorExpression condition)
			{
				var controlVariables = variableDecl.Variables.Where (
					v =>
					{
						var identifier = new IdentifierExpression (v.Name);
						return condition.Left.Match (identifier).Success ||
							condition.Right.Match (identifier).Success;
					}).ToList ();
				return controlVariables.Count == 1 ? controlVariables [0] : null;
			}
開發者ID:adisik,項目名稱:simple-assembly-explorer,代碼行數:12,代碼來源:ForControlVariableNotModifiedIssue.cs

示例12: VisitBinaryOperatorExpression

            public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
            {
                bool leftdangerous = false;
                bool rightdangerous = false;

                if (binaryOperatorExpression.Operator == BinaryOperatorType.Equality)
                {
                    if (binaryOperatorExpression.Left is PrimitiveExpression)
                    {
                        PrimitiveExpression prim = (PrimitiveExpression)binaryOperatorExpression.Left;
                        if (prim.Value.GetType() == typeof(double) ||
                            prim.Value.GetType() == typeof(float) ||
                            prim.Value.GetType() == typeof(decimal))
                        {
                            leftdangerous = true;
                        }
                    }
                    else if (binaryOperatorExpression.Left is IdentifierExpression)
                    {
                        IdentifierExpression idexpr = (IdentifierExpression)binaryOperatorExpression.Left;
                        if (doublefloatvariables.Contains(idexpr.Identifier))
                        {
                            leftdangerous = true;
                        }
                    }

                    if (binaryOperatorExpression.Right is PrimitiveExpression)
                    {
                        PrimitiveExpression prim = (PrimitiveExpression)binaryOperatorExpression.Right;
                        if (prim.Value.GetType() == typeof(double) ||
                            prim.Value.GetType() == typeof(float) ||
                            prim.Value.GetType() == typeof(decimal))
                        {
                            rightdangerous = true;
                        }
                    }
                    else if (binaryOperatorExpression.Right is IdentifierExpression)
                    {
                        IdentifierExpression idexpr = (IdentifierExpression)binaryOperatorExpression.Right;
                        if (doublefloatvariables.Contains(idexpr.Identifier))
                        {
                            rightdangerous = true;
                        }
                    }

                    if (leftdangerous || rightdangerous)
                    {
                        UnlockWith(binaryOperatorExpression);
                    }
                }
                return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);
            }
開發者ID:vlad2135,項目名稱:strokes,代碼行數:52,代碼來源:DangerousEqualityCheckAchievement.cs

示例13: AddIsNaNIssue

			void AddIsNaNIssue(BinaryOperatorExpression binaryOperatorExpr, Expression argExpr, string floatType)
			{
				if (ctx.Resolve (argExpr).Type.ReflectionName != "System.Single")
					floatType = "double";
				AddIssue (binaryOperatorExpr, string.Format(ctx.TranslateString ("Use {0}.IsNan()"), floatType),
					script => {
						Expression expr = new InvocationExpression (new MemberReferenceExpression (
							new TypeReferenceExpression (new PrimitiveType (floatType)), "IsNaN"), argExpr.Clone ());
						if (binaryOperatorExpr.Operator == BinaryOperatorType.InEquality)
							expr = new UnaryOperatorExpression (UnaryOperatorType.Not, expr);
						script.Replace (binaryOperatorExpr, expr);
					});
			}
開發者ID:Gobiner,項目名稱:ILSpy,代碼行數:13,代碼來源:CompareFloatWithEqualityOperatorIssue.cs

示例14: GetRightSide

		internal static Expression GetRightSide(BinaryOperatorExpression expression)
		{
			var parent = expression.Parent as BinaryOperatorExpression;
			if (parent != null) {
				if (parent.Left == expression) {
					var parentClone = (BinaryOperatorExpression)parent.Clone();
					parentClone.Left = expression.Right.Clone();
					return parentClone;
				}

			}
			return expression.Right.Clone();
		}
開發者ID:0xb1dd1e,項目名稱:NRefactory,代碼行數:13,代碼來源:SplitIfAction.cs

示例15: CreateAndSplit

		static CodeAction CreateAndSplit(RefactoringContext context, IfElseStatement ifStatement, BinaryOperatorExpression bOp)
		{
			return new CodeAction(
				context.TranslateString("Split if"),
				script => {
					var nestedIf = (IfElseStatement)ifStatement.Clone();
					nestedIf.Condition = GetRightSide(bOp); 
					script.Replace(ifStatement.Condition, GetLeftSide(bOp));
					script.Replace(ifStatement.TrueStatement, new BlockStatement { nestedIf });
				},
				bOp.OperatorToken
			);
		}
開發者ID:0xb1dd1e,項目名稱:NRefactory,代碼行數:13,代碼來源:SplitIfAction.cs


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