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


C# CSharpResolver.ResolveBinaryOperator方法代码示例

本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.Resolver.CSharpResolver.ResolveBinaryOperator方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpResolver.ResolveBinaryOperator方法的具体用法?C# CSharpResolver.ResolveBinaryOperator怎么用?C# CSharpResolver.ResolveBinaryOperator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.NRefactory.CSharp.Resolver.CSharpResolver的用法示例。


在下文中一共展示了CSharpResolver.ResolveBinaryOperator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EnumBitwiseOrWithMissingBaseType

		public void EnumBitwiseOrWithMissingBaseType()
		{
			var resolver = new CSharpResolver(enumWithMissingBaseType.Compilation);
			var lhs = new ConstantResolveResult(enumWithMissingBaseType, 1);
			var rhs = new ConstantResolveResult(enumWithMissingBaseType, 2);
			var rr = (ConstantResolveResult)resolver.ResolveBinaryOperator(BinaryOperatorType.BitwiseOr, lhs, rhs);
			Assert.AreEqual(enumWithMissingBaseType, rr.Type);
			Assert.AreEqual(3, rr.ConstantValue);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:9,代码来源:BinaryOperatorTests.cs

示例2: Resolve

		public override ResolveResult Resolve(CSharpResolver resolver)
		{
			ResolveResult lhs = left.Resolve(resolver);
			ResolveResult rhs = right.Resolve(resolver);
			return resolver.ResolveBinaryOperator(operatorType, lhs, rhs);
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:6,代码来源:ConstantValues.cs

示例3: VisitBinaryOperator

		Value VisitBinaryOperator(OperatorResolveResult result, BinaryOperatorType operatorType, bool checkForOverflow = false)
		{
			Debug.Assert(result.Operands.Count == 2);
			Debug.Assert(operatorType != BinaryOperatorType.ConditionalAnd && operatorType != BinaryOperatorType.ConditionalOr && operatorType != BinaryOperatorType.NullCoalescing);
			var lhs = Convert(result.Operands[0]).GetPermanentReference(evalThread);
			var rhs = Convert(result.Operands[1]).GetPermanentReference(evalThread);
			if (result.UserDefinedOperatorMethod != null)
				return InvokeMethod(null, result.UserDefinedOperatorMethod, lhs, rhs);
			var lhsRR = lhs.ToResolveResult(context);
			var rhsRR = rhs.ToResolveResult(context);
			CSharpResolver resolver = new CSharpResolver(debuggerTypeSystem).WithCheckForOverflow(checkForOverflow);
			var val = resolver.ResolveBinaryOperator(operatorType, lhsRR, rhsRR);
			if (val.IsCompileTimeConstant)
				return Convert(val);
			switch (operatorType) {
				case BinaryOperatorType.Equality:
				case BinaryOperatorType.InEquality:
					bool equality = (operatorType == BinaryOperatorType.Equality);
					if (lhsRR.Type.IsKnownType(KnownTypeCode.String) && rhsRR.Type.IsKnownType(KnownTypeCode.String)) {
						if (lhs.IsNull || rhs.IsNull) {
							bool bothNull = lhs.IsNull && rhs.IsNull;
							return Eval.CreateValue(evalThread, equality ? bothNull : !bothNull);
						} else {
							bool equal = (string)lhs.PrimitiveValue == (string)rhs.PrimitiveValue;
							return Eval.CreateValue(evalThread, equality ? equal : !equal);
						}
					}
					if (lhsRR.Type.IsReferenceType != false && rhsRR.Type.IsReferenceType != false) {
						// Reference comparison
						if (lhs.IsNull || rhs.IsNull) {
							bool bothNull = lhs.IsNull && rhs.IsNull;
							return Eval.CreateValue(evalThread, equality ? bothNull : !bothNull);
						} else {
							bool equal = lhs.Address == rhs.Address;
							return Eval.CreateValue(evalThread, equality ? equal : !equal);
						}
					}
					goto default;
				case BinaryOperatorType.Add:
					if (lhsRR.Type.IsKnownType(KnownTypeCode.String) || rhsRR.Type.IsKnownType(KnownTypeCode.String)) {
						var method = debuggerTypeSystem.FindType(KnownTypeCode.String)
							.GetMethods(m => m.Name == "Concat" && m.Parameters.Count == 2)
							.Single(m => m.Parameters.All(p => p.Type.IsKnownType(KnownTypeCode.Object)));
						return InvokeMethod(null, method, lhs, rhs);
					}
					goto default;
				default:
					throw new GetValueException("Operator {0} is not supported for {1} and {2}!", operatorType, new CSharpAmbience().ConvertType(lhsRR.Type), new CSharpAmbience().ConvertType(rhsRR.Type));
			}
		}
开发者ID:fanyjie,项目名称:SharpDevelop,代码行数:50,代码来源:ExpressionEvaluationVisitor.cs

示例4: VisitConditionalOperator

		Value VisitConditionalOperator(OperatorResolveResult result, BinaryOperatorType bitwiseOperatorType)
		{
			Debug.Assert(result.Operands.Count == 2);
			var lhs = Convert(result.Operands[0]).GetPermanentReference(evalThread);
			CSharpResolver resolver = new CSharpResolver(debuggerTypeSystem);
			Value condVal;
			if (bitwiseOperatorType == BinaryOperatorType.BitwiseAnd)
				condVal = Convert(resolver.ResolveConditionFalse(lhs.ToResolveResult(context)));
			else
				condVal = Convert(resolver.ResolveCondition(lhs.ToResolveResult(context)));
			if ((bool)condVal.PrimitiveValue)
				return lhs;
			var rhs = Convert(result.Operands[1]);
			var val = resolver.ResolveBinaryOperator(bitwiseOperatorType, lhs.ToResolveResult(context), rhs.ToResolveResult(context));
			return Convert(val);
		}
开发者ID:fanyjie,项目名称:SharpDevelop,代码行数:16,代码来源:ExpressionEvaluationVisitor.cs

示例5: VisitBinaryOperator

		Value VisitBinaryOperator(OperatorResolveResult result, BinaryOperatorType operatorType, bool checkForOverflow = false)
		{
			Debug.Assert(result.Operands.Count == 2);
			Debug.Assert(operatorType != BinaryOperatorType.ConditionalAnd && operatorType != BinaryOperatorType.ConditionalOr && operatorType != BinaryOperatorType.NullCoalescing);
			var lhs = Convert(result.Operands[0]).GetPermanentReference(evalThread);
			var rhs = Convert(result.Operands[1]).GetPermanentReference(evalThread);
			if (result.UserDefinedOperatorMethod != null)
				return InvokeMethod(null, result.UserDefinedOperatorMethod, lhs, rhs);
			var lhsRR = lhs.ToResolveResult(context);
			var rhsRR = rhs.ToResolveResult(context);
			CSharpResolver resolver = new CSharpResolver(debuggerTypeSystem).WithCheckForOverflow(checkForOverflow);
			var val = resolver.ResolveBinaryOperator(operatorType, lhsRR, rhsRR);
			if (val.IsCompileTimeConstant)
				return Convert(val);
			if (operatorType == BinaryOperatorType.Add &&
			    (lhsRR.Type.IsKnownType(KnownTypeCode.String) || rhsRR.Type.IsKnownType(KnownTypeCode.String))) {
				var method = debuggerTypeSystem.FindType(KnownTypeCode.String)
					.GetMethods(m => m.Name == "Concat" && m.Parameters.Count == 2)
					.Single(m => m.Parameters.All(p => p.Type.IsKnownType(KnownTypeCode.Object)));
				return InvokeMethod(null, method, lhs, rhs);
			}
			throw new InvalidOperationException();
		}
开发者ID:kristjan84,项目名称:SharpDevelop,代码行数:23,代码来源:ExpressionEvaluationVisitor.cs


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