Пример #1
0
        public static JoinedEnumerable <TElement> Wrap <TElement>(IEnumerable <TElement> source, bool isOuter)
        {
            JoinedEnumerable <TElement> joinedSource
                = source as JoinedEnumerable <TElement> ??
                  new JoinedEnumerable <TElement>(source);

            joinedSource.IsOuter = isOuter;
            return(joinedSource);
        }
Пример #2
0
        public static IEnumerable <TResult> Join <TOuter, TInner, TKey, TResult>(this JoinedEnumerable <TOuter> outer, IEnumerable <TInner> inner, Func <TOuter, TKey> outerKeySelector, Func <TInner, TKey> innerKeySelector, Func <TOuter, TInner, TResult> resultSelector, IEqualityComparer <TKey> comparer = null)
        {
            if (outer == null)
            {
                throw new ArgumentNullException("outer");
            }
            if (inner == null)
            {
                throw new ArgumentNullException("inner");
            }
            if (outerKeySelector == null)
            {
                throw new ArgumentNullException("outerKeySelector");
            }
            if (innerKeySelector == null)
            {
                throw new ArgumentNullException("innerKeySelector");
            }
            if (resultSelector == null)
            {
                throw new ArgumentNullException("resultSelector");
            }

            bool leftOuter  = outer.IsOuter;
            bool rightOuter = (inner is JoinedEnumerable <TInner>) && ((JoinedEnumerable <TInner>)inner).IsOuter;

            if (leftOuter && rightOuter)
            {
                return(FullOuterJoin(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer));
            }

            if (leftOuter)
            {
                return(LeftOuterJoin(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer));
            }

            if (rightOuter)
            {
                return(RightOuterJoin(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer));
            }

            return(Enumerable.Join(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer));
        }