/// <summary>
 /// 执行方法
 /// </summary>
 /// <param name="customMethodInfo">方法的详细信息</param>
 /// <returns></returns>
 public object ExecMethod(CustomMethodInfo customMethodInfo)
 {
     object ret = null;
     try
     {
         ParameterHelper parameterHelper = new ParameterHelper(this._httpRequestDescription.WebParameters);
         //得到了方法中参数的值
         object[] args = parameterHelper.GetParameterValues(customMethodInfo.ParamterInfos);
         //动态执行方法
         ret = customMethodInfo.Method.Invoke(customMethodInfo.Instance, args);
     }
     catch {
         throw;
     }
     return ret;
 }
Exemple #2
0
        /// <summary>
        /// 执行方法
        /// </summary>
        /// <returns></returns>
        public object ExecMethod()
        {
            object ret = null;//返回值
            object newInstance = null;//新实例
            try
            {
                ParameterHelper parameterHelper = new ParameterHelper(this._httpRequestDescription);
                //得到了方法中参数的值
                object[] args = parameterHelper.GetParameterValues(this.CurCustomMethodInfo.ParamterInfos);

                newInstance = this.CurCustomMethodInfo.ClassType.CreateInstace();
                //动态执行方法 这里会 新创建一个实例
                ret = this.CurCustomMethodInfo.Method.Invoke(newInstance, args);

            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    //如果捕获到的异常有内部错误,则抛出此内部错误
                    ex=ex.InnerException;
                }
                //否则直接抛异常错误
                ret = ex;
                throw ex;
            }
            finally {
                //指定了调用方法的回调
                if (InvokeMethodCallback.InvokeCallbackEventHandler != null)
                {
                    //指定该回调
                    InvokeMethodCallback.InvokeCallbackEventHandler(ret, this._context);
                }

                if (newInstance is IAjax)
                {
                    //将当前新实例给释放掉
                    (newInstance as IAjax).Dispose();
                }
            }
            return ret;
        }