コード例 #1
0
        public static IEnumerable <TResult> GroupJoin <TKey, TSource, TInner, TResult>(this IndexDefinition <TSource> source,
                                                                                       IEnumerable <TInner> inner, Func <TInner, TKey> innerKeySelector,
                                                                                       Expression <Func <TSource, TKey> > outerKeySelector,
                                                                                       Func <TSource, IEnumerable <TInner>, TResult> resultSelector,
                                                                                       IEqualityComparer <TKey> equalityComparer)
        {
            Dictionary <TKey, Tuple <TSource, List <TInner> > > dictionary = new Dictionary <TKey, Tuple <TSource, List <TInner> > >();

            foreach (TInner innerItem in inner)
            {
                TKey key   = innerKeySelector(innerItem);
                var  value = IndexFinder.FindInIndex(source, outerKeySelector, key, equalityComparer);
                if (value != null)
                {
                    if (dictionary.ContainsKey(key))
                    {
                        Tuple <TSource, List <TInner> > tuple = dictionary[key];
                        tuple.Item2.Add(innerItem);
                    }
                    else
                    {
                        List <TInner> list = new List <TInner>();
                        list.Add(innerItem);
                        dictionary.Add(key, new Tuple <TSource, List <TInner> >(value, list));
                    }
                }
            }
            foreach (KeyValuePair <TKey, Tuple <TSource, List <TInner> > > key in dictionary)
            {
                yield return(resultSelector(key.Value.Item1, key.Value.Item2));
            }
        }
コード例 #2
0
 public static IEnumerable <TResult> Join <TKey, TSource, TInner, TResult>(this IndexDefinition <TSource> source,
                                                                           IEnumerable <TInner> inner, Func <TInner, TKey> innerKeySelector,
                                                                           Expression <Func <TSource, TKey> > outerKeySelector,
                                                                           Func <TSource, TInner, TResult> resultSelector)
 {
     foreach (TInner innerItem in inner)
     {
         TKey key   = innerKeySelector(innerItem);
         var  value = IndexFinder.FindInIndex(source, outerKeySelector, key, null);
         if (value != null)
         {
             yield return(resultSelector(value, innerItem));
         }
     }
 }