ArrayList.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641
  1. // System.Collections.ArrayList
  2. //
  3. // Author:
  4. // Vladimir Vukicevic ([email protected])
  5. // Duncan Mak ([email protected])
  6. // Patrik Torstensson ([email protected])
  7. // Ben Maurer ([email protected])
  8. //
  9. // (C) 2001 Vladimir Vukicevic
  10. // (C) 2002 Ximian, Inc.
  11. // (C) 2003 Ben Maurer
  12. //
  13. using System;
  14. namespace System.Collections {
  15. [MonoTODO ("add versioning, changing the arraylist should invalidate all enumerators")]
  16. [Serializable]
  17. public class ArrayList : IList, ICollection, IEnumerable, ICloneable {
  18. // Keep these three fields in sync with mono-reflection.h.
  19. private int count = 0;
  20. private int capacity = defaultCapacity;
  21. private object[] dataArray;
  22. // constructors
  23. public ArrayList () {
  24. dataArray = new object[capacity];
  25. }
  26. public ArrayList (ICollection c) {
  27. if (null == c)
  28. throw new ArgumentNullException();
  29. //Emulate MS.NET behavior. Throw RankException when passed a
  30. // multi-dimensional Array.
  31. Array arr = c as Array;
  32. if (null != arr && arr.Rank > 1)
  33. throw new RankException ();
  34. this.capacity = (c.Count == 0) ? defaultCapacity : c.Count;
  35. dataArray = new object [capacity];
  36. foreach (object o in c)
  37. Add (o);
  38. }
  39. public ArrayList (int capacity) {
  40. if (capacity < 0)
  41. throw new ArgumentOutOfRangeException ("capacity", capacity, "Value must be greater than or equal to zero.");
  42. if (capacity > 0)
  43. this.capacity = capacity;
  44. // else if capacity == 0 then use defaultCapacity
  45. dataArray = new object[this.capacity];
  46. }
  47. private ArrayList (object[] dataArray, int count, int capacity,
  48. bool fixedSize, bool readOnly, bool synchronized) {
  49. this.dataArray = new object [capacity];
  50. dataArray.CopyTo (this.dataArray, 0);
  51. this.count = count;
  52. this.capacity = capacity;
  53. this.fixedSize = fixedSize;
  54. this.readOnly = readOnly;
  55. this.synchronized = synchronized;
  56. }
  57. public static ArrayList ReadOnly (ArrayList list) {
  58. if (list == null)
  59. throw new ArgumentNullException ();
  60. if (list.IsSynchronized)
  61. return ArrayList.Synchronized (list);
  62. else
  63. return new ArrayList (list.ToArray (), list.Count, list.Capacity, list.IsFixedSize, true, list.IsSynchronized);
  64. }
  65. public static IList ReadOnly (IList list) {
  66. if (list == null)
  67. throw new ArgumentNullException ();
  68. ArrayList al = new ArrayList ();
  69. foreach (object o in list)
  70. al.Add (o);
  71. return (IList) ArrayList.ReadOnly (al);
  72. }
  73. public static ArrayList Synchronized (ArrayList list) {
  74. if (list == null)
  75. throw new ArgumentNullException ();
  76. return new SyncArrayList(new ArrayList (list.ToArray (), list.Count, list.Capacity, list.IsFixedSize, list.IsReadOnly, true));
  77. }
  78. public static IList Synchronized (IList list) {
  79. if (list == null)
  80. throw new ArgumentNullException ();
  81. ArrayList al = new ArrayList ();
  82. foreach (object o in list)
  83. al.Add (o);
  84. return (IList) ArrayList.Synchronized (al);
  85. }
  86. public static ArrayList FixedSize (ArrayList list) {
  87. if (list == null)
  88. throw new ArgumentNullException ();
  89. if (list.IsSynchronized)
  90. return Synchronized(list);
  91. return new ArrayList (list.ToArray (), list.Count, list.Capacity, true, list.IsReadOnly, list.IsSynchronized);
  92. }
  93. public static IList FixedSize (IList list) {
  94. if (list == null)
  95. throw new ArgumentNullException ();
  96. if (list.IsSynchronized)
  97. return Synchronized(list);
  98. ArrayList al = new ArrayList ();
  99. foreach (object o in list)
  100. al.Add (o);
  101. return (IList) ArrayList.FixedSize (al);
  102. }
  103. public static ArrayList Repeat (object value, int count) {
  104. ArrayList al = new ArrayList (count);
  105. for (int i = 0; i < count; i++) {
  106. al.dataArray[i] = value;
  107. }
  108. al.count = count;
  109. return al;
  110. }
  111. [Serializable]
  112. private class ListWrapper : ArrayList {
  113. IList list;
  114. public ListWrapper (IList list) {
  115. if (null == list)
  116. throw new ArgumentNullException();
  117. this.list = list;
  118. count = ((ICollection) list).Count;
  119. }
  120. // ArrayList
  121. public override int Capacity {
  122. get { return list.Count; }
  123. set {
  124. // MS seems to do this
  125. if (value < list.Count) {
  126. throw new ArgumentOutOfRangeException
  127. ("ArrayList Capacity being set to less than Count");
  128. }
  129. // There is no idiom for Capacity for
  130. // IList, so we do nothing, as MS does.
  131. }
  132. }
  133. public override void AddRange (ICollection collection) {
  134. if (collection == null)
  135. throw new ArgumentNullException ("colllection");
  136. if (IsFixedSize || IsReadOnly)
  137. throw new NotSupportedException ();
  138. InsertRange (Count, collection);
  139. }
  140. public override int BinarySearch (object value) {
  141. return BinarySearch (value, null);
  142. }
  143. public override int BinarySearch (object value, IComparer comparer) {
  144. return BinarySearch (0, Count, value, comparer);
  145. }
  146. public override int BinarySearch (int index, int count, object value,
  147. IComparer comparer) {
  148. if ((index < 0) || (count < 0))
  149. throw new ArgumentOutOfRangeException ();
  150. if ((index > Count) || (index + count) > Count)
  151. throw new ArgumentException ();
  152. if (comparer == null)
  153. comparer = Comparer.Default;
  154. int low = index;
  155. int hi = index + count - 1;
  156. int mid;
  157. while (low <= hi) {
  158. mid = (low + hi) / 2;
  159. int r = comparer.Compare (value, list [mid]);
  160. if (r == 0)
  161. return mid;
  162. if (r < 0)
  163. hi = mid-1;
  164. else
  165. low = mid+1;
  166. }
  167. return ~low;
  168. }
  169. public override void CopyTo (Array array) {
  170. if (null == array)
  171. throw new ArgumentNullException("array");
  172. if (array.Rank > 1)
  173. throw new ArgumentException("array cannot be multidimensional");
  174. CopyTo (array, 0);
  175. }
  176. public override void CopyTo (int index, Array array,
  177. int arrayIndex, int count) {
  178. if (array == null)
  179. throw new ArgumentNullException ();
  180. if (index < 0 || arrayIndex < 0 || count < 0)
  181. throw new ArgumentOutOfRangeException ();
  182. if (array.Rank > 1 || index >= Count || Count > (array.Length - arrayIndex))
  183. throw new ArgumentException ();
  184. for (int i = index; i < index + count; i++)
  185. array.SetValue(list [i], arrayIndex++);
  186. }
  187. public override ArrayList GetRange (int index, int count) {
  188. if (index < 0 || count < 0)
  189. throw new ArgumentOutOfRangeException ();
  190. if (Count < (index + count))
  191. throw new ArgumentException ();
  192. return (ArrayList) new Range (this, index, count);
  193. }
  194. public override void InsertRange (int index, ICollection col) {
  195. if (col == null)
  196. throw new ArgumentNullException ();
  197. if (index < 0 || index > Count)
  198. throw new ArgumentOutOfRangeException ();
  199. if (IsReadOnly || IsFixedSize)
  200. throw new NotSupportedException ();
  201. if (index == Count) {
  202. foreach (object element in col)
  203. list.Insert (index++, element);
  204. }
  205. }
  206. public override int LastIndexOf (object value) {
  207. return LastIndexOf (value, Count, 0);
  208. }
  209. public override int LastIndexOf (object value, int startIndex) {
  210. return LastIndexOf (value, startIndex, 0);
  211. }
  212. public override int LastIndexOf (object value, int startIndex, int count) {
  213. if (null == value){
  214. return -1;
  215. }
  216. if (startIndex > Count || count < 0 || (startIndex + count > Count))
  217. throw new ArgumentOutOfRangeException ();
  218. int length = startIndex - count + 1;
  219. for (int i = startIndex; i >= length; i--)
  220. if (list [i] == value)
  221. return i;
  222. return -1;
  223. }
  224. public override void RemoveRange (int index, int count) {
  225. if ((index < 0) || (count < 0))
  226. throw new ArgumentOutOfRangeException ();
  227. if ((index > Count) || (index + count) > Count)
  228. throw new ArgumentException ();
  229. if (IsReadOnly || IsFixedSize)
  230. throw new NotSupportedException ();
  231. for (int i = 0; i < count; i++)
  232. list.RemoveAt (index);
  233. }
  234. public override void Reverse () {
  235. Reverse (0, Count);
  236. }
  237. public override void Reverse (int index, int count) {
  238. if ((index < 0) || (count < 0))
  239. throw new ArgumentOutOfRangeException ();
  240. if ((index > Count) || (index + count) > Count)
  241. throw new ArgumentException ();
  242. if (IsReadOnly)
  243. throw new NotSupportedException ();
  244. object tmp = null;
  245. for (int i = index; i < count; i++) {
  246. tmp = list [i];
  247. list [i] = list [count - i];
  248. list [count - i] = tmp;
  249. }
  250. }
  251. public override void SetRange (int index, ICollection col) {
  252. if (index < 0 || (index + col.Count) > Count)
  253. throw new ArgumentOutOfRangeException ();
  254. if (col == null)
  255. throw new ArgumentNullException ();
  256. if (IsReadOnly)
  257. throw new NotSupportedException ();
  258. for (int i = index; i < col.Count; i++)
  259. foreach (object o in col)
  260. list [i] = o;
  261. }
  262. // Other overloads just call this
  263. public override void Sort (int index, int count, IComparer comparer) {
  264. if ((index < 0) || (count < 0))
  265. throw new ArgumentOutOfRangeException ();
  266. if ((index > Count) || (index + count) > Count)
  267. throw new ArgumentException ();
  268. if (IsReadOnly)
  269. throw new NotSupportedException ();
  270. // TODO: do some real sorting
  271. object [] tmpArr = new Object [count];
  272. CopyTo (index, tmpArr, 0, count);
  273. Array.Sort (tmpArr, 0, count, comparer);
  274. for (int i = 0; i < count; i++)
  275. list [i + index] = tmpArr [i];
  276. }
  277. public override object [] ToArray () {
  278. return (object []) ToArray (typeof (object));
  279. }
  280. public override Array ToArray (Type type) {
  281. int count = Count;
  282. Array result = Array.CreateInstance (type, count);
  283. for (int i = 0; i < count; i++)
  284. result.SetValue (list [i], i);
  285. return result;
  286. }
  287. public override void TrimToSize () {
  288. // Microsoft does not implement this method
  289. }
  290. // IList
  291. public override bool IsFixedSize {
  292. get { return list.IsFixedSize; }
  293. }
  294. public override bool IsReadOnly {
  295. get { return list.IsReadOnly; }
  296. }
  297. public override object this [int index] {
  298. get { return list [index]; }
  299. set { list [index] = value; }
  300. }
  301. public override int Add (object value) {
  302. return list.Add (value);
  303. }
  304. public override void Clear () {
  305. list.Clear ();
  306. }
  307. public override bool Contains (object value) {
  308. return list.Contains (value);
  309. }
  310. public override int IndexOf (object value) {
  311. return list.IndexOf (value);
  312. }
  313. public override void Insert (int index, object value) {
  314. list.Insert (index, value);
  315. }
  316. public override void Remove (object value) {
  317. list.Remove (value);
  318. }
  319. public override void RemoveAt (int index) {
  320. list.RemoveAt (index);
  321. }
  322. // ICollection
  323. public override int Count {
  324. get { return count; }
  325. }
  326. public override bool IsSynchronized {
  327. get { return ((ICollection) list).IsSynchronized; }
  328. }
  329. public override object SyncRoot {
  330. get { return ((ICollection) list).SyncRoot; }
  331. }
  332. public override void CopyTo (Array array, int index) {
  333. ((ICollection) list).CopyTo (array, index);
  334. }
  335. // ICloneable
  336. public override object Clone () {
  337. return new ListWrapper (list);
  338. }
  339. // IEnumerable
  340. public override IEnumerator GetEnumerator () {
  341. return ((IEnumerable) list).GetEnumerator ();
  342. }
  343. }
  344. public static ArrayList Adapter (IList list) {
  345. return new ListWrapper (list);
  346. }
  347. // properties
  348. private bool fixedSize = false;
  349. private bool readOnly = false;
  350. private bool synchronized = false;
  351. private long version = 0;
  352. private ArrayList source = null;
  353. private const int defaultCapacity = 16;
  354. private void copyDataArray (object[] outArray) {
  355. for (int i = 0; i < count; i++) {
  356. outArray[i] = dataArray[i];
  357. }
  358. }
  359. private void setSize (int newSize) {
  360. if (newSize == capacity)
  361. return;
  362. capacity = (newSize == 0) ? defaultCapacity : newSize;
  363. // note that this assumes that we've already sanity-checked
  364. // the new size
  365. object[] newDataArray = new object[capacity];
  366. copyDataArray (newDataArray);
  367. dataArray = newDataArray;
  368. }
  369. // note that this DOES NOT update count
  370. private void shiftElements (int startIndex, int numshift) {
  371. if (numshift == 0) {
  372. return;
  373. }
  374. if (count + numshift > capacity) {
  375. setSize (capacity * 2);
  376. shiftElements (startIndex, numshift);
  377. } else {
  378. if (numshift > 0) {
  379. int numelts = count - startIndex;
  380. for (int i = numelts-1; i >= 0; i--) {
  381. dataArray[startIndex + numshift + i] = dataArray[startIndex + i];
  382. }
  383. for (int i = startIndex; i < startIndex + numshift; i++) {
  384. dataArray[i] = null;
  385. }
  386. } else {
  387. int numelts = count - startIndex + numshift;
  388. for (int i = 0; i < numelts; i++) {
  389. dataArray [i + startIndex] = dataArray [i + startIndex - numshift];
  390. }
  391. for (int i = count + numshift; i < count; i++) {
  392. dataArray[i] = null;
  393. }
  394. }
  395. }
  396. }
  397. public virtual int Capacity {
  398. get {
  399. return capacity;
  400. }
  401. set {
  402. if (readOnly) {
  403. throw new NotSupportedException
  404. ("Collection is read-only.");
  405. }
  406. if (value < count) {
  407. throw new ArgumentOutOfRangeException
  408. ("ArrayList Capacity being set to less than Count");
  409. }
  410. if (fixedSize && value != capacity) {
  411. throw new NotSupportedException
  412. ("Collection is fixed size.");
  413. }
  414. setSize (value);
  415. }
  416. }
  417. private void CheckSourceVersion() {
  418. if (null != this.source && this.version != this.source.version) {
  419. throw new InvalidOperationException();
  420. }
  421. }
  422. public virtual int Count {
  423. get {
  424. CheckSourceVersion();
  425. return count;
  426. }
  427. }
  428. public virtual bool IsFixedSize {
  429. get {
  430. return fixedSize;
  431. }
  432. }
  433. public virtual bool IsReadOnly {
  434. get {
  435. return readOnly;
  436. }
  437. }
  438. public virtual bool IsSynchronized {
  439. get {
  440. return synchronized;
  441. }
  442. }
  443. public virtual object this[int index] {
  444. get {
  445. CheckSourceVersion();
  446. if (index < 0) {
  447. throw new ArgumentOutOfRangeException ("index < 0");
  448. }
  449. if (index >= count) {
  450. throw new ArgumentOutOfRangeException ("index out of range");
  451. }
  452. return dataArray[index];
  453. }
  454. set {
  455. if (index < 0) {
  456. throw new ArgumentOutOfRangeException ("index < 0");
  457. }
  458. if (index >= count) {
  459. throw new ArgumentOutOfRangeException ("index out of range");
  460. }
  461. if (readOnly) {
  462. throw new NotSupportedException ("Collection is read-only.");
  463. }
  464. dataArray[index] = value;
  465. version++;
  466. }
  467. }
  468. public virtual object SyncRoot {
  469. get {
  470. return this;
  471. }
  472. }
  473. // methods
  474. public virtual int Add (object value) {
  475. if (readOnly)
  476. throw new NotSupportedException ("ArrayList is read-only.");
  477. if (fixedSize)
  478. throw new NotSupportedException ("ArrayList is fixed size.");
  479. if (count + 1 >= capacity)
  480. setSize (capacity * 2);
  481. dataArray[count] = value;
  482. version++;
  483. return count++;
  484. }
  485. public virtual void AddRange (ICollection c) {
  486. if (null == c)
  487. throw new ArgumentNullException ("c");
  488. if (readOnly || fixedSize)
  489. throw new NotSupportedException ();
  490. int cc = c.Count;
  491. if (count + cc >= capacity)
  492. Capacity = cc < count? count * 2: count + cc + 1;
  493. c.CopyTo (dataArray, count);
  494. count += cc;
  495. version++;
  496. }
  497. public virtual int BinarySearch (object value) {
  498. return BinarySearch (0, count, value, null);
  499. }
  500. public virtual int BinarySearch (object value, IComparer comparer) {
  501. return BinarySearch (0, count, value, comparer);
  502. }
  503. public virtual int BinarySearch (int index, int count,
  504. object value, IComparer comparer) {
  505. return Array.BinarySearch (dataArray, index, count, value, comparer);
  506. }
  507. public virtual void Clear () {
  508. if (readOnly || fixedSize)
  509. throw new NotSupportedException();
  510. Array.Clear (dataArray, 0, count);
  511. count = 0;
  512. version++;
  513. }
  514. public virtual object Clone () {
  515. return new ArrayList (dataArray, count, capacity,
  516. fixedSize, readOnly, synchronized);
  517. }
  518. public virtual bool Contains (object item) {
  519. for (int i = 0; i < count; i++) {
  520. if (Object.Equals (dataArray[i], item)) {
  521. return true;
  522. }
  523. }
  524. return false;
  525. }
  526. public virtual void CopyTo (Array array) {
  527. if (null == array)
  528. throw new ArgumentNullException("array");
  529. if (array.Rank > 1)
  530. throw new ArgumentException("array cannot be multidimensional");
  531. Array.Copy (dataArray, 0, array, 0, this.count);
  532. }
  533. public virtual void CopyTo (Array array, int arrayIndex) {
  534. if (null == array)
  535. throw new ArgumentNullException("array");
  536. if (arrayIndex < 0)
  537. throw new ArgumentOutOfRangeException("arrayIndex");
  538. if (array.Rank > 1)
  539. throw new ArgumentException("array cannot be multidimensional");
  540. if (this.count > array.Length - arrayIndex)
  541. throw new ArgumentException("this ArrayList has more items than the space available in array from arrayIndex to the end of array");
  542. Array.Copy (dataArray, 0, array, arrayIndex, this.count);
  543. }
  544. public virtual void CopyTo (int index, Array array,
  545. int arrayIndex, int count) {
  546. if (null == array)
  547. throw new ArgumentNullException("array");
  548. if (arrayIndex < 0)
  549. throw new ArgumentOutOfRangeException("arrayIndex");
  550. if (index < 0)
  551. throw new ArgumentOutOfRangeException("index");
  552. if (count < 0)
  553. throw new ArgumentOutOfRangeException("count");
  554. if (index >= this.count)
  555. throw new ArgumentException("index is greater than or equal to the source ArrayList.Count");
  556. if (array.Rank > 1)
  557. throw new ArgumentException("array cannot be multidimensional");
  558. if (arrayIndex >= array.Length)
  559. throw new ArgumentException("arrayIndex is greater than or equal to array's length");
  560. if (this.count > array.Length - arrayIndex)
  561. throw new ArgumentException("this ArrayList has more items than the space available in array from arrayIndex to the end of array");
  562. Array.Copy (dataArray, index, array, arrayIndex, count);
  563. }
  564. [Serializable]
  565. private class ArrayListEnumerator : IEnumerator, ICloneable {
  566. private object[] data;
  567. private int idx;
  568. private int start;
  569. private int num;
  570. private ArrayList enumeratee;
  571. private long version;
  572. internal ArrayListEnumerator(int index, int count, object[] items, ArrayList al, long ver) {
  573. data = items;
  574. start = index;
  575. num = count;
  576. idx = start - 1;
  577. enumeratee = al;
  578. version = ver;
  579. }
  580. public object Clone () {
  581. return new ArrayListEnumerator (start, num, data, enumeratee, version);
  582. }
  583. public virtual object Current {
  584. get {
  585. return data [idx];
  586. }
  587. }
  588. public virtual bool MoveNext() {
  589. if (enumeratee.version != version)
  590. throw new InvalidOperationException();
  591. if (++idx < start + num)
  592. return true;
  593. return false;
  594. }
  595. public virtual void Reset() {
  596. idx = start - 1;
  597. }
  598. }
  599. public virtual IEnumerator GetEnumerator () {
  600. return new ArrayListEnumerator(0, this.Count, dataArray, this, this.version);
  601. }
  602. private void ValidateRange(int index, int count) {
  603. if (index < 0) {
  604. throw new ArgumentOutOfRangeException("index", index, "Must be equal to or greater than zero");
  605. }
  606. if (count < 0) {
  607. throw new ArgumentOutOfRangeException("count", count, "Must be equal to or greater than zero");
  608. }
  609. if (index > this.count - 1) {
  610. throw new ArgumentException();
  611. }
  612. if (index + count > this.count) {
  613. throw new ArgumentException();
  614. }
  615. }
  616. public virtual IEnumerator GetEnumerator (int index, int count) {
  617. ValidateRange(index, count);
  618. return new ArrayListEnumerator(index, count, dataArray, this, this.version);
  619. }
  620. public virtual ArrayList GetRange (int index, int count) {
  621. ValidateRange(index, count);
  622. ArrayList retVal = new ArrayList(count);
  623. for (int i = index; i < count + index; i++) {
  624. retVal.Add(this[i]);
  625. }
  626. retVal.version = this.version;
  627. retVal.source = this;
  628. return retVal;
  629. }
  630. public virtual int IndexOf (object value) {
  631. return IndexOf (value, 0, count);
  632. }
  633. public virtual int IndexOf (object value, int startIndex) {
  634. return IndexOf (value, startIndex, count - startIndex);
  635. }
  636. public virtual int IndexOf (object value, int startIndex, int count) {
  637. if (startIndex < 0 || startIndex + count > this.count || count < 0) {
  638. throw new ArgumentOutOfRangeException ("IndexOf arguments out of range");
  639. }
  640. for (int i = startIndex; i < (startIndex + count); i++) {
  641. if (Object.Equals (dataArray[i], value)) {
  642. return i;
  643. }
  644. }
  645. return -1;
  646. }
  647. public virtual void Insert (int index, object value) {
  648. if (readOnly) {
  649. throw new NotSupportedException
  650. ("Collection is read-only.");
  651. }
  652. if (fixedSize) {
  653. throw new NotSupportedException
  654. ("Collection is fixed size.");
  655. }
  656. if (index < 0 || index > count) {
  657. throw new ArgumentOutOfRangeException ("index < 0 or index >= capacity");
  658. }
  659. shiftElements (index, 1);
  660. dataArray[index] = value;
  661. count++;
  662. version++;
  663. }
  664. public virtual void InsertRange (int index, ICollection c) {
  665. if (c == null)
  666. throw new ArgumentNullException ();
  667. if (index < 0 || index > count)
  668. throw new ArgumentOutOfRangeException ();
  669. if (IsReadOnly || IsFixedSize)
  670. throw new NotSupportedException ();
  671. // Get a copy of the collection before the shift in case the collection
  672. // is this. Otherwise the enumerator will be confused.
  673. Array source = Array.CreateInstance(typeof(object), c.Count);
  674. c.CopyTo(source, 0);
  675. shiftElements (index, c.Count);
  676. count += c.Count;
  677. foreach (object o in source)
  678. dataArray[index++] = o;
  679. version++;
  680. }
  681. public virtual int LastIndexOf (object value) {
  682. return LastIndexOf (value, count - 1, count);
  683. }
  684. public virtual int LastIndexOf (object value, int startIndex) {
  685. if (startIndex < 0 || startIndex > count - 1) {
  686. throw new ArgumentOutOfRangeException("startIndex", startIndex, "");
  687. }
  688. return LastIndexOf (value, startIndex, startIndex + 1);
  689. }
  690. public virtual int LastIndexOf (object value, int startIndex,
  691. int count) {
  692. if (null == value){
  693. return -1;
  694. }
  695. if (startIndex >= this.count)
  696. throw new ArgumentOutOfRangeException ("startIndex >= Count");
  697. if (count < 0)
  698. throw new ArgumentOutOfRangeException ("count < 0");
  699. if (startIndex + 1 < count)
  700. throw new ArgumentOutOfRangeException ("startIndex + 1 < count");
  701. int EndIndex = startIndex - count + 1;
  702. for (int i = startIndex; i >= EndIndex; i--) {
  703. if (Object.Equals (dataArray[i], value)) {
  704. return i;
  705. }
  706. }
  707. return -1;
  708. }
  709. public virtual void Remove (object obj) {
  710. if (IsFixedSize || IsReadOnly)
  711. throw new NotSupportedException ();
  712. int objIndex = IndexOf (obj);
  713. if (objIndex == -1) {
  714. // shouldn't an exception be thrown here??
  715. // the MS docs don't indicate one, and testing
  716. // with the MS .net framework doesn't indicate one
  717. return;
  718. }
  719. RemoveRange (objIndex, 1);
  720. }
  721. public virtual void RemoveAt (int index) {
  722. if (readOnly) {
  723. throw new NotSupportedException
  724. ("Collection is read-only.");
  725. }
  726. if (fixedSize) {
  727. throw new NotSupportedException
  728. ("Collection is fixed size.");
  729. }
  730. if ((index < 0) || (index >= this.count))
  731. throw new ArgumentOutOfRangeException ("index", "Index was out of range. Must be non-negative and less than the size of the collection.");
  732. shiftElements (index, -1);
  733. this.count -= 1;
  734. version ++;
  735. }
  736. public virtual void RemoveRange (int index, int count) {
  737. if (readOnly) {
  738. throw new NotSupportedException
  739. ("Collection is read-only.");
  740. }
  741. if (fixedSize) {
  742. throw new NotSupportedException
  743. ("Collection is fixed size.");
  744. }
  745. if (index < 0)
  746. throw new ArgumentOutOfRangeException ("index", "Non-negative number required.");
  747. if (count < 0)
  748. throw new ArgumentOutOfRangeException ("count", "Non-negative number required.");
  749. if (index + count > this.count)
  750. throw new ArgumentException ("Offset and length were out of bounds for the array " +
  751. "or count is greater than the number of elements from index " +
  752. "to the end of the source collection.");
  753. shiftElements (index, - count);
  754. this.count -= count;
  755. version++;
  756. }
  757. public virtual void Reverse () {
  758. Reverse (0, count);
  759. }
  760. public virtual void Reverse (int index, int count) {
  761. if (readOnly) {
  762. throw new NotSupportedException
  763. ("Collection is read-only.");
  764. }
  765. if (index < 0 || index + count > this.count) {
  766. throw new ArgumentOutOfRangeException
  767. ("index/count out of range");
  768. }
  769. Array.Reverse (dataArray, index, count);
  770. version++;
  771. }
  772. public virtual void SetRange (int index, ICollection c) {
  773. if (c == null)
  774. throw new ArgumentNullException ();
  775. if (readOnly)
  776. throw new NotSupportedException ();
  777. if (index < 0 || (index + c.Count) > count)
  778. throw new ArgumentOutOfRangeException ();
  779. c.CopyTo(dataArray, index);
  780. }
  781. public virtual void Sort () {
  782. Sort (0, count, null);
  783. }
  784. public virtual void Sort (IComparer comparer) {
  785. Sort (0, count, comparer);
  786. }
  787. public virtual void Sort (int index, int count, IComparer comparer) {
  788. if (readOnly) {
  789. throw new NotSupportedException
  790. ("Collection is read-only.");
  791. }
  792. if (index < 0 || index + count > this.count) {
  793. throw new ArgumentOutOfRangeException
  794. ("index/count out of range");
  795. }
  796. Array.Sort (dataArray, index, count, comparer);
  797. version++;
  798. }
  799. public virtual object[] ToArray() {
  800. object[] outArray = new object[count];
  801. Array.Copy (dataArray, outArray, count);
  802. return outArray;
  803. }
  804. public virtual Array ToArray (Type type) {
  805. Array outArray = Array.CreateInstance (type, count);
  806. Array.Copy (dataArray, outArray, count);
  807. return outArray;
  808. }
  809. public virtual void TrimToSize () {
  810. if (IsReadOnly || IsFixedSize)
  811. throw new NotSupportedException ();
  812. setSize(count);
  813. version++;
  814. }
  815. private class Range : ArrayList {
  816. ArrayList baseList;
  817. int baseIndex;
  818. int baseSize;
  819. long baseVersion;
  820. internal Range (ArrayList list, int index, int count)
  821. {
  822. baseList = list;
  823. baseIndex = index;
  824. baseSize = count;
  825. baseVersion = list.version;
  826. }
  827. int RealIndex (int index)
  828. {
  829. return index + baseIndex;
  830. }
  831. int RealEnd {
  832. get {return baseIndex + baseSize;}
  833. }
  834. private void CheckVersion ()
  835. {
  836. if (baseVersion != this.baseList.version)
  837. throw new InvalidOperationException ();
  838. }
  839. public override int Add (object value)
  840. {
  841. CheckVersion ();
  842. baseList.Insert (RealEnd, value);
  843. baseVersion++;
  844. return baseSize++;
  845. }
  846. public override void AddRange (ICollection c)
  847. {
  848. CheckVersion ();
  849. baseList.InsertRange (RealEnd, c);
  850. baseVersion++;
  851. baseSize += c.Count;
  852. }
  853. public override int BinarySearch (int index, int count, object value, IComparer comparer)
  854. {
  855. CheckVersion ();
  856. if ((index < 0) || (count < 0))
  857. throw new ArgumentOutOfRangeException ();
  858. if ((index > Count) || (index + count) > Count)
  859. throw new ArgumentException ();
  860. int i = baseList.BinarySearch (RealIndex (index), count, value, comparer);
  861. // Account for how a BinarySearch works
  862. if (i >= 0) return i - baseIndex;
  863. return i + baseIndex;
  864. }
  865. public override int Capacity {
  866. get {return baseList.Capacity;}
  867. set {
  868. if (value < Count)
  869. throw new ArgumentOutOfRangeException("value");
  870. // From profiling it looks like Microsoft does not do anything
  871. // This make sense, since we can't very well have a "capacity" for the range.
  872. }
  873. }
  874. public override void Clear ()
  875. {
  876. CheckVersion ();
  877. if (baseSize != 0) {
  878. baseList.RemoveRange (baseIndex, baseSize);
  879. baseVersion++;
  880. baseSize = 0;
  881. }
  882. }
  883. public override object Clone ()
  884. {
  885. CheckVersion ();
  886. // Debugging Microsoft shows that this is _exactly_ how they do it.
  887. Range arrayList = new Range (baseList, baseIndex, baseSize);
  888. arrayList.baseList = (ArrayList)baseList.Clone ();
  889. return arrayList;
  890. }
  891. public override bool Contains (object item)
  892. {
  893. CheckVersion ();
  894. // Is much faster to check for null than to call Equals.
  895. if (item == null) {
  896. for (int i = 0; i < baseSize; i++)
  897. if (baseList[baseIndex + i] == null)
  898. return true;
  899. return false;
  900. } else {
  901. for (int i = 0; i < baseSize; i++)
  902. if (item.Equals (baseList [baseIndex + i]))
  903. return true;
  904. return false;
  905. }
  906. }
  907. public override void CopyTo (Array array, int index)
  908. {
  909. CheckVersion ();
  910. if (null == array)
  911. throw new ArgumentNullException ("array");
  912. if (array.Rank > 1)
  913. throw new ArgumentException ("array cannot be multidimensional");
  914. if (index < 0)
  915. throw new ArgumentOutOfRangeException ("index");
  916. if (array.Length - index < baseSize)
  917. throw new ArgumentException ();
  918. Array.Copy (baseList.dataArray, baseIndex, array, index, baseSize);
  919. }
  920. public override void CopyTo (int index, Array array, int arrayIndex, int count)
  921. {
  922. CheckVersion ();
  923. if (null == array)
  924. throw new ArgumentNullException ("array");
  925. if (array.Rank > 1)
  926. throw new ArgumentException ("array cannot be multidimensional");
  927. if (index < 0)
  928. throw new ArgumentOutOfRangeException ("index");
  929. if (count < 0)
  930. throw new ArgumentOutOfRangeException ("count");
  931. if (array.Length - index < baseSize)
  932. throw new ArgumentException ();
  933. if (baseSize - index < count)
  934. throw new ArgumentException ();
  935. Array.Copy (baseList.dataArray, RealIndex (index), array, arrayIndex, count);
  936. }
  937. public override int Count {
  938. get {
  939. CheckVersion ();
  940. return baseSize;
  941. }
  942. }
  943. public override bool IsReadOnly {
  944. get { return baseList.IsReadOnly; }
  945. }
  946. public override bool IsFixedSize {
  947. get { return baseList.IsFixedSize; }
  948. }
  949. public override bool IsSynchronized {
  950. get { return baseList.IsSynchronized; }
  951. }
  952. public override IEnumerator GetEnumerator ()
  953. {
  954. return GetEnumerator (0, baseSize);
  955. }
  956. public override IEnumerator GetEnumerator (int index, int count)
  957. {
  958. CheckVersion ();
  959. if (index < 0)
  960. throw new ArgumentOutOfRangeException ("index");
  961. if (count < 0)
  962. throw new ArgumentOutOfRangeException ("count");
  963. if (baseSize - index < count)
  964. throw new ArgumentException ();
  965. return baseList.GetEnumerator (RealIndex (index), count);
  966. }
  967. public override ArrayList GetRange (int index, int count)
  968. {
  969. CheckVersion ();
  970. if (index < 0)
  971. throw new ArgumentOutOfRangeException ("index");
  972. if (count < 0)
  973. throw new ArgumentOutOfRangeException ("count");
  974. if (baseSize - index < count)
  975. throw new ArgumentException ();
  976. // We have to create a wrapper around a wrapper
  977. // because if we update the inner most wrapper, the
  978. // outer ones must still function. If we just wrapped
  979. // the outer most ArrayList, the others would not update
  980. // their version.
  981. return new Range (this, index, count);
  982. }
  983. public override object SyncRoot {
  984. get {return baseList.SyncRoot;}
  985. }
  986. public override int IndexOf (object value)
  987. {
  988. CheckVersion ();
  989. int i = baseList.IndexOf (value, baseIndex, baseSize);
  990. if (i >= 0) return i - baseIndex;
  991. else return -1;
  992. }
  993. public override int IndexOf (object value, int startIndex)
  994. {
  995. CheckVersion ();
  996. if (startIndex < 0 || startIndex > baseSize)
  997. throw new ArgumentOutOfRangeException ();
  998. int i = baseList.IndexOf (value, RealIndex (startIndex), baseSize - startIndex);
  999. if (i >= 0) return i - baseIndex;
  1000. return -1;
  1001. }
  1002. public override int IndexOf (object value, int startIndex, int count)
  1003. {
  1004. CheckVersion ();
  1005. if (startIndex < 0 || startIndex > baseSize)
  1006. throw new ArgumentOutOfRangeException("startIndex");
  1007. if (count < 0 || (startIndex > baseSize - count))
  1008. throw new ArgumentOutOfRangeException("count");
  1009. int i = baseList.IndexOf (value, RealIndex (startIndex), count);
  1010. if (i >= 0) return i - baseIndex;
  1011. return -1;
  1012. }
  1013. public override void Insert (int index, object value)
  1014. {
  1015. CheckVersion ();
  1016. if (index < 0 || index > baseSize)
  1017. throw new ArgumentOutOfRangeException("index");
  1018. baseList.Insert ( RealIndex (index), value);
  1019. baseVersion++;
  1020. baseSize++;
  1021. }
  1022. public override void InsertRange (int index, ICollection c)
  1023. {
  1024. CheckVersion ();
  1025. if (index < 0 || index > baseSize)
  1026. throw new ArgumentOutOfRangeException("index");
  1027. baseList.InsertRange (RealIndex (index), c);
  1028. baseVersion++;
  1029. baseSize += c.Count;
  1030. }
  1031. public override int LastIndexOf (object value)
  1032. {
  1033. CheckVersion ();
  1034. int i = baseList.LastIndexOf (value, baseIndex, baseSize);
  1035. if (i >= 0) return i - baseIndex;
  1036. return -1;
  1037. }
  1038. public override int LastIndexOf (object value, int startIndex)
  1039. {
  1040. return LastIndexOf (value, startIndex, startIndex + 1);
  1041. }
  1042. public override int LastIndexOf (object value, int startIndex, int count)
  1043. {
  1044. CheckVersion ();
  1045. if (baseSize == 0)
  1046. return -1;
  1047. if (startIndex < 0 || startIndex >= baseSize)
  1048. throw new ArgumentOutOfRangeException("startIndex");
  1049. int i = baseList.LastIndexOf (value, RealIndex (startIndex), count);
  1050. if (i >= 0) return i - baseIndex;
  1051. return -1;
  1052. }
  1053. // Remove will just call the overrided methods in here
  1054. public override void RemoveAt (int index)
  1055. {
  1056. CheckVersion ();
  1057. if (index < 0 || index >= baseSize)
  1058. throw new ArgumentOutOfRangeException ("index");
  1059. baseList.RemoveAt (RealIndex (index));
  1060. baseVersion++;
  1061. baseSize--;
  1062. }
  1063. public override void RemoveRange (int index, int count)
  1064. {
  1065. CheckVersion ();
  1066. if (index < 0)
  1067. throw new ArgumentOutOfRangeException ("index");
  1068. if (count < 0)
  1069. throw new ArgumentOutOfRangeException ("count");
  1070. if (baseSize - index < count)
  1071. throw new ArgumentException ();
  1072. baseList.RemoveRange (RealIndex (index), count);
  1073. baseVersion++;
  1074. baseSize -= count;
  1075. }
  1076. public override void Reverse (int index, int count)
  1077. {
  1078. CheckVersion ();
  1079. if (index < 0)
  1080. throw new ArgumentOutOfRangeException ("index");
  1081. if (count < 0)
  1082. throw new ArgumentOutOfRangeException ("count");
  1083. if (baseSize - index < count)
  1084. throw new ArgumentException ();
  1085. baseList.Reverse (RealIndex (index), count);
  1086. baseVersion++;
  1087. }
  1088. public override void SetRange (int index, ICollection c)
  1089. {
  1090. CheckVersion ();
  1091. if (index < 0 || index >= baseSize)
  1092. throw new ArgumentOutOfRangeException("index");
  1093. baseList.SetRange (RealIndex (index), c);
  1094. baseVersion++;
  1095. }
  1096. // Other overloads just call this
  1097. public override void Sort (int index, int count, IComparer comparer)
  1098. {
  1099. CheckVersion ();
  1100. if (index < 0)
  1101. throw new ArgumentOutOfRangeException ("index");
  1102. if (count < 0)
  1103. throw new ArgumentOutOfRangeException ("count");
  1104. if (baseSize - index < count)
  1105. throw new ArgumentException ();
  1106. baseList.Sort (RealIndex (index), count, comparer);
  1107. baseVersion++;
  1108. }
  1109. public override object this [int index] {
  1110. get {
  1111. CheckVersion ();
  1112. if (index < 0 || index >= baseSize)
  1113. throw new ArgumentOutOfRangeException("index");
  1114. return baseList[baseIndex + index];
  1115. }
  1116. set {
  1117. CheckVersion ();
  1118. if (index < 0 || index >= baseSize)
  1119. throw new ArgumentOutOfRangeException("index");
  1120. baseList [baseIndex + index] = value;
  1121. baseVersion++;
  1122. }
  1123. }
  1124. public override object [] ToArray ()
  1125. {
  1126. CheckVersion ();
  1127. object [] array = new object [baseSize];
  1128. Array.Copy (baseList.dataArray, baseIndex, array, 0, baseSize);
  1129. return array;
  1130. }
  1131. public override Array ToArray (Type type)
  1132. {
  1133. CheckVersion ();
  1134. if (type == null)
  1135. throw new ArgumentNullException("type");
  1136. Array array = Array.CreateInstance (type, baseSize);
  1137. Array.Copy (baseList.dataArray, baseIndex, array, 0, baseSize);
  1138. return array;
  1139. }
  1140. public override void TrimToSize ()
  1141. {
  1142. throw new NotSupportedException ("Can not trim range");
  1143. }
  1144. }
  1145. private class SyncArrayList : ArrayList {
  1146. private ArrayList _list;
  1147. // constructors
  1148. public SyncArrayList(ArrayList list) {
  1149. _list = list;
  1150. }
  1151. // properties
  1152. public override int Capacity {
  1153. get {
  1154. lock (_list.SyncRoot) {
  1155. return _list.Capacity;
  1156. }
  1157. }
  1158. set {
  1159. lock (_list.SyncRoot) {
  1160. _list.Capacity = value;
  1161. }
  1162. }
  1163. }
  1164. public override int Count {
  1165. get {
  1166. lock (_list.SyncRoot) {
  1167. return _list.Count;
  1168. }
  1169. }
  1170. }
  1171. public override bool IsFixedSize {
  1172. get {
  1173. lock (_list.SyncRoot) {
  1174. return _list.IsFixedSize;
  1175. }
  1176. }
  1177. }
  1178. public override bool IsReadOnly {
  1179. get {
  1180. lock (_list.SyncRoot) {
  1181. return _list.IsReadOnly;
  1182. }
  1183. }
  1184. }
  1185. public override bool IsSynchronized {
  1186. get {
  1187. lock (_list.SyncRoot) {
  1188. return _list.IsSynchronized;
  1189. }
  1190. }
  1191. }
  1192. public override object this[int index] {
  1193. get {
  1194. lock (_list.SyncRoot) {
  1195. return _list[index];
  1196. }
  1197. }
  1198. set {
  1199. lock (_list.SyncRoot) {
  1200. _list[index] = value;
  1201. }
  1202. }
  1203. }
  1204. // methods
  1205. public override int Add (object value) {
  1206. lock (_list.SyncRoot) {
  1207. return _list.Add(value);
  1208. }
  1209. }
  1210. public override void AddRange (ICollection c) {
  1211. lock (_list.SyncRoot) {
  1212. _list.AddRange(c);
  1213. }
  1214. }
  1215. public override int BinarySearch (int index, int count, object value, IComparer comparer) {
  1216. lock (_list.SyncRoot) {
  1217. return Array.BinarySearch (dataArray, index, count, value, comparer);
  1218. }
  1219. }
  1220. public override void Clear () {
  1221. lock (_list.SyncRoot) {
  1222. _list.Clear();
  1223. }
  1224. }
  1225. public override object Clone () {
  1226. lock (_list.SyncRoot) {
  1227. return new SyncArrayList((ArrayList) _list.Clone());
  1228. }
  1229. }
  1230. public override bool Contains (object item) {
  1231. lock (_list.SyncRoot) {
  1232. return _list.Contains(item);
  1233. }
  1234. }
  1235. public override void CopyTo (Array array) {
  1236. lock (_list.SyncRoot) {
  1237. _list.CopyTo(array);
  1238. }
  1239. }
  1240. public override void CopyTo (Array array, int arrayIndex) {
  1241. lock (_list.SyncRoot) {
  1242. _list.CopyTo(array, arrayIndex);
  1243. }
  1244. }
  1245. public override void CopyTo (int index, Array array, int arrayIndex, int count) {
  1246. lock (_list.SyncRoot) {
  1247. _list.CopyTo(index, array, arrayIndex, count);
  1248. }
  1249. }
  1250. public override IEnumerator GetEnumerator () {
  1251. lock (_list.SyncRoot) {
  1252. return _list.GetEnumerator();
  1253. }
  1254. }
  1255. public override IEnumerator GetEnumerator (int index, int count) {
  1256. lock (_list.SyncRoot) {
  1257. return _list.GetEnumerator(index, count);
  1258. }
  1259. }
  1260. public override ArrayList GetRange (int index, int count) {
  1261. lock (_list.SyncRoot) {
  1262. return new SyncArrayList(_list.GetRange(index, count));
  1263. }
  1264. }
  1265. public override int IndexOf (object value, int startIndex, int count) {
  1266. lock (_list.SyncRoot) {
  1267. return _list.IndexOf(value, startIndex, count);
  1268. }
  1269. }
  1270. public override void Insert (int index, object value) {
  1271. lock (_list.SyncRoot) {
  1272. _list.Insert(index, value);
  1273. }
  1274. }
  1275. public override void InsertRange (int index, ICollection c) {
  1276. lock (_list.SyncRoot) {
  1277. _list.InsertRange(index, c);
  1278. }
  1279. }
  1280. public override int LastIndexOf (object value, int startIndex) {
  1281. lock (_list.SyncRoot) {
  1282. return _list.LastIndexOf(value, startIndex);
  1283. }
  1284. }
  1285. public override int LastIndexOf (object value, int startIndex, int count) {
  1286. lock (_list.SyncRoot) {
  1287. return _list.LastIndexOf(value, startIndex, count);
  1288. }
  1289. }
  1290. public override void Remove (object obj) {
  1291. lock (_list.SyncRoot) {
  1292. _list.Remove(obj);
  1293. }
  1294. }
  1295. public override void RemoveRange (int index, int count) {
  1296. lock (_list.SyncRoot) {
  1297. _list.RemoveRange(index, count);
  1298. }
  1299. }
  1300. public override void Reverse (int index, int count) {
  1301. lock (_list.SyncRoot) {
  1302. _list.Reverse(index, count);
  1303. }
  1304. }
  1305. public override void SetRange (int index, ICollection c) {
  1306. lock (_list.SyncRoot) {
  1307. _list.SetRange(index, c);
  1308. }
  1309. }
  1310. public override void Sort (int index, int count, IComparer comparer) {
  1311. lock (_list.SyncRoot) {
  1312. _list.Sort(index, count, comparer);
  1313. }
  1314. }
  1315. public override object[] ToArray() {
  1316. lock (_list.SyncRoot) {
  1317. return _list.ToArray();
  1318. }
  1319. }
  1320. public override Array ToArray (Type type) {
  1321. lock (_list.SyncRoot) {
  1322. return _list.ToArray(type);
  1323. }
  1324. }
  1325. public override void TrimToSize () {
  1326. lock (_list.SyncRoot) {
  1327. _list.TrimToSize();
  1328. }
  1329. }
  1330. }
  1331. }
  1332. }