3a4894af0e41aba9536667fb0aed5937483aa567
[mono.git] / mcs / class / System.Data / System.Data.SqlTypes / SqlByte.cs
1 //
2 // System.Data.SqlTypes.SqlByte
3 //
4 // Author:
5 //   Tim Coleman <tim@timcoleman.com>
6 //
7 // (C) Copyright 2002 Tim Coleman
8 //
9
10 using System;
11
12 namespace System.Data.SqlTypes
13 {
14         public struct SqlByte : INullable, IComparable
15         {
16                 #region Fields
17
18                 byte value;
19                 public static readonly SqlByte MaxValue = new SqlByte (0xff);
20                 public static readonly SqlByte MinValue = new SqlByte (0);
21                 public static readonly SqlByte Null;
22                 public static readonly SqlByte Zero = new SqlByte (0);
23
24                 #endregion
25
26                 #region Constructors
27
28                 public SqlByte (byte value) 
29                 {
30                         this.value = value;
31                 }
32
33                 #endregion
34
35                 #region Properties
36
37                 public bool IsNull {
38                         get { return (bool) (this == Null); }
39                 }
40
41                 public byte Value { 
42                         get { 
43                                 if (this.IsNull) 
44                                         throw new SqlNullValueException ("The property contains Null.");
45                                 else 
46                                         return value; 
47                         }
48                 }
49
50                 #endregion
51
52                 #region Methods
53
54                 public static SqlByte Add (SqlByte x, SqlByte y)
55                 {
56                         return (x + y);
57                 }
58
59                 public static SqlByte BitwiseAnd (SqlByte x, SqlByte y)
60                 {
61                         return (x & y);
62                 }
63
64                 public static SqlByte BitwiseOr (SqlByte x, SqlByte y)
65                 {
66                         return (x | y);
67                 }
68
69                 [MonoTODO]
70                 public int CompareTo (object value)
71                 {
72                         throw new NotImplementedException ();
73                 }
74
75                 public static SqlByte Divide (SqlByte x, SqlByte y)
76                 {
77                         return (x / y);
78                 }
79
80                 [MonoTODO]
81                 public override bool Equals (object value)
82                 {
83                         throw new NotImplementedException ();
84                 }
85
86                 public static SqlBoolean Equals (SqlByte x, SqlByte y)
87                 {
88                         return (x == y);
89                 }
90
91                 public override int GetHashCode ()
92                 {
93                         return (int)value;
94                 }
95
96                 public static SqlBoolean GreaterThan (SqlByte x, SqlByte y)
97                 {
98                         return (x > y);
99                 }
100
101                 public static SqlBoolean GreaterThanOrEqual (SqlByte x, SqlByte y)
102                 {
103                         return (x >= y);
104                 }
105
106                 public static SqlBoolean LessThan (SqlByte x, SqlByte y)
107                 {
108                         return (x < y);
109                 }
110
111                 public static SqlBoolean LessThanOrEqual (SqlByte x, SqlByte y)
112                 {
113                         return (x <= y);
114                 }
115
116                 public static SqlByte Mod (SqlByte x, SqlByte y)
117                 {
118                         return (x % y);
119                 }
120
121                 public static SqlByte Multiply (SqlByte x, SqlByte y)
122                 {
123                         return (x * y);
124                 }
125
126                 public static SqlBoolean NotEquals (SqlByte x, SqlByte y)
127                 {
128                         return (x != y);
129                 }
130
131                 public static SqlByte OnesComplement (SqlByte x)
132                 {
133                         return ~x;
134                 }
135
136                 [MonoTODO]
137                 public static SqlByte Parse (string s)
138                 {
139                         throw new NotImplementedException ();
140                 }
141
142                 public static SqlByte Subtract (SqlByte x, SqlByte y)
143                 {
144                         return (x - y);
145                 }
146
147                 public SqlBoolean ToSqlBoolean ()
148                 {
149                         return ((SqlBoolean)this);
150                 }
151                 
152                 public SqlDecimal ToSqlDecimal ()
153                 {
154                         return ((SqlDecimal)this);
155                 }
156
157                 public SqlDouble ToSqlDouble ()
158                 {
159                         return ((SqlDouble)this);
160                 }
161
162                 public SqlInt16 ToSqlInt16 ()
163                 {
164                         return ((SqlInt16)this);
165                 }
166
167                 public SqlInt32 ToSqlInt32 ()
168                 {
169                         return ((SqlInt32)this);
170                 }
171
172                 public SqlInt64 ToSqlInt64 ()
173                 {
174                         return ((SqlInt64)this);
175                 }
176
177                 public SqlMoney ToSqlMoney ()
178                 {
179                         return ((SqlMoney)this);
180                 }
181
182                 public SqlSingle ToSqlSingle ()
183                 {
184                         return ((SqlSingle)this);
185                 }
186
187                 [MonoTODO]
188                 public SqlString ToSqlString ()
189                 {
190                         throw new NotImplementedException ();
191                 }
192
193                 [MonoTODO]
194                 public override string ToString ()
195                 {
196                         throw new NotImplementedException ();
197                 }
198
199                 public static SqlByte Xor (SqlByte x, SqlByte y)
200                 {
201                         return (x ^ y);
202                 }
203
204                 public static SqlByte operator + (SqlByte x, SqlByte y)
205                 {
206                         return new SqlByte ((byte) (x.Value + y.Value));
207                 }
208
209                 public static SqlByte operator & (SqlByte x, SqlByte y)
210                 {
211                         return new SqlByte ((byte) (x.Value & y.Value));
212                 }
213
214                 public static SqlByte operator | (SqlByte x, SqlByte y)
215                 {
216                         return new SqlByte ((byte) (x.Value | y.Value));
217                 }
218
219                 public static SqlByte operator / (SqlByte x, SqlByte y)
220                 {
221                         return new SqlByte ((byte) (x.Value / y.Value));
222                 }
223
224                 public static SqlBoolean operator == (SqlByte x, SqlByte y)
225                 {
226                         if (x.IsNull || y.IsNull) 
227                                 return SqlBoolean.Null;
228                         else
229                                 return new SqlBoolean (x.Value == y.Value);
230                 }
231
232                 public static SqlByte operator ^ (SqlByte x, SqlByte y)
233                 {
234                         return new SqlByte ((byte) (x.Value ^ y.Value));
235                 }
236
237                 public static SqlBoolean operator > (SqlByte x, SqlByte y)
238                 {
239                         if (x.IsNull || y.IsNull) 
240                                 return SqlBoolean.Null;
241                         else
242                                 return new SqlBoolean (x.Value > y.Value);
243                 }
244
245                 public static SqlBoolean operator >= (SqlByte x, SqlByte y)
246                 {
247                         if (x.IsNull || y.IsNull) 
248                                 return SqlBoolean.Null;
249                         else
250                                 return new SqlBoolean (x.Value >= y.Value);
251                 }
252
253                 public static SqlBoolean operator != (SqlByte x, SqlByte y)
254                 {
255                         if (x.IsNull || y.IsNull) 
256                                 return SqlBoolean.Null;
257                         else
258                                 return new SqlBoolean (!(x.Value == y.Value));
259                 }
260
261                 public static SqlBoolean operator < (SqlByte x, SqlByte y)
262                 {
263                         if (x.IsNull || y.IsNull) 
264                                 return SqlBoolean.Null;
265                         else
266                                 return new SqlBoolean (x.Value < y.Value);
267                 }
268
269                 public static SqlBoolean operator <= (SqlByte x, SqlByte y)
270                 {
271                         if (x.IsNull || y.IsNull) 
272                                 return SqlBoolean.Null;
273                         else
274                                 return new SqlBoolean (x.Value <= y.Value);
275                 }
276
277                 public static SqlByte operator % (SqlByte x, SqlByte y)
278                 {
279                         return new SqlByte ((byte) (x.Value % y.Value));
280                 }
281
282                 public static SqlByte operator * (SqlByte x, SqlByte y)
283                 {
284                         return new SqlByte ((byte) (x.Value * y.Value));
285                 }
286
287                 public static SqlByte operator ~ (SqlByte x)
288                 {
289                         return new SqlByte ((byte) ~x.Value);
290                 }
291
292                 public static SqlByte operator - (SqlByte x, SqlByte y)
293                 {
294                         return new SqlByte ((byte) (x.Value - y.Value));
295                 }
296
297                 public static explicit operator SqlByte (SqlBoolean x)
298                 {
299                         if (x.IsNull)
300                                 return Null;
301                         else
302                                 return new SqlByte (x.ByteValue);
303                 }
304
305                 public static explicit operator byte (SqlByte x)
306                 {
307                         return x.Value;
308                 }
309
310                 public static explicit operator SqlByte (SqlDecimal x)
311                 {
312                         if (x.IsNull)
313                                 return Null;
314                         else
315                                 return new SqlByte ((byte)x.Value);
316                 }
317
318                 public static explicit operator SqlByte (SqlDouble x)
319                 {
320                         if (x.IsNull)
321                                 return Null;
322                         else
323                                 return new SqlByte ((byte)x.Value);
324                 }
325
326                 public static explicit operator SqlByte (SqlInt16 x)
327                 {
328                         if (x.IsNull)
329                                 return Null;
330                         else
331                                 return new SqlByte ((byte)x.Value);
332                 }
333
334                 public static explicit operator SqlByte (SqlInt32 x)
335                 {
336                         if (x.IsNull)
337                                 return Null;
338                         else
339                                 return new SqlByte ((byte)x.Value);
340                 }
341
342                 public static explicit operator SqlByte (SqlInt64 x)
343                 {
344                         if (x.IsNull)
345                                 return Null;
346                         else
347                                 return new SqlByte ((byte)x.Value);
348                 }
349
350                 public static explicit operator SqlByte (SqlMoney x)
351                 {
352                         if (x.IsNull)
353                                 return Null;
354                         else
355                                 return new SqlByte ((byte)x.Value);
356                 }
357
358                 public static explicit operator SqlByte (SqlSingle x)
359                 {
360                         if (x.IsNull)
361                                 return Null;
362                         else
363                                 return new SqlByte ((byte)x.Value);
364                 }
365
366                 [MonoTODO]
367                 public static explicit operator SqlByte (SqlString x)
368                 {
369                         throw new NotImplementedException ();
370                 }
371
372                 public static implicit operator SqlByte (byte x)
373                 {
374                         return new SqlByte (x);
375                 }
376                 
377                 #endregion
378         }
379 }
380