using System; using System.Collections.Generic; using System.Text; using System.Collections; using FastReport.Utils; namespace FastReport.Data { /// /// Represents the collection of objects. /// public class DataSourceCollection : FRCollectionBase { /// /// Gets or sets a data source. /// /// The index of a data source in this collection. /// The data source with specified index. public DataSourceBase this[int index] { get { return List[index] as DataSourceBase; } set { List[index] = value; } } /// /// Finds a datasource by its name. /// /// The name of a datasource. /// The object if found; otherwise null. public DataSourceBase FindByName(string name) { foreach (DataSourceBase c in this) { if (c.Name == name) return c; } return null; } /// /// Finds a datasource by its alias. /// /// The alias of a datasource. /// The object if found; otherwise null. public DataSourceBase FindByAlias(string alias) { foreach (DataSourceBase c in this) { if (c.Alias == alias) return c; } return null; } /// /// Sorts data sources by theirs names. /// public void Sort() { InnerList.Sort(new DataSourceComparer()); } /// /// Initializes a new instance of the class with default settings. /// /// The owner of this collection. public DataSourceCollection(Base owner) : base(owner) { } } /// /// Represents the comparer class that used for sorting the collection of data sources. /// public class DataSourceComparer : IComparer { /// public int Compare(object x, object y) { object xValue = x.GetType().GetProperty("Name").GetValue(x, null); object yValue = y.GetType().GetProperty("Name").GetValue(y, null); IComparable comp = xValue as IComparable; return comp.CompareTo(yValue); } } }