private object ExecuteAnonymousMethod(RestControllerMethodInfo info, HttpRequest request) { var instantiator = InstanceCreatorCache.Default.GetCreator(info.MethodInfo.DeclaringType); object bodyObj = null; try { bodyObj = _bodySerializer.FromBody(request.Content, request.RequestContentType, info.BodyParameterType); } catch (JsonReaderException) { return _responseFactory.CreateBadRequest(); } catch (InvalidOperationException) { return _responseFactory.CreateBadRequest(); } object[] parameters = null; try { parameters = info.GetParametersFromUri(request.Uri).Concat(new[] { bodyObj }).ToArray(); } catch (FormatException) { return _responseFactory.CreateBadRequest(); } return info.MethodInfo.Invoke( instantiator.Create(info.MethodInfo.DeclaringType, info.ControllerConstructorArgs()), parameters); }
public async Task<IRestResponse> ExecuteMethodAsync(RestControllerMethodInfo info, HttpRequest request) { var methodInvokeResult = ExecuteAnonymousMethod(info, request); if (!info.IsAsync) return (IRestResponse)methodInvokeResult; return await (dynamic)methodInvokeResult; }
internal string ToBody(object bodyObject, HttpRequest req) { if (bodyObject == null) { return null; } if (req.ResponseContentType == MediaType.JSON) { return JsonConvert.SerializeObject(bodyObject); } else if (req.ResponseContentType == MediaType.XML) { return XmlSerializeObject(bodyObject); } return null; }
private object ExecuteAnonymousMethod(RestControllerMethodInfo info, HttpRequest request) { var instantiator = InstanceCreatorCache.Default.GetCreator(info.MethodInfo.DeclaringType); object[] parameters = null; try { parameters = info.GetParametersFromUri(request.Uri).ToArray(); } catch (FormatException) { return _responseFactory.CreateBadRequest(); } return info.MethodInfo.Invoke( instantiator.Create(info.MethodInfo.DeclaringType, info.ControllerConstructorArgs()), parameters); }
internal abstract Task<IHttpResponse> HandleRequest(HttpRequest request);