(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Data / System.Data.Odbc / OdbcParameterCollection.cs
blob27cf61d920ac23c5172ad6c1e0c952f68029a535
1 //
2 // System.Data.Odbc.OdbcParameterCollection
3 //
4 // Authors:
5 // Brian Ritchie (brianlritchie@hotmail.com)
6 // Umadevi S (sumadevi@novell.com)
7 //
8 // Copyright (C) Brian Ritchie, 2002
9 // Copyright (C) Novell,Inc
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 //
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 //
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Collections;
36 using System.Data;
37 using System.ComponentModel;
38 using System.Data.Common;
40 namespace System.Data.Odbc
42 [ListBindable (false)]
43 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBParametersEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
44 public sealed class OdbcParameterCollection : MarshalByRefObject,
45 IDataParameterCollection, IList, ICollection, IEnumerable
47 #region Fields
49 ArrayList list = new ArrayList ();
51 #endregion // Fields
53 #region Constructors
55 internal OdbcParameterCollection () {
58 #endregion // Constructors
60 #region Properties
62 [Browsable (false)]
63 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
64 public int Count {
65 get { return list.Count; }
68 [Browsable (false)]
69 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
70 public OdbcParameter this[int index] {
71 get { return (OdbcParameter) list[index]; }
72 set { list[index] = value; }
75 [Browsable (false)]
76 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
77 public OdbcParameter this[string parameterName] {
78 get {
79 foreach (OdbcParameter p in list)
80 if (p.ParameterName.Equals (parameterName))
81 return p;
82 throw new IndexOutOfRangeException ("The specified name does not exist: " + parameterName);
84 set {
85 if (!Contains (parameterName))
86 throw new IndexOutOfRangeException("The specified name does not exist: " + parameterName);
87 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 get { return this[name]; }
120 set {
121 if (!(value is OdbcParameter))
122 throw new InvalidCastException ("Only OdbcParameter objects can be used.");
123 this [name] = (OdbcParameter) value;
128 #endregion // Properties
130 #region Methods
132 public int Add (object value)
134 if (!(value is OdbcParameter))
135 throw new InvalidCastException ("The parameter was not an OdbcParameter.");
136 Add ((OdbcParameter) value);
137 return IndexOf (value);
142 public OdbcParameter Add (OdbcParameter parameter)
144 if (parameter.Container != null)
145 throw new ArgumentException ("The OdbcParameter specified in the value parameter is already added to this or another OdbcParameterCollection.");
147 parameter.Container = this;
148 list.Add (parameter);
149 return parameter;
152 public OdbcParameter Add (string name, object value)
154 return Add (new OdbcParameter (name, value));
157 public OdbcParameter Add (string name, OdbcType type)
159 return Add (new OdbcParameter (name, type));
162 public OdbcParameter Add (string name, OdbcType type, int width)
164 return Add (new OdbcParameter (name, type, width));
167 public OdbcParameter Add (string name, OdbcType type,
168 int width, string src_col)
170 return Add (new OdbcParameter (name, type, width, src_col));
173 internal void Bind(IntPtr hstmt)
175 for (int i=0;i<Count;i++)
177 this[i].Bind(hstmt,i+1);
182 int IList.Add (object value)
184 if (!(value is IDataParameter))
185 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 ((OdbcParameter[])(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 (OdbcParameter p in list)
258 p.Container = null;
260 list.Clear ();
263 public bool Contains (object value)
265 if (!(value is OdbcParameter))
266 throw new InvalidCastException ("The parameter was not an OdbcParameter.");
267 return Contains (((OdbcParameter) value).ParameterName);
270 public bool Contains (string value)
272 foreach (OdbcParameter 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 OdbcParameter))
291 throw new InvalidCastException ("The parameter was not an OdbcParameter.");
292 return IndexOf (((OdbcParameter) 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 ((OdbcParameter) 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));
327 #endregion // Methods