2 * Firebird ADO.NET Data provider for .NET and Mono
4 * The contents of this file are subject to the Initial
5 * Developer's Public License Version 1.0 (the "License");
6 * you may not use this file except in compliance with the
7 * License. You may obtain a copy of the License at
8 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 * Software distributed under the License is distributed on
11 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
12 * express or implied. See the License for the specific
13 * language governing rights and limitations under the License.
15 * Copyright (c) 2002, 2005 Carlos Guzman Alvarez
16 * All Rights Reserved.
21 using System.ComponentModel;
22 using System.Collections;
23 using System.Globalization;
25 using FirebirdSql.Data.Common;
27 namespace FirebirdSql.Data.Firebird
29 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/overview/*'/>
32 [Editor(typeof(Design.FbParameterCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
34 public sealed class FbParameterCollection : MarshalByRefObject, IDataParameterCollection, IList, ICollection, IEnumerable
38 private ArrayList parameters;
44 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/indexer[@name="Item(System.String)"]/*'/>
46 [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
48 public FbParameter this[string parameterName]
50 get { return (FbParameter)this[this.IndexOf(parameterName)]; }
51 set { this[this.IndexOf(parameterName)] = (FbParameter)value; }
54 object IDataParameterCollection.this[string parameterName]
56 get { return this[parameterName]; }
57 set { this[parameterName] = (FbParameter)value; }
60 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/indexer[@name="Item(System.Int32)"]/*'/>
62 [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
64 public FbParameter this[int index]
66 get { return (FbParameter)this.parameters[index]; }
67 set { this.parameters[index] = (FbParameter)value; }
70 object IList.this[int index]
72 get { return (FbParameter)this[index]; }
73 set { this[index] = (FbParameter)value; }
80 internal FbParameterCollection()
82 this.parameters = ArrayList.Synchronized(new ArrayList());
87 #region IList Properties
89 bool IList.IsFixedSize
91 get { return this.parameters.IsFixedSize; }
96 get { return this.parameters.IsReadOnly; }
101 #region ICollection Properties
103 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/property[@name="Count"]/*'/>
105 [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
109 get { return this.parameters.Count; }
112 bool ICollection.IsSynchronized
114 get { return this.parameters.IsSynchronized; }
117 object ICollection.SyncRoot
119 get { return this.parameters.SyncRoot; }
124 #region ICollection Methods
126 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="CopyTo(System.Array,System.Int32)"]/*'/>
127 public void CopyTo(Array array, int index)
129 this.parameters.CopyTo(array, index);
134 #region IList Methods
136 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="Clear"]/*'/>
139 this.parameters.Clear();
144 #region IEnumerable Methods
146 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="GetEnumerator"]/*'/>
147 public IEnumerator GetEnumerator()
149 return this.parameters.GetEnumerator();
156 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="Contains(System.Object)"]/*'/>
157 public bool Contains(object value)
159 return this.parameters.Contains(value);
162 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="Contains(System.String)"]/*'/>
163 public bool Contains(string parameterName)
165 return (-1 != this.IndexOf(parameterName));
168 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="IndexOf(System.Object)"]/*'/>
169 public int IndexOf(object value)
171 return this.parameters.IndexOf(value);
174 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="IndexOf(System.String)"]/*'/>
175 public int IndexOf(string parameterName)
178 foreach (FbParameter item in this.parameters)
180 if (GlobalizationHelper.CultureAwareCompare(item.ParameterName, parameterName))
189 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="Insert(System.Int32,System.Object)"]/*'/>
190 public void Insert(int index, object value)
192 this.parameters.Insert(index, value);
195 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="Remove(System.Object)"]/*'/>
196 public void Remove(object value)
198 if (!(value is FbParameter))
200 throw new InvalidCastException("The parameter passed was not a FbParameter.");
202 if (!this.Contains(value))
204 throw new SystemException("The parameter does not exist in the collection.");
207 this.parameters.Remove(value);
209 ((FbParameter)value).Parent = null;
212 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="RemoveAt(System.Int32)"]/*'/>
213 public void RemoveAt(int index)
215 if (index < 0 || index > this.Count)
217 throw new IndexOutOfRangeException("The specified index does not exist.");
220 FbParameter parameter = this[index];
221 this.parameters.RemoveAt(index);
222 parameter.Parent = null;
225 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="RemoveAt(System.String)"]/*'/>
226 public void RemoveAt(string parameterName)
228 this.RemoveAt(this.IndexOf(parameterName));
231 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="Add(System.String,System.Object)"]/*'/>
232 public FbParameter Add(string parameterName, object value)
234 FbParameter param = new FbParameter(parameterName, value);
236 return this.Add(param);
239 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="Add(System.String,FbDbType)"]/*'/>
240 public FbParameter Add(string parameterName, FbDbType type)
242 FbParameter param = new FbParameter(parameterName, type);
244 return this.Add(param);
247 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="Add(System.String,FbDbType,System.Int32)"]/*'/>
248 public FbParameter Add(string parameterName, FbDbType fbType, int size)
250 FbParameter param = new FbParameter(parameterName, fbType, size);
252 return this.Add(param);
255 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="Add(System.String,FbDbType,System.Int32,System.String)"]/*'/>
256 public FbParameter Add(
257 string parameterName, FbDbType fbType, int size, string sourceColumn)
259 FbParameter param = new FbParameter(parameterName, fbType, size, sourceColumn);
261 return this.Add(param);
264 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="Add(System.Object)"]/*'/>
265 public int Add(object value)
267 if (!(value is FbParameter))
269 throw new InvalidCastException("The parameter passed was not a FbParameter.");
272 return this.IndexOf(this.Add(value as FbParameter));
275 /// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="Add(FbParameter)"]/*'/>
276 public FbParameter Add(FbParameter value)
278 lock (this.parameters.SyncRoot)
282 throw new ArgumentException("The value parameter is null.");
284 if (value.Parent != null)
286 throw new ArgumentException("The FbParameter specified in the value parameter is already added to this or another FbParameterCollection.");
288 if (value.ParameterName == null ||
289 value.ParameterName.Length == 0)
291 value.ParameterName = this.GenerateParameterName();
295 if (this.IndexOf(value) != -1)
297 throw new ArgumentException("FbParameterCollection already contains FbParameter with ParameterName '" + value.ParameterName + "'.");
301 this.parameters.Add(value);
309 #region Private Methods
311 private string GenerateParameterName()
313 int index = this.Count + 1;
314 string name = String.Empty;
318 name = "Parameter" + index.ToString(CultureInfo.InvariantCulture);
320 if (this.IndexOf(name) == -1)