Mark tests as not working under TARGET_JVM
[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 #if NET_2_0
38 using System.Xml;
39 using System.Xml.Schema;
40 using System.Xml.Serialization;
41 using System.Runtime.Serialization;
42 #endif
43
44 namespace System.Data.SqlTypes
45 {
46         public struct SqlByte : INullable, IComparable
47 #if NET_2_0
48                                    , IXmlSerializable
49 #endif
50         {
51                 #region Fields
52
53                 byte value;
54                 private bool notNull;
55
56                 public static readonly SqlByte MaxValue = new SqlByte (0xff);
57                 public static readonly SqlByte MinValue = new SqlByte (0);
58                 public static readonly SqlByte Null;
59                 public static readonly SqlByte Zero = new SqlByte (0);
60
61                 #endregion
62
63                 #region Constructors
64
65                 public SqlByte (byte value) 
66                 {
67                         this.value = value;
68                         notNull = true;
69                 }
70
71                 #endregion
72
73                 #region Properties
74
75                 public bool IsNull {
76                         get { return !notNull; }
77                 }
78
79                 public byte Value { 
80                         get { 
81                                 if (this.IsNull) 
82                                         throw new SqlNullValueException ();
83                                 else 
84                                         return value; 
85                         }
86                 }
87
88                 #endregion
89
90                 #region Methods
91
92                 public static SqlByte Add (SqlByte x, SqlByte y)
93                 {
94                         return (x + y);
95                 }
96
97                 public static SqlByte BitwiseAnd (SqlByte x, SqlByte y)
98                 {
99                         return (x & y);
100                 }
101
102                 public static SqlByte BitwiseOr (SqlByte x, SqlByte y)
103                 {
104                         return (x | y);
105                 }
106
107                 public int CompareTo (object value)
108                 {
109                         if (value == null)
110                                 return 1;
111                         if (!(value is SqlByte))
112                                 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlByte"));
113
114                         return CompareTo ((SqlByte) value);
115                 }
116 #if NET_2_0
117                 public
118 #endif
119                 int CompareTo (SqlByte value)
120                 {
121                         if (value.IsNull)
122                                 return 1;
123                         else
124                                 return this.value.CompareTo (value.Value);
125                 }
126
127                 public static SqlByte Divide (SqlByte x, SqlByte y)
128                 {
129                         return (x / y);
130                 }
131
132                 public override bool Equals (object value)
133                 {
134                         if (!(value is SqlByte))
135                                 return false;
136                         else if (this.IsNull && ((SqlByte)value).IsNull)
137                                  return true;
138                         else if (((SqlByte)value).IsNull)
139                                 return false;
140                         else
141                                 return (bool) (this == (SqlByte)value);
142                 }
143
144                 public static SqlBoolean Equals (SqlByte x, SqlByte y)
145                 {
146                         return (x == y);
147                 }
148
149                 public override int GetHashCode ()
150                 {
151                         return (int)value;
152                 }
153
154                 public static SqlBoolean GreaterThan (SqlByte x, SqlByte y)
155                 {
156                         return (x > y);
157                 }
158
159                 public static SqlBoolean GreaterThanOrEqual (SqlByte x, SqlByte y)
160                 {
161                         return (x >= y);
162                 }
163
164                 public static SqlBoolean LessThan (SqlByte x, SqlByte y)
165                 {
166                         return (x < y);
167                 }
168
169                 public static SqlBoolean LessThanOrEqual (SqlByte x, SqlByte y)
170                 {
171                         return (x <= y);
172                 }
173
174                 public static SqlByte Mod (SqlByte x, SqlByte y)
175                 {
176                         return (x % y);
177                 }
178
179                 public static SqlByte Multiply (SqlByte x, SqlByte y)
180                 {
181                         return (x * y);
182                 }
183
184                 public static SqlBoolean NotEquals (SqlByte x, SqlByte y)
185                 {
186                         return (x != y);
187                 }
188
189                 public static SqlByte OnesComplement (SqlByte x)
190                 {
191                         return ~x;
192                 }
193
194                 public static SqlByte Parse (string s)
195                 {
196                         checked {
197                                 return new SqlByte (Byte.Parse (s));
198                         }
199                 }
200
201                 public static SqlByte Subtract (SqlByte x, SqlByte y)
202                 {
203                         return (x - y);
204                 }
205
206                 public SqlBoolean ToSqlBoolean ()
207                 {
208                         return ((SqlBoolean)this);
209                 }
210                 
211                 public SqlDecimal ToSqlDecimal ()
212                 {
213                         return ((SqlDecimal)this);
214                 }
215
216                 public SqlDouble ToSqlDouble ()
217                 {
218                         return ((SqlDouble)this);
219                 }
220
221                 public SqlInt16 ToSqlInt16 ()
222                 {
223                         return ((SqlInt16)this);
224                 }
225
226                 public SqlInt32 ToSqlInt32 ()
227                 {
228                         return ((SqlInt32)this);
229                 }
230
231                 public SqlInt64 ToSqlInt64 ()
232                 {
233                         return ((SqlInt64)this);
234                 }
235
236                 public SqlMoney ToSqlMoney ()
237                 {
238                         return ((SqlMoney)this);
239                 }
240
241                 public SqlSingle ToSqlSingle ()
242                 {
243                         return ((SqlSingle)this);
244                 }
245
246                 public SqlString ToSqlString ()
247                 {
248                         return ((SqlString)this);
249                 }
250
251                 public override string ToString ()
252                 {
253                         if (this.IsNull)
254                                 return "Null";
255                         else
256                                 return value.ToString ();
257                 }
258
259                 public static SqlByte Xor (SqlByte x, SqlByte y)
260                 {
261                         return (x ^ y);
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 SqlByte operator & (SqlByte x, SqlByte y)
272                 {
273                         return new SqlByte ((byte) (x.Value & y.Value));
274                 }
275
276                 public static SqlByte operator | (SqlByte x, SqlByte y)
277                 {
278                         return new SqlByte ((byte) (x.Value | y.Value));
279                 }
280
281                 public static SqlByte operator / (SqlByte x, SqlByte y)
282                 {
283                         checked {
284                                 return new SqlByte ((byte) (x.Value / y.Value));
285                         }
286                 }
287
288                 public static SqlBoolean operator == (SqlByte x, SqlByte y)
289                 {
290                         if (x.IsNull || y.IsNull) 
291                                 return SqlBoolean.Null;
292                         else
293                                 return new SqlBoolean (x.Value == y.Value);
294                 }
295
296                 public static SqlByte operator ^ (SqlByte x, SqlByte y)
297                 {
298                         return new SqlByte ((byte) (x.Value ^ y.Value));
299                 }
300
301                 public static SqlBoolean operator > (SqlByte x, SqlByte y)
302                 {
303                         if (x.IsNull || y.IsNull) 
304                                 return SqlBoolean.Null;
305                         else
306                                 return new SqlBoolean (x.Value > y.Value);
307                 }
308
309                 public static SqlBoolean operator >= (SqlByte x, SqlByte y)
310                 {
311                         if (x.IsNull || y.IsNull) 
312                                 return SqlBoolean.Null;
313                         else
314                                 return new SqlBoolean (x.Value >= y.Value);
315                 }
316
317                 public static SqlBoolean operator != (SqlByte x, SqlByte y)
318                 {
319                         if (x.IsNull || y.IsNull) 
320                                 return SqlBoolean.Null;
321                         else
322                                 return new SqlBoolean (!(x.Value == y.Value));
323                 }
324
325                 public static SqlBoolean operator < (SqlByte x, SqlByte y)
326                 {
327                         if (x.IsNull || y.IsNull) 
328                                 return SqlBoolean.Null;
329                         else
330                                 return new SqlBoolean (x.Value < y.Value);
331                 }
332
333                 public static SqlBoolean operator <= (SqlByte x, SqlByte y)
334                 {
335                         if (x.IsNull || y.IsNull) 
336                                 return SqlBoolean.Null;
337                         else
338                                 return new SqlBoolean (x.Value <= y.Value);
339                 }
340
341                 public static SqlByte operator % (SqlByte x, SqlByte y)
342                 {
343                         return new SqlByte ((byte) (x.Value % y.Value));
344                 }
345
346                 public static SqlByte operator * (SqlByte x, SqlByte y)
347                 {
348                         checked {
349                                 return new SqlByte ((byte) (x.Value * y.Value));
350                         }
351                 }
352
353                 public static SqlByte operator ~ (SqlByte x)
354                 {
355                         return new SqlByte ((byte) ~x.Value);
356                 }
357
358                 public static SqlByte operator - (SqlByte x, SqlByte y)
359                 {
360                         checked {
361                                 return new SqlByte ((byte) (x.Value - y.Value));
362                         }
363                 }
364
365                 public static explicit operator SqlByte (SqlBoolean x)
366                 {
367                         if (x.IsNull)
368                                 return Null;
369                         else
370                                 return new SqlByte (x.ByteValue);
371                 }
372
373                 public static explicit operator byte (SqlByte x)
374                 {
375                         return x.Value;
376                 }
377
378                 public static explicit operator SqlByte (SqlDecimal x)
379                 {
380                         checked {
381                                 if (x.IsNull)
382                                         return Null;
383                                 else 
384                                         return new SqlByte ((byte)x.Value);
385                         }
386                 }
387
388                 public static explicit operator SqlByte (SqlDouble x)
389                 {
390                         if (x.IsNull)
391                                 return Null;
392                         else {
393                                 checked {
394                                         return new SqlByte ((byte)x.Value);
395                                 }
396                         }
397                 }
398
399                 public static explicit operator SqlByte (SqlInt16 x)
400                 {
401                         checked {
402                                 if (x.IsNull)
403                                         return Null;
404                                 else                           
405                                         return new SqlByte ((byte)x.Value);
406                         }
407                 }
408
409                 public static explicit operator SqlByte (SqlInt32 x)
410                 {
411                         checked {
412                                 if (x.IsNull)
413                                         return Null;
414                                 else                           
415                                         return new SqlByte ((byte)x.Value);
416                         }
417                 }
418
419                 public static explicit operator SqlByte (SqlInt64 x)
420                 {
421                         if (x.IsNull)
422                                 return Null;
423                         else {
424                                 checked {
425                                         return new SqlByte ((byte)x.Value);
426                                 }
427                         }
428                 }
429
430                 public static explicit operator SqlByte (SqlMoney x)
431                 {
432                         checked {
433                                 if (x.IsNull)
434                                         return Null;
435                                 else                                    
436                                         return new SqlByte ((byte)x.Value);
437                         }
438                 }
439
440                 public static explicit operator SqlByte (SqlSingle x)
441                 {
442                         if (x.IsNull)
443                                 return Null;
444                         else {
445                                 checked {
446                                         return new SqlByte ((byte)x.Value);
447                                 }
448                         }
449                 }
450
451
452                 public static explicit operator SqlByte (SqlString x)
453                 {                       
454                         checked {
455                                 return SqlByte.Parse (x.Value);
456                         }
457                 }
458
459                 public static implicit operator SqlByte (byte x)
460                 {
461                         return new SqlByte (x);
462                 }
463                 
464 #if NET_2_0
465                 public static XmlQualifiedName GetXsdType (XmlSchemaSet schemaSet)
466                 {
467                         XmlQualifiedName qualifiedName = new XmlQualifiedName ("unsignedByte", "http://www.w3.org/2001/XMLSchema");
468                         return qualifiedName;
469                 }
470                 
471                 [MonoTODO]
472                 XmlSchema IXmlSerializable.GetSchema ()
473                 {
474                         throw new NotImplementedException ();
475                 }
476                                                                                 
477                 [MonoTODO]
478                 void IXmlSerializable.ReadXml (XmlReader reader)
479                 {
480                         throw new NotImplementedException ();
481                 }
482                                                                                 
483                 [MonoTODO]
484                 void IXmlSerializable.WriteXml (XmlWriter writer)
485                 {
486                         throw new NotImplementedException ();
487                 }
488 #endif
489                 #endregion
490         }
491 }
492