private object InvokeWorker(params object[] args) { if (_target.IsStatic) { try { return(_target.Invoke(null, args)); } catch (TargetInvocationException e) { throw ExceptionHelpers.UpdateForRethrow(e.InnerException); } } LightLambda targetLambda; if (TryGetLightLambdaTarget(args[0], out targetLambda)) { // no need to Invoke, just interpret the lambda body return(InterpretLambdaInvoke(targetLambda, SkipFirstArg(args))); } try { return(_target.Invoke(args[0], SkipFirstArg(args))); } catch (TargetInvocationException e) { throw ExceptionHelpers.UpdateForRethrow(e.InnerException); } }
public override int Run(InterpretedFrame frame) { try { frame.Data[Index] = Activator.CreateInstance(_type); } catch (TargetInvocationException e) { ExceptionHelpers.UpdateForRethrow(e.InnerException); throw e.InnerException; } return(1); }
public sealed override int Run(InterpretedFrame frame) { var first = frame.StackIndex - _argumentCount; object[] args = null; object instance = null; try { object ret; if (_target.IsStatic) { args = new object[_argumentCount]; for (var i = 0; i < args.Length; i++) { args[i] = frame.Data[first + i]; } try { ret = _target.Invoke(null, args); } catch (TargetInvocationException e) { throw ExceptionHelpers.UpdateForRethrow(e.InnerException); } } else { args = new object[_argumentCount - 1]; for (var i = 0; i < args.Length; i++) { args[i] = frame.Data[first + i + 1]; } instance = frame.Data[first]; LightLambda targetLambda; if (TryGetLightLambdaTarget(instance, out targetLambda)) { // no need to Invoke, just interpret the lambda body ret = InterpretLambdaInvoke(targetLambda, args); } else { try { ret = _target.Invoke(instance, args); } catch (TargetInvocationException e) { throw ExceptionHelpers.UpdateForRethrow(e.InnerException); } } } if (_target.ReturnType != typeof(void)) { frame.Data[first] = ret; frame.StackIndex = first + 1; } else { frame.StackIndex = first; } } finally { if (args != null) { foreach (var arg in _byrefArgs) { if (arg.ArgumentIndex == -1) { // instance param, just copy back the exact instance invoked with, which // gets passed by reference from reflection for value types. arg.Update(frame, instance); } else { arg.Update(frame, args[arg.ArgumentIndex]); } } } } return(1); }