当前位置: 首页>>代码示例>>C#>>正文


C# Ast.BinaryOperatorExpression类代码示例

本文整理汇总了C#中ICSharpCode.NRefactory.Ast.BinaryOperatorExpression的典型用法代码示例。如果您正苦于以下问题:C# BinaryOperatorExpression类的具体用法?C# BinaryOperatorExpression怎么用?C# BinaryOperatorExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BinaryOperatorExpression类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了BinaryOperatorExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitBinaryOperatorExpression

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

                return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);
            }
开发者ID:timdams,项目名称:strokes,代码行数:7,代码来源:OperatorOrAchievement.cs

示例2: VisitBinaryOperatorExpression

		public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
		{
			switch (binaryOperatorExpression.Op) {
				case BinaryOperatorType.NullCoalescing:
					return binaryOperatorExpression.Right.AcceptVisitor(this, data);
				case BinaryOperatorType.DivideInteger:
					return resolver.ProjectContent.SystemTypes.Int32;
				case BinaryOperatorType.Concat:
					return resolver.ProjectContent.SystemTypes.String;
				case BinaryOperatorType.Equality:
				case BinaryOperatorType.InEquality:
				case BinaryOperatorType.ReferenceEquality:
				case BinaryOperatorType.ReferenceInequality:
				case BinaryOperatorType.LogicalAnd:
				case BinaryOperatorType.LogicalOr:
				case BinaryOperatorType.LessThan:
				case BinaryOperatorType.LessThanOrEqual:
				case BinaryOperatorType.GreaterThan:
				case BinaryOperatorType.GreaterThanOrEqual:
					return resolver.ProjectContent.SystemTypes.Boolean;
				default:
					return MemberLookupHelper.GetCommonType(resolver.ProjectContent,
					                                        binaryOperatorExpression.Left.AcceptVisitor(this, data) as IReturnType,
					                                        binaryOperatorExpression.Right.AcceptVisitor(this, data) as IReturnType);
			}
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:26,代码来源:TypeVisitor.cs

示例3: GetCastExpression

        private CastExpression GetCastExpression(BinaryOperatorExpression binaryOperatorExpression)
        {
            TypeReference leftType = GetExpressionType(binaryOperatorExpression.Left);

            CastExpression castedUnsignedShift = new CastExpression(new TypeReference("u" + leftType.Type), binaryOperatorExpression, CastType.Cast);
            ParenthesizedExpression parenthesizedCastedUnsignedShift = new ParenthesizedExpression(castedUnsignedShift);
            return new CastExpression(new TypeReference(leftType.Type), parenthesizedCastedUnsignedShift, CastType.Cast);
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:8,代码来源:UnsignedShiftTransformer.cs

示例4: BuildCondition

		/// <summary>
		/// Turns "(a.b as T).d.e" into "(a != null) && (a.b is T) && ((a.b as T).d != null)"
		/// </summary>
		Expression BuildCondition(Expression targetExpr)
		{
			var parts = GetConditionParts(targetExpr);
			Expression condition = null;
			foreach (var part in parts) {
				if (condition == null) {
					// first
					condition = new ParenthesizedExpression(part);
				} else {
					condition = new BinaryOperatorExpression(new ParenthesizedExpression(part), BinaryOperatorType.LogicalAnd, condition);
				}
			}
			return condition;
		}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:17,代码来源:CheckMemberNotNull.cs

示例5: AddInteger

		/// <summary>
		/// Returns the existing expression plus the specified integer value.
		/// The old <paramref name="expr"/> object is not modified, but might be a subobject on the new expression
		/// (and thus its parent property is modified).
		/// </summary>
		public static Expression AddInteger(Expression expr, int value)
		{
			PrimitiveExpression pe = expr as PrimitiveExpression;
			if (pe != null && pe.Value is int) {
				int newVal = (int)pe.Value + value;
				return new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
			}
			BinaryOperatorExpression boe = expr as BinaryOperatorExpression;
			if (boe != null && boe.Op == BinaryOperatorType.Add) {
				// clone boe:
				boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right);
				
				boe.Right = AddInteger(boe.Right, value);
				if (boe.Right is PrimitiveExpression && ((PrimitiveExpression)boe.Right).Value is int) {
					int newVal = (int)((PrimitiveExpression)boe.Right).Value;
					if (newVal == 0) {
						return boe.Left;
					} else if (newVal < 0) {
						((PrimitiveExpression)boe.Right).Value = -newVal;
						boe.Op = BinaryOperatorType.Subtract;
					}
				}
				return boe;
			}
			if (boe != null && boe.Op == BinaryOperatorType.Subtract) {
				pe = boe.Right as PrimitiveExpression;
				if (pe != null && pe.Value is int) {
					int newVal = (int)pe.Value - value;
					if (newVal == 0)
						return boe.Left;
					
					// clone boe:
					boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right);
					
					if (newVal < 0) {
						newVal = -newVal;
						boe.Op = BinaryOperatorType.Add;
					}
					boe.Right = new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
					return boe;
				}
			}
			BinaryOperatorType opType = BinaryOperatorType.Add;
			if (value < 0) {
				value = -value;
				opType = BinaryOperatorType.Subtract;
			}
			return new BinaryOperatorExpression(expr, opType, new PrimitiveExpression(value, value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)));
		}
