示例#1
0
            public override void Dispose()
            {
                if (_enumerator != null)
                {
                    _enumerator.Dispose();
                    _enumerator = null;
                    _set        = null;
                }

                base.Dispose();
            }
            private NewSet <TSource> FillSet()
            {
                NewSet <TSource> set;

                if (_source is ICollection <TSource> src)
                {
                    set = new NewSet <TSource>(_comparer, src.Count);
                }
                else
                {
                    set = new NewSet <TSource>(_comparer);
                }

                set.UnionWith(_source);
                return(set);
            }
示例#3
0
            public override bool MoveNext()
            {
                switch (_state)
                {
                case 1:
                    _enumerator = _source.GetEnumerator();
                    if (!_enumerator.MoveNext())
                    {
                        Dispose();
                        return(false);
                    }

                    TSource element = _enumerator.Current;
                    _set = new NewSet <TSource>(_comparer);
                    _set.Add(element);
                    _current = element;
                    _state   = 2;
                    return(true);

                case 2:
                    Debug.Assert(_enumerator != null);
                    Debug.Assert(_set != null);
                    while (_enumerator.MoveNext())
                    {
                        element = _enumerator.Current;
                        if (_set.Add(element))
                        {
                            _current = element;
                            return(true);
                        }
                    }

                    break;
                }

                Dispose();
                return(false);
            }