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;
39 using System.Xml.Schema;
40 using System.Xml.Serialization;
41 using System.Runtime.Serialization;
44 namespace System.Data.SqlTypes
46 public struct SqlByte : INullable, IComparable
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);
65 public SqlByte (byte value)
76 get { return !notNull; }
82 throw new SqlNullValueException ();
92 public static SqlByte Add (SqlByte x, SqlByte y)
97 public static SqlByte BitwiseAnd (SqlByte x, SqlByte y)
102 public static SqlByte BitwiseOr (SqlByte x, SqlByte y)
107 public int CompareTo (object value)
111 if (!(value is SqlByte))
112 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlByte"));
114 return CompareTo ((SqlByte) value);
119 int CompareTo (SqlByte value)
124 return this.value.CompareTo (value.Value);
127 public static SqlByte Divide (SqlByte x, SqlByte y)
132 public override bool Equals (object value)
134 if (!(value is SqlByte))
136 else if (this.IsNull && ((SqlByte)value).IsNull)
138 else if (((SqlByte)value).IsNull)
141 return (bool) (this == (SqlByte)value);
144 public static SqlBoolean Equals (SqlByte x, SqlByte y)
149 public override int GetHashCode ()
154 public static SqlBoolean GreaterThan (SqlByte x, SqlByte y)
159 public static SqlBoolean GreaterThanOrEqual (SqlByte x, SqlByte y)
164 public static SqlBoolean LessThan (SqlByte x, SqlByte y)
169 public static SqlBoolean LessThanOrEqual (SqlByte x, SqlByte y)
174 public static SqlByte Mod (SqlByte x, SqlByte y)
179 public static SqlByte Multiply (SqlByte x, SqlByte y)
184 public static SqlBoolean NotEquals (SqlByte x, SqlByte y)
189 public static SqlByte OnesComplement (SqlByte x)
194 public static SqlByte Parse (string s)
197 return new SqlByte (Byte.Parse (s));
201 public static SqlByte Subtract (SqlByte x, SqlByte y)
206 public SqlBoolean ToSqlBoolean ()
208 return ((SqlBoolean)this);
211 public SqlDecimal ToSqlDecimal ()
213 return ((SqlDecimal)this);
216 public SqlDouble ToSqlDouble ()
218 return ((SqlDouble)this);
221 public SqlInt16 ToSqlInt16 ()
223 return ((SqlInt16)this);
226 public SqlInt32 ToSqlInt32 ()
228 return ((SqlInt32)this);
231 public SqlInt64 ToSqlInt64 ()
233 return ((SqlInt64)this);
236 public SqlMoney ToSqlMoney ()
238 return ((SqlMoney)this);
241 public SqlSingle ToSqlSingle ()
243 return ((SqlSingle)this);
246 public SqlString ToSqlString ()
248 return ((SqlString)this);
251 public override string ToString ()
256 return value.ToString ();
259 public static SqlByte Xor (SqlByte x, SqlByte y)
264 public static SqlByte operator + (SqlByte x, SqlByte y)
267 return new SqlByte ((byte) (x.Value + y.Value));
271 public static SqlByte operator & (SqlByte x, SqlByte y)
273 return new SqlByte ((byte) (x.Value & y.Value));
276 public static SqlByte operator | (SqlByte x, SqlByte y)
278 return new SqlByte ((byte) (x.Value | y.Value));
281 public static SqlByte operator / (SqlByte x, SqlByte y)
284 return new SqlByte ((byte) (x.Value / y.Value));
288 public static SqlBoolean operator == (SqlByte x, SqlByte y)
290 if (x.IsNull || y.IsNull)
291 return SqlBoolean.Null;
293 return new SqlBoolean (x.Value == y.Value);
296 public static SqlByte operator ^ (SqlByte x, SqlByte y)
298 return new SqlByte ((byte) (x.Value ^ y.Value));
301 public static SqlBoolean operator > (SqlByte x, SqlByte y)
303 if (x.IsNull || y.IsNull)
304 return SqlBoolean.Null;
306 return new SqlBoolean (x.Value > y.Value);
309 public static SqlBoolean operator >= (SqlByte x, SqlByte y)
311 if (x.IsNull || y.IsNull)
312 return SqlBoolean.Null;
314 return new SqlBoolean (x.Value >= y.Value);
317 public static SqlBoolean operator != (SqlByte x, SqlByte y)
319 if (x.IsNull || y.IsNull)
320 return SqlBoolean.Null;
322 return new SqlBoolean (!(x.Value == y.Value));
325 public static SqlBoolean operator < (SqlByte x, SqlByte y)
327 if (x.IsNull || y.IsNull)
328 return SqlBoolean.Null;
330 return new SqlBoolean (x.Value < y.Value);
333 public static SqlBoolean operator <= (SqlByte x, SqlByte y)
335 if (x.IsNull || y.IsNull)
336 return SqlBoolean.Null;
338 return new SqlBoolean (x.Value <= y.Value);
341 public static SqlByte operator % (SqlByte x, SqlByte y)
343 return new SqlByte ((byte) (x.Value % y.Value));
346 public static SqlByte operator * (SqlByte x, SqlByte y)
349 return new SqlByte ((byte) (x.Value * y.Value));
353 public static SqlByte operator ~ (SqlByte x)
355 return new SqlByte ((byte) ~x.Value);
358 public static SqlByte operator - (SqlByte x, SqlByte y)
361 return new SqlByte ((byte) (x.Value - y.Value));
365 public static explicit operator SqlByte (SqlBoolean x)
370 return new SqlByte (x.ByteValue);
373 public static explicit operator byte (SqlByte x)
378 public static explicit operator SqlByte (SqlDecimal x)
384 return new SqlByte ((byte)x.Value);
388 public static explicit operator SqlByte (SqlDouble x)
394 return new SqlByte ((byte)x.Value);
399 public static explicit operator SqlByte (SqlInt16 x)
405 return new SqlByte ((byte)x.Value);
409 public static explicit operator SqlByte (SqlInt32 x)
415 return new SqlByte ((byte)x.Value);
419 public static explicit operator SqlByte (SqlInt64 x)
425 return new SqlByte ((byte)x.Value);
430 public static explicit operator SqlByte (SqlMoney x)
436 return new SqlByte ((byte)x.Value);
440 public static explicit operator SqlByte (SqlSingle x)
446 return new SqlByte ((byte)x.Value);
452 public static explicit operator SqlByte (SqlString x)
455 return SqlByte.Parse (x.Value);
459 public static implicit operator SqlByte (byte x)
461 return new SqlByte (x);
465 public static XmlQualifiedName GetXsdType (XmlSchemaSet schemaSet)
467 XmlQualifiedName qualifiedName = new XmlQualifiedName ("unsignedByte", "http://www.w3.org/2001/XMLSchema");
468 return qualifiedName;
472 XmlSchema IXmlSerializable.GetSchema ()
474 throw new NotImplementedException ();
478 void IXmlSerializable.ReadXml (XmlReader reader)
480 throw new NotImplementedException ();
484 void IXmlSerializable.WriteXml (XmlWriter writer)
486 throw new NotImplementedException ();