private static void OutputResponse(JsRequest r) { string output = r.ToJson(); HttpContext.Current.Response.Write(output); }
private void HandleJsRequest(JsRequest r) { if (r == null) { return; } Type type = this.GetType(); ParameterInfo currentParameterInfo = null; MethodInfo currentMethod = null; for (int i = 0; i < r.Methods.Count; i++) { Method m = r.Methods[i]; if (m != null) { try { MethodInfo mi = type.GetMethod(m.Name, BindingFlags.Public | BindingFlags.Instance); currentMethod = mi; if (mi != null && mi.IsPublic) { object[] args = m.ToArray(); ParameterInfo[] pis = mi.GetParameters(); if (pis != null) { if (pis.Length == 1 && args.Length > 1) { args = new object[] { args }; } for (int ii = 0; ii < pis.Length; ii++) { ParameterInfo pi = pis[ii]; currentParameterInfo = pi; Type ptype = pi.ParameterType; args[ii] = Convert.ChangeType(args[ii], ptype); } } if (mi.ReturnType != typeof(void)) { m.MethodReturnValue = mi.Invoke(this, args); } else { mi.Invoke(this, args); } } } catch (ArgumentNullException err) { ErrorHandler.Handle(err); HandleInvalidInputException(currentParameterInfo, m); } catch (InvalidCastException err) { ErrorHandler.Handle(err); HandleInvalidInputException(currentParameterInfo, m); } catch (FormatException err) { ErrorHandler.Handle(err); HandleInvalidInputException(currentParameterInfo, m); } catch (TargetInvocationException err) { Exception innerException = ErrorHandler.Handle(err); if (innerException is CustomException) { HandleUnknownException(m, ErrorHandler.Handle(err)); } else if (!(innerException is IgnorableException)) { HandleInvokeException(currentMethod, m); } } catch (Exception err) { HandleUnknownException(m, err); } } } string output = r.ToJson(); Response.Write(output); }