using FastReport.Utils; using System.Collections; 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 their 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) { string xValue = (x as DataSourceBase).Alias; string yValue = (y as DataSourceBase).Alias; return xValue.CompareTo(yValue); } } }