public void Clone_IsShallowCopy() { var hash = new HashtableEx(); for (int i = 0; i < 10; i++) { hash.Add(i, new Foo()); } HashtableEx clone = (HashtableEx)hash.Clone(); for (int i = 0; i < clone.Count; i++) { Assert.AreEqual("Hello World", ((Foo)clone[i]).StringValue); Assert.AreEqual(hash[i], clone[i]); } // Change object in original hashtable ((Foo)hash[1]).StringValue = "Goodbye"; Assert.AreEqual("Goodbye", ((Foo)clone[1]).StringValue); // Removing an object from the original hashtable doesn't change the clone hash.Remove(0); Assert.IsTrue(clone.Contains(0)); }
public static void PerformActionOnAllHashtableWrappers(HashtableEx hashtable, Action <HashtableEx> action) { // Synchronized returns a slightly different version of HashtableEx HashtableEx[] hashtableTypes = { (HashtableEx)hashtable.Clone(), }; foreach (HashtableEx hashtableType in hashtableTypes) { action(hashtableType); } }