Ejemplo n.º 1
0
        public void GetEnumerator_EnumerationsAreSnapshots()
        {
            IProducerConsumerCollection <int> c = CreateProducerConsumerCollection();

            Assert.Empty(c);

            using (IEnumerator <int> e1 = c.GetEnumerator())
            {
                Assert.True(c.TryAdd(1));
                using (IEnumerator <int> e2 = c.GetEnumerator())
                {
                    Assert.True(c.TryAdd(2));
                    using (IEnumerator <int> e3 = c.GetEnumerator())
                    {
                        int item;
                        Assert.True(c.TryTake(out item));
                        using (IEnumerator <int> e4 = c.GetEnumerator())
                        {
                            Assert.False(e1.MoveNext());

                            Assert.True(e2.MoveNext());
                            Assert.False(e2.MoveNext());

                            Assert.True(e3.MoveNext());
                            Assert.True(e3.MoveNext());
                            Assert.False(e3.MoveNext());

                            Assert.True(e4.MoveNext());
                            Assert.False(e4.MoveNext());
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public async Task GetEnumerator_Generic_ExpectedElementsYielded(int numItems, bool consumeFromSameThread)
        {
            IProducerConsumerCollection <int> c = CreateProducerConsumerCollection();

            using (var e = c.GetEnumerator())
            {
                Assert.False(e.MoveNext());
            }

            // Add, and validate enumeration after each item added
            for (int i = 1; i <= numItems; i++)
            {
                Assert.True(c.TryAdd(i));
                Assert.Equal(i, c.Count);
                Assert.Equal(i, c.Distinct().Count());
            }

            // Take, and validate enumerate after each item removed.
            Action consume = () =>
            {
                for (int i = 1; i <= numItems; i++)
                {
                    int item;
                    Assert.True(c.TryTake(out item));
                    Assert.Equal(numItems - i, c.Count);
                    Assert.Equal(numItems - i, c.Distinct().Count());
                }
            };

            if (consumeFromSameThread)
            {
                consume();
            }
            else
            {
                await ThreadFactory.StartNew(consume);
            }
        }
Ejemplo n.º 3
0
 public IEnumerator <T> GetEnumerator()
 {
     return(_collection.GetEnumerator());
 }
 public IEnumerator <T> GetEnumerator()
 {
     return(_itemQueue.GetEnumerator());
 }
 /// <summary>Gets an enumerator for the collection.</summary>
 /// <returns>An enumerator.</returns>
 public IEnumerator <T> GetEnumerator()
 {
     return(_contained.GetEnumerator());
 }
 /// <summary>Provides an <see cref="T:System.Collections.Generics.IEnumerator{T}"/> for items in the collection.</summary>
 /// <returns>An <see cref="T:System.Collections.Generics.IEnumerator{T}"/> for the items in the collection.</returns>
 /// <exception cref="T:System.ObjectDisposedException">The <see
 /// cref="T:System.Collections.Concurrent.BlockingCollection{T}"/> has been disposed.</exception>
 IEnumerator <T> IEnumerable <T> .GetEnumerator()
 {
     CheckDisposed();
     return(m_collection.GetEnumerator());
 }
Ejemplo n.º 7
0
 public IEnumerator <T> GetEnumerator()
 {
     return(_producerConsumer.GetEnumerator());
 }
Ejemplo n.º 8
0
 /// <summary>Gets an enumerator for the collection.</summary>
 /// <returns>An enumerator.</returns>
 public IEnumerator <T> GetEnumerator() => _contained.GetEnumerator();
Ejemplo n.º 9
0
 public IEnumerator <T> GetEnumerator() => _itemQueue.GetEnumerator();
Ejemplo n.º 10
0
 public IEnumerator <T> GetEnumerator()
 {
     return(_inner.GetEnumerator());
 }
 /// <summary>
 /// 열거자 얻기
 /// </summary>
 /// <returns></returns>
 public IEnumerator <T> GetEnumerator()
 {
     return(InnerCollection.GetEnumerator());
 }