开发者ID:XQuantumForceX,项目名称:Reflexil,代码行数:54,代码来源:Expression.cs

示例6: VisitBinaryOperatorExpression

 public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binary, object data)
 {
     int? myPrecedence = GetPrecedence(binary);
     if (GetPrecedence(binary.Left) > myPrecedence) {
         binary.Left = Deparenthesize(binary.Left);
     }
     if (GetPrecedence(binary.Right) > myPrecedence) {
         binary.Right = Deparenthesize(binary.Right);
     }
     // Associativity
     if (GetPrecedence(binary.Left) == myPrecedence && myPrecedence.HasValue) {
         binary.Left = Deparenthesize(binary.Left);
     }
     return base.VisitBinaryOperatorExpression(binary, data);
 }
开发者ID:almazik,项目名称:ILSpy,代码行数:15,代码来源:RemoveParenthesis.cs

示例7: VisitBinaryOperatorExpression

		/// <summary>
		/// We have to replace code such as:
		///		doc.FirstName ?? ""
		/// Into 
		///		doc.FirstName != null ? doc.FirstName : ""
		/// Because we use DynamicNullObject instead of null, and that preserve the null coallasing semantics.
		/// </summary>
		public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
		{
			if(binaryOperatorExpression.Op==BinaryOperatorType.NullCoalescing)
			{
				var node = new ConditionalExpression(
					new BinaryOperatorExpression(binaryOperatorExpression.Left, BinaryOperatorType.ReferenceInequality,
					                             new PrimitiveExpression(null, null)),
					binaryOperatorExpression.Left,
					binaryOperatorExpression.Right
					);
				ReplaceCurrentNode(node);
				return null;
			}

			return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);
		}
开发者ID:nzdunic,项目名称:ravendb,代码行数:23,代码来源:TransformNullCoalasingOperatorTransformer.cs

示例8: GenerateCode

		public override void GenerateCode(List<AbstractNode> nodes, IList items)
		{
			TypeReference intReference = new TypeReference("System.Int32");
			MethodDeclaration method = new MethodDeclaration("GetHashCode", Modifiers.Public | Modifiers.Override, intReference, null, null);
			Expression expr = CallGetHashCode(new IdentifierExpression(currentClass.Fields[0].Name));
			for (int i = 1; i < currentClass.Fields.Count; i++) {
				IdentifierExpression identifier = new IdentifierExpression(currentClass.Fields[i].Name);
				expr = new BinaryOperatorExpression(expr, BinaryOperatorType.ExclusiveOr,
				                                    CallGetHashCode(identifier));
			}
			method.Body = new BlockStatement();
			method.Body.AddChild(new ReturnStatement(expr));
			nodes.Add(method);
			
			TypeReference boolReference = new TypeReference("System.Boolean");
			TypeReference objectReference = new TypeReference("System.Object");
			
			method = new MethodDeclaration("Equals", Modifiers.Public | Modifiers.Override, boolReference, null, null);
			method.Parameters.Add(new ParameterDeclarationExpression(objectReference, "obj"));
			method.Body = new BlockStatement();
			
			TypeReference currentType = ConvertType(currentClass.DefaultReturnType);
			expr = new TypeOfIsExpression(new IdentifierExpression("obj"), currentType);
			expr = new ParenthesizedExpression(expr);
			expr = new UnaryOperatorExpression(expr, UnaryOperatorType.Not);
			method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(false, "false"))));
			
			expr = new BinaryOperatorExpression(new ThisReferenceExpression(),
			                                    BinaryOperatorType.Equality,
			                                    new IdentifierExpression("obj"));
			method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(true, "true"))));
			
			VariableDeclaration var = new VariableDeclaration("my" + currentClass.Name,
			                                                  new CastExpression(currentType, new IdentifierExpression("obj"), CastType.Cast),
			                                                  currentType);
			method.Body.AddChild(new LocalVariableDeclaration(var));
			
			expr = TestEquality(var.Name, currentClass.Fields[0]);
			for (int i = 1; i < currentClass.Fields.Count; i++) {
				expr = new BinaryOperatorExpression(expr, BinaryOperatorType.LogicalAnd,
				                                    TestEquality(var.Name, currentClass.Fields[i]));
			}
			
			method.Body.AddChild(new ReturnStatement(expr));
			
			nodes.Add(method);
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:47,代码来源:EqualsCodeGenerator.cs

