GetHashCode() public method

public GetHashCode ( object obj ) : int
obj object
return int
		public void DefaultInvariant ()
		{
			CaseInsensitiveHashCodeProvider cih = new CaseInsensitiveHashCodeProvider (
				CultureInfo.InvariantCulture);
			int h1 = cih.GetHashCode ("Test String");

			cih = CaseInsensitiveHashCodeProvider.DefaultInvariant;
			int h2 = cih.GetHashCode ("Test String");

			Assert.AreEqual (h1, h2, "#1");

			CaseInsensitiveHashCodeProvider cih1 = CaseInsensitiveHashCodeProvider.DefaultInvariant;
			CaseInsensitiveHashCodeProvider cih2 = CaseInsensitiveHashCodeProvider.DefaultInvariant;
			Assert.IsTrue (object.ReferenceEquals (cih1, cih2));
		}
		public void Default ()
		{
			CaseInsensitiveHashCodeProvider cih = new CaseInsensitiveHashCodeProvider (
				CultureInfo.CurrentCulture);
			int h1 = cih.GetHashCode ("Test String");

			cih = CaseInsensitiveHashCodeProvider.Default;
			int h2 = cih.GetHashCode ("Test String");

			Assert.AreEqual (h1, h2, "#1");

			Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
			CaseInsensitiveHashCodeProvider cih1 = CaseInsensitiveHashCodeProvider.Default;
			Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
			CaseInsensitiveHashCodeProvider cih2 = CaseInsensitiveHashCodeProvider.Default;
			Assert.IsFalse (object.ReferenceEquals (cih1, cih2), "#2");
		}
		public void HashCode ()
		{
			CaseInsensitiveHashCodeProvider cih = new CaseInsensitiveHashCodeProvider ();
			int h1 = cih.GetHashCode ("Test String");
			int h2 = cih.GetHashCode ("test string");
			int h3 = cih.GetHashCode ("TEST STRING");

			Assert.IsTrue (h1 == h2, "Mixed Case != lower case");
			Assert.IsTrue (h1 == h3, "Mixed Case != UPPER CASE");

			h1 = cih.GetHashCode ("one");
			h2 = cih.GetHashCode ("another");
			// Actually this is quite possible.
			Assert.IsFalse (h1 == h2);
		}
		public void SerializationRoundtrip ()
		{
			CaseInsensitiveHashCodeProvider enus = new CaseInsensitiveHashCodeProvider (new CultureInfo ("en-US"));
			BinaryFormatter bf = new BinaryFormatter ();
			MemoryStream ms = new MemoryStream ();
			bf.Serialize (ms, enus);

			ms.Position = 0;
			CaseInsensitiveHashCodeProvider clone = (CaseInsensitiveHashCodeProvider) bf.Deserialize (ms);
			Assert.AreEqual (enus.GetHashCode (String.Empty), clone.GetHashCode (String.Empty), "GetHashCode(string)");
			Assert.AreEqual (enus.GetHashCode (Int32.MinValue), clone.GetHashCode (Int32.MinValue), "GetHashCode(int)");
		}