public static TargetObject CallMethod (MdbEvaluationContext ctx, string name, TargetObject target, params TargetObject[] args) { #if REFLECTION_INVOKE if (target is TargetGenericInstanceObject || !(target is TargetStructObject)) { // Calling methods on generic objects is suprisingly not supported // by the debugger. As a workaround we do the call using reflection. if (name != "ToString" || args.Length != 0) { GetTypeOf (ctx, "System.Convert"); TargetType cc = ctx.Frame.Language.LookupType ("System.Convert"); SR.BindingFlags sf = SR.BindingFlags.InvokeMethod | SR.BindingFlags.Static | SR.BindingFlags.FlattenHierarchy | SR.BindingFlags.Public | SR.BindingFlags.NonPublic; CallMethodWithReflection (ctx, sf, "ToString", cc, null, target); } SR.BindingFlags f = SR.BindingFlags.InvokeMethod | SR.BindingFlags.Instance | SR.BindingFlags.Public | SR.BindingFlags.NonPublic; return CallMethodWithReflection (ctx, f, name, target.Type, target, args); } #endif ctx.AssertTargetInvokeAllowed (); TargetType[] types = new TargetType [args.Length]; for (int n=0; n<types.Length; n++) types [n] = args [n].Type; TargetStructObject starget = (TargetStructObject) target; MemberReference mem = OverloadResolve (ctx, name, starget.Type, types, true, false, true); TargetFunctionType function = (TargetFunctionType) ((TargetMethodInfo) mem.Member).Type; while (starget.Type != mem.DeclaringType) { TargetStructObject par = starget.GetParentObject (ctx.Thread); if (par != null) starget = par; else break; } TargetMethodSignature sig = function.GetSignature (ctx.Thread); TargetObject[] objs = new TargetObject [args.Length]; for (int i = 0; i < args.Length; i++) { objs [i] = TargetObjectConvert.ImplicitConversionRequired ( ctx, args [i], sig.ParameterTypes [i]); } return Server.Instance.RuntimeInvoke (ctx, function, starget, objs); }
public static TargetObject CallStaticMethod (MdbEvaluationContext ctx, string name, TargetType type, params TargetObject[] args) { #if REFLECTION_INVOKE if (type is TargetGenericInstanceType || !(type is TargetStructType)) { // Calling methods on generic objects is suprisingly not supported // by the debugger. As a workaround we do the call using reflection. SR.BindingFlags f = SR.BindingFlags.InvokeMethod | SR.BindingFlags.Static | SR.BindingFlags.Public | SR.BindingFlags.NonPublic; return CallMethodWithReflection (ctx, f, name, type, null, args); } #endif ctx.AssertTargetInvokeAllowed (); TargetType[] types = new TargetType [args.Length]; for (int n=0; n<types.Length; n++) types [n] = args [n].Type; MemberReference mem = OverloadResolve (ctx, name, type, types, false, true, true); TargetFunctionType function = (TargetFunctionType) ((TargetMethodInfo) mem.Member).Type; TargetMethodSignature sig = function.GetSignature (ctx.Thread); TargetObject[] objs = new TargetObject [args.Length]; for (int i = 0; i < args.Length; i++) { objs [i] = TargetObjectConvert.ImplicitConversionRequired (ctx, args [i], sig.ParameterTypes [i]); } return Server.Instance.RuntimeInvoke (ctx, function, null, objs); }
public static TargetStructObject GetTypeOf (MdbEvaluationContext ctx, string typeName) { ctx.AssertTargetInvokeAllowed (); TargetType tt = ctx.Frame.Language.LookupType ("System.Type"); if (tt == null) return null; TargetObject tn = ctx.Frame.Language.CreateInstance (ctx.Thread, ObjectUtil.FixTypeName (typeName)); TargetObject res = CallStaticMethod (ctx, "GetType", tt, tn); return (TargetStructObject) ctx.GetRealObject (res); }