hytos / ID2.Manager / ID2.Manager.Compare / Classes / LinqExtension.cs @ 416979ec
이력 | 보기 | 이력해설 | 다운로드 (1.21 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
|
7 |
namespace ID2.Manager.Classes |
8 |
{ |
9 |
public static class LinqExtension |
10 |
{ |
11 |
public static void ForAll<T>(this IEnumerable<T> collection, Action<T> action) |
12 |
{ |
13 |
foreach (var item in collection) |
14 |
{ |
15 |
action(item); |
16 |
} |
17 |
} |
18 |
public static void ParallelForAll<T>(this IEnumerable<T> collection, Action<T> action) |
19 |
{ |
20 |
Parallel.ForEach(collection, item => action(item)); |
21 |
} |
22 |
|
23 |
public static T Find<T>(this IEnumerable<T> collection, Predicate<T> selector) |
24 |
{ |
25 |
foreach (var item in collection) |
26 |
{ |
27 |
var value = selector(item); |
28 |
|
29 |
if (value) |
30 |
return item; |
31 |
} |
32 |
|
33 |
return default(T); |
34 |
} |
35 |
|
36 |
static public bool ContainsAll<T>(this IEnumerable<T> owner, IEnumerable<T> contain) |
37 |
{ |
38 |
foreach (var item in owner) |
39 |
{ |
40 |
if (!contain.Contains(item)) |
41 |
{ |
42 |
return false; |
43 |
} |
44 |
} |
45 |
|
46 |
return true; |
47 |
} |
48 |
} |
49 |
} |