Addtypeofchar simpletypemapaddtypeofint32

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: object equality. Unique objects do not always have unique HashCodes (no matter how hard you try). There just aren't enough hashcodes to go around :) I understand why my previous 'patch' wasn't accepted (didn't expect it to be). Since we are not using an object's own "GetHashCode()" to get it's hashcode, we can not use it's own "Equals" to determine equality. So we really have to do is create a new method on ObjectProbe that compares two objects in much the same way that ObjectProbe generates hashcodes. I was just too lazy to write it yesterday :) Here is an updated unit test and a potential fix... --- BEGIN UNIT TEST --- using IBatisNet.DataMapper; using IBatisNet.DataMapper.TypeHandlers; using NUnit.Framework; namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests { [TestFixture] public class CacheKeyTest { [Test] public void ShouldNotConsider1LAndNegative9223372034707292159LToBeEqual() { // old version of ObjectProbe gave TestClass based on these longs the same HashCode DoTestClassEquals(1L, -9223372034707292159L); } [Test] public void ShouldNotConsider1LAndNegative9223372036524971138LToBeEqual() { // current version of ObjectProbe gives TestClass based on these longs the same HashCode DoTestClassEquals(1L, -9223372036524971138L); } private static void DoTestClassEquals(long firstLong, long secondLong) { TypeHandlerFactory factory = new TypeHandlerFactory(); // Two cache keys are equal except for the parameter. CacheKey key = new CacheKey(factory, "STATEMENT", "SQL", new TestClass(firstLong), new string {"AProperty"}, 0, 0, CacheKeyType.Object); CacheKey aDifferentKey = new CacheKey(factory, "STATEMENT", "SQL", new TestClass(secondLong), new string {"AProperty"}, 0, 0, CacheKeyType.Object); Assert.IsFalse(aDifferentKey.Equals(key)); // should not be equal. } private class TestClass { private long _property = long.MinValue; public TestClass(long aProperty) { _property = aProperty; } public long AProperty { get { return _property; } set {...
View Full Document

Ask a homework question - tutors are online