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);
}
}