DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlNull.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 
20 
21 namespace Deveel.Data.Sql.Objects {
22  [Serializable]
23  public struct SqlNull : ISqlObject, IConvertible, ISerializable {
24  public static readonly SqlNull Value = new SqlNull();
25 
26  private SqlNull(ObjectData data) {
27  }
28 
29  int IComparable.CompareTo(object obj) {
30  return (this as ISqlObject).CompareTo((ISqlObject) obj);
31  }
32 
33  int IComparable<ISqlObject>.CompareTo(ISqlObject other) {
34  throw new NotSupportedException();
35  }
36 
37  public bool IsNull {
38  get { return true; }
39  }
40 
42  }
43 
45  return false;
46  }
47 
48  public override bool Equals(object obj) {
49  if (obj is SqlNull)
50  return true;
51  if (obj is ISqlObject)
52  return ((ISqlObject) obj).IsNull;
53 
54  return false;
55  }
56 
57  public override int GetHashCode() {
58  return 0;
59  }
60 
61  public static bool operator ==(SqlNull a, ISqlObject b) {
62  if (Equals(a, b))
63  return true;
64  if (b == null || b.IsNull)
65  return true;
66 
67  return false;
68  }
69 
70  public static bool operator !=(SqlNull a, ISqlObject b) {
71  return !(a == b);
72  }
73 
74  TypeCode IConvertible.GetTypeCode() {
75  return TypeCode.Object;
76  }
77 
78  bool IConvertible.ToBoolean(IFormatProvider provider) {
79  throw new InvalidCastException();
80  }
81 
82  char IConvertible.ToChar(IFormatProvider provider) {
83  throw new InvalidCastException();
84  }
85 
86  sbyte IConvertible.ToSByte(IFormatProvider provider) {
87  throw new InvalidCastException();
88  }
89 
90  byte IConvertible.ToByte(IFormatProvider provider) {
91  throw new InvalidCastException();
92  }
93 
94  short IConvertible.ToInt16(IFormatProvider provider) {
95  throw new InvalidCastException();
96  }
97 
98  ushort IConvertible.ToUInt16(IFormatProvider provider) {
99  throw new InvalidCastException();
100  }
101 
102  int IConvertible.ToInt32(IFormatProvider provider) {
103  throw new InvalidCastException();
104  }
105 
106  uint IConvertible.ToUInt32(IFormatProvider provider) {
107  throw new InvalidCastException();
108  }
109 
110  long IConvertible.ToInt64(IFormatProvider provider) {
111  throw new InvalidCastException();
112  }
113 
114  ulong IConvertible.ToUInt64(IFormatProvider provider) {
115  throw new InvalidCastException();
116  }
117 
118  float IConvertible.ToSingle(IFormatProvider provider) {
119  throw new InvalidCastException();
120  }
121 
122  double IConvertible.ToDouble(IFormatProvider provider) {
123  throw new InvalidCastException();
124  }
125 
126  decimal IConvertible.ToDecimal(IFormatProvider provider) {
127  throw new InvalidCastException();
128  }
129 
130  DateTime IConvertible.ToDateTime(IFormatProvider provider) {
131  throw new InvalidCastException();
132  }
133 
134  string IConvertible.ToString(IFormatProvider provider) {
135  throw new InvalidCastException();
136  }
137 
138  object IConvertible.ToType(Type conversionType, IFormatProvider provider) {
139  throw new InvalidCastException();
140  }
141 
142  public override string ToString() {
143  return "NULL";
144  }
145  }
146 }
void GetData(SerializeData data)
override string ToString()
Definition: SqlNull.cs:142
SqlNull(ObjectData data)
Definition: SqlNull.cs:26
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
Defines the contract for a valid SQL Object
Definition: ISqlObject.cs:23
override bool Equals(object obj)
Definition: SqlNull.cs:48
bool IsComparableTo(ISqlObject other)
Checks if the current object is comparable with the given one.
override int GetHashCode()
Definition: SqlNull.cs:57