(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Data / System.Data.OleDb / OleDbParameterCollection.cs
blob2daa27569a6468f5cdaaa3a8a3a9f5d64973d997
1 //
2 // System.Data.OleDb.OleDbParameterCollection
3 //
4 // Author:
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Tim Coleman (tim@timcoleman.com)
7 // Umadevi S (sumadevi@novell.com)
8 //
9 // Copyright (C) Rodrigo Moya, 2002
10 // Copyright (C) Tim Coleman, 2002
11 // Copyright (C) Novell Inc.
15 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
17 // Permission is hereby granted, free of charge, to any person obtaining
18 // a copy of this software and associated documentation files (the
19 // "Software"), to deal in the Software without restriction, including
20 // without limitation the rights to use, copy, modify, merge, publish,
21 // distribute, sublicense, and/or sell copies of the Software, and to
22 // permit persons to whom the Software is furnished to do so, subject to
23 // the following conditions:
24 //
25 // The above copyright notice and this permission notice shall be
26 // included in all copies or substantial portions of the Software.
27 //
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using System.Collections;
38 using System.Data;
39 using System.Data.Common;
40 using System.ComponentModel;
42 namespace System.Data.OleDb
44 [ListBindable (false)]
45 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBParametersEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
46 public sealed class OleDbParameterCollection : MarshalByRefObject,
47 IDataParameterCollection, IList, ICollection, IEnumerable
49 #region Fields
51 ArrayList list = new ArrayList ();
53 #endregion // Fields
55 #region Constructors
57 internal OleDbParameterCollection () {
60 #endregion // Constructors
62 #region Properties
64 [Browsable (false)]
65 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
66 public int Count {
67 get { return list.Count; }
70 [Browsable (false)]
71 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
72 public OleDbParameter this[int index] {
73 get { return (OleDbParameter) list[index]; }
74 set { list[index] = value; }
77 [Browsable (false)]
78 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
79 public OleDbParameter this[string parameterName] {
80 get {
81 foreach (OleDbParameter p in list)
82 if (p.ParameterName.Equals (parameterName))
83 return p;
84 throw new IndexOutOfRangeException ("The specified name does not exist: " + parameterName);
86 set {
87 if (!Contains (parameterName)) throw new IndexOutOfRangeException("The specified name does not exist: " + parameterName);
88 this [IndexOf (parameterName)] = value;
92 int ICollection.Count {
93 get { return list.Count; }
96 bool IList.IsFixedSize {
97 get { return false; }
100 bool IList.IsReadOnly {
101 get { return false; }
104 bool ICollection.IsSynchronized {
105 get { return list.IsSynchronized; }
108 object ICollection.SyncRoot {
109 get { return list.SyncRoot; }
112 object IList.this[int index] {
113 get { return list[index]; }
114 set { list[index] = value; }
117 object IDataParameterCollection.this[string name]
119 [MonoTODO]
120 get {
121 throw new NotImplementedException ();
123 [MonoTODO]
124 set {
125 throw new NotImplementedException ();
129 internal IntPtr GdaParameterList {
130 [MonoTODO]
131 get {
132 IntPtr param_list;
134 param_list = libgda.gda_parameter_list_new ();
135 // FIXME: add parameters to list
137 return param_list;
141 #endregion // Properties
143 #region Methods
145 public int Add (object value) {
146 if (!(value is OleDbParameter))
147 throw new InvalidCastException ("The parameter was not an OleDbParameter.");
148 Add ((OleDbParameter) value);
149 return IndexOf (value);
152 public OleDbParameter Add (OleDbParameter parameter)
154 if (parameter.Container != null)
155 throw new ArgumentException ("The OleDbParameter specified in the value parameter is already added to this or another OleDbParameterCollection.");
157 parameter.Container = this;
158 list.Add (parameter);
159 return parameter;
162 public OleDbParameter Add (string name, object value)
164 return Add (new OleDbParameter (name, value));
167 public OleDbParameter Add (string name, OleDbType type)
169 return Add (new OleDbParameter (name, type));
172 public OleDbParameter Add (string name, OleDbType type, int width)
174 return Add (new OleDbParameter (name, type, width));
177 public OleDbParameter Add (string name, OleDbType type,
178 int width, string src_col)
180 return Add (new OleDbParameter (name, type, width, src_col));
183 int IList.Add (object value)
185 if (!(value is IDataParameter))
186 throw new InvalidCastException ();
188 list.Add (value);
189 return list.IndexOf (value);
192 void IList.Clear ()
194 list.Clear ();
197 bool IList.Contains (object value)
199 return list.Contains (value);
202 bool IDataParameterCollection.Contains (string value)
204 for (int i = 0; i < list.Count; i++) {
205 IDataParameter parameter;
207 parameter = (IDataParameter) list[i];
208 if (parameter.ParameterName == value)
209 return true;
212 return false;
215 void ICollection.CopyTo (Array array, int index)
217 ((OleDbParameter[])(list.ToArray ())).CopyTo (array, index);
220 IEnumerator IEnumerable.GetEnumerator ()
222 return list.GetEnumerator ();
225 int IList.IndexOf (object value)
227 return list.IndexOf (value);
230 int IDataParameterCollection.IndexOf (string name)
232 return list.IndexOf (((IDataParameterCollection) this)[name]);
235 void IList.Insert (int index, object value)
237 list.Insert (index, value);
240 void IList.Remove (object value)
242 list.Remove (value);
245 void IList.RemoveAt (int index)
247 list.Remove ((object) list[index]);
250 void IDataParameterCollection.RemoveAt (string name)
252 list.Remove (((IDataParameterCollection) this)[name]);
255 public void Clear() {
257 foreach (OleDbParameter p in list)
258 p.Container = null;
260 list.Clear ();
263 public bool Contains (object value) {
265 if (!(value is OleDbParameter))
266 throw new InvalidCastException ("The parameter was not an OleDbParameter.");
267 return Contains (((OleDbParameter) value).ParameterName);
270 public bool Contains (string value) {
272 foreach (OleDbParameter p in list)
273 if (p.ParameterName.Equals (value))
274 return true;
275 return false;
278 public void CopyTo (Array array, int index) {
280 list.CopyTo (array, index);
283 public IEnumerator GetEnumerator() {
285 return list.GetEnumerator ();
288 public int IndexOf (object value) {
290 if (!(value is OleDbParameter))
291 throw new InvalidCastException ("The parameter was not an OleDbParameter.");
292 return IndexOf (((OleDbParameter) value).ParameterName);
295 public int IndexOf (string parameterName) {
297 for (int i = 0; i < Count; i += 1)
298 if (this [i].ParameterName.Equals (parameterName))
299 return i;
300 return -1;
303 public void Insert (int index, object value) {
305 list.Insert (index, value);
308 public void Remove (object value) {
310 ((OleDbParameter) value).Container = null;
311 list.Remove (value);
314 public void RemoveAt (int index) {
316 this [index].Container = null;
317 list.RemoveAt (index);
320 public void RemoveAt (string parameterName) {
322 RemoveAt (IndexOf (parameterName));
326 #endregion // Methods