public static TypeMismatch ( string expr ) : Exception | ||
expr | string | |
리턴 | Exception |
private object EvalUnaryOp(int op, object vl) { object value = DBNull.Value; if (DataExpression.IsUnknown(vl)) { return(DBNull.Value); } switch (op) { case Operators.Noop: return(vl); case Operators.UnaryPlus: if (ExpressionNode.IsNumeric(vl.GetType())) { return(vl); } throw ExprException.TypeMismatch(this.ToString()); case Operators.Negative: // the have to be better way for doing this.. if (ExpressionNode.IsNumeric(vl.GetType())) { if (vl is byte) { value = -(Byte)vl; } else if (vl is Int16) { value = -(Int16)vl; } else if (vl is Int32) { value = -(Int32)vl; } else if (vl is Int64) { value = -(Int64)vl; } else if (vl is Single) { value = -(Single)vl; } else if (vl is Double) { value = -(Double)vl; } else if (vl is Decimal) { value = -(Decimal)vl; } else { Debug.Assert(false, "Missing a type conversion " + vl.GetType().FullName); value = DBNull.Value; } return(value); } throw ExprException.TypeMismatch(this.ToString()); case Operators.Not: if (DataExpression.ToBoolean(vl) != false) { return(false); } return(true); default: throw ExprException.UnsupportedOperator(op); } }
private object EvalUnaryOp(int op, object vl) { object value = DBNull.Value; if (DataExpression.IsUnknown(vl)) { return(DBNull.Value); } StorageType storageType; switch (op) { case Operators.Noop: return(vl); case Operators.UnaryPlus: storageType = DataStorage.GetStorageType(vl.GetType()); if (ExpressionNode.IsNumericSql(storageType)) { return(vl); } throw ExprException.TypeMismatch(ToString()); case Operators.Negative: // the have to be better way for doing this.. storageType = DataStorage.GetStorageType(vl.GetType()); if (ExpressionNode.IsNumericSql(storageType)) { switch (storageType) { case StorageType.Byte: value = -(byte)vl; break; case StorageType.Int16: value = -(short)vl; break; case StorageType.Int32: value = -(int)vl; break; case StorageType.Int64: value = -(long)vl; break; case StorageType.Single: value = -(float)vl; break; case StorageType.Double: value = -(double)vl; break; case StorageType.Decimal: value = -(decimal)vl; break; case StorageType.SqlDecimal: value = -(SqlDecimal)vl; break; case StorageType.SqlDouble: value = -(SqlDouble)vl; break; case StorageType.SqlSingle: value = -(SqlSingle)vl; break; case StorageType.SqlMoney: value = -(SqlMoney)vl; break; case StorageType.SqlInt64: value = -(SqlInt64)vl; break; case StorageType.SqlInt32: value = -(SqlInt32)vl; break; case StorageType.SqlInt16: value = -(SqlInt16)vl; break; default: Debug.Fail("Missing a type conversion"); value = DBNull.Value; break; } return(value); } throw ExprException.TypeMismatch(ToString()); case Operators.Not: if (vl is SqlBoolean) { if (((SqlBoolean)vl).IsFalse) { return(SqlBoolean.True); } else if (((SqlBoolean)vl).IsTrue) { return(SqlBoolean.False); } throw ExprException.UnsupportedOperator(op); // or should the result of not SQLNull be SqlNull ? } else { if (DataExpression.ToBoolean(vl) != false) { return(false); } return(true); } default: throw ExprException.UnsupportedOperator(op); } }
private object EvalUnaryOp(int op, object vl) { if (!DataExpression.IsUnknown(vl)) { switch (op) { case 0: return(vl); case 1: { StorageType storageType = DataStorage.GetStorageType(vl.GetType()); if (!ExpressionNode.IsNumericSql(storageType)) { throw ExprException.TypeMismatch(this.ToString()); } switch (storageType) { case StorageType.Byte: return((int)-((byte)vl)); case StorageType.Int16: return((int)-((short)vl)); case StorageType.Int32: return(-((int)vl)); case StorageType.Int64: return(-((long)vl)); case StorageType.Single: return(-((float)vl)); case StorageType.Double: return(-((double)vl)); case StorageType.Decimal: return(-((decimal)vl)); case StorageType.SqlDecimal: return(-((SqlDecimal)vl)); case StorageType.SqlDouble: return(-((SqlDouble)vl)); case StorageType.SqlInt16: return(-((SqlInt16)vl)); case StorageType.SqlInt32: return(-((SqlInt32)vl)); case StorageType.SqlInt64: return(-((SqlInt64)vl)); case StorageType.SqlMoney: return(-((SqlMoney)vl)); case StorageType.SqlSingle: return(-((SqlSingle)vl)); } break; } case 2: if (!ExpressionNode.IsNumericSql(DataStorage.GetStorageType(vl.GetType()))) { throw ExprException.TypeMismatch(this.ToString()); } return(vl); case 3: { if (!(vl is SqlBoolean)) { if (DataExpression.ToBoolean(vl)) { return(false); } return(true); } SqlBoolean flag2 = (SqlBoolean)vl; if (!flag2.IsFalse) { SqlBoolean flag = (SqlBoolean)vl; if (!flag.IsTrue) { throw ExprException.UnsupportedOperator(op); } return(SqlBoolean.False); } return(SqlBoolean.True); } default: throw ExprException.UnsupportedOperator(op); } } return(DBNull.Value); }