2 // System.Data.SqlTypes.SqlByte
5 // Tim Coleman <tim@timcoleman.com>
6 // Ville Palo <vi64pa@kolumbus.fi>
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:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
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.
36 using System.Globalization;
38 namespace System.Data.SqlTypes
40 public struct SqlByte : INullable, IComparable
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);
56 public SqlByte (byte value)
67 get { return !notNull; }
73 throw new SqlNullValueException ();
83 public static SqlByte Add (SqlByte x, SqlByte y)
88 public static SqlByte BitwiseAnd (SqlByte x, SqlByte y)
93 public static SqlByte BitwiseOr (SqlByte x, SqlByte y)
98 public int CompareTo (object value)
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)
107 return this.value.CompareTo (((SqlByte)value).Value);
110 public static SqlByte Divide (SqlByte x, SqlByte y)
115 public override bool Equals (object value)
117 if (!(value is SqlByte))
119 else if (this.IsNull && ((SqlByte)value).IsNull)
121 else if (((SqlByte)value).IsNull)
124 return (bool) (this == (SqlByte)value);
127 public static SqlBoolean Equals (SqlByte x, SqlByte y)
132 public override int GetHashCode ()
137 public static SqlBoolean GreaterThan (SqlByte x, SqlByte y)
142 public static SqlBoolean GreaterThanOrEqual (SqlByte x, SqlByte y)
147 public static SqlBoolean LessThan (SqlByte x, SqlByte y)
152 public static SqlBoolean LessThanOrEqual (SqlByte x, SqlByte y)
157 public static SqlByte Mod (SqlByte x, SqlByte y)
162 public static SqlByte Multiply (SqlByte x, SqlByte y)
167 public static SqlBoolean NotEquals (SqlByte x, SqlByte y)
172 public static SqlByte OnesComplement (SqlByte x)
177 public static SqlByte Parse (string s)
180 return new SqlByte (Byte.Parse (s));
184 public static SqlByte Subtract (SqlByte x, SqlByte 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 ()
239 return value.ToString ();
242 public static SqlByte Xor (SqlByte x, SqlByte y)
247 public static SqlByte operator + (SqlByte x, SqlByte y)
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)
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;
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;
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;
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;
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;
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;
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)
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)
344 return new SqlByte ((byte) (x.Value - y.Value));
348 public static explicit operator SqlByte (SqlBoolean x)
353 return new SqlByte (x.ByteValue);
356 public static explicit operator byte (SqlByte x)
361 public static explicit operator SqlByte (SqlDecimal x)
367 return new SqlByte ((byte)x.Value);
371 public static explicit operator SqlByte (SqlDouble x)
377 return new SqlByte ((byte)x.Value);
382 public static explicit operator SqlByte (SqlInt16 x)
388 return new SqlByte ((byte)x.Value);
392 public static explicit operator SqlByte (SqlInt32 x)
398 return new SqlByte ((byte)x.Value);
402 public static explicit operator SqlByte (SqlInt64 x)
408 return new SqlByte ((byte)x.Value);
413 public static explicit operator SqlByte (SqlMoney x)
419 return new SqlByte ((byte)x.Value);
423 public static explicit operator SqlByte (SqlSingle x)
429 return new SqlByte ((byte)x.Value);
435 public static explicit operator SqlByte (SqlString x)
438 return SqlByte.Parse (x.Value);
442 public static implicit operator SqlByte (byte x)
444 return new SqlByte (x);