ConditionCollection.cs 4.6 KB

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