using System.Collections; namespace Core.GIS.NetTopologySuite.Utilities { /// /// Executes a transformation function on each element of a collection /// and returns the results in a new List. /// public class CollectionUtil { /// /// /// /// /// /// public delegate T FunctionDelegate(T obj); /// /// Executes a function on each item in a /// and returns the results in a new . /// /// /// /// public static IList Transform(ICollection coll, FunctionDelegate func) { IList result = new ArrayList(); IEnumerator i = coll.GetEnumerator(); foreach (object obj in coll) { result.Add(func(obj)); } return result; } /// /// Executes a function on each item in a /// but does not accumulate the result. /// /// /// public static void Apply(ICollection coll, FunctionDelegate func) { foreach (object obj in coll) { func(obj); } } /// /// Executes a function on each item in a /// and collects all the entries for which the result /// of the function is equal to true. /// /// /// /// public static IList Select(ICollection coll, FunctionDelegate func) { IList result = new ArrayList(); foreach (object obj in coll) { if (true.Equals(func(obj))) { result.Add(obj); } } return result; } } }