Object identity for Hashtables http://www.thescripts.com/forum/post828177-1.html
...Implementation of IHashCodeProvider that does a non-virtual call to System.Object.GetHashCode() to retrieve an AppDomain-unique hash code for an object, regardless if GetHashCode is overridden... http://www.msjogren.net/dotnet/eng/samples/misc.asp ----- 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); } }