public async Task <bool> MoveNext(CancellationToken cancellationToken)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    if (_sourceEnumerator == null)
                    {
                        _sourceEnumerator = _groupJoinAsyncEnumerable._source.GetEnumerator();
                        _hasNext          = await _sourceEnumerator.MoveNext(cancellationToken);

                        _nextOuter = default;
                    }

                    if (_hasNext)
                    {
                        var outer
#pragma warning disable IDE0034 // Simplify 'default' expression - Equals(object, object) causes default(object)
                            = Equals(_nextOuter, default(TOuter))
#pragma warning restore IDE0034 // Simplify 'default' expression
                                ? _groupJoinAsyncEnumerable._outerShaper
                              .Shape(_groupJoinAsyncEnumerable._queryContext, _sourceEnumerator.Current)
                                : _nextOuter;

                        _nextOuter = default;

                        var inner
                            = _groupJoinAsyncEnumerable._innerShaper
                              .Shape(_groupJoinAsyncEnumerable._queryContext, _sourceEnumerator.Current);

                        var inners = new List <TInner>();

                        if (inner == null)
                        {
                            Current
                                = _groupJoinAsyncEnumerable._resultSelector(
                                      outer, inners.ToAsyncEnumerable());

                            _hasNext = await _sourceEnumerator.MoveNext(cancellationToken);

                            return(true);
                        }

                        var currentGroupKey = _groupJoinAsyncEnumerable._innerKeySelector(inner);

                        inners.Add(inner);

                        while (true)
                        {
                            _hasNext = await _sourceEnumerator.MoveNext(cancellationToken);

                            if (!_hasNext)
                            {
                                break;
                            }

                            if (_groupJoinAsyncEnumerable._hasOuters)
                            {
                                _nextOuter
                                    = _groupJoinAsyncEnumerable._outerShaper
                                      .Shape(_groupJoinAsyncEnumerable._queryContext, _sourceEnumerator.Current);

                                if (!Equals(outer, _nextOuter))
                                {
                                    break;
                                }

                                _nextOuter = default;
                            }

                            inner
                                = _groupJoinAsyncEnumerable._innerShaper
                                  .Shape(_groupJoinAsyncEnumerable._queryContext, _sourceEnumerator.Current);

                            if (inner == null)
                            {
                                break;
                            }

                            var innerKey = _groupJoinAsyncEnumerable._innerKeySelector(inner);

                            if (!_comparer.Equals(currentGroupKey, innerKey))
                            {
                                break;
                            }

                            inners.Add(inner);
                        }

                        Current
                            = _groupJoinAsyncEnumerable._resultSelector(
                                  outer, inners.ToAsyncEnumerable());

                        return(true);
                    }

                    return(false);
                }
