/// <summary> /// Cretes a SerializableList of another type and convert all elements in this type. /// </summary> /// <typeparam name="U">Convert into this Type </typeparam> /// <param name="converter">Converter from T to U</param> /// <returns>the converted SerializableList</returns> public SerializableList <U> ConvertAll <U>(Converter <T, U> converter) { SerializableList <U> result = new SerializableList <U>(); foreach (T element in this) { result.Add(converter(element)); } return(result); }
/// <summary> /// Filter the SerializableList, applying the predicate to all elements. /// </summary> /// <param name="predicate"></param> /// <returns>Filtered SerializableList</returns> public SerializableList <T> FindAll(Predicate <T> predicate) { SerializableList <T> result = new SerializableList <T>(); foreach (T element in this) { if (predicate(element)) { result.Add(element); } } return(result); }
/// <summary> /// Performs an "exclusive-or" of the two SerializableLists, keeping only the elements that /// are in one of the SerializableLists, but not in both. The original SerializableLists are not modified /// during this operation. The result SerializableList is a <c>Clone()</c> of this SerializableList containing /// the elements from the exclusive-or operation. /// </summary> /// <param name="a">A SerializableList of elements.</param> /// <returns>A SerializableList containing the result of <c>a ^ b</c>.</returns> public virtual SerializableList <T> ExclusiveOr(SerializableList <T> a) { SerializableList <T> resultSerializableList = (SerializableList <T>) this.Clone(); foreach (T element in a) { if (resultSerializableList.Contains(element)) { resultSerializableList.Remove(element); } else { resultSerializableList.Add(element); } } return(resultSerializableList); }
/// <summary> /// Retains only the elements in this SerializableList that are contained in the specified collection. /// </summary> /// <param name="c">Collection that defines the SerializableList of elements to be retained.</param> /// <returns><c>true</c> if this SerializableList changed as a result of this operation.</returns> public bool RetainAll(SerializableList <T> c) { //Put data from C into a SerializableList so we can use the Contains() method. SerializableList <T> cSerializableList = new SerializableList <T>(c); //We are going to build a SerializableList of elements to remove. SerializableList <T> removeSerializableList = new SerializableList <T>(); foreach (T o in this) { //If C does not contain O, then we need to remove O from our //SerializableList. We can't do this while iterating through our SerializableList, so //we put it into RemoveSerializableList for later. if (!cSerializableList.Contains(o)) { removeSerializableList.Add(o); } } return(this.RemoveAll(removeSerializableList)); }