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
47 [SerializableAttribute]
48 [XmlSchemaProvider ("GetXsdType")]
50 public struct SqlByte : INullable, IComparable
60 public static readonly SqlByte MaxValue = new SqlByte (0xff);
61 public static readonly SqlByte MinValue = new SqlByte (0);
62 public static readonly SqlByte Null;
63 public static readonly SqlByte Zero = new SqlByte (0);
69 public SqlByte (byte value)
80 get { return !notNull; }
86 throw new SqlNullValueException ();
96 public static SqlByte Add (SqlByte x, SqlByte y)
101 public static SqlByte BitwiseAnd (SqlByte x, SqlByte y)
106 public static SqlByte BitwiseOr (SqlByte x, SqlByte y)
111 public int CompareTo (object value)
115 if (!(value is SqlByte))
116 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlByte"));
118 return CompareTo ((SqlByte) value);
123 int CompareTo (SqlByte value)
128 return this.value.CompareTo (value.Value);
131 public static SqlByte Divide (SqlByte x, SqlByte y)
136 public override bool Equals (object value)
138 if (!(value is SqlByte))
140 else if (this.IsNull)
141 return ((SqlByte)value).IsNull;
142 else if (((SqlByte)value).IsNull)
145 return (bool) (this == (SqlByte)value);
148 public static SqlBoolean Equals (SqlByte x, SqlByte y)
153 public override int GetHashCode ()
158 public static SqlBoolean GreaterThan (SqlByte x, SqlByte y)
163 public static SqlBoolean GreaterThanOrEqual (SqlByte x, SqlByte y)
168 public static SqlBoolean LessThan (SqlByte x, SqlByte y)
173 public static SqlBoolean LessThanOrEqual (SqlByte x, SqlByte y)
178 public static SqlByte Mod (SqlByte x, SqlByte y)
184 // Why did Microsoft add this method in 2.0??? What's
185 // the difference????
186 public static SqlByte Modulus (SqlByte x, SqlByte y)
192 public static SqlByte Multiply (SqlByte x, SqlByte y)
197 public static SqlBoolean NotEquals (SqlByte x, SqlByte y)
202 public static SqlByte OnesComplement (SqlByte x)
207 public static SqlByte Parse (string s)
210 return new SqlByte (Byte.Parse (s));
214 public static SqlByte Subtract (SqlByte x, SqlByte y)
219 public SqlBoolean ToSqlBoolean ()
221 return ((SqlBoolean)this);
224 public SqlDecimal ToSqlDecimal ()
226 return ((SqlDecimal)this);
229 public SqlDouble ToSqlDouble ()
231 return ((SqlDouble)this);
234 public SqlInt16 ToSqlInt16 ()
236 return ((SqlInt16)this);
239 public SqlInt32 ToSqlInt32 ()
241 return ((SqlInt32)this);
244 public SqlInt64 ToSqlInt64 ()
246 return ((SqlInt64)this);
249 public SqlMoney ToSqlMoney ()
251 return ((SqlMoney)this);
254 public SqlSingle ToSqlSingle ()
256 return ((SqlSingle)this);
259 public SqlString ToSqlString ()
261 return ((SqlString)this);
264 public override string ToString ()
269 return value.ToString ();
272 public static SqlByte Xor (SqlByte x, SqlByte y)
277 public static SqlByte operator + (SqlByte x, SqlByte y)
280 return new SqlByte ((byte) (x.Value + y.Value));
284 public static SqlByte operator & (SqlByte x, SqlByte y)
286 return new SqlByte ((byte) (x.Value & y.Value));
289 public static SqlByte operator | (SqlByte x, SqlByte y)
291 return new SqlByte ((byte) (x.Value | y.Value));
294 public static SqlByte operator / (SqlByte x, SqlByte y)
297 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 SqlByte operator ^ (SqlByte x, SqlByte y)
311 return new SqlByte ((byte) (x.Value ^ y.Value));
314 public static SqlBoolean operator > (SqlByte x, SqlByte y)
316 if (x.IsNull || y.IsNull)
317 return SqlBoolean.Null;
319 return new SqlBoolean (x.Value > y.Value);
322 public static SqlBoolean operator >= (SqlByte x, SqlByte y)
324 if (x.IsNull || y.IsNull)
325 return SqlBoolean.Null;
327 return new SqlBoolean (x.Value >= y.Value);
330 public static SqlBoolean operator != (SqlByte x, SqlByte y)
332 if (x.IsNull || y.IsNull)
333 return SqlBoolean.Null;
335 return new SqlBoolean (!(x.Value == y.Value));
338 public static SqlBoolean operator < (SqlByte x, SqlByte y)
340 if (x.IsNull || y.IsNull)
341 return SqlBoolean.Null;
343 return new SqlBoolean (x.Value < y.Value);
346 public static SqlBoolean operator <= (SqlByte x, SqlByte y)
348 if (x.IsNull || y.IsNull)
349 return SqlBoolean.Null;
351 return new SqlBoolean (x.Value <= y.Value);
354 public static SqlByte operator % (SqlByte x, SqlByte y)
356 return new SqlByte ((byte) (x.Value % y.Value));
359 public static SqlByte operator * (SqlByte x, SqlByte y)
362 return new SqlByte ((byte) (x.Value * y.Value));
366 public static SqlByte operator ~ (SqlByte x)
368 return new SqlByte ((byte) ~x.Value);
371 public static SqlByte operator - (SqlByte x, SqlByte y)
374 return new SqlByte ((byte) (x.Value - y.Value));
378 public static explicit operator SqlByte (SqlBoolean x)
383 return new SqlByte (x.ByteValue);
386 public static explicit operator byte (SqlByte x)
391 public static explicit operator SqlByte (SqlDecimal x)
397 return new SqlByte ((byte)x.Value);
401 public static explicit operator SqlByte (SqlDouble x)
407 return new SqlByte ((byte)x.Value);
412 public static explicit operator SqlByte (SqlInt16 x)
418 return new SqlByte ((byte)x.Value);
422 public static explicit operator SqlByte (SqlInt32 x)
428 return new SqlByte ((byte)x.Value);
432 public static explicit operator SqlByte (SqlInt64 x)
438 return new SqlByte ((byte)x.Value);
443 public static explicit operator SqlByte (SqlMoney x)
449 return new SqlByte ((byte)x.Value);
453 public static explicit operator SqlByte (SqlSingle x)
459 return new SqlByte ((byte)x.Value);
465 public static explicit operator SqlByte (SqlString x)
468 return SqlByte.Parse (x.Value);
472 public static implicit operator SqlByte (byte x)
474 return new SqlByte (x);
478 public static XmlQualifiedName GetXsdType (XmlSchemaSet schemaSet)
480 XmlQualifiedName qualifiedName = new XmlQualifiedName ("unsignedByte", "http://www.w3.org/2001/XMLSchema");
481 return qualifiedName;
485 XmlSchema IXmlSerializable.GetSchema ()
487 throw new NotImplementedException ();
491 void IXmlSerializable.ReadXml (XmlReader reader)
493 throw new NotImplementedException ();
497 void IXmlSerializable.WriteXml (XmlWriter writer)
499 throw new NotImplementedException ();