Mega Code Archive

 
Categories / C# / Collections Data Structure
 

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;         }    } }