PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/SupportClass.cs

https://bitbucket.org/danipen/mono
C# | 2174 lines | 1193 code | 182 blank | 799 comment | 143 complexity | 29551f6981dde7353d8c4d183bfeb601 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /******************************************************************************
  2. * The MIT License
  3. * Copyright (c) 2003 Novell Inc. www.novell.com
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the Software), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *******************************************************************************/
  23. //
  24. // Novell.Directory.Ldap.SupportClass.cs
  25. //
  26. // Author:
  27. // Sunil Kumar (Sunilk@novell.com)
  28. //
  29. // (C) 2003 Novell, Inc (http://www.novell.com)
  30. //
  31. // Support classes replicate the functionality of the original code, but in some cases they are
  32. // substantially different architecturally. Although every effort is made to preserve the
  33. // original architecture of the application in the converted project, the user should be aware that
  34. // the primary goal of these support classes is to replicate functionality, and that at times
  35. // the architecture of the resulting solution may differ somewhat.
  36. //
  37. using System;
  38. /// <summary>
  39. /// This interface should be implemented by any class whose instances are intended
  40. /// to be executed by a thread.
  41. /// </summary>
  42. public interface IThreadRunnable
  43. {
  44. /// <summary>
  45. /// This method has to be implemented in order that starting of the thread causes the object's
  46. /// run method to be called in that separately executing thread.
  47. /// </summary>
  48. void Run();
  49. }
  50. public class Integer32 : System.Object
  51. {
  52. private System.Int32 _wintv;
  53. public Integer32(System.Int32 ival)
  54. {
  55. _wintv=ival;
  56. }
  57. public System.Int32 intValue
  58. {
  59. get
  60. {
  61. return _wintv;
  62. }
  63. set
  64. {
  65. _wintv=value;
  66. }
  67. }
  68. }
  69. /// <summary>
  70. /// Contains conversion support elements such as classes, interfaces and static methods.
  71. /// </summary>
  72. public class SupportClass
  73. {
  74. /// <summary>
  75. /// Receives a byte array and returns it transformed in an sbyte array
  76. /// </summary>
  77. /// <param name="byteArray">Byte array to process</param>
  78. /// <returns>The transformed array</returns>
  79. [CLSCompliantAttribute(false)]
  80. public static sbyte[] ToSByteArray(byte[] byteArray)
  81. {
  82. #if TARGET_JVM
  83. return vmw.common.TypeUtils.ToSByteArray(byteArray);
  84. #else
  85. sbyte[] sbyteArray = new sbyte[byteArray.Length];
  86. for(int index=0; index < byteArray.Length; index++)
  87. sbyteArray[index] = (sbyte) byteArray[index];
  88. return sbyteArray;
  89. #endif
  90. }
  91. /*******************************/
  92. /// <summary>
  93. /// Converts an array of sbytes to an array of bytes
  94. /// </summary>
  95. /// <param name="sbyteArray">The array of sbytes to be converted</param>
  96. /// <returns>The new array of bytes</returns>
  97. [CLSCompliantAttribute(false)]
  98. public static byte[] ToByteArray(sbyte[] sbyteArray)
  99. {
  100. #if TARGET_JVM
  101. return (byte[])vmw.common.TypeUtils.ToByteArray(sbyteArray);;
  102. #else
  103. byte[] byteArray = new byte[sbyteArray.Length];
  104. for(int index=0; index < sbyteArray.Length; index++)
  105. byteArray[index] = (byte) sbyteArray[index];
  106. return byteArray;
  107. #endif
  108. }
  109. /// <summary>
  110. /// Converts a string to an array of bytes
  111. /// </summary>
  112. /// <param name="sourceString">The string to be converted</param>
  113. /// <returns>The new array of bytes</returns>
  114. public static byte[] ToByteArray(string sourceString)
  115. {
  116. byte[] byteArray = new byte[sourceString.Length];
  117. for (int index=0; index < sourceString.Length; index++)
  118. byteArray[index] = (byte) sourceString[index];
  119. return byteArray;
  120. }
  121. /// <summary>
  122. /// Converts a array of object-type instances to a byte-type array.
  123. /// </summary>
  124. /// <param name="tempObjectArray">Array to convert.</param>
  125. /// <returns>An array of byte type elements.</returns>
  126. public static byte[] ToByteArray(object[] tempObjectArray)
  127. {
  128. byte[] byteArray = new byte[tempObjectArray.Length];
  129. for (int index = 0; index < tempObjectArray.Length; index++)
  130. byteArray[index] = (byte)tempObjectArray[index];
  131. return byteArray;
  132. }
  133. /*******************************/
  134. /// <summary>Reads a number of characters from the current source Stream and writes the data to the target array at the specified index.</summary>
  135. /// <param name="sourceStream">The source Stream to read from.</param>
  136. /// <param name="target">Contains the array of characteres read from the source Stream.</param>
  137. /// <param name="start">The starting index of the target array.</param>
  138. /// <param name="count">The maximum number of characters to read from the source Stream.</param>
  139. /// <returns>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.</returns>
  140. [CLSCompliantAttribute(false)]
  141. public static System.Int32 ReadInput(System.IO.Stream sourceStream, ref sbyte[] target, int start, int count)
  142. {
  143. // Returns 0 bytes if not enough space in target
  144. if (target.Length == 0)
  145. return 0;
  146. byte[] receiver = new byte[target.Length];
  147. int bytesRead=0;
  148. int startIndex=start;
  149. int bytesToRead=count;
  150. while( bytesToRead > 0 ) {
  151. int n= sourceStream.Read(receiver, startIndex, bytesToRead);
  152. if (n==0)
  153. break;
  154. bytesRead+=n;
  155. startIndex+=n;
  156. bytesToRead-=n;
  157. }
  158. // Returns -1 if EOF
  159. if (bytesRead == 0)
  160. return -1;
  161. for(int i = start; i < start + bytesRead; i++)
  162. target[i] = (sbyte)receiver[i];
  163. return bytesRead;
  164. }
  165. /// <summary>Reads a number of characters from the current source TextReader and writes the data to the target array at the specified index.</summary>
  166. /// <param name="sourceTextReader">The source TextReader to read from</param>
  167. /// <param name="target">Contains the array of characteres read from the source TextReader.</param>
  168. /// <param name="start">The starting index of the target array.</param>
  169. /// <param name="count">The maximum number of characters to read from the source TextReader.</param>
  170. /// <returns>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.</returns>
  171. [CLSCompliantAttribute(false)]
  172. public static System.Int32 ReadInput(System.IO.TextReader sourceTextReader, ref sbyte[] target, int start, int count)
  173. {
  174. // Returns 0 bytes if not enough space in target
  175. if (target.Length == 0) return 0;
  176. char[] charArray = new char[target.Length];
  177. int bytesRead = sourceTextReader.Read(charArray, start, count);
  178. // Returns -1 if EOF
  179. if (bytesRead == 0) return -1;
  180. for(int index=start; index<start+bytesRead; index++)
  181. target[index] = (sbyte)charArray[index];
  182. return bytesRead;
  183. }
  184. /*******************************/
  185. /// <summary>
  186. /// This method returns the literal value received
  187. /// </summary>
  188. /// <param name="literal">The literal to return</param>
  189. /// <returns>The received value</returns>
  190. public static long Identity(long literal)
  191. {
  192. return literal;
  193. }
  194. /// <summary>
  195. /// This method returns the literal value received
  196. /// </summary>
  197. /// <param name="literal">The literal to return</param>
  198. /// <returns>The received value</returns>
  199. [CLSCompliantAttribute(false)]
  200. public static ulong Identity(ulong literal)
  201. {
  202. return literal;
  203. }
  204. /// <summary>
  205. /// This method returns the literal value received
  206. /// </summary>
  207. /// <param name="literal">The literal to return</param>
  208. /// <returns>The received value</returns>
  209. public static float Identity(float literal)
  210. {
  211. return literal;
  212. }
  213. /// <summary>
  214. /// This method returns the literal value received
  215. /// </summary>
  216. /// <param name="literal">The literal to return</param>
  217. /// <returns>The received value</returns>
  218. public static double Identity(double literal)
  219. {
  220. return literal;
  221. }
  222. /*******************************/
  223. /// <summary>
  224. /// The class performs token processing from strings
  225. /// </summary>
  226. public class Tokenizer
  227. {
  228. //Element list identified
  229. private System.Collections.ArrayList elements;
  230. //Source string to use
  231. private string source;
  232. //The tokenizer uses the default delimiter set: the space character, the tab character, the newline character, and the carriage-return character
  233. private string delimiters = " \t\n\r";
  234. private bool returnDelims=false;
  235. /// <summary>
  236. /// Initializes a new class instance with a specified string to process
  237. /// </summary>
  238. /// <param name="source">String to tokenize</param>
  239. public Tokenizer(string source)
  240. {
  241. this.elements = new System.Collections.ArrayList();
  242. this.elements.AddRange(source.Split(this.delimiters.ToCharArray()));
  243. this.RemoveEmptyStrings();
  244. this.source = source;
  245. }
  246. /// <summary>
  247. /// Initializes a new class instance with a specified string to process
  248. /// and the specified token delimiters to use
  249. /// </summary>
  250. /// <param name="source">String to tokenize</param>
  251. /// <param name="delimiters">String containing the delimiters</param>
  252. public Tokenizer(string source, string delimiters)
  253. {
  254. this.elements = new System.Collections.ArrayList();
  255. this.delimiters = delimiters;
  256. this.elements.AddRange(source.Split(this.delimiters.ToCharArray()));
  257. this.RemoveEmptyStrings();
  258. this.source = source;
  259. }
  260. public Tokenizer(string source, string delimiters,bool retDel)
  261. {
  262. this.elements = new System.Collections.ArrayList();
  263. this.delimiters = delimiters;
  264. this.source = source;
  265. this.returnDelims = retDel;
  266. if( returnDelims)
  267. Tokenize();
  268. else
  269. this.elements.AddRange(source.Split(this.delimiters.ToCharArray()));
  270. this.RemoveEmptyStrings();
  271. }
  272. private void Tokenize()
  273. {
  274. string tempstr = this.source;
  275. string toks = "";
  276. if (tempstr.IndexOfAny(this.delimiters.ToCharArray()) < 0 && tempstr.Length > 0)
  277. {
  278. this.elements.Add(tempstr);
  279. }
  280. else if (tempstr.IndexOfAny(this.delimiters.ToCharArray()) < 0 && tempstr.Length <= 0)
  281. {
  282. return;
  283. }
  284. while (tempstr.IndexOfAny(this.delimiters.ToCharArray()) >= 0)
  285. {
  286. if(tempstr.IndexOfAny(this.delimiters.ToCharArray()) == 0)
  287. {
  288. if (tempstr.Length > 1 )
  289. {
  290. this.elements.Add(tempstr.Substring(0,1));
  291. tempstr=tempstr.Substring(1);
  292. }
  293. else
  294. tempstr = "";
  295. }
  296. else
  297. {
  298. toks = tempstr.Substring(0,tempstr.IndexOfAny(this.delimiters.ToCharArray()));
  299. this.elements.Add(toks);
  300. this.elements.Add(tempstr.Substring(toks.Length,1));
  301. if ( tempstr.Length > (toks.Length + 1))
  302. {
  303. tempstr = tempstr.Substring(toks.Length + 1);
  304. }
  305. else
  306. tempstr = "";
  307. }
  308. }
  309. if (tempstr.Length > 0)
  310. {
  311. this.elements.Add(tempstr);
  312. }
  313. }
  314. /// <summary>
  315. /// Current token count for the source string
  316. /// </summary>
  317. public int Count
  318. {
  319. get
  320. {
  321. return (this.elements.Count);
  322. }
  323. }
  324. /// <summary>
  325. /// Determines if there are more tokens to return from the source string
  326. /// </summary>
  327. /// <returns>True or false, depending if there are more tokens</returns>
  328. public bool HasMoreTokens()
  329. {
  330. return (this.elements.Count > 0);
  331. }
  332. /// <summary>
  333. /// Returns the next token from the token list
  334. /// </summary>
  335. /// <returns>The string value of the token</returns>
  336. public string NextToken()
  337. {
  338. string result;
  339. if (source == "") throw new System.Exception();
  340. else
  341. {
  342. if(returnDelims){
  343. // Tokenize();
  344. RemoveEmptyStrings();
  345. result = (string) this.elements[0];
  346. this.elements.RemoveAt(0);
  347. return result;
  348. }
  349. else
  350. {
  351. this.elements = new System.Collections.ArrayList();
  352. this.elements.AddRange(this.source.Split(delimiters.ToCharArray()));
  353. RemoveEmptyStrings();
  354. result = (string) this.elements[0];
  355. this.elements.RemoveAt(0);
  356. this.source = this.source.Remove(this.source.IndexOf(result),result.Length);
  357. this.source = this.source.TrimStart(this.delimiters.ToCharArray());
  358. return result;
  359. }
  360. }
  361. }
  362. /// <summary>
  363. /// Returns the next token from the source string, using the provided
  364. /// token delimiters
  365. /// </summary>
  366. /// <param name="delimiters">String containing the delimiters to use</param>
  367. /// <returns>The string value of the token</returns>
  368. public string NextToken(string delimiters)
  369. {
  370. this.delimiters = delimiters;
  371. return NextToken();
  372. }
  373. /// <summary>
  374. /// Removes all empty strings from the token list
  375. /// </summary>
  376. private void RemoveEmptyStrings()
  377. {
  378. for (int index=0; index < this.elements.Count; index++)
  379. if ((string)this.elements[index]== "")
  380. {
  381. this.elements.RemoveAt(index);
  382. index--;
  383. }
  384. }
  385. }
  386. /*******************************/
  387. /// <summary>
  388. /// Provides support for DateFormat
  389. /// </summary>
  390. public class DateTimeFormatManager
  391. {
  392. static public DateTimeFormatHashTable manager = new DateTimeFormatHashTable();
  393. /// <summary>
  394. /// Hashtable class to provide functionality for dateformat properties
  395. /// </summary>
  396. public class DateTimeFormatHashTable :System.Collections.Hashtable
  397. {
  398. /// <summary>
  399. /// Sets the format for datetime.
  400. /// </summary>
  401. /// <param name="format">DateTimeFormat instance to set the pattern</param>
  402. /// <param name="newPattern">A string with the pattern format</param>
  403. public void SetDateFormatPattern(System.Globalization.DateTimeFormatInfo format, System.String newPattern)
  404. {
  405. if (this[format] != null)
  406. ((DateTimeFormatProperties) this[format]).DateFormatPattern = newPattern;
  407. else
  408. {
  409. DateTimeFormatProperties tempProps = new DateTimeFormatProperties();
  410. tempProps.DateFormatPattern = newPattern;
  411. Add(format, tempProps);
  412. }
  413. }
  414. /// <summary>
  415. /// Gets the current format pattern of the DateTimeFormat instance
  416. /// </summary>
  417. /// <param name="format">The DateTimeFormat instance which the value will be obtained</param>
  418. /// <returns>The string representing the current datetimeformat pattern</returns>
  419. public string GetDateFormatPattern(System.Globalization.DateTimeFormatInfo format)
  420. {
  421. if (this[format] == null)
  422. return "d-MMM-yy";
  423. else
  424. return ((DateTimeFormatProperties) this[format]).DateFormatPattern;
  425. }
  426. /// <summary>
  427. /// Sets the datetimeformat pattern to the giving format
  428. /// </summary>
  429. /// <param name="format">The datetimeformat instance to set</param>
  430. /// <param name="newPattern">The new datetimeformat pattern</param>
  431. public void SetTimeFormatPattern(System.Globalization.DateTimeFormatInfo format, System.String newPattern)
  432. {
  433. if (this[format] != null)
  434. ((DateTimeFormatProperties) this[format]).TimeFormatPattern = newPattern;
  435. else
  436. {
  437. DateTimeFormatProperties tempProps = new DateTimeFormatProperties();
  438. tempProps.TimeFormatPattern = newPattern;
  439. Add(format, tempProps);
  440. }
  441. }
  442. /// <summary>
  443. /// Gets the current format pattern of the DateTimeFormat instance
  444. /// </summary>
  445. /// <param name="format">The DateTimeFormat instance which the value will be obtained</param>
  446. /// <returns>The string representing the current datetimeformat pattern</returns>
  447. public string GetTimeFormatPattern(System.Globalization.DateTimeFormatInfo format)
  448. {
  449. if (this[format] == null)
  450. return "h:mm:ss tt";
  451. else
  452. return ((DateTimeFormatProperties) this[format]).TimeFormatPattern;
  453. }
  454. /// <summary>
  455. /// Internal class to provides the DateFormat and TimeFormat pattern properties on .NET
  456. /// </summary>
  457. class DateTimeFormatProperties
  458. {
  459. public string DateFormatPattern = "d-MMM-yy";
  460. public string TimeFormatPattern = "h:mm:ss tt";
  461. }
  462. }
  463. }
  464. /*******************************/
  465. /// <summary>
  466. /// Gets the DateTimeFormat instance and date instance to obtain the date with the format passed
  467. /// </summary>
  468. /// <param name="format">The DateTimeFormat to obtain the time and date pattern</param>
  469. /// <param name="date">The date instance used to get the date</param>
  470. /// <returns>A string representing the date with the time and date patterns</returns>
  471. public static string FormatDateTime(System.Globalization.DateTimeFormatInfo format, System.DateTime date)
  472. {
  473. string timePattern = DateTimeFormatManager.manager.GetTimeFormatPattern(format);
  474. string datePattern = DateTimeFormatManager.manager.GetDateFormatPattern(format);
  475. return date.ToString(datePattern + " " + timePattern, format);
  476. }
  477. /*******************************/
  478. /// <summary>
  479. /// Adds a new key-and-value pair into the hash table
  480. /// </summary>
  481. /// <param name="collection">The collection to work with</param>
  482. /// <param name="key">Key used to obtain the value</param>
  483. /// <param name="newValue">Value asociated with the key</param>
  484. /// <returns>The old element associated with the key</returns>
  485. public static System.Object PutElement(System.Collections.IDictionary collection, System.Object key, System.Object newValue)
  486. {
  487. System.Object element = collection[key];
  488. collection[key] = newValue;
  489. return element;
  490. }
  491. /*******************************/
  492. /// <summary>
  493. /// This class contains static methods to manage arrays.
  494. /// </summary>
  495. public class ArrayListSupport
  496. {
  497. /// <summary>
  498. /// Obtains an array containing all the elements of the collection.
  499. /// </summary>
  500. /// <param name="collection">The collection from wich to obtain the elements.</param>
  501. /// <param name="objects">The array containing all the elements of the collection.</param>
  502. /// <returns>The array containing all the elements of the collection.</returns>
  503. public static System.Object[] ToArray(System.Collections.ArrayList collection, System.Object[] objects)
  504. {
  505. int index = 0;
  506. System.Collections.IEnumerator tempEnumerator = collection.GetEnumerator();
  507. while (tempEnumerator.MoveNext())
  508. objects[index++] = tempEnumerator.Current;
  509. return objects;
  510. }
  511. }
  512. /*******************************/
  513. /// <summary>
  514. /// Removes the first occurrence of an specific object from an ArrayList instance.
  515. /// </summary>
  516. /// <param name="arrayList">The ArrayList instance</param>
  517. /// <param name="element">The element to remove</param>
  518. /// <returns>True if item is found in the ArrayList; otherwise, false</returns>
  519. public static System.Boolean VectorRemoveElement(System.Collections.IList arrayList, System.Object element)
  520. {
  521. System.Boolean containsItem = arrayList.Contains(element);
  522. arrayList.Remove(element);
  523. return containsItem;
  524. }
  525. /*******************************/
  526. /// <summary>
  527. /// Support class used to handle threads
  528. /// </summary>
  529. public class ThreadClass : IThreadRunnable
  530. {
  531. /// <summary>
  532. /// The instance of System.Threading.Thread
  533. /// </summary>
  534. private System.Threading.Thread threadField;
  535. /// <summary>
  536. /// Initializes a new instance of the ThreadClass class
  537. /// </summary>
  538. public ThreadClass()
  539. {
  540. threadField = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
  541. }
  542. /// <summary>
  543. /// Initializes a new instance of the Thread class.
  544. /// </summary>
  545. /// <param name="Name">The name of the thread</param>
  546. public ThreadClass(string Name)
  547. {
  548. threadField = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
  549. this.Name = Name;
  550. }
  551. /// <summary>
  552. /// Initializes a new instance of the Thread class.
  553. /// </summary>
  554. /// <param name="Start">A ThreadStart delegate that references the methods to be invoked when this thread begins executing</param>
  555. public ThreadClass(System.Threading.ThreadStart Start)
  556. {
  557. threadField = new System.Threading.Thread(Start);
  558. }
  559. /// <summary>
  560. /// Initializes a new instance of the Thread class.
  561. /// </summary>
  562. /// <param name="Start">A ThreadStart delegate that references the methods to be invoked when this thread begins executing</param>
  563. /// <param name="Name">The name of the thread</param>
  564. public ThreadClass(System.Threading.ThreadStart Start, string Name)
  565. {
  566. threadField = new System.Threading.Thread(Start);
  567. this.Name = Name;
  568. }
  569. /// <summary>
  570. /// This method has no functionality unless the method is overridden
  571. /// </summary>
  572. public virtual void Run()
  573. {
  574. }
  575. /// <summary>
  576. /// Causes the operating system to change the state of the current thread instance to ThreadState.Running
  577. /// </summary>
  578. public virtual void Start()
  579. {
  580. threadField.Start();
  581. }
  582. /// <summary>
  583. /// Interrupts a thread that is in the WaitSleepJoin thread state
  584. /// </summary>
  585. public virtual void Interrupt()
  586. {
  587. threadField.Interrupt();
  588. }
  589. /// <summary>
  590. /// Gets the current thread instance
  591. /// </summary>
  592. public System.Threading.Thread Instance
  593. {
  594. get
  595. {
  596. return threadField;
  597. }
  598. set
  599. {
  600. threadField = value;
  601. }
  602. }
  603. /// <summary>
  604. /// Gets or sets the name of the thread
  605. /// </summary>
  606. public System.String Name
  607. {
  608. get
  609. {
  610. return threadField.Name;
  611. }
  612. set
  613. {
  614. if (threadField.Name == null)
  615. threadField.Name = value;
  616. }
  617. }
  618. /// <summary>
  619. /// Gets or sets a value indicating the scheduling priority of a thread
  620. /// </summary>
  621. public System.Threading.ThreadPriority Priority
  622. {
  623. get
  624. {
  625. return threadField.Priority;
  626. }
  627. set
  628. {
  629. threadField.Priority = value;
  630. }
  631. }
  632. /// <summary>
  633. /// Gets a value indicating the execution status of the current thread
  634. /// </summary>
  635. public bool IsAlive
  636. {
  637. get
  638. {
  639. return threadField.IsAlive;
  640. }
  641. }
  642. /// <summary>
  643. /// Gets or sets a value indicating whether or not a thread is a background thread.
  644. /// </summary>
  645. public bool IsBackground
  646. {
  647. get
  648. {
  649. return threadField.IsBackground;
  650. }
  651. set
  652. {
  653. threadField.IsBackground = value;
  654. }
  655. }
  656. /// <summary>
  657. /// Blocks the calling thread until a thread terminates
  658. /// </summary>
  659. public void Join()
  660. {
  661. threadField.Join();
  662. }
  663. /// <summary>
  664. /// Blocks the calling thread until a thread terminates or the specified time elapses
  665. /// </summary>
  666. /// <param name="MiliSeconds">Time of wait in milliseconds</param>
  667. public void Join(long MiliSeconds)
  668. {
  669. lock(this)
  670. {
  671. threadField.Join(new System.TimeSpan(MiliSeconds * 10000));
  672. }
  673. }
  674. /// <summary>
  675. /// Blocks the calling thread until a thread terminates or the specified time elapses
  676. /// </summary>
  677. /// <param name="MiliSeconds">Time of wait in milliseconds</param>
  678. /// <param name="NanoSeconds">Time of wait in nanoseconds</param>
  679. public void Join(long MiliSeconds, int NanoSeconds)
  680. {
  681. lock(this)
  682. {
  683. threadField.Join(new System.TimeSpan(MiliSeconds * 10000 + NanoSeconds * 100));
  684. }
  685. }
  686. /// <summary>
  687. /// Resumes a thread that has been suspended
  688. /// </summary>
  689. public void Resume()
  690. {
  691. threadField.Resume();
  692. }
  693. /// <summary>
  694. /// Raises a ThreadAbortException in the thread on which it is invoked,
  695. /// to begin the process of terminating the thread. Calling this method
  696. /// usually terminates the thread
  697. /// </summary>
  698. public void Abort()
  699. {
  700. threadField.Abort();
  701. }
  702. /// <summary>
  703. /// Raises a ThreadAbortException in the thread on which it is invoked,
  704. /// to begin the process of terminating the thread while also providing
  705. /// exception information about the thread termination.
  706. /// Calling this method usually terminates the thread.
  707. /// </summary>
  708. /// <param name="stateInfo">An object that contains application-specific information, such as state, which can be used by the thread being aborted</param>
  709. public void Abort(System.Object stateInfo)
  710. {
  711. lock(this)
  712. {
  713. threadField.Abort(stateInfo);
  714. }
  715. }
  716. /// <summary>
  717. /// Suspends the thread, if the thread is already suspended it has no effect
  718. /// </summary>
  719. public void Suspend()
  720. {
  721. threadField.Suspend();
  722. }
  723. /// <summary>
  724. /// Obtain a String that represents the current Object
  725. /// </summary>
  726. /// <returns>A String that represents the current Object</returns>
  727. public override System.String ToString()
  728. {
  729. return "Thread[" + Name + "," + Priority.ToString() + "," + "" + "]";
  730. }
  731. /// <summary>
  732. /// Gets the currently running thread
  733. /// </summary>
  734. /// <returns>The currently running thread</returns>
  735. public static ThreadClass Current()
  736. {
  737. ThreadClass CurrentThread = new ThreadClass();
  738. CurrentThread.Instance = System.Threading.Thread.CurrentThread;
  739. return CurrentThread;
  740. }
  741. }
  742. /*******************************/
  743. /// <summary>
  744. /// This class contains different methods to manage Collections.
  745. /// </summary>
  746. public class CollectionSupport : System.Collections.CollectionBase
  747. {
  748. /// <summary>
  749. /// Creates an instance of the Collection by using an inherited constructor.
  750. /// </summary>
  751. public CollectionSupport() : base()
  752. {
  753. }
  754. /// <summary>
  755. /// Adds an specified element to the collection.
  756. /// </summary>
  757. /// <param name="element">The element to be added.</param>
  758. /// <returns>Returns true if the element was successfuly added. Otherwise returns false.</returns>
  759. public virtual bool Add(System.Object element)
  760. {
  761. return (this.List.Add(element) != -1);
  762. }
  763. /// <summary>
  764. /// Adds all the elements contained in the specified collection.
  765. /// </summary>
  766. /// <param name="collection">The collection used to extract the elements that will be added.</param>
  767. /// <returns>Returns true if all the elements were successfuly added. Otherwise returns false.</returns>
  768. public virtual bool AddAll(System.Collections.ICollection collection)
  769. {
  770. bool result = false;
  771. if (collection!=null)
  772. {
  773. System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(collection).GetEnumerator();
  774. while (tempEnumerator.MoveNext())
  775. {
  776. if (tempEnumerator.Current != null)
  777. result = this.Add(tempEnumerator.Current);
  778. }
  779. }
  780. return result;
  781. }
  782. /// <summary>
  783. /// Adds all the elements contained in the specified support class collection.
  784. /// </summary>
  785. /// <param name="collection">The collection used to extract the elements that will be added.</param>
  786. /// <returns>Returns true if all the elements were successfuly added. Otherwise returns false.</returns>
  787. public virtual bool AddAll(CollectionSupport collection)
  788. {
  789. return this.AddAll((System.Collections.ICollection)collection);
  790. }
  791. /// <summary>
  792. /// Verifies if the specified element is contained into the collection.
  793. /// </summary>
  794. /// <param name="element"> The element that will be verified.</param>
  795. /// <returns>Returns true if the element is contained in the collection. Otherwise returns false.</returns>
  796. public virtual bool Contains(System.Object element)
  797. {
  798. return this.List.Contains(element);
  799. }
  800. /// <summary>
  801. /// Verifies if all the elements of the specified collection are contained into the current collection.
  802. /// </summary>
  803. /// <param name="collection">The collection used to extract the elements that will be verified.</param>
  804. /// <returns>Returns true if all the elements are contained in the collection. Otherwise returns false.</returns>
  805. public virtual bool ContainsAll(System.Collections.ICollection collection)
  806. {
  807. bool result = false;
  808. System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(collection).GetEnumerator();
  809. while (tempEnumerator.MoveNext())
  810. if (!(result = this.Contains(tempEnumerator.Current)))
  811. break;
  812. return result;
  813. }
  814. /// <summary>
  815. /// Verifies if all the elements of the specified collection are contained into the current collection.
  816. /// </summary>
  817. /// <param name="collection">The collection used to extract the elements that will be verified.</param>
  818. /// <returns>Returns true if all the elements are contained in the collection. Otherwise returns false.</returns>
  819. public virtual bool ContainsAll(CollectionSupport collection)
  820. {
  821. return this.ContainsAll((System.Collections.ICollection) collection);
  822. }
  823. /// <summary>
  824. /// Verifies if the collection is empty.
  825. /// </summary>
  826. /// <returns>Returns true if the collection is empty. Otherwise returns false.</returns>
  827. public virtual bool IsEmpty()
  828. {
  829. return (this.Count == 0);
  830. }
  831. /// <summary>
  832. /// Removes an specified element from the collection.
  833. /// </summary>
  834. /// <param name="element">The element to be removed.</param>
  835. /// <returns>Returns true if the element was successfuly removed. Otherwise returns false.</returns>
  836. public virtual bool Remove(System.Object element)
  837. {
  838. bool result = false;
  839. if (this.Contains(element))
  840. {
  841. this.List.Remove(element);
  842. result = true;
  843. }
  844. return result;
  845. }
  846. /// <summary>
  847. /// Removes all the elements contained into the specified collection.
  848. /// </summary>
  849. /// <param name="collection">The collection used to extract the elements that will be removed.</param>
  850. /// <returns>Returns true if all the elements were successfuly removed. Otherwise returns false.</returns>
  851. public virtual bool RemoveAll(System.Collections.ICollection collection)
  852. {
  853. bool result = false;
  854. System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(collection).GetEnumerator();
  855. while (tempEnumerator.MoveNext())
  856. {
  857. if (this.Contains(tempEnumerator.Current))
  858. result = this.Remove(tempEnumerator.Current);
  859. }
  860. return result;
  861. }
  862. /// <summary>
  863. /// Removes all the elements contained into the specified collection.
  864. /// </summary>
  865. /// <param name="collection">The collection used to extract the elements that will be removed.</param>
  866. /// <returns>Returns true if all the elements were successfuly removed. Otherwise returns false.</returns>
  867. public virtual bool RemoveAll(CollectionSupport collection)
  868. {
  869. return this.RemoveAll((System.Collections.ICollection) collection);
  870. }
  871. /// <summary>
  872. /// Removes all the elements that aren't contained into the specified collection.
  873. /// </summary>
  874. /// <param name="collection">The collection used to verify the elements that will be retained.</param>
  875. /// <returns>Returns true if all the elements were successfully removed. Otherwise returns false.</returns>
  876. public virtual bool RetainAll(System.Collections.ICollection collection)
  877. {
  878. bool result = false;
  879. System.Collections.IEnumerator tempEnumerator = this.GetEnumerator();
  880. CollectionSupport tempCollection = new CollectionSupport();
  881. tempCollection.AddAll(collection);
  882. while (tempEnumerator.MoveNext())
  883. if (!tempCollection.Contains(tempEnumerator.Current))
  884. {
  885. result = this.Remove(tempEnumerator.Current);
  886. if (result == true)
  887. {
  888. tempEnumerator = this.GetEnumerator();
  889. }
  890. }
  891. return result;
  892. }
  893. /// <summary>
  894. /// Removes all the elements that aren't contained into the specified collection.
  895. /// </summary>
  896. /// <param name="collection">The collection used to verify the elements that will be retained.</param>
  897. /// <returns>Returns true if all the elements were successfully removed. Otherwise returns false.</returns>
  898. public virtual bool RetainAll(CollectionSupport collection)
  899. {
  900. return this.RetainAll((System.Collections.ICollection) collection);
  901. }
  902. /// <summary>
  903. /// Obtains an array containing all the elements of the collection.
  904. /// </summary>
  905. /// <returns>The array containing all the elements of the collection</returns>
  906. public virtual System.Object[] ToArray()
  907. {
  908. int index = 0;
  909. System.Object[] objects = new System.Object[this.Count];
  910. System.Collections.IEnumerator tempEnumerator = this.GetEnumerator();
  911. while (tempEnumerator.MoveNext())
  912. objects[index++] = tempEnumerator.Current;
  913. return objects;
  914. }
  915. /// <summary>
  916. /// Obtains an array containing all the elements of the collection.
  917. /// </summary>
  918. /// <param name="objects">The array into which the elements of the collection will be stored.</param>
  919. /// <returns>The array containing all the elements of the collection.</returns>
  920. public virtual System.Object[] ToArray(System.Object[] objects)
  921. {
  922. int index = 0;
  923. System.Collections.IEnumerator tempEnumerator = this.GetEnumerator();
  924. while (tempEnumerator.MoveNext())
  925. objects[index++] = tempEnumerator.Current;
  926. return objects;
  927. }
  928. /// <summary>
  929. /// Creates a CollectionSupport object with the contents specified in array.
  930. /// </summary>
  931. /// <param name="array">The array containing the elements used to populate the new CollectionSupport object.</param>
  932. /// <returns>A CollectionSupport object populated with the contents of array.</returns>
  933. public static CollectionSupport ToCollectionSupport(System.Object[] array)
  934. {
  935. CollectionSupport tempCollectionSupport = new CollectionSupport();
  936. tempCollectionSupport.AddAll(array);
  937. return tempCollectionSupport;
  938. }
  939. }
  940. /*******************************/
  941. /// <summary>
  942. /// This class contains different methods to manage list collections.
  943. /// </summary>
  944. public class ListCollectionSupport : System.Collections.ArrayList
  945. {
  946. /// <summary>
  947. /// Creates a new instance of the class ListCollectionSupport.
  948. /// </summary>
  949. public ListCollectionSupport() : base()
  950. {
  951. }
  952. /// <summary>
  953. /// Creates a new instance of the class ListCollectionSupport.
  954. /// </summary>
  955. /// <param name="collection">The collection to insert into the new object.</param>
  956. public ListCollectionSupport(System.Collections.ICollection collection) : base(collection)
  957. {
  958. }
  959. /// <summary>
  960. /// Creates a new instance of the class ListCollectionSupport with the specified capacity.
  961. /// </summary>
  962. /// <param name="capacity">The capacity of the new array.</param>
  963. public ListCollectionSupport(int capacity) : base(capacity)
  964. {
  965. }
  966. /// <summary>
  967. /// Adds an object to the end of the List.
  968. /// </summary>
  969. /// <param name="valueToInsert">The value to insert in the array list.</param>
  970. /// <returns>Returns true after adding the value.</returns>
  971. public virtual bool Add(System.Object valueToInsert)
  972. {
  973. base.Insert(this.Count, valueToInsert);
  974. return true;
  975. }
  976. /// <summary>
  977. /// Adds all the elements contained into the specified collection, starting at the specified position.
  978. /// </summary>
  979. /// <param name="index">Position at which to add the first element from the specified collection.</param>
  980. /// <param name="list">The list used to extract the elements that will be added.</param>
  981. /// <returns>Returns true if all the elements were successfuly added. Otherwise returns false.</returns>
  982. public virtual bool AddAll(int index, System.Collections.IList list)
  983. {
  984. bool result = false;
  985. if (list!=null)
  986. {
  987. System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(list).GetEnumerator();
  988. int tempIndex = index;
  989. while (tempEnumerator.MoveNext())
  990. {
  991. base.Insert(tempIndex++, tempEnumerator.Current);
  992. result = true;
  993. }
  994. }
  995. return result;
  996. }
  997. /// <summary>
  998. /// Adds all the elements contained in the specified collection.
  999. /// </summary>
  1000. /// <param name="collection">The collection used to extract the elements that will be added.</param>
  1001. /// <returns>Returns true if all the elements were successfuly added. Otherwise returns false.</returns>
  1002. public virtual bool AddAll(System.Collections.IList collection)
  1003. {
  1004. return this.AddAll(this.Count,collection);
  1005. }
  1006. /// <summary>
  1007. /// Adds all the elements contained in the specified support class collection.
  1008. /// </summary>
  1009. /// <param name="collection">The collection used to extract the elements that will be added.</param>
  1010. /// <returns>Returns true if all the elements were successfuly added. Otherwise returns false.</returns>
  1011. public virtual bool AddAll(CollectionSupport collection)
  1012. {
  1013. return this.AddAll(this.Count,collection);
  1014. }
  1015. /// <summary>
  1016. /// Adds all the elements contained into the specified support class collection, starting at the specified position.
  1017. /// </summary>
  1018. /// <param name="index">Position at which to add the first element from the specified collection.</param>
  1019. /// <param name="list">The list used to extract the elements that will be added.</param>
  1020. /// <returns>Returns true if all the elements were successfuly added. Otherwise returns false.</returns>
  1021. public virtual bool AddAll(int index, CollectionSupport collection)
  1022. {
  1023. return this.AddAll(index,(System.Collections.IList)collection);
  1024. }
  1025. /// <summary>
  1026. /// Creates a copy of the ListCollectionSupport.
  1027. /// </summary>
  1028. /// <returns> A copy of the ListCollectionSupport.</returns>
  1029. public virtual System.Object ListCollectionClone()
  1030. {
  1031. return MemberwiseClone();
  1032. }
  1033. /// <summary>
  1034. /// Returns an iterator of the collection.
  1035. /// </summary>
  1036. /// <returns>An IEnumerator.</returns>
  1037. public virtual System.Collections.IEnumerator ListIterator()
  1038. {
  1039. return base.GetEnumerator();
  1040. }
  1041. /// <summary>
  1042. /// Removes all the elements contained into the specified collection.
  1043. /// </summary>
  1044. /// <param name="collection">The collection used to extract the elements that will be removed.</param>
  1045. /// <returns>Returns true if all the elements were successfuly removed. Otherwise returns false.</returns>
  1046. public virtual bool RemoveAll(System.Collections.ICollection collection)
  1047. {
  1048. bool result = false;
  1049. System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(collection).GetEnumerator();
  1050. while (tempEnumerator.MoveNext())
  1051. {
  1052. result = true;
  1053. if (base.Contains(tempEnumerator.Current))
  1054. base.Remove(tempEnumerator.Current);
  1055. }
  1056. return result;
  1057. }
  1058. /// <summary>
  1059. /// Removes all the elements contained into the specified collection.
  1060. /// </summary>
  1061. /// <param name="collection">The collection used to extract the elements that will be removed.</param>
  1062. /// <returns>Returns true if all the elements were successfuly removed. Otherwise returns false.</returns>
  1063. public virtual bool RemoveAll(CollectionSupport collection)
  1064. {
  1065. return this.RemoveAll((System.Collections.ICollection) collection);
  1066. }
  1067. /// <summary>
  1068. /// Removes the value in the specified index from the list.
  1069. /// </summary>
  1070. /// <param name="index">The index of the value to remove.</param>
  1071. /// <returns>Returns the value removed.</returns>
  1072. public virtual System.Object RemoveElement(int index)
  1073. {
  1074. System.Object objectRemoved = this[index];
  1075. this.RemoveAt(index);
  1076. return objectRemoved;
  1077. }
  1078. /// <summary>
  1079. /// Removes an specified element from the collection.
  1080. /// </summary>
  1081. /// <param name="element">The element to be removed.</param>
  1082. /// <returns>Returns true if the element was successfuly removed. Otherwise returns false.</returns>
  1083. public virtual bool RemoveElement(System.Object element)
  1084. {
  1085. bool result = false;
  1086. if (this.Contains(element))
  1087. {
  1088. base.Remove(element);
  1089. result = true;
  1090. }
  1091. return result;
  1092. }
  1093. /// <summary>
  1094. /// Removes the first value from an array list.
  1095. /// </summary>
  1096. /// <returns>Returns the value removed.</returns>
  1097. public virtual System.Object RemoveFirst()
  1098. {
  1099. System.Object objectRemoved = this[0];
  1100. this.RemoveAt(0);
  1101. return objectRemoved;
  1102. }
  1103. /// <summary>
  1104. /// Removes the last value from an array list.
  1105. /// </summary>
  1106. /// <returns>Returns the value removed.</returns>
  1107. public virtual System.Object RemoveLast()
  1108. {
  1109. System.Object objectRemoved = this[this.Count-1];
  1110. base.RemoveAt(this.Count-1);
  1111. return objectRemoved;
  1112. }
  1113. /// <summary>
  1114. /// Removes all the elements that aren't contained into the specified collection.
  1115. /// </summary>
  1116. /// <param name="collection">The collection used to verify the elements that will be retained.</param>
  1117. /// <returns>Returns true if all the elements were successfully removed. Otherwise returns false.</returns>
  1118. public virtual bool RetainAll(System.Collections.ICollection collection)
  1119. {
  1120. bool result = false;
  1121. System.Collections.IEnumerator tempEnumerator = this.GetEnumerator();
  1122. ListCollectionSupport tempCollection = new ListCollectionSupport(collection);
  1123. while (tempEnumerator.MoveNext())
  1124. if (!tempCollection.Contains(tempEnumerator.Current))
  1125. {
  1126. result = this.RemoveElement(tempEnumerator.Current);
  1127. if (result == true)
  1128. {
  1129. tempEnumerator = this.GetEnumerator();
  1130. }
  1131. }
  1132. return result;
  1133. }
  1134. /// <summary>
  1135. /// Removes all the elements that aren't contained into the specified collection.
  1136. /// </summary>
  1137. /// <param name="collection">The collection used to verify the elements that will be retained.</param>
  1138. /// <returns>Returns true if all the elements were successfully removed. Otherwise returns false.</returns>
  1139. public virtual bool RetainAll(CollectionSupport collection)
  1140. {
  1141. return this.RetainAll((System.Collections.ICollection) collection);
  1142. }
  1143. /// <summary>
  1144. /// Verifies if all the elements of the specified collection are contained into the current collection.
  1145. /// </summary>
  1146. /// <param name="collection">The collection used to extract the elements that will be verified.</param>
  1147. /// <returns>Returns true if all the elements are contained in the collection. Otherwise returns false.</returns>
  1148. public virtual bool ContainsAll(System.Collections.ICollection collection)
  1149. {
  1150. bool result = false;
  1151. System.Collections.IEnumerator tempEnumerator = new System.Collections.ArrayList(collection).GetEnumerator();
  1152. while (tempEnumerator.MoveNext())
  1153. if(!(result = this.Contains(tempEnumerator.Current)))
  1154. break;
  1155. return result;
  1156. }
  1157. /// <summary>
  1158. /// Verifies if all the elements of the specified collection are contained into the current collection.
  1159. /// </summary>
  1160. /// <param name="collection">The collection used to extract the elements that will be verified.</param>
  1161. /// <returns>Returns true if all the elements are contained in the collection. Otherwise returns false.</returns>
  1162. public virtual bool ContainsAll(CollectionSupport collection)
  1163. {
  1164. return this.ContainsAll((System.Collections.ICollection) collection);
  1165. }
  1166. /// <summary>
  1167. /// Returns a new list containing a portion of the current list between a specified range.
  1168. /// </summary>
  1169. /// <param name="startIndex">The start index of the range.</param>
  1170. /// <param name="endIndex">The end index of the range.</param>
  1171. /// <returns>A ListCollectionSupport instance containing the specified elements.</returns>
  1172. public virtual ListCollectionSupport SubList(int startIndex, int endIndex)
  1173. {
  1174. int index = 0;
  1175. System.Collections.IEnumerator tempEnumerator = this.GetEnumerator();
  1176. ListCollectionSupport result = new ListCollectionSupport();
  1177. for(index = startIndex; index < endIndex; index++)
  1178. result.Add(this[index]);
  1179. return (ListCollectionSupport)result;
  1180. }
  1181. /// <summary>
  1182. /// Obtains an array containing all the elements of the collection.
  1183. /// </summary>
  1184. /// <param name="objects">The array into which the elements of the collection will be stored.</param>
  1185. /// <returns>The array containing all the elements of the collection.</returns>
  1186. public virtual System.Object[] ToArray(System.Object[] objects)
  1187. {
  1188. if (objects.Length < this.Count)
  1189. objects = new System.Object[this.Count];
  1190. int index = 0;
  1191. System.Collections.IEnumerator tempEnumerator = this.GetEnumerator();
  1192. while (tempEnumerator.MoveNext())
  1193. objects[index++] = tempEnumerator.Current;
  1194. return objects;
  1195. }
  1196. /// <summary>
  1197. /// Returns an iterator of the collection starting at the specified position.
  1198. /// </summary>
  1199. /// <param name="index">The position to set the iterator.</param>
  1200. /// <returns>An IEnumerator at the specified position.</returns>
  1201. public virtual System.Collections.IEnumerator ListIterator(int index)
  1202. {
  1203. if ((index < 0) || (index > this.Count)) throw new System.IndexOutOfRangeException();
  1204. System.Collections.IEnumerator tempEnumerator= this.GetEnumerator();
  1205. if (index > 0)
  1206. {
  1207. int i=0;
  1208. while ((tempEnumerator.MoveNext()) && (i < index - 1))
  1209. i++;
  1210. }
  1211. return tempEnumerator;
  1212. }
  1213. /// <summary>
  1214. /// Gets the last value from a list.
  1215. /// </summary>
  1216. /// <returns>Returns the last element of the list.</returns>
  1217. public virtual System.Object GetLast()
  1218. {
  1219. if (this.Count == 0) throw new System.ArgumentOutOfRangeException();
  1220. else
  1221. {
  1222. return this[this.Count - 1];
  1223. }
  1224. }
  1225. /// <summary>
  1226. /// Return whether this list is empty.
  1227. /// </summary>
  1228. /// <returns>True if the list is empty, false if it isn't.</returns>
  1229. public virtual bool IsEmpty()
  1230. {
  1231. return (this.Count == 0);
  1232. }
  1233. /// <summary>
  1234. /// Replaces the element at the specified position in this list with the specified element.
  1235. /// </summary>
  1236. /// <param name="index">Index of element to replace.</param>
  1237. /// <param name="element">Element to be stored at the specified position.</param>
  1238. /// <returns>The element previously at the specified position.</returns>
  1239. public virtual System.Object Set(int index, System.Object element)
  1240. {
  1241. System.Object result = this[index];
  1242. this[index] = element;
  1243. return result;
  1244. }
  1245. /// <summary>
  1246. /// Returns the element at the specified position in the list.
  1247. /// </summary>
  1248. /// <param name="index">Index of element to return.</param>
  1249. /// <param name="element">Element to be stored at the specified position.</param>
  1250. /// <returns>The element at the specified position in the list.</returns>
  1251. public virtual System.Object Get(int index)
  1252. {
  1253. return this[index];
  1254. }
  1255. }
  1256. /*******************************/
  1257. /// <summary>
  1258. /// This class manages array operations.
  1259. /// </summary>
  1260. public class ArraysSupport
  1261. {
  1262. /// <summary>
  1263. /// Compares the entire members of one array whith the other one.
  1264. /// </summary>
  1265. /// <param name="array1">The array to be compared.</param>
  1266. /// <param name="array2">The array to be compared with.</param>
  1267. /// <returns>True if both arrays are equals otherwise it returns false.</returns>
  1268. /// <remarks>Two arrays are equal if they contains the same elements in the same order.</remarks>
  1269. public static bool IsArrayEqual(System.Array array1, System.Array array2)
  1270. {
  1271. if (array1.Length != array2.Length)
  1272. return false;
  1273. for (int i = 0; i < array1.Length; i++)
  1274. if (!(array1.GetValue(i).Equals(array2.GetValue(i))))
  1275. return false;
  1276. return true;
  1277. }
  1278. /// <summary>
  1279. /// Fills the array with an specific value from an specific index to an specific index.
  1280. /// </summary>
  1281. /// <param name="array">The array to be filled.</param>
  1282. /// <param name="fromindex">The first index to be filled.</param>
  1283. /// <param name="toindex">The last index to be filled.</param>
  1284. /// <param name="val">The value to fill the array with.</param>
  1285. public static void FillArray(System.Array array, System.Int32 fromindex,System.Int32 toindex, System.Object val)
  1286. {
  1287. System.Object Temp_Object = val;
  1288. System.Type elementtype = array.GetType().GetElementType();
  1289. if (elementtype != val.GetType())
  1290. Temp_Object = System.Convert.ChangeType(val, elementtype);
  1291. if (array.Length == 0)
  1292. throw (new System.NullReferenceException());
  1293. if (fromindex > toindex)
  1294. throw (new System.ArgumentException());
  1295. if ((fromindex < 0) || ((System.Array)array).Length < toindex)
  1296. throw (new System.IndexOutOfRangeException());
  1297. for (int index = (fromindex > 0) ? fromindex-- : fromindex; index < toindex; index++)
  1298. array.SetValue(Temp_Object, index);
  1299. }
  1300. /// <summary>
  1301. /// Fills the array with an specific value.
  1302. /// </summary>
  1303. /// <param name="array">The array to be filled.</param>
  1304. /// <param name="val">The value to fill the array with.</param>
  1305. public static void FillArray(System.Array array, System.Object val)
  1306. {
  1307. FillArray(array, 0, array.Length, val);
  1308. }
  1309. }
  1310. /*******************************/
  1311. /// <summary>
  1312. /// This class manages a set of elements.
  1313. /// </summary>
  1314. public class SetSupport : System.Collections.ArrayList
  1315. {
  1316. /// <summary>
  1317. /// Creates a new set.
  1318. /// </summary>
  1319. public SetSupport(): base()
  1320. {

Large files files are truncated, but you can click here to view the full file