#if NET40 || NET461 // Copyright © 2004, 2013, Oracle and/or its affiliates. All rights reserved. // // MySQL Connector/NET is licensed under the terms of the GPLv2 // , like most // MySQL Connectors. There are special exceptions to the terms and // conditions of the GPLv2 as it is applied to this software, see the // FLOSS License Exception // . // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published // by the Free Software Foundation; version 2 of the License. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using Externals.MySql.Data.MySqlClient.Properties; using System; using System.Collections; using System.ComponentModel; using System.Data.Common; namespace Externals.MySql.Data.MySqlClient { [Editor("Externals.MySql.Data.MySqlClient.Design.DBParametersEditor,MySql.Design", typeof(System.Drawing.Design.UITypeEditor))] [ListBindable(true)] internal sealed partial class MySqlParameterCollection : DbParameterCollection { /// /// Adds a to the with the parameter name, the data type, the column length, and the source column name. /// /// The name of the parameter. /// One of the values. /// The length of the column. /// The name of the source column. /// The newly added object. public MySqlParameter Add(string parameterName, MySqlDbType dbType, int size, string sourceColumn) { return Add(new MySqlParameter(parameterName, dbType, size, sourceColumn)); } #region DbParameterCollection Implementation /// /// Adds an array of values to the end of the . /// /// public override void AddRange(Array values) { foreach (DbParameter p in values) Add(p); } /// /// Retrieve the parameter with the given name. /// /// /// protected override DbParameter GetParameter(string parameterName) { return (DbParameter)InternalGetParameter(parameterName); } protected override DbParameter GetParameter(int index) { return (DbParameter)InternalGetParameter(index); } protected override void SetParameter(string parameterName, DbParameter value) { InternalSetParameter(parameterName, value as MySqlParameter); } protected override void SetParameter(int index, DbParameter value) { InternalSetParameter(index, value as MySqlParameter); } /// /// Adds the specified object to the . /// /// The to add to the collection. /// The index of the new object. public override int Add(object value) { MySqlParameter parameter = value as MySqlParameter; if (parameter == null) throw new MySqlException("Only MySqlParameter objects may be stored"); parameter = Add(parameter); return IndexOf(parameter); } /// /// Gets a value indicating whether a with the specified parameter name exists in the collection. /// /// The name of the object to find. /// true if the collection contains the parameter; otherwise, false. public override bool Contains(string parameterName) { return IndexOf(parameterName) != -1; } /// /// Gets a value indicating whether a MySqlParameter exists in the collection. /// /// The value of the object to find. /// true if the collection contains the object; otherwise, false. /// Gets a value indicating whether a exists in the collection. public override bool Contains(object value) { MySqlParameter parameter = value as MySqlParameter; if (null == parameter) throw new ArgumentException("Argument must be of type DbParameter", "value"); return items.Contains(parameter); } /// /// Copies MySqlParameter objects from the MySqlParameterCollection to the specified array. /// /// /// public override void CopyTo(Array array, int index) { items.ToArray().CopyTo(array, index); } /// /// Returns an enumerator that iterates through the . /// /// public override IEnumerator GetEnumerator() { return items.GetEnumerator(); } /// /// Inserts a MySqlParameter into the collection at the specified index. /// /// /// public override void Insert(int index, object value) { MySqlParameter parameter = value as MySqlParameter; if (parameter == null) throw new MySqlException("Only MySqlParameter objects may be stored"); InternalAdd(parameter, index); } /// /// Gets a value that indicates whether the /// has a fixed size. /// public override bool IsFixedSize { get { return (items as IList).IsFixedSize; } } /// /// Gets a value that indicates whether the /// is read-only. /// public override bool IsReadOnly { get { return (items as IList).IsReadOnly; } } /// /// Gets a value that indicates whether the /// is synchronized. /// public override bool IsSynchronized { get { return (items as IList).IsSynchronized; } } /// /// Removes the specified MySqlParameter from the collection. /// /// public override void Remove(object value) { MySqlParameter p = (value as MySqlParameter); p.Collection = null; int index = IndexOf(p); items.Remove(p); indexHashCS.Remove(p.ParameterName); indexHashCI.Remove(p.ParameterName); AdjustHashes(index, false); } /// /// Removes the specified from the collection using the parameter name. /// /// The name of the object to retrieve. public override void RemoveAt(string parameterName) { DbParameter p = GetParameter(parameterName); Remove(p); } /// /// Removes the specified from the collection using a specific index. /// /// The zero-based index of the parameter. /// Removes the specified from the collection. public override void RemoveAt(int index) { object o = items[index]; Remove(o); } /// /// Gets an object that can be used to synchronize access to the /// . /// public override object SyncRoot { get { return (items as IList).SyncRoot; } } #endregion } } #endif