PropertyDescriptorCollection.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. bool readOnly;
  25. public PropertyDescriptorCollection (PropertyDescriptor[] properties)
  26. {
  27. this.properties = new ArrayList ();
  28. if (properties == null)
  29. return;
  30. foreach (PropertyDescriptor p in properties)
  31. this.properties.Add (p);
  32. }
  33. public int Add (PropertyDescriptor value)
  34. {
  35. properties.Add (value);
  36. return properties.Count - 1;
  37. }
  38. int IList.Add (object value)
  39. {
  40. return Add ((PropertyDescriptor) value);
  41. }
  42. void IDictionary.Add (object key, object value)
  43. {
  44. Add ((PropertyDescriptor) value);
  45. }
  46. public void Clear ()
  47. {
  48. properties.Clear ();
  49. }
  50. void IList.Clear ()
  51. {
  52. Clear ();
  53. }
  54. void IDictionary.Clear ()
  55. {
  56. Clear ();
  57. }
  58. public bool Contains (PropertyDescriptor value)
  59. {
  60. return properties.Contains (value);
  61. }
  62. bool IList.Contains (object value)
  63. {
  64. return Contains ((PropertyDescriptor) value);
  65. }
  66. bool IDictionary.Contains (object value)
  67. {
  68. return Contains ((PropertyDescriptor) value);
  69. }
  70. public void CopyTo (Array array, int index)
  71. {
  72. properties.CopyTo (array, index);
  73. }
  74. public virtual PropertyDescriptor Find (string name, bool ignoreCase)
  75. {
  76. foreach (PropertyDescriptor p in properties) {
  77. if (0 == String.Compare (name, p.Name, ignoreCase))
  78. return p;
  79. }
  80. return null;
  81. }
  82. public virtual IEnumerator GetEnumerator ()
  83. {
  84. return properties.GetEnumerator ();
  85. }
  86. [MonoTODO]
  87. IDictionaryEnumerator IDictionary.GetEnumerator ()
  88. {
  89. throw new NotImplementedException ();
  90. }
  91. public int IndexOf (PropertyDescriptor value)
  92. {
  93. return properties.IndexOf (value);
  94. }
  95. int IList.IndexOf (object value)
  96. {
  97. return IndexOf ((PropertyDescriptor) value);
  98. }
  99. public void Insert (int index, PropertyDescriptor value)
  100. { Insert (index, value);
  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. public virtual PropertyDescriptorCollection Sort ()
  127. {
  128. properties.Sort ();
  129. return this;
  130. }
  131. public virtual PropertyDescriptorCollection Sort (IComparer comparer)
  132. {
  133. properties.Sort (comparer);
  134. return this;
  135. }
  136. [MonoTODO]
  137. public virtual PropertyDescriptorCollection Sort (string[] order)
  138. {
  139. throw new NotImplementedException ();
  140. }
  141. [MonoTODO]
  142. public virtual PropertyDescriptorCollection Sort (string[] order, IComparer comparer)
  143. {
  144. throw new NotImplementedException ();
  145. }
  146. [MonoTODO]
  147. protected void InternalSort (IComparer ic)
  148. {
  149. throw new NotImplementedException ();
  150. }
  151. [MonoTODO]
  152. protected void InternalSort (string [] order)
  153. {
  154. throw new NotImplementedException ();
  155. }
  156. bool IDictionary.IsFixedSize
  157. {
  158. get {
  159. return !readOnly;
  160. }
  161. }
  162. bool IList.IsFixedSize
  163. {
  164. get {
  165. return !readOnly;
  166. }
  167. }
  168. public bool IsReadOnly
  169. {
  170. get {
  171. return readOnly;
  172. }
  173. }
  174. public bool IsSynchronized
  175. {
  176. get {
  177. return false;
  178. }
  179. }
  180. public int Count
  181. {
  182. get {
  183. return properties.Count;
  184. }
  185. }
  186. object ICollection.SyncRoot
  187. {
  188. get {
  189. return null;
  190. }
  191. }
  192. ICollection IDictionary.Keys
  193. {
  194. get {
  195. string [] keys = new string [properties.Count];
  196. int i = 0;
  197. foreach (PropertyDescriptor p in properties)
  198. keys [i++] = p.Name;
  199. return keys;
  200. }
  201. }
  202. ICollection IDictionary.Values
  203. {
  204. get {
  205. return (ICollection) properties.Clone ();
  206. }
  207. }
  208. object IDictionary.this [object key]
  209. {
  210. get {
  211. if (!(key is string))
  212. return null;
  213. return this [(string) key];
  214. }
  215. set {
  216. if (!(key is string) || (value as PropertyDescriptor) == null)
  217. throw new ArgumentException ();
  218. int idx = properties.IndexOf (value);
  219. if (idx == -1)
  220. Add ((PropertyDescriptor) value);
  221. else
  222. properties [idx] = value;
  223. }
  224. }
  225. public virtual PropertyDescriptor this [string s]
  226. {
  227. get {
  228. return Find (s, false);
  229. }
  230. }
  231. object IList.this [int index]
  232. {
  233. get {
  234. return properties [index];
  235. }
  236. set {
  237. properties [index] = value;
  238. }
  239. }
  240. public virtual PropertyDescriptor this [int index]
  241. {
  242. get {
  243. return (PropertyDescriptor) properties [index];
  244. }
  245. }
  246. }
  247. }