/// <summary> /// Finds all distinct elements for the specified column /// </summary> /// <param name="columnName">Name of the column.</param> /// <returns></returns> public virtual TList <T> FindAllDistinct(string columnName) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T)); PropertyDescriptor filterBy = props.Find(columnName, true); TList <T> result = new TList <T>(); object a; object b; bool found; foreach (T item in this) { a = filterBy.GetValue(item); found = false; foreach (T item2 in result) { b = filterBy.GetValue(item2); if ((a == null && b == null) || (a != null && b != null && a.Equals(b))) { found = true; break; } } if (!found) { result.Add(item); } } return(result); }
///<summary> /// Creates an exact copy of this TList{T} object. ///</summary> ///<returns>A new, identical copy of the TList{T}.</returns> public virtual TList <T> Copy(IDictionary existingCopies) { if (existingCopies == null) { existingCopies = new Hashtable(); } TList <T> copy = new TList <T>(); foreach (T item in this) { T itemCopy = default(T); if (existingCopies.Contains(item)) { itemCopy = (T)existingCopies[item]; } else { itemCopy = (T)MakeCopyOf(item, existingCopies); } copy.Add(itemCopy); } foreach (T item in this.DeletedItems) { copy.DeletedItems.Add(item); } return(copy); }
/// <summary> /// Gets the range /// </summary> /// <param name="index">The index.</param> /// <param name="count">The count.</param> /// <returns></returns> public TList <T> GetRange(int index, int count) { if ((index < 0) || (count < 0)) { throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", "ArgumentOutOfRange_NeedNonNegNum"); } TList <T> list1 = new TList <T>(); for (int i = index; i < index + count && i < this.Count; i++) { list1.Add(this.Items[i]); } return(list1); }
/// <summary> /// Retrieves the all the elements that match the conditions defined by the specified predicate. /// </summary> /// <param name="match">The <see cref="T:System.Predicate`1"></see> delegate that defines the conditions of the elements to search for.</param> /// <returns> /// A <see cref="T:TList{T}"></see> containing all the elements that match the conditions defined by the specified predicate, if found; otherwise, an empty <see cref="T:TList{T}"></see>. /// </returns> /// <exception cref="T:System.ArgumentNullException">match is null.</exception> public new TList <T> FindAll(Predicate <T> match) { if (match == null) { throw new ArgumentNullException("match"); } TList <T> result = new TList <T>(); foreach (T item in this.Items) { if (match(item)) { result.Add(item); } } return(result); }
/// <summary> /// Adds the data in this collection to another collection /// </summary> /// <param name="copyTo"></param> public virtual void CopyTo(TList <T> copyTo) { // make sure not to duplicate the item if it's already there ArrayList alreadySeenItem = new ArrayList(); foreach (T item in copyTo) { alreadySeenItem.Add(item.ToString()); } foreach (T item in this) { T itemCopy = (T)MakeCopyOf(item); if (alreadySeenItem.IndexOf(itemCopy.ToString()) < 0) { copyTo.Add(itemCopy); } } }
///<summary> /// Finds a collection of <see cref="IEntity" /> objects in the current list matching the search criteria. ///</summary> /// <param name="findAllByType"><see cref="FindAllByType" /> Type to easily search by</param> /// <param name="propertyName">Property of the object to search.</param> /// <param name="value">Value to find.</param> /// <param name="ignoreCase">A Boolean indicating a case-sensitive or insensitive comparison (true indicates a case-insensitive comparison). String properties only.</param> public virtual TList <T> FindAllBy(FindAllByType findAllByType, string propertyName, object value, bool ignoreCase) { PropertyDescriptorCollection props = base.PropertyCollection; PropertyDescriptor searchBy = props.Find(propertyName, true); TList <T> result = new TList <T>(); int index = 0; while (index > -1) { index = this.FindAllBy(findAllByType, searchBy, value, index, ignoreCase); if (index > -1) { result.Add(this[index]); //Increment the index to start at the next item index++; } } return(result); }