PageRenderTime 23ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/mcs/class/System.DirectoryServices/System.DirectoryServices/PropertyValueCollection.cs

https://bitbucket.org/danipen/mono
C# | 215 lines | 158 code | 24 blank | 33 comment | 19 complexity | 63f88edc88561ac8d30b5c4034c41ec3 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  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. // System.DirectoryServices.PropertyValueCollection .cs
  25. //
  26. // Author:
  27. // Sunil Kumar (sunilk@novell.com)
  28. //
  29. // (C) Novell Inc.
  30. //
  31. using System;
  32. using System.Collections;
  33. namespace System.DirectoryServices
  34. {
  35. public class PropertyValueCollection : CollectionBase
  36. {
  37. private bool _Mbit;
  38. private DirectoryEntry _parent;
  39. internal PropertyValueCollection(DirectoryEntry parent):base()
  40. {
  41. _Mbit = false;
  42. _parent = parent;
  43. }
  44. internal bool Mbit
  45. {
  46. get
  47. {
  48. return _Mbit;
  49. }
  50. set
  51. {
  52. _Mbit = value;
  53. }
  54. }
  55. public object this[ int index ]
  56. {
  57. get
  58. {
  59. return( (object) List[index] );
  60. }
  61. set
  62. {
  63. List[index] = value;
  64. _Mbit = true;
  65. }
  66. }
  67. public int Add( object value )
  68. {
  69. if(Contains(value))
  70. {
  71. return -1;
  72. }
  73. else
  74. {
  75. _Mbit=true;
  76. return( List.Add( value ) );
  77. }
  78. }
  79. public void AddRange(object[] values)
  80. {
  81. foreach (object value in values)
  82. Add (value);
  83. }
  84. public void AddRange (PropertyValueCollection coll)
  85. {
  86. foreach (object value in coll)
  87. Add (value);
  88. }
  89. public int IndexOf( object value )
  90. {
  91. return( List.IndexOf( value ) );
  92. }
  93. public void Insert( int index, object value )
  94. {
  95. List.Insert( index, value );
  96. _Mbit = true;
  97. }
  98. public void Remove( object value )
  99. {
  100. List.Remove( value );
  101. _Mbit = true;
  102. }
  103. public bool Contains( object value )
  104. {
  105. return( List.Contains( value ) );
  106. }
  107. internal bool ContainsCaselessStringValue( string value )
  108. {
  109. for(int i=0; i< this.Count; ++i)
  110. {
  111. string lVal = (string) List[i];
  112. if(String.Compare(value,lVal,true)==0)
  113. {
  114. return true;
  115. }
  116. }
  117. return false;
  118. }
  119. public void CopyTo (object[] copy_to, int index)
  120. {
  121. foreach (object o in List)
  122. copy_to[index++] = o;
  123. }
  124. [MonoTODO]
  125. protected override void OnClearComplete ()
  126. {
  127. if (_parent != null) {
  128. _parent.CommitDeferred();
  129. }
  130. }
  131. [MonoTODO]
  132. protected override void OnInsertComplete (int index, object value)
  133. {
  134. if (_parent != null) {
  135. _parent.CommitDeferred();
  136. }
  137. }
  138. [MonoTODO]
  139. protected override void OnRemoveComplete (int index, object value)
  140. {
  141. if (_parent != null) {
  142. _parent.CommitDeferred();
  143. }
  144. }
  145. [MonoTODO]
  146. protected override void OnSetComplete (int index, object oldValue, object newValue)
  147. {
  148. if (_parent != null) {
  149. _parent.CommitDeferred();
  150. }
  151. }
  152. [MonoTODO]
  153. public string PropertyName
  154. {
  155. get
  156. {
  157. return string.Empty;
  158. }
  159. }
  160. public object Value
  161. {
  162. get
  163. {
  164. switch (Count) {
  165. case 0 :
  166. return null;
  167. case 1 :
  168. return (object) List[0];
  169. default :
  170. // System.Object[] oArray= new System.Object[this.Count];
  171. // object[] oArray= new object[this.Count];
  172. // Array.Copy((System.Array)List,0,(System.Array)oArray,0,this.Count);
  173. Array LArray = new object[Count];
  174. for ( int i = LArray.GetLowerBound(0); i <= LArray.GetUpperBound(0); i++ )
  175. LArray.SetValue( List[i], i );
  176. return LArray;
  177. }
  178. }
  179. set
  180. {
  181. if (value == null && List.Count == 0)
  182. return;
  183. List.Clear();
  184. if (value != null) {
  185. Add(value);
  186. }
  187. _Mbit = true;
  188. }
  189. }
  190. }
  191. }