2002-10-31 Tim Coleman (tim@timcoleman.com)
[mono.git] / mcs / class / Mono.Data.TdsClient / Mono.Data.TdsClient / TdsParameterCollection.cs
1 //
2 // Mono.Data.TdsClient.TdsParameterCollection.cs
3 //
4 // Author:
5 //   Tim Coleman (tim@timcoleman.com)
6 //
7 // Copyright (C) Tim Coleman, 2002
8 //
9
10 using Mono.Data.TdsClient.Internal;
11 using System;
12 using System.Collections;
13 using System.ComponentModel;
14 using System.Data;
15 using System.Data.Common;
16 using System.Runtime.InteropServices;
17
18 namespace Mono.Data.TdsClient {
19         public sealed class TdsParameterCollection : MarshalByRefObject, IDataParameterCollection, IList, ICollection, IEnumerable
20         {
21                 #region Fields
22
23                 ArrayList list = new ArrayList ();
24
25                 #endregion // Fields
26
27                 #region Properties
28
29                 public int Count {
30                         get { return list.Count; }
31                 }
32
33                 object IList.this [int index] {
34                         get { return (TdsParameter) this[index]; }
35                         set { this[index] = (TdsParameter) value; }
36                 }
37
38                 public TdsParameter this [int index] {
39                         get { 
40                                 if (index >= Count)
41                                         throw new IndexOutOfRangeException ();
42                                 return (TdsParameter) list[index]; 
43                         }
44                         set { 
45                                 if (index >= Count)
46                                         throw new IndexOutOfRangeException ();
47                                 list[index] = (TdsParameter) value; 
48                         }
49                 }
50
51                 object IDataParameterCollection.this [string parameterName] {
52                         get { return (TdsParameter) this[parameterName]; }
53                         set { this [parameterName] = (TdsParameter) value; }
54                 }
55
56                 public TdsParameter this [string parameterName] {
57                         get { return this[IndexOf (parameterName)]; }
58                         set { this[IndexOf (parameterName)] = value; }
59                 }
60
61                 bool IList.IsFixedSize {
62                         get { return false; }
63                 }
64
65                 bool IList.IsReadOnly {
66                         get { return false; }
67                 }
68
69                 bool ICollection.IsSynchronized {
70                         [MonoTODO]
71                         get { throw new NotImplementedException (); }
72                 }
73
74                 object ICollection.SyncRoot {
75                         [MonoTODO]
76                         get { throw new NotImplementedException (); }
77                 }
78
79                 #endregion // Properties
80
81                 #region Methods 
82
83                 public int Add (object value)
84                 {
85                         if (!(value is TdsParameter))
86                                 throw new InvalidCastException ();
87                         Add ((TdsParameter) value);
88                         return IndexOf (value);
89                 }
90
91                 public TdsParameter Add (TdsParameter value)
92                 {
93                         list.Add (value);
94                         return value; 
95                 }
96
97                 public TdsParameter Add (string parameterName, object value)
98                 {
99                         return Add (new TdsParameter (parameterName, value));
100                 }
101
102                 public void Clear ()
103                 {
104                         list.Clear ();
105                 }
106
107                 public bool Contains (object value)
108                 {
109                         return list.Contains (value);
110                 }
111
112                 public bool Contains (string value)
113                 {
114                         return (IndexOf (value) >= 0);
115                 }
116
117                 public void CopyTo (Array array, int index)
118                 {
119                         throw new NotImplementedException ();
120                 }
121
122                 public IEnumerator GetEnumerator ()
123                 {
124                         return list.GetEnumerator ();
125                 }
126
127                 public int IndexOf (object value)
128                 {
129                         return list.IndexOf (value);
130                 }
131
132                 public int IndexOf (string parameterName)
133                 {
134                         for (int i = 0; i < list.Count; i += 1) 
135                                 if (((TdsParameter) list[i]).ParameterName == parameterName)
136                                         return i;
137                         return -1;
138                 }
139
140                 public void Insert (int index, object value)
141                 {
142                         list.Insert (index, value);
143                 }
144
145                 public void Remove (object value)
146                 {
147                         list.Remove (value);
148                 }
149
150                 public void RemoveAt (int index)
151                 {
152                         list.RemoveAt (index);
153                 }
154
155                 public void RemoveAt (string parameterName)
156                 {
157                         RemoveAt (IndexOf (parameterName));
158                 }
159
160
161                 #endregion // Methods
162         }
163 }
164