예제 #1
0
        private static void TestComparerSerialization <T>(SCG.IEqualityComparer <T> equalityComparer, string internalTypeName = null)
        {
            var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            var s  = new MemoryStream();

            var dict = new Dictionary <T, T>(equalityComparer);

            Assert.Same(equalityComparer, dict.EqualityComparer);

            bf.Serialize(s, dict);
            s.Position = 0;
            dict       = (Dictionary <T, T>)bf.Deserialize(s);

            if (internalTypeName == null)
            {
                Assert.IsType(equalityComparer.GetType(), dict.EqualityComparer);
            }
            else
            {
                Assert.Equal(internalTypeName, dict.EqualityComparer.GetType().ToString());
            }

            Assert.True(equalityComparer.Equals(dict.EqualityComparer));
        }