ArrayList.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640
  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. count = 0;
  511. version++;
  512. }
  513. public virtual object Clone () {
  514. return new ArrayList (dataArray, count, capacity,
  515. fixedSize, readOnly, synchronized);
  516. }
  517. public virtual bool Contains (object item) {
  518. for (int i = 0; i < count; i++) {
  519. if (Object.Equals (dataArray[i], item)) {
  520. return true;
  521. }
  522. }
  523. return false;
  524. }
  525. public virtual void CopyTo (Array array) {
  526. if (null == array)
  527. throw new ArgumentNullException("array");
  528. if (array.Rank > 1)
  529. throw new ArgumentException("array cannot be multidimensional");
  530. Array.Copy (dataArray, 0, array, 0, this.count);
  531. }
  532. public virtual void CopyTo (Array array, int arrayIndex) {
  533. if (null == array)
  534. throw new ArgumentNullException("array");
  535. if (arrayIndex < 0)
  536. throw new ArgumentOutOfRangeException("arrayIndex");
  537. if (array.Rank > 1)
  538. throw new ArgumentException("array cannot be multidimensional");
  539. if (this.count > array.Length - arrayIndex)
  540. throw new ArgumentException("this ArrayList has more items than the space available in array from arrayIndex to the end of array");
  541. Array.Copy (dataArray, 0, array, arrayIndex, this.count);
  542. }
  543. public virtual void CopyTo (int index, Array array,
  544. int arrayIndex, int count) {
  545. if (null == array)
  546. throw new ArgumentNullException("array");
  547. if (arrayIndex < 0)
  548. throw new ArgumentOutOfRangeException("arrayIndex");
  549. if (index < 0)
  550. throw new ArgumentOutOfRangeException("index");
  551. if (count < 0)
  552. throw new ArgumentOutOfRangeException("count");
  553. if (index >= this.count)
  554. throw new ArgumentException("index is greater than or equal to the source ArrayList.Count");
  555. if (array.Rank > 1)
  556. throw new ArgumentException("array cannot be multidimensional");
  557. if (arrayIndex >= array.Length)
  558. throw new ArgumentException("arrayIndex is greater than or equal to array's length");
  559. if (this.count > array.Length - arrayIndex)
  560. throw new ArgumentException("this ArrayList has more items than the space available in array from arrayIndex to the end of array");
  561. Array.Copy (dataArray, index, array, arrayIndex, count);
  562. }
  563. [Serializable]
  564. private class ArrayListEnumerator : IEnumerator, ICloneable {
  565. private object[] data;
  566. private int idx;
  567. private int start;
  568. private int num;
  569. private ArrayList enumeratee;
  570. private long version;
  571. internal ArrayListEnumerator(int index, int count, object[] items, ArrayList al, long ver) {
  572. data = items;
  573. start = index;
  574. num = count;
  575. idx = start - 1;
  576. enumeratee = al;
  577. version = ver;
  578. }
  579. public object Clone () {
  580. return new ArrayListEnumerator (start, num, data, enumeratee, version);
  581. }
  582. public virtual object Current {
  583. get {
  584. return data [idx];
  585. }
  586. }
  587. public virtual bool MoveNext() {
  588. if (enumeratee.version != version)
  589. throw new InvalidOperationException();
  590. if (++idx < start + num)
  591. return true;
  592. return false;
  593. }
  594. public virtual void Reset() {
  595. idx = start - 1;
  596. }
  597. }
  598. public virtual IEnumerator GetEnumerator () {
  599. return new ArrayListEnumerator(0, this.Count, dataArray, this, this.version);
  600. }
  601. private void ValidateRange(int index, int count) {
  602. if (index < 0) {
  603. throw new ArgumentOutOfRangeException("index", index, "Must be equal to or greater than zero");
  604. }
  605. if (count < 0) {
  606. throw new ArgumentOutOfRangeException("count", count, "Must be equal to or greater than zero");
  607. }
  608. if (index > this.count - 1) {
  609. throw new ArgumentException();
  610. }
  611. if (index + count > this.count) {
  612. throw new ArgumentException();
  613. }
  614. }
  615. public virtual IEnumerator GetEnumerator (int index, int count) {
  616. ValidateRange(index, count);
  617. return new ArrayListEnumerator(index, count, dataArray, this, this.version);
  618. }
  619. public virtual ArrayList GetRange (int index, int count) {
  620. ValidateRange(index, count);
  621. ArrayList retVal = new ArrayList(count);
  622. for (int i = index; i < count + index; i++) {
  623. retVal.Add(this[i]);
  624. }
  625. retVal.version = this.version;
  626. retVal.source = this;
  627. return retVal;
  628. }
  629. public virtual int IndexOf (object value) {
  630. return IndexOf (value, 0, count);
  631. }
  632. public virtual int IndexOf (object value, int startIndex) {
  633. return IndexOf (value, startIndex, count - startIndex);
  634. }
  635. public virtual int IndexOf (object value, int startIndex, int count) {
  636. if (startIndex < 0 || startIndex + count > this.count || count < 0) {
  637. throw new ArgumentOutOfRangeException ("IndexOf arguments out of range");
  638. }
  639. for (int i = startIndex; i < (startIndex + count); i++) {
  640. if (Object.Equals (dataArray[i], value)) {
  641. return i;
  642. }
  643. }
  644. return -1;
  645. }
  646. public virtual void Insert (int index, object value) {
  647. if (readOnly) {
  648. throw new NotSupportedException
  649. ("Collection is read-only.");
  650. }
  651. if (fixedSize) {
  652. throw new NotSupportedException
  653. ("Collection is fixed size.");
  654. }
  655. if (index < 0 || index > count) {
  656. throw new ArgumentOutOfRangeException ("index < 0 or index >= capacity");
  657. }
  658. shiftElements (index, 1);
  659. dataArray[index] = value;
  660. count++;
  661. version++;
  662. }
  663. public virtual void InsertRange (int index, ICollection c) {
  664. if (c == null)
  665. throw new ArgumentNullException ();
  666. if (index < 0 || index > count)
  667. throw new ArgumentOutOfRangeException ();
  668. if (IsReadOnly || IsFixedSize)
  669. throw new NotSupportedException ();
  670. // Get a copy of the collection before the shift in case the collection
  671. // is this. Otherwise the enumerator will be confused.
  672. Array source = Array.CreateInstance(typeof(object), c.Count);
  673. c.CopyTo(source, 0);
  674. shiftElements (index, c.Count);
  675. count += c.Count;
  676. foreach (object o in source)
  677. dataArray[index++] = o;
  678. version++;
  679. }
  680. public virtual int LastIndexOf (object value) {
  681. return LastIndexOf (value, count - 1, count);
  682. }
  683. public virtual int LastIndexOf (object value, int startIndex) {
  684. if (startIndex < 0 || startIndex > count - 1) {
  685. throw new ArgumentOutOfRangeException("startIndex", startIndex, "");
  686. }
  687. return LastIndexOf (value, startIndex, startIndex + 1);
  688. }
  689. public virtual int LastIndexOf (object value, int startIndex,
  690. int count) {
  691. if (null == value){
  692. return -1;
  693. }
  694. if (startIndex >= this.count)
  695. throw new ArgumentOutOfRangeException ("startIndex >= Count");
  696. if (count < 0)
  697. throw new ArgumentOutOfRangeException ("count < 0");
  698. if (startIndex + 1 < count)
  699. throw new ArgumentOutOfRangeException ("startIndex + 1 < count");
  700. int EndIndex = startIndex - count + 1;
  701. for (int i = startIndex; i >= EndIndex; i--) {
  702. if (Object.Equals (dataArray[i], value)) {
  703. return i;
  704. }
  705. }
  706. return -1;
  707. }
  708. public virtual void Remove (object obj) {
  709. if (IsFixedSize || IsReadOnly)
  710. throw new NotSupportedException ();
  711. int objIndex = IndexOf (obj);
  712. if (objIndex == -1) {
  713. // shouldn't an exception be thrown here??
  714. // the MS docs don't indicate one, and testing
  715. // with the MS .net framework doesn't indicate one
  716. return;
  717. }
  718. RemoveRange (objIndex, 1);
  719. }
  720. public virtual void RemoveAt (int index) {
  721. if (readOnly) {
  722. throw new NotSupportedException
  723. ("Collection is read-only.");
  724. }
  725. if (fixedSize) {
  726. throw new NotSupportedException
  727. ("Collection is fixed size.");
  728. }
  729. if ((index < 0) || (index >= this.count))
  730. throw new ArgumentOutOfRangeException ("index", "Index was out of range. Must be non-negative and less than the size of the collection.");
  731. shiftElements (index, -1);
  732. this.count -= 1;
  733. version ++;
  734. }
  735. public virtual void RemoveRange (int index, int count) {
  736. if (readOnly) {
  737. throw new NotSupportedException
  738. ("Collection is read-only.");
  739. }
  740. if (fixedSize) {
  741. throw new NotSupportedException
  742. ("Collection is fixed size.");
  743. }
  744. if (index < 0)
  745. throw new ArgumentOutOfRangeException ("index", "Non-negative number required.");
  746. if (count < 0)
  747. throw new ArgumentOutOfRangeException ("count", "Non-negative number required.");
  748. if (index + count > this.count)
  749. throw new ArgumentException ("Offset and length were out of bounds for the array " +
  750. "or count is greater than the number of elements from index " +
  751. "to the end of the source collection.");
  752. shiftElements (index, - count);
  753. this.count -= count;
  754. version++;
  755. }
  756. public virtual void Reverse () {
  757. Reverse (0, count);
  758. }
  759. public virtual void Reverse (int index, int count) {
  760. if (readOnly) {
  761. throw new NotSupportedException
  762. ("Collection is read-only.");
  763. }
  764. if (index < 0 || index + count > this.count) {
  765. throw new ArgumentOutOfRangeException
  766. ("index/count out of range");
  767. }
  768. Array.Reverse (dataArray, index, count);
  769. version++;
  770. }
  771. public virtual void SetRange (int index, ICollection c) {
  772. if (c == null)
  773. throw new ArgumentNullException ();
  774. if (readOnly)
  775. throw new NotSupportedException ();
  776. if (index < 0 || (index + c.Count) > count)
  777. throw new ArgumentOutOfRangeException ();
  778. c.CopyTo(dataArray, index);
  779. }
  780. public virtual void Sort () {
  781. Sort (0, count, null);
  782. }
  783. public virtual void Sort (IComparer comparer) {
  784. Sort (0, count, comparer);
  785. }
  786. public virtual void Sort (int index, int count, IComparer comparer) {
  787. if (readOnly) {
  788. throw new NotSupportedException
  789. ("Collection is read-only.");
  790. }
  791. if (index < 0 || index + count > this.count) {
  792. throw new ArgumentOutOfRangeException
  793. ("index/count out of range");
  794. }
  795. Array.Sort (dataArray, index, count, comparer);
  796. version++;
  797. }
  798. public virtual object[] ToArray() {
  799. object[] outArray = new object[count];
  800. Array.Copy (dataArray, outArray, count);
  801. return outArray;
  802. }
  803. public virtual Array ToArray (Type type) {
  804. Array outArray = Array.CreateInstance (type, count);
  805. Array.Copy (dataArray, outArray, count);
  806. return outArray;
  807. }
  808. public virtual void TrimToSize () {
  809. if (IsReadOnly || IsFixedSize)
  810. throw new NotSupportedException ();
  811. setSize(count);
  812. version++;
  813. }
  814. private class Range : ArrayList {
  815. ArrayList baseList;
  816. int baseIndex;
  817. int baseSize;
  818. long baseVersion;
  819. internal Range (ArrayList list, int index, int count)
  820. {
  821. baseList = list;
  822. baseIndex = index;
  823. baseSize = count;
  824. baseVersion = list.version;
  825. }
  826. int RealIndex (int index)
  827. {
  828. return index + baseIndex;
  829. }
  830. int RealEnd {
  831. get {return baseIndex + baseSize;}
  832. }
  833. private void CheckVersion ()
  834. {
  835. if (baseVersion != this.baseList.version)
  836. throw new InvalidOperationException ();
  837. }
  838. public override int Add (object value)
  839. {
  840. CheckVersion ();
  841. baseList.Insert (RealEnd, value);
  842. baseVersion++;
  843. return baseSize++;
  844. }
  845. public override void AddRange (ICollection c)
  846. {
  847. CheckVersion ();
  848. baseList.InsertRange (RealEnd, c);
  849. baseVersion++;
  850. baseSize += c.Count;
  851. }
  852. public override int BinarySearch (int index, int count, object value, IComparer comparer)
  853. {
  854. CheckVersion ();
  855. if ((index < 0) || (count < 0))
  856. throw new ArgumentOutOfRangeException ();
  857. if ((index > Count) || (index + count) > Count)
  858. throw new ArgumentException ();
  859. int i = baseList.BinarySearch (RealIndex (index), count, value, comparer);
  860. // Account for how a BinarySearch works
  861. if (i >= 0) return i - baseIndex;
  862. return i + baseIndex;
  863. }
  864. public override int Capacity {
  865. get {return baseList.Capacity;}
  866. set {
  867. if (value < Count)
  868. throw new ArgumentOutOfRangeException("value");
  869. // From profiling it looks like Microsoft does not do anything
  870. // This make sense, since we can't very well have a "capacity" for the range.
  871. }
  872. }
  873. public override void Clear ()
  874. {
  875. CheckVersion ();
  876. if (baseSize != 0) {
  877. baseList.RemoveRange (baseIndex, baseSize);
  878. baseVersion++;
  879. baseSize = 0;
  880. }
  881. }
  882. public override object Clone ()
  883. {
  884. CheckVersion ();
  885. // Debugging Microsoft shows that this is _exactly_ how they do it.
  886. Range arrayList = new Range (baseList, baseIndex, baseSize);
  887. arrayList.baseList = (ArrayList)baseList.Clone ();
  888. return arrayList;
  889. }
  890. public override bool Contains (object item)
  891. {
  892. CheckVersion ();
  893. // Is much faster to check for null than to call Equals.
  894. if (item == null) {
  895. for (int i = 0; i < baseSize; i++)
  896. if (baseList[baseIndex + i] == null)
  897. return true;
  898. return false;
  899. } else {
  900. for (int i = 0; i < baseSize; i++)
  901. if (item.Equals (baseList [baseIndex + i]))
  902. return true;
  903. return false;
  904. }
  905. }
  906. public override void CopyTo (Array array, int index)
  907. {
  908. CheckVersion ();
  909. if (null == array)
  910. throw new ArgumentNullException ("array");
  911. if (array.Rank > 1)
  912. throw new ArgumentException ("array cannot be multidimensional");
  913. if (index < 0)
  914. throw new ArgumentOutOfRangeException ("index");
  915. if (array.Length - index < baseSize)
  916. throw new ArgumentException ();
  917. Array.Copy (baseList.dataArray, baseIndex, array, index, baseSize);
  918. }
  919. public override void CopyTo (int index, Array array, int arrayIndex, int count)
  920. {
  921. CheckVersion ();
  922. if (null == array)
  923. throw new ArgumentNullException ("array");
  924. if (array.Rank > 1)
  925. throw new ArgumentException ("array cannot be multidimensional");
  926. if (index < 0)
  927. throw new ArgumentOutOfRangeException ("index");
  928. if (count < 0)
  929. throw new ArgumentOutOfRangeException ("count");
  930. if (array.Length - index < baseSize)
  931. throw new ArgumentException ();
  932. if (baseSize - index < count)
  933. throw new ArgumentException ();
  934. Array.Copy (baseList.dataArray, RealIndex (index), array, arrayIndex, count);
  935. }
  936. public override int Count {
  937. get {
  938. CheckVersion ();
  939. return baseSize;
  940. }
  941. }
  942. public override bool IsReadOnly {
  943. get { return baseList.IsReadOnly; }
  944. }
  945. public override bool IsFixedSize {
  946. get { return baseList.IsFixedSize; }
  947. }
  948. public override bool IsSynchronized {
  949. get { return baseList.IsSynchronized; }
  950. }
  951. public override IEnumerator GetEnumerator ()
  952. {
  953. return GetEnumerator (0, baseSize);
  954. }
  955. public override IEnumerator GetEnumerator (int index, int count)
  956. {
  957. CheckVersion ();
  958. if (index < 0)
  959. throw new ArgumentOutOfRangeException ("index");
  960. if (count < 0)
  961. throw new ArgumentOutOfRangeException ("count");
  962. if (baseSize - index < count)
  963. throw new ArgumentException ();
  964. return baseList.GetEnumerator (RealIndex (index), count);
  965. }
  966. public override ArrayList GetRange (int index, int count)
  967. {
  968. CheckVersion ();
  969. if (index < 0)
  970. throw new ArgumentOutOfRangeException ("index");
  971. if (count < 0)
  972. throw new ArgumentOutOfRangeException ("count");
  973. if (baseSize - index < count)
  974. throw new ArgumentException ();
  975. // We have to create a wrapper around a wrapper
  976. // because if we update the inner most wrapper, the
  977. // outer ones must still function. If we just wrapped
  978. // the outer most ArrayList, the others would not update
  979. // their version.
  980. return new Range (this, index, count);
  981. }
  982. public override object SyncRoot {
  983. get {return baseList.SyncRoot;}
  984. }
  985. public override int IndexOf (object value)
  986. {
  987. CheckVersion ();
  988. int i = baseList.IndexOf (value, baseIndex, baseSize);
  989. if (i >= 0) return i - baseIndex;
  990. else return -1;
  991. }
  992. public override int IndexOf (object value, int startIndex)
  993. {
  994. CheckVersion ();
  995. if (startIndex < 0 || startIndex > baseSize)
  996. throw new ArgumentOutOfRangeException ();
  997. int i = baseList.IndexOf (value, RealIndex (startIndex), baseSize - startIndex);
  998. if (i >= 0) return i - baseIndex;
  999. return -1;
  1000. }
  1001. public override int IndexOf (object value, int startIndex, int count)
  1002. {
  1003. CheckVersion ();
  1004. if (startIndex < 0 || startIndex > baseSize)
  1005. throw new ArgumentOutOfRangeException("startIndex");
  1006. if (count < 0 || (startIndex > baseSize - count))
  1007. throw new ArgumentOutOfRangeException("count");
  1008. int i = baseList.IndexOf (value, RealIndex (startIndex), count);
  1009. if (i >= 0) return i - baseIndex;
  1010. return -1;
  1011. }
  1012. public override void Insert (int index, object value)
  1013. {
  1014. CheckVersion ();
  1015. if (index < 0 || index > baseSize)
  1016. throw new ArgumentOutOfRangeException("index");
  1017. baseList.Insert ( RealIndex (index), value);
  1018. baseVersion++;
  1019. baseSize++;
  1020. }
  1021. public override void InsertRange (int index, ICollection c)
  1022. {
  1023. CheckVersion ();
  1024. if (index < 0 || index > baseSize)
  1025. throw new ArgumentOutOfRangeException("index");
  1026. baseList.InsertRange (RealIndex (index), c);
  1027. baseVersion++;
  1028. baseSize += c.Count;
  1029. }
  1030. public override int LastIndexOf (object value)
  1031. {
  1032. CheckVersion ();
  1033. int i = baseList.LastIndexOf (value, baseIndex, baseSize);
  1034. if (i >= 0) return i - baseIndex;
  1035. return -1;
  1036. }
  1037. public override int LastIndexOf (object value, int startIndex)
  1038. {
  1039. return LastIndexOf (value, startIndex, startIndex + 1);
  1040. }
  1041. public override int LastIndexOf (object value, int startIndex, int count)
  1042. {
  1043. CheckVersion ();
  1044. if (baseSize == 0)
  1045. return -1;
  1046. if (startIndex < 0 || startIndex >= baseSize)
  1047. throw new ArgumentOutOfRangeException("startIndex");
  1048. int i = baseList.LastIndexOf (value, RealIndex (startIndex), count);
  1049. if (i >= 0) return i - baseIndex;
  1050. return -1;
  1051. }
  1052. // Remove will just call the overrided methods in here
  1053. public override void RemoveAt (int index)
  1054. {
  1055. CheckVersion ();
  1056. if (index < 0 || index >= baseSize)
  1057. throw new ArgumentOutOfRangeException ("index");
  1058. baseList.RemoveAt (RealIndex (index));
  1059. baseVersion++;
  1060. baseSize--;
  1061. }
  1062. public override void RemoveRange (int index, int count)
  1063. {
  1064. CheckVersion ();
  1065. if (index < 0)
  1066. throw new ArgumentOutOfRangeException ("index");
  1067. if (count < 0)
  1068. throw new ArgumentOutOfRangeException ("count");
  1069. if (baseSize - index < count)
  1070. throw new ArgumentException ();
  1071. baseList.RemoveRange (RealIndex (index), count);
  1072. baseVersion++;
  1073. baseSize -= count;
  1074. }
  1075. public override void Reverse (int index, int count)
  1076. {
  1077. CheckVersion ();
  1078. if (index < 0)
  1079. throw new ArgumentOutOfRangeException ("index");
  1080. if (count < 0)
  1081. throw new ArgumentOutOfRangeException ("count");
  1082. if (baseSize - index < count)
  1083. throw new ArgumentException ();
  1084. baseList.Reverse (RealIndex (index), count);
  1085. baseVersion++;
  1086. }
  1087. public override void SetRange (int index, ICollection c)
  1088. {
  1089. CheckVersion ();
  1090. if (index < 0 || index >= baseSize)
  1091. throw new ArgumentOutOfRangeException("index");
  1092. baseList.SetRange (RealIndex (index), c);
  1093. baseVersion++;
  1094. }
  1095. // Other overloads just call this
  1096. public override void Sort (int index, int count, IComparer comparer)
  1097. {
  1098. CheckVersion ();
  1099. if (index < 0)
  1100. throw new ArgumentOutOfRangeException ("index");
  1101. if (count < 0)
  1102. throw new ArgumentOutOfRangeException ("count");
  1103. if (baseSize - index < count)
  1104. throw new ArgumentException ();
  1105. baseList.Sort (RealIndex (index), count, comparer);
  1106. baseVersion++;
  1107. }
  1108. public override object this [int index] {
  1109. get {
  1110. CheckVersion ();
  1111. if (index < 0 || index >= baseSize)
  1112. throw new ArgumentOutOfRangeException("index");
  1113. return baseList[baseIndex + index];
  1114. }
  1115. set {
  1116. CheckVersion ();
  1117. if (index < 0 || index >= baseSize)
  1118. throw new ArgumentOutOfRangeException("index");
  1119. baseList [baseIndex + index] = value;
  1120. baseVersion++;
  1121. }
  1122. }
  1123. public override object [] ToArray ()
  1124. {
  1125. CheckVersion ();
  1126. object [] array = new object [baseSize];
  1127. Array.Copy (baseList.dataArray, baseIndex, array, 0, baseSize);
  1128. return array;
  1129. }
  1130. public override Array ToArray (Type type)
  1131. {
  1132. CheckVersion ();
  1133. if (type == null)
  1134. throw new ArgumentNullException("type");
  1135. Array array = Array.CreateInstance (type, baseSize);
  1136. Array.Copy (baseList.dataArray, baseIndex, array, 0, baseSize);
  1137. return array;
  1138. }
  1139. public override void TrimToSize ()
  1140. {
  1141. throw new NotSupportedException ("Can not trim range");
  1142. }
  1143. }
  1144. private class SyncArrayList : ArrayList {
  1145. private ArrayList _list;
  1146. // constructors
  1147. public SyncArrayList(ArrayList list) {
  1148. _list = list;
  1149. }
  1150. // properties
  1151. public override int Capacity {
  1152. get {
  1153. lock (_list.SyncRoot) {
  1154. return _list.Capacity;
  1155. }
  1156. }
  1157. set {
  1158. lock (_list.SyncRoot) {
  1159. _list.Capacity = value;
  1160. }
  1161. }
  1162. }
  1163. public override int Count {
  1164. get {
  1165. lock (_list.SyncRoot) {
  1166. return _list.Count;
  1167. }
  1168. }
  1169. }
  1170. public override bool IsFixedSize {
  1171. get {
  1172. lock (_list.SyncRoot) {
  1173. return _list.IsFixedSize;
  1174. }
  1175. }
  1176. }
  1177. public override bool IsReadOnly {
  1178. get {
  1179. lock (_list.SyncRoot) {
  1180. return _list.IsReadOnly;
  1181. }
  1182. }
  1183. }
  1184. public override bool IsSynchronized {
  1185. get {
  1186. lock (_list.SyncRoot) {
  1187. return _list.IsSynchronized;
  1188. }
  1189. }
  1190. }
  1191. public override object this[int index] {
  1192. get {
  1193. lock (_list.SyncRoot) {
  1194. return _list[index];
  1195. }
  1196. }
  1197. set {
  1198. lock (_list.SyncRoot) {
  1199. _list[index] = value;
  1200. }
  1201. }
  1202. }
  1203. // methods
  1204. public override int Add (object value) {
  1205. lock (_list.SyncRoot) {
  1206. return _list.Add(value);
  1207. }
  1208. }
  1209. public override void AddRange (ICollection c) {
  1210. lock (_list.SyncRoot) {
  1211. _list.AddRange(c);
  1212. }
  1213. }
  1214. public override int BinarySearch (int index, int count, object value, IComparer comparer) {
  1215. lock (_list.SyncRoot) {
  1216. return Array.BinarySearch (dataArray, index, count, value, comparer);
  1217. }
  1218. }
  1219. public override void Clear () {
  1220. lock (_list.SyncRoot) {
  1221. _list.Clear();
  1222. }
  1223. }
  1224. public override object Clone () {
  1225. lock (_list.SyncRoot) {
  1226. return new SyncArrayList((ArrayList) _list.Clone());
  1227. }
  1228. }
  1229. public override bool Contains (object item) {
  1230. lock (_list.SyncRoot) {
  1231. return _list.Contains(item);
  1232. }
  1233. }
  1234. public override void CopyTo (Array array) {
  1235. lock (_list.SyncRoot) {
  1236. _list.CopyTo(array);
  1237. }
  1238. }
  1239. public override void CopyTo (Array array, int arrayIndex) {
  1240. lock (_list.SyncRoot) {
  1241. _list.CopyTo(array, arrayIndex);
  1242. }
  1243. }
  1244. public override void CopyTo (int index, Array array, int arrayIndex, int count) {
  1245. lock (_list.SyncRoot) {
  1246. _list.CopyTo(index, array, arrayIndex, count);
  1247. }
  1248. }
  1249. public override IEnumerator GetEnumerator () {
  1250. lock (_list.SyncRoot) {
  1251. return _list.GetEnumerator();
  1252. }
  1253. }
  1254. public override IEnumerator GetEnumerator (int index, int count) {
  1255. lock (_list.SyncRoot) {
  1256. return _list.GetEnumerator(index, count);
  1257. }
  1258. }
  1259. public override ArrayList GetRange (int index, int count) {
  1260. lock (_list.SyncRoot) {
  1261. return new SyncArrayList(_list.GetRange(index, count));
  1262. }
  1263. }
  1264. public override int IndexOf (object value, int startIndex, int count) {
  1265. lock (_list.SyncRoot) {
  1266. return _list.IndexOf(value, startIndex, count);
  1267. }
  1268. }
  1269. public override void Insert (int index, object value) {
  1270. lock (_list.SyncRoot) {
  1271. _list.Insert(index, value);
  1272. }
  1273. }
  1274. public override void InsertRange (int index, ICollection c) {
  1275. lock (_list.SyncRoot) {
  1276. _list.InsertRange(index, c);
  1277. }
  1278. }
  1279. public override int LastIndexOf (object value, int startIndex) {
  1280. lock (_list.SyncRoot) {
  1281. return _list.LastIndexOf(value, startIndex);
  1282. }
  1283. }
  1284. public override int LastIndexOf (object value, int startIndex, int count) {
  1285. lock (_list.SyncRoot) {
  1286. return _list.LastIndexOf(value, startIndex, count);
  1287. }
  1288. }
  1289. public override void Remove (object obj) {
  1290. lock (_list.SyncRoot) {
  1291. _list.Remove(obj);
  1292. }
  1293. }
  1294. public override void RemoveRange (int index, int count) {
  1295. lock (_list.SyncRoot) {
  1296. _list.RemoveRange(index, count);
  1297. }
  1298. }
  1299. public override void Reverse (int index, int count) {
  1300. lock (_list.SyncRoot) {
  1301. _list.Reverse(index, count);
  1302. }
  1303. }
  1304. public override void SetRange (int index, ICollection c) {
  1305. lock (_list.SyncRoot) {
  1306. _list.SetRange(index, c);
  1307. }
  1308. }
  1309. public override void Sort (int index, int count, IComparer comparer) {
  1310. lock (_list.SyncRoot) {
  1311. _list.Sort(index, count, comparer);
  1312. }
  1313. }
  1314. public override object[] ToArray() {
  1315. lock (_list.SyncRoot) {
  1316. return _list.ToArray();
  1317. }
  1318. }
  1319. public override Array ToArray (Type type) {
  1320. lock (_list.SyncRoot) {
  1321. return _list.ToArray(type);
  1322. }
  1323. }
  1324. public override void TrimToSize () {
  1325. lock (_list.SyncRoot) {
  1326. _list.TrimToSize();
  1327. }
  1328. }
  1329. }
  1330. }
  1331. }