Esempio n. 1
0
            public override bool MoveNext()
            {
                switch (_state)
                {
                case 1:
                    _node  = _prepended;
                    _state = 2;
                    goto case 2;

                case 2:
                    if (_node != null)
                    {
                        _current = _node.Item;
                        _node    = _node.Linked;
                        return(true);
                    }

                    GetSourceEnumerator();
                    _state = 3;
                    goto case 3;

                case 3:
                    if (LoadFromEnumerator())
                    {
                        return(true);
                    }

                    if (_appended == null)
                    {
                        return(false);
                    }

                    _enumerator = ((IEnumerable <TSource>)_appended.ToArray(_appendCount)).GetEnumerator();
                    _state      = 4;
                    goto case 4;

                case 4:
                    return(LoadFromEnumerator());
                }

                Dispose();
                return(false);
            }
Esempio n. 2
0
            private TSource[] LazyToArray()
            {
                Debug.Assert(GetCount(onlyIfCheap: true) == -1);

                var builder = new LargeArrayBuilder <TSource>(initialize: true);

                for (SingleLinkedNode <TSource> node = _prepended; node != null; node = node.Linked)
                {
                    builder.Add(node.Item);
                }

                builder.AddRange(_source);

                if (_appended != null)
                {
                    foreach (TSource item in _appended.ToArray())
                    {
                        builder.Add(item);
                    }
                }

                return(builder.ToArray());
            }