Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: Add a Request.CreateResponse overload that takes the content CLR type as parameter. [883]

$
0
0
Request.CreateResponse<T> doesn't use the runtime type of the object for content-negotiation. This would be an issue when the formatter doesn't responds to CanWriteType(typeof(object)) with false (example ODataMediaTypeFormatter). An example scenario can be found [here](https://gist.github.com/raghuramn/5084608).

Having a non-generic overload where we can specify T would be useful.
Comments: Without this overload I had to write code like this, ``` public static class HttpRequestMessageExtensions { private static MethodInfo _createResponse = InitCreateResponse(); private static MethodInfo InitCreateResponse() { Expression<Func<HttpRequestMessage, HttpResponseMessage>> expr = (request) => request.CreateResponse<object>(HttpStatusCode.OK, default(object)); return (expr.Body as MethodCallExpression).Method.GetGenericMethodDefinition(); } // Content negotiation doesn't use the runtime type of the object. This helper method is CreateResponse overload that passes // the specified type to content negotiation. public static HttpResponseMessage CreateResponse(this HttpRequestMessage request, HttpStatusCode status, Type type, object value) { return _createResponse.MakeGenericMethod(type).Invoke(null, new[] { request, status, value }) as HttpResponseMessage; } } ```

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>