ArrayList.cs 42 KB

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