示例9: VisitBinaryOperatorExpression

            public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
            {
                bool leftdangerous = false;
                bool rightdangerous = false;
                if(binaryOperatorExpression.Op== BinaryOperatorType.Equality)
                {
                    if(binaryOperatorExpression.Left is PrimitiveExpression)
                    {
                        PrimitiveExpression prim = (PrimitiveExpression) binaryOperatorExpression.Left;
                        if (prim.LiteralFormat == LiteralFormat.DecimalNumber)
                            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.LiteralFormat == LiteralFormat.DecimalNumber)
                            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:timdams,项目名称:strokes,代码行数:45,代码来源:DangerousEqualityCheckAchievement.cs

示例10: VisitBinaryOperatorExpression

 // The following conversions are implemented:
 //   a == null -> a Is Nothing
 //   a != null -> a Is Not Nothing
 //   i++ / ++i as statement: convert to i += 1
 //   i-- / --i as statement: convert to i -= 1
 //   ForStatement -> ForNextStatement when for-loop is simple
 //   if (Event != null) Event(this, bla); -> RaiseEvent Event(this, bla)
 //   Casts to value types are marked as conversions
 public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
 {
     if (binaryOperatorExpression.Op == BinaryOperatorType.Equality || binaryOperatorExpression.Op == BinaryOperatorType.InEquality) {
         if (IsNullLiteralExpression(binaryOperatorExpression.Left)) {
             Expression tmp = binaryOperatorExpression.Left;
             binaryOperatorExpression.Left = binaryOperatorExpression.Right;
             binaryOperatorExpression.Right = tmp;
         }
         if (IsNullLiteralExpression(binaryOperatorExpression.Right)) {
             if (binaryOperatorExpression.Op == BinaryOperatorType.Equality) {
                 binaryOperatorExpression.Op = BinaryOperatorType.ReferenceEquality;
             } else {
                 binaryOperatorExpression.Op = BinaryOperatorType.ReferenceInequality;
             }
         }
     }
     return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);
 }
开发者ID:pusp,项目名称:o2platform,代码行数:26,代码来源:CSharpConstructsConvertVisitor.cs

示例11: VisitBinaryOperatorExpression

 public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
 {
     base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);
     if (IsEmptyStringLiteral(binaryOperatorExpression.Right)) {
         if (binaryOperatorExpression.Op == BinaryOperatorType.Equality) {
             ReplaceCurrentNode(CallStringIsNullOrEmpty(binaryOperatorExpression.Left));
         } else if (binaryOperatorExpression.Op == BinaryOperatorType.InEquality) {
             ReplaceCurrentNode(new UnaryOperatorExpression(CallStringIsNullOrEmpty(binaryOperatorExpression.Left),
                                                            UnaryOperatorType.Not));
         }
     } else if (IsEmptyStringLiteral(binaryOperatorExpression.Left)) {
         if (binaryOperatorExpression.Op == BinaryOperatorType.Equality) {
             ReplaceCurrentNode(CallStringIsNullOrEmpty(binaryOperatorExpression.Right));
         } else if (binaryOperatorExpression.Op == BinaryOperatorType.InEquality) {
             ReplaceCurrentNode(new UnaryOperatorExpression(CallStringIsNullOrEmpty(binaryOperatorExpression.Right),
                                                            UnaryOperatorType.Not));
         }
     }
     return null;
 }
