PropertyDescriptorCollection.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. //
  2. // System.ComponentModel.PropertyDescriptorCollection.cs
  3. //
  4. // Authors:
  5. // Rodrigo Moya ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. //
  8. // (C) Rodrigo Moya, 2002
  9. // (c) 2002 Ximian, Inc. (http://www.ximian.com)
  10. //
  11. using System.Collections;
  12. namespace System.ComponentModel
  13. {
  14. /// <summary>
  15. /// Represents a collection of PropertyDescriptor objects.
  16. /// </summary>
  17. public class PropertyDescriptorCollection : IList, ICollection, IEnumerable, IDictionary
  18. {
  19. public static readonly PropertyDescriptorCollection Empty =
  20. new PropertyDescriptorCollection (null);
  21. ArrayList properties;
  22. bool readOnly;
  23. public PropertyDescriptorCollection (PropertyDescriptor[] properties)
  24. {
  25. this.properties = new ArrayList ();
  26. if (properties == null)
  27. return;
  28. foreach (PropertyDescriptor p in properties)
  29. this.properties.Add (p);
  30. }
  31. public int Add (PropertyDescriptor value)
  32. {
  33. properties.Add (value);
  34. return properties.Count - 1;
  35. }
  36. int IList.Add (object value)
  37. {
  38. return Add ((PropertyDescriptor) value);
  39. }
  40. void IDictionary.Add (object key, object value)
  41. {
  42. Add ((PropertyDescriptor) value);
  43. }
  44. public void Clear ()
  45. {
  46. properties.Clear ();
  47. }
  48. void IList.Clear ()
  49. {
  50. Clear ();
  51. }
  52. void IDictionary.Clear ()
  53. {
  54. Clear ();
  55. }
  56. public bool Contains (PropertyDescriptor value)
  57. {
  58. return properties.Contains (value);
  59. }
  60. bool IList.Contains (object value)
  61. {
  62. return Contains ((PropertyDescriptor) value);
  63. }
  64. bool IDictionary.Contains (object value)
  65. {
  66. return Contains ((PropertyDescriptor) value);
  67. }
  68. public void CopyTo (Array array, int index)
  69. {
  70. properties.CopyTo (array, index);
  71. }
  72. public virtual PropertyDescriptor Find (string name, bool ignoreCase)
  73. {
  74. foreach (PropertyDescriptor p in properties) {
  75. if (0 == String.Compare (name, p.Name, ignoreCase))
  76. return p;
  77. }
  78. return null;
  79. }
  80. public virtual IEnumerator GetEnumerator ()
  81. {
  82. return properties.GetEnumerator ();
  83. }
  84. [MonoTODO]
  85. IDictionaryEnumerator IDictionary.GetEnumerator ()
  86. {
  87. throw new NotImplementedException ();
  88. }
  89. public int IndexOf (PropertyDescriptor value)
  90. {
  91. return properties.IndexOf (value);
  92. }
  93. int IList.IndexOf (object value)
  94. {
  95. return IndexOf ((PropertyDescriptor) value);
  96. }
  97. [MonoTODO]
  98. public void Insert (int index, PropertyDescriptor value)
  99. {
  100. throw new NotImplementedException ();
  101. }
  102. void IList.Insert (int index, object value)
  103. {
  104. Insert (index, (PropertyDescriptor) value);
  105. }
  106. public void Remove (PropertyDescriptor value)
  107. {
  108. properties.Remove (value);
  109. }
  110. void IDictionary.Remove (object value)
  111. {
  112. Remove ((PropertyDescriptor) value);
  113. }
  114. void IList.Remove (object value)
  115. {
  116. Remove ((PropertyDescriptor) value);
  117. }
  118. public void RemoveAt (int index)
  119. {
  120. properties.RemoveAt (index);
  121. }
  122. void IList.RemoveAt (int index)
  123. {
  124. RemoveAt (index);
  125. }
  126. [MonoTODO]
  127. public virtual PropertyDescriptorCollection Sort ()
  128. {
  129. throw new NotImplementedException ();
  130. }
  131. [MonoTODO]
  132. public virtual PropertyDescriptorCollection Sort (IComparer ic)
  133. {
  134. throw new NotImplementedException ();
  135. }
  136. [MonoTODO]
  137. protected void InternalSort (IComparer ic)
  138. {
  139. throw new NotImplementedException ();
  140. }
  141. [MonoTODO]
  142. protected void InternalSort (string [] order)
  143. {
  144. throw new NotImplementedException ();
  145. }
  146. bool IDictionary.IsFixedSize
  147. {
  148. get {
  149. return !readOnly;
  150. }
  151. }
  152. bool IList.IsFixedSize
  153. {
  154. get {
  155. return !readOnly;
  156. }
  157. }
  158. public bool IsReadOnly
  159. {
  160. get {
  161. return readOnly;
  162. }
  163. }
  164. public bool IsSynchronized
  165. {
  166. get {
  167. return false;
  168. }
  169. }
  170. public int Count
  171. {
  172. get {
  173. return properties.Count;
  174. }
  175. }
  176. object ICollection.SyncRoot
  177. {
  178. get {
  179. return null;
  180. }
  181. }
  182. ICollection IDictionary.Keys
  183. {
  184. get {
  185. string [] keys = new string [properties.Count];
  186. int i = 0;
  187. foreach (PropertyDescriptor p in properties)
  188. keys [i++] = p.Name;
  189. return keys;
  190. }
  191. }
  192. ICollection IDictionary.Values
  193. {
  194. get {
  195. return (ICollection) properties.Clone ();
  196. }
  197. }
  198. object IDictionary.this [object key]
  199. {
  200. get {
  201. if (!(key is string))
  202. return null;
  203. return this [(string) key];
  204. }
  205. set {
  206. if (!(key is string) || (value as PropertyDescriptor) == null)
  207. throw new ArgumentException ();
  208. int idx = properties.IndexOf (value);
  209. if (idx == -1)
  210. Add ((PropertyDescriptor) value);
  211. else
  212. properties [idx] = value;
  213. }
  214. }
  215. public virtual PropertyDescriptor this [string s]
  216. {
  217. get {
  218. return Find (s, false);
  219. }
  220. }
  221. object IList.this [int index]
  222. {
  223. get {
  224. return properties [index];
  225. }
  226. set {
  227. properties [index] = value;
  228. }
  229. }
  230. public virtual PropertyDescriptor this [int index]
  231. {
  232. get {
  233. return (PropertyDescriptor) properties [index];
  234. }
  235. }
  236. }
  237. }