Files
mono/mcs/class/System.Data/System.Data.SqlClient/SqlParameterCollection.cs
T
Tim Coleman 9efe5974b7 2002-11-04 Tim Coleman <[email protected]>
* list:
                Add Mono.Data.TdsClient.Internal.TdsBigDecimal
                Add System.Data.SqlClient.SqlParameterConverter
                Add System.Data.DataSysDescriptionAttribute
        * System.Data/DataSysDescriptionAttribute.cs:
                New class added
        * System.Data.Common/DbDataPermission.cs:
                Add CreateInstance method
        * System.Data.SqlClient/SqlClientPermission.cs:
        * System.Data.SqlClient/SqlError.cs:
                Add Serializable attribute
        * System.Data.SqlClient/SqlCommand.cs:
        * System.Data.SqlClient/SqlConnection.cs:
        * System.Data.SqlClient/SqlDataAdapter.cs:
        * System.Data.SqlClient/SqlParameter.cs:
                Add some missing property attributes
        * System.Data.SqlClient/SqlCommandBuilder.cs:
                Add some missing property attributes
                Implement properties
        * System.Data.SqlClient/SqlDataReader.cs:
                Implement missing methods
        * System.Data.SqlClient/SqlErrorCollection.cs:
                Implement the properties
        * System.Data.SqlClient/SqlException.cs:
                Remove extra property accessors
        * System.Data.SqlClient/SqlInfoMessageEventArgs.cs:
                Add internal constructor
        * System.Data.SqlClient/SqlParameterCollection.cs:
                Add internal constructor
                Add property attributes
        * System.Data.SqlClient/SqlParameterConverter.cs:
                New internal class added
        * System.Data.SqlClient/SqlRowUpdatedEventArgs.cs:
        * System.Data.SqlClient/SqlRowUpdatingEventArgs.cs:
                Remove destructor
        * System.Data.SqlTypes/SqlDecimal.cs:
                Add implicit conversion from TdsBigDecimal to SqlDecimal
        * System.Data.SqlTypes/SqlString.cs:
        * System.Data.SqlTypes/SqlInt16.cs:
        * System.Data.SqlTypes/SqlDateTime.cs:
                Change code to remove compiler warnings

svn path=/trunk/mcs/; revision=8813
2002-11-04 18:23:26 +00:00

238 lines
5.2 KiB
C#

//
// System.Data.SqlClient.SqlParameterCollection.cs
//
// Author:
// Rodrigo Moya ([email protected])
// Daniel Morgan ([email protected])
// Tim Coleman ([email protected])
//
// (C) Ximian, Inc 2002
// Copyright (C) Tim Coleman, 2002
//
using System;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Collections;
namespace System.Data.SqlClient {
[ListBindable (false)]
public sealed class SqlParameterCollection : MarshalByRefObject, IDataParameterCollection, IList, ICollection, IEnumerable
{
#region Fields
ArrayList list = new ArrayList();
SqlCommand command;
#endregion // Fields
#region Constructors
internal SqlParameterCollection (SqlCommand command)
{
this.command = command;
}
#endregion // Constructors
#region Properties
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public int Count {
get { return list.Count; }
}
object IList.this [int index] {
[MonoTODO]
get {
return (SqlParameter) this[index];
}
[MonoTODO]
set {
this[index] = (SqlParameter) value;
}
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public SqlParameter this [int index] {
get { return (SqlParameter) list[index]; }
set { list[index] = (SqlParameter) value; }
}
object IDataParameterCollection.this [string parameterName] {
get { return this[parameterName]; }
set {
CheckType(value);
this[parameterName] = (SqlParameter) value;
}
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public SqlParameter this [string parameterName] {
get {
foreach (SqlParameter p in list)
if (p.ParameterName.Equals (parameterName))
return p;
throw new IndexOutOfRangeException ("The specified name does not exist: " + parameterName);
}
set {
if (!Contains (parameterName))
throw new IndexOutOfRangeException("The specified name does not exist: " + parameterName);
this [IndexOf (parameterName)] = value;
}
}
bool IList.IsFixedSize {
get { throw new NotImplementedException (); }
}
bool IList.IsReadOnly {
get { throw new NotImplementedException (); }
}
bool ICollection.IsSynchronized {
get { throw new NotImplementedException (); }
}
object ICollection.SyncRoot {
get { throw new NotImplementedException (); }
}
#endregion // Properties
#region Methods
public int Add (object value)
{
// Check if value is a SqlParameter.
CheckType (value);
Add ((SqlParameter) value);
return IndexOf (value);
}
public SqlParameter Add (SqlParameter value)
{
list.Add (value);
return value;
}
public SqlParameter Add (string parameterName, object value)
{
SqlParameter sqlparam = new SqlParameter();
sqlparam.Value = value;
// TODO: Get the dbtype and Sqldbtype from system type of value.
return Add(sqlparam);
}
public SqlParameter Add (string parameterName, SqlDbType sqlDbType)
{
SqlParameter sqlparam = new SqlParameter();
sqlparam.ParameterName = parameterName;
sqlparam.SqlDbType = sqlDbType;
return Add(sqlparam);
}
public SqlParameter Add (string parameterName, SqlDbType sqlDbType, int size)
{
SqlParameter sqlparam = new SqlParameter();
sqlparam.ParameterName = parameterName;
sqlparam.SqlDbType = sqlDbType;
sqlparam.Size = size;
return Add(sqlparam);
}
public SqlParameter Add (string parameterName, SqlDbType sqlDbType, int size, string sourceColumn)
{
SqlParameter sqlparam = new SqlParameter ();
sqlparam.ParameterName = parameterName;
sqlparam.SqlDbType = sqlDbType;
sqlparam.Size = size;
sqlparam.SourceColumn = sourceColumn;
return Add (sqlparam);
}
public void Clear()
{
list.Clear ();
}
public bool Contains (object value)
{
CheckType (value);
return Contains (((SqlParameter) value).ParameterName);
}
public bool Contains (string value)
{
foreach (SqlParameter p in list)
if (p.ParameterName.Equals (value))
return true;
return false;
}
[MonoTODO]
public void CopyTo(Array array, int index)
{
throw new NotImplementedException ();
}
public IEnumerator GetEnumerator()
{
return list.GetEnumerator ();
}
public int IndexOf (object value)
{
CheckType (value);
return IndexOf (((SqlParameter) value).ParameterName);
}
public int IndexOf (string parameterName)
{
return list.IndexOf (parameterName);
}
public void Insert (int index, object value)
{
list.Insert (index, value);
}
public void Remove (object value)
{
list.Remove (value);
}
public void RemoveAt (int index)
{
list.RemoveAt (index);
}
public void RemoveAt (string parameterName)
{
RemoveAt (IndexOf (parameterName));
}
/// <summary>
/// This method checks if the parameter value is of
/// SqlParameter type. If it doesn't, throws an InvalidCastException.
/// </summary>
private void CheckType(object value)
{
if(!(value is SqlParameter))
throw new InvalidCastException("Only SQLParameter objects can be used.");
}
#endregion // Methods
}
}