| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378 |
- // ArrayList.cs
- //
- // Implementation of the ECMA ArrayList.
- //
- // Copyright (c) 2003 Thong (Tum) Nguyen [[email protected]]
- // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- namespace System.Collections
- {
- [Serializable]
- #if INSIDE_CORLIB
- [ComVisible(true)]
- [DebuggerDisplay ("Count={Count}")]
- [DebuggerTypeProxy (typeof (CollectionDebuggerView))]
- public class ArrayList : IList, ICloneable, ICollection, IEnumerable {
- #else
- internal class ArrayList : IList {
- #endif
- #region Enumerator
- private sealed class ArrayListEnumerator
- : IEnumerator, ICloneable
- {
- private object m_Current;
- private ArrayList m_List;
- private int m_Pos;
- private int m_Index;
- private int m_Count;
- private int m_ExpectedStateChanges;
- public ArrayListEnumerator(ArrayList list)
- : this(list, 0, list.Count)
- {
- }
- public object Clone()
- {
- return this.MemberwiseClone();
- }
- public ArrayListEnumerator(ArrayList list, int index, int count)
- {
- m_List = list;
- m_Index = index;
- m_Count = count;
- m_Pos = m_Index - 1;
- m_Current = null;
- m_ExpectedStateChanges = list._version;
- }
- public object Current
- {
- get
- {
- if (m_Pos == m_Index - 1) {
- throw new InvalidOperationException("Enumerator unusable (Reset pending, or past end of array.");
- }
- return m_Current;
- }
- }
- public bool MoveNext()
- {
- if (m_List._version != m_ExpectedStateChanges)
- {
- throw new InvalidOperationException("List has changed.");
- }
- m_Pos++;
- if (m_Pos - m_Index < m_Count)
- {
- m_Current = m_List[m_Pos];
- return true;
- }
- return false;
- }
- public void Reset()
- {
- m_Current = null;
- m_Pos = m_Index - 1;
- }
- }
-
- sealed class SimpleEnumerator : IEnumerator, ICloneable
- {
- ArrayList list;
- object currentElement;
- int index;
- int version;
- static readonly object endFlag = new object ();
-
- public SimpleEnumerator (ArrayList list)
- {
- this.list = list;
- index = -1;
- version = list._version;
- currentElement = endFlag;
- }
- public object Clone ()
- {
- return MemberwiseClone ();
- }
-
- public bool MoveNext ()
- {
- if (version != list._version)
- throw new InvalidOperationException("List has changed.");
-
- if (++index < list.Count) {
- currentElement = list [index];
- return true;
- } else {
- currentElement = endFlag;
- return false;
- }
- }
-
- public object Current {
- get {
- if (currentElement == endFlag) {
- if (index == -1)
- throw new InvalidOperationException ("Enumerator not started");
- else
- throw new InvalidOperationException ("Enumerator ended");
- }
-
- return currentElement;
- }
- }
-
- public void Reset ()
- {
- if (version != list._version)
- throw new InvalidOperationException ("List has changed.");
-
- currentElement = endFlag;
- index = -1;
- }
- }
- #endregion
- #region ArrayListAdapter
- /// <summary>
- /// Adapts various ILists into an ArrayList.
- /// </summary>
- [Serializable]
- private sealed class ArrayListAdapter
- : ArrayList
- {
- private sealed class EnumeratorWithRange
- : IEnumerator, ICloneable
- {
- private int m_StartIndex;
- private int m_Count;
- private int m_MaxCount;
- private IEnumerator m_Enumerator;
- public EnumeratorWithRange(IEnumerator enumerator, int index, int count)
- {
- m_Count = 0;
- m_StartIndex = index;
- m_MaxCount = count;
- m_Enumerator = enumerator;
- Reset();
- }
- public object Clone()
- {
- return this.MemberwiseClone();
- }
- public object Current
- {
- get
- {
- return m_Enumerator.Current;
- }
- }
- public bool MoveNext()
- {
- if (m_Count >= m_MaxCount)
- {
- return false;
- }
-
- m_Count++;
- return m_Enumerator.MoveNext();
- }
- public void Reset()
- {
- m_Count = 0;
- m_Enumerator.Reset();
- for (int i = 0; i < m_StartIndex; i++)
- {
- m_Enumerator.MoveNext();
- }
- }
- }
- private IList m_Adaptee;
- public ArrayListAdapter(IList adaptee)
- : base(0, true)
- {
- m_Adaptee = adaptee;
- }
- public override object this[int index]
- {
- get
- {
- return m_Adaptee[index];
- }
- set
- {
- m_Adaptee[index] = value;
- }
- }
- public override int Count
- {
- get
- {
- return m_Adaptee.Count;
- }
- }
- public override int Capacity
- {
- get
- {
- return m_Adaptee.Count;
- }
- set
- {
- if (value < m_Adaptee.Count)
- {
- throw new ArgumentException("capacity");
- }
- }
- }
- public override bool IsFixedSize
- {
- get
- {
- return m_Adaptee.IsFixedSize;
- }
- }
- public override bool IsReadOnly
- {
- get
- {
- return m_Adaptee.IsReadOnly;
- }
- }
- public override object SyncRoot
- {
- get
- {
- return m_Adaptee.SyncRoot;
- }
- }
- public override int Add(object value)
- {
- return m_Adaptee.Add(value);
- }
- public override void Clear()
- {
- m_Adaptee.Clear();
- }
- public override bool Contains(object value)
- {
- return m_Adaptee.Contains(value);
- }
- public override int IndexOf(object value)
- {
- return m_Adaptee.IndexOf(value);
- }
- public override int IndexOf(object value, int startIndex)
- {
- return IndexOf(value, startIndex, m_Adaptee.Count - startIndex);
- }
- public override int IndexOf(object value, int startIndex, int count)
- {
- if (startIndex < 0 || startIndex > m_Adaptee.Count)
- {
- ThrowNewArgumentOutOfRangeException ("startIndex", startIndex,
- "Does not specify valid index.");
- }
- if (count < 0)
- {
- ThrowNewArgumentOutOfRangeException ("count", count,
- "Can't be less than 0.");
- }
- // re-ordered to avoid possible integer overflow
- if (startIndex > m_Adaptee.Count - count) {
- // LAMESPEC: Every other method throws ArgumentException
- throw new ArgumentOutOfRangeException("count",
- "Start index and count do not specify a valid range.");
- }
- if (value == null)
- {
- for (int i = startIndex; i < startIndex + count; i++)
- {
- if (m_Adaptee[i] == null)
- {
- return i;
- }
- }
- }
- else
- {
- for (int i = startIndex; i < startIndex + count; i++)
- {
- if (value.Equals(m_Adaptee[i]))
- {
- return i;
- }
- }
- }
- return -1;
- }
- public override int LastIndexOf(object value)
- {
- return LastIndexOf(value, m_Adaptee.Count - 1);
- }
- public override int LastIndexOf(object value, int startIndex)
- {
- return LastIndexOf(value, startIndex, startIndex + 1);
- }
- public override int LastIndexOf(object value, int startIndex, int count)
- {
- if (startIndex < 0)
- {
- ThrowNewArgumentOutOfRangeException ("startIndex", startIndex, "< 0");
- }
- if (count < 0)
- {
- ThrowNewArgumentOutOfRangeException ("count", count, "count is negative.");
- }
- if (startIndex - count + 1 < 0)
- {
- ThrowNewArgumentOutOfRangeException ("count", count, "count is too large.");
- }
- if (value == null)
- {
- for (int i = startIndex; i > startIndex - count; i--)
- {
- if (m_Adaptee[i] == null)
- {
- return i;
- }
- }
- }
- else
- {
- for (int i = startIndex; i > startIndex - count; i--)
- {
- if (value.Equals(m_Adaptee[i]))
- {
- return i;
- }
- }
- }
- return -1;
- }
- public override void Insert(int index, object value)
- {
- m_Adaptee.Insert(index, value);
- }
- public override void InsertRange(int index, ICollection c)
- {
- if (c == null)
- {
- throw new ArgumentNullException("c");
- }
- if (index > m_Adaptee.Count)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Index must be >= 0 and <= Count.");
- }
- foreach (object value in c)
- {
- m_Adaptee.Insert(index++, value);
- }
- }
- public override void Remove(object value)
- {
- m_Adaptee.Remove(value);
- }
- public override void RemoveAt(int index)
- {
- m_Adaptee.RemoveAt(index);
- }
- public override void RemoveRange(int index, int count)
- {
- CheckRange(index, count, m_Adaptee.Count);
- for (int i = 0; i < count; i++)
- {
- m_Adaptee.RemoveAt(index);
- }
- }
- public override void Reverse()
- {
- Reverse(0, m_Adaptee.Count);
- }
- public override void Reverse(int index, int count)
- {
- object tmp;
- CheckRange(index, count, m_Adaptee.Count);
-
- for (int i = 0; i < count / 2; i++)
- {
- tmp = m_Adaptee[i + index];
- m_Adaptee[i + index] = m_Adaptee[(index + count) - i + index - 1];
- m_Adaptee[(index + count) - i + index - 1] = tmp;
- }
- }
- public override void SetRange(int index, ICollection c)
- {
- if (c == null)
- {
- throw new ArgumentNullException("c");
- }
- if (index < 0 || index + c.Count > m_Adaptee.Count)
- {
- throw new ArgumentOutOfRangeException("index");
- }
- int x = index;
- foreach (object value in c)
- {
- m_Adaptee[x++] = value;
- }
- }
- public override void CopyTo(System.Array array)
- {
- m_Adaptee.CopyTo(array, 0);
- }
- public override void CopyTo(System.Array array, int index)
- {
- m_Adaptee.CopyTo(array, index);
- }
- public override void CopyTo(int index, System.Array array, int arrayIndex, int count)
- {
- if (index < 0)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Can't be less than zero.");
- }
- if (arrayIndex < 0)
- {
- ThrowNewArgumentOutOfRangeException ("arrayIndex", arrayIndex,
- "Can't be less than zero.");
- }
- if (count < 0)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Can't be less than zero.");
- }
- if (index >= m_Adaptee.Count)
- {
- throw new ArgumentException("Can't be more or equal to list count.",
- "index");
- }
- if (array.Rank > 1)
- {
- throw new ArgumentException("Can't copy into multi-dimensional array.");
- }
- if (arrayIndex >= array.Length)
- {
- throw new ArgumentException("arrayIndex can't be greater than array.Length - 1.");
- }
- if (array.Length - arrayIndex + 1 < count)
- {
- throw new ArgumentException("Destination array is too small.");
- }
- // re-ordered to avoid possible integer overflow
- if (index > m_Adaptee.Count - count) {
- throw new ArgumentException("Index and count do not denote a valid range of elements.", "index");
- }
- for (int i = 0; i < count; i++)
- {
- array.SetValue(m_Adaptee[index + i], arrayIndex + i);
- }
- }
- public override bool IsSynchronized
- {
- get
- {
- return m_Adaptee.IsSynchronized;
- }
- }
- public override IEnumerator GetEnumerator()
- {
- return m_Adaptee.GetEnumerator();
- }
-
- public override IEnumerator GetEnumerator(int index, int count)
- {
- CheckRange(index, count, m_Adaptee.Count);
- return new EnumeratorWithRange(m_Adaptee.GetEnumerator(), index, count);
- }
- public override void AddRange(ICollection c)
- {
- foreach (object value in c)
- {
- m_Adaptee.Add(value);
- }
- }
- public override int BinarySearch(object value)
- {
- return BinarySearch(value, null);
- }
- public override int BinarySearch(object value, IComparer comparer)
- {
- return BinarySearch(0, m_Adaptee.Count, value, comparer);
- }
- public override int BinarySearch(int index, int count, object value, IComparer comparer)
- {
- int r, x, y, z;
- // Doing a direct BinarySearch on the adaptee will perform poorly if the adaptee is a linked-list.
- // Alternatives include copying the adaptee to a temporary array first.
- CheckRange(index, count, m_Adaptee.Count);
- if (comparer == null)
- {
- comparer = Comparer.Default;
- }
- x = index;
- y = index + count - 1;
- while (x <= y)
- {
- // Be careful with overflows
- z = x + ((y - x) / 2);
-
- r = comparer.Compare(value, m_Adaptee[z]);
-
- if (r < 0)
- {
- y = z - 1;
- }
- else if (r > 0)
- {
- x = z + 1;
- }
- else
- {
- return z;
- }
- }
- return ~x;
- }
- public override object Clone()
- {
- return new ArrayList.ArrayListAdapter(m_Adaptee);
- }
- public override ArrayList GetRange(int index, int count)
- {
- CheckRange(index, count, m_Adaptee.Count);
-
- return new RangedArrayList(this, index, count);
- }
- public override void TrimToSize()
- {
- // N/A
- }
- public override void Sort()
- {
- Sort(Comparer.Default);
- }
- public override void Sort(IComparer comparer)
- {
- Sort(0, m_Adaptee.Count, comparer);
- }
- public override void Sort(int index, int count, IComparer comparer)
- {
- CheckRange(index, count, m_Adaptee.Count);
- if (comparer == null)
- {
- comparer = Comparer.Default;
- }
- // Doing a direct sort on the adaptee will perform poorly if the adaptee is a linked-list.
- // Alternatives include copying the adaptee into a temporary array first.
- QuickSort(m_Adaptee, index, index + count - 1, comparer);
- }
- /// <summary>
- /// Swaps two items in a list at the specified indexes.
- /// </summary>
- private static void Swap(IList list, int x, int y)
- {
- object tmp;
-
- tmp = list[x];
- list[x] = list[y];
- list[y] = tmp;
- }
- /// <summary>
- /// Quicksort for lists.
- /// </summary>
- /// <remarks>
- /// This function acts as both qsort() and partition().
- /// </remarks>
- internal static void QuickSort(IList list, int left, int right, IComparer comparer)
- {
- int i, j, middle;
- object pivot;
-
- if (left >= right)
- {
- return;
- }
- // Pick the pivot using the median-of-three strategy.
- // Be careful with overflows
- middle = left + ((right - left) / 2);
- if (comparer.Compare(list[middle], list[left]) < 0)
- {
- Swap(list, middle, left);
- }
- if (comparer.Compare(list[right], list[left]) < 0)
- {
- Swap(list, right, left);
- }
- if (comparer.Compare(list[right], list[middle]) < 0)
- {
- Swap(list, right, middle);
- }
-
- if (right - left + 1 <= 3)
- {
- return;
- }
-
- // Put the pivot in right - 1.
- Swap(list, right - 1, middle);
- // List should look like:
- //
- // [Small] ..Numbers.. [Middle] ..Numbers.. [Pivot][Large]
- pivot = list[right - 1];
- // Sort from (left + 1) to (right - 2).
- i = left;
- j = right - 1;
-
- for (;;)
- {
- while (comparer.Compare(list[++i], pivot) < 0);
- while (comparer.Compare(list[--j], pivot) > 0);
-
- if (i < j)
- {
- Swap(list, i, j);
- }
- else
- {
- break;
- }
- }
- // Put pivot into the right position (real middle).
- Swap(list, right - 1, i);
- // Recursively sort the left and right sub lists.
- QuickSort(list, left, i - 1, comparer);
- QuickSort(list, i + 1, right, comparer);
- }
- public override object[] ToArray()
- {
- object[] retval;
- retval = new object[m_Adaptee.Count];
- m_Adaptee.CopyTo(retval, 0);
-
- return retval;
- }
- public override Array ToArray(Type elementType)
- {
- Array retval;
- retval = Array.CreateInstance(elementType, m_Adaptee.Count);
- m_Adaptee.CopyTo(retval, 0);
-
- return retval;
- }
- }
- #endregion // ArrayListAdapter
- //
- // ArrayList wrappers
- //
- #region ArrayListWrapper
- /// <summary>
- /// Base wrapper/decorator for ArrayLists. Simply delegates all methods to
- /// the underlying wrappee.
- /// </summary>
- [Serializable]
- private class ArrayListWrapper
- : ArrayList
- {
- protected ArrayList m_InnerArrayList;
- #region Constructors
- public ArrayListWrapper(ArrayList innerArrayList)
- {
- m_InnerArrayList = innerArrayList;
- }
- #endregion
- #region Indexers
- public override object this[int index]
- {
- get
- {
- return m_InnerArrayList[index];
- }
- set
- {
- m_InnerArrayList[index] = value;
- }
- }
- #endregion
- #region Properties
- public override int Count
- {
- get
- {
- return m_InnerArrayList.Count;
- }
- }
- public override int Capacity
- {
- get
- {
- return m_InnerArrayList.Capacity;
- }
- set
- {
- m_InnerArrayList.Capacity = value;
- }
- }
- public override bool IsFixedSize
- {
- get
- {
- return m_InnerArrayList.IsFixedSize;
- }
- }
- public override bool IsReadOnly
- {
- get
- {
- return m_InnerArrayList.IsReadOnly;
- }
- }
- public override bool IsSynchronized
- {
- get
- {
- return m_InnerArrayList.IsSynchronized;
- }
- }
- public override object SyncRoot
- {
- get
- {
- return m_InnerArrayList.SyncRoot;
- }
- }
- #endregion
- #region Methods
- public override int Add(object value)
- {
- return m_InnerArrayList.Add(value);
- }
- public override void Clear()
- {
- m_InnerArrayList.Clear();
- }
- public override bool Contains(object value)
- {
- return m_InnerArrayList.Contains(value);
- }
- public override int IndexOf(object value)
- {
- return m_InnerArrayList.IndexOf(value);
- }
- public override int IndexOf(object value, int startIndex)
- {
- return m_InnerArrayList.IndexOf(value, startIndex);
- }
- public override int IndexOf(object value, int startIndex, int count)
- {
- return m_InnerArrayList.IndexOf(value, startIndex, count);
- }
- public override int LastIndexOf(object value)
- {
- return m_InnerArrayList.LastIndexOf(value);
- }
- public override int LastIndexOf(object value, int startIndex)
- {
- return m_InnerArrayList.LastIndexOf(value, startIndex);
- }
- public override int LastIndexOf(object value, int startIndex, int count)
- {
- return m_InnerArrayList.LastIndexOf(value, startIndex, count);
- }
- public override void Insert(int index, object value)
- {
- m_InnerArrayList.Insert(index, value);
- }
- public override void InsertRange(int index, ICollection c)
- {
- m_InnerArrayList.InsertRange(index, c);
- }
- public override void Remove(object value)
- {
- m_InnerArrayList.Remove(value);
- }
- public override void RemoveAt(int index)
- {
- m_InnerArrayList.RemoveAt(index);
- }
- public override void RemoveRange(int index, int count)
- {
- m_InnerArrayList.RemoveRange(index, count);
- }
- public override void Reverse()
- {
- m_InnerArrayList.Reverse();
- }
- public override void Reverse(int index, int count)
- {
- m_InnerArrayList.Reverse(index, count);
- }
- public override void SetRange(int index, ICollection c)
- {
- m_InnerArrayList.SetRange(index, c);
- }
- public override void CopyTo(System.Array array)
- {
- m_InnerArrayList.CopyTo(array);
- }
- public override void CopyTo(System.Array array, int index)
- {
- m_InnerArrayList.CopyTo(array, index);
- }
- public override void CopyTo(int index, System.Array array, int arrayIndex, int count)
- {
- m_InnerArrayList.CopyTo(index, array, arrayIndex, count);
- }
- public override IEnumerator GetEnumerator()
- {
- return m_InnerArrayList.GetEnumerator();
- }
- public override IEnumerator GetEnumerator(int index, int count)
- {
- return m_InnerArrayList.GetEnumerator(index, count);
- }
- public override void AddRange(ICollection c)
- {
- m_InnerArrayList.AddRange(c);
- }
- public override int BinarySearch(object value)
- {
- return m_InnerArrayList.BinarySearch(value);
- }
- public override int BinarySearch(object value, IComparer comparer)
- {
- return m_InnerArrayList.BinarySearch(value, comparer);
- }
- public override int BinarySearch(int index, int count, object value, IComparer comparer)
- {
- return m_InnerArrayList.BinarySearch(index, count, value, comparer);
- }
- public override object Clone()
- {
- return m_InnerArrayList.Clone();
- }
- public override ArrayList GetRange(int index, int count)
- {
- return m_InnerArrayList.GetRange(index, count);
- }
- public override void TrimToSize()
- {
- m_InnerArrayList.TrimToSize();
- }
- public override void Sort()
- {
- m_InnerArrayList.Sort();
- }
- public override void Sort(IComparer comparer)
- {
- m_InnerArrayList.Sort(comparer);
- }
- public override void Sort(int index, int count, IComparer comparer)
- {
- m_InnerArrayList.Sort(index, count, comparer);
- }
- public override object[] ToArray()
- {
- return m_InnerArrayList.ToArray();
- }
- public override Array ToArray(Type elementType)
- {
- return m_InnerArrayList.ToArray(elementType);
- }
- #endregion
- }
- #endregion
- #region SynchronizedArrayListWrapper
- /// <summary>
- /// ArrayListWrapper that synchronizes calls to all methods/properties.
- /// </summary>
- /// <remarks>
- /// Works by just synchronizing all method calls. In the future careful optimisation
- /// could give better performance...
- /// </remarks>
- [Serializable]
- private sealed class SynchronizedArrayListWrapper
- : ArrayListWrapper
- {
- private object m_SyncRoot;
- #region Constructors
- /// <summary>
- /// Creates a new synchronized wrapper for the given <see cref="ArrayList"/>.
- /// </summary>
- /// <param name="innerArrayList"></param>
- internal SynchronizedArrayListWrapper(ArrayList innerArrayList)
- : base(innerArrayList)
- {
- m_SyncRoot = innerArrayList.SyncRoot;
- }
- #endregion
- #region Indexers
- public override object this[int index]
- {
- get
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList[index];
- }
- }
- set
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList[index] = value;
- }
- }
- }
-
- #endregion
- #region Properties
-
- // Some of these properties may be calculated so it's best to synchronize
- // them even though it might cause a performance hit.
- // Better safe than sorry ;D.
- public override int Count
- {
- get
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.Count;
- }
- }
- }
- public override int Capacity
- {
- get
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.Capacity;
- }
- }
- set
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.Capacity = value;
- }
- }
- }
- public override bool IsFixedSize
- {
- get
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.IsFixedSize;
- }
- }
- }
- public override bool IsReadOnly
- {
- get
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.IsReadOnly;
- }
- }
- }
- public override bool IsSynchronized
- {
- get
- {
- return true;
- }
- }
- public override object SyncRoot
- {
- get
- {
- return m_SyncRoot;
- }
- }
- #endregion
- #region Methods
- public override int Add(object value)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.Add(value);
- }
- }
- public override void Clear()
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.Clear();
- }
- }
- public override bool Contains(object value)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.Contains(value);
- }
- }
- public override int IndexOf(object value)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.IndexOf(value);
- }
- }
- public override int IndexOf(object value, int startIndex)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.IndexOf(value, startIndex);
- }
- }
- public override int IndexOf(object value, int startIndex, int count)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.IndexOf(value, startIndex, count);
- }
- }
- public override int LastIndexOf(object value)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.LastIndexOf(value);
- }
- }
- public override int LastIndexOf(object value, int startIndex)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.LastIndexOf(value, startIndex);
- }
- }
- public override int LastIndexOf(object value, int startIndex, int count)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.LastIndexOf(value, startIndex, count);
- }
- }
- public override void Insert(int index, object value)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.Insert(index, value);
- }
- }
- public override void InsertRange(int index, ICollection c)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.InsertRange(index, c);
- }
- }
- public override void Remove(object value)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.Remove(value);
- }
- }
- public override void RemoveAt(int index)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.RemoveAt(index);
- }
- }
- public override void RemoveRange(int index, int count)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.RemoveRange(index, count);
- }
- }
- public override void Reverse()
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.Reverse();
- }
- }
- public override void Reverse(int index, int count)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.Reverse(index, count);
- }
- }
- public override void CopyTo(System.Array array)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.CopyTo(array);
- }
- }
- public override void CopyTo(System.Array array, int index)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.CopyTo(array, index);
- }
- }
- public override void CopyTo(int index, System.Array array, int arrayIndex, int count)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.CopyTo(index, array, arrayIndex, count);
- }
- }
- public override IEnumerator GetEnumerator()
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.GetEnumerator();
- }
- }
- public override IEnumerator GetEnumerator(int index, int count)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.GetEnumerator(index, count);
- }
- }
- public override void AddRange(ICollection c)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.AddRange(c);
- }
- }
- public override int BinarySearch(object value)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.BinarySearch(value);
- }
- }
- public override int BinarySearch(object value, IComparer comparer)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.BinarySearch(value, comparer);
- }
- }
- public override int BinarySearch(int index, int count, object value, IComparer comparer)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.BinarySearch(index, count, value, comparer);
- }
- }
- public override object Clone()
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.Clone();
- }
- }
- public override ArrayList GetRange(int index, int count)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.GetRange(index, count);
- }
- }
- public override void TrimToSize()
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.TrimToSize();
- }
- }
- public override void Sort()
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.Sort();
- }
- }
- public override void Sort(IComparer comparer)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.Sort(comparer);
- }
- }
- public override void Sort(int index, int count, IComparer comparer)
- {
- lock (m_SyncRoot)
- {
- m_InnerArrayList.Sort(index, count, comparer);
- }
- }
- public override object[] ToArray()
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.ToArray();
- }
- }
- public override Array ToArray(Type elementType)
- {
- lock (m_SyncRoot)
- {
- return m_InnerArrayList.ToArray(elementType);
- }
- }
- #endregion
- }
- #endregion
- #region FixedSizeArrayListWrapper
- [Serializable]
- private class FixedSizeArrayListWrapper
- : ArrayListWrapper
- {
- #region Constructors
- public FixedSizeArrayListWrapper(ArrayList innerList)
- : base(innerList)
- {
- }
- #endregion
- #region Properties
-
- /// <summary>
- /// Gets the error message to display when an readonly/fixedsize related exception is
- /// thrown.
- /// </summary>
- protected virtual string ErrorMessage
- {
- get
- {
- return "Can't add or remove from a fixed-size list.";
- }
- }
- public override int Capacity
- {
- get
- {
- return base.Capacity;
- }
- set
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- }
- public override bool IsFixedSize
- {
- get
- {
- return true;
- }
- }
- #endregion
- #region Methods
- public override int Add(object value)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void AddRange(ICollection c)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void Clear()
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void Insert(int index, object value)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void InsertRange(int index, ICollection c)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void Remove(object value)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void RemoveAt(int index)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void RemoveRange(int index, int count)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
-
- public override void TrimToSize()
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- #endregion
- }
- #endregion
- #region ReadOnlyArrayListWrapper
- [Serializable]
- private sealed class ReadOnlyArrayListWrapper
- : FixedSizeArrayListWrapper
- {
- protected override string ErrorMessage
- {
- get
- {
- return "Can't modify a readonly list.";
- }
- }
- public override bool IsReadOnly
- {
- get
- {
- return true;
- }
- }
- public ReadOnlyArrayListWrapper(ArrayList innerArrayList)
- : base(innerArrayList)
- {
- }
- public override object this[int index]
- {
- get
- {
- return m_InnerArrayList[index];
- }
- set
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- }
- public override void Reverse()
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void Reverse(int index, int count)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void SetRange(int index, ICollection c)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void Sort()
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void Sort(IComparer comparer)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void Sort(int index, int count, IComparer comparer)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- }
- #endregion
- #region RangedArrayList
- [Serializable]
- private sealed class RangedArrayList
- : ArrayListWrapper
- {
- private int m_InnerIndex;
- private int m_InnerCount;
- private int m_InnerStateChanges;
- public RangedArrayList(ArrayList innerList, int index, int count)
- : base(innerList)
- {
- m_InnerIndex = index;
- m_InnerCount = count;
- m_InnerStateChanges = innerList._version;
- }
- #region Indexers
- public override bool IsSynchronized
- {
- get
- {
- return false;
- }
- }
- public override object this[int index]
- {
- get
- {
- if (index < 0 || index > m_InnerCount)
- {
- throw new ArgumentOutOfRangeException("index");
- }
- return m_InnerArrayList[m_InnerIndex + index];
- }
- set
- {
- if (index < 0 || index > m_InnerCount)
- {
- throw new ArgumentOutOfRangeException("index");
- }
- m_InnerArrayList[m_InnerIndex + index] = value;
- }
- }
- #endregion
- #region Properties
- public override int Count
- {
- get
- {
- VerifyStateChanges();
- return m_InnerCount;
- }
- }
- public override int Capacity
- {
- get
- {
- return m_InnerArrayList.Capacity;
- }
- set
- {
- if (value < m_InnerCount)
- {
- throw new ArgumentOutOfRangeException();
- }
- }
- }
- #endregion
- #region Methods
- private void VerifyStateChanges()
- {
- if (m_InnerStateChanges != m_InnerArrayList._version)
- {
- throw new InvalidOperationException
- ("ArrayList view is invalid because the underlying ArrayList was modified.");
- }
- }
- public override int Add(object value)
- {
- VerifyStateChanges();
- m_InnerArrayList.Insert(m_InnerIndex + m_InnerCount, value);
- m_InnerStateChanges = m_InnerArrayList._version;
- return ++m_InnerCount;
- }
- public override void Clear()
- {
- VerifyStateChanges();
- m_InnerArrayList.RemoveRange(m_InnerIndex, m_InnerCount);
- m_InnerCount = 0;
- m_InnerStateChanges = m_InnerArrayList._version;
- }
- public override bool Contains(object value)
- {
- return m_InnerArrayList.Contains(value, m_InnerIndex, m_InnerCount);
- }
- public override int IndexOf(object value)
- {
- return IndexOf(value, 0);
- }
- public override int IndexOf(object value, int startIndex)
- {
- return IndexOf(value, startIndex, m_InnerCount - startIndex);
- }
- public override int IndexOf(object value, int startIndex, int count)
- {
- if (startIndex < 0 || startIndex > m_InnerCount)
- {
- ThrowNewArgumentOutOfRangeException ("startIndex", startIndex,
- "Does not specify valid index.");
- }
- if (count < 0)
- {
- ThrowNewArgumentOutOfRangeException ("count", count,
- "Can't be less than 0.");
- }
- // re-ordered to avoid possible integer overflow
- if (startIndex > m_InnerCount - count)
- {
- // LAMESPEC: Every other method throws ArgumentException
- throw new ArgumentOutOfRangeException("count",
- "Start index and count do not specify a valid range.");
- }
- int retval = m_InnerArrayList.IndexOf(value, m_InnerIndex + startIndex, count);
- if (retval == -1)
- {
- return -1;
- }
- else
- {
- return retval - m_InnerIndex;
- }
- }
- public override int LastIndexOf(object value)
- {
- return LastIndexOf(value, m_InnerCount - 1);
- }
- public override int LastIndexOf(object value, int startIndex)
- {
- return LastIndexOf(value, startIndex, startIndex + 1);
- }
- public override int LastIndexOf(object value, int startIndex, int count)
- {
- if (startIndex < 0)
- {
- ThrowNewArgumentOutOfRangeException ("startIndex", startIndex, "< 0");
- }
- if (count < 0)
- {
- ThrowNewArgumentOutOfRangeException ("count", count, "count is negative.");
- }
- int retval = m_InnerArrayList.LastIndexOf(value, m_InnerIndex + startIndex, count);
- if (retval == -1)
- {
- return -1;
- }
- else
- {
- return retval - m_InnerIndex;
- }
- }
- public override void Insert(int index, object value)
- {
- VerifyStateChanges();
-
- if (index < 0 || index > m_InnerCount)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Index must be >= 0 and <= Count.");
- }
- m_InnerArrayList.Insert(m_InnerIndex + index, value);
- m_InnerCount++;
- m_InnerStateChanges = m_InnerArrayList._version;
- }
- public override void InsertRange(int index, ICollection c)
- {
- VerifyStateChanges();
- if (index < 0 || index > m_InnerCount)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Index must be >= 0 and <= Count.");
- }
- m_InnerArrayList.InsertRange(m_InnerIndex + index, c);
- m_InnerCount += c.Count;
- m_InnerStateChanges = m_InnerArrayList._version;
- }
- public override void Remove(object value)
- {
- VerifyStateChanges();
- int x = IndexOf(value);
- if (x > -1)
- {
- RemoveAt(x);
- }
- m_InnerStateChanges = m_InnerArrayList._version;
- }
- public override void RemoveAt(int index)
- {
- VerifyStateChanges();
- if (index < 0 || index > m_InnerCount)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Index must be >= 0 and <= Count.");
- }
- m_InnerArrayList.RemoveAt(m_InnerIndex + index);
- m_InnerCount--;
- m_InnerStateChanges = m_InnerArrayList._version;
- }
- public override void RemoveRange(int index, int count)
- {
- VerifyStateChanges();
- CheckRange(index, count, m_InnerCount);
- m_InnerArrayList.RemoveRange(m_InnerIndex + index, count);
- m_InnerCount -= count;
- m_InnerStateChanges = m_InnerArrayList._version;
- }
- public override void Reverse()
- {
- Reverse(0, m_InnerCount);
- }
- public override void Reverse(int index, int count)
- {
- VerifyStateChanges();
- CheckRange(index, count, m_InnerCount);
- m_InnerArrayList.Reverse(m_InnerIndex + index, count);
- m_InnerStateChanges = m_InnerArrayList._version;
- }
- public override void SetRange(int index, ICollection c)
- {
- VerifyStateChanges();
- if (index < 0 || index > m_InnerCount)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Index must be >= 0 and <= Count.");
- }
- m_InnerArrayList.SetRange(m_InnerIndex + index, c);
- m_InnerStateChanges = m_InnerArrayList._version;
- }
- public override void CopyTo(System.Array array)
- {
- CopyTo(array, 0);
- }
- public override void CopyTo(System.Array array, int index)
- {
- CopyTo(0, array, index, m_InnerCount);
- }
- public override void CopyTo(int index, System.Array array, int arrayIndex, int count)
- {
- CheckRange(index, count, m_InnerCount);
- m_InnerArrayList.CopyTo(m_InnerIndex + index, array, arrayIndex, count);
- }
- public override IEnumerator GetEnumerator()
- {
- return GetEnumerator(0, m_InnerCount);
- }
- public override IEnumerator GetEnumerator(int index, int count)
- {
- CheckRange(index, count, m_InnerCount);
- return m_InnerArrayList.GetEnumerator(m_InnerIndex + index, count);
- }
- public override void AddRange(ICollection c)
- {
- VerifyStateChanges();
- m_InnerArrayList.InsertRange(m_InnerCount, c);
- m_InnerCount += c.Count;
- m_InnerStateChanges = m_InnerArrayList._version;
- }
- public override int BinarySearch(object value)
- {
- return BinarySearch(0, m_InnerCount, value, Comparer.Default);
- }
- public override int BinarySearch(object value, IComparer comparer)
- {
- return BinarySearch(0, m_InnerCount, value, comparer);
- }
- public override int BinarySearch(int index, int count, object value, IComparer comparer)
- {
- CheckRange(index, count, m_InnerCount);
- return m_InnerArrayList.BinarySearch(m_InnerIndex + index, count, value, comparer);
- }
- public override object Clone()
- {
- return new RangedArrayList((ArrayList)m_InnerArrayList.Clone(), m_InnerIndex, m_InnerCount);
- }
- public override ArrayList GetRange(int index, int count)
- {
- CheckRange(index, count, m_InnerCount);
- return new RangedArrayList(this, index, count);
- }
- public override void TrimToSize()
- {
- throw new NotSupportedException();
- }
- public override void Sort()
- {
- Sort(Comparer.Default);
- }
- public override void Sort(IComparer comparer)
- {
- Sort(0, m_InnerCount, comparer);
- }
- public override void Sort(int index, int count, IComparer comparer)
- {
- VerifyStateChanges();
- CheckRange(index, count, m_InnerCount);
- m_InnerArrayList.Sort(m_InnerIndex + index, count, comparer);
- m_InnerStateChanges = m_InnerArrayList._version;
- }
- public override object[] ToArray()
- {
- object[] array;
- array = new object[m_InnerCount];
- m_InnerArrayList.CopyTo (m_InnerIndex, array, 0, m_InnerCount);
- return array;
- }
- public override Array ToArray(Type elementType)
- {
- Array array;
- array = Array.CreateInstance(elementType, m_InnerCount);
- m_InnerArrayList.CopyTo(m_InnerIndex, array, 0, m_InnerCount);
- return array;
- }
- #endregion
- }
- #endregion
- //
- // List wrappers
- //
- #region SynchronizedListWrapper
- [Serializable]
- private sealed class SynchronizedListWrapper
- : ListWrapper
- {
- private object m_SyncRoot;
- public SynchronizedListWrapper(IList innerList)
- : base(innerList)
- {
- m_SyncRoot = innerList.SyncRoot;
- }
- public override int Count
- {
- get
- {
- lock (m_SyncRoot)
- {
- return m_InnerList.Count;
- }
- }
- }
- public override bool IsSynchronized
- {
- get
- {
- return true;
- }
- }
- public override object SyncRoot
- {
- get
- {
- lock (m_SyncRoot)
- {
- return m_InnerList.SyncRoot;
- }
- }
- }
- public override bool IsFixedSize
- {
- get
- {
- lock (m_SyncRoot)
- {
- return m_InnerList.IsFixedSize;
- }
- }
- }
- public override bool IsReadOnly
- {
- get
- {
- lock (m_SyncRoot)
- {
- return m_InnerList.IsReadOnly;
- }
- }
- }
- public override object this[int index]
- {
- get
- {
- lock (m_SyncRoot)
- {
- return m_InnerList[index];
- }
- }
- set
- {
- lock (m_SyncRoot)
- {
- m_InnerList[index] = value;
- }
- }
- }
- public override int Add(object value)
- {
- lock (m_SyncRoot)
- {
- return m_InnerList.Add(value);
- }
- }
- public override void Clear()
- {
- lock (m_SyncRoot)
- {
- m_InnerList.Clear();
- }
- }
- public override bool Contains(object value)
- {
- lock (m_SyncRoot)
- {
- return m_InnerList.Contains(value);
- }
- }
- public override int IndexOf(object value)
- {
- lock (m_SyncRoot)
- {
- return m_InnerList.IndexOf(value);
- }
- }
- public override void Insert(int index, object value)
- {
- lock (m_SyncRoot)
- {
- m_InnerList.Insert(index, value);
- }
- }
- public override void Remove(object value)
- {
- lock (m_SyncRoot)
- {
- m_InnerList.Remove(value);
- }
- }
- public override void RemoveAt(int index)
- {
- lock (m_SyncRoot)
- {
- m_InnerList.RemoveAt(index);
- }
- }
- public override void CopyTo(Array array, int index)
- {
- lock (m_SyncRoot)
- {
- m_InnerList.CopyTo(array, index);
- }
- }
- public override IEnumerator GetEnumerator()
- {
- lock (m_SyncRoot)
- {
- return m_InnerList.GetEnumerator();
- }
- }
- }
- #endregion
- #region FixedSizeListWrapper
- [Serializable]
- private class FixedSizeListWrapper
- : ListWrapper
- {
- protected virtual string ErrorMessage
- {
- get
- {
- return "List is fixed-size.";
- }
- }
- public override bool IsFixedSize
- {
- get
- {
- return true;
- }
- }
- public FixedSizeListWrapper(IList innerList)
- : base(innerList)
- {
- }
- public override int Add(object value)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void Clear()
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void Insert(int index, object value)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void Remove(object value)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- public override void RemoveAt(int index)
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- }
- #endregion
- #region ReadOnlyListWrapper
- [Serializable]
- private sealed class ReadOnlyListWrapper
- : FixedSizeListWrapper
- {
- protected override string ErrorMessage
- {
- get
- {
- return "List is read-only.";
- }
- }
- public override bool IsReadOnly
- {
- get
- {
- return true;
- }
- }
- public ReadOnlyListWrapper(IList innerList)
- : base(innerList)
- {
- }
- public override object this[int index]
- {
- get
- {
- return m_InnerList[index];
- }
- set
- {
- throw new NotSupportedException(this.ErrorMessage);
- }
- }
- }
- #endregion
- #region ListWrapper
- /// <summary>
- /// Decorates/Wraps any <c>IList</c> implementing object.
- /// </summary>
- [Serializable]
- private class ListWrapper
- : IList
- {
- #region Fields
- protected IList m_InnerList;
- #endregion
- #region Constructors
- public ListWrapper(IList innerList)
- {
- m_InnerList = innerList;
- }
- #endregion
- #region Indexers
- public virtual object this[int index]
- {
- get
- {
- return m_InnerList[index];
- }
- set
- {
- m_InnerList[index] = value;
- }
- }
- #endregion
- #region Properties
- public virtual int Count
- {
- get
- {
- return m_InnerList.Count;
- }
- }
- public virtual bool IsSynchronized
- {
- get
- {
- return m_InnerList.IsSynchronized;
- }
- }
- public virtual object SyncRoot
- {
- get
- {
- return m_InnerList.SyncRoot;
- }
- }
- public virtual bool IsFixedSize
- {
- get
- {
- return m_InnerList.IsFixedSize;
- }
- }
- public virtual bool IsReadOnly
- {
- get
- {
- return m_InnerList.IsReadOnly;
- }
- }
- #endregion
- #region Methods
- public virtual int Add(object value)
- {
- return m_InnerList.Add(value);
- }
- public virtual void Clear()
- {
- m_InnerList.Clear();
- }
- public virtual bool Contains(object value)
- {
- return m_InnerList.Contains(value);
- }
- public virtual int IndexOf(object value)
- {
- return m_InnerList.IndexOf(value);
- }
- public virtual void Insert(int index, object value)
- {
- m_InnerList.Insert(index, value);
- }
- public virtual void Remove(object value)
- {
- m_InnerList.Remove(value);
- }
- public virtual void RemoveAt(int index)
- {
- m_InnerList.RemoveAt(index);
- }
- public virtual void CopyTo(Array array, int index)
- {
- m_InnerList.CopyTo(array, index);
- }
- public virtual IEnumerator GetEnumerator()
- {
- return m_InnerList.GetEnumerator();
- }
- #endregion
- }
- #endregion
- //
- // Start of ArrayList
- //
- #region Fields
- private const int DefaultInitialCapacity = 4;
- /// <summary>
- /// Array to store the items.
- /// </summary>
- private object[] _items;
-
- /// <summary>
- /// Number of items in the list.
- /// </summary>
- private int _size;
- /// <summary>
- /// Total number of state changes.
- /// </summary>
- private int _version;
- #endregion
-
- #region Constructors
- /// <summary>
- /// Initializes a new instance of the <see cref="ArrayList"/> class that is empty and
- /// has the default initial capacity (16).
- /// </summary>
- public ArrayList()
- {
- _items = EmptyArray<object>.Value;
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="ArrayList"/> class that contains
- /// elements copied from the specified collection and that has the same initial capacity
- /// as the number of elements copied.
- /// </summary>
- /// <param name="c">
- /// The <see cref="ICollection"/> whose elements are copied into the new list.
- /// </param>
- /// <exception cref="ArgumentNullException">
- /// The argument <c>c</c> is a null reference.
- /// </exception>
- public ArrayList(ICollection c)
- {
- Array array;
- if (c == null)
- {
- throw new ArgumentNullException("c");
- }
-
- array = c as Array;
- if (array != null && array.Rank != 1)
- {
- throw new RankException();
- }
- _items = new object[c.Count];
- AddRange(c);
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="ArrayList"/> class that is empty and
- /// has the specified initial capacity.
- /// </summary>
- /// <param name="capacity">
- /// The number of elements that hte new list is initially capable of storing.
- /// </param>
- /// <exception cref="ArgumentOutOfRangeException">
- /// The <c>capacity</c> is less than zero.
- /// </exception>
- public ArrayList(int capacity)
- {
- if (capacity < 0)
- {
- ThrowNewArgumentOutOfRangeException ("capacity",
- capacity, "The initial capacity can't be smaller than zero.");
- }
- if (capacity == 0)
- {
- capacity = DefaultInitialCapacity;
- }
- _items = new object [capacity];
- }
- /// <summary>
- /// Used by ArrayListAdapter to allow creation of an ArrayList with no storage buffer.
- /// </summary>
- private ArrayList(int initialCapacity, bool forceZeroSize)
- {
- if (forceZeroSize)
- {
- _items = null;
- }
- else
- {
- throw new InvalidOperationException("Use ArrayList(int)");
- }
- }
- /// <summary>
- /// Initializes a new array list that contains a copy of the given array and with the
- /// given count.
- /// </summary>
- /// <param name="array"></param>
- private ArrayList(object[] array, int index, int count)
- {
- if (count == 0)
- {
- _items = new object[DefaultInitialCapacity];
- }
- else
- {
- _items = new object[count];
- }
- Array.Copy(array, index, _items, 0, count);
- _size = count;
- }
- #endregion
- #region Indexers
- /// <summary>
- /// Gets/Sets an element in the list by index.
- /// </summary>
- /// <exception cref="ArgumentOutOfRangeException">
- /// The index is less than 0 or more then or equal to the list count.
- /// </exception>
- public virtual object this[int index]
- {
- get
- {
- if (index < 0 || index >= _size)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Index is less than 0 or more than or equal to the list count.");
- }
- return _items[index];
- }
- set
- {
- if (index < 0 || index >= _size)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Index is less than 0 or more than or equal to the list count.");
- }
- _items[index] = value;
- _version++;
- }
- }
- #endregion
- #region Properties
- /// <summary>
- /// Gets the number of elements in the list.
- /// </summary>
- public virtual int Count
- {
- get
- {
- return _size;
- }
- }
- /// <summary>
- /// Gets the number of elements the list can carry without needing to expand.
- /// </summary>
- /// <remarks>
- /// ArrayLists automatically double their capacity when the capacity limit is broken.
- /// </remarks>
- /// <exception cref="ArgumentOutOfRangeException">
- /// The capacity is less than the count.
- /// </exception>
- public virtual int Capacity
- {
- get
- {
- return _items.Length;
- }
- set
- {
- if (value < _size)
- {
- ThrowNewArgumentOutOfRangeException ("Capacity", value,
- "Must be more than count.");
- }
- object[] newArray;
- newArray = new object[value];
- Array.Copy(_items, 0, newArray, 0, _size);
- _items = newArray;
- }
- }
- /// <summary>
- /// <see cref="IList.IsFixedSize"/>
- /// </summary>
- /// <remarks/>
- public virtual bool IsFixedSize
- {
- get
- {
- return false;
- }
- }
- /// <summary>
- /// <see cref="IList.IsReadOnly"/>
- /// </summary>
- public virtual bool IsReadOnly
- {
- get
- {
- return false;
- }
- }
- /// <summary>
- /// <see cref="ICollection.IsSynchronized"/>
- /// </summary>
- public virtual bool IsSynchronized
- {
- get
- {
- return false;
- }
- }
- /// <summary>
- /// <see cref="ICollection.SyncRoot"/>
- /// </summary>
- public virtual object SyncRoot
- {
- get
- {
- return this;
- }
- }
- #endregion
- #region Methods
- /// <remarks>
- /// Ensures that the list has the capacity to contain the given <c>count</c> by
- /// automatically expanding the capacity when required.
- /// </remarks>
- private void EnsureCapacity(int count)
- {
- if (count <= _items.Length)
- {
- return;
- }
- int newLength;
- object[] newData;
- newLength = _items.Length << 1;
- if (newLength == 0)
- newLength = DefaultInitialCapacity;
- while (newLength < count)
- {
- newLength <<= 1;
- }
- newData = new object[newLength];
- Array.Copy(_items, 0, newData, 0, _items.Length);
- _items = newData;
- }
-
- /// <summary>
- /// Shifts a section of the list.
- /// </summary>
- /// <param name="index">
- /// The start of the section to shift (the element at index is included in the shift).
- /// </param>
- /// <param name="count">
- /// The number of positions to shift by (can be negative).
- /// </param>
- private void Shift(int index, int count)
- {
- if (count > 0)
- {
- if (_size + count > _items.Length)
- {
- int newLength;
- object[] newData;
-
- newLength = (_items.Length > 0) ? _items.Length << 1 : 1;
- while (newLength < _size + count)
- {
- newLength <<= 1;
- }
-
- newData = new object[newLength];
- Array.Copy(_items, 0, newData, 0, index);
- Array.Copy(_items, index, newData, index + count, _size - index);
- _items = newData;
- }
- else
- {
- Array.Copy(_items, index, _items, index + count, _size - index);
- }
- }
- else if (count < 0)
- {
- // Remember count is negative so this is actually index + (-count)
- int x = index - count ;
- Array.Copy(_items, x, _items, index, _size - x);
- Array.Clear(_items, _size + count, - count);
- }
- }
- public virtual int Add(object value)
- {
- // Do a check here in case EnsureCapacity isn't inlined.
- if (_items.Length <= _size /* same as _items.Length < _size + 1) */)
- {
- EnsureCapacity(_size + 1);
- }
- _items[_size] = value;
-
- _version++;
- return _size++;
- }
- public virtual void Clear()
- {
- // Keep the array but null all members so they can be garbage collected.
- Array.Clear(_items, 0, _size);
- _size = 0;
- _version++;
- }
- public virtual bool Contains(object item)
- {
- return IndexOf(item, 0, _size) > -1;
- }
- internal virtual bool Contains(object value, int startIndex, int count)
- {
- return IndexOf(value, startIndex, count) > -1;
- }
- public virtual int IndexOf(object value)
- {
- return IndexOf(value, 0);
- }
- public virtual int IndexOf(object value, int startIndex)
- {
- return IndexOf(value, startIndex, _size - startIndex);
- }
- public virtual int IndexOf(object value, int startIndex, int count)
- {
- if (startIndex < 0 || startIndex > _size)
- {
- ThrowNewArgumentOutOfRangeException ("startIndex", startIndex,
- "Does not specify valid index.");
- }
- if (count < 0)
- {
- ThrowNewArgumentOutOfRangeException ("count", count,
- "Can't be less than 0.");
- }
- // re-ordered to avoid integer overflow
- if (startIndex > _size - count)
- {
- // LAMESPEC: Every other method throws ArgumentException
- throw new ArgumentOutOfRangeException("count",
- "Start index and count do not specify a valid range.");
- }
- return Array.IndexOf(_items, value, startIndex, count);
- }
- public virtual int LastIndexOf(object value)
- {
- return LastIndexOf(value, _size - 1);
- }
- public virtual int LastIndexOf(object value, int startIndex)
- {
- return LastIndexOf(value, startIndex, startIndex + 1);
- }
- public virtual int LastIndexOf (object value, int startIndex, int count)
- {
- // Array will catch the exceptions
- return Array.LastIndexOf (_items, value, startIndex, count);
- }
- public virtual void Insert(int index, object value)
- {
- if (index < 0 || index > _size)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Index must be >= 0 and <= Count.");
- }
- Shift(index, 1);
- _items[index] = value;
- _size++;
- _version++;
- }
- public virtual void InsertRange(int index, ICollection c)
- {
- int i;
- if (c == null)
- {
- throw new ArgumentNullException("c");
- }
- if (index < 0 || index > _size)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Index must be >= 0 and <= Count.");
- }
- i = c.Count;
-
- // Do a check here in case EnsureCapacity isn't inlined.
- if (_items.Length < _size + i)
- {
- EnsureCapacity(_size + i);
- }
- if (index < _size)
- {
- Array.Copy(_items, index, _items, index + i, _size - index);
- }
-
- // Handle inserting a range from a list to itself specially.
- if (this == c.SyncRoot)
- {
- // Copy range before the insert point.
- Array.Copy(_items, 0, _items, index, index);
- // Copy range after the insert point.
- Array.Copy(_items, index + i, _items, index << 1, _size - index);
- }
- else
- {
- c.CopyTo(_items, index);
- }
-
- _size += c.Count;
- _version++;
- }
- public virtual void Remove(object obj)
- {
- int x;
- x = IndexOf(obj);
- if (x > -1)
- {
- RemoveAt(x);
- }
- _version++;
- }
- public virtual void RemoveAt(int index)
- {
- if (index < 0 || index >= _size)
- {
- ThrowNewArgumentOutOfRangeException ("index", index,
- "Less than 0 or more than list count.");
- }
- Shift(index, -1);
- _size--;
- _version++;
- }
- public virtual void RemoveRange(int index, int count)
- {
- ArrayList.CheckRange(index, count, _size);
-
- Shift(index, -count);
- _size -= count;
- _version++;
- }
- public virtual void Reverse()
- {
- Array.Reverse(_items, 0, _size);
- _version++;
- }
- public virtual void Reverse(int index, int count)
- {
- ArrayList.CheckRange(index, count, _size);
- Array.Reverse(_items, index, count);
- _version++;
- }
- public virtual void CopyTo(System.Array array)
- {
- Array.Copy(_items, array, _size);
- }
- public virtual void CopyTo(System.Array array, int arrayIndex)
- {
- CopyTo(0, array, arrayIndex, _size);
- }
- public virtual void CopyTo(int index, System.Array array, int arrayIndex, int count)
- {
- if (array == null)
- {
- throw new ArgumentNullException("array");
- }
- if (array.Rank != 1)
- {
- // LAMESPEC:
- // This should be a RankException because Array.Copy throws RankException.
- throw new ArgumentException("Must have only 1 dimensions.", "array");
- }
- Array.Copy(_items, index, array, arrayIndex, count);
- }
- public virtual IEnumerator GetEnumerator()
- {
- return new SimpleEnumerator(this);
- }
- public virtual IEnumerator GetEnumerator(int index, int count)
- {
- ArrayList.CheckRange(index, count, _size);
- return new ArrayListEnumerator(this, index, count);
- }
- public virtual void AddRange(ICollection c)
- {
- InsertRange(_size, c);
- }
- public virtual int BinarySearch(object value)
- {
- try
- {
- return Array.BinarySearch(_items, 0, _size, value);
- }
- catch (InvalidOperationException e)
- {
- throw new ArgumentException(e.Message);
- }
- }
- public virtual int BinarySearch(object value, IComparer comparer)
- {
- try
- {
- return Array.BinarySearch(_items, 0, _size, value, comparer);
- }
- catch (InvalidOperationException e)
- {
- throw new ArgumentException(e.Message);
- }
- }
- public virtual int BinarySearch(int index, int count, object value, IComparer comparer)
- {
- try
- {
- return Array.BinarySearch(_items, index, count, value, comparer);
- }
- catch (InvalidOperationException e)
- {
- throw new ArgumentException(e.Message);
- }
- }
- public virtual ArrayList GetRange(int index, int count)
- {
- ArrayList.CheckRange(index, count, _size);
- if (this.IsSynchronized)
- {
- return ArrayList.Synchronized(new RangedArrayList(this, index, count));
- }
- else
- {
- return new RangedArrayList(this, index, count);
- }
- }
- public virtual void SetRange(int index, ICollection c)
- {
- if (c == null)
- {
- throw new ArgumentNullException("c");
- }
- if (index < 0 || index + c.Count > _size)
- {
- throw new ArgumentOutOfRangeException("index");
- }
- c.CopyTo(_items, index);
- _version++;
- }
- public virtual void TrimToSize()
- {
- if (_items.Length > _size)
- {
- object[] newArray;
- if (_size == 0)
- {
- newArray = new object[DefaultInitialCapacity];
- }
- else
- {
- newArray = new object[_size];
- }
-
- Array.Copy(_items, 0, newArray, 0, _size);
- _items = newArray;
- }
- }
- public virtual void Sort()
- {
- Array.Sort(_items, 0, _size);
- _version++;
- }
- public virtual void Sort(IComparer comparer)
- {
- Array.Sort(_items, 0, _size, comparer);
- }
- public virtual void Sort(int index, int count, IComparer comparer)
- {
- ArrayList.CheckRange(index, count, _size);
- Array.Sort(_items, index, count, comparer);
- }
- public virtual object[] ToArray()
- {
- object[] retval;
- retval = new object[_size];
- CopyTo(retval);
-
- return retval;
- }
- public virtual Array ToArray(Type type)
- {
- Array retval;
-
- retval = Array.CreateInstance(type, _size);
- CopyTo(retval);
- return retval;
- }
- public virtual object Clone()
- {
- return new ArrayList(this._items, 0, this._size);
- }
- #endregion
- #region Static Methods
- /// <summary>
- /// Does a check of the arguments many of the methods in ArrayList use.
- /// </summary>
- /// <remarks>
- /// The choice of exceptions thrown sometimes seem to be arbitrarily chosen so
- /// not all methods actually make use of CheckRange.
- /// </remarks>
- internal static void CheckRange(int index, int count, int listCount)
- {
- if (index < 0)
- {
- ThrowNewArgumentOutOfRangeException ("index", index, "Can't be less than 0.");
- }
- if (count < 0)
- {
- ThrowNewArgumentOutOfRangeException ("count", count, "Can't be less than 0.");
- }
- // re-ordered to avoid possible integer overflow
- if (index > listCount - count)
- {
- throw new ArgumentException("Index and count do not denote a valid range of elements.", "index");
- }
- }
- internal static void ThrowNewArgumentOutOfRangeException (string name, object actual, string message)
- {
- throw new ArgumentOutOfRangeException (
- #if !INSIDE_CORLIB && NET_2_1
- name, message
- #else
- name, actual, message
- #endif
- );
- }
- public static ArrayList Adapter(IList list)
- {
- // LAMESPEC: EWWW. Other lists aren't *Array*Lists.
- if (list == null)
- {
- throw new ArgumentNullException("list");
- }
- ArrayList arrayList = list as ArrayList;
- if (arrayList != null)
- return arrayList;
- else
- arrayList = new ArrayListAdapter(list);
- if (list.IsSynchronized)
- return ArrayList.Synchronized(arrayList);
- else
- return arrayList;
- }
- public static ArrayList Synchronized(ArrayList list)
- {
- if (list == null)
- {
- throw new ArgumentNullException("list");
- }
- if (list.IsSynchronized)
- {
- return list;
- }
- return new SynchronizedArrayListWrapper(list);
- }
- public static IList Synchronized(IList list)
- {
- if (list == null)
- {
- throw new ArgumentNullException("list");
- }
- if (list.IsSynchronized)
- {
- return list;
- }
- return new SynchronizedListWrapper(list);
- }
- public static ArrayList ReadOnly(ArrayList list)
- {
- if (list == null)
- {
- throw new ArgumentNullException("list");
- }
- if (list.IsReadOnly)
- {
- return list;
- }
- return new ReadOnlyArrayListWrapper(list);
- }
- public static IList ReadOnly(IList list)
- {
- if (list == null)
- {
- throw new ArgumentNullException("list");
- }
- if (list.IsReadOnly)
- {
- return list;
- }
- return new ReadOnlyListWrapper(list);
- }
- public static ArrayList FixedSize(ArrayList list)
- {
- if (list == null)
- {
- throw new ArgumentNullException("list");
- }
- if (list.IsFixedSize)
- {
- return list;
- }
- return new FixedSizeArrayListWrapper(list);
- }
- public static IList FixedSize(IList list)
- {
- if (list == null)
- {
- throw new ArgumentNullException("list");
- }
- if (list.IsFixedSize)
- {
- return list;
- }
- return new FixedSizeListWrapper(list);
- }
- public static ArrayList Repeat(object value, int count)
- {
- ArrayList arrayList = new ArrayList(count);
- for (int i = 0; i < count; i++)
- {
- arrayList.Add(value);
- }
- return arrayList;
- }
- #endregion
- }
- }
|