**** Merged from MCS ****
[mono-project.git] / mcs / class / Mono.Data.TdsClient / Mono.Data.TdsTypes / TdsBinary.cs
blobf183c6904397887669962c7f84e77f9911cb6c9c
1 //
2 // Mono.Data.TdsTypes.TdsBinary
3 //
4 // Author:
5 // Tim Coleman (tim@timcoleman.com)
6 //
7 // (C) Copyright Tim Coleman, 2002
8 //
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:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
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.TdsClient;
32 using System;
33 using System.Data.SqlTypes;
34 using System.Globalization;
36 namespace Mono.Data.TdsTypes {
37 public struct TdsBinary : INullable, IComparable
39 #region Fields
41 byte[] value;
42 private bool notNull;
44 public static readonly TdsBinary Null;
46 #endregion
48 #region Constructors
50 public TdsBinary (byte[] value)
52 this.value = value;
53 notNull = true;
56 #endregion
58 #region Properties
60 public bool IsNull {
61 get { return !notNull; }
64 public byte this[int index] {
65 get {
66 if (this.IsNull)
67 throw new TdsNullValueException ("The property contains Null.");
68 else if (index >= this.Length)
69 throw new TdsNullValueException ("The index parameter indicates a position beyond the length of the byte array.");
70 else
71 return value [index];
75 public int Length {
76 get {
77 if (this.IsNull)
78 throw new TdsNullValueException ("The property contains Null.");
79 else
80 return value.Length;
84 public byte[] Value
86 get {
87 if (this.IsNull)
88 throw new TdsNullValueException ("The property contains Null.");
89 else
90 return value;
94 #endregion
96 #region Methods
98 [MonoTODO]
99 public int CompareTo (object value)
101 throw new NotImplementedException ();
104 public static TdsBinary Concat (TdsBinary x, TdsBinary y)
106 return (x + y);
109 public override bool Equals (object value)
111 if (!(value is TdsBinary))
112 return false;
113 else
114 return (bool) (this == (TdsBinary)value);
117 public static TdsBoolean Equals (TdsBinary x, TdsBinary y)
119 return (x == y);
122 [MonoTODO]
123 public override int GetHashCode ()
125 throw new NotImplementedException ();
128 #endregion
130 #region Operators
132 public static TdsBoolean GreaterThan (TdsBinary x, TdsBinary y)
134 return (x > y);
137 public static TdsBoolean GreaterThanOrEqual (TdsBinary x, TdsBinary y)
139 return (x >= y);
142 public static TdsBoolean LessThan (TdsBinary x, TdsBinary y)
144 return (x < y);
147 public static TdsBoolean LessThanOrEqual (TdsBinary x, TdsBinary y)
149 return (x <= y);
152 public static TdsBoolean NotEquals (TdsBinary x, TdsBinary y)
154 return (x != y);
157 public TdsGuid ToTdsGuid ()
159 return new TdsGuid (value);
162 public override string ToString ()
164 if (IsNull)
165 return "null";
166 return String.Format ("TdsBinary ({0})", Length);
169 #endregion
171 #region Operators
173 [MonoTODO]
174 public static TdsBinary operator + (TdsBinary x, TdsBinary y)
176 throw new NotImplementedException ();
179 [MonoTODO]
180 public static TdsBoolean operator == (TdsBinary x, TdsBinary y)
182 if (x.IsNull || y.IsNull)
183 return TdsBoolean.Null;
184 else
185 throw new NotImplementedException ();
188 [MonoTODO]
189 public static TdsBoolean operator > (TdsBinary x, TdsBinary y)
191 if (x.IsNull || y.IsNull)
192 return TdsBoolean.Null;
193 else
194 throw new NotImplementedException ();
197 [MonoTODO]
198 public static TdsBoolean operator >= (TdsBinary x, TdsBinary y)
200 if (x.IsNull || y.IsNull)
201 return TdsBoolean.Null;
202 else
203 throw new NotImplementedException ();
206 [MonoTODO]
207 public static TdsBoolean operator != (TdsBinary x, TdsBinary y)
209 if (x.IsNull || y.IsNull)
210 return TdsBoolean.Null;
211 else
212 throw new NotImplementedException ();
215 [MonoTODO]
216 public static TdsBoolean operator < (TdsBinary x, TdsBinary y)
218 if (x.IsNull || y.IsNull)
219 return TdsBoolean.Null;
220 else
221 throw new NotImplementedException ();
224 [MonoTODO]
225 public static TdsBoolean operator <= (TdsBinary x, TdsBinary y)
227 if (x.IsNull || y.IsNull)
228 return TdsBoolean.Null;
229 else
230 throw new NotImplementedException ();
233 public static explicit operator byte[] (TdsBinary x)
235 return x.Value;
238 [MonoTODO]
239 public static explicit operator TdsBinary (TdsGuid x)
241 throw new NotImplementedException ();
244 public static implicit operator TdsBinary (byte[] x)
246 return new TdsBinary (x);
249 #endregion