/****************************************************************************** * The MIT License * Copyright (c) 2003 Novell Inc. 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. *******************************************************************************/ // // Novell.Directory.Ldap.SupportClass.cs // // Author: // Sunil Kumar (Sunilk@novell.com) // // (C) 2003 Novell, Inc (http://www.novell.com) // // Support classes replicate the functionality of the original code, but in some cases they are // substantially different architecturally. Although every effort is made to preserve the // original architecture of the application in the converted project, the user should be aware that // the primary goal of these support classes is to replicate functionality, and that at times // the architecture of the resulting solution may differ somewhat. // using System; /// /// This interface should be implemented by any class whose instances are intended /// to be executed by a thread. /// public interface IThreadRunnable { /// /// This method has to be implemented in order that starting of the thread causes the object's /// run method to be called in that separately executing thread. /// void Run(); } public class Integer32 : System.Object { private System.Int32 _wintv; public Integer32(System.Int32 ival) { _wintv=ival; } public System.Int32 intValue { get { return _wintv; } set { _wintv=value; } } } /// /// Contains conversion support elements such as classes, interfaces and static methods. /// public class SupportClass { /// /// Receives a byte array and returns it transformed in an sbyte array /// /// Byte array to process /// The transformed array [CLSCompliantAttribute(false)] public static sbyte[] ToSByteArray(byte[] byteArray) { #if TARGET_JVM return vmw.common.TypeUtils.ToSByteArray(byteArray); #else sbyte[] sbyteArray = new sbyte[byteArray.Length]; for(int index=0; index < byteArray.Length; index++) sbyteArray[index] = (sbyte) byteArray[index]; return sbyteArray; #endif } /*******************************/ /// /// Converts an array of sbytes to an array of bytes /// /// The array of sbytes to be converted /// The new array of bytes [CLSCompliantAttribute(false)] public static byte[] ToByteArray(sbyte[] sbyteArray) { #if TARGET_JVM return (byte[])vmw.common.TypeUtils.ToByteArray(sbyteArray);; #else byte[] byteArray = new byte[sbyteArray.Length]; for(int index=0; index < sbyteArray.Length; index++) byteArray[index] = (byte) sbyteArray[index]; return byteArray; #endif } /// /// Converts a string to an array of bytes /// /// The string to be converted /// The new array of bytes public static byte[] ToByteArray(string sourceString) { byte[] byteArray = new byte[sourceString.Length]; for (int index=0; index < sourceString.Length; index++) byteArray[index] = (byte) sourceString[index]; return byteArray; } /// /// Converts a array of object-type instances to a byte-type array. /// /// Array to convert. /// An array of byte type elements. public static byte[] ToByteArray(object[] tempObjectArray) { byte[] byteArray = new byte[tempObjectArray.Length]; for (int index = 0; index < tempObjectArray.Length; index++) byteArray[index] = (byte)tempObjectArray[index]; return byteArray; } /*******************************/ /// Reads a number of characters from the current source Stream and writes the data to the target array at the specified index. /// The source Stream to read from. /// Contains the array of characteres read from the source Stream. /// The starting index of the target array. /// The maximum number of characters to read from the source Stream. /// The number of characters read. The number will be less than or equal to count depending on the data available in the source Stream. Returns -1 if the end of the stream is reached. [CLSCompliantAttribute(false)] public static System.Int32 ReadInput(System.IO.Stream sourceStream, ref sbyte[] target, int start, int count) { // Returns 0 bytes if not enough space in target if (target.Length == 0) return 0; byte[] receiver = new byte[target.Length]; int bytesRead=0; int startIndex=start; int bytesToRead=count; while( bytesToRead > 0 ) { int n= sourceStream.Read(receiver, startIndex, bytesToRead); if (n==0) break; bytesRead+=n; startIndex+=n; bytesToRead-=n; } // Returns -1 if EOF if (bytesRead == 0) return -1; for(int i = start; i < start + bytesRead; i++) target[i] = (sbyte)receiver[i]; return bytesRead; } /// Reads a number of characters from the current source TextReader and writes the data to the target array at the specified index. /// The source TextReader to read from /// Contains the array of characteres read from the source TextReader. /// The starting index of the target array. /// The maximum number of characters to read from the source TextReader. /// The number of characters read. The number will be less than or equal to count depending on the data available in the source TextReader. Returns -1 if the end of the stream is reached. [CLSCompliantAttribute(false)] public static System.Int32 ReadInput(System.IO.TextReader sourceTextReader, ref sbyte[] target, int start, int count) { // Returns 0 bytes if not enough space in target if (target.Length == 0) return 0; char[] charArray = new char[target.Length]; int bytesRead = sourceTextReader.Read(charArray, start, count); // Returns -1 if EOF if (bytesRead == 0) return -1; for(int index=start; index /// This method returns the literal value received /// /// The literal to return /// The received value public static long Identity(long literal) { return literal; } /// /// This method returns the literal value received /// /// The literal to return /// The received value [CLSCompliantAttribute(false)] public static ulong Identity(ulong literal) { return literal; } /// /// This method returns the literal value received /// /// The literal to return /// The received value public static float Identity(float literal) { return literal; } /// /// This method returns the literal value received /// /// The literal to return /// The received value public static double Identity(double literal) { return literal; } /*******************************/ /// /// The class performs token processing from strings /// public class Tokenizer { //Element list identified private System.Collections.ArrayList elements; //Source string to use private string source; //The tokenizer uses the default delimiter set: the space character, the tab character, the newline character, and the carriage-return character private string delimiters = " \t\n\r"; private bool returnDelims=false; /// /// Initializes a new class instance with a specified string to process /// /// String to tokenize public Tokenizer(string source) { this.elements = new System.Collections.ArrayList(); this.elements.AddRange(source.Split(this.delimiters.ToCharArray())); this.RemoveEmptyStrings(); this.source = source; } /// /// Initializes a new class instance with a specified string to process /// and the specified token delimiters to use /// /// String to tokenize /// String containing the delimiters public Tokenizer(string source, string delimiters) { this.elements = new System.Collections.ArrayList(); this.delimiters = delimiters; this.elements.AddRange(source.Split(this.delimiters.ToCharArray())); this.RemoveEmptyStrings(); this.source = source; } public Tokenizer(string source, string delimiters,bool retDel) { this.elements = new System.Collections.ArrayList(); this.delimiters = delimiters; this.source = source; this.returnDelims = retDel; if( returnDelims) Tokenize(); else this.elements.AddRange(source.Split(this.delimiters.ToCharArray())); this.RemoveEmptyStrings(); } private void Tokenize() { string tempstr = this.source; string toks = ""; if (tempstr.IndexOfAny(this.delimiters.ToCharArray()) < 0 && tempstr.Length > 0) { this.elements.Add(tempstr); } else if (tempstr.IndexOfAny(this.delimiters.ToCharArray()) < 0 && tempstr.Length <= 0) { return; } while (tempstr.IndexOfAny(this.delimiters.ToCharArray()) >= 0) { if(tempstr.IndexOfAny(this.delimiters.ToCharArray()) == 0) { if (tempstr.Length > 1 ) { this.elements.Add(tempstr.Substring(0,1)); tempstr=tempstr.Substring(1); } else tempstr = ""; } else { toks = tempstr.Substring(0,tempstr.IndexOfAny(this.delimiters.ToCharArray())); this.elements.Add(toks); this.elements.Add(tempstr.Substring(toks.Length,1)); if ( tempstr.Length > (toks.Length + 1)) { tempstr = tempstr.Substring(toks.Length + 1); } else tempstr = ""; } } if (tempstr.Length > 0) { this.elements.Add(tempstr); } } /// /// Current token count for the source string /// public int Count { get { return (this.elements.Count); } } /// /// Determines if there are more tokens to return from the source string /// /// True or false, depending if there are more tokens public bool HasMoreTokens() { return (this.elements.Count > 0); } /// /// Returns the next token from the token list /// /// The string value of the token public string NextToken() { string result; if (source == "") throw new System.Exception(); else { if(returnDelims){ // Tokenize(); RemoveEmptyStrings(); result = (string) this.elements[0]; this.elements.RemoveAt(0); return result; } else { this.elements = new System.Collections.ArrayList(); this.elements.AddRange(this.source.Split(delimiters.ToCharArray())); RemoveEmptyStrings(); result = (string) this.elements[0]; this.elements.RemoveAt(0); this.source = this.source.Remove(this.source.IndexOf(result),result.Length); this.source = this.source.TrimStart(this.delimiters.ToCharArray()); return result; } } } /// /// Returns the next token from the source string, using the provided /// token delimiters /// /// String containing the delimiters to use /// The string value of the token public string NextToken(string delimiters) { this.delimiters = delimiters; return NextToken(); } /// /// Removes all empty strings from the token list /// private void RemoveEmptyStrings() { for (int index=0; index < this.elements.Count; index++) if ((string)this.elements[index]== "") { this.elements.RemoveAt(index); index--; } } } /*******************************/ /// /// Provides support for DateFormat /// public class DateTimeFormatManager { static public DateTimeFormatHashTable manager = new DateTimeFormatHashTable(); /// /// Hashtable class to provide functionality for dateformat properties /// public class DateTimeFormatHashTable :System.Collections.Hashtable { /// /// Sets the format for datetime. /// /// DateTimeFormat instance to set the pattern /// A string with the pattern format public void SetDateFormatPattern(System.Globalization.DateTimeFormatInfo format, System.String newPattern) { if (this[format] != null) ((DateTimeFormatProperties) this[format]).DateFormatPattern = newPattern; else { DateTimeFormatProperties tempProps = new DateTimeFormatProperties(); tempProps.DateFormatPattern = newPattern; Add(format, tempProps); } } /// /// Gets the current format pattern of the DateTimeFormat instance /// /// The DateTimeFormat instance which the value will be obtained /// The string representing the current datetimeformat pattern public string GetDateFormatPattern(System.Globalization.DateTimeFormatInfo format) { if (this[format] == null) return "d-MMM-yy"; else return ((DateTimeFormatProperties) this[format]).DateFormatPattern; } /// /// Sets the datetimeformat pattern to the giving format /// /// The datetimeformat instance to set /// The new datetimeformat pattern public void SetTimeFormatPattern(System.Globalization.DateTimeFormatInfo format, System.String newPattern) { if (this[format] != null) ((DateTimeFormatProperties) this[format]).TimeFormatPattern = newPattern; else { DateTimeFormatProperties tempProps = new DateTimeFormatProperties(); tempProps.TimeFormatPattern = newPattern; Add(format, tempProps); } } /// /// Gets the current format pattern of the DateTimeFormat instance /// /// The DateTimeFormat instance which the value will be obtained /// The string representing the current datetimeformat pattern public string GetTimeFormatPattern(System.Globalization.DateTimeFormatInfo format) { if (this[format] == null) return "h:mm:ss tt"; else return ((DateTimeFormatProperties) this[format]).TimeFormatPattern; } /// /// Internal class to provides the DateFormat and TimeFormat pattern properties on .NET /// class DateTimeFormatProperties { public string DateFormatPattern = "d-MMM-yy"; public string TimeFormatPattern = "h:mm:ss tt"; } } } /*******************************/ /// /// Gets the DateTimeFormat instance and date instance to obtain the date with the format passed /// /// The DateTimeFormat to obtain the time and date pattern /// The date instance used to get the date /// A string representing the date with the time and date patterns public static string FormatDateTime(System.Globalization.DateTimeFormatInfo format, System.DateTime date) { string timePattern = DateTimeFormatManager.manager.GetTimeFormatPattern(format); string datePattern = DateTimeFormatManager.manager.GetDateFormatPattern(format); return date.ToString(datePattern + " " + timePattern, format); } /*******************************/ /// /// Adds a new key-and-value pair into the hash table /// /// The collection to work with /// Key used to obtain the value /// Value asociated with the key /// The old element associated with the key public static System.Object PutElement(System.Collections.IDictionary collection, System.Object key, System.Object newValue) { System.Object element = collection[key]; collection[key] = newValue; return element; } /*******************************/ /// /// This class contains static methods to manage arrays. /// public class ArrayListSupport { /// /// Obtains an array containing all the elements of the collection. /// /// The collection from wich to obtain the elements. /// The array containing all the elements of the collection. /// The array containing all the elements of the collection. public static System.Object[] ToArray(System.Collections.ArrayList collection, System.Object[] objects) { int index = 0; System.Collections.IEnumerator tempEnumerator = collection.GetEnumerator(); while (tempEnumerator.MoveNext()) objects[index++] = tempEnumerator.Current; return objects; } } /*******************************/ /// /// Removes the first occurrence of an specific object from an ArrayList instance. /// /// The ArrayList instance /// The element to remove /// True if item is found in the ArrayList; otherwise, false public static System.Boolean VectorRemoveElement(System.Collections.IList arrayList, System.Object element) { System.Boolean containsItem = arrayList.Contains(element); arrayList.Remove(element); return containsItem; } /*******************************/ /// /// Support class used to handle threads /// public class ThreadClass : IThreadRunnable { /// /// The instance of System.Threading.Thread /// private System.Threading.Thread threadField; /// /// Initializes a new instance of the ThreadClass class /// public ThreadClass() { threadField = new System.Threading.Thread(new System.Threading.ThreadStart(Run)); } /// /// Initializes a new instance of the Thread class. /// /// The name of the thread public ThreadClass(string Name) { threadField = new System.Threading.Thread(new System.Threading.ThreadStart(Run)); this.Name = Name; } /// /// Initializes a new instance of the Thread class. /// /// A ThreadStart delegate that references the methods to be invoked when this thread begins executing public ThreadClass(System.Threading.ThreadStart Start) { threadField = new System.Threading.Thread(Start); } /// /// Initializes a new instance of the Thread class. /// /// A ThreadStart delegate that references the methods to be invoked when this thread begins executing /// The name of the thread public ThreadClass(System.Threading.ThreadStart Start, string Name) { threadField = new System.Threading.Thread(Start); this.Name = Name; } /// /// This method has no functionality unless the method is overridden /// public virtual void Run() { } /// /// Causes the operating system to change the state of the current thread instance to ThreadState.Running /// public virtual void Start() { threadField.Start(); } /// /// Interrupts a thread that is in the WaitSleepJoin thread state /// public virtual void Interrupt() { threadField.Interrupt(); } /// /// Gets the current thread instance /// public System.Threading.Thread Instance { get { return threadField; } set { threadField = value; } } /// /// Gets or sets the name of the thread /// public System.String Name { get { return threadField.Name; } set { if (threadField.Name == null) threadField.Name = value; } } /// /// Gets or sets a value indicating the scheduling priority of a thread /// public System.Threading.ThreadPriority Priority { get { return threadField.Priority; } set { threadField.Priority = value; } } /// /// Gets a value indicating the execution status of the current thread /// public bool IsAlive { get { return threadField.IsAlive; } } /// /// Gets or sets a value indicating whether or not a thread is a background thread. /// public bool IsBackground { get { return threadField.IsBackground; } set { threadField.IsBackground = value; } } /// /// Blocks the calling thread until a thread terminates /// public void Join() { threadField.Join(); } /// /// Blocks the calling thread until a thread terminates or the specified time elapses /// /// Time of wait in milliseconds public void Join(long MiliSeconds) { lock(this) { threadField.Join(new System.TimeSpan(MiliSeconds * 10000)); } } /// /// Blocks the calling thread until a thread terminates or the specified time elapses /// /// Time of wait in milliseconds /// Time of wait in nanoseconds public void Join(long MiliSeconds, int NanoSeconds) { lock(this) { threadField.Join(new System.TimeSpan(MiliSeconds * 10000 + NanoSeconds * 100)); } } /// /// Resumes a thread that has been suspended /// public void Resume() { threadField.Resume(); } /// /// Raises a ThreadAbortException in the thread on which it is invoked, /// to begin the process of terminating the thread. Calling this method /// usually terminates the thread /// public void Abort() { threadField.Abort(); } /// /// Raises a ThreadAbortException in the thread on which it is invoked, /// to begin the process of terminating the thread while also providing /// exception information about the thread termination. /// Calling this method usually terminates the thread. /// /// An object that contains application-specific information, such as state, which can be used by the thread being aborted public void Abort(System.Object stateInfo) { lock(this) { threadField.Abort(stateInfo); } } /// /// Suspends the thread, if the thread is already suspended it has no effect /// public void Suspend() { threadField.Suspend(); } /// /// Obtain a String that represents the current Object /// /// A String that represents the current Object public override System.String ToString() { return "Thread[" + Name + "," + Priority.ToString() + "," + "" + "]"; } /// /// Gets the currently running thread /// /// The currently running thread public static ThreadClass Current() { ThreadClass CurrentThread = new ThreadClass(); CurrentThread.Instance = System.Threading.Thread.CurrentThread; return CurrentThread; } } /*******************************/ /// /// This class contains different methods to manage Collections. /// public class CollectionSupport : System.Collections.CollectionBase { /// /// Creates an instance of the Collection by using an inherited constructor. /// public CollectionSupport() : base() { } /// /// Adds an specified element to the collection. /// /// The element to be added. /// Returns true if the element was successfuly added. Otherwise returns false. public virtual bool Add(System.Object element) { return (this.List.Add(element) != -1); } /// /// Adds all the elements contained in the specified collection. /// /// The collection used to extract the elements that will be added. /// Returns true if all the elements were successfuly added. Otherwise returns false. public virtual bool AddAll(System.Collections.ICollection collection) { bool result = false; if (collection!=null) { System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(collection).GetEnumerator(); while (tempEnumerator.MoveNext()) { if (tempEnumerator.Current != null) result = this.Add(tempEnumerator.Current); } } return result; } /// /// Adds all the elements contained in the specified support class collection. /// /// The collection used to extract the elements that will be added. /// Returns true if all the elements were successfuly added. Otherwise returns false. public virtual bool AddAll(CollectionSupport collection) { return this.AddAll((System.Collections.ICollection)collection); } /// /// Verifies if the specified element is contained into the collection. /// /// The element that will be verified. /// Returns true if the element is contained in the collection. Otherwise returns false. public virtual bool Contains(System.Object element) { return this.List.Contains(element); } /// /// Verifies if all the elements of the specified collection are contained into the current collection. /// /// The collection used to extract the elements that will be verified. /// Returns true if all the elements are contained in the collection. Otherwise returns false. public virtual bool ContainsAll(System.Collections.ICollection collection) { bool result = false; System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(collection).GetEnumerator(); while (tempEnumerator.MoveNext()) if (!(result = this.Contains(tempEnumerator.Current))) break; return result; } /// /// Verifies if all the elements of the specified collection are contained into the current collection. /// /// The collection used to extract the elements that will be verified. /// Returns true if all the elements are contained in the collection. Otherwise returns false. public virtual bool ContainsAll(CollectionSupport collection) { return this.ContainsAll((System.Collections.ICollection) collection); } /// /// Verifies if the collection is empty. /// /// Returns true if the collection is empty. Otherwise returns false. public virtual bool IsEmpty() { return (this.Count == 0); } /// /// Removes an specified element from the collection. /// /// The element to be removed. /// Returns true if the element was successfuly removed. Otherwise returns false. public virtual bool Remove(System.Object element) { bool result = false; if (this.Contains(element)) { this.List.Remove(element); result = true; } return result; } /// /// Removes all the elements contained into the specified collection. /// /// The collection used to extract the elements that will be removed. /// Returns true if all the elements were successfuly removed. Otherwise returns false. public virtual bool RemoveAll(System.Collections.ICollection collection) { bool result = false; System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(collection).GetEnumerator(); while (tempEnumerator.MoveNext()) { if (this.Contains(tempEnumerator.Current)) result = this.Remove(tempEnumerator.Current); } return result; } /// /// Removes all the elements contained into the specified collection. /// /// The collection used to extract the elements that will be removed. /// Returns true if all the elements were successfuly removed. Otherwise returns false. public virtual bool RemoveAll(CollectionSupport collection) { return this.RemoveAll((System.Collections.ICollection) collection); } /// /// Removes all the elements that aren't contained into the specified collection. /// /// The collection used to verify the elements that will be retained. /// Returns true if all the elements were successfully removed. Otherwise returns false. public virtual bool RetainAll(System.Collections.ICollection collection) { bool result = false; System.Collections.IEnumerator tempEnumerator = this.GetEnumerator(); CollectionSupport tempCollection = new CollectionSupport(); tempCollection.AddAll(collection); while (tempEnumerator.MoveNext()) if (!tempCollection.Contains(tempEnumerator.Current)) { result = this.Remove(tempEnumerator.Current); if (result == true) { tempEnumerator = this.GetEnumerator(); } } return result; } /// /// Removes all the elements that aren't contained into the specified collection. /// /// The collection used to verify the elements that will be retained. /// Returns true if all the elements were successfully removed. Otherwise returns false. public virtual bool RetainAll(CollectionSupport collection) { return this.RetainAll((System.Collections.ICollection) collection); } /// /// Obtains an array containing all the elements of the collection. /// /// The array containing all the elements of the collection public virtual System.Object[] ToArray() { int index = 0; System.Object[] objects = new System.Object[this.Count]; System.Collections.IEnumerator tempEnumerator = this.GetEnumerator(); while (tempEnumerator.MoveNext()) objects[index++] = tempEnumerator.Current; return objects; } /// /// Obtains an array containing all the elements of the collection. /// /// The array into which the elements of the collection will be stored. /// The array containing all the elements of the collection. public virtual System.Object[] ToArray(System.Object[] objects) { int index = 0; System.Collections.IEnumerator tempEnumerator = this.GetEnumerator(); while (tempEnumerator.MoveNext()) objects[index++] = tempEnumerator.Current; return objects; } /// /// Creates a CollectionSupport object with the contents specified in array. /// /// The array containing the elements used to populate the new CollectionSupport object. /// A CollectionSupport object populated with the contents of array. public static CollectionSupport ToCollectionSupport(System.Object[] array) { CollectionSupport tempCollectionSupport = new CollectionSupport(); tempCollectionSupport.AddAll(array); return tempCollectionSupport; } } /*******************************/ /// /// This class contains different methods to manage list collections. /// public class ListCollectionSupport : System.Collections.ArrayList { /// /// Creates a new instance of the class ListCollectionSupport. /// public ListCollectionSupport() : base() { } /// /// Creates a new instance of the class ListCollectionSupport. /// /// The collection to insert into the new object. public ListCollectionSupport(System.Collections.ICollection collection) : base(collection) { } /// /// Creates a new instance of the class ListCollectionSupport with the specified capacity. /// /// The capacity of the new array. public ListCollectionSupport(int capacity) : base(capacity) { } /// /// Adds an object to the end of the List. /// /// The value to insert in the array list. /// Returns true after adding the value. public virtual bool Add(System.Object valueToInsert) { base.Insert(this.Count, valueToInsert); return true; } /// /// Adds all the elements contained into the specified collection, starting at the specified position. /// /// Position at which to add the first element from the specified collection. /// The list used to extract the elements that will be added. /// Returns true if all the elements were successfuly added. Otherwise returns false. public virtual bool AddAll(int index, System.Collections.IList list) { bool result = false; if (list!=null) { System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(list).GetEnumerator(); int tempIndex = index; while (tempEnumerator.MoveNext()) { base.Insert(tempIndex++, tempEnumerator.Current); result = true; } } return result; } /// /// Adds all the elements contained in the specified collection. /// /// The collection used to extract the elements that will be added. /// Returns true if all the elements were successfuly added. Otherwise returns false. public virtual bool AddAll(System.Collections.IList collection) { return this.AddAll(this.Count,collection); } /// /// Adds all the elements contained in the specified support class collection. /// /// The collection used to extract the elements that will be added. /// Returns true if all the elements were successfuly added. Otherwise returns false. public virtual bool AddAll(CollectionSupport collection) { return this.AddAll(this.Count,collection); } /// /// Adds all the elements contained into the specified support class collection, starting at the specified position. /// /// Position at which to add the first element from the specified collection. /// The list used to extract the elements that will be added. /// Returns true if all the elements were successfuly added. Otherwise returns false. public virtual bool AddAll(int index, CollectionSupport collection) { return this.AddAll(index,(System.Collections.IList)collection); } /// /// Creates a copy of the ListCollectionSupport. /// /// A copy of the ListCollectionSupport. public virtual System.Object ListCollectionClone() { return MemberwiseClone(); } /// /// Returns an iterator of the collection. /// /// An IEnumerator. public virtual System.Collections.IEnumerator ListIterator() { return base.GetEnumerator(); } /// /// Removes all the elements contained into the specified collection. /// /// The collection used to extract the elements that will be removed. /// Returns true if all the elements were successfuly removed. Otherwise returns false. public virtual bool RemoveAll(System.Collections.ICollection collection) { bool result = false; System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(collection).GetEnumerator(); while (tempEnumerator.MoveNext()) { result = true; if (base.Contains(tempEnumerator.Current)) base.Remove(tempEnumerator.Current); } return result; } /// /// Removes all the elements contained into the specified collection. /// /// The collection used to extract the elements that will be removed. /// Returns true if all the elements were successfuly removed. Otherwise returns false. public virtual bool RemoveAll(CollectionSupport collection) { return this.RemoveAll((System.Collections.ICollection) collection); } /// /// Removes the value in the specified index from the list. /// /// The index of the value to remove. /// Returns the value removed. public virtual System.Object RemoveElement(int index) { System.Object objectRemoved = this[index]; this.RemoveAt(index); return objectRemoved; } /// /// Removes an specified element from the collection. /// /// The element to be removed. /// Returns true if the element was successfuly removed. Otherwise returns false. public virtual bool RemoveElement(System.Object element) { bool result = false; if (this.Contains(element)) { base.Remove(element); result = true; } return result; } /// /// Removes the first value from an array list. /// /// Returns the value removed. public virtual System.Object RemoveFirst() { System.Object objectRemoved = this[0]; this.RemoveAt(0); return objectRemoved; } /// /// Removes the last value from an array list. /// /// Returns the value removed. public virtual System.Object RemoveLast() { System.Object objectRemoved = this[this.Count-1]; base.RemoveAt(this.Count-1); return objectRemoved; } /// /// Removes all the elements that aren't contained into the specified collection. /// /// The collection used to verify the elements that will be retained. /// Returns true if all the elements were successfully removed. Otherwise returns false. public virtual bool RetainAll(System.Collections.ICollection collection) { bool result = false; System.Collections.IEnumerator tempEnumerator = this.GetEnumerator(); ListCollectionSupport tempCollection = new ListCollectionSupport(collection); while (tempEnumerator.MoveNext()) if (!tempCollection.Contains(tempEnumerator.Current)) { result = this.RemoveElement(tempEnumerator.Current); if (result == true) { tempEnumerator = this.GetEnumerator(); } } return result; } /// /// Removes all the elements that aren't contained into the specified collection. /// /// The collection used to verify the elements that will be retained. /// Returns true if all the elements were successfully removed. Otherwise returns false. public virtual bool RetainAll(CollectionSupport collection) { return this.RetainAll((System.Collections.ICollection) collection); } /// /// Verifies if all the elements of the specified collection are contained into the current collection. /// /// The collection used to extract the elements that will be verified. /// Returns true if all the elements are contained in the collection. Otherwise returns false. public virtual bool ContainsAll(System.Collections.ICollection collection) { bool result = false; System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(collection).GetEnumerator(); while (tempEnumerator.MoveNext()) if(!(result = this.Contains(tempEnumerator.Current))) break; return result; } /// /// Verifies if all the elements of the specified collection are contained into the current collection. /// /// The collection used to extract the elements that will be verified. /// Returns true if all the elements are contained in the collection. Otherwise returns false. public virtual bool ContainsAll(CollectionSupport collection) { return this.ContainsAll((System.Collections.ICollection) collection); } /// /// Returns a new list containing a portion of the current list between a specified range. /// /// The start index of the range. /// The end index of the range. /// A ListCollectionSupport instance containing the specified elements. public virtual ListCollectionSupport SubList(int startIndex, int endIndex) { int index = 0; System.Collections.IEnumerator tempEnumerator = this.GetEnumerator(); ListCollectionSupport result = new ListCollectionSupport(); for(index = startIndex; index < endIndex; index++) result.Add(this[index]); return (ListCollectionSupport)result; } /// /// Obtains an array containing all the elements of the collection. /// /// The array into which the elements of the collection will be stored. /// The array containing all the elements of the collection. public virtual System.Object[] ToArray(System.Object[] objects) { if (objects.Length < this.Count) objects = new System.Object[this.Count]; int index = 0; System.Collections.IEnumerator tempEnumerator = this.GetEnumerator(); while (tempEnumerator.MoveNext()) objects[index++] = tempEnumerator.Current; return objects; } /// /// Returns an iterator of the collection starting at the specified position. /// /// The position to set the iterator. /// An IEnumerator at the specified position. public virtual System.Collections.IEnumerator ListIterator(int index) { if ((index < 0) || (index > this.Count)) throw new System.IndexOutOfRangeException(); System.Collections.IEnumerator tempEnumerator= this.GetEnumerator(); if (index > 0) { int i=0; while ((tempEnumerator.MoveNext()) && (i < index - 1)) i++; } return tempEnumerator; } /// /// Gets the last value from a list. /// /// Returns the last element of the list. public virtual System.Object GetLast() { if (this.Count == 0) throw new System.ArgumentOutOfRangeException(); else { return this[this.Count - 1]; } } /// /// Return whether this list is empty. /// /// True if the list is empty, false if it isn't. public virtual bool IsEmpty() { return (this.Count == 0); } /// /// Replaces the element at the specified position in this list with the specified element. /// /// Index of element to replace. /// Element to be stored at the specified position. /// The element previously at the specified position. public virtual System.Object Set(int index, System.Object element) { System.Object result = this[index]; this[index] = element; return result; } /// /// Returns the element at the specified position in the list. /// /// Index of element to return. /// Element to be stored at the specified position. /// The element at the specified position in the list. public virtual System.Object Get(int index) { return this[index]; } } /*******************************/ /// /// This class manages array operations. /// public class ArraysSupport { /// /// Compares the entire members of one array whith the other one. /// /// The array to be compared. /// The array to be compared with. /// True if both arrays are equals otherwise it returns false. /// Two arrays are equal if they contains the same elements in the same order. public static bool IsArrayEqual(System.Array array1, System.Array array2) { if (array1.Length != array2.Length) return false; for (int i = 0; i < array1.Length; i++) if (!(array1.GetValue(i).Equals(array2.GetValue(i)))) return false; return true; } /// /// Fills the array with an specific value from an specific index to an specific index. /// /// The array to be filled. /// The first index to be filled. /// The last index to be filled. /// The value to fill the array with. public static void FillArray(System.Array array, System.Int32 fromindex,System.Int32 toindex, System.Object val) { System.Object Temp_Object = val; System.Type elementtype = array.GetType().GetElementType(); if (elementtype != val.GetType()) Temp_Object = System.Convert.ChangeType(val, elementtype); if (array.Length == 0) throw (new System.NullReferenceException()); if (fromindex > toindex) throw (new System.ArgumentException()); if ((fromindex < 0) || ((System.Array)array).Length < toindex) throw (new System.IndexOutOfRangeException()); for (int index = (fromindex > 0) ? fromindex-- : fromindex; index < toindex; index++) array.SetValue(Temp_Object, index); } /// /// Fills the array with an specific value. /// /// The array to be filled. /// The value to fill the array with. public static void FillArray(System.Array array, System.Object val) { FillArray(array, 0, array.Length, val); } } /*******************************/ /// /// This class manages a set of elements. /// public class SetSupport : System.Collections.ArrayList { /// /// Creates a new set. /// public SetSupport(): base() { } /// /// Creates a new set initialized with System.Collections.ICollection object /// /// System.Collections.ICollection object to initialize the set object public SetSupport(System.Collections.ICollection collection): base(collection) { } /// /// Creates a new set initialized with a specific capacity. /// /// value to set the capacity of the set object public SetSupport(int capacity): base(capacity) { } /// /// Adds an element to the set. /// /// The object to be added. /// True if the object was added, false otherwise. public new virtual bool Add(object objectToAdd) { if (this.Contains(objectToAdd)) return false; else { base.Add(objectToAdd); return true; } } /// /// Adds all the elements contained in the specified collection. /// /// The collection used to extract the elements that will be added. /// Returns true if all the elements were successfuly added. Otherwise returns false. public virtual bool AddAll(System.Collections.ICollection collection) { bool result = false; if (collection!=null) { System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(collection).GetEnumerator(); while (tempEnumerator.MoveNext()) { if (tempEnumerator.Current != null) result = this.Add(tempEnumerator.Current); } } return result; } /// /// Adds all the elements contained in the specified support class collection. /// /// The collection used to extract the elements that will be added. /// Returns true if all the elements were successfuly added. Otherwise returns false. public virtual bool AddAll(CollectionSupport collection) { return this.AddAll((System.Collections.ICollection)collection); } /// /// Verifies that all the elements of the specified collection are contained into the current collection. /// /// The collection used to extract the elements that will be verified. /// True if the collection contains all the given elements. public virtual bool ContainsAll(System.Collections.ICollection collection) { bool result = false; System.Collections.IEnumerator tempEnumerator = collection.GetEnumerator(); while (tempEnumerator.MoveNext()) if (!(result = this.Contains(tempEnumerator.Current))) break; return result; } /// /// Verifies if all the elements of the specified collection are contained into the current collection. /// /// The collection used to extract the elements that will be verified. /// Returns true if all the elements are contained in the collection. Otherwise returns false. public virtual bool ContainsAll(CollectionSupport collection) { return this.ContainsAll((System.Collections.ICollection) collection); } /// /// Verifies if the collection is empty. /// /// True if the collection is empty, false otherwise. public virtual bool IsEmpty() { return (this.Count == 0); } /// /// Removes an element from the set. /// /// The element to be removed. /// True if the element was removed. public new virtual bool Remove(object elementToRemove) { bool result = false; if (this.Contains(elementToRemove)) result = true; base.Remove(elementToRemove); return result; } /// /// Removes all the elements contained in the specified collection. /// /// The collection used to extract the elements that will be removed. /// True if all the elements were successfuly removed, false otherwise. public virtual bool RemoveAll(System.Collections.ICollection collection) { bool result = false; System.Collections.IEnumerator tempEnumerator = collection.GetEnumerator(); while (tempEnumerator.MoveNext()) { if ((result == false) && (this.Contains(tempEnumerator.Current))) result = true; this.Remove(tempEnumerator.Current); } return result; } /// /// Removes all the elements contained into the specified collection. /// /// The collection used to extract the elements that will be removed. /// Returns true if all the elements were successfuly removed. Otherwise returns false. public virtual bool RemoveAll(CollectionSupport collection) { return this.RemoveAll((System.Collections.ICollection) collection); } /// /// Removes all the elements that aren't contained in the specified collection. /// /// The collection used to verify the elements that will be retained. /// True if all the elements were successfully removed, false otherwise. public virtual bool RetainAll(System.Collections.ICollection collection) { bool result = false; System.Collections.IEnumerator tempEnumerator = collection.GetEnumerator(); SetSupport tempSet = (SetSupport)collection; while (tempEnumerator.MoveNext()) if (!tempSet.Contains(tempEnumerator.Current)) { result = this.Remove(tempEnumerator.Current); tempEnumerator = this.GetEnumerator(); } return result; } /// /// Removes all the elements that aren't contained into the specified collection. /// /// The collection used to verify the elements that will be retained. /// Returns true if all the elements were successfully removed. Otherwise returns false. public virtual bool RetainAll(CollectionSupport collection) { return this.RetainAll((System.Collections.ICollection) collection); } /// /// Obtains an array containing all the elements of the collection. /// /// The array containing all the elements of the collection. public new virtual object[] ToArray() { int index = 0; object[] tempObject= new object[this.Count]; System.Collections.IEnumerator tempEnumerator = this.GetEnumerator(); while (tempEnumerator.MoveNext()) tempObject[index++] = tempEnumerator.Current; return tempObject; } /// /// Obtains an array containing all the elements in the collection. /// /// The array into which the elements of the collection will be stored. /// The array containing all the elements of the collection. public virtual object[] ToArray(object[] objects) { int index = 0; System.Collections.IEnumerator tempEnumerator = this.GetEnumerator(); while (tempEnumerator.MoveNext()) objects[index++] = tempEnumerator.Current; return objects; } } /*******************************/ /// /// This class manages different operation with collections. /// public class AbstractSetSupport : SetSupport { /// /// The constructor with no parameters to create an abstract set. /// public AbstractSetSupport() { } } /*******************************/ /// /// Removes the element with the specified key from a Hashtable instance. /// /// The Hashtable instance /// The key of the element to remove /// The element removed public static System.Object HashtableRemove(System.Collections.Hashtable hashtable, System.Object key) { System.Object element = hashtable[key]; hashtable.Remove(key); return element; } /*******************************/ /// /// Sets the size of the ArrayList. If the new size is greater than the current capacity, then new null items are added to the end of the ArrayList. If the new size is lower than the current size, then all elements after the new size are discarded /// /// The ArrayList to be changed /// The new ArrayList size public static void SetSize(System.Collections.ArrayList arrayList, int newSize) { if (newSize < 0) throw new System.ArgumentException(); else { if (newSize < arrayList.Count) arrayList.RemoveRange(newSize,(arrayList.Count-newSize)); else while(newSize > arrayList.Count) arrayList.Add(null); } } /*******************************/ /// /// Adds an element to the top end of a Stack instance. /// /// The Stack instance /// The element to add /// The element added public static System.Object StackPush(System.Collections.Stack stack, System.Object element) { stack.Push(element); return element; } /*******************************/ /// /// Copies an array of chars obtained from a String into a specified array of chars /// /// The String to get the chars from /// Position of the String to start getting the chars /// Position of the String to end getting the chars /// Array to return the chars /// Position of the destination array of chars to start storing the chars /// An array of chars public static void GetCharsFromString(string sourceString, int sourceStart, int sourceEnd, ref char[] destinationArray, int destinationStart) { int sourceCounter; int destinationCounter; sourceCounter = sourceStart; destinationCounter = destinationStart; while (sourceCounter < sourceEnd) { destinationArray[destinationCounter] = (char) sourceString[sourceCounter]; sourceCounter++; destinationCounter++; } } /*******************************/ /// /// Creates an output file stream to write to the file with the specified name. /// /// Name of the file to write. /// True in order to write to the end of the file, false otherwise. /// New instance of FileStream with the proper file mode. public static System.IO.FileStream GetFileStream(string FileName, bool Append) { if (Append) return new System.IO.FileStream(FileName, System.IO.FileMode.Append); else return new System.IO.FileStream(FileName, System.IO.FileMode.Create); } /*******************************/ /// /// Converts an array of sbytes to an array of chars /// /// The array of sbytes to convert /// The new array of chars [CLSCompliantAttribute(false)] public static char[] ToCharArray(sbyte[] sByteArray) { char[] charArray = new char[sByteArray.Length]; sByteArray.CopyTo(charArray, 0); return charArray; } /// /// Converts an array of bytes to an array of chars /// /// The array of bytes to convert /// The new array of chars public static char[] ToCharArray(byte[] byteArray) { char[] charArray = new char[byteArray.Length]; byteArray.CopyTo(charArray, 0); return charArray; } /*******************************/ /// /// Encapsulates the functionality of message digest algorithms such as SHA-1 or MD5. /// public class MessageDigestSupport { private System.Security.Cryptography.HashAlgorithm algorithm; private byte[] data; private int position; private string algorithmName; /// /// The HashAlgorithm instance that provide the cryptographic hash algorithm /// public System.Security.Cryptography.HashAlgorithm Algorithm { get { return this.algorithm; } set { this.algorithm = value; } } /// /// The digest data /// public byte[] Data { get { return this.data; } set { this.data = value; } } /// /// The name of the cryptographic hash algorithm used in the instance /// public string AlgorithmName { get { return this.algorithmName; } } /// /// Creates a message digest using the specified name to set Algorithm property. /// /// The name of the algorithm to use public MessageDigestSupport(System.String algorithm) { if (algorithm.Equals("SHA-1")) { this.algorithmName = "SHA"; } else { this.algorithmName = algorithm; } this.Algorithm = (System.Security.Cryptography.HashAlgorithm) System.Security.Cryptography.CryptoConfig.CreateFromName(this.algorithmName); this.position = 0; } /// /// Computes the hash value for the internal data digest. /// /// The array of signed bytes with the resulting hash value [CLSCompliantAttribute(false)] public sbyte[] DigestData() { sbyte[] result = ToSByteArray(this.Algorithm.ComputeHash(this.data)); this.Reset(); return result; } /// /// Performs and update on the digest with the specified array and then completes the digest /// computation. /// /// The array of bytes for final update to the digest /// An array of signed bytes with the resulting hash value [CLSCompliantAttribute(false)] public sbyte[] DigestData(byte[] newData) { this.Update(newData); return this.DigestData(); } /// /// Updates the digest data with the specified array of bytes by making an append /// operation in the internal array of data. /// /// The array of bytes for the update operation public void Update(byte[] newData) { if (position == 0) { this.Data = newData; this.position = this.Data.Length - 1; } else { byte[] oldData = this.Data; this.Data = new byte[newData.Length + position + 1]; oldData.CopyTo(this.Data, 0); newData.CopyTo(this.Data, oldData.Length); this.position = this.Data.Length - 1; } } /// /// Updates the digest data with the input byte by calling the method Update with an array. /// /// The input byte for the update public void Update(byte newData) { byte[] newDataArray = new byte[1]; newDataArray[0] = newData; this.Update(newDataArray); } /// /// Updates the specified count of bytes with the input array of bytes starting at the /// input offset. /// /// The array of bytes for the update operation /// The initial position to start from in the array of bytes /// The number of bytes fot the update public void Update(byte[] newData, int offset, int count) { byte[] newDataArray = new byte[count]; System.Array.Copy(newData, offset, newDataArray, 0, count); this.Update(newDataArray); } /// /// Resets the digest data to the initial state. /// public void Reset() { this.data = null; this.position = 0; } /// /// Returns a string representation of the Message Digest /// /// A string representation of the object public override string ToString() { return this.Algorithm.ToString(); } /// /// Generates a new instance of the MessageDigestSupport class using the specified algorithm /// /// The name of the algorithm to use /// A new instance of the MessageDigestSupport class public static MessageDigestSupport GetInstance(System.String algorithm) { return new MessageDigestSupport(algorithm); } /// /// Compares two arrays of signed bytes evaluating equivalence in digest data /// /// An array of signed bytes for comparison /// An array of signed bytes for comparison /// True if the input digest arrays are equal [CLSCompliantAttribute(false)] public static bool EquivalentDigest(System.SByte[] firstDigest, System.SByte[] secondDigest) { bool result = false; if (firstDigest.Length == secondDigest.Length) { int index = 0; result = true; while(result && index < firstDigest.Length) { result = firstDigest[index] == secondDigest[index]; index++; } } return result; } } /*******************************/ /// /// This class uses a cryptographic Random Number Generator to provide support for /// strong pseudo-random number generation. /// public class SecureRandomSupport { private System.Security.Cryptography.RNGCryptoServiceProvider generator; /// /// Initializes a new instance of the random number generator. /// public SecureRandomSupport() { this.generator = new System.Security.Cryptography.RNGCryptoServiceProvider(); } /// /// Initializes a new instance of the random number generator with the given seed. /// /// The initial seed for the generator public SecureRandomSupport(byte[] seed) { this.generator = new System.Security.Cryptography.RNGCryptoServiceProvider(seed); } /// /// Returns an array of bytes with a sequence of cryptographically strong random values /// /// The array of bytes to fill [CLSCompliantAttribute(false)] public sbyte[] NextBytes(byte[] randomnumbersarray) { this.generator.GetBytes(randomnumbersarray); return ToSByteArray(randomnumbersarray); } /// /// Returns the given number of seed bytes generated for the first running of a new instance /// of the random number generator /// /// Number of seed bytes to generate /// Seed bytes generated public static byte[] GetSeed(int numberOfBytes) { System.Security.Cryptography.RNGCryptoServiceProvider generatedSeed = new System.Security.Cryptography.RNGCryptoServiceProvider(); byte[] seeds = new byte[numberOfBytes]; generatedSeed.GetBytes(seeds); return seeds; } /// /// Creates a new instance of the random number generator with the seed provided by the user /// /// Seed to create a new random number generator public void SetSeed(byte[] newSeed) { this.generator = new System.Security.Cryptography.RNGCryptoServiceProvider(newSeed); } /// /// Creates a new instance of the random number generator with the seed provided by the user /// /// Seed to create a new random number generator public void SetSeed(long newSeed) { byte[] bytes = new byte[8]; for (int index= 7; index > 0 ; index--) { bytes[index] = (byte)(newSeed - (long)((newSeed >> 8) << 8)); newSeed = (long)(newSeed >> 8); } SetSeed(bytes); } } /*******************************/ /// /// Interface used by classes which must be single threaded. /// public interface SingleThreadModel { } /*******************************/ /// /// Creates an instance of a received Type. /// /// The Type of the new class instance to return. /// An Object containing the new instance. public static System.Object CreateNewInstance(System.Type classType) { System.Object instance = null; System.Type[] constructor = new System.Type[]{}; System.Reflection.ConstructorInfo[] constructors = null; constructors = classType.GetConstructors(); if (constructors.Length == 0) throw new System.UnauthorizedAccessException(); else { for(int i = 0; i < constructors.Length; i++) { System.Reflection.ParameterInfo[] parameters = constructors[i].GetParameters(); if (parameters.Length == 0) { instance = classType.GetConstructor(constructor).Invoke(new System.Object[]{}); break; } else if (i == constructors.Length -1) throw new System.MethodAccessException(); } } return instance; } /*******************************/ /// /// Writes the exception stack trace to the received stream /// /// Exception to obtain information from /// Output sream used to write to public static void WriteStackTrace(System.Exception throwable, System.IO.TextWriter stream) { stream.Write(throwable.StackTrace); stream.Flush(); } /*******************************/ /// /// Determines whether two Collections instances are equals. /// /// The first Collections to compare. /// The second Collections to compare. /// Return true if the first collection is the same instance as the second collection, otherwise return false. public static bool EqualsSupport(System.Collections.ICollection source, System.Collections.ICollection target ) { System.Collections.IEnumerator sourceEnumerator = ReverseStack(source); System.Collections.IEnumerator targetEnumerator = ReverseStack(target); if (source.Count != target.Count) return false; while(sourceEnumerator.MoveNext() && targetEnumerator.MoveNext()) if (!sourceEnumerator.Current.Equals(targetEnumerator.Current)) return false; return true; } /// /// Determines if a Collection is equal to the Object. /// /// The first Collections to compare. /// The Object to compare. /// Return true if the first collection contains the same values of the second Object, otherwise return false. public static bool EqualsSupport(System.Collections.ICollection source, System.Object target) { if((target.GetType())!= (typeof(System.Collections.ICollection))) return false; else return EqualsSupport(source,(System.Collections.ICollection)target); } /// /// Determines if a IDictionaryEnumerator is equal to the Object. /// /// The first IDictionaryEnumerator to compare. /// The second Object to compare. /// Return true if the first IDictionaryEnumerator contains the same values of the second Object, otherwise return false. public static bool EqualsSupport(System.Collections.IDictionaryEnumerator source, System.Object target) { if((target.GetType())!= (typeof(System.Collections.IDictionaryEnumerator))) return false; else return EqualsSupport(source,(System.Collections.IDictionaryEnumerator)target); } /// /// Determines whether two IDictionaryEnumerator instances are equals. /// /// The first IDictionaryEnumerator to compare. /// The second IDictionaryEnumerator to compare. /// Return true if the first IDictionaryEnumerator contains the same values as the second IDictionaryEnumerator, otherwise return false. public static bool EqualsSupport(System.Collections.IDictionaryEnumerator source, System.Collections.IDictionaryEnumerator target ) { while(source.MoveNext() && target.MoveNext()) if (source.Key.Equals(target.Key)) if(source.Value.Equals(target.Value)) return true; return false; } /// /// Reverses the Stack Collection received. /// /// The collection to reverse. /// The collection received in reverse order if it was a System.Collections.Stack type, otherwise it does /// nothing to the collection. public static System.Collections.IEnumerator ReverseStack(System.Collections.ICollection collection) { if((collection.GetType()) == (typeof(System.Collections.Stack))) { System.Collections.ArrayList collectionStack = new System.Collections.ArrayList(collection); collectionStack.Reverse(); return collectionStack.GetEnumerator(); } else return collection.GetEnumerator(); } }