From a8e5510df2d06ee12f4522db0a3342a0a2981c0b Mon Sep 17 00:00:00 2001 From: David Hollifield Date: Wed, 28 Jan 2015 17:28:04 -0500 Subject: [PATCH 1/3] Check for non-null Response in OnActionExecuted A null response can happen if the WebApi method throws an exception and doesn't return anything. --- .../LinqToQueryableAttribute.cs | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/LinqToQuerystring.WebApi/LinqToQueryableAttribute.cs b/LinqToQuerystring.WebApi/LinqToQueryableAttribute.cs index 722589a..14113ee 100644 --- a/LinqToQuerystring.WebApi/LinqToQueryableAttribute.cs +++ b/LinqToQuerystring.WebApi/LinqToQueryableAttribute.cs @@ -22,38 +22,41 @@ public LinqToQueryableAttribute(bool forceDynamicProperties = false, int maxPage public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { - object responseObject; - - actionExecutedContext.Response.TryGetContentValue(out responseObject); - var originalquery = responseObject as IQueryable; - - if (originalquery != null) + if (actionExecutedContext.Response != null) { - var queryString = actionExecutedContext.Request.RequestUri.Query; - var genericType = originalquery.GetType().GetGenericArguments()[0]; + object responseObject; - var reply = originalquery.LinqToQuerystring(genericType, queryString, this.forceDynamicProperties, this.maxPageSize); - var replyType = reply.GetType(); + actionExecutedContext.Response.TryGetContentValue(out responseObject); + var originalquery = responseObject as IQueryable; - if (typeof(IQueryable).IsAssignableFrom(replyType)) + if (originalquery != null) { - var queryableType = typeof(IQueryable<>).GetGenericTypeDefinition(); - var genericArgs = replyType.GetGenericArguments(); - replyType = queryableType.MakeGenericType(genericArgs); + var queryString = actionExecutedContext.Request.RequestUri.Query; + var genericType = originalquery.GetType().GetGenericArguments()[0]; + + var reply = originalquery.LinqToQuerystring(genericType, queryString, this.forceDynamicProperties, this.maxPageSize); + var replyType = reply.GetType(); + + if (typeof(IQueryable).IsAssignableFrom(replyType)) + { + var queryableType = typeof(IQueryable<>).GetGenericTypeDefinition(); + var genericArgs = replyType.GetGenericArguments(); + replyType = queryableType.MakeGenericType(genericArgs); + } + + var configuraton = actionExecutedContext.ActionContext.ControllerContext.Configuration; + var conneg = (IContentNegotiator) configuraton.Services.GetService(typeof(IContentNegotiator)); + var formatter = conneg.Negotiate( + replyType, + actionExecutedContext.Request, + configuraton.Formatters); + + actionExecutedContext.Response = new HttpResponseMessage + { + StatusCode = HttpStatusCode.OK, + Content = new ObjectContent(replyType, reply, formatter.Formatter) + }; } - - var configuraton = actionExecutedContext.ActionContext.ControllerContext.Configuration; - var conneg = (IContentNegotiator)configuraton.Services.GetService(typeof(IContentNegotiator)); - var formatter = conneg.Negotiate( - replyType, - actionExecutedContext.Request, - configuraton.Formatters); - - actionExecutedContext.Response = new HttpResponseMessage - { - StatusCode = HttpStatusCode.OK, - Content = new ObjectContent(replyType, reply, formatter.Formatter) - }; } } } From 6d5d7df6793c5d50c6f554416070216b95388480 Mon Sep 17 00:00:00 2001 From: cyl102 Date: Fri, 20 Feb 2015 13:39:15 +0000 Subject: [PATCH 2/3] The dns doesn't seems to work anymore --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 68f25fe..8c2255c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Linq to Querystring v0.7.0 ========================== ## New Website -Linq to Querystring now has a project page! Please refer to http://linqtoquerystring.net/ for documentation and samples. +Linq to Querystring now has a project page! Please refer to http://roysvork.github.io/LinqToQuerystring/ for documentation and samples. ## Installation From 894c4be73dae55bb66e7685cba81193fd2cf5211 Mon Sep 17 00:00:00 2001 From: Chris Marisic Date: Fri, 11 Mar 2016 15:31:29 -0500 Subject: [PATCH 3/3] update url original url is dead --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c2255c..c67c6da 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Linq to Querystring v0.7.0 ========================== ## New Website -Linq to Querystring now has a project page! Please refer to http://roysvork.github.io/LinqToQuerystring/ for documentation and samples. +Linq to Querystring now has a project page! Please refer to http://beyond-code.com/LinqToQuerystring/ for documentation and samples. ## Installation