added NET_2_0 strongly typed overrides
[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                         }
71                 }
72
73                 public int Add( object value )  
74                 {
75                         if(Contains(value))
76                         {
77                                 return -1;
78                         }
79                         else
80                         {
81                                 _Mbit=true;
82                                 return( List.Add( value ) );
83                         }
84
85                 }
86
87                 public void AddRange(object[] values)
88                 {
89                         foreach (object value in values)
90                                 Add (value);
91                 }
92
93                 public void AddRange (PropertyValueCollection coll)
94                 {
95                         foreach (object value in coll)
96                                 Add (value);
97                 }
98
99                 public int IndexOf( object value )  
100                 {
101                         return( List.IndexOf( value ) );
102                 }
103
104                 public void Insert( int index, object value )  
105                 {
106                         List.Insert( index, value );
107                 }
108
109                 public void Remove( object value )  
110                 {
111                         List.Remove( value );
112                 }
113
114                 public bool Contains( object value )  
115                 {
116                         return( List.Contains( value ) );
117                 }
118
119                 internal bool ContainsCaselessStringValue( string value )  
120                 {
121                         for(int i=0; i< this.Count; ++i)
122                         {
123                                 string lVal = (string) List[i];
124                                 if(String.Compare(value,lVal,true)==0)
125                                 {
126                                         return true;
127                                 }
128                         }
129                         return false;
130                 }
131
132                 public void CopyTo (object[] copy_to, int index)
133                 {
134                         foreach (object o in List)
135                                 copy_to[index++] = o;
136                 }
137
138                 [MonoTODO]
139                 protected override void OnClearComplete ()
140                 {
141                         if (_parent != null) {
142                                 _parent.CommitDeferred();
143                         }
144                 }
145
146                 [MonoTODO]
147                 protected override void OnInsertComplete (int index, object value)
148                 {
149                         if (_parent != null) {
150                                 _parent.CommitDeferred();
151                         }
152                 }
153
154                 [MonoTODO]
155                 protected override void OnRemoveComplete (int index, object value)
156                 {
157                         if (_parent != null) {
158                                 _parent.CommitDeferred();
159                         }
160                 }
161
162                 [MonoTODO]
163                 protected override void OnSetComplete (int index, object oldValue, object newValue)
164                 {
165                         if (_parent != null) {
166                                 _parent.CommitDeferred();
167                         }
168                 }
169
170                 public object Value 
171                 {
172                         get
173                         {
174                                 switch (Count) {
175                                         case 0 : 
176                                                 return null;
177                                         case 1 :
178                                                 return (object) List[0];
179                                         default :
180 //                                      System.Object[] oArray= new System.Object[this.Count];
181 //                                      object[] oArray= new object[this.Count];
182 //                                      Array.Copy((System.Array)List,0,(System.Array)oArray,0,this.Count);
183                                                 Array LArray = new object[Count];
184                                                 for ( int i = LArray.GetLowerBound(0); i <= LArray.GetUpperBound(0); i++ )
185                                                         LArray.SetValue( List[i], i );
186                                                 return LArray;
187                                 }
188                         }
189                         set
190                         {
191                                 List.Clear();
192                                 if (value != null) {
193                                         Add(value);
194                                 }
195                         }
196                 }
197
198         }
199 }