using System; using System.IO; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using FastReport.Utils; namespace FastReport.Format { /// /// Represents a collection of formats used by the and /// objects. /// public class FormatCollection : CollectionBase, IFRSerializable { /// /// Gets or sets the element at the specified index. /// /// Index of an element. /// The element at the specified index. public FormatBase this[int index] { get { return List[index] as FormatBase; } set { List[index] = value; } } /// /// Adds the specified elements to the end of this collection. /// /// Array of elements to add. public void AddRange(FormatBase[] range) { foreach (FormatBase t in range) { Add(t); } } /// /// Adds an object to the end of this collection. /// /// Object to add. /// Index of the added object. public int Add(FormatBase value) { if (value == null) return -1; return List.Add(value); } /// /// Inserts an object into this collection at the specified index. /// /// The zero-based index at which value should be inserted. /// The object to insert. public void Insert(int index, FormatBase value) { if (value != null) List.Insert(index, value); } /// /// Removes the specified object from the collection. /// /// Object to remove. public void Remove(FormatBase value) { if (Contains(value)) List.Remove(value); } /// /// Returns the zero-based index of the first occurrence of an object. /// /// The object to locate in the collection. /// The zero-based index of the first occurrence of value within the entire collection, if found; /// otherwise, -1. public int IndexOf(FormatBase value) { return List.IndexOf(value); } /// /// Determines whether an element is in the collection. /// /// The object to locate in the collection. /// true if object is found in the collection; otherwise, false. public bool Contains(FormatBase value) { return List.Contains(value); } /// public void Serialize(FRWriter writer) { writer.ItemName = "Formats"; foreach (FormatBase c in this) { writer.Write(c); } } /// public void Deserialize(FRReader reader) { Clear(); while (reader.NextItem()) { FormatBase format = reader.Read() as FormatBase; Add(format); } } /// /// Copies formats from another collection. /// /// Collection to copy from. public void Assign(FormatCollection collection) { Clear(); foreach (FormatBase format in collection) { Add(format.Clone()); } } /// public override bool Equals(object obj) { FormatCollection collection = obj as FormatCollection; if (collection == null || Count != collection.Count) return false; for (int i = 0; i < Count; i++) { if (!this[i].Equals(collection[i])) return false; } return true; } /// public override int GetHashCode() { return base.GetHashCode(); } } }