Пример #1
0
        private void WriteAjaxMethods(Type ajaxType)
        {
            Dictionary <string, AsyncMethodInfo> ajaxMethods = AjaxMethodHelper.GetAjaxMethods(ajaxType);
            List <AjaxMethodInfo> methodInfoList             = new List <AjaxMethodInfo>();
            List <string>         paramList = new List <string>();

            foreach (string key in ajaxMethods.Keys)
            {
                paramList.Clear();
                AjaxMethodInfo methodInfo = new AjaxMethodInfo();
                methodInfo.Name = key;
                foreach (ParameterInfo pi in ajaxMethods[key].Method.GetParameters())
                {
                    paramList.Add(pi.Name);
                }

                methodInfo.Async     = ajaxMethods[key].Async;
                methodInfo.Paramters = paramList.ToArray();
                methodInfoList.Add(methodInfo);
            }

            WriteToBuffer(methodInfoList.ToArray());
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="invokeObject"></param>
        /// <param name="MethodName"></param>
        /// <returns></returns>
        private AjaxCallbackParam InvokeMethod(object invokeObject, string MethodName)
        {
            var ajaxMethods = AjaxMethodHelper.GetAjaxMethods(invokeObject.GetType());

            if (ajaxMethods.ContainsKey(MethodName))
            {
                var parameters = ajaxMethods[MethodName].Method.GetParameters();
                var plist      = new List <object>();
                foreach (var p in parameters)
                {
                    object obj = GetObject(p.ParameterType, p.Name);
                    plist.Add(obj);
                }

                var    method  = ajaxMethods[MethodName].Method;
                var    handler = DynamicCalls.GetMethodInvoker(method);
                object value   = handler.Invoke(invokeObject, plist.ToArray());
                return(new AjaxCallbackParam(value));
            }
            else
            {
                throw new AjaxException(string.Format("未找到服务器端方法{0}!", MethodName));
            }
        }