Esempio n. 1
0
        public static IList <TObject> CopySpecificationToList <TObject>(IEnumerable <TObject> source, Predicate <TObject> predicate)
        {
            IList <TObject> copy = new List <TObject>();

            CollectionHelper.ActionOnSpecification <TObject>(source, delegate(TObject t) { copy.Add(t); }, predicate);
            return(copy);
        }
        /// <summary>
        /// Find 从集合中选取符合条件的元素
        /// </summary>
        public static IList <TObject> Find <TObject>(IEnumerable <TObject> source, Predicate <TObject> predicate)
        {
            IList <TObject> list = new List <TObject>();

            CollectionHelper.ActionOnSpecification(source, delegate(TObject ele) { list.Add(ele); }, predicate);
            return(list);
        }
Esempio n. 3
0
        /// <summary>
        /// ConvertSpecification 将source中的符合predicate条件元素转换为TResult类型
        /// </summary>
        public static IList <TResult> ConvertSpecification <TObject, TResult>(IEnumerable <TObject> source, Func <TObject, TResult> converter, Predicate <TObject> predicate)
        {
            IList <TResult> list = new List <TResult>();

            CollectionHelper.ActionOnSpecification <TObject>(source, delegate(TObject ele) { list.Add(converter(ele)); }, predicate);
            return(list);
        }
 /// <summary>
 /// ActionOnEach  对集合中的每个元素执行action。
 /// </summary>
 public static void ActionOnEach <TObject>(IEnumerable <TObject> collection, Action <TObject> action)
 {
     CollectionHelper.ActionOnSpecification <TObject>(collection, action, null);
 }