Пример #1
0
        /// <summary>
        /// The reflective method for invoking methods. See documentation for RealProxy.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage message)
        {
            // Convert to a MethodCallMessage
            System.Runtime.Remoting.Messaging.IMethodCallMessage methodMessage = new System.Runtime.Remoting.Messaging.MethodCallMessageWrapper((System.Runtime.Remoting.Messaging.IMethodCallMessage)message);

            // Extract the method being called
            System.Reflection.MethodBase method = methodMessage.MethodBase;

            // Perform the call
            object returnValue = null;

            if (method.DeclaringType == typeof(IDynamicProxy))
            {
                // Handle IDynamicProxy interface calls on this instance instead of on the proxy target instance
                returnValue = method.Invoke(this, methodMessage.Args);
            }
            else
            {
                // Delegate to the invocation handler
                returnValue = invocationHandler(proxyTarget, method, methodMessage.Args);
            }

            // Create the return message (ReturnMessage)
            System.Runtime.Remoting.Messaging.ReturnMessage returnMessage = new System.Runtime.Remoting.Messaging.ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage);
            return(returnMessage);
        }
        /// <summary>
        /// 用于调用方法的反射方法。有关realproxy,请参阅文档。
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage message)
        {
            // 转换为 MethodCallMessage
            System.Runtime.Remoting.Messaging.IMethodCallMessage methodMessage = new System.Runtime.Remoting.Messaging.MethodCallMessageWrapper((System.Runtime.Remoting.Messaging.IMethodCallMessage)message);

            // 提取正在调用的方法
            System.Reflection.MethodBase method = methodMessage.MethodBase;

            // 执行 call
            object returnValue = null;

            if (method.DeclaringType == typeof(IDynamicProxy))
            {
                // 处理此实例而不是代理目标实例上的IDynamicProxy接口调用
                returnValue = method.Invoke(this, methodMessage.Args);
            }
            else
            {
                // 委托给调用处理程序
                returnValue = invocationHandler(proxyTarget, method, methodMessage.Args);
            }

            // 创建返回消息 (ReturnMessage)
            System.Runtime.Remoting.Messaging.ReturnMessage returnMessage = new System.Runtime.Remoting.Messaging.ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage);
            return(returnMessage);
        }
Пример #3
0
 /// <summary>
 /// Safe compiler invoke for exceptions
 /// </summary>
 /// <param name="exp">Invoking expression</param>
 /// <param name="method">method to Invoke</param>
 /// <param name="target">method target</param>
 /// <param name="parmeters">parameters for invoke</param>
 /// <returns>result of invoke</returns>
 public static object SafeInvoke(Expression exp, System.Reflection.MethodBase method, object target, object[] parmeters)
 {
     try
     {
         return(method.Invoke(target, System.Reflection.BindingFlags.Default, null, parmeters, null));
     }
     catch (System.Reflection.TargetInvocationException)
     {
         throw ExecutionException.ThrowInvalidOp(exp);
     }
     catch (ArgumentException ex)
     {
         throw ExecutionException.ThrowInvalidOp(exp, new NameExpression(ex.ParamName, ExpressionType.Identifier));
     }
     catch (System.Reflection.TargetParameterCountException)
     {
         throw ExecutionException.ThrowArgumentMisMatch(exp);
     }
 }
Пример #4
0
            public override bool Rewrite(CodeDescriptor decompilee, System.Reflection.MethodBase callee, Analysis.StackElement[] args, Analysis.IDecompiler stack, IFunctionBuilder builder)
            {
                Array arr = (Array)args[0].Sample;

                if (arr == null)
                {
                    throw new InvalidOperationException("Unable to deduce array length");
                }

                int  numElems = arr.Length;
                Type tTE      = arr.GetType().GetElementType();
                Type tTA;

                callee.IsFunction(out tTA);
                FunctionCall      newCall = IntrinsicFunctions.NewArray(tTE, LiteralReference.CreateConstant(numElems), arr);
                FunctionSpec      fspec   = (FunctionSpec)newCall.Callee;
                IntrinsicFunction ifun    = fspec.IntrinsicRep;
                ArrayParams       aparams = (ArrayParams)ifun.Parameter;

                for (int i = 0; i < numElems; i++)
                {
                    aparams.Elements[i] = IntrinsicFunctions.GetArrayElement(
                        args[0].Expr,
                        LiteralReference.CreateConstant(i));
                }

                object sample = null;

                try
                {
                    sample = callee.Invoke(arr);
                }
                catch (Exception)
                {
                }

                Expression conv = IntrinsicFunctions.Cast(newCall, arr.GetType(), tTA);

                stack.Push(conv, sample);
                return(true);
            }
 public override void Execute(T e)
 {
     method.Invoke(eventListener, new object[] { e });
 }
Пример #6
0
        static public void CustomAssert(bool condition, string assertString, bool pauseOnFail = false)
        {
            if (!condition)
            {
                System.Text.StringBuilder       message     = new System.Text.StringBuilder();
                System.Diagnostics.StackTrace   stackTrace  = new System.Diagnostics.StackTrace(true);
                System.Diagnostics.StackFrame[] stackFrames = stackTrace.GetFrames();
                int    line       = 0;
                string file       = "";
                int    col        = 0;
                bool   foundStart = false;

                //message.Append("<color=white>");
                message.Append(assertString);
                //message.Append("</color>");
                message.Append("\n");

                for (int i = 0; i < stackFrames.Length; i++)
                {
                    System.Reflection.MethodBase mb = stackFrames[i].GetMethod();
                    if (!foundStart && mb.DeclaringType != typeof(PrintSystem))
                    {
                        file       = formatFileName(stackFrames[i].GetFileName());
                        line       = stackFrames[i].GetFileLineNumber();
                        col        = stackFrames[i].GetFileColumnNumber();
                        foundStart = true;
                    }

                    if (foundStart)
                    {
                        //message.Append(mb.DeclaringType.FullName);
                        message.Append(mb.DeclaringType.Namespace);
                        message.Append(".");
                        message.Append(mb.DeclaringType.Name);
                        message.Append(":");
                        message.Append(mb.Name);
                        message.Append("(");
                        if (showParameters)
                        {
                            System.Reflection.ParameterInfo[] paramters = mb.GetParameters();
                            for (int k = 0; k < paramters.Length; k++)
                            {
                                message.Append(paramters[k].ParameterType.Name);
                                if (k + 1 < paramters.Length)
                                {
                                    message.Append(", ");
                                }
                            }
                        }

                        message.Append(")");

                        message.Append(" (at ");

                        message.Append(formatFileName(stackFrames[i].GetFileName()));
                        message.Append(":");
                        message.Append(stackFrames[i].GetFileLineNumber());
                        message.Append(")");
                        message.Append("\n");
                    }
                }
                unityLog = typeof(UnityEngine.Debug).GetMethod("LogPlayerBuildError",
                                                               System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
                unityLog.Invoke(null, new object[] { message.ToString(), file, line, col });

                if (pauseOnFail)
                {
                    Debug.Break();
                }
            }
        }
Пример #7
0
 public static void Invoke(this System.Reflection.MethodBase method, object obj, params object[] args)
 {
     method.Invoke(obj, args);
 }
Пример #8
0
 public static TResult Invoke <TResult>(this System.Reflection.MethodBase method, object obj, params object[] args)
 {
     return((TResult)method.Invoke(obj, args));
 }