Copied remotely
[mono.git] / mcs / class / System.Data / System.Data.SqlClient / SqlParameterCollection.cs
index 634d884fadc0e2145df8e68dd96a8fec70ae5bfc..ca74bf393097909b687824f00921fcd5b94ddb72 100644 (file)
@@ -5,24 +5,60 @@
 //   Rodrigo Moya (rodrigo@ximian.com)
 //   Daniel Morgan (danmorg@sc.rr.com)
 //   Tim Coleman (tim@timcoleman.com)
+//   Diego Caravana (diego@toth.it)
 //
 // (C) Ximian, Inc 2002
 // Copyright (C) Tim Coleman, 2002
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using Mono.Data.Tds;
 using System;
 using System.ComponentModel;
 using System.Data;
 using System.Data.Common;
+
+#if NET_2_0
+using System.Data.ProviderBase;
+#endif // NET_2_0
+
 using System.Collections;
 
 namespace System.Data.SqlClient {
        [ListBindable (false)]
+       [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DataParametersEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
+#if NET_2_0
+       public sealed class SqlParameterCollection : DbParameterBaseCollection, IDataParameterCollection, IList, ICollection, IEnumerable
+#else
        public sealed class SqlParameterCollection : MarshalByRefObject, IDataParameterCollection, IList, ICollection, IEnumerable
+#endif // NET_2_0
        {
                #region Fields
 
                ArrayList list = new ArrayList();
+               TdsMetaParameterCollection metaParameters;
                SqlCommand command;
 
                #endregion // Fields
@@ -32,6 +68,7 @@ namespace System.Data.SqlClient {
                internal SqlParameterCollection (SqlCommand command)
                {
                        this.command = command;
+                       metaParameters = new TdsMetaParameterCollection ();
                }
 
                #endregion // Constructors
@@ -40,13 +77,21 @@ namespace System.Data.SqlClient {
 
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]      
-               public int Count {
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        int Count {
                        get { return list.Count; }                        
                }
 
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]      
-               public SqlParameter this [int index] {
+               public 
+#if NET_2_0
+               new
+#endif // NET_2_0
+        SqlParameter this [int index] {
                        get { return (SqlParameter) list [index]; }                       
                        set { list [index] = (SqlParameter) value; }                      
                }
@@ -62,7 +107,11 @@ namespace System.Data.SqlClient {
 
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]      
-               public SqlParameter this [string parameterName] {
+               public 
+#if NET_2_0
+               new
+#endif // NET_2_0
+        SqlParameter this [string parameterName] {
                        get {
                                foreach (SqlParameter p in list)
                                        if (p.ParameterName.Equals (parameterName))
@@ -96,12 +145,20 @@ namespace System.Data.SqlClient {
                object ICollection.SyncRoot {
                        get { return list.SyncRoot; }
                }
+
+               internal TdsMetaParameterCollection MetaParameters {
+                       get { return metaParameters; }
+               }
                
                #endregion // Properties
 
                #region Methods
 
-               public int Add (object value)
+               public  
+#if NET_2_0
+               override
+#endif // NET_2_0
+        int Add (object value)
                {
                        if (!(value is SqlParameter))
                                throw new InvalidCastException ("The parameter was not an SqlParameter.");
@@ -116,6 +173,7 @@ namespace System.Data.SqlClient {
                        
                        value.Container = this;
                        list.Add (value);
+                       metaParameters.Add (value.MetaParameter);
                        return value;
                }
                
@@ -139,19 +197,36 @@ namespace System.Data.SqlClient {
                        return Add (new SqlParameter (parameterName, sqlDbType, size, sourceColumn));
                }
 
-               public void Clear()
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        void Clear()
                {
+                       metaParameters.Clear ();
+                       
+                       foreach (SqlParameter p in list)
+                               p.Container = null;
+                       
                        list.Clear ();
                }
                
-               public bool Contains (object value)
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        bool Contains (object value)
                {
                        if (!(value is SqlParameter))
                                throw new InvalidCastException ("The parameter was not an SqlParameter.");
                        return Contains (((SqlParameter) value).ParameterName);
                }
 
-               public bool Contains (string value)
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        bool Contains (string value)
                {
                        foreach (SqlParameter p in list)
                                if (p.ParameterName.Equals (value))
@@ -159,48 +234,101 @@ namespace System.Data.SqlClient {
                        return false;
                }
 
-               public void CopyTo (Array array, int index)
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        void CopyTo (Array array, int index)
                {
                        list.CopyTo (array, index);
                }
 
-               public IEnumerator GetEnumerator()
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        IEnumerator GetEnumerator()
                {
                        return list.GetEnumerator ();
                }
                
-               public int IndexOf (object value)
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        int IndexOf (object value)
                {
                        if (!(value is SqlParameter))
                                throw new InvalidCastException ("The parameter was not an SqlParameter.");
                        return IndexOf (((SqlParameter) value).ParameterName);
                }
                
-               public int IndexOf (string parameterName)
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        int IndexOf (string parameterName)
                {
-                       return list.IndexOf (parameterName);
+                       for (int i = 0; i < Count; i += 1)
+                                if (this [i].ParameterName.Equals (parameterName))
+                                        return i;
+                        return -1;
+
                }
 
-               public void Insert (int index, object value)
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        void Insert (int index, object value)
                {
                        list.Insert (index, value);
                }
 
-               public void Remove (object value)
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        void Remove (object value)
                {
+                       ((SqlParameter) value).Container = null;
+                       
+                       metaParameters.Remove (((SqlParameter) value).MetaParameter);
                        list.Remove (value);
                }
 
-               public void RemoveAt (int index)
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        void RemoveAt (int index)
                {
+                       this [index].Container = null;
+                       metaParameters.RemoveAt (index);
                        list.RemoveAt (index);
                }
 
-               public void RemoveAt (string parameterName)
+               public 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        void RemoveAt (string parameterName)
                {
                        RemoveAt (IndexOf (parameterName));
                }
 
+                [MonoTODO]
+                protected 
+#if NET_2_0
+               override
+#endif // NET_2_0
+        Type ItemType
+                {
+                        get {throw new NotImplementedException ();}
+                        
+                }
+
+
                #endregion // Methods   
        }
 }