2 using System
.Collections
.Generic
;
4 namespace IEnumerableExtras
7 /// Compare <see cref="IEnumerable{T}"/> extension.
9 public static class EnumerableCompare
12 /// Compare this instance of <see cref="IEnumerable{TValue}"/> with another instance
13 /// if same type using equivalence function and produce a list of items present
14 /// in both collections and a list of items missing from second collection.
16 /// <typeparam name="TValue"></typeparam>
17 /// <param name="a"></param>
18 /// <param name="b"></param>
19 /// <param name="missingFromOther"></param>
20 /// <param name="equivFunc"></param>
21 /// <returns></returns>
22 public static IEnumerable
<Pair
<TValue
>> Compare
< TValue
>( this IEnumerable
<TValue
> a
,
23 IEnumerable
<TValue
> b
,
24 out IEnumerable
<TValue
> missingFromOther
,
25 Func
<TValue
, TValue
, bool> equivFunc
)
27 List
<Pair
<TValue
>> common
= new List
<Pair
<TValue
>>();
28 List
<TValue
> missing
= new List
<TValue
>();
30 foreach ( TValue fromA
in a
)
34 foreach ( TValue fromB
in b
)
36 if ( equivFunc( fromA
, fromB
) )
38 common
.Add( new Pair
<TValue
>( fromA
, fromB
) );
50 missingFromOther
= missing
;