(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Data / System.Data.SqlTypes / SqlByte.cs
blobba87529490d0f4d4fbcca88d3521e6c534fd04d0
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
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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.
35 using System;
36 using System.Globalization;
38 namespace System.Data.SqlTypes
40 public struct SqlByte : INullable, IComparable
42 #region Fields
44 byte value;
45 private bool notNull;
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);
52 #endregion
54 #region Constructors
56 public SqlByte (byte value)
58 this.value = value;
59 notNull = true;
62 #endregion
64 #region Properties
66 public bool IsNull {
67 get { return !notNull; }
70 public byte Value {
71 get {
72 if (this.IsNull)
73 throw new SqlNullValueException ();
74 else
75 return value;
79 #endregion
81 #region Methods
83 public static SqlByte Add (SqlByte x, SqlByte y)
85 return (x + y);
88 public static SqlByte BitwiseAnd (SqlByte x, SqlByte y)
90 return (x & y);
93 public static SqlByte BitwiseOr (SqlByte x, SqlByte y)
95 return (x | y);
98 public int CompareTo (object value)
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);
110 public static SqlByte Divide (SqlByte x, SqlByte y)
112 return (x / y);
115 public override bool Equals (object value)
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);
127 public static SqlBoolean Equals (SqlByte x, SqlByte y)
129 return (x == y);
132 public override int GetHashCode ()
134 return (int)value;
137 public static SqlBoolean GreaterThan (SqlByte x, SqlByte y)
139 return (x > y);
142 public static SqlBoolean GreaterThanOrEqual (SqlByte x, SqlByte y)
144 return (x >= y);
147 public static SqlBoolean LessThan (SqlByte x, SqlByte y)
149 return (x < y);
152 public static SqlBoolean LessThanOrEqual (SqlByte x, SqlByte y)
154 return (x <= y);
157 public static SqlByte Mod (SqlByte x, SqlByte y)
159 return (x % y);
162 public static SqlByte Multiply (SqlByte x, SqlByte y)
164 return (x * y);
167 public static SqlBoolean NotEquals (SqlByte x, SqlByte y)
169 return (x != y);
172 public static SqlByte OnesComplement (SqlByte x)
174 return ~x;
177 public static SqlByte Parse (string s)
179 checked {
180 return new SqlByte (Byte.Parse (s));
184 public static SqlByte Subtract (SqlByte x, SqlByte y)
186 return (x - y);
189 public SqlBoolean ToSqlBoolean ()
191 return ((SqlBoolean)this);
194 public SqlDecimal ToSqlDecimal ()
196 return ((SqlDecimal)this);
199 public SqlDouble ToSqlDouble ()
201 return ((SqlDouble)this);
204 public SqlInt16 ToSqlInt16 ()
206 return ((SqlInt16)this);
209 public SqlInt32 ToSqlInt32 ()
211 return ((SqlInt32)this);
214 public SqlInt64 ToSqlInt64 ()
216 return ((SqlInt64)this);
219 public SqlMoney ToSqlMoney ()
221 return ((SqlMoney)this);
224 public SqlSingle ToSqlSingle ()
226 return ((SqlSingle)this);
229 public SqlString ToSqlString ()
231 return ((SqlString)this);
234 public override string ToString ()
236 if (this.IsNull)
237 return "Null";
238 else
239 return value.ToString ();
242 public static SqlByte Xor (SqlByte x, SqlByte y)
244 return (x ^ y);
247 public static SqlByte operator + (SqlByte x, SqlByte y)
249 checked {
250 return new SqlByte ((byte) (x.Value + y.Value));
254 public static SqlByte operator & (SqlByte x, SqlByte y)
256 return new SqlByte ((byte) (x.Value & y.Value));
259 public static SqlByte operator | (SqlByte x, SqlByte y)
261 return new SqlByte ((byte) (x.Value | y.Value));
264 public static SqlByte operator / (SqlByte x, SqlByte y)
266 checked {
267 return new SqlByte ((byte) (x.Value / y.Value));
271 public static SqlBoolean operator == (SqlByte x, SqlByte y)
273 if (x.IsNull || y.IsNull)
274 return SqlBoolean.Null;
275 else
276 return new SqlBoolean (x.Value == y.Value);
279 public static SqlByte operator ^ (SqlByte x, SqlByte y)
281 return new SqlByte ((byte) (x.Value ^ y.Value));
284 public static SqlBoolean operator > (SqlByte x, SqlByte y)
286 if (x.IsNull || y.IsNull)
287 return SqlBoolean.Null;
288 else
289 return new SqlBoolean (x.Value > y.Value);
292 public static SqlBoolean operator >= (SqlByte x, SqlByte y)
294 if (x.IsNull || y.IsNull)
295 return SqlBoolean.Null;
296 else
297 return new SqlBoolean (x.Value >= y.Value);
300 public static SqlBoolean operator != (SqlByte x, SqlByte y)
302 if (x.IsNull || y.IsNull)
303 return SqlBoolean.Null;
304 else
305 return new SqlBoolean (!(x.Value == y.Value));
308 public static SqlBoolean operator < (SqlByte x, SqlByte y)
310 if (x.IsNull || y.IsNull)
311 return SqlBoolean.Null;
312 else
313 return new SqlBoolean (x.Value < y.Value);
316 public static SqlBoolean operator <= (SqlByte x, SqlByte y)
318 if (x.IsNull || y.IsNull)
319 return SqlBoolean.Null;
320 else
321 return new SqlBoolean (x.Value <= y.Value);
324 public static SqlByte operator % (SqlByte x, SqlByte y)
326 return new SqlByte ((byte) (x.Value % y.Value));
329 public static SqlByte operator * (SqlByte x, SqlByte y)
331 checked {
332 return new SqlByte ((byte) (x.Value * y.Value));
336 public static SqlByte operator ~ (SqlByte x)
338 return new SqlByte ((byte) ~x.Value);
341 public static SqlByte operator - (SqlByte x, SqlByte y)
343 checked {
344 return new SqlByte ((byte) (x.Value - y.Value));
348 public static explicit operator SqlByte (SqlBoolean x)
350 if (x.IsNull)
351 return Null;
352 else
353 return new SqlByte (x.ByteValue);
356 public static explicit operator byte (SqlByte x)
358 return x.Value;
361 public static explicit operator SqlByte (SqlDecimal x)
363 checked {
364 if (x.IsNull)
365 return Null;
366 else
367 return new SqlByte ((byte)x.Value);
371 public static explicit operator SqlByte (SqlDouble x)
373 if (x.IsNull)
374 return Null;
375 else {
376 checked {
377 return new SqlByte ((byte)x.Value);
382 public static explicit operator SqlByte (SqlInt16 x)
384 checked {
385 if (x.IsNull)
386 return Null;
387 else
388 return new SqlByte ((byte)x.Value);
392 public static explicit operator SqlByte (SqlInt32 x)
394 checked {
395 if (x.IsNull)
396 return Null;
397 else
398 return new SqlByte ((byte)x.Value);
402 public static explicit operator SqlByte (SqlInt64 x)
404 if (x.IsNull)
405 return Null;
406 else {
407 checked {
408 return new SqlByte ((byte)x.Value);
413 public static explicit operator SqlByte (SqlMoney x)
415 checked {
416 if (x.IsNull)
417 return Null;
418 else
419 return new SqlByte ((byte)x.Value);
423 public static explicit operator SqlByte (SqlSingle x)
425 if (x.IsNull)
426 return Null;
427 else {
428 checked {
429 return new SqlByte ((byte)x.Value);
435 public static explicit operator SqlByte (SqlString x)
437 checked {
438 return SqlByte.Parse (x.Value);
442 public static implicit operator SqlByte (byte x)
444 return new SqlByte (x);
447 #endregion