2 // System.Data.SqlTypes.SqlInt64
5 // Tim Coleman <tim@timcoleman.com>
6 // Ville Palo <vi64pa@koti.soon.fi>
8 // (C) Copyright 2002 Tim Coleman
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Xml.Schema;
37 using System.Globalization;
38 using System.Xml.Serialization;
40 namespace System.Data.SqlTypes
43 [SerializableAttribute]
44 [XmlSchemaProvider ("GetSchema")]
46 public struct SqlInt64 : INullable, IComparable
57 public static readonly SqlInt64 MaxValue = new SqlInt64 (9223372036854775807);
58 public static readonly SqlInt64 MinValue = new SqlInt64 (-9223372036854775808);
60 public static readonly SqlInt64 Null;
61 public static readonly SqlInt64 Zero = new SqlInt64 (0);
67 public SqlInt64 (long value)
78 get { return !notNull; }
84 throw new SqlNullValueException ();
94 public static SqlInt64 Add (SqlInt64 x, SqlInt64 y)
99 public static SqlInt64 BitwiseAnd (SqlInt64 x, SqlInt64 y)
104 public static SqlInt64 BitwiseOr (SqlInt64 x, SqlInt64 y)
109 public int CompareTo (object value)
113 else if (!(value is SqlInt64))
114 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlInt64"));
115 return CompareSqlInt64 ((SqlInt64) value);
119 public int CompareTo (SqlInt64 value)
121 return CompareSqlInt64 ((SqlInt64) value);
125 private int CompareSqlInt64 (SqlInt64 value)
130 return this.value.CompareTo (value.Value);
133 public static SqlInt64 Divide (SqlInt64 x, SqlInt64 y)
138 public override bool Equals (object value)
140 if (!(value is SqlInt64))
142 else if (this.IsNull && ((SqlInt64)value).IsNull)
144 else if (((SqlInt64)value).IsNull)
147 return (bool) (this == (SqlInt64)value);
150 public static SqlBoolean Equals (SqlInt64 x, SqlInt64 y)
155 public override int GetHashCode ()
157 return (int)(value & 0xffffffff) ^ (int)(value >> 32);
160 public static SqlBoolean GreaterThan (SqlInt64 x, SqlInt64 y)
165 public static SqlBoolean GreaterThanOrEqual (SqlInt64 x, SqlInt64 y)
170 public static SqlBoolean LessThan (SqlInt64 x, SqlInt64 y)
175 public static SqlBoolean LessThanOrEqual (SqlInt64 x, SqlInt64 y)
180 public static SqlInt64 Mod (SqlInt64 x, SqlInt64 y)
186 public static SqlInt64 Modulus (SqlInt64 x, SqlInt64 y)
192 public static SqlInt64 Multiply (SqlInt64 x, SqlInt64 y)
197 public static SqlBoolean NotEquals (SqlInt64 x, SqlInt64 y)
202 public static SqlInt64 OnesComplement (SqlInt64 x)
211 public static SqlInt64 Parse (string s)
214 return new SqlInt64 (Int64.Parse (s));
218 public static SqlInt64 Subtract (SqlInt64 x, SqlInt64 y)
223 public SqlBoolean ToSqlBoolean ()
225 return ((SqlBoolean)this);
228 public SqlByte ToSqlByte ()
230 return ((SqlByte)this);
233 public SqlDecimal ToSqlDecimal ()
235 return ((SqlDecimal)this);
238 public SqlDouble ToSqlDouble ()
240 return ((SqlDouble)this);
243 public SqlInt16 ToSqlInt16 ()
245 return ((SqlInt16)this);
248 public SqlInt32 ToSqlInt32 ()
250 return ((SqlInt32)this);
253 public SqlMoney ToSqlMoney ()
255 return ((SqlMoney)this);
258 public SqlSingle ToSqlSingle ()
260 return ((SqlSingle)this);
263 public SqlString ToSqlString ()
265 return ((SqlString)this);
268 public override string ToString ()
273 return value.ToString ();
276 public static SqlInt64 Xor (SqlInt64 x, SqlInt64 y)
281 public static SqlInt64 operator + (SqlInt64 x, SqlInt64 y)
284 return new SqlInt64 (x.Value + y.Value);
288 public static SqlInt64 operator & (SqlInt64 x, SqlInt64 y)
290 return new SqlInt64 (x.value & y.Value);
293 public static SqlInt64 operator | (SqlInt64 x, SqlInt64 y)
295 return new SqlInt64 (x.value | y.Value);
298 public static SqlInt64 operator / (SqlInt64 x, SqlInt64 y)
301 return new SqlInt64 (x.Value / y.Value);
305 public static SqlBoolean operator == (SqlInt64 x, SqlInt64 y)
307 if (x.IsNull || y.IsNull)
308 return SqlBoolean.Null;
310 return new SqlBoolean (x.Value == y.Value);
313 public static SqlInt64 operator ^ (SqlInt64 x, SqlInt64 y)
315 return new SqlInt64 (x.Value ^ y.Value);
318 public static SqlBoolean operator > (SqlInt64 x, SqlInt64 y)
320 if (x.IsNull || y.IsNull)
321 return SqlBoolean.Null;
323 return new SqlBoolean (x.Value > y.Value);
326 public static SqlBoolean operator >= (SqlInt64 x, SqlInt64 y)
328 if (x.IsNull || y.IsNull)
329 return SqlBoolean.Null;
331 return new SqlBoolean (x.Value >= y.Value);
334 public static SqlBoolean operator != (SqlInt64 x, SqlInt64 y)
336 if (x.IsNull || y.IsNull)
337 return SqlBoolean.Null;
339 return new SqlBoolean (!(x.Value == y.Value));
342 public static SqlBoolean operator < (SqlInt64 x, SqlInt64 y)
344 if (x.IsNull || y.IsNull)
345 return SqlBoolean.Null;
347 return new SqlBoolean (x.Value < y.Value);
350 public static SqlBoolean operator <= (SqlInt64 x, SqlInt64 y)
352 if (x.IsNull || y.IsNull)
353 return SqlBoolean.Null;
355 return new SqlBoolean (x.Value <= y.Value);
358 public static SqlInt64 operator % (SqlInt64 x, SqlInt64 y)
360 return new SqlInt64(x.Value % y.Value);
363 public static SqlInt64 operator * (SqlInt64 x, SqlInt64 y)
366 return new SqlInt64 (x.Value * y.Value);
370 public static SqlInt64 operator ~ (SqlInt64 x)
373 return SqlInt64.Null;
375 return new SqlInt64 (~(x.Value));
378 public static SqlInt64 operator - (SqlInt64 x, SqlInt64 y)
381 return new SqlInt64 (x.Value - y.Value);
385 public static SqlInt64 operator - (SqlInt64 n)
387 return new SqlInt64 (-(n.Value));
390 public static explicit operator SqlInt64 (SqlBoolean x)
393 return SqlInt64.Null;
395 return new SqlInt64 ((long)x.ByteValue);
398 public static explicit operator SqlInt64 (SqlDecimal x)
402 return SqlInt64.Null;
404 return new SqlInt64 ((long)x.Value);
408 public static explicit operator SqlInt64 (SqlDouble x)
411 return SqlInt64.Null;
414 return new SqlInt64 ((long)x.Value);
419 public static explicit operator long (SqlInt64 x)
424 public static explicit operator SqlInt64 (SqlMoney x)
428 return SqlInt64.Null;
430 return new SqlInt64 ((long) Math.Round (x.Value));
434 public static explicit operator SqlInt64 (SqlSingle x)
437 return SqlInt64.Null;
440 return new SqlInt64 ((long)x.Value);
445 public static explicit operator SqlInt64 (SqlString x)
448 return SqlInt64.Parse (x.Value);
452 public static implicit operator SqlInt64 (long x)
454 return new SqlInt64 (x);
457 public static implicit operator SqlInt64 (SqlByte x)
460 return SqlInt64.Null;
462 return new SqlInt64 ((long)x.Value);
465 public static implicit operator SqlInt64 (SqlInt16 x)
468 return SqlInt64.Null;
470 return new SqlInt64 ((long)x.Value);
473 public static implicit operator SqlInt64 (SqlInt32 x)
476 return SqlInt64.Null;
478 return new SqlInt64 ((long)x.Value);
483 XmlSchema IXmlSerializable.GetSchema ()
485 throw new NotImplementedException ();
489 void IXmlSerializable.ReadXml (XmlReader reader)
491 throw new NotImplementedException ();
495 void IXmlSerializable.WriteXml (XmlWriter writer)
497 throw new NotImplementedException ();