开发者ID:SergeTruth,项目名称:OxyChart,代码行数:20,代码来源:VBNetConstructsConvertVisitor.cs

示例12: TrackedVisitBinaryOperatorExpression

 public override object TrackedVisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
 {
     Expression left = binaryOperatorExpression.Left;
     TypeReference leftType = GetExpressionType(left);
     if (leftType != null && (leftType.RankSpecifier == null || leftType.RankSpecifier.Length == 0) && (binaryOperatorExpression.Right is PrimitiveExpression))
     {
         string fullName = GetFullName(leftType);
         if (types.Contains(fullName))
         {
             Expression minValue = (Expression) values[fullName];
             PrimitiveExpression nullRight = (PrimitiveExpression) binaryOperatorExpression.Right;
             if (nullRight.Value == null)
             {
                 BinaryOperatorExpression replacedBinOP = binaryOperatorExpression;
                 replacedBinOP.Right = minValue;
                 ReplaceCurrentNode(replacedBinOP);
             }
         }
     }
     return base.TrackedVisitBinaryOperatorExpression(binaryOperatorExpression, data);
 }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:21,代码来源:NullableValueTypeTransformer.cs

示例13: VisitBinaryOperatorExpression

        public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
        {
            base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);

            if (resolver.CompilationUnit == null)
                return null;

            switch (binaryOperatorExpression.Op) {
                case BinaryOperatorType.Equality:
                case BinaryOperatorType.InEquality:
                    ConvertEqualityToReferenceEqualityIfRequired(binaryOperatorExpression);
                    break;
                case BinaryOperatorType.Add:
                    ConvertArgumentsForStringConcatenationIfRequired(binaryOperatorExpression);
                    break;
                case BinaryOperatorType.Divide:
                    ConvertDivisionToIntegerDivisionIfRequired(binaryOperatorExpression);
                    break;
            }
            return null;
        }
开发者ID:SergeTruth,项目名称:OxyChart,代码行数:21,代码来源:CSharpToVBNetConvertVisitor.cs

示例14: TrackedVisitBinaryOperatorExpression

        public override object TrackedVisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
        {
            if (binaryOperatorExpression.Op == BinaryOperatorType.UnsignedShiftRight)
            {
                binaryOperatorExpression.Op = BinaryOperatorType.ShiftRight;
                CastExpression castExpression = GetCastExpression(binaryOperatorExpression);
                ReplaceCurrentNode(castExpression);
            }
            else if (binaryOperatorExpression.Op == BinaryOperatorType.UnsignedShiftRightAssign)
            {
                Expression left = binaryOperatorExpression.Left;
                Expression right = new BinaryOperatorExpression(left, BinaryOperatorType.ShiftRight, binaryOperatorExpression.Right);
                right.Parent = binaryOperatorExpression.Parent;
                CastExpression castExpression = GetCastExpression((BinaryOperatorExpression) right);
                right.Parent = castExpression;
                AssignmentExpression assignment = new AssignmentExpression(left, AssignmentOperatorType.Assign, castExpression);
                assignment.Parent = binaryOperatorExpression.Parent;

                ReplaceCurrentNode(assignment);
            }
            return base.TrackedVisitBinaryOperatorExpression(binaryOperatorExpression, data);
        }
开发者ID:sourcewarehouse,项目名称:janett,代码行数:22,代码来源:UnsignedShiftTransformer.cs

示例15: VisitBinaryOperatorExpression

 public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
 {
     bool lhs = binaryOperatorExpression.Left.AcceptVisitor(this, data) == SymbolDefined;
     bool rhs = binaryOperatorExpression.Right.AcceptVisitor(this, data) == SymbolDefined;
     bool result;
     switch (binaryOperatorExpression.Op) {
         case BinaryOperatorType.LogicalAnd:
             result = lhs && rhs;
             break;
         case BinaryOperatorType.LogicalOr:
             result = lhs || rhs;
             break;
         case BinaryOperatorType.Equality:
             result = lhs == rhs;
             break;
         case BinaryOperatorType.InEquality:
             result = lhs != rhs;
             break;
         default:
             return null;
     }
     return result ? SymbolDefined : null;
 }
开发者ID:pusp,项目名称:o2platform,代码行数:23,代码来源:ConditionalCompilation.cs


注:本文中的ICSharpCode.NRefactory.Ast.BinaryOperatorExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。