Пример #2
0
                public async Task <bool> MoveNext(CancellationToken cancellationToken)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    if (_sourceEnumerator == null)
                    {
                        _outerGroupJoinIncludeContext = _groupJoinAsyncEnumerable._outerGroupJoinInclude?.Initialize(_groupJoinAsyncEnumerable._queryContext);
                        _innerGroupJoinIncludeContext = _groupJoinAsyncEnumerable._innerGroupJoinInclude?.Initialize(_groupJoinAsyncEnumerable._queryContext);
                        _outerEntityAccessor          = _groupJoinAsyncEnumerable._outerGroupJoinInclude?.EntityAccessor as Func <TOuter, object>;
                        _innerEntityAccessor          = _groupJoinAsyncEnumerable._innerGroupJoinInclude?.EntityAccessor as Func <TInner, object>;
                        _sourceEnumerator             = _groupJoinAsyncEnumerable._source.GetEnumerator();
                        _hasNext = await _sourceEnumerator.MoveNext(cancellationToken);

                        _nextOuter = default(TOuter);
                    }

                    if (_hasNext)
                    {
                        var outer
                            = Equals(_nextOuter, default(TOuter))
                                ? _groupJoinAsyncEnumerable._outerShaper
                              .Shape(_groupJoinAsyncEnumerable._queryContext, _sourceEnumerator.Current)
                                : _nextOuter;

                        _nextOuter = default(TOuter);

                        if (_outerGroupJoinIncludeContext != null)
                        {
                            if (_outerEntityAccessor != null)
                            {
                                await _outerGroupJoinIncludeContext.IncludeAsync(_outerEntityAccessor(outer), cancellationToken);
                            }
                            else
                            {
                                await _outerGroupJoinIncludeContext.IncludeAsync(outer, cancellationToken);
                            }
                        }

                        var inner
                            = _groupJoinAsyncEnumerable._innerShaper
                              .Shape(_groupJoinAsyncEnumerable._queryContext, _sourceEnumerator.Current);

                        var inners = new List <TInner>();

                        if (inner == null)
                        {
                            Current
                                = _groupJoinAsyncEnumerable._resultSelector(
                                      outer, AsyncLinqOperatorProvider.ToAsyncEnumerable(inners));

                            _hasNext = await _sourceEnumerator.MoveNext(cancellationToken);

                            return(true);
                        }

                        var currentGroupKey = _groupJoinAsyncEnumerable._innerKeySelector(inner);

                        if (_innerGroupJoinIncludeContext != null)
                        {
                            if (_innerEntityAccessor != null)
                            {
                                await _innerGroupJoinIncludeContext.IncludeAsync(_innerEntityAccessor(inner), cancellationToken);
                            }
                            else
                            {
                                await _innerGroupJoinIncludeContext.IncludeAsync(inner, cancellationToken);
                            }
                        }

                        inners.Add(inner);

                        while (true)
                        {
                            _hasNext = await _sourceEnumerator.MoveNext(cancellationToken);

                            if (!_hasNext)
                            {
                                break;
                            }

                            if (_groupJoinAsyncEnumerable._hasOuters)
                            {
                                _nextOuter
                                    = _groupJoinAsyncEnumerable._outerShaper
                                      .Shape(_groupJoinAsyncEnumerable._queryContext, _sourceEnumerator.Current);

                                if (!Equals(outer, _nextOuter))
                                {
                                    break;
                                }

                                _nextOuter = default(TOuter);
                            }

                            inner
                                = _groupJoinAsyncEnumerable._innerShaper
                                  .Shape(_groupJoinAsyncEnumerable._queryContext, _sourceEnumerator.Current);

                            if (inner == null)
                            {
                                break;
                            }

                            var innerKey = _groupJoinAsyncEnumerable._innerKeySelector(inner);

                            if (!_comparer.Equals(currentGroupKey, innerKey))
                            {
                                break;
                            }

                            if (_innerGroupJoinIncludeContext != null)
                            {
                                await _innerGroupJoinIncludeContext.IncludeAsync(inner, cancellationToken);
                            }

                            inners.Add(inner);
                        }

                        Current
                            = _groupJoinAsyncEnumerable._resultSelector(
                                  outer, AsyncLinqOperatorProvider.ToAsyncEnumerable(inners));

                        return(true);
                    }

                    return(false);
                }
                public async Task <bool> MoveNext(CancellationToken cancellationToken)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    if (_sourceEnumerator == null)
                    {
                        _groupJoinAsyncEnumerable._outerGroupJoinInclude?.Initialize(_groupJoinAsyncEnumerable._queryContext);
                        _groupJoinAsyncEnumerable._innerGroupJoinInclude?.Initialize(_groupJoinAsyncEnumerable._queryContext);
                        _sourceEnumerator = _groupJoinAsyncEnumerable._source.GetEnumerator();
                        _hasNext          = await _sourceEnumerator.MoveNext();
                    }

                    if (_hasNext)
                    {
                        var outer
                            = _groupJoinAsyncEnumerable._outerShaper
                              .Shape(_groupJoinAsyncEnumerable._queryContext, _sourceEnumerator.Current);

                        if (_groupJoinAsyncEnumerable._outerGroupJoinInclude != null)
                        {
                            await _groupJoinAsyncEnumerable._outerGroupJoinInclude.IncludeAsync(outer, cancellationToken);
                        }

                        var inner
                            = _groupJoinAsyncEnumerable._innerShaper
                              .Shape(_groupJoinAsyncEnumerable._queryContext, _sourceEnumerator.Current);

                        var inners = new List <TInner>();

                        if (inner == null)
                        {
                            Current
                                = _groupJoinAsyncEnumerable._resultSelector(
                                      outer, AsyncLinqOperatorProvider.ToAsyncEnumerable(inners));

                            _hasNext = await _sourceEnumerator.MoveNext();

                            return(true);
                        }

                        var currentGroupKey = _groupJoinAsyncEnumerable._innerKeySelector(inner);

                        if (_groupJoinAsyncEnumerable._innerGroupJoinInclude != null)
                        {
                            await _groupJoinAsyncEnumerable._innerGroupJoinInclude.IncludeAsync(inner, cancellationToken);
                        }

                        inners.Add(inner);

                        while (true)
                        {
                            _hasNext = await _sourceEnumerator.MoveNext();

                            if (!_hasNext)
                            {
                                break;
                            }

                            inner
                                = _groupJoinAsyncEnumerable._innerShaper
                                  .Shape(_groupJoinAsyncEnumerable._queryContext, _sourceEnumerator.Current);

                            if (inner == null)
                            {
                                break;
                            }

                            var innerKey = _groupJoinAsyncEnumerable._innerKeySelector(inner);

                            if (!_comparer.Equals(currentGroupKey, innerKey))
                            {
                                break;
                            }

                            if (_groupJoinAsyncEnumerable._innerGroupJoinInclude != null)
                            {
                                await _groupJoinAsyncEnumerable._innerGroupJoinInclude.IncludeAsync(inner, cancellationToken);
                            }

                            inners.Add(inner);
                        }

                        Current
                            = _groupJoinAsyncEnumerable._resultSelector(
                                  outer, AsyncLinqOperatorProvider.ToAsyncEnumerable(inners));

                        return(true);
                    }

                    return(false);
                }