[System.DirectoryServices] Rename method parameters to match .NET contract
[mono.git] / mcs / class / System.DirectoryServices / System.DirectoryServices / PropertyValueCollection.cs
1 /******************************************************************************
2 * The MIT License
3 * Copyright (c) 2003 Novell Inc.,  www.novell.com
4
5 * Permission is hereby granted, free of charge, to any person obtaining  a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including  without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
9 * copies of the Software, and to  permit persons to whom the Software is 
10 * furnished to do so, subject to the following conditions:
11
12 * The above copyright notice and this permission notice shall be included in 
13 * all copies or substantial portions of the Software.
14
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *******************************************************************************/
23
24 //
25 // System.DirectoryServices.PropertyValueCollection .cs
26 //
27 // Author:
28 //   Sunil Kumar (sunilk@novell.com)
29 //
30 // (C)  Novell Inc.
31 //
32 using System;
33 using System.Collections;
34
35 namespace System.DirectoryServices
36 {
37         public class PropertyValueCollection : CollectionBase
38         {
39
40                 private bool _Mbit;
41                 private DirectoryEntry _parent;
42
43                 internal PropertyValueCollection(DirectoryEntry parent):base()
44                 {
45                         _Mbit = false;
46                         _parent = parent;
47                 }
48
49                 internal bool Mbit
50                 {
51                         get
52                         {
53                                 return _Mbit;
54                         }
55                         set
56                         {
57                                 _Mbit = value;
58                         }
59                 }
60
61                 public object  this[ int index ]  
62                 {
63                         get  
64                         {
65                                 return( (object) List[index] );
66                         }
67                         set  
68                         {
69                                 List[index] = value;
70                                 _Mbit = true;
71                         }
72                 }
73
74                 public int Add( object value )  
75                 {
76                         if(Contains(value))
77                         {
78                                 return -1;
79                         }
80                         else
81                         {
82                                 _Mbit=true;
83                                 return( List.Add( value ) );
84                         }
85
86                 }
87
88                 public void AddRange(object[] value)
89                 {
90                         foreach (object val in value)
91                                 Add (val);
92                 }
93
94                 public void AddRange (PropertyValueCollection value)
95                 {
96                         foreach (object val in value)
97                                 Add (val);
98                 }
99
100                 public int IndexOf( object value )  
101                 {
102                         return( List.IndexOf( value ) );
103                 }
104
105                 public void Insert( int index, object value )  
106                 {
107                         List.Insert( index, value );
108                         _Mbit = true;
109                 }
110
111                 public void Remove( object value )  
112                 {
113                         List.Remove( value );
114                         _Mbit = true;
115                 }
116
117                 public bool Contains( object value )  
118                 {
119                         return( List.Contains( value ) );
120                 }
121
122                 internal bool ContainsCaselessStringValue( string value )  
123                 {
124                         for(int i=0; i< this.Count; ++i)
125                         {
126                                 string lVal = (string) List[i];
127                                 if(String.Compare(value,lVal,true)==0)
128                                 {
129                                         return true;
130                                 }
131                         }
132                         return false;
133                 }
134
135                 public void CopyTo (object[] array, int index)
136                 {
137                         foreach (object o in List)
138                                 array[index++] = o;
139                 }
140
141                 [MonoTODO]
142                 protected override void OnClearComplete ()
143                 {
144                         if (_parent != null) {
145                                 _parent.CommitDeferred();
146                         }
147                 }
148
149                 [MonoTODO]
150                 protected override void OnInsertComplete (int index, object value)
151                 {
152                         if (_parent != null) {
153                                 _parent.CommitDeferred();
154                         }
155                 }
156
157                 [MonoTODO]
158                 protected override void OnRemoveComplete (int index, object value)
159                 {
160                         if (_parent != null) {
161                                 _parent.CommitDeferred();
162                         }
163                 }
164
165                 [MonoTODO]
166                 protected override void OnSetComplete (int index, object oldValue, object newValue)
167                 {
168                         if (_parent != null) {
169                                 _parent.CommitDeferred();
170                         }
171                 }
172
173                 [MonoTODO]
174                 public string PropertyName
175                 {
176                         get
177                         {
178                                 return string.Empty;
179                         }
180                 }
181
182                 public object Value 
183                 {
184                         get
185                         {
186                                 switch (Count) {
187                                         case 0 : 
188                                                 return null;
189                                         case 1 :
190                                                 return (object) List[0];
191                                         default :
192 //                                      System.Object[] oArray= new System.Object[this.Count];
193 //                                      object[] oArray= new object[this.Count];
194 //                                      Array.Copy((System.Array)List,0,(System.Array)oArray,0,this.Count);
195                                                 Array LArray = new object[Count];
196                                                 for ( int i = LArray.GetLowerBound(0); i <= LArray.GetUpperBound(0); i++ )
197                                                         LArray.SetValue( List[i], i );
198                                                 return LArray;
199                                 }
200                         }
201                         set
202                         {
203                                 if (value == null && List.Count == 0)
204                                         return;
205
206                                 List.Clear();
207                                 if (value != null) {
208                                         Add(value);
209                                 }
210                                 _Mbit = true;
211                         }
212                 }
213
214         }
215 }