public CorValue CreateCorValue(EvaluationContext ctx, CorType type, params CorValRef[] args) { CorEvaluationContext cctx = (CorEvaluationContext)ctx; CorValue[] vargs = new CorValue [args.Length]; for (int n = 0; n < args.Length; n++) { vargs [n] = args [n].Val; } Type t = type.GetTypeInfo(cctx.Session); MethodInfo ctor = null; foreach (MethodInfo met in t.GetMethods()) { if (met.IsSpecialName && met.Name == ".ctor") { ParameterInfo[] pinfos = met.GetParameters(); if (pinfos.Length == 1) { ctor = met; break; } } } if (ctor == null) { return(null); } CorFunction func = type.Class.Module.GetFunctionFromToken(ctor.MetadataToken); return(cctx.RuntimeInvoke(func, type.TypeParameters, null, vargs)); }
bool IsApplicable(CorEvaluationContext ctx, MethodInfo method, CorType[] types, out string error, out int matchCount) { ParameterInfo[] mparams = method.GetParameters(); matchCount = 0; for (int i = 0; i < types.Length; i++) { Type param_type = mparams[i].ParameterType; if (param_type.FullName == GetTypeName(ctx, types[i])) { matchCount++; continue; } if (IsAssignableFrom(ctx, param_type, types[i])) { continue; } error = String.Format( "Argument {0}: Cannot implicitly convert `{1}' to `{2}'", i, GetTypeName(ctx, types[i]), param_type.FullName); return(false); } error = null; return(true); }
protected override EvaluationContext GetEvaluationContext(int frameIndex, EvaluationOptions options) { CorEvaluationContext ctx = new CorEvaluationContext(session, this, frameIndex, options); ctx.Thread = thread; return(ctx); }
public override string GetTypeName(EvaluationContext ctx, object gtype) { CorType type = (CorType)gtype; CorEvaluationContext cctx = (CorEvaluationContext)ctx; Type t; if (CorMetadataImport.CoreTypes.TryGetValue(type.Type, out t)) { return(t.FullName); } try { if (type.Type == CorElementType.ELEMENT_TYPE_ARRAY || type.Type == CorElementType.ELEMENT_TYPE_SZARRAY) { return(GetTypeName(ctx, type.FirstTypeParameter) + "[" + new string (',', type.Rank - 1) + "]"); } if (type.Type == CorElementType.ELEMENT_TYPE_BYREF) { return(GetTypeName(ctx, type.FirstTypeParameter) + "&"); } if (type.Type == CorElementType.ELEMENT_TYPE_PTR) { return(GetTypeName(ctx, type.FirstTypeParameter) + "*"); } return(type.GetTypeInfo(cctx.Session).FullName); } catch (Exception ex) { Console.WriteLine(ex); throw; } }
public static void SetValue(this CorValRef thisVal, EvaluationContext ctx, CorValRef val) { CorEvaluationContext cctx = (CorEvaluationContext)ctx; CorObjectAdaptor actx = (CorObjectAdaptor)ctx.Adapter; if (actx.IsEnum(ctx, thisVal.Val.ExactType) && !actx.IsEnum(ctx, val.Val.ExactType)) { ValueReference vr = actx.GetMember(ctx, null, thisVal, "value__"); vr.Value = val; // Required to make sure that var returns an up-to-date value object thisVal.IsValid = false; return; } CorReferenceValue s = thisVal.Val.CastToReferenceValue(); if (s != null) { CorReferenceValue v = val.Val.CastToReferenceValue(); if (v != null) { s.Value = v.Value; return; } } CorGenericValue gv = CorObjectAdaptor.GetRealObject(cctx, thisVal.Val) as CorGenericValue; if (gv != null) { gv.SetValue(ctx.Adapter.TargetObjectToObject(ctx, val)); } }
public override bool HasMember(EvaluationContext ctx, object tt, string memberName, BindingFlags bindingFlags) { CorEvaluationContext cctx = (CorEvaluationContext)ctx; CorType ct = (CorType)tt; while (ct != null) { Type type = ct.GetTypeInfo(cctx.Session); FieldInfo field = type.GetField(memberName, bindingFlags); if (field != null) { return(true); } PropertyInfo prop = type.GetProperty(memberName, bindingFlags); if (prop != null) { MethodInfo getter = prop.CanRead ? prop.GetGetMethod(bindingFlags.HasFlag(BindingFlags.NonPublic)) : null; if (getter != null) { return(true); } } if (bindingFlags.HasFlag(BindingFlags.DeclaredOnly)) { break; } ct = ct.Base; } return(false); }
MethodInfo OverloadResolve(CorEvaluationContext ctx, string methodName, CorType type, CorType[] argtypes, BindingFlags flags, bool throwIfNotFound) { List <MethodInfo> candidates = new List <MethodInfo> (); CorType currentType = type; while (currentType != null) { Type rtype = currentType.GetTypeInfo(ctx.Session); foreach (MethodInfo met in rtype.GetMethods(flags)) { if (met.Name == methodName || (!ctx.CaseSensitive && met.Name.Equals(methodName, StringComparison.CurrentCultureIgnoreCase))) { if (argtypes == null) { return(met); } ParameterInfo[] pars = met.GetParameters(); if (pars.Length == argtypes.Length) { candidates.Add(met); } } } if (methodName == ".ctor") { break; // Can't create objects using constructor from base classes } currentType = currentType.Base; } return(OverloadResolve(ctx, GetTypeName(ctx, type), methodName, argtypes, candidates, throwIfNotFound)); }
protected override IEnumerable <ValueReference> OnGetLocalVariables(EvaluationContext ctx) { CorEvaluationContext wctx = (CorEvaluationContext)ctx; uint offset; CorDebugMappingResult mr; wctx.Frame.GetIP(out offset, out mr); return(GetLocals(wctx, null, (int)offset, false)); }
public override object RuntimeInvoke(EvaluationContext gctx, object gtargetType, object gtarget, string methodName, object[] ggenericArgTypes, object[] gargTypes, object[] gargValues) { // FIXME: support generic methods by using the genericArgTypes parameter CorType targetType = (CorType)gtargetType; CorValRef target = (CorValRef)gtarget; CorType[] argTypes = CastArray <CorType> (gargTypes); CorValRef[] argValues = CastArray <CorValRef> (gargValues); BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic; if (target != null) { flags |= BindingFlags.Instance; } else { flags |= BindingFlags.Static; } CorEvaluationContext ctx = (CorEvaluationContext)gctx; MethodInfo method = OverloadResolve(ctx, methodName, targetType, argTypes, flags, true); ParameterInfo[] parameters = method.GetParameters(); for (int n = 0; n < parameters.Length; n++) { if (parameters[n].ParameterType == typeof(object) && (IsValueType(ctx, argValues[n]))) { argValues[n] = Box(ctx, argValues[n]); } } if (method != null) { CorValRef v = new CorValRef(delegate { CorFunction func = targetType.Class.Module.GetFunctionFromToken(method.MetadataToken); CorValue[] args = new CorValue[argValues.Length]; for (int n = 0; n < args.Length; n++) { args[n] = argValues[n].Val; } return(ctx.RuntimeInvoke(func, new CorType[0], target != null ? target.Val : null, args)); }); if (v.Val == null) { return(null); } else { return(v); } } else { throw new EvaluatorException("Invalid method name or incompatible arguments."); } }
IEnumerable <ValueReference> GetLocals(CorEvaluationContext ctx, ISymbolScope scope, int offset, bool showHidden) { if (ctx.Frame.FrameType != CorFrameType.ILFrame) { yield break; } if (scope == null) { ISymbolMethod met = ctx.Frame.Function.GetSymbolMethod(ctx.Session); if (met != null) { scope = met.RootScope; } else { int count = ctx.Frame.GetLocalVariablesCount(); for (int n = 0; n < count; n++) { int locn = n; CorValRef vref = new CorValRef(delegate { return(ctx.Frame.GetLocalVariable(locn)); }); yield return(new VariableReference(ctx, vref, "local_" + (n + 1), ObjectValueFlags.Variable)); } yield break; } } foreach (ISymbolVariable var in scope.GetLocals()) { if (var.Name == "$site") { continue; } if (var.Name.IndexOfAny(new char[] { '$', '<', '>' }) == -1 || showHidden) { int addr = var.AddressField1; CorValRef vref = new CorValRef(delegate { return(ctx.Frame.GetLocalVariable(addr)); }); yield return(new VariableReference(ctx, vref, var.Name, ObjectValueFlags.Variable)); } } foreach (ISymbolScope cs in scope.GetChildren()) { if (cs.StartOffset <= offset && cs.EndOffset >= offset) { foreach (VariableReference var in GetLocals(ctx, cs, offset, showHidden)) { yield return(var); } } } }
bool IsValueType(CorEvaluationContext ctx, CorValRef val) { CorValue v = GetRealObject(ctx, val); if (v.Type == CorElementType.ELEMENT_TYPE_VALUETYPE) { return(true); } return(v is CorGenericValue); }
public override bool HasMethod(EvaluationContext gctx, object gtargetType, string methodName, object[] gargTypes, BindingFlags flags) { CorType targetType = (CorType)gtargetType; CorType[] argTypes = gargTypes != null?CastArray <CorType> (gargTypes) : null; CorEvaluationContext ctx = (CorEvaluationContext)gctx; flags = flags | BindingFlags.Public | BindingFlags.NonPublic; return(OverloadResolve(ctx, methodName, targetType, argTypes, flags, false) != null); }
public CorValRef GetBoxedArg(CorEvaluationContext ctx, CorValRef val, Type argType) { // Boxes a value when required if (argType == typeof(object) && IsValueType(ctx, val)) { return(Box(ctx, val)); } else { return(val); } }
CorValRef Box(CorEvaluationContext ctx, CorValRef val) { CorValRef arr = new CorValRef(delegate { return(ctx.Session.NewArray(ctx, (CorType)GetValueType(ctx, val), 1)); }); ArrayAdaptor realArr = new ArrayAdaptor(ctx, arr); realArr.SetElement(new int[] { 0 }, val); CorType at = (CorType)GetType(ctx, "System.Array"); object[] argTypes = new object[] { GetType(ctx, "System.Int32") }; return((CorValRef)RuntimeInvoke(ctx, at, arr, "GetValue", argTypes, new object[] { CreateValue(ctx, 0) })); }
IEnumerable <Type> GetAllTypes(EvaluationContext gctx) { CorEvaluationContext ctx = (CorEvaluationContext)gctx; foreach (CorModule mod in ctx.Session.GetModules()) { CorMetadataImport mi = ctx.Session.GetMetadataForModule(mod.Name); if (mi != null) { foreach (Type t in mi.DefinedTypes) { yield return(t); } } } }
public override ValueReference GetIndexerReference(EvaluationContext ctx, object target, object[] indices) { CorEvaluationContext cctx = (CorEvaluationContext)ctx; CorType targetType = GetValueType(ctx, target) as CorType; CorValRef[] values = new CorValRef[indices.Length]; CorType[] types = new CorType[indices.Length]; for (int n = 0; n < indices.Length; n++) { types[n] = (CorType)GetValueType(ctx, indices[n]); values[n] = (CorValRef)indices[n]; } List <MethodInfo> candidates = new List <MethodInfo> (); List <PropertyInfo> props = new List <PropertyInfo> (); List <CorType> propTypes = new List <CorType> (); CorType t = targetType; while (t != null) { Type type = t.GetTypeInfo(cctx.Session); foreach (PropertyInfo prop in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { MethodInfo mi = null; try { mi = prop.CanRead ? prop.GetGetMethod() : null; } catch { // Ignore } if (mi != null && mi.GetParameters().Length > 0) { candidates.Add(mi); props.Add(prop); propTypes.Add(t); } } t = t.Base; } MethodInfo idx = OverloadResolve(cctx, GetTypeName(ctx, targetType), null, types, candidates, true); int i = candidates.IndexOf(idx); return(new PropertyReference(ctx, props[i], (CorValRef)target, propTypes[i], values)); }
public CorValue NewArray(CorEvaluationContext ctx, CorType elemType, int size) { ManualResetEvent doneEvent = new ManualResetEvent(false); CorValue result = null; EvalEventHandler completeHandler = delegate(object o, CorEvalEventArgs eargs) { OnEndEvaluating(); result = eargs.Eval.Result; doneEvent.Set(); eargs.Continue = false; }; EvalEventHandler exceptionHandler = delegate(object o, CorEvalEventArgs eargs) { OnEndEvaluating(); result = eargs.Eval.Result; doneEvent.Set(); eargs.Continue = false; }; try { process.OnEvalComplete += completeHandler; process.OnEvalException += exceptionHandler; ctx.Eval.NewParameterizedArray(elemType, 1, 1, 0); process.SetAllThreadsDebugState(CorDebugThreadState.THREAD_SUSPEND, ctx.Thread); OnStartEvaluating(); ClearEvalStatus(); process.Continue(false); if (doneEvent.WaitOne(ctx.Options.EvaluationTimeout, false)) { return(result); } else { return(null); } } finally { process.OnEvalComplete -= completeHandler; process.OnEvalException -= exceptionHandler; } }
string EvaluateExpression(CorThread thread, string exp) { try { if (thread.ActiveFrame == null) { return(string.Empty); } EvaluationOptions ops = Options.EvaluationOptions; ops.AllowTargetInvoke = true; CorEvaluationContext ctx = new CorEvaluationContext(this, new CorBacktrace(thread, this), 0, ops); ctx.Thread = thread; ValueReference val = ctx.Evaluator.Evaluate(ctx, exp); return(val.CreateObjectValue(false).Value); } catch (Exception ex) { OnDebuggerOutput(true, ex.ToString()); return(string.Empty); } }
public override object GetEnclosingType(EvaluationContext gctx) { CorEvaluationContext ctx = (CorEvaluationContext)gctx; if (ctx.Frame.FrameType != CorFrameType.ILFrame || ctx.Frame.Function == null) { return(null); } CorClass cls = ctx.Frame.Function.Class; List <CorType> tpars = new List <CorType> (); foreach (CorType t in ctx.Frame.TypeParameters) { tpars.Add(t); } return(cls.GetParameterizedType(CorElementType.ELEMENT_TYPE_CLASS, tpars.ToArray())); }
protected override IEnumerable <ValueReference> OnGetParameters(EvaluationContext gctx) { CorEvaluationContext ctx = (CorEvaluationContext)gctx; if (ctx.Frame.FrameType == CorFrameType.ILFrame && ctx.Frame.Function != null) { MethodInfo met = ctx.Frame.Function.GetMethodInfo(ctx.Session); if (met != null) { foreach (ParameterInfo pi in met.GetParameters()) { int pos = pi.Position; if (met.IsStatic) { pos--; } CorValRef vref = null; try { vref = new CorValRef(delegate { return(ctx.Frame.GetArgument(pos)); }); } catch (Exception /*ex*/) { } if (vref != null) { yield return(new VariableReference(ctx, vref, pi.Name, ObjectValueFlags.Parameter)); } } yield break; } } int count = ctx.Frame.GetArgumentCount(); for (int n = 0; n < count; n++) { int locn = n; CorValRef vref = new CorValRef(delegate { return(ctx.Frame.GetArgument(locn)); }); yield return(new VariableReference(ctx, vref, "arg_" + (n + 1), ObjectValueFlags.Parameter)); } }
public override IEnumerable <EnumMember> GetEnumMembers(EvaluationContext ctx, object tt) { CorType t = (CorType)tt; CorEvaluationContext cctx = (CorEvaluationContext)ctx; Type type = t.GetTypeInfo(cctx.Session); foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.Static)) { if (field.IsLiteral && field.IsStatic) { object val = field.GetValue(null); EnumMember em = new EnumMember(); em.Value = (long)System.Convert.ChangeType(val, typeof(long)); em.Name = field.Name; yield return(em); } } }
public override ValueReference GetCurrentException(EvaluationContext ctx) { CorEvaluationContext wctx = (CorEvaluationContext)ctx; CorValue exception = wctx.Thread.CurrentException; if (exception != null) { CorHandleValue exceptionHandle = wctx.Session.GetHandle(exception); CorValRef vref = new CorValRef(delegate { return(exceptionHandle); }); return(new VariableReference(ctx, vref, "__EXCEPTION_OBJECT__", ObjectValueFlags.Variable)); } else { return(base.GetCurrentException(ctx)); } }
protected override IEnumerable <ValueReference> GetMembers(EvaluationContext ctx, object tt, object gval, BindingFlags bindingFlags) { CorType t = (CorType)tt; CorValRef val = (CorValRef)gval; if (t.Class == null) { yield break; } CorEvaluationContext cctx = (CorEvaluationContext)ctx; while (t != null) { Type type = t.GetTypeInfo(cctx.Session); foreach (FieldInfo field in type.GetFields(bindingFlags)) { yield return(new FieldReference(ctx, val, t, field)); } foreach (PropertyInfo prop in type.GetProperties(bindingFlags)) { MethodInfo mi = null; try { mi = prop.CanRead ? prop.GetGetMethod() : null; } catch { // Ignore } if (mi != null && mi.GetParameters().Length == 0) { yield return(new PropertyReference(ctx, prop, val, t)); } } if ((bindingFlags & BindingFlags.DeclaredOnly) != 0) { break; } t = t.Base; } }
public override object TargetObjectToObject(EvaluationContext ctx, object objr) { CorValue obj = GetRealObject(ctx, objr); if ((obj is CorReferenceValue) && ((CorReferenceValue)obj).IsNull) { return(new EvaluationResult("(null)")); } CorStringValue stringVal = obj as CorStringValue; if (stringVal != null) { return(stringVal.String); } CorArrayValue arr = obj as CorArrayValue; if (arr != null) { return(base.TargetObjectToObject(ctx, objr)); } CorEvaluationContext cctx = (CorEvaluationContext)ctx; CorObjectValue co = obj as CorObjectValue; if (co != null) { return(base.TargetObjectToObject(ctx, objr)); } CorGenericValue genVal = obj as CorGenericValue; if (genVal != null) { return(genVal.GetValue()); } return(base.TargetObjectToObject(ctx, objr)); }
bool IsAssignableFrom(CorEvaluationContext ctx, Type baseType, CorType ctype) { string tname = baseType.FullName; string ctypeName = GetTypeName(ctx, ctype); if (tname == "System.Object") { return(true); } if (tname == ctypeName) { return(true); } if (CorMetadataImport.CoreTypes.ContainsKey(ctype.Type)) { return(false); } switch (ctype.Type) { case CorElementType.ELEMENT_TYPE_ARRAY: case CorElementType.ELEMENT_TYPE_SZARRAY: case CorElementType.ELEMENT_TYPE_BYREF: case CorElementType.ELEMENT_TYPE_PTR: return(false); } while (ctype != null) { if (GetTypeName(ctx, ctype) == tname) { return(true); } ctype = ctype.Base; } return(false); }
protected override ValueReference OnGetThisReference(EvaluationContext gctx) { CorEvaluationContext ctx = (CorEvaluationContext)gctx; if (ctx.Frame.FrameType != CorFrameType.ILFrame || ctx.Frame.Function == null) { return(null); } MethodInfo mi = ctx.Frame.Function.GetMethodInfo(ctx.Session); if (mi == null || mi.IsStatic) { return(null); } CorValRef vref = new CorValRef(delegate { return(ctx.Frame.GetArgument(0)); }); return(new VariableReference(ctx, vref, "this", ObjectValueFlags.Variable | ObjectValueFlags.ReadOnly)); }
public override object CreateValue(EvaluationContext gctx, object value) { CorEvaluationContext ctx = (CorEvaluationContext)gctx; if (value is string) { return(new CorValRef(delegate { return ctx.Session.NewString(ctx, (string)value); })); } foreach (KeyValuePair <CorElementType, Type> tt in CorMetadataImport.CoreTypes) { if (tt.Value == value.GetType()) { CorValue val = ctx.Eval.CreateValue(tt.Key, null); CorGenericValue gv = val.CastToGenericValue(); gv.SetValue(value); return(new CorValRef(val)); } } throw new NotSupportedException(); }
public override object GetType(EvaluationContext gctx, string name, object[] gtypeArgs) { CorType[] typeArgs = CastArray <CorType> (gtypeArgs); CorEvaluationContext ctx = (CorEvaluationContext)gctx; foreach (CorModule mod in ctx.Session.GetModules()) { CorMetadataImport mi = ctx.Session.GetMetadataForModule(mod.Name); if (mi != null) { foreach (Type t in mi.DefinedTypes) { if (t.FullName == name) { CorClass cls = mod.GetClassFromToken(t.MetadataToken); return(cls.GetParameterizedType(CorElementType.ELEMENT_TYPE_CLASS, typeArgs)); } } } } return(null); }
protected override EvaluationContext GetEvaluationContext (int frameIndex, EvaluationOptions options) { CorEvaluationContext ctx = new CorEvaluationContext (session, this, frameIndex, options); ctx.Thread = thread; return ctx; }
public ArrayAdaptor(EvaluationContext ctx, CorValRef obj, CorArrayValue array) { this.ctx = (CorEvaluationContext)ctx; this.array = array; this.obj = obj; }
public ArrayAdaptor (EvaluationContext ctx, CorValRef obj, CorArrayValue array) { this.ctx = (CorEvaluationContext) ctx; this.array = array; this.obj = obj; }
string EvaluateExpression (CorThread thread, string exp) { try { if (thread.ActiveFrame == null) return string.Empty; EvaluationOptions ops = Options.EvaluationOptions.Clone (); ops.AllowTargetInvoke = true; CorEvaluationContext ctx = new CorEvaluationContext (this, new CorBacktrace (thread, this), 0, ops); ctx.Thread = thread; ValueReference val = ctx.Evaluator.Evaluate (ctx, exp); return val.CreateObjectValue (false).Value; } catch (Exception ex) { OnDebuggerOutput (true, ex.ToString ()); return string.Empty; } }
public CorValue RuntimeInvoke (CorEvaluationContext ctx, CorFunction function, CorType[] typeArgs, CorValue thisObj, CorValue[] arguments) { if (!ctx.Thread.ActiveChain.IsManaged) throw new EvaluatorException ("Cannot evaluate expression because the thread is stopped in native code."); CorValue[] args; if (thisObj == null) args = arguments; else { args = new CorValue[arguments.Length + 1]; args[0] = thisObj; arguments.CopyTo (args, 1); } CorMethodCall mc = new CorMethodCall (); CorValue exception = null; CorEval eval = ctx.Eval; EvalEventHandler completeHandler = delegate (object o, CorEvalEventArgs eargs) { OnEndEvaluating (); mc.DoneEvent.Set (); eargs.Continue = false; }; EvalEventHandler exceptionHandler = delegate (object o, CorEvalEventArgs eargs) { OnEndEvaluating (); exception = eargs.Eval.Result; mc.DoneEvent.Set (); eargs.Continue = false; }; process.OnEvalComplete += completeHandler; process.OnEvalException += exceptionHandler; mc.OnInvoke = delegate { if (function.GetMethodInfo (this).Name == ".ctor") eval.NewParameterizedObject (function, typeArgs, args); else eval.CallParameterizedFunction (function, typeArgs, args); process.SetAllThreadsDebugState (CorDebugThreadState.THREAD_SUSPEND, ctx.Thread); ClearEvalStatus (); OnStartEvaluating (); process.Continue (false); }; mc.OnAbort = delegate { eval.Abort (); }; mc.OnGetDescription = delegate { System.Reflection.MethodInfo met = function.GetMethodInfo (ctx.Session); if (met != null) return met.Name; else return "<Unknown>"; }; try { ObjectAdapter.AsyncExecute (mc, ctx.Options.EvaluationTimeout); } finally { process.OnEvalComplete -= completeHandler; process.OnEvalException -= exceptionHandler; } if (exception != null) { /* ValueReference<CorValue, CorType> msg = ctx.Adapter.GetMember (ctx, val, "Message"); if (msg != null) { string s = msg.ObjectValue as string; mc.ExceptionMessage = s; } else mc.ExceptionMessage = "Evaluation failed.";*/ CorValRef vref = new CorValRef (exception); throw new EvaluatorException ("Evaluation failed: " + ObjectAdapter.GetValueTypeName (ctx, vref)); } return eval.Result; }
public CorValue RuntimeInvoke(CorEvaluationContext ctx, CorFunction function, CorType[] typeArgs, CorValue thisObj, CorValue[] arguments) { if (!ctx.Thread.ActiveChain.IsManaged) { throw new EvaluatorException("Cannot evaluate expression because the thread is stopped in native code."); } CorValue[] args; if (thisObj == null) { args = arguments; } else { args = new CorValue[arguments.Length + 1]; args[0] = thisObj; arguments.CopyTo(args, 1); } CorMethodCall mc = new CorMethodCall(); CorValue exception = null; CorEval eval = ctx.Eval; EvalEventHandler completeHandler = delegate(object o, CorEvalEventArgs eargs) { OnEndEvaluating(); mc.DoneEvent.Set(); eargs.Continue = false; }; EvalEventHandler exceptionHandler = delegate(object o, CorEvalEventArgs eargs) { OnEndEvaluating(); exception = eargs.Eval.Result; mc.DoneEvent.Set(); eargs.Continue = false; }; process.OnEvalComplete += completeHandler; process.OnEvalException += exceptionHandler; mc.OnInvoke = delegate { if (function.GetMethodInfo(this).Name == ".ctor") { eval.NewParameterizedObject(function, typeArgs, args); } else { eval.CallParameterizedFunction(function, typeArgs, args); } process.SetAllThreadsDebugState(CorDebugThreadState.THREAD_SUSPEND, ctx.Thread); ClearEvalStatus(); OnStartEvaluating(); process.Continue(false); }; mc.OnAbort = delegate { eval.Abort(); }; mc.OnGetDescription = delegate { System.Reflection.MethodInfo met = function.GetMethodInfo(ctx.Session); if (met != null) { return(met.Name); } else { return("<Unknown>"); } }; try { ObjectAdapter.AsyncExecute(mc, ctx.Options.EvaluationTimeout); } finally { process.OnEvalComplete -= completeHandler; process.OnEvalException -= exceptionHandler; } if (exception != null) { /* ValueReference<CorValue, CorType> msg = ctx.Adapter.GetMember (ctx, val, "Message"); * if (msg != null) { * string s = msg.ObjectValue as string; * mc.ExceptionMessage = s; * } * else * mc.ExceptionMessage = "Evaluation failed.";*/ CorValRef vref = new CorValRef(exception); throw new EvaluatorException("Evaluation failed: " + ObjectAdapter.GetValueTypeName(ctx, vref)); } return(eval.Result); }
public StringAdaptor (EvaluationContext ctx, CorValRef obj, CorStringValue str) { this.ctx = (CorEvaluationContext) ctx; this.str = str; this.obj = obj; }
public CorValue NewArray (CorEvaluationContext ctx, CorType elemType, int size) { ManualResetEvent doneEvent = new ManualResetEvent (false); CorValue result = null; EvalEventHandler completeHandler = delegate (object o, CorEvalEventArgs eargs) { OnEndEvaluating (); result = eargs.Eval.Result; doneEvent.Set (); eargs.Continue = false; }; EvalEventHandler exceptionHandler = delegate (object o, CorEvalEventArgs eargs) { OnEndEvaluating (); result = eargs.Eval.Result; doneEvent.Set (); eargs.Continue = false; }; try { process.OnEvalComplete += completeHandler; process.OnEvalException += exceptionHandler; ctx.Eval.NewParameterizedArray (elemType, 1, 1, 0); process.SetAllThreadsDebugState (CorDebugThreadState.THREAD_SUSPEND, ctx.Thread); OnStartEvaluating (); ClearEvalStatus (); process.Continue (false); if (doneEvent.WaitOne (ctx.Options.EvaluationTimeout, false)) return result; else return null; } finally { process.OnEvalComplete -= completeHandler; process.OnEvalException -= exceptionHandler; } }
public ArrayAdaptor (EvaluationContext ctx, CorValRef obj) { this.obj = obj; this.ctx = (CorEvaluationContext) ctx; }