75bb0e3bcdccf1c4dfcd6e545a5f8b64fd5cb0ac
[mono.git] / mcs / class / Mono.Data.TdsClient / Mono.Data.TdsTypes / TdsBinary.cs
1 //
2 // Mono.Data.TdsTypes.TdsBinary
3 //
4 // Author:
5 //   Tim Coleman (tim@timcoleman.com)
6 //
7 // (C) Copyright Tim Coleman, 2002
8 //
9
10 using Mono.Data.TdsClient;
11 using System;
12 using System.Data.SqlTypes;
13 using System.Globalization;
14
15 namespace Mono.Data.TdsTypes {
16         public struct TdsBinary : INullable, IComparable
17         {
18                 #region Fields
19
20                 byte[] value;
21                 private bool notNull;
22
23                 public static readonly TdsBinary Null;
24
25                 #endregion
26
27                 #region Constructors
28                 
29                 public TdsBinary (byte[] value) 
30                 {
31                         this.value = value;
32                         notNull = true;
33                 }
34
35                 #endregion
36
37                 #region Properties
38
39                 public bool IsNull {
40                         get { return !notNull; }
41                 }
42
43                 public byte this[int index] {
44                         get { 
45                                 if (this.IsNull)
46                                         throw new TdsNullValueException ("The property contains Null.");
47                                 else if (index >= this.Length)
48                                         throw new TdsNullValueException ("The index parameter indicates a position beyond the length of the byte array.");
49                                 else
50                                         return value [index]; 
51                         }
52                 }
53
54                 public int Length {
55                         get { 
56                                 if (this.IsNull)
57                                         throw new TdsNullValueException ("The property contains Null.");
58                                 else
59                                         return value.Length;
60                         }
61                 }
62
63                 public byte[] Value 
64                 {
65                         get { 
66                                 if (this.IsNull) 
67                                         throw new TdsNullValueException ("The property contains Null.");
68                                 else 
69                                         return value; 
70                         }
71                 }
72
73                 #endregion
74
75                 #region Methods
76
77                 [MonoTODO]
78                 public int CompareTo (object value) 
79                 {
80                         throw new NotImplementedException ();
81                 }
82
83                 public static TdsBinary Concat (TdsBinary x, TdsBinary y) 
84                 {
85                         return (x + y);
86                 }
87
88                 public override bool Equals (object value) 
89                 {
90                         if (!(value is TdsBinary))
91                                 return false;
92                         else
93                                 return (bool) (this == (TdsBinary)value);
94                 }
95
96                 public static TdsBoolean Equals (TdsBinary x, TdsBinary y) 
97                 {
98                         return (x == y);
99                 }
100
101                 [MonoTODO]
102                 public override int GetHashCode () 
103                 {
104                         throw new NotImplementedException ();
105                 }
106
107                 #endregion
108
109                 #region Operators
110
111                 public static TdsBoolean GreaterThan (TdsBinary x, TdsBinary y) 
112                 {
113                         return (x > y);
114                 }
115
116                 public static TdsBoolean GreaterThanOrEqual (TdsBinary x, TdsBinary y) 
117                 {
118                         return (x >= y);
119                 }
120
121                 public static TdsBoolean LessThan (TdsBinary x, TdsBinary y) 
122                 {
123                         return (x < y);
124                 }
125
126                 public static TdsBoolean LessThanOrEqual (TdsBinary x, TdsBinary y) 
127                 {
128                         return (x <= y);
129                 }
130
131                 public static TdsBoolean NotEquals (TdsBinary x, TdsBinary y) 
132                 {
133                         return (x != y);
134                 }
135
136                 public TdsGuid ToTdsGuid () 
137                 {
138                         return new TdsGuid (value);
139                 }
140
141                 public override string ToString () 
142                 {
143                         if (IsNull)
144                                 return "null";
145                         return String.Format ("TdsBinary ({0})", Length);
146                 }
147
148                 #endregion
149
150                 #region Operators
151
152                 [MonoTODO]
153                 public static TdsBinary operator + (TdsBinary x, TdsBinary y) 
154                 {
155                         throw new NotImplementedException ();
156                 }
157
158                 [MonoTODO]
159                 public static TdsBoolean operator == (TdsBinary x, TdsBinary y) 
160                 {
161                         if (x.IsNull || y.IsNull) 
162                                 return TdsBoolean.Null;
163                         else
164                                 throw new NotImplementedException ();
165                 }
166
167                 [MonoTODO]
168                 public static TdsBoolean operator > (TdsBinary x, TdsBinary y) 
169                 {
170                         if (x.IsNull || y.IsNull) 
171                                 return TdsBoolean.Null;
172                         else
173                                 throw new NotImplementedException ();
174                 }
175
176                 [MonoTODO]
177                 public static TdsBoolean operator >= (TdsBinary x, TdsBinary y) 
178                 {
179                         if (x.IsNull || y.IsNull) 
180                                 return TdsBoolean.Null;
181                         else
182                                 throw new NotImplementedException ();
183                 }
184
185                 [MonoTODO]
186                 public static TdsBoolean operator != (TdsBinary x, TdsBinary y) 
187                 {
188                         if (x.IsNull || y.IsNull) 
189                                 return TdsBoolean.Null;
190                         else
191                                 throw new NotImplementedException ();
192                 }
193
194                 [MonoTODO]
195                 public static TdsBoolean operator < (TdsBinary x, TdsBinary y) 
196                 {
197                         if (x.IsNull || y.IsNull) 
198                                 return TdsBoolean.Null;
199                         else
200                                 throw new NotImplementedException ();
201                 }
202
203                 [MonoTODO]
204                 public static TdsBoolean operator <= (TdsBinary x, TdsBinary y) 
205                 {
206                         if (x.IsNull || y.IsNull) 
207                                 return TdsBoolean.Null;
208                         else
209                                 throw new NotImplementedException ();
210                 }
211
212                 public static explicit operator byte[] (TdsBinary x) 
213                 {
214                         return x.Value;
215                 }
216
217                 [MonoTODO]
218                 public static explicit operator TdsBinary (TdsGuid x) 
219                 {
220                         throw new NotImplementedException ();
221                 }
222
223                 public static implicit operator TdsBinary (byte[] x) 
224                 {
225                         return new TdsBinary (x);
226                 }
227
228                 #endregion
229         }
230 }