21 namespace Deveel.Data.Sql.Objects {
65 throw new ArgumentOutOfRangeException(
"value");
75 : this((byte)(value ? 1 : 0)) {
89 int IComparable.CompareTo(
object obj) {
91 throw new ArgumentException();
93 return CompareTo((ISqlObject) obj);
111 var num = (SqlNumber) other;
114 }
else if (num == SqlNumber.One) {
116 }
else if (num == SqlNumber.Zero) {
117 otherBoolean = False;
119 throw new ArgumentOutOfRangeException(
"other",
"The given numeric value is out of range for a comparison with SQL BOOLEAN.");
124 throw new ArgumentException(String.Format(
"Object of type {0} cannot be compared to SQL BOOLEAN", other.GetType().FullName));
127 return CompareTo(otherBoolean);
132 get {
return value == null; }
154 var num = (SqlNumber) other;
155 return num == SqlNumber.Zero || num == SqlNumber.One;
162 public override bool Equals(
object obj) {
169 return Equals((SqlBoolean) obj);
174 if (IsNull && other.
IsNull)
176 if (IsNull && !other.
IsNull)
178 if (!IsNull && other.
IsNull)
181 return value.Equals(other.
value);
193 throw new InvalidOperationException();
201 if (value == 1 || other.
value == 1)
212 if (value == 1 && other.
value == 1)
223 if (value == 1 && other.
value == 0)
225 if (value == 0 && other.
value == 1)
233 return value == null ? 0 : value.Value.GetHashCode();
236 TypeCode IConvertible.GetTypeCode() {
237 return TypeCode.Boolean;
240 bool IConvertible.ToBoolean(IFormatProvider provider) {
244 char IConvertible.ToChar(IFormatProvider provider) {
245 throw new InvalidCastException();
248 sbyte IConvertible.ToSByte(IFormatProvider provider) {
249 return (sbyte) (
this as IConvertible).ToInt32(provider);
252 byte IConvertible.ToByte(IFormatProvider provider) {
254 throw new NullReferenceException();
259 short IConvertible.ToInt16(IFormatProvider provider) {
260 return (
short) (
this as IConvertible).ToInt32(provider);
263 ushort IConvertible.ToUInt16(IFormatProvider provider) {
264 return (ushort) (
this as IConvertible).ToInt32(provider);
267 int IConvertible.ToInt32(IFormatProvider provider) {
269 throw new NullReferenceException();
274 uint IConvertible.ToUInt32(IFormatProvider provider) {
275 return (uint) (
this as IConvertible).ToInt32(provider);
278 long IConvertible.ToInt64(IFormatProvider provider) {
279 return (
this as IConvertible).ToInt64(provider);
282 ulong IConvertible.ToUInt64(IFormatProvider provider) {
283 return (
this as IConvertible).ToUInt64(provider);
286 float IConvertible.ToSingle(IFormatProvider provider) {
287 return (
this as IConvertible).ToInt32(provider);
290 double IConvertible.ToDouble(IFormatProvider provider) {
291 return (
this as IConvertible).ToInt32(provider);
294 decimal IConvertible.ToDecimal(IFormatProvider provider) {
295 return (
this as IConvertible).ToInt32(provider);
298 DateTime IConvertible.ToDateTime(IFormatProvider provider) {
299 throw new InvalidCastException();
302 string IConvertible.ToString(IFormatProvider provider) {
306 object IConvertible.ToType(Type conversionType, IFormatProvider provider) {
307 if (conversionType == typeof (
bool))
310 throw new InvalidCastException(String.Format(
"Cannot convert a SQL BOOLEAN to {0}", conversionType.FullName));
315 if (other.
IsNull && IsNull)
318 if (IsNull && !other.
IsNull)
320 if (!IsNull && other.
IsNull)
323 return value.Value.CompareTo(other.
value.Value);
382 throw new InvalidCastException();
384 return value.
value == 1;
415 if (String.IsNullOrEmpty(s))
416 throw new ArgumentNullException(
"s");
419 if (!TryParse(s, out value))
420 throw new FormatException();
445 if (String.IsNullOrEmpty(s))
448 if (String.Equals(s,
"true", StringComparison.OrdinalIgnoreCase) ||
449 String.Equals(s,
"1")) {
453 if (String.Equals(s,
"false", StringComparison.OrdinalIgnoreCase) ||
454 String.Equals(s,
"0")) {
471 throw new InvalidOperationException(
"Should never happen!");
static bool TryParse(string s, out SqlBoolean value)
Attempts to parse a given string to an instance of SqlBoolean.
override string ToString()
void GetData(SerializeData data)
SqlBoolean(ObjectData data)
SqlBoolean(byte value)
Constructs a given boolean object with a defined byte value.
override int GetHashCode()
SqlBoolean XOr(SqlBoolean other)
void SetValue(string key, Type type, object value)
override bool Equals(object obj)
Defines the contract for a valid SQL Object
bool Equals(SqlBoolean other)
SqlBoolean(bool value)
Constructs an object from a runtime boolean object.
static SqlBoolean Parse(string s)
Parses the given string to extract a boolean value equivalent.
bool IsComparableTo(ISqlObject other)
Indicates if the given ISqlObject can be compared to this SqlBoolean.
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
SqlBoolean Or(SqlBoolean other)
SqlBoolean And(SqlBoolean other)
bool HasValue(string key)
int CompareTo(ISqlObject other)
int CompareTo(SqlBoolean other)