markus / KCOM / Extensions / LinqExtension.cs @ eeb0a39c
이력 | 보기 | 이력해설 | 다운로드 (760 Bytes)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
|
7 |
namespace KCOM |
8 |
{ |
9 |
public static class Extensions |
10 |
{ |
11 |
public static IEnumerable<TSource> WhereIf<TSource>(this IEnumerable<TSource> source, bool condition, Func<TSource, bool> predicate) |
12 |
{ |
13 |
if (condition) |
14 |
return source.Where(predicate); |
15 |
else |
16 |
return source; |
17 |
} |
18 |
|
19 |
public static IEnumerable<TSource> WhereIf<TSource>(this IEnumerable<TSource> source, bool condition, Func<TSource, int, bool> predicate) |
20 |
{ |
21 |
if (condition) |
22 |
return source.Where(predicate); |
23 |
else |
24 |
return source; |
25 |
} |
26 |
} |
27 |
} |