2 // Mono.Data.SybaseTypes.SybaseInt32
5 // Tim Coleman (tim@timcoleman.com)
7 // (C) Copyright Tim Coleman, 2002
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using Mono
.Data
.SybaseClient
;
33 using System
.Data
.SqlTypes
;
34 using System
.Globalization
;
36 namespace Mono
.Data
.SybaseTypes
{
37 public struct SybaseInt32
: INullable
, IComparable
44 public static readonly SybaseInt32 MaxValue
= new SybaseInt32 (2147483647);
45 public static readonly SybaseInt32 MinValue
= new SybaseInt32 (-2147483648);
46 public static readonly SybaseInt32 Null
;
47 public static readonly SybaseInt32 Zero
= new SybaseInt32 (0);
53 public SybaseInt32(int value)
64 get { return !notNull; }
70 throw new SybaseNullValueException ();
80 public static SybaseInt32
Add (SybaseInt32 x
, SybaseInt32 y
)
85 public static SybaseInt32
BitwiseAnd(SybaseInt32 x
, SybaseInt32 y
)
90 public static SybaseInt32
BitwiseOr(SybaseInt32 x
, SybaseInt32 y
)
95 public int CompareTo(object value)
99 else if (!(value is SybaseInt32
))
100 throw new ArgumentException (Locale
.GetText ("Value is not a System.Data.SybaseTypes.SybaseInt32"));
101 else if (((SybaseInt32
)value).IsNull
)
104 return this.value.CompareTo (((SybaseInt32
)value).Value
);
107 public static SybaseInt32
Divide(SybaseInt32 x
, SybaseInt32 y
)
112 public override bool Equals(object value)
114 if (!(value is SybaseInt32
))
117 return (bool) (this == (SybaseInt32
)value);
120 public static SybaseBoolean
Equals(SybaseInt32 x
, SybaseInt32 y
)
125 public override int GetHashCode()
130 public static SybaseBoolean
GreaterThan (SybaseInt32 x
, SybaseInt32 y
)
135 public static SybaseBoolean
GreaterThanOrEqual (SybaseInt32 x
, SybaseInt32 y
)
140 public static SybaseBoolean
LessThan(SybaseInt32 x
, SybaseInt32 y
)
145 public static SybaseBoolean
LessThanOrEqual(SybaseInt32 x
, SybaseInt32 y
)
150 public static SybaseInt32
Mod(SybaseInt32 x
, SybaseInt32 y
)
155 public static SybaseInt32
Multiply(SybaseInt32 x
, SybaseInt32 y
)
160 public static SybaseBoolean
NotEquals(SybaseInt32 x
, SybaseInt32 y
)
165 public static SybaseInt32
OnesComplement(SybaseInt32 x
)
170 public static SybaseInt32
Parse(string s
)
172 return new SybaseInt32 (Int32
.Parse (s
));
175 public static SybaseInt32
Subtract(SybaseInt32 x
, SybaseInt32 y
)
180 public SybaseBoolean
ToSybaseBoolean()
182 return ((SybaseBoolean
)this);
185 public SybaseByte
ToSybaseByte()
187 return ((SybaseByte
)this);
190 public SybaseDecimal
ToSybaseDecimal()
192 return ((SybaseDecimal
)this);
195 public SybaseDouble
ToSybaseDouble()
197 return ((SybaseDouble
)this);
200 public SybaseInt16
ToSybaseInt16()
202 return ((SybaseInt16
)this);
205 public SybaseInt64
ToSybaseInt64()
207 return ((SybaseInt64
)this);
210 public SybaseMoney
ToSybaseMoney()
212 return ((SybaseMoney
)this);
215 public SybaseSingle
ToSybaseSingle()
217 return ((SybaseSingle
)this);
220 public SybaseString
ToSybaseString ()
222 return ((SybaseString
)this);
225 public override string ToString()
230 return value.ToString ();
233 public static SybaseInt32
Xor(SybaseInt32 x
, SybaseInt32 y
)
243 public static SybaseInt32
operator + (SybaseInt32 x
, SybaseInt32 y
)
245 return new SybaseInt32 (x
.Value
+ y
.Value
);
249 public static SybaseInt32
operator & (SybaseInt32 x
, SybaseInt32 y
)
251 return new SybaseInt32 (x
.Value
& y
.Value
);
255 public static SybaseInt32
operator | (SybaseInt32 x
, SybaseInt32 y
)
257 return new SybaseInt32 (x
.Value
| y
.Value
);
261 public static SybaseInt32
operator / (SybaseInt32 x
, SybaseInt32 y
)
263 return new SybaseInt32 (x
.Value
/ y
.Value
);
267 public static SybaseBoolean
operator == (SybaseInt32 x
, SybaseInt32 y
)
269 if (x
.IsNull
|| y
.IsNull
)
270 return SybaseBoolean
.Null
;
272 return new SybaseBoolean (x
.Value
== y
.Value
);
275 // Bitwise Exclusive-OR (XOR)
276 public static SybaseInt32
operator ^
(SybaseInt32 x
, SybaseInt32 y
)
278 return new SybaseInt32 (x
.Value ^ y
.Value
);
282 public static SybaseBoolean
operator >(SybaseInt32 x
, SybaseInt32 y
)
284 if (x
.IsNull
|| y
.IsNull
)
285 return SybaseBoolean
.Null
;
287 return new SybaseBoolean (x
.Value
> y
.Value
);
291 public static SybaseBoolean
operator >= (SybaseInt32 x
, SybaseInt32 y
)
293 if (x
.IsNull
|| y
.IsNull
)
294 return SybaseBoolean
.Null
;
296 return new SybaseBoolean (x
.Value
>= y
.Value
);
299 // != Inequality Compare
300 public static SybaseBoolean
operator != (SybaseInt32 x
, SybaseInt32 y
)
302 if (x
.IsNull
|| y
.IsNull
)
303 return SybaseBoolean
.Null
;
305 return new SybaseBoolean (x
.Value
!= y
.Value
);
309 public static SybaseBoolean
operator < (SybaseInt32 x
, SybaseInt32 y
)
311 if (x
.IsNull
|| y
.IsNull
)
312 return SybaseBoolean
.Null
;
314 return new SybaseBoolean (x
.Value
< y
.Value
);
318 public static SybaseBoolean
operator <= (SybaseInt32 x
, SybaseInt32 y
)
320 if (x
.IsNull
|| y
.IsNull
)
321 return SybaseBoolean
.Null
;
323 return new SybaseBoolean (x
.Value
<= y
.Value
);
327 public static SybaseInt32
operator % (SybaseInt32 x
, SybaseInt32 y
)
329 return new SybaseInt32 (x
.Value
% y
.Value
);
332 // Compute Multiplication
333 public static SybaseInt32
operator * (SybaseInt32 x
, SybaseInt32 y
)
335 return new SybaseInt32 (x
.Value
* y
.Value
);
339 public static SybaseInt32
operator ~
(SybaseInt32 x
)
341 return new SybaseInt32 (~x
.Value
);
345 public static SybaseInt32
operator - (SybaseInt32 x
, SybaseInt32 y
)
347 return new SybaseInt32 (x
.Value
- y
.Value
);
351 public static SybaseInt32
operator - (SybaseInt32 x
)
353 return new SybaseInt32 (-x
.Value
);
357 public static explicit operator SybaseInt32 (SybaseBoolean x
)
362 return new SybaseInt32 ((int)x
.ByteValue
);
365 public static explicit operator SybaseInt32 (SybaseDecimal x
)
370 return new SybaseInt32 ((int)x
.Value
);
373 public static explicit operator SybaseInt32 (SybaseDouble x
)
378 return new SybaseInt32 ((int)x
.Value
);
381 public static explicit operator int (SybaseInt32 x
)
386 public static explicit operator SybaseInt32 (SybaseInt64 x
)
391 return new SybaseInt32 ((int)x
.Value
);
394 public static explicit operator SybaseInt32(SybaseMoney x
)
399 return new SybaseInt32 ((int)x
.Value
);
402 public static explicit operator SybaseInt32(SybaseSingle x
)
407 return new SybaseInt32 ((int)x
.Value
);
410 public static explicit operator SybaseInt32(SybaseString x
)
412 return SybaseInt32
.Parse (x
.Value
);
415 public static implicit operator SybaseInt32(int x
)
417 return new SybaseInt32 (x
);
420 public static implicit operator SybaseInt32(SybaseByte x
)
425 return new SybaseInt32 ((int)x
.Value
);
428 public static implicit operator SybaseInt32(SybaseInt16 x
)
433 return new SybaseInt32 ((int)x
.Value
);