Copied remotely
[mono.git] / mcs / class / Mono.Data.SybaseClient / Mono.Data.SybaseTypes / SybaseByte.cs
1 //
2 // Mono.Data.SybaseTypes.SybaseByte
3 //
4 // Author:
5 //   Tim Coleman <tim@timcoleman.com>
6 //
7 // Based on System.Data.SqlTypes.SqlByte
8 //
9 //
10 // (C) Ximian, Inc. 2002-2003
11 // (C) Copyright Tim Coleman, 2002
12 //
13
14 //
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:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
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.
33 //
34
35 using Mono.Data.SybaseClient;
36 using System;
37 using System.Data.SqlTypes;
38 using System.Globalization;
39
40 namespace Mono.Data.SybaseTypes {
41         public struct SybaseByte : INullable, IComparable
42         {
43                 #region Fields
44
45                 byte value;
46                 private bool notNull;
47
48                 public static readonly SybaseByte MaxValue = new SybaseByte (0xff);
49                 public static readonly SybaseByte MinValue = new SybaseByte (0);
50                 public static readonly SybaseByte Null;
51                 public static readonly SybaseByte Zero = new SybaseByte (0);
52
53                 #endregion
54
55                 #region Constructors
56
57                 public SybaseByte (byte value) 
58                 {
59                         this.value = value;
60                         notNull = true;
61                 }
62
63                 #endregion
64
65                 #region Properties
66
67                 public bool IsNull {
68                         get { return !notNull; }
69                 }
70
71                 public byte Value { 
72                         get { 
73                                 if (this.IsNull) 
74                                         throw new SybaseNullValueException ();
75                                 else 
76                                         return value; 
77                         }
78                 }
79
80                 #endregion
81
82                 #region Methods
83
84                 public static SybaseByte Add (SybaseByte x, SybaseByte y)
85                 {
86                         return (x + y);
87                 }
88
89                 public static SybaseByte BitwiseAnd (SybaseByte x, SybaseByte y)
90                 {
91                         return (x & y);
92                 }
93
94                 public static SybaseByte BitwiseOr (SybaseByte x, SybaseByte y)
95                 {
96                         return (x | y);
97                 }
98
99                 public int CompareTo (object value)
100                 {
101                         if (value == null)
102                                 return 1;
103                         else if (!(value is SybaseByte))
104                                 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SybaseTypes.SybaseByte"));
105                         else if (((SybaseByte)value).IsNull)
106                                 return 1;
107                         else
108                                 return this.value.CompareTo (((SybaseByte)value).Value);
109                 }
110
111                 public static SybaseByte Divide (SybaseByte x, SybaseByte y)
112                 {
113                         return (x / y);
114                 }
115
116                 public override bool Equals (object value)
117                 {
118                         if (!(value is SybaseByte))
119                                 return false;
120                         else
121                                 return (bool) (this == (SybaseByte)value);
122                 }
123
124                 public static SybaseBoolean Equals (SybaseByte x, SybaseByte y)
125                 {
126                         return (x == y);
127                 }
128
129                 public override int GetHashCode ()
130                 {
131                         return (int)value;
132                 }
133
134                 public static SybaseBoolean GreaterThan (SybaseByte x, SybaseByte y)
135                 {
136                         return (x > y);
137                 }
138
139                 public static SybaseBoolean GreaterThanOrEqual (SybaseByte x, SybaseByte y)
140                 {
141                         return (x >= y);
142                 }
143
144                 public static SybaseBoolean LessThan (SybaseByte x, SybaseByte y)
145                 {
146                         return (x < y);
147                 }
148
149                 public static SybaseBoolean LessThanOrEqual (SybaseByte x, SybaseByte y)
150                 {
151                         return (x <= y);
152                 }
153
154                 public static SybaseByte Mod (SybaseByte x, SybaseByte y)
155                 {
156                         return (x % y);
157                 }
158
159                 public static SybaseByte Multiply (SybaseByte x, SybaseByte y)
160                 {
161                         return (x * y);
162                 }
163
164                 public static SybaseBoolean NotEquals (SybaseByte x, SybaseByte y)
165                 {
166                         return (x != y);
167                 }
168
169                 public static SybaseByte OnesComplement (SybaseByte x)
170                 {
171                         return ~x;
172                 }
173
174                 public static SybaseByte Parse (string s)
175                 {
176                         return new SybaseByte (Byte.Parse (s));
177                 }
178
179                 public static SybaseByte Subtract (SybaseByte x, SybaseByte y)
180                 {
181                         return (x - y);
182                 }
183
184                 public SybaseBoolean ToSybaseBoolean ()
185                 {
186                         return ((SybaseBoolean)this);
187                 }
188                 
189                 public SybaseDecimal ToSybaseDecimal ()
190                 {
191                         return ((SybaseDecimal)this);
192                 }
193
194                 public SybaseDouble ToSybaseDouble ()
195                 {
196                         return ((SybaseDouble)this);
197                 }
198
199                 public SybaseInt16 ToSybaseInt16 ()
200                 {
201                         return ((SybaseInt16)this);
202                 }
203
204                 public SybaseInt32 ToSybaseInt32 ()
205                 {
206                         return ((SybaseInt32)this);
207                 }
208
209                 public SybaseInt64 ToSybaseInt64 ()
210                 {
211                         return ((SybaseInt64)this);
212                 }
213
214                 public SybaseMoney ToSybaseMoney ()
215                 {
216                         return ((SybaseMoney)this);
217                 }
218
219                 public SybaseSingle ToSybaseSingle ()
220                 {
221                         return ((SybaseSingle)this);
222                 }
223
224                 public SybaseString ToSybaseString ()
225                 {
226                         return ((SybaseString)this);
227                 }
228
229                 public override string ToString ()
230                 {
231                         if (this.IsNull)
232                                 return "Null";
233                         else
234                                 return value.ToString ();
235                 }
236
237                 public static SybaseByte Xor (SybaseByte x, SybaseByte y)
238                 {
239                         return (x ^ y);
240                 }
241
242                 public static SybaseByte operator + (SybaseByte x, SybaseByte y)
243                 {
244                         return new SybaseByte ((byte) (x.Value + y.Value));
245                 }
246
247                 public static SybaseByte operator & (SybaseByte x, SybaseByte y)
248                 {
249                         return new SybaseByte ((byte) (x.Value & y.Value));
250                 }
251
252                 public static SybaseByte operator | (SybaseByte x, SybaseByte y)
253                 {
254                         return new SybaseByte ((byte) (x.Value | y.Value));
255                 }
256
257                 public static SybaseByte operator / (SybaseByte x, SybaseByte y)
258                 {
259                         return new SybaseByte ((byte) (x.Value / y.Value));
260                 }
261
262                 public static SybaseBoolean operator == (SybaseByte x, SybaseByte y)
263                 {
264                         if (x.IsNull || y.IsNull) 
265                                 return SybaseBoolean.Null;
266                         else
267                                 return new SybaseBoolean (x.Value == y.Value);
268                 }
269
270                 public static SybaseByte operator ^ (SybaseByte x, SybaseByte y)
271                 {
272                         return new SybaseByte ((byte) (x.Value ^ y.Value));
273                 }
274
275                 public static SybaseBoolean operator > (SybaseByte x, SybaseByte y)
276                 {
277                         if (x.IsNull || y.IsNull) 
278                                 return SybaseBoolean.Null;
279                         else
280                                 return new SybaseBoolean (x.Value > y.Value);
281                 }
282
283                 public static SybaseBoolean operator >= (SybaseByte x, SybaseByte y)
284                 {
285                         if (x.IsNull || y.IsNull) 
286                                 return SybaseBoolean.Null;
287                         else
288                                 return new SybaseBoolean (x.Value >= y.Value);
289                 }
290
291                 public static SybaseBoolean operator != (SybaseByte x, SybaseByte y)
292                 {
293                         if (x.IsNull || y.IsNull) 
294                                 return SybaseBoolean.Null;
295                         else
296                                 return new SybaseBoolean (!(x.Value == y.Value));
297                 }
298
299                 public static SybaseBoolean operator < (SybaseByte x, SybaseByte y)
300                 {
301                         if (x.IsNull || y.IsNull) 
302                                 return SybaseBoolean.Null;
303                         else
304                                 return new SybaseBoolean (x.Value < y.Value);
305                 }
306
307                 public static SybaseBoolean operator <= (SybaseByte x, SybaseByte y)
308                 {
309                         if (x.IsNull || y.IsNull) 
310                                 return SybaseBoolean.Null;
311                         else
312                                 return new SybaseBoolean (x.Value <= y.Value);
313                 }
314
315                 public static SybaseByte operator % (SybaseByte x, SybaseByte y)
316                 {
317                         return new SybaseByte ((byte) (x.Value % y.Value));
318                 }
319
320                 public static SybaseByte operator * (SybaseByte x, SybaseByte y)
321                 {
322                         return new SybaseByte ((byte) (x.Value * y.Value));
323                 }
324
325                 public static SybaseByte operator ~ (SybaseByte x)
326                 {
327                         return new SybaseByte ((byte) ~x.Value);
328                 }
329
330                 public static SybaseByte operator - (SybaseByte x, SybaseByte y)
331                 {
332                         return new SybaseByte ((byte) (x.Value - y.Value));
333                 }
334
335                 public static explicit operator SybaseByte (SybaseBoolean x)
336                 {
337                         if (x.IsNull)
338                                 return Null;
339                         else
340                                 return new SybaseByte (x.ByteValue);
341                 }
342
343                 public static explicit operator byte (SybaseByte x)
344                 {
345                         return x.Value;
346                 }
347
348                 public static explicit operator SybaseByte (SybaseDecimal x)
349                 {
350                         if (x.IsNull)
351                                 return Null;
352                         else
353                                 return new SybaseByte ((byte)x.Value);
354                 }
355
356                 public static explicit operator SybaseByte (SybaseDouble x)
357                 {
358                         if (x.IsNull)
359                                 return Null;
360                         else
361                                 return new SybaseByte ((byte)x.Value);
362                 }
363
364                 public static explicit operator SybaseByte (SybaseInt16 x)
365                 {
366                         if (x.IsNull)
367                                 return Null;
368                         else
369                                 return new SybaseByte ((byte)x.Value);
370                 }
371
372                 public static explicit operator SybaseByte (SybaseInt32 x)
373                 {
374                         if (x.IsNull)
375                                 return Null;
376                         else
377                                 return new SybaseByte ((byte)x.Value);
378                 }
379
380                 public static explicit operator SybaseByte (SybaseInt64 x)
381                 {
382                         if (x.IsNull)
383                                 return Null;
384                         else
385                                 return new SybaseByte ((byte)x.Value);
386                 }
387
388                 public static explicit operator SybaseByte (SybaseMoney x)
389                 {
390                         if (x.IsNull)
391                                 return Null;
392                         else
393                                 return new SybaseByte ((byte)x.Value);
394                 }
395
396                 public static explicit operator SybaseByte (SybaseSingle x)
397                 {
398                         if (x.IsNull)
399                                 return Null;
400                         else
401                                 return new SybaseByte ((byte)x.Value);
402                 }
403
404
405                 public static explicit operator SybaseByte (SybaseString x)
406                 {
407                         return SybaseByte.Parse (x.Value);
408                 }
409
410                 public static implicit operator SybaseByte (byte x)
411                 {
412                         return new SybaseByte (x);
413                 }
414                 
415                 #endregion
416         }
417 }
418