@@ -115,13 +115,17 @@ private Func<IHttpContext, IHttpRequestHandler, string, Task<IHttpRequestHandler
115115 {
116116 return null ;
117117 }
118+ return CreateIndexerFunction < IHttpRequestHandler > ( arg , indexer ) ;
119+ }
120+ internal static Func < IHttpContext , T , string , Task < T > > CreateIndexerFunction < T > ( Type arg , MethodInfo indexer )
121+ {
118122 var parameterType = indexer . GetParameters ( ) [ 1 ] . ParameterType ;
119123
120124 var httpContext = Expression . Parameter ( typeof ( IHttpContext ) ) ;
121- var inputHandler = Expression . Parameter ( typeof ( IHttpRequestHandler ) ) ;
125+ var inputHandler = Expression . Parameter ( typeof ( T ) ) ;
122126 var inputObject = Expression . Parameter ( typeof ( string ) ) ;
123127
124- var tryParseMethod = parameterType . GetMethod ( "TryParse" , new [ ] { typeof ( string ) , parameterType . MakeByRefType ( ) } ) ;
128+ var tryParseMethod = parameterType . GetMethod ( "TryParse" , new [ ] { typeof ( string ) , parameterType . MakeByRefType ( ) } ) ;
125129
126130 Expression body ;
127131
@@ -130,11 +134,11 @@ private Func<IHttpContext, IHttpRequestHandler, string, Task<IHttpRequestHandler
130134 var handlerConverted = Expression . Convert ( inputHandler , arg ) ;
131135 var objectConverted =
132136 Expression . Convert (
133- Expression . Call ( typeof ( Convert ) . GetMethod ( "ChangeType" , new [ ] { typeof ( object ) , typeof ( Type ) } ) , inputObject ,
137+ Expression . Call ( typeof ( Convert ) . GetMethod ( "ChangeType" , new [ ] { typeof ( object ) , typeof ( Type ) } ) , inputObject ,
134138 Expression . Constant ( parameterType ) ) , parameterType ) ;
135139
136140 var indexerExpression = Expression . Call ( handlerConverted , indexer , httpContext , objectConverted ) ;
137- var returnValue = Expression . Convert ( indexerExpression , typeof ( IHttpRequestHandler ) ) ;
141+ var returnValue = Expression . Convert ( indexerExpression , typeof ( T ) ) ;
138142
139143 body = returnValue ;
140144 }
@@ -146,23 +150,25 @@ private Func<IHttpContext, IHttpRequestHandler, string, Task<IHttpRequestHandler
146150 var objectConverted = inputConvertedVar ;
147151
148152 var indexerExpression = Expression . Call ( handlerConverted , indexer , httpContext , objectConverted ) ;
149- var returnValue = Expression . Convert ( indexerExpression , typeof ( Task < IHttpRequestHandler > ) ) ;
150- var returnTarget = Expression . Label ( typeof ( Task < IHttpRequestHandler > ) ) ;
151- var returnLabel = Expression . Label ( returnTarget , Expression . Convert ( Expression . Constant ( null ) , typeof ( Task < IHttpRequestHandler > ) ) ) ;
153+ var returnValue = Expression . Convert ( indexerExpression , typeof ( Task < T > ) ) ;
154+ var returnTarget = Expression . Label ( typeof ( Task < T > ) ) ;
155+ var returnLabel = Expression . Label ( returnTarget ,
156+ Expression . Convert ( Expression . Constant ( null ) , typeof ( Task < T > ) ) ) ;
152157 body =
153158 Expression . Block (
154- new [ ] { inputConvertedVar } ,
159+ new [ ] { inputConvertedVar } ,
155160 Expression . IfThen (
156- Expression . Call ( tryParseMethod , inputObject ,
157- inputConvertedVar ) ,
158- Expression . Return ( returnTarget , returnValue )
159- ) ,
161+ Expression . Call ( tryParseMethod , inputObject ,
162+ inputConvertedVar ) ,
163+ Expression . Return ( returnTarget , returnValue )
164+ ) ,
160165 returnLabel ) ;
161166 }
162167
163-
164- return Expression . Lambda < Func < IHttpContext , IHttpRequestHandler , string , Task < IHttpRequestHandler > > > ( body , httpContext , inputHandler ,
165- inputObject ) . Compile ( ) ;
168+ return
169+ Expression . Lambda < Func < IHttpContext , T , string , Task < T > > > ( body , httpContext ,
170+ inputHandler ,
171+ inputObject ) . Compile ( ) ;
166172 }
167173 private MethodInfo GetIndexer ( Type arg )
168174 {
0 commit comments