Exemple #1
0
 /// <summary>Returns an enumerator that iterates through a collection.</summary>
 /// <remarks>This function may have a big impact on memory usage, since it needs to create a flat copy of the whole dictionary!.</remarks>
 /// <returns>
 /// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
 /// </returns>
 IEnumerator IEnumerable.GetEnumerator()
 {
     lock (this)
     {
         KeyValuePair <TKey, TValue>[] items = new KeyValuePair <TKey, TValue> [dict.Count];
         CopyTo(items, 0);
         return(items.GetEnumerator());
     }
 }
Exemple #2
0
        IEnumerator <KeyValuePair <char, T> > IEnumerable <KeyValuePair <char, T> > .GetEnumerator()
        {
            KeyValuePair <char, T>[] buffer = new KeyValuePair <char, T> [m_Alphabet.Length];

            for (int i = 0; i < m_Alphabet.Length; i++)
            {
                buffer[i] = new KeyValuePair <char, T>(m_Alphabet[i], m_Items[i]);
            }

            return((IEnumerator <KeyValuePair <char, T> >)buffer.GetEnumerator());
        }
        public void TestCopyToWithOffset()
        {
            int offset = 5;
            var dict   = GetDefaultHashMap2();

            KeyValuePair <FakeKey <int>, string>[] elements = new KeyValuePair <FakeKey <int>, string> [dict.Count + offset];

            dict.CopyTo(elements, offset);

            // element insertion order
            var enumerator = elements.GetEnumerator();

            for (int i = 0; i < offset; i++)
            {
                Assert.IsTrue(enumerator.MoveNext());
                Assert.AreEqual(null, ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Key);
                Assert.AreEqual(null, ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Value);
            }

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(new FakeKey <int>(2), ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Key);
            Assert.AreEqual("MyString", ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Value);

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(new FakeKey <int>(0), ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Key);
            Assert.AreEqual("OtherString", ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Value);

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(new FakeKey <int>(5), ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Key);
            Assert.AreEqual("NumberFive", ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Value);

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(new FakeKey <int>(int.MaxValue), ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Key);
            Assert.AreEqual("Maximum", ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Value);

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(null, ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Key);
            Assert.AreEqual("NullValue", ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Value);

            Assert.IsTrue(enumerator.MoveNext());
            Assert.AreEqual(new FakeKey <int>(int.MinValue), ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Key);
            Assert.AreEqual("Minimum", ((KeyValuePair <FakeKey <int>, string>)enumerator.Current).Value);

            Assert.IsFalse(enumerator.MoveNext());
            Assert.IsFalse(enumerator.MoveNext());
        }
Exemple #4
0
            public IEnumerator <KeyValuePair <ILocator, IOperationCollection> > GetEnumerator()
            {
                IEnumerable <KeyValuePair <ILocator, IOperationCollection> > enumerable;

                if (Count == 0)
                {
                    enumerable = System.Linq.Enumerable.Empty <KeyValuePair <ILocator, IOperationCollection> >();
                }
                else if (cache != null)
                {
                    enumerable = cache;
                }
                else
                {
                    enumerable = new KeyValuePair <ILocator, IOperationCollection>[] { new KeyValuePair <ILocator, IOperationCollection>(Operations.Locator, Operations) }
                };

                return(enumerable.GetEnumerator());
            }

            IEnumerator IEnumerable.GetEnumerator()
            {
                return(GetEnumerator());
            }
Exemple #5
0
        /// <summary>
        /// Returns an enumerator that iterates through the collection.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
        /// </returns>
        public IEnumerator <KeyValuePair <K, V> > GetEnumerator()
        {
            IList <KeyValuePair <K, V> > nullArray = new KeyValuePair <K, V> [0];

            return(nullArray.GetEnumerator());
        }
 public IEnumerator <KeyValuePair <string, string> > GetEnumerator()
 {
     KeyValuePair <string, string>[] array = new KeyValuePair <string, string> [Count];
     CopyTo(array, 0);
     return((IEnumerator <KeyValuePair <string, string> >)array.GetEnumerator());
 }
Exemple #7
0
 public IEnumerator<KeyValuePair<Player, Room>> GetEnumerator()
 {
     return playerLocation.GetEnumerator();
 }