| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377 |
- // 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;
- namespace System.Collections
- {
- #if NET_2_0
- [ComVisible(true)]
- #endif
- [Serializable]
- #if INSIDE_CORLIB
- public
- #else
- internal
- #endif
- class ArrayList
- : IList, ICloneable, ICollection, IEnumerable
- {
- #region Enumerator
- private sealed class ArrayListEnumerator
- : IEnumerator, ICloneable
- {
- private int m_Pos;
- private int m_Index;
- private int m_Count;
- private object m_Current;
- private ArrayList m_List;
- 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;
- int index;
- int version;
- object currentElement;
- static 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)
- {
- throw new ArgumentOutOfRangeException("startIndex", startIndex,
- "Does not specify valid index.");
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("startIndex", startIndex, "< 0");
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException("count", count, "count is negative.");
- }
- if (startIndex - count + 1 < 0)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("index", index,
- "Can't be less than zero.");
- }
- if (arrayIndex < 0)
- {
- throw new ArgumentOutOfRangeException("arrayIndex", arrayIndex,
- "Can't be less than zero.");
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("startIndex", startIndex,
- "Does not specify valid index.");
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("startIndex", startIndex, "< 0");
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("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
- #if NET_2_0
- private const int DefaultInitialCapacity = 4;
- #else
- private const int DefaultInitialCapacity = 16;
- #endif
-
- /// <summary>
- /// Number of items in the list.
- /// </summary>
- private int _size;
- /// <summary>
- /// Array to store the items.
- /// </summary>
- private object[] _items;
-
- /// <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()
- {
- #if NET_2_0
- _items = new object[0];
- #else
- _items = new object[DefaultInitialCapacity];
- #endif
- }
- /// <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)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("startIndex", startIndex,
- "Does not specify valid index.");
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("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)
- {
- throw new ArgumentOutOfRangeException("index", index, "Can't be less than 0.");
- }
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException("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");
- }
- }
- 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
- }
- }
|