/// <summary> /// Uses reflection to create new instance of the appropriate ReflectedCaller /// </summary> private static CallInstruction SlowCreate(MethodInfo info, ParameterInfo[] pis) { List <Type> types = new List <Type>(); if (!info.IsStatic) { types.Add(info.DeclaringType !); } foreach (ParameterInfo pi in pis) { types.Add(pi.ParameterType); } if (info.ReturnType != typeof(void)) { types.Add(info.ReturnType); } Type[] arrTypes = types.ToArray(); try { return((CallInstruction)Activator.CreateInstance(GetHelperType(info, arrTypes), info) !); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } }
public sealed override int Run(InterpretedFrame frame) { var first = frame.StackIndex - ArgumentCount; var args = GetArgs(frame, first); try { object ret; try { ret = Constructor.Invoke(args); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } frame.Data[first] = ret; frame.StackIndex = first + 1; } finally { foreach (var arg in _byrefArgs) { arg.Update(frame, args[arg.ArgumentIndex]); } } return(1); }
public override int Run(InterpretedFrame frame) { int first = frame.StackIndex - _argumentCount; object ret; if (_target.IsStatic) { object[] args = GetArgs(frame, first, 0); try { ret = _target.Invoke(null, args); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } } else { object instance = frame.Data[first]; NullCheck(instance); object[] args = GetArgs(frame, first, 1); 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) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } } } if (_target.ReturnType != typeof(void)) { frame.Data[first] = ret; frame.StackIndex = first + 1; } else { frame.StackIndex = first; } return(1); }
public override void Update(InterpretedFrame frame, object?value) { var obj = _object == null ? null : frame.Data[_object.GetValueOrDefault().Index]; try { _property.SetValue(obj, value); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } }
public override int Run(InterpretedFrame frame) { try { frame.Data[Index] = Activator.CreateInstance(_type); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } return(1); }
public override int Run(InterpretedFrame frame) { object value; try { value = Activator.CreateInstance(_type); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } frame.Data[Index] = new StrongBox <object>(value); return(1); }
public override int Run(InterpretedFrame frame) { var first = frame.StackIndex - ArgumentCount; var args = GetArgs(frame, first); object ret; try { ret = Constructor.Invoke(args); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } frame.Data[first] = ret; frame.StackIndex = first + 1; return(1); }
public override void Update(InterpretedFrame frame, object?value) { var args = new object?[_args.Length + 1]; for (var i = 0; i < args.Length - 1; i++) { args[i] = frame.Data[_args[i].Index]; } args[args.Length - 1] = value; var instance = _obj == null ? null : frame.Data[_obj.GetValueOrDefault().Index]; try { _indexer.Invoke(instance, args); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } }
public sealed override int Run(InterpretedFrame frame) { int first = frame.StackIndex - _argumentCount; object?[]? args = null; object? instance = null; try { object?ret; if (_target.IsStatic) { args = GetArgs(frame, first, 0); try { ret = _target.Invoke(null, args); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } } else { instance = frame.Data[first]; NullCheck(instance); args = GetArgs(frame, first, 1); if (TryGetLightLambdaTarget(instance, out LightLambda? targetLambda)) { // no need to Invoke, just interpret the lambda body ret = InterpretLambdaInvoke(targetLambda, args); } else { try { ret = _target.Invoke(instance, args); } catch (TargetInvocationException e) { ExceptionHelpers.UnwrapAndRethrow(e); throw ContractUtils.Unreachable; } } } if (_target.ReturnType != typeof(void)) { frame.Data[first] = ret; frame.StackIndex = first + 1; } else { frame.StackIndex = first; } } finally { if (args != null) { foreach (ByRefUpdater arg in _byrefArgs) { // -1: instance param, just copy back the exact instance invoked with, which // gets passed by reference from reflection for value types. arg.Update(frame, arg.ArgumentIndex == -1 ? instance : args[arg.ArgumentIndex]); } } } return(1); }