本文整理汇总了C#中CodeBinaryOperatorType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# CodeBinaryOperatorType.ToString方法的具体用法?C# CodeBinaryOperatorType.ToString怎么用?C# CodeBinaryOperatorType.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeBinaryOperatorType
的用法示例。
在下文中一共展示了CodeBinaryOperatorType.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapOperatorToMethod
[SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")] // bogus since the casts are in different case statements
internal static MethodInfo MapOperatorToMethod(
CodeBinaryOperatorType op,
Type lhs,
CodeExpression lhsExpression,
Type rhs,
CodeExpression rhsExpression,
RuleValidation validator,
out ValidationError error)
{
// determine what the method name should be
string methodName;
string message;
OperatorGrouping group;
switch (op)
{
case CodeBinaryOperatorType.ValueEquality:
methodName = "op_Equality";
group = OperatorGrouping.Equality;
break;
case CodeBinaryOperatorType.GreaterThan:
methodName = "op_GreaterThan";
group = OperatorGrouping.Relational;
break;
case CodeBinaryOperatorType.GreaterThanOrEqual:
methodName = "op_GreaterThanOrEqual";
group = OperatorGrouping.Relational;
break;
case CodeBinaryOperatorType.LessThan:
methodName = "op_LessThan";
group = OperatorGrouping.Relational;
break;
case CodeBinaryOperatorType.LessThanOrEqual:
methodName = "op_LessThanOrEqual";
group = OperatorGrouping.Relational;
break;
case CodeBinaryOperatorType.Add:
methodName = "op_Addition";
group = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.Subtract:
methodName = "op_Subtraction";
group = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.Multiply:
methodName = "op_Multiply";
group = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.Divide:
methodName = "op_Division";
group = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.Modulus:
methodName = "op_Modulus";
group = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.BitwiseAnd:
methodName = "op_BitwiseAnd";
group = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.BitwiseOr:
methodName = "op_BitwiseOr";
group = OperatorGrouping.Arithmetic;
break;
default:
Debug.Assert(false, "Operator " + op.ToString() + " not implemented");
message = string.Format(CultureInfo.CurrentCulture, Messages.BinaryOpNotSupported, op.ToString());
error = new ValidationError(message, ErrorNumbers.Error_CodeExpressionNotHandled);
return null;
}
// NOTE: types maybe NullLiteral, which signifies the constant "null"
List<MethodInfo> candidates = new List<MethodInfo>();
bool lhsNullable = ConditionHelper.IsNullableValueType(lhs);
bool rhsNullable = ConditionHelper.IsNullableValueType(rhs);
Type lhsType0 = (lhsNullable) ? Nullable.GetUnderlyingType(lhs) : lhs;
Type rhsType0 = (rhsNullable) ? Nullable.GetUnderlyingType(rhs) : rhs;
// special cases for enums
if (lhsType0.IsEnum)
{
// only 3 cases (U = underlying type of E):
// E = E + U
// U = E - E
// E = E - U
// plus the standard comparisons (E == E, E > E, etc.)
// need to also allow E == 0
Type underlyingType;
switch (op)
{
case CodeBinaryOperatorType.Add:
underlyingType = EnumHelper.GetUnderlyingType(lhsType0);
if ((underlyingType != null) &&
(RuleValidation.TypesAreAssignable(rhsType0, underlyingType, rhsExpression, out error)))
{
error = null;
return new EnumOperationMethodInfo(lhs, op, rhs, false);
}
break;
//.........这里部分代码省略.........
示例2: EvaluateBinaryOperation
//.........这里部分代码省略.........
case CodeBinaryOperatorType.ValueEquality:
literal = Literal.MakeLiteral(lhsType, lhsValue);
if (literal == null)
{
break;
}
literal2 = Literal.MakeLiteral(rhsType, rhsValue);
if (literal2 == null)
{
break;
}
return literal.Equal(literal2);
case CodeBinaryOperatorType.BitwiseOr:
literal3 = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue);
if (literal3 == null)
{
break;
}
literal4 = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue);
if (literal4 == null)
{
break;
}
return literal3.BitOr(literal4);
case CodeBinaryOperatorType.BitwiseAnd:
literal3 = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue);
if (literal3 == null)
{
break;
}
literal4 = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue);
if (literal4 == null)
{
break;
}
return literal3.BitAnd(literal4);
case CodeBinaryOperatorType.LessThan:
literal = Literal.MakeLiteral(lhsType, lhsValue);
if (literal == null)
{
break;
}
literal2 = Literal.MakeLiteral(rhsType, rhsValue);
if (literal2 == null)
{
break;
}
return literal.LessThan(literal2);
case CodeBinaryOperatorType.LessThanOrEqual:
literal = Literal.MakeLiteral(lhsType, lhsValue);
if (literal == null)
{
break;
}
literal2 = Literal.MakeLiteral(rhsType, rhsValue);
if (literal2 == null)
{
break;
}
return literal.LessThanOrEqual(literal2);
case CodeBinaryOperatorType.GreaterThan:
literal = Literal.MakeLiteral(lhsType, lhsValue);
if (literal == null)
{
break;
}
literal2 = Literal.MakeLiteral(rhsType, rhsValue);
if (literal2 == null)
{
break;
}
return literal.GreaterThan(literal2);
case CodeBinaryOperatorType.GreaterThanOrEqual:
literal = Literal.MakeLiteral(lhsType, lhsValue);
if (literal == null)
{
break;
}
literal2 = Literal.MakeLiteral(rhsType, rhsValue);
if (literal2 == null)
{
break;
}
return literal.GreaterThanOrEqual(literal2);
default:
exception = new RuleEvaluationException(string.Format(CultureInfo.CurrentCulture, Messages.BinaryOpNotSupported, new object[] { operation.ToString() }));
exception.Data["ErrorObject"] = binaryExpr;
throw exception;
}
exception = new RuleEvaluationException(string.Format(CultureInfo.CurrentCulture, Messages.BinaryOpFails, new object[] { operation.ToString(), RuleDecompiler.DecompileType(lhsType), RuleDecompiler.DecompileType(rhsType) }));
exception.Data["ErrorObject"] = binaryExpr;
throw exception;
}
示例3: AllowedComparison
internal static RuleBinaryExpressionInfo AllowedComparison(
Type lhs,
CodeExpression lhsExpression,
Type rhs,
CodeExpression rhsExpression,
CodeBinaryOperatorType comparison,
RuleValidation validator,
out ValidationError error)
{
// note that null values come in as a NullLiteral type
TypeFlags lhsFlags, rhsFlags;
// are the types supported?
if ((supportedTypes.TryGetValue(lhs, out lhsFlags)) && (supportedTypes.TryGetValue(rhs, out rhsFlags)))
{
// both sides supported
if (lhsFlags == rhsFlags)
{
// both sides the same type, so it's allowed
// only allow equality on booleans
if ((lhsFlags == TypeFlags.Bool) && (comparison != CodeBinaryOperatorType.ValueEquality))
{
string message = string.Format(CultureInfo.CurrentCulture, Messages.RelationalOpBadTypes, comparison.ToString(),
RuleDecompiler.DecompileType(lhs),
RuleDecompiler.DecompileType(rhs));
error = new ValidationError(message, ErrorNumbers.Error_OperandTypesIncompatible);
return null;
}
error = null;
return new RuleBinaryExpressionInfo(lhs, rhs, typeof(bool));
}
// if not the same, only certain combinations allowed
switch (lhsFlags | rhsFlags)
{
case TypeFlags.Decimal | TypeFlags.SignedNumbers:
case TypeFlags.Decimal | TypeFlags.UnsignedNumbers:
case TypeFlags.Decimal | TypeFlags.ULong:
case TypeFlags.Float | TypeFlags.SignedNumbers:
case TypeFlags.Float | TypeFlags.UnsignedNumbers:
case TypeFlags.Float | TypeFlags.ULong:
case TypeFlags.ULong | TypeFlags.UnsignedNumbers:
case TypeFlags.SignedNumbers | TypeFlags.UnsignedNumbers:
error = null;
return new RuleBinaryExpressionInfo(lhs, rhs, typeof(bool));
}
string message2 = string.Format(CultureInfo.CurrentCulture, Messages.RelationalOpBadTypes, comparison.ToString(),
(lhs == typeof(NullLiteral)) ? Messages.NullValue : RuleDecompiler.DecompileType(lhs),
(rhs == typeof(NullLiteral)) ? Messages.NullValue : RuleDecompiler.DecompileType(rhs));
error = new ValidationError(message2, ErrorNumbers.Error_OperandTypesIncompatible);
return null;
}
else
{
// see if they override the operator
MethodInfo operatorOverride = MapOperatorToMethod(comparison, lhs, lhsExpression, rhs, rhsExpression, validator, out error);
if (operatorOverride != null)
return new RuleBinaryExpressionInfo(lhs, rhs, operatorOverride);
// unable to evaluate, so return false
return null;
}
}
示例4: Translate
private NodeType Translate(CodeBinaryOperatorType oper){
switch(oper){
case CodeBinaryOperatorType.Add : return NodeType.Add;
case CodeBinaryOperatorType.BitwiseAnd : return NodeType.And;
case CodeBinaryOperatorType.BitwiseOr : return NodeType.Or;
case CodeBinaryOperatorType.BooleanAnd : return NodeType.LogicalAnd;
case CodeBinaryOperatorType.BooleanOr : return NodeType.LogicalOr;
case CodeBinaryOperatorType.Divide : return NodeType.Div;
case CodeBinaryOperatorType.GreaterThan : return NodeType.Gt;
case CodeBinaryOperatorType.GreaterThanOrEqual : return NodeType.Ge;
case CodeBinaryOperatorType.IdentityEquality: return NodeType.Eq;
case CodeBinaryOperatorType.IdentityInequality: return NodeType.Ne;
case CodeBinaryOperatorType.LessThan : return NodeType.Lt;
case CodeBinaryOperatorType.LessThanOrEqual : return NodeType.Le;
case CodeBinaryOperatorType.Modulus : return NodeType.Rem;
case CodeBinaryOperatorType.Multiply : return NodeType.Mul;
case CodeBinaryOperatorType.Subtract : return NodeType.Sub;
case CodeBinaryOperatorType.ValueEquality : return NodeType.Eq;
}
Debug.Assert(false);
this.HandleError(Error.DidNotExpect, "CodeBinaryOperatorType value == "+oper.ToString());
return NodeType.Nop;
}
示例5: ResultType
internal static RuleBinaryExpressionInfo ResultType(
CodeBinaryOperatorType operation,
Type lhs,
CodeExpression lhsExpression,
Type rhs,
CodeExpression rhsExpression,
RuleValidation validator,
out ValidationError error)
{
// do we support the types natively?
TypeFlags lhsType, rhsType;
if (supportedTypes.TryGetValue(lhs, out lhsType) && supportedTypes.TryGetValue(rhs, out rhsType))
{
Type resultType = ResultType(operation, lhsType, rhsType);
if (resultType != null)
{
error = null;
return new RuleBinaryExpressionInfo(lhs, rhs, resultType);
}
else
{
string message = string.Format(CultureInfo.CurrentCulture, Messages.ArithOpBadTypes, operation.ToString(),
(lhs == typeof(NullLiteral)) ? Messages.NullValue : RuleDecompiler.DecompileType(lhs),
(rhs == typeof(NullLiteral)) ? Messages.NullValue : RuleDecompiler.DecompileType(rhs));
error = new ValidationError(message, ErrorNumbers.Error_OperandTypesIncompatible);
return null;
}
}
else
{
// not natively supported, see if user overrides operator
MethodInfo opOverload = Literal.MapOperatorToMethod(operation, lhs, lhsExpression, rhs, rhsExpression, validator, out error);
if (opOverload != null)
return new RuleBinaryExpressionInfo(lhs, rhs, opOverload);
else
return null;
}
}
示例6: AllowedComparison
internal static RuleBinaryExpressionInfo AllowedComparison(Type lhs, CodeExpression lhsExpression, Type rhs, CodeExpression rhsExpression, CodeBinaryOperatorType comparison, RuleValidation validator, out ValidationError error)
{
TypeFlags flags;
TypeFlags flags2;
if (!supportedTypes.TryGetValue(lhs, out flags) || !supportedTypes.TryGetValue(rhs, out flags2))
{
MethodInfo mi = MapOperatorToMethod(comparison, lhs, lhsExpression, rhs, rhsExpression, validator, out error);
if (mi != null)
{
return new RuleBinaryExpressionInfo(lhs, rhs, mi);
}
return null;
}
if (flags == flags2)
{
if ((flags == TypeFlags.Bool) && (comparison != CodeBinaryOperatorType.ValueEquality))
{
string str = string.Format(CultureInfo.CurrentCulture, Messages.RelationalOpBadTypes, new object[] { comparison.ToString(), RuleDecompiler.DecompileType(lhs), RuleDecompiler.DecompileType(rhs) });
error = new ValidationError(str, 0x545);
return null;
}
error = null;
return new RuleBinaryExpressionInfo(lhs, rhs, typeof(bool));
}
switch ((flags | flags2))
{
case (TypeFlags.ULong | TypeFlags.UnsignedNumbers):
case (TypeFlags.Float | TypeFlags.SignedNumbers):
case (TypeFlags.Float | TypeFlags.UnsignedNumbers):
case (TypeFlags.Float | TypeFlags.ULong):
case (TypeFlags.UnsignedNumbers | TypeFlags.SignedNumbers):
case (TypeFlags.Decimal | TypeFlags.SignedNumbers):
case (TypeFlags.Decimal | TypeFlags.UnsignedNumbers):
case (TypeFlags.Decimal | TypeFlags.ULong):
error = null;
return new RuleBinaryExpressionInfo(lhs, rhs, typeof(bool));
}
string errorText = string.Format(CultureInfo.CurrentCulture, Messages.RelationalOpBadTypes, new object[] { comparison.ToString(), (lhs == typeof(NullLiteral)) ? Messages.NullValue : RuleDecompiler.DecompileType(lhs), (rhs == typeof(NullLiteral)) ? Messages.NullValue : RuleDecompiler.DecompileType(rhs) });
error = new ValidationError(errorText, 0x545);
return null;
}
示例7: MapOperatorToMethod
internal static MethodInfo MapOperatorToMethod(CodeBinaryOperatorType op, Type lhs, CodeExpression lhsExpression, Type rhs, CodeExpression rhsExpression, RuleValidation validator, out ValidationError error)
{
string str;
string str2;
OperatorGrouping arithmetic;
switch (op)
{
case CodeBinaryOperatorType.Add:
str = "op_Addition";
arithmetic = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.Subtract:
str = "op_Subtraction";
arithmetic = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.Multiply:
str = "op_Multiply";
arithmetic = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.Divide:
str = "op_Division";
arithmetic = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.Modulus:
str = "op_Modulus";
arithmetic = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.ValueEquality:
str = "op_Equality";
arithmetic = OperatorGrouping.Equality;
break;
case CodeBinaryOperatorType.BitwiseOr:
str = "op_BitwiseOr";
arithmetic = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.BitwiseAnd:
str = "op_BitwiseAnd";
arithmetic = OperatorGrouping.Arithmetic;
break;
case CodeBinaryOperatorType.LessThan:
str = "op_LessThan";
arithmetic = OperatorGrouping.Relational;
break;
case CodeBinaryOperatorType.LessThanOrEqual:
str = "op_LessThanOrEqual";
arithmetic = OperatorGrouping.Relational;
break;
case CodeBinaryOperatorType.GreaterThan:
str = "op_GreaterThan";
arithmetic = OperatorGrouping.Relational;
break;
case CodeBinaryOperatorType.GreaterThanOrEqual:
str = "op_GreaterThanOrEqual";
arithmetic = OperatorGrouping.Relational;
break;
default:
str2 = string.Format(CultureInfo.CurrentCulture, Messages.BinaryOpNotSupported, new object[] { op.ToString() });
error = new ValidationError(str2, 0x548);
return null;
}
List<MethodInfo> candidates = new List<MethodInfo>();
bool flag = ConditionHelper.IsNullableValueType(lhs);
bool flag2 = ConditionHelper.IsNullableValueType(rhs);
Type rhsType = flag ? Nullable.GetUnderlyingType(lhs) : lhs;
Type type = flag2 ? Nullable.GetUnderlyingType(rhs) : rhs;
if (!rhsType.IsEnum)
{
if (type.IsEnum)
{
Type underlyingType;
switch (op)
{
case CodeBinaryOperatorType.Add:
underlyingType = EnumHelper.GetUnderlyingType(type);
if ((underlyingType == null) || !RuleValidation.TypesAreAssignable(rhsType, underlyingType, lhsExpression, out error))
{
break;
}
error = null;
return new EnumOperationMethodInfo(lhs, op, rhs, false);
case CodeBinaryOperatorType.Subtract:
{
underlyingType = EnumHelper.GetUnderlyingType(type);
if (underlyingType == null)
{
break;
}
//.........这里部分代码省略.........
示例8: EvaluateBinaryOperation
//.........这里部分代码省略.........
break;
return leftArithmetic.Multiply(rightArithmetic);
case CodeBinaryOperatorType.Divide:
leftArithmetic = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue);
if (leftArithmetic == null)
break;
rightArithmetic = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue);
if (rightArithmetic == null)
break;
return leftArithmetic.Divide(rightArithmetic);
case CodeBinaryOperatorType.Modulus:
leftArithmetic = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue);
if (leftArithmetic == null)
break;
rightArithmetic = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue);
if (rightArithmetic == null)
break;
return leftArithmetic.Modulus(rightArithmetic);
case CodeBinaryOperatorType.BitwiseAnd:
leftArithmetic = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue);
if (leftArithmetic == null)
break;
rightArithmetic = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue);
if (rightArithmetic == null)
break;
return leftArithmetic.BitAnd(rightArithmetic);
case CodeBinaryOperatorType.BitwiseOr:
leftArithmetic = ArithmeticLiteral.MakeLiteral(lhsType, lhsValue);
if (leftArithmetic == null)
break;
rightArithmetic = ArithmeticLiteral.MakeLiteral(rhsType, rhsValue);
if (rightArithmetic == null)
break;
return leftArithmetic.BitOr(rightArithmetic);
case CodeBinaryOperatorType.ValueEquality:
leftLiteral = Literal.MakeLiteral(lhsType, lhsValue);
if (leftLiteral == null)
break;
rightLiteral = Literal.MakeLiteral(rhsType, rhsValue);
if (rightLiteral == null)
break;
return leftLiteral.Equal(rightLiteral);
case CodeBinaryOperatorType.IdentityEquality:
return lhsValue == rhsValue;
case CodeBinaryOperatorType.IdentityInequality:
return lhsValue != rhsValue;
case CodeBinaryOperatorType.LessThan:
leftLiteral = Literal.MakeLiteral(lhsType, lhsValue);
if (leftLiteral == null)
break;
rightLiteral = Literal.MakeLiteral(rhsType, rhsValue);
if (rightLiteral == null)
break;
return leftLiteral.LessThan(rightLiteral);
case CodeBinaryOperatorType.LessThanOrEqual:
leftLiteral = Literal.MakeLiteral(lhsType, lhsValue);
if (leftLiteral == null)
break;
rightLiteral = Literal.MakeLiteral(rhsType, rhsValue);
if (rightLiteral == null)
break;
return leftLiteral.LessThanOrEqual(rightLiteral);
case CodeBinaryOperatorType.GreaterThan:
leftLiteral = Literal.MakeLiteral(lhsType, lhsValue);
if (leftLiteral == null)
break;
rightLiteral = Literal.MakeLiteral(rhsType, rhsValue);
if (rightLiteral == null)
break;
return leftLiteral.GreaterThan(rightLiteral);
case CodeBinaryOperatorType.GreaterThanOrEqual:
leftLiteral = Literal.MakeLiteral(lhsType, lhsValue);
if (leftLiteral == null)
break;
rightLiteral = Literal.MakeLiteral(rhsType, rhsValue);
if (rightLiteral == null)
break;
return leftLiteral.GreaterThanOrEqual(rightLiteral);
default:
// should never happen
// BooleanAnd & BooleanOr short-circuited before call
// Assign disallowed at validation time
message = string.Format(CultureInfo.CurrentCulture, Messages.BinaryOpNotSupported, operation.ToString());
exception = new RuleEvaluationException(message);
exception.Data[RuleUserDataKeys.ErrorObject] = binaryExpr;
throw exception;
}
message = string.Format(CultureInfo.CurrentCulture,
Messages.BinaryOpFails,
operation.ToString(),
RuleDecompiler.DecompileType(lhsType),
RuleDecompiler.DecompileType(rhsType));
exception = new RuleEvaluationException(message);
exception.Data[RuleUserDataKeys.ErrorObject] = binaryExpr;
throw exception;
}