本文整理汇总了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);
}
示例2: Resolve
public override ResolveResult Resolve(CSharpResolver resolver)
{
ResolveResult lhs = left.Resolve(resolver);
ResolveResult rhs = right.Resolve(resolver);
return resolver.ResolveBinaryOperator(operatorType, lhs, rhs);
}
示例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));
}
}
示例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);
}
示例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();
}