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