コード例 #1
0
        private object InvokeWorker(params object[] args)
        {
            if (_target.IsStatic)
            {
                try
                {
                    return(_target.Invoke(null, args));
                }
                catch (TargetInvocationException e)
                {
                    throw ExceptionHelpers.UpdateForRethrow(e.InnerException);
                }
            }

            try
            {
                return(_target.Invoke(args[0], GetNonStaticArgs(args)));
            }
            catch (TargetInvocationException e)
            {
                throw ExceptionHelpers.UpdateForRethrow(e.InnerException);
            }
        }
コード例 #2
0
ファイル: NewInstruction.cs プロジェクト: rsumner31/corefx2
        public override int Run(InterpretedFrame frame)
        {
            int first = frame.StackIndex - _argumentCount;

            object[] 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);
        }
コード例 #3
0
        public override object InvokeInstance(object instance, params object[] args)
        {
            if (_target.IsStatic)
            {
                try
                {
                    return(_target.Invoke(null, args));
                }
                catch (TargetInvocationException e)
                {
                    throw ExceptionHelpers.UpdateForRethrow(e.InnerException);
                }
            }

            try
            {
                return(_target.Invoke(instance, args));
            }
            catch (TargetInvocationException e)
            {
                throw ExceptionHelpers.UpdateForRethrow(e.InnerException);
            }
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
        public override int Run(InterpretedFrame frame)
        {
            int first = frame.StackIndex - _argumentCount;

            object[] args = GetArgs(frame, first);

            object ret;

            try
            {
                ret = _constructor.Invoke(args);
            }
            catch (TargetInvocationException e)
            {
                ExceptionHelpers.UpdateForRethrow(e.InnerException);
                throw e.InnerException;
            }

            frame.Data[first] = ret;
            frame.StackIndex  = first + 1;

            return(+1);
        }
コード例 #6
0
        /// <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;
            }
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }