@@ -22,38 +22,41 @@ public LinqToQueryableAttribute(bool forceDynamicProperties = false, int maxPage
22
22
23
23
public override void OnActionExecuted ( HttpActionExecutedContext actionExecutedContext )
24
24
{
25
- object responseObject ;
26
-
27
- actionExecutedContext . Response . TryGetContentValue ( out responseObject ) ;
28
- var originalquery = responseObject as IQueryable ;
29
-
30
- if ( originalquery != null )
25
+ if ( actionExecutedContext . Response != null )
31
26
{
32
- var queryString = actionExecutedContext . Request . RequestUri . Query ;
33
- var genericType = originalquery . GetType ( ) . GetGenericArguments ( ) [ 0 ] ;
27
+ object responseObject ;
34
28
35
- var reply = originalquery . LinqToQuerystring ( genericType , queryString , this . forceDynamicProperties , this . maxPageSize ) ;
36
- var replyType = reply . GetType ( ) ;
29
+ actionExecutedContext . Response . TryGetContentValue ( out responseObject ) ;
30
+ var originalquery = responseObject as IQueryable ;
37
31
38
- if ( typeof ( IQueryable ) . IsAssignableFrom ( replyType ) )
32
+ if ( originalquery != null )
39
33
{
40
- var queryableType = typeof ( IQueryable < > ) . GetGenericTypeDefinition ( ) ;
41
- var genericArgs = replyType . GetGenericArguments ( ) ;
42
- replyType = queryableType . MakeGenericType ( genericArgs ) ;
34
+ var queryString = actionExecutedContext . Request . RequestUri . Query ;
35
+ var genericType = originalquery . GetType ( ) . GetGenericArguments ( ) [ 0 ] ;
36
+
37
+ var reply = originalquery . LinqToQuerystring ( genericType , queryString , this . forceDynamicProperties , this . maxPageSize ) ;
38
+ var replyType = reply . GetType ( ) ;
39
+
40
+ if ( typeof ( IQueryable ) . IsAssignableFrom ( replyType ) )
41
+ {
42
+ var queryableType = typeof ( IQueryable < > ) . GetGenericTypeDefinition ( ) ;
43
+ var genericArgs = replyType . GetGenericArguments ( ) ;
44
+ replyType = queryableType . MakeGenericType ( genericArgs ) ;
45
+ }
46
+
47
+ var configuraton = actionExecutedContext . ActionContext . ControllerContext . Configuration ;
48
+ var conneg = ( IContentNegotiator ) configuraton . Services . GetService ( typeof ( IContentNegotiator ) ) ;
49
+ var formatter = conneg . Negotiate (
50
+ replyType ,
51
+ actionExecutedContext . Request ,
52
+ configuraton . Formatters ) ;
53
+
54
+ actionExecutedContext . Response = new HttpResponseMessage
55
+ {
56
+ StatusCode = HttpStatusCode . OK ,
57
+ Content = new ObjectContent ( replyType , reply , formatter . Formatter )
58
+ } ;
43
59
}
44
-
45
- var configuraton = actionExecutedContext . ActionContext . ControllerContext . Configuration ;
46
- var conneg = ( IContentNegotiator ) configuraton . Services . GetService ( typeof ( IContentNegotiator ) ) ;
47
- var formatter = conneg . Negotiate (
48
- replyType ,
49
- actionExecutedContext . Request ,
50
- configuraton . Formatters ) ;
51
-
52
- actionExecutedContext . Response = new HttpResponseMessage
53
- {
54
- StatusCode = HttpStatusCode . OK ,
55
- Content = new ObjectContent ( replyType , reply , formatter . Formatter )
56
- } ;
57
60
}
58
61
}
59
62
}
0 commit comments