SortCollection.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Collections;
  5. using System.IO;
  6. using FastReport.Utils;
  7. namespace FastReport
  8. {
  9. /// <summary>
  10. /// Represents a collection of sort conditions used in the <see cref="DataBand.Sort"/>.
  11. /// </summary>
  12. public class SortCollection : CollectionBase, IFRSerializable
  13. {
  14. /// <summary>
  15. /// Gets or sets the element at the specified index.
  16. /// </summary>
  17. /// <param name="index">Index of an element.</param>
  18. /// <returns>The element at the specified index.</returns>
  19. public Sort this[int index]
  20. {
  21. get { return List[index] as Sort; }
  22. set { List[index] = value; }
  23. }
  24. /// <summary>
  25. /// Adds the specified elements to the end of this collection.
  26. /// </summary>
  27. /// <param name="range"></param>
  28. public void AddRange(Sort[] range)
  29. {
  30. foreach (Sort s in range)
  31. {
  32. Add(s);
  33. }
  34. }
  35. /// <summary>
  36. /// Adds an object to the end of this collection.
  37. /// </summary>
  38. /// <param name="value">Object to add.</param>
  39. /// <returns>Index of the added object.</returns>
  40. public int Add(Sort value)
  41. {
  42. return List.Add(value);
  43. }
  44. /// <summary>
  45. /// Inserts an object into this collection at the specified index.
  46. /// </summary>
  47. /// <param name="index">The zero-based index at which value should be inserted.</param>
  48. /// <param name="value">The object to insert.</param>
  49. public void Insert(int index, Sort value)
  50. {
  51. List.Insert(index, value);
  52. }
  53. /// <summary>
  54. /// Removes the specified object from the collection.
  55. /// </summary>
  56. /// <param name="value">Object to remove.</param>
  57. public void Remove(Sort value)
  58. {
  59. int i = IndexOf(value);
  60. if (i != -1)
  61. List.RemoveAt(i);
  62. }
  63. /// <summary>
  64. /// Returns the zero-based index of the first occurrence of an object.
  65. /// </summary>
  66. /// <param name="value">The object to locate in the collection.</param>
  67. /// <returns>The zero-based index of the first occurrence of value within the entire collection, if found;
  68. /// otherwise, -1.</returns>
  69. public int IndexOf(Sort value)
  70. {
  71. return List.IndexOf(value);
  72. }
  73. /// <summary>
  74. /// Determines whether an element is in the collection.
  75. /// </summary>
  76. /// <param name="value">The object to locate in the collection.</param>
  77. /// <returns><b>true</b> if object is found in the collection; otherwise, <b>false</b>.</returns>
  78. public bool Contains(Sort value)
  79. {
  80. return IndexOf(value) != -1;
  81. }
  82. /// <inheritdoc/>
  83. public void Serialize(FRWriter writer)
  84. {
  85. writer.ItemName = "Sort";
  86. foreach (Sort s in this)
  87. {
  88. writer.Write(s);
  89. }
  90. }
  91. /// <inheritdoc/>
  92. public void Deserialize(FRReader reader)
  93. {
  94. Clear();
  95. while (reader.NextItem())
  96. {
  97. Sort s = new Sort();
  98. reader.Read(s);
  99. Add(s);
  100. }
  101. }
  102. /// <summary>
  103. /// Assigns values from another collection.
  104. /// </summary>
  105. /// <param name="source">Collection to assign from.</param>
  106. public void Assign(SortCollection source)
  107. {
  108. Clear();
  109. foreach (Sort sort in source)
  110. {
  111. Add(sort);
  112. }
  113. }
  114. }
  115. }