* DataSetReadXmlTest.cs: Added NotWorking test for bug #80045.
[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 //   Ville Palo <vi64pa@kolumbus.fi>
7 //
8 // (C) Copyright 2002 Tim Coleman
9 // (C) Copyright 2003 Ville Palo
10 //
11
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 using System;
36 using System.Globalization;
37
38 namespace System.Data.SqlTypes
39 {
40         public struct SqlByte : INullable, IComparable
41         {
42                 #region Fields
43
44                 byte value;
45                 private bool notNull;
46
47                 public static readonly SqlByte MaxValue = new SqlByte (0xff);
48                 public static readonly SqlByte MinValue = new SqlByte (0);
49                 public static readonly SqlByte Null;
50                 public static readonly SqlByte Zero = new SqlByte (0);
51
52                 #endregion
53
54                 #region Constructors
55
56                 public SqlByte (byte value) 
57                 {
58                         this.value = value;
59                         notNull = true;
60                 }
61
62                 #endregion
63
64                 #region Properties
65
66                 public bool IsNull {
67                         get { return !notNull; }
68                 }
69
70                 public byte Value { 
71                         get { 
72                                 if (this.IsNull) 
73                                         throw new SqlNullValueException ();
74                                 else 
75                                         return value; 
76                         }
77                 }
78
79                 #endregion
80
81                 #region Methods
82
83                 public static SqlByte Add (SqlByte x, SqlByte y)
84                 {
85                         return (x + y);
86                 }
87
88                 public static SqlByte BitwiseAnd (SqlByte x, SqlByte y)
89                 {
90                         return (x & y);
91                 }
92
93                 public static SqlByte BitwiseOr (SqlByte x, SqlByte y)
94                 {
95                         return (x | y);
96                 }
97
98                 public int CompareTo (object value)
99                 {
100                         if (value == null)
101                                 return 1;
102                         else if (!(value is SqlByte))
103                                 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlByte"));
104                         else if (((SqlByte)value).IsNull)
105                                 return 1;
106                         else
107                                 return this.value.CompareTo (((SqlByte)value).Value);
108                 }
109
110                 public static SqlByte Divide (SqlByte x, SqlByte y)
111                 {
112                         return (x / y);
113                 }
114
115                 public override bool Equals (object value)
116                 {
117                         if (!(value is SqlByte))
118                                 return false;
119                         else if (this.IsNull && ((SqlByte)value).IsNull)
120                                  return true;
121                         else if (((SqlByte)value).IsNull)
122                                 return false;
123                         else
124                                 return (bool) (this == (SqlByte)value);
125                 }
126
127                 public static SqlBoolean Equals (SqlByte x, SqlByte y)
128                 {
129                         return (x == y);
130                 }
131
132                 public override int GetHashCode ()
133                 {
134                         return (int)value;
135                 }
136
137                 public static SqlBoolean GreaterThan (SqlByte x, SqlByte y)
138                 {
139                         return (x > y);
140                 }
141
142                 public static SqlBoolean GreaterThanOrEqual (SqlByte x, SqlByte y)
143                 {
144                         return (x >= y);
145                 }
146
147                 public static SqlBoolean LessThan (SqlByte x, SqlByte y)
148                 {
149                         return (x < y);
150                 }
151
152                 public static SqlBoolean LessThanOrEqual (SqlByte x, SqlByte y)
153                 {
154                         return (x <= y);
155                 }
156
157                 public static SqlByte Mod (SqlByte x, SqlByte y)
158                 {
159                         return (x % y);
160                 }
161
162                 public static SqlByte Multiply (SqlByte x, SqlByte y)
163                 {
164                         return (x * y);
165                 }
166
167                 public static SqlBoolean NotEquals (SqlByte x, SqlByte y)
168                 {
169                         return (x != y);
170                 }
171
172                 public static SqlByte OnesComplement (SqlByte x)
173                 {
174                         return ~x;
175                 }
176
177                 public static SqlByte Parse (string s)
178                 {
179                         checked {
180                                 return new SqlByte (Byte.Parse (s));
181                         }
182                 }
183
184                 public static SqlByte Subtract (SqlByte x, SqlByte y)
185                 {
186                         return (x - y);
187                 }
188
189                 public SqlBoolean ToSqlBoolean ()
190                 {
191                         return ((SqlBoolean)this);
192                 }
193                 
194                 public SqlDecimal ToSqlDecimal ()
195                 {
196                         return ((SqlDecimal)this);
197                 }
198
199                 public SqlDouble ToSqlDouble ()
200                 {
201                         return ((SqlDouble)this);
202                 }
203
204                 public SqlInt16 ToSqlInt16 ()
205                 {
206                         return ((SqlInt16)this);
207                 }
208
209                 public SqlInt32 ToSqlInt32 ()
210                 {
211                         return ((SqlInt32)this);
212                 }
213
214                 public SqlInt64 ToSqlInt64 ()
215                 {
216                         return ((SqlInt64)this);
217                 }
218
219                 public SqlMoney ToSqlMoney ()
220                 {
221                         return ((SqlMoney)this);
222                 }
223
224                 public SqlSingle ToSqlSingle ()
225                 {
226                         return ((SqlSingle)this);
227                 }
228
229                 public SqlString ToSqlString ()
230                 {
231                         return ((SqlString)this);
232                 }
233
234                 public override string ToString ()
235                 {
236                         if (this.IsNull)
237                                 return "Null";
238                         else
239                                 return value.ToString ();
240                 }
241
242                 public static SqlByte Xor (SqlByte x, SqlByte y)
243                 {
244                         return (x ^ y);
245                 }
246
247                 public static SqlByte operator + (SqlByte x, SqlByte y)
248                 {
249                         checked {
250                                 return new SqlByte ((byte) (x.Value + y.Value));
251                         }
252                 }
253
254                 public static SqlByte operator & (SqlByte x, SqlByte y)
255                 {
256                         return new SqlByte ((byte) (x.Value & y.Value));
257                 }
258
259                 public static SqlByte operator | (SqlByte x, SqlByte y)
260                 {
261                         return new SqlByte ((byte) (x.Value | y.Value));
262                 }
263
264                 public static SqlByte operator / (SqlByte x, SqlByte y)
265                 {
266                         checked {
267                                 return new SqlByte ((byte) (x.Value / y.Value));
268                         }
269                 }
270
271                 public static SqlBoolean operator == (SqlByte x, SqlByte y)
272                 {
273                         if (x.IsNull || y.IsNull) 
274                                 return SqlBoolean.Null;
275                         else
276                                 return new SqlBoolean (x.Value == y.Value);
277                 }
278
279                 public static SqlByte operator ^ (SqlByte x, SqlByte y)
280                 {
281                         return new SqlByte ((byte) (x.Value ^ y.Value));
282                 }
283
284                 public static SqlBoolean operator > (SqlByte x, SqlByte y)
285                 {
286                         if (x.IsNull || y.IsNull) 
287                                 return SqlBoolean.Null;
288                         else
289                                 return new SqlBoolean (x.Value > y.Value);
290                 }
291
292                 public static SqlBoolean operator >= (SqlByte x, SqlByte y)
293                 {
294                         if (x.IsNull || y.IsNull) 
295                                 return SqlBoolean.Null;
296                         else
297                                 return new SqlBoolean (x.Value >= y.Value);
298                 }
299
300                 public static SqlBoolean operator != (SqlByte x, SqlByte y)
301                 {
302                         if (x.IsNull || y.IsNull) 
303                                 return SqlBoolean.Null;
304                         else
305                                 return new SqlBoolean (!(x.Value == y.Value));
306                 }
307
308                 public static SqlBoolean operator < (SqlByte x, SqlByte y)
309                 {
310                         if (x.IsNull || y.IsNull) 
311                                 return SqlBoolean.Null;
312                         else
313                                 return new SqlBoolean (x.Value < y.Value);
314                 }
315
316                 public static SqlBoolean operator <= (SqlByte x, SqlByte y)
317                 {
318                         if (x.IsNull || y.IsNull) 
319                                 return SqlBoolean.Null;
320                         else
321                                 return new SqlBoolean (x.Value <= y.Value);
322                 }
323
324                 public static SqlByte operator % (SqlByte x, SqlByte y)
325                 {
326                         return new SqlByte ((byte) (x.Value % y.Value));
327                 }
328
329                 public static SqlByte operator * (SqlByte x, SqlByte y)
330                 {
331                         checked {
332                                 return new SqlByte ((byte) (x.Value * y.Value));
333                         }
334                 }
335
336                 public static SqlByte operator ~ (SqlByte x)
337                 {
338                         return new SqlByte ((byte) ~x.Value);
339                 }
340
341                 public static SqlByte operator - (SqlByte x, SqlByte y)
342                 {
343                         checked {
344                                 return new SqlByte ((byte) (x.Value - y.Value));
345                         }
346                 }
347
348                 public static explicit operator SqlByte (SqlBoolean x)
349                 {
350                         if (x.IsNull)
351                                 return Null;
352                         else
353                                 return new SqlByte (x.ByteValue);
354                 }
355
356                 public static explicit operator byte (SqlByte x)
357                 {
358                         return x.Value;
359                 }
360
361                 public static explicit operator SqlByte (SqlDecimal x)
362                 {
363                         checked {
364                                 if (x.IsNull)
365                                         return Null;
366                                 else 
367                                         return new SqlByte ((byte)x.Value);
368                         }
369                 }
370
371                 public static explicit operator SqlByte (SqlDouble x)
372                 {
373                         if (x.IsNull)
374                                 return Null;
375                         else {
376                                 checked {
377                                         return new SqlByte ((byte)x.Value);
378                                 }
379                         }
380                 }
381
382                 public static explicit operator SqlByte (SqlInt16 x)
383                 {
384                         checked {
385                                 if (x.IsNull)
386                                         return Null;
387                                 else                           
388                                         return new SqlByte ((byte)x.Value);
389                         }
390                 }
391
392                 public static explicit operator SqlByte (SqlInt32 x)
393                 {
394                         checked {
395                                 if (x.IsNull)
396                                         return Null;
397                                 else                           
398                                         return new SqlByte ((byte)x.Value);
399                         }
400                 }
401
402                 public static explicit operator SqlByte (SqlInt64 x)
403                 {
404                         if (x.IsNull)
405                                 return Null;
406                         else {
407                                 checked {
408                                         return new SqlByte ((byte)x.Value);
409                                 }
410                         }
411                 }
412
413                 public static explicit operator SqlByte (SqlMoney x)
414                 {
415                         checked {
416                                 if (x.IsNull)
417                                         return Null;
418                                 else                                    
419                                         return new SqlByte ((byte)x.Value);
420                         }
421                 }
422
423                 public static explicit operator SqlByte (SqlSingle x)
424                 {
425                         if (x.IsNull)
426                                 return Null;
427                         else {
428                                 checked {
429                                         return new SqlByte ((byte)x.Value);
430                                 }
431                         }
432                 }
433
434
435                 public static explicit operator SqlByte (SqlString x)
436                 {                       
437                         checked {
438                                 return SqlByte.Parse (x.Value);
439                         }
440                 }
441
442                 public static implicit operator SqlByte (byte x)
443                 {
444                         return new SqlByte (x);
445                 }
446                 
447                 #endregion
448         }
449 }
450