Yes, should be
On 9/28/06, Ron Grabowski <[EMAIL PROTECTED]> wrote:
Why is CacheKey.Update(object) using obj.GetHasCode()? Won't that call the
overriden GetHashCode method if its overriden? Is that a BadIdea? Should it be:
public CacheKey Update(object obj)
{
int baseHashCode = HashCodeProvider.GetIdentityHashCode(obj);
...
----- Original Message ----
From: Ron Grabowski <[EMAIL PROTECTED]>
To: dev@ibatis.apache.org
Sent: Thursday, September 28, 2006 12:25:53 AM
Subject: IBatisNet - HashCodeProvider.GetIdentityHashCode
public static int GetIdentityHashCode(object obj)
{
System.Reflection.MethodInfo methodInfo = null;
Type type = typeof(object);
methodInfo = type.GetMethod("GetHashCode");
return (int) methodInfo.Invoke(obj, null);
}
Why can't we call:
public static int GetIdentityHashCode(object obj)
{
return obj.GetHashCode();
}
Does using reflection call the framework's GetHashCode method even if the
object has overriden it?
Can we cache the MethodInfo?
public class HashCodeProvider
{
private static MethodInfo getHashCodeMethodInfo = null;
static HashCodeProvider()
{
Type type = typeof(object);
getHashCodeMethodInfo = type.GetMethod("GetHashCode");
}
public static int GetIdentityHashCode(object obj)
{
return (int)getHashCodeMethodInfo.Invoke(obj, null);
}
}
--
Cheers,
Gilles
<a href="http://www.amazon.com/gp/registry/6JCP7AORB0LE">Wish List</a>