2 // System.Data.SqlTypes.SqlChars
5 // Tim Coleman <tim@timcoleman.com>
7 // Copyright (C) Tim Coleman, 2003
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Globalization;
39 using System.Xml.Schema;
40 using System.Xml.Serialization;
41 using System.Runtime.Serialization;
43 namespace System.Data.SqlTypes
45 [SerializableAttribute]
46 [XmlSchemaProvider ("GetXsdType")]
47 public sealed class SqlChars : INullable, IXmlSerializable, ISerializable
53 StorageState storage = StorageState.UnmanagedBuffer;
65 public SqlChars (char[] buffer)
73 storage = StorageState.Buffer;
77 public SqlChars (SqlString value)
84 buffer = value.Value.ToCharArray ();
85 storage = StorageState.Buffer;
93 public char [] Buffer {
94 get { return buffer; }
98 get { return !notNull; }
101 public char this [long offset] {
103 if (notNull && offset >= 0 && offset < buffer.Length)
104 buffer [offset] = value;
108 throw new SqlNullValueException ("Data is Null");
109 if (offset < 0 || offset >= buffer.Length)
110 throw new ArgumentOutOfRangeException ("Parameter name: offset");
111 return buffer [offset];
117 if (!notNull || buffer == null)
118 throw new SqlNullValueException ("Data is Null");
119 if (buffer.Length < 0)
121 return buffer.Length;
125 public long MaxLength {
127 if (!notNull || buffer == null || storage == StorageState.Stream)
129 return buffer.Length;
133 public static SqlChars Null {
135 return new SqlChars ();
139 public StorageState Storage {
141 if (storage == StorageState.UnmanagedBuffer)
142 throw new SqlNullValueException ("Data is Null");
147 public char [] Value {
151 return (char []) buffer.Clone ();
159 public void SetLength (long value)
162 throw new SqlTypeException ("There is no buffer");
163 if (value < 0 || value > buffer.Length)
164 throw new ArgumentOutOfRangeException ("Specified argument was out of the range of valid values.");
165 Array.Resize (ref buffer, (int) value);
168 public void SetNull ()
174 public static explicit operator SqlString (SqlChars x)
177 return SqlString.Null;
179 return new SqlString (new String (x.Value));
183 public static explicit operator SqlChars (SqlString x)
188 return new SqlChars (x.Value);
191 public SqlString ToSqlString ()
193 if (buffer == null) {
194 return SqlString.Null;
197 return new SqlString (buffer.ToString ());
202 public long Read (long offset, char [] buffer, int offsetInBuffer, int count)
204 throw new NotImplementedException ();
207 [MonoNotSupported("")]
208 public void Write (long offset, char [] buffer, int offsetInBuffer, int count)
210 throw new NotImplementedException ();
213 public static XmlQualifiedName GetXsdType (XmlSchemaSet schemaSet)
215 XmlQualifiedName qualifiedName = new XmlQualifiedName ("string", "http://www.w3.org/2001/XMLSchema");
216 return qualifiedName;
220 XmlSchema IXmlSerializable.GetSchema ()
222 throw new NotImplementedException ();
226 void IXmlSerializable.ReadXml (XmlReader reader)
228 throw new NotImplementedException ();
232 void IXmlSerializable.WriteXml (XmlWriter writer)
234 throw new NotImplementedException ();
238 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
240 throw new NotImplementedException ();