当前位置: 首页>>代码示例>>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;未经允许,请勿转载。