GetEnumerator() public method

public GetEnumerator ( ) : System.Collections.IDictionaryEnumerator
return System.Collections.IDictionaryEnumerator
		public void DefaultValues ()
		{
			HybridDictionary hd = new HybridDictionary (100);
			Assert.AreEqual (0, hd.Count, "Count");
			Assert.IsFalse (hd.IsFixedSize, "IsFixedSize");
			Assert.IsFalse (hd.IsReadOnly, "IsReadOnly");
			Assert.IsFalse (hd.IsSynchronized, "IsSynchronized");
			Assert.AreEqual (0, hd.Keys.Count, "Keys");
			Assert.AreEqual (0, hd.Values.Count, "Values");
			Assert.AreSame (hd, hd.SyncRoot, "SyncRoot");
			Assert.IsNotNull (hd.GetEnumerator (), "GetEnumerator");
			Assert.IsNotNull ((hd as IEnumerable).GetEnumerator (), "IEnumerable.GetEnumerator");
		}
        public void Test01()
        {
            HybridDictionary hd;
            IDictionaryEnumerator en;

            DictionaryEntry curr;        // Enumerator.Current value
            DictionaryEntry de;        // Enumerator.Entry value
            Object k;        // Enumerator.Key value
            Object v;        // Enumerator.Value

            const int BIG_LENGTH = 100;

            // simple string values
            string[] valuesShort =
            {
                "",
                " ",
                "$%^#",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keysShort =
            {
                Int32.MaxValue.ToString(),
                " ",
                System.DateTime.Today.ToString(),
                "",
                "$%^#"
            };

            string[] valuesLong = new string[BIG_LENGTH];
            string[] keysLong = new string[BIG_LENGTH];

            for (int i = 0; i < BIG_LENGTH; i++)
            {
                valuesLong[i] = "Item" + i;
                keysLong[i] = "keY" + i;
            }

            // [] HybridDictionary GetEnumerator()
            //-----------------------------------------------------------------

            hd = new HybridDictionary();

            //  [] Enumerator for empty dictionary
            //
            en = hd.GetEnumerator();
            IEnumerator en2;
            en2 = ((IEnumerable)hd).GetEnumerator();
            string type = en.GetType().ToString();
            if (type.IndexOf("Enumerator", 0) == 0)
            {
                Assert.False(true, string.Format("Error, type is not Enumerator"));
            }

            //
            //  MoveNext should return false
            //
            bool res = en.MoveNext();
            if (res)
            {
                Assert.False(true, string.Format("Error, MoveNext returned true"));
            }

            //
            //  Attempt to get Current should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; });

            //  ---------------------------------------------------------
            //   [] Enumerator for Filled dictionary  - list
            //  ---------------------------------------------------------
            //
            for (int i = 0; i < valuesShort.Length; i++)
            {
                hd.Add(keysShort[i], valuesShort[i]);
            }

            en = hd.GetEnumerator();
            type = en.GetType().ToString();
            if (type.IndexOf("Enumerator", 0) == 0)
            {
                Assert.False(true, string.Format("Error, type is not Enumerator"));
            }

            //
            //  MoveNext should return true
            //

            for (int i = 0; i < hd.Count; i++)
            {
                res = en.MoveNext();
                if (!res)
                {
                    Assert.False(true, string.Format("Error, MoveNext returned false", i));
                }

                curr = (DictionaryEntry)en.Current;
                de = en.Entry;
                //
                //enumerator enumerates in different than added order
                // so we'll check Contains
                //
                if (!hd.Contains(curr.Key.ToString()))
                {
                    Assert.False(true, string.Format("Error, Current dictionary doesn't contain key from enumerator", i));
                }
                if (!hd.Contains(en.Key.ToString()))
                {
                    Assert.False(true, string.Format("Error, Current dictionary doesn't contain key from enumerator", i));
                }
                if (!hd.Contains(de.Key.ToString()))
                {
                    Assert.False(true, string.Format("Error, Current dictionary doesn't contain Entry.Key from enumerator", i));
                }
                if (String.Compare(hd[curr.Key.ToString()].ToString(), curr.Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, Value for current Key is different in dictionary", i));
                }
                if (String.Compare(hd[de.Key.ToString()].ToString(), de.Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, Entry.Value for current Entry.Key is different in dictionary", i));
                }
                if (String.Compare(hd[en.Key.ToString()].ToString(), en.Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, En-tor.Value for current En-tor.Key is different in dictionary", i));
                }

                // while we didn't MoveNext, Current should return the same value
                DictionaryEntry curr1 = (DictionaryEntry)en.Current;
                if (!curr.Equals(curr1))
                {
                    Assert.False(true, string.Format("Error, second call of Current returned different result", i));
                }
                DictionaryEntry de1 = en.Entry;
                if (!de.Equals(de1))
                {
                    Assert.False(true, string.Format("Error, second call of Entry returned different result", i));
                }
            }

            // next MoveNext should bring us outside of the collection
            //
            res = en.MoveNext();
            res = en.MoveNext();
            if (res)
            {
                Assert.False(true, string.Format("Error, MoveNext returned true"));
            }

            //
            //  Attempt to get Current should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; });

            //
            //  Attempt to get Entry should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { de = en.Entry; });

            //
            //  Attempt to get Key should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { k = en.Key; });

            //
            //  Attempt to get Value should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { v = en.Value; });

            en.Reset();

            //
            //  Attempt to get Current should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; });

            //
            //  Attempt to get Entry should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { de = en.Entry; });

            //  ---------------------------------------------------------
            //   [] Enumerator for Filled dictionary  - hashtable
            //  ---------------------------------------------------------
            //
            for (int i = 0; i < valuesLong.Length; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }

            en = hd.GetEnumerator();
            type = en.GetType().ToString();
            if (type.IndexOf("Enumerator", 0) == 0)
            {
                Assert.False(true, string.Format("Error, type is not Enumerator"));
            }

            //
            //  MoveNext should return true
            //

            for (int i = 0; i < hd.Count; i++)
            {
                res = en.MoveNext();
                if (!res)
                {
                    Assert.False(true, string.Format("Error, MoveNext returned false", i));
                }

                curr = (DictionaryEntry)en.Current;
                de = en.Entry;
                //
                //enumerator enumerates in different than added order
                // so we'll check Contains
                //
                if (!hd.Contains(curr.Key.ToString()))
                {
                    Assert.False(true, string.Format("Error, Current dictionary doesn't contain key from enumerator", i));
                }
                if (!hd.Contains(en.Key.ToString()))
                {
                    Assert.False(true, string.Format("Error, Current dictionary doesn't contain key from enumerator", i));
                }
                if (!hd.Contains(de.Key.ToString()))
                {
                    Assert.False(true, string.Format("Error, Current dictionary doesn't contain Entry.Key from enumerator", i));
                }
                if (String.Compare(hd[curr.Key.ToString()].ToString(), curr.Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, Value for current Key is different in dictionary", i));
                }
                if (String.Compare(hd[de.Key.ToString()].ToString(), de.Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, Entry.Value for current Entry.Key is different in dictionary", i));
                }
                if (String.Compare(hd[en.Key.ToString()].ToString(), en.Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, En-tor.Value for current En-tor.Key is different in dictionary", i));
                }

                // while we didn't MoveNext, Current should return the same value
                DictionaryEntry curr1 = (DictionaryEntry)en.Current;
                if (!curr.Equals(curr1))
                {
                    Assert.False(true, string.Format("Error, second call of Current returned different result", i));
                }
                DictionaryEntry de1 = en.Entry;
                if (!de.Equals(de1))
                {
                    Assert.False(true, string.Format("Error, second call of Entry returned different result", i));
                }
            }

            // next MoveNext should bring us outside of the collection
            //
            res = en.MoveNext();
            res = en.MoveNext();
            if (res)
            {
                Assert.False(true, string.Format("Error, MoveNext returned true"));
            }

            //
            //  Attempt to get Current should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; });

            //
            //  Attempt to get Entry should result in exception
            //

            Assert.Throws<InvalidOperationException>(() => { de = en.Entry; });

            //
            //  Attempt to get Key should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { k = en.Key; });

            //
            //  Attempt to get Value should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { v = en.Value; });

            en.Reset();

            //
            //  Attempt to get Current should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; });

            //
            //  Attempt to get Entry should result in exception
            //
            Assert.Throws<InvalidOperationException>(() => { de = en.Entry; });

            //=========================================================
            // --------------------------------------------------------
            //
            //   Modify dictionary when enumerating
            //
            //  [] Enumerator and short modified HD (list)
            //
            hd.Clear();
            if (hd.Count < 1)
            {
                for (int i = 0; i < valuesShort.Length; i++)
                {
                    hd.Add(keysShort[i], valuesShort[i]);
                }
            }

            en = hd.GetEnumerator();
            res = en.MoveNext();
            if (!res)
            {
                Assert.False(true, string.Format("Error, MoveNext returned false"));
            }
            curr = (DictionaryEntry)en.Current;
            de = en.Entry;
            k = en.Key;
            v = en.Value;
            int cnt = hd.Count;
            hd.Remove(keysShort[0]);
            if (hd.Count != cnt - 1)
            {
                Assert.False(true, string.Format("Error, didn't remove item with 0th key"));
            }

            // will return just removed item
            DictionaryEntry curr2 = (DictionaryEntry)en.Current;
            if (!curr.Equals(curr2))
            {
                Assert.False(true, string.Format("Error, current returned different value after modification"));
            }

            // will return just removed item
            DictionaryEntry de2 = en.Entry;
            if (!de.Equals(de2))
            {
                Assert.False(true, string.Format("Error, Entry returned different value after modification"));
            }

            // will return just removed item
            Object k2 = en.Key;
            if (!k.Equals(k2))
            {
                Assert.False(true, string.Format("Error, Key returned different value after modification"));
            }


            // will return just removed item
            Object v2 = en.Value;
            if (!v.Equals(v2))
            {
                Assert.False(true, string.Format("Error, Value returned different value after modification"));
            }

            // exception expected
            Assert.Throws<InvalidOperationException>(() => { res = en.MoveNext(); });

            // ==========================================================
            //
            //
            //  [] Enumerator and long modified HD (hashtable)
            //
            hd.Clear();
            if (hd.Count < 1)
            {
                for (int i = 0; i < valuesLong.Length; i++)
                {
                    hd.Add(keysLong[i], valuesLong[i]);
                }
            }

            en = hd.GetEnumerator();
            res = en.MoveNext();
            if (!res)
            {
                Assert.False(true, string.Format("Error, MoveNext returned false"));
            }
            curr = (DictionaryEntry)en.Current;
            de = en.Entry;
            k = en.Key;
            v = en.Value;
            cnt = hd.Count;
            hd.Remove(keysLong[0]);
            if (hd.Count != cnt - 1)
            {
                Assert.False(true, string.Format("Error, didn't remove item with 0th key"));
            }

            // will return just removed item
            DictionaryEntry curr3 = (DictionaryEntry)en.Current;
            if (!curr.Equals(curr3))
            {
                Assert.False(true, string.Format("Error, current returned different value after modification"));
            }

            // will return just removed item

            DictionaryEntry de3 = en.Entry;
            if (!de.Equals(de3))
            {
                Assert.False(true, string.Format("Error, Entry returned different value after modification"));
            }


            // will return just removed item
            Object k3 = en.Key;
            if (!k.Equals(k3))
            {
                Assert.False(true, string.Format("Error, Key returned different value after modification"));
            }

            // will return just removed item
            Object v3 = en.Value;
            if (!v.Equals(v3))
            {
                Assert.False(true, string.Format("Error, Value returned different value after modification"));
            }

            // exception expected
            Assert.Throws<InvalidOperationException>(() => { res = en.MoveNext(); });

            //
            //   Modify collection when enumerated beyond the end
            //
            //  [] Enumerator and short HD (list) modified after enumerating beyond the end
            //
            hd.Clear();
            for (int i = 0; i < valuesShort.Length; i++)
            {
                hd.Add(keysShort[i], valuesShort[i]);
            }

            en = hd.GetEnumerator();
            for (int i = 0; i < hd.Count; i++)
            {
                en.MoveNext();
            }
            curr = (DictionaryEntry)en.Current;
            de = en.Entry;
            k = en.Key;
            v = en.Value;

            cnt = hd.Count;
            hd.Remove(keysShort[0]);
            if (hd.Count != cnt - 1)
            {
                Assert.False(true, string.Format("Error, didn't remove item with 0th key"));
            }

            // will return just removed item
            DictionaryEntry curr4 = (DictionaryEntry)en.Current;
            if (!curr.Equals(curr4))
            {
                Assert.False(true, string.Format("Error, current returned different value after modification"));
            }

            // will return just removed item
            DictionaryEntry de4 = en.Entry;
            if (!de.Equals(de4))
            {
                Assert.False(true, string.Format("Error, Entry returned different value after modification"));
            }

            // will return just removed item
            Object k4 = en.Key;
            if (!k.Equals(k4))
            {
                Assert.False(true, string.Format("Error, Key returned different value after modification"));
            }

            // will return just removed item
            Object v4 = en.Value;
            if (!v.Equals(v4))
            {
                Assert.False(true, string.Format("Error, Value returned different value after modification"));
            }

            // exception expected
            Assert.Throws<InvalidOperationException>(() => { res = en.MoveNext(); });

            //
            //  [] Enumerator and long HD (hashtable) modified after enumerating beyond the end

            hd.Clear();
            for (int i = 0; i < valuesLong.Length; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }

            en = hd.GetEnumerator();
            for (int i = 0; i < hd.Count; i++)
            {
                en.MoveNext();
            }
            curr = (DictionaryEntry)en.Current;
            de = en.Entry;
            k = en.Key;
            v = en.Value;

            cnt = hd.Count;
            hd.Remove(keysLong[0]);
            if (hd.Count != cnt - 1)
            {
                Assert.False(true, string.Format("Error, didn't remove item with 0th key"));
            }

            // will return just removed item

            DictionaryEntry curr5 = (DictionaryEntry)en.Current;
            if (!curr.Equals(curr5))
            {
                Assert.False(true, string.Format("Error, current returned different value after modification"));
            }


            // will return just removed item

            DictionaryEntry de5 = en.Entry;
            if (!de.Equals(de5))
            {
                Assert.False(true, string.Format("Error, Entry returned different value after modification"));
            }


            // will return just removed item
            Object k5 = en.Key;
            if (!k.Equals(k5))
            {
                Assert.False(true, string.Format("Error, Key returned different value after modification"));
            }


            // will return just removed item

            Object v5 = en.Value;
            if (!v.Equals(v5))
            {
                Assert.False(true, string.Format("Error, Value returned different value after modification"));
            }


            // exception expected
            Assert.Throws<InvalidOperationException>(() => { res = en.MoveNext(); });

            //  ---------------------------------------------------------
            //   [] Enumerator for empty case-insensitive dictionary
            //  ---------------------------------------------------------
            //
            hd = new HybridDictionary(true);

            en = hd.GetEnumerator();
            type = en.GetType().ToString();
            if (type.IndexOf("Enumerator", 0) == 0)
            {
                Assert.False(true, string.Format("Error, type is not Enumerator"));
            }
        }
        /// <summary>
        /// IDictionary interface that returns an enumerator on the dictionary contents
        /// </summary>
        /// <returns>Returns an enumerator on the dictionary contents</returns>
        protected IDictionaryEnumerator GetDictionaryEnumerator()
        {
            HybridDictionary namespaceTable = new HybridDictionary(_lastDecl);

            for (int thisDecl = 0; thisDecl < _lastDecl; thisDecl++)
            {
                if (_nsDeclarations[thisDecl].Uri != null)
                {
                    namespaceTable[_nsDeclarations[thisDecl].Prefix] = _nsDeclarations[thisDecl].Uri;
                }
            }

            return namespaceTable.GetEnumerator();
        }
Beispiel #4
0
        /// <summary>Retrieves a cache enumerator used to iterate through the key settings and their values contained in the cache.</summary>
        /// <returns>An enumerator to iterate through the <see cref="Cache"/> object.</returns>
        public ICacheEnumerator GetEnumerator()
        {
            Purge();

            return(new CacheEnumerator(_data.GetEnumerator()));
        }
Beispiel #5
0
    public string setInLineStyles(string htmlContent)
    {
        htmlContent = this.removeStylesForFirstDiv(htmlContent);

        int startIndex = 0;
        int indexClass = htmlContent.IndexOf("class", startIndex);

        HybridDictionary hdStyles = new System.Collections.Specialized.HybridDictionary();

        // The token class was found:
        while (indexClass >= 0)
        {
            int nextChar = indexClass + 5;

            string className = string.Empty;

            // It is a class attribute applied to a html tag:
            if (nextChar < htmlContent.Length && htmlContent[nextChar] == '=')
            {
                // Get the class name:
                for (int i = nextChar + 1; htmlContent[i] != ' ' && htmlContent[i] != '>'; i++)
                {
                    className += htmlContent[i];
                }
            }

            if (!string.IsNullOrEmpty(className) && !hdStyles.Contains(className))
            {
                string classDef = this.getClassDefinition(htmlContent, className);

                if (!string.IsNullOrEmpty(classDef) && !hdStyles.Contains(className))
                {
                    hdStyles.Add(className, classDef);
                }
            }

            startIndex = indexClass + 5;
            indexClass = htmlContent.IndexOf("class", startIndex);
        }

        string htmlContentChanged = string.Empty;

        // We finished to collect all the class elements and its definitions:
        if (hdStyles.Count > 0)
        {
            StringBuilder sbClasses = new StringBuilder(htmlContent);

            // We are ready to replace class entries to inline styles:
            IDictionaryEnumerator e = hdStyles.GetEnumerator();

            while (e.MoveNext())
            {
                string classToReplace = "class=" + e.Key.ToString();
                string inlineStyle    = "style=\"" + e.Value.ToString() + "\"";

                // First option:
                sbClasses.Replace(classToReplace, inlineStyle);

                // Second option:
                classToReplace = "class=\"" + e.Key.ToString() + "\"";
                sbClasses.Replace(classToReplace, inlineStyle);
            }

            htmlContentChanged = sbClasses.ToString();
        }
        else
        {
            htmlContentChanged = htmlContent;
        }

        return(htmlContentChanged);
    }
        public void Test01()
        {
            IntlStrings intl;
            HybridDictionary hd;
            const int BIG_LENGTH = 100;

            // simple string values
            string[] valuesShort =
            {
                "",
                " ",
                "$%^#",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keysShort =
            {
                Int32.MaxValue.ToString(),
                " ",
                System.DateTime.Today.ToString(),
                "",
                "$%^#"
            };

            string[] valuesLong = new string[BIG_LENGTH];
            string[] keysLong = new string[BIG_LENGTH];

            // string [] destination;
            Array destination;

            int cnt = 0;            // Count

            // initialize IntStrings
            intl = new IntlStrings();

            for (int i = 0; i < BIG_LENGTH; i++)
            {
                valuesLong[i] = "Item" + i;
                keysLong[i] = "keY" + i;
            }

            // [] HybridDictionary is constructed as expected
            //-----------------------------------------------------------------

            hd = new HybridDictionary();

            // []  Copy empty dictionary into empty array
            //
            destination = Array.CreateInstance(typeof(Object), 0);

            Assert.Throws<ArgumentOutOfRangeException>(() => { hd.CopyTo(destination, -1); });

            hd.CopyTo(destination, 0);

            // exception even when copying empty dictionary
            Assert.Throws<ArgumentException>(() => { hd.CopyTo(destination, 1); });

            //  [] Copy empty dictionary into filled array
            //
            destination = Array.CreateInstance(typeof(Object), valuesShort.Length);
            for (int i = 0; i < valuesShort.Length; i++)
            {
                destination.SetValue(valuesShort[i], i);
            }
            hd.CopyTo(destination, 0);
            if (destination.Length != valuesShort.Length)
            {
                Assert.False(true, string.Format("Error, altered array after copying empty dictionary"));
            }
            if (destination.Length == valuesShort.Length)
            {
                for (int i = 0; i < valuesShort.Length; i++)
                {
                    if (String.Compare(destination.GetValue(i).ToString(), valuesShort[i]) != 0)
                    {
                        Assert.False(true, string.Format("Error, altered item {0} after copying empty dictionary", i));
                    }
                }
            }


            //  [] few simple strings and CopyTo(Array, 0)
            //

            hd.Clear();
            cnt = hd.Count;
            int len = valuesShort.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysShort[i], valuesShort[i]);
            }
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length));
            }

            destination = Array.CreateInstance(typeof(Object), len);
            hd.CopyTo(destination, 0);
            //
            //
            for (int i = 0; i < len; i++)
            {
                // verify that dictionary is copied correctly
                //

                if (String.Compare(hd[keysShort[i]].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), hd[keysShort[i]]));
                }
                if (String.Compare(keysShort[i], ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), keysShort[i]));
                }
            }

            //  [] few simple strings and CopyTo(Array, middle_index)
            //


            hd.Clear();

            hd.Clear();
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysShort[i], valuesShort[i]);
            }
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, valuesShort.Length));
            }

            destination = Array.CreateInstance(typeof(Object), len * 2);
            hd.CopyTo(destination, len);

            //
            //
            for (int i = 0; i < len; i++)
            {
                // verify that dictionary is copied correctly
                //
                if (String.Compare(hd[keysShort[i]].ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, hd[keysShort[i]]));
                }
                // verify keysShort
                if (String.Compare(keysShort[i], ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, keysShort[i]));
                }
            }

            //  [] many simple strings and CopyTo(Array, 0)
            //

            hd.Clear();
            cnt = hd.Count;
            len = valuesLong.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }

            destination = Array.CreateInstance(typeof(Object), len);
            hd.CopyTo(destination, 0);
            //
            //
            IDictionaryEnumerator en = hd.GetEnumerator();
            en.MoveNext();
            // items are copied in the same order they are enumerated
            for (int i = 0; i < len; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;

                if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), hd[k]));
                }
                if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), k.ToString()));
                }
                en.MoveNext();
            }

            //  [] many simple strings and CopyTo(Array, middle_index)
            //


            hd.Clear();

            hd.Clear();
            len = valuesLong.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }
            if (hd.Count != len)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }

            destination = Array.CreateInstance(typeof(Object), len * 2);
            hd.CopyTo(destination, len);

            //
            //
            en = hd.GetEnumerator();
            en.MoveNext();
            for (int i = 0; i < len; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;
                if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, hd[k]));
                }
                // verify keysShort
                if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, k));
                }
                en.MoveNext();
            }

            //
            // [] many Intl strings and CopyTo(Array, 0)
            //

            string[] intlValues = new string[len * 2];

            // fill array with unique strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                string val = intl.GetRandomString(MAX_LEN);
                while (Array.IndexOf(intlValues, val) != -1)
                    val = intl.GetRandomString(MAX_LEN);
                intlValues[i] = val;
            }

            Boolean caseInsensitive = false;
            for (int i = 0; i < len * 2; i++)
            {
                if (intlValues[i].Length != 0 && intlValues[i].ToLower() == intlValues[i].ToUpper())
                    caseInsensitive = true;
            }

            hd.Clear();
            for (int i = 0; i < len; i++)
            {
                hd.Add(intlValues[i + len], intlValues[i]);
            }
            if (hd.Count != (len))
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
            }

            destination = Array.CreateInstance(typeof(Object), len);
            hd.CopyTo(destination, 0);
            //
            //
            en = hd.GetEnumerator();
            en.MoveNext();
            for (int i = 0; i < len; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;
                if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, hd[k]));
                }
                // verify keysShort
                if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, k));
                }
                en.MoveNext();
            }


            //
            // [] many Intl strings and CopyTo(Array, middle_index)
            //


            destination = Array.CreateInstance(typeof(Object), len * 2);
            hd.CopyTo(destination, len);

            //
            // order of items is the same as they were in dictionary
            //
            en = hd.GetEnumerator();
            en.MoveNext();
            for (int i = 0; i < len; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;
                if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, hd[k]));
                }
                // verify keysShort
                if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, k));
                }
                en.MoveNext();
            }

            // [] few Intl strings and CopyTo(Array, 0)
            //

            int len1 = valuesShort.Length;

            hd.Clear();
            for (int i = 0; i < len1; i++)
            {
                hd.Add(intlValues[i + len1], intlValues[i]);
            }
            if (hd.Count != (len1))
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len1));
            }

            destination = Array.CreateInstance(typeof(Object), len1);
            hd.CopyTo(destination, 0);
            //
            //
            en = hd.GetEnumerator();
            en.MoveNext();
            for (int i = 0; i < len1; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;
                if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, hd[k]));
                }
                // verify keysShort
                if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, k));
                }
                en.MoveNext();
            }

            //
            // [] few Intl strings and CopyTo(Array, middle_index)
            //


            destination = Array.CreateInstance(typeof(Object), len1 * 2);
            hd.CopyTo(destination, len1);

            //
            // order of items is the same as they were in dictionary
            //
            en = hd.GetEnumerator();
            en.MoveNext();
            for (int i = 0; i < len1; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;
                if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i + len1)).Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len1)).Value, hd[k]));
                }
                // verify keysShort
                if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i + len1)).Key.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len1)).Key, k));
                }
                en.MoveNext();
            }


            //
            // [] Case sensitivity
            //

            string[] intlValuesUpper = new string[len * 2];
            string[] intlValuesLower = new string[len * 2];

            // fill array with unique upper-case strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                string val = intlValues[i].ToUpper();
                while (Array.IndexOf(intlValuesUpper, val) != -1)
                    val = intl.GetRandomString(MAX_LEN).ToUpper();
                intlValuesUpper[i] = val;
            }

            caseInsensitive = false;
            for (int i = 0; i < len * 2; i++)
            {
                intlValuesLower[i] = intlValuesUpper[i].ToLower();
                if (intlValuesLower[i].Length != 0 &&
            intlValuesLower[i] == intlValuesUpper[i])
                    caseInsensitive = true;
            }

            hd.Clear();
            //
            // will use first half of array as values and second half as keys
            //
            for (int i = 0; i < len; i++)
            {
                hd.Add(intlValuesUpper[i + len], intlValuesUpper[i]);     // adding uppercase strings
            }

            destination = Array.CreateInstance(typeof(Object), len);
            hd.CopyTo(destination, 0);

            //
            //
            en = hd.GetEnumerator();
            en.MoveNext();
            for (int i = 0; i < len; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;
                if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, hd[k]));
                }

                if (!caseInsensitive && Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) > -1)
                {
                    Assert.False(true, string.Format("Error, copied lowercase string"));
                }
                // verify keysShort
                if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0)
                {
                    Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, k));
                }

                if (!caseInsensitive && Array.IndexOf(intlValuesLower, ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) > -1)
                {
                    Assert.False(true, string.Format("Error, copied lowercase key"));
                }
                en.MoveNext();
            }

            //  ----------------------------------------------------------------
            //   [] Parameter validation for short HybridDictionary (list)
            //  ----------------------------------------------------------------

            hd = new HybridDictionary();
            for (int i = 0; i < len1; i++)
            {
                hd.Add(keysShort[i], valuesShort[i]);
            }
            //
            //   CopyTo(null, int)
            //
            destination = null;
            Assert.Throws<ArgumentNullException>(() => { hd.CopyTo(destination, 0); });

            //
            //   CopyTo(Array, -1)
            //

            destination = Array.CreateInstance(typeof(Object), 2);
            Assert.Throws<ArgumentOutOfRangeException>(() => { hd.CopyTo(destination, -1); });

            //
            //   CopyTo(Array, upperBound+1)
            //
            cnt = hd.Count;

            destination = Array.CreateInstance(typeof(Object), cnt);
            Assert.Throws<ArgumentException>(() => { hd.CopyTo(destination, cnt); });

            //
            //   CopyTo(Array, upperBound+2)
            //
            Assert.Throws<ArgumentException>(() => { hd.CopyTo(destination, cnt + 1); });

            //
            //   CopyTo(Array, not_enough_space)
            //
            Assert.Throws<ArgumentException>(() => { hd.CopyTo(destination, cnt / 2); });

            //
            //   CopyTo(multidim_Array, 0)
            //

            Array dest = new String[cnt, cnt];
            Assert.Throws<ArgumentException>(() => { hd.CopyTo(dest, 0); });

            //
            //   CopyTo(wrong_type, 0)
            //

            dest = Array.CreateInstance(typeof(ArrayList), cnt);
            Assert.Throws<System.InvalidCastException>(() => { hd.CopyTo(dest, 0); });
            //
            //   CopyTo(Array, upperBound+1) - copy empty dictionary - no exception
            //
            hd.Clear();

            destination = Array.CreateInstance(typeof(Object), len);
            hd.CopyTo(destination, len);


            //  ----------------------------------------------------------------
            //   [] Parameter validation for long HybridDictionary (hashtable)
            //  ----------------------------------------------------------------

            hd = new HybridDictionary();
            len = valuesLong.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }
            //
            //   CopyTo(null, int)
            //
            destination = null;
            Assert.Throws<ArgumentNullException>(() => { hd.CopyTo(destination, 0); });
            //
            //   CopyTo(Array, -1)
            //

            destination = Array.CreateInstance(typeof(Object), 2);
            Assert.Throws<ArgumentOutOfRangeException>(() => { hd.CopyTo(destination, -1); });

            //
            //   CopyTo(Array, upperBound+1)
            //
            cnt = hd.Count;

            destination = Array.CreateInstance(typeof(Object), cnt);
            Assert.Throws<ArgumentException>(() => { hd.CopyTo(destination, cnt); });

            //
            //   CopyTo(Array, upperBound+2)
            //
            Assert.Throws<ArgumentException>(() => { hd.CopyTo(destination, cnt + 1); });

            //
            //   CopyTo(Array, not_enough_space)
            //
            Assert.Throws<ArgumentException>(() => { hd.CopyTo(destination, cnt / 2); });

            //
            //   CopyTo(multidim_Array, 0)
            //

            dest = Array.CreateInstance(typeof(string), cnt, cnt);
            Assert.Throws<ArgumentException>(() => { hd.CopyTo(dest, 0); });

            //
            //   CopyTo(wrong_type, 0)
            //

            dest = Array.CreateInstance(typeof(ArrayList), cnt);
            Assert.Throws<System.InvalidCastException>(() => { hd.CopyTo(dest, 0); });

            //
            //  [] CopyTo() for few not_overriding_Equals objects
            //

            hd.Clear();
            int num = 2;
            Hashtable[] lbl = new Hashtable[num];
            ArrayList[] b = new ArrayList[num];
            for (int i = 0; i < num; i++)
            {
                lbl[i] = new Hashtable();
                b[i] = new ArrayList();
                hd.Add(lbl[i], b[i]);
            }

            destination = Array.CreateInstance(typeof(Object), num);
            hd.CopyTo(destination, 0);
            //
            //
            en = hd.GetEnumerator();
            en.MoveNext();
            for (int i = 0; i < num; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;
                if (!hd[k].Equals(((DictionaryEntry)destination.GetValue(i)).Value))
                {
                    Assert.False(true, string.Format("Error, failed to copy {0}th entry", i));
                }
                // verify keysShort
                if (!k.Equals(((DictionaryEntry)destination.GetValue(i)).Key))
                {
                    Assert.False(true, string.Format("Error, failed to copy {0} entry", i));
                }
                en.MoveNext();
            }

            //  [] CopyTo() for many not_overriding_Equals objects
            //
            hd.Clear();
            num = 40;
            lbl = new Hashtable[num];
            b = new ArrayList[num];
            for (int i = 0; i < num; i++)
            {
                lbl[i] = new Hashtable();
                b[i] = new ArrayList();
                hd.Add(lbl[i], b[i]);
            }

            destination = Array.CreateInstance(typeof(Object), num);
            hd.CopyTo(destination, 0);
            //
            //
            en = hd.GetEnumerator();
            en.MoveNext();
            for (int i = 0; i < num; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;
                if (!hd[k].Equals(((DictionaryEntry)destination.GetValue(i)).Value))
                {
                    Assert.False(true, string.Format("Error, failed to copy {0}th entry", i));
                }
                // verify keysShort
                if (!k.Equals(((DictionaryEntry)destination.GetValue(i)).Key))
                {
                    Assert.False(true, string.Format("Error, failed to copy {0} entry", i));
                }
                en.MoveNext();
            }

            //
            //  [] CopyTo() - for short case-insensitive HybridDictionary
            //
            hd = new HybridDictionary(true);
            len = 3;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }

            destination = Array.CreateInstance(typeof(Object), len);
            hd.CopyTo(destination, 0);
            //
            //
            en = hd.GetEnumerator();
            en.MoveNext();
            for (int i = 0; i < len; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;
                if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) < 0)
                {
                    Assert.False(true, string.Format("Error, failed to copy {0}th entry when case-insensitive", i));
                }
                // verify keysShort
                if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) < 0)
                {
                    Assert.False(true, string.Format("Error, failed to copy {0} entry when case-insensitive", i));
                }
                en.MoveNext();
            }

            //  [] CopyTo() - for long case-insensitive HybridDictionary
            //
            hd = new HybridDictionary(true);
            len = valuesLong.Length;
            for (int i = 0; i < len; i++)
            {
                hd.Add(keysLong[i], valuesLong[i]);
            }

            destination = Array.CreateInstance(typeof(Object), len);
            hd.CopyTo(destination, 0);
            //
            //
            en = hd.GetEnumerator();
            en.MoveNext();
            for (int i = 0; i < len; i++)
            {
                // verify that dictionary is copied correctly
                //
                Object k = en.Key;
                if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) < 0)
                {
                    Assert.False(true, string.Format("Error, failed to copy {0}th entry when case-insensitive", i));
                }
                // verify keysShort
                if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) < 0)
                {
                    Assert.False(true, string.Format("Error, failed to copy {0} entry when case-insensitive", i));
                }
                en.MoveNext();
            }
        }