/// <summary> /// Invokes RuntimeHelpers.GetHashCode on given value, that is a default hashCode ignoring user overrides. /// </summary> /// <param name="value">Valid value.</param> /// <returns>Hash code of the object in the debugee.</returns> public static int InvokeDefaultGetHashCode(this Value value) { if (hashCodeMethod == null || hashCodeMethod.Process.HasExited) { DebugType typeRuntimeHelpers = DebugType.CreateFromType(value.AppDomain, typeof(System.Runtime.CompilerServices.RuntimeHelpers)); hashCodeMethod = (DebugMethodInfo)typeRuntimeHelpers.GetMethod("GetHashCode", BindingFlags.Public | BindingFlags.Static); if (hashCodeMethod == null) { throw new DebuggerException("Cannot obtain method System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode"); } } Value defaultHashCode = Eval.InvokeMethod(DebuggerHelpers.hashCodeMethod, null, new Value[] { value }); //MethodInfo method = value.Type.GetMember("GetHashCode", BindingFlags.Method | BindingFlags.IncludeSuperType) as MethodInfo; //string hashCode = value.InvokeMethod(method, null).AsString; return((int)defaultHashCode.PrimitiveValue); }
/// <summary> /// Invokes RuntimeHelpers.GetHashCode on given value, that is a default hashCode ignoring user overrides. /// </summary> /// <param name="value">Valid value.</param> /// <returns>Hash code of the object in the debugee.</returns> public static int InvokeDefaultGetHashCode(this Value value) { if (hashCodeMethod == null || hashCodeMethod.Process.HasExited) { DebugType typeRuntimeHelpers = DebugType.CreateFromType(value.AppDomain, typeof(System.Runtime.CompilerServices.RuntimeHelpers)); hashCodeMethod = (DebugMethodInfo)typeRuntimeHelpers.GetMethod("GetHashCode", BindingFlags.Public | BindingFlags.Static); if (hashCodeMethod == null) { throw new DebuggerException("Cannot obtain method System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode"); } } // David: I had hard time finding out how to invoke static method. // value.InvokeMethod is nice for instance methods. // what about MethodInfo.Invoke() ? // also, there could be an overload that takes 1 parameter instead of array Value defaultHashCode = Eval.InvokeMethod(DebuggerHelpers.hashCodeMethod, null, new Value[] { value }); //MethodInfo method = value.Type.GetMember("GetHashCode", BindingFlags.Method | BindingFlags.IncludeSuperType) as MethodInfo; //string hashCode = value.InvokeMethod(method, null).AsString; return((int)defaultHashCode.PrimitiveValue); }