2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.DirectoryServices / System.DirectoryServices / PropertyValueCollection.cs
blob419efd3ea381516f16bbf05d8358b5c1a2fc2f80
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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 *******************************************************************************/
25 // System.DirectoryServices.PropertyValueCollection .cs
27 // Author:
28 // Sunil Kumar (sunilk@novell.com)
30 // (C) Novell Inc.
32 using System;
33 using System.Collections;
35 namespace System.DirectoryServices
37 public class PropertyValueCollection : CollectionBase
40 private bool _Mbit;
41 private DirectoryEntry _parent;
43 internal PropertyValueCollection(DirectoryEntry parent):base()
45 _Mbit = false;
46 _parent = parent;
49 internal bool Mbit
51 get
53 return _Mbit;
55 set
57 _Mbit = value;
61 public object this[ int index ]
63 get
65 return( (object) List[index] );
67 set
69 List[index] = value;
70 _Mbit = true;
74 public int Add( object value )
76 if(Contains(value))
78 return -1;
80 else
82 _Mbit=true;
83 return( List.Add( value ) );
88 public void AddRange(object[] values)
90 foreach (object value in values)
91 Add (value);
94 public void AddRange (PropertyValueCollection coll)
96 foreach (object value in coll)
97 Add (value);
100 public int IndexOf( object value )
102 return( List.IndexOf( value ) );
105 public void Insert( int index, object value )
107 List.Insert( index, value );
108 _Mbit = true;
111 public void Remove( object value )
113 List.Remove( value );
114 _Mbit = true;
117 public bool Contains( object value )
119 return( List.Contains( value ) );
122 internal bool ContainsCaselessStringValue( string value )
124 for(int i=0; i< this.Count; ++i)
126 string lVal = (string) List[i];
127 if(String.Compare(value,lVal,true)==0)
129 return true;
132 return false;
135 public void CopyTo (object[] copy_to, int index)
137 foreach (object o in List)
138 copy_to[index++] = o;
141 [MonoTODO]
142 protected override void OnClearComplete ()
144 if (_parent != null) {
145 _parent.CommitDeferred();
149 [MonoTODO]
150 protected override void OnInsertComplete (int index, object value)
152 if (_parent != null) {
153 _parent.CommitDeferred();
157 [MonoTODO]
158 protected override void OnRemoveComplete (int index, object value)
160 if (_parent != null) {
161 _parent.CommitDeferred();
165 [MonoTODO]
166 protected override void OnSetComplete (int index, object oldValue, object newValue)
168 if (_parent != null) {
169 _parent.CommitDeferred();
173 public object Value
177 switch (Count) {
178 case 0 :
179 return null;
180 case 1 :
181 return (object) List[0];
182 default :
183 // System.Object[] oArray= new System.Object[this.Count];
184 // object[] oArray= new object[this.Count];
185 // Array.Copy((System.Array)List,0,(System.Array)oArray,0,this.Count);
186 Array LArray = new object[Count];
187 for ( int i = LArray.GetLowerBound(0); i <= LArray.GetUpperBound(0); i++ )
188 LArray.SetValue( List[i], i );
189 return LArray;
194 if (value == null && List.Count == 0)
195 return;
197 List.Clear();
198 if (value != null) {
199 Add(value);
201 _Mbit = true;