Add WhereIf to IEnumerable : IEnumerable « Collections Data Structure « C# / C Sharp






Add WhereIf to IEnumerable

    
//The MIT License (MIT)
//http://arolibraries.codeplex.com/license

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;

namespace AroLibraries.ExtensionMethods.Enumerable
{
    public static class IEnumerableExt
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="source"></param>
        /// <param name="condition"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static IEnumerable<TSource> Ext_WhereIf<TSource>(this IEnumerable<TSource> source, bool condition, Func<TSource, bool> predicate)
        {
            if (condition)
                return source.Where(predicate);
            else
                return source;
        }
        public static IEnumerable<TSource> Ext_WhereIf<TSource>(this IEnumerable<TSource> source, bool condition, Func<TSource, int, bool> predicate)
        {
            if (condition)
                return source.Where(predicate);
            else
                return source;
        }
   }
}

   
    
    
    
  








Related examples in the same category

1.Determines whether the specified collection is null or empty.
2.Determines whether the collection contains the specified element
3.Determines whether the collection contains all the elements in the specified collection.
4.Aggregate IEnumerable
5.Convert IEnumerable To DataTable
6.Convert IEnumerable by Func
7.Split IEnumerable
8.Shuffle IEnumerable
9.For each IEnumerable
10.Sleep before yield each element in IEnumerable
11.Add OrderBy to IEnumerable
12.Add Repeat extension to IEnumerable
13.Yield element in IEnumerable until Predicate
14.IEnumerable extension for get second and third element
15.Simple function to determine if an item is an IEnumerable
16.Object class extension for IEnumerable, IComparable and where
17.Output DataTable and IEnumerable to console
18.Convert IEnumerable to String
19.Convert XmlNodeList to IEnumerable
20.Returns the first element contained in both, source and candidates.
21.Given a range (start,end) and a number of steps, will yield that a number for each step
22.Compares two sequences.
23.Empty Enumerable/Enumerator
24.CharEnumerator supports iterating over a String and reading its individual characters.
25.IEnumerable interface exposes the enumerator, which supports a simple iteration over a non-generic collection.
26.IEnumerator interface supports a simple iteration over a nongeneric collection.
27.Convert IEnumerable to ObservableCollection
28.IEnumerable To Comma String
29.Do all for IEnumerable and Action
30.Convert IEnumerable to IEnumerable
31.Filter IEnumerable with Predicate
32.Join IEnumerable
33.Mode value for IEnumerable
34.Build Statistics function on to IEnumerable
35.Compare two IEnumerable
36.Convert IEnumerable to HashSet
37.Concatenate IEnumerable to String
38.Singleton IEnumerable
39.Convert IEnumerable To ReadOnlyCollection
40.Performs the specified action on each element of the IEnumerable
41.Creates a list by applying a delegate to pairs of items in the IEnumerable
42.Returns true if there are enough items in the IEnumerable
43.Returns true if there are no more than a set number of items in the IEnumerable
44.Groups items into same size lots.