using System.Collections;
using System.Collections.Generic;
public class SerializerKey
public Type Type { get; set; }
public string Name { get; set; }
public class SerializerKeyComparer : IEqualityComparer<SerializerKey>
public bool Equals(SerializerKey x, SerializerKey y)
if (ReferenceEquals(x, y))
if (ReferenceEquals(x, null))
if (ReferenceEquals(y, null))
if (x.GetType() != y.GetType())
String.Equals(x.Name, y.Name, StringComparison.InvariantCulture),
String.Equals(x.Type.FullName, y.Type.FullName, StringComparison.InvariantCulture),
String.Equals(x.Type.AssemblyQualifiedName, y.Type.AssemblyQualifiedName, StringComparison.InvariantCulture),
return tests.All(o => o);
public int GetHashCode(SerializerKey obj)
obj.Type.FullName.GetHashCode(),
obj.Type.AssemblyQualifiedName.GetHashCode(),
return props.Aggregate((s1, s2) => (s1 * 397) ^ s2);
public static void Main()
var hashtable = new Hashtable();
var hashKey1 = new { Type = typeof(DateTime), Name = string.Empty };
var hashKey2 = new { Type = typeof(DateTime), Name = string.Empty };
hashtable[hashKey1] = "1";
hashtable[hashKey1] = "2";
var dictionary1 = new Dictionary<SerializerKey,string>();
var dictionary2 = new Dictionary<SerializerKey,string>(new SerializerKeyComparer());
var dictionaryKey1 = new SerializerKey { Type = typeof(DateTime), Name = string.Empty };
var dictionaryKey2 = new SerializerKey { Type = typeof(DateTime), Name = string.Empty };
dictionary1[dictionaryKey1] = "1";
dictionary1[dictionaryKey2] = "2";
dictionary2[dictionaryKey1] = "1";
dictionary2[dictionaryKey2] = "2";
Console.WriteLine("Hashtable");
Console.WriteLine(hashKey1.GetHashCode());
Console.WriteLine(hashKey2.GetHashCode());
Console.WriteLine(hashtable.Count);
Console.WriteLine("Dictionary default implementation");
Console.WriteLine(dictionaryKey1.GetHashCode());
Console.WriteLine(dictionaryKey2.GetHashCode());
Console.WriteLine(dictionary1.Count());
Console.WriteLine("Dictionary using SerializerKeyComparer");
Console.WriteLine(new SerializerKeyComparer().GetHashCode(dictionaryKey1).GetHashCode());
Console.WriteLine(new SerializerKeyComparer().GetHashCode(dictionaryKey2).GetHashCode());
Console.WriteLine(dictionary2.Count());