Exemplo n.º 1
0
//		public static MethodInfo GetFromName(Process process, uint? domainID, System.Type type, string methodName, int paramCount)
//		{
//			if (type.IsNested) throw new DebuggerException("Not implemented for nested types");
//			if (type.IsGenericType) throw new DebuggerException("Not implemented for generic types");
//			if (type.IsGenericParameter) throw new DebuggerException("Type can not be generic parameter");
//
//			DebugType debugType = DebugType.Create(process, domainID, type.FullName);
//			if (debugType == null) {
//				throw new DebuggerException("Type " + type.FullName + " not found");
//			}
//
//			foreach(MethodInfo methodInfo in debugType.GetMethods(methodName)) {
//				if (methodInfo.ParameterCount == paramCount) {
//					return methodInfo;
//				}
//			}
//			throw new DebuggerException("Method " + methodName + " not found");
//		}

        /// <summary>
        /// Synchronously invoke the method of an a given object
        /// </summary>
        public Value Invoke(Value objectInstance, Value[] arguments)
        {
            return(Eval.InvokeMethod(
                       this,
                       this.IsStatic ? null : objectInstance,
                       arguments ?? new Value[0]
                       ));
        }
Exemplo n.º 2
0
        /// <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 = findDebuggeeHashCodeMethod(value);
            }
            Value valueHashCode;

            try {
                valueHashCode = Eval.InvokeMethod(WindowsDebugger.EvalThread, hashCodeMethod, null, new Value[] { value });
            } catch (InvalidComObjectException) {
                // debuggee was restarted
                hashCodeMethod = findDebuggeeHashCodeMethod(value);
                valueHashCode  = Eval.InvokeMethod(WindowsDebugger.EvalThread, hashCodeMethod, null, new Value[] { value });
            }
            return((int)valueHashCode.PrimitiveValue);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <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);
        }
        /// <inheritdoc/>
        public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            List <Value> args = new List <Value>();

            foreach (object arg in parameters)
            {
                args.Add((Value)arg);
            }
            if (this.IsSpecialName && this.Name == ".ctor")
            {
                if (obj != null)
                {
                    throw new GetValueException("'obj' must be null for constructor call");
                }
                return(Eval.NewObject(this, args.ToArray()));
            }
            else
            {
                return(Eval.InvokeMethod(this, (Value)obj, args.ToArray()));
            }
        }