PropertyDescriptorCollection.cs 5.2 KB

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