11
11
using System . Reflection ;
12
12
using System . Threading ;
13
13
using System . Threading . Tasks ;
14
- using Microsoft . AspNetCore . Http ;
15
14
using Microsoft . AspNetCore . Http . Metadata ;
16
15
using Microsoft . Extensions . DependencyInjection ;
17
16
using Microsoft . Extensions . Internal ;
18
17
using Microsoft . Extensions . Logging ;
19
18
20
- namespace Microsoft . AspNetCore . Routing . Internal
19
+ namespace Microsoft . AspNetCore . Http
21
20
{
22
- internal static class MapActionExpressionTreeBuilder
21
+ /// <summary>
22
+ /// Builds <see cref="RequestDelegate"/> implementations from <see cref="Delegate"/> request handlers.
23
+ /// </summary>
24
+ public static class RequestDelegateBuilder
23
25
{
24
26
private static readonly MethodInfo ChangeTypeMethodInfo = GetMethodInfo < Func < object , Type , object > > ( ( value , type ) => Convert . ChangeType ( value , type , CultureInfo . InvariantCulture ) ) ;
25
- private static readonly MethodInfo ExecuteTaskOfTMethodInfo = typeof ( MapActionExpressionTreeBuilder ) . GetMethod ( nameof ( ExecuteTask ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
26
- private static readonly MethodInfo ExecuteTaskOfStringMethodInfo = typeof ( MapActionExpressionTreeBuilder ) . GetMethod ( nameof ( ExecuteTaskOfString ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
27
- private static readonly MethodInfo ExecuteValueTaskOfTMethodInfo = typeof ( MapActionExpressionTreeBuilder ) . GetMethod ( nameof ( ExecuteValueTaskOfT ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
28
- private static readonly MethodInfo ExecuteValueTaskMethodInfo = typeof ( MapActionExpressionTreeBuilder ) . GetMethod ( nameof ( ExecuteValueTask ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
29
- private static readonly MethodInfo ExecuteValueTaskOfStringMethodInfo = typeof ( MapActionExpressionTreeBuilder ) . GetMethod ( nameof ( ExecuteValueTaskOfString ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
30
- private static readonly MethodInfo ExecuteTaskResultOfTMethodInfo = typeof ( MapActionExpressionTreeBuilder ) . GetMethod ( nameof ( ExecuteTaskResult ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
31
- private static readonly MethodInfo ExecuteValueResultTaskOfTMethodInfo = typeof ( MapActionExpressionTreeBuilder ) . GetMethod ( nameof ( ExecuteValueTaskResult ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
27
+ private static readonly MethodInfo ExecuteTaskOfTMethodInfo = typeof ( RequestDelegateBuilder ) . GetMethod ( nameof ( ExecuteTask ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
28
+ private static readonly MethodInfo ExecuteTaskOfStringMethodInfo = typeof ( RequestDelegateBuilder ) . GetMethod ( nameof ( ExecuteTaskOfString ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
29
+ private static readonly MethodInfo ExecuteValueTaskOfTMethodInfo = typeof ( RequestDelegateBuilder ) . GetMethod ( nameof ( ExecuteValueTaskOfT ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
30
+ private static readonly MethodInfo ExecuteValueTaskMethodInfo = typeof ( RequestDelegateBuilder ) . GetMethod ( nameof ( ExecuteValueTask ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
31
+ private static readonly MethodInfo ExecuteValueTaskOfStringMethodInfo = typeof ( RequestDelegateBuilder ) . GetMethod ( nameof ( ExecuteValueTaskOfString ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
32
+ private static readonly MethodInfo ExecuteTaskResultOfTMethodInfo = typeof ( RequestDelegateBuilder ) . GetMethod ( nameof ( ExecuteTaskResult ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
33
+ private static readonly MethodInfo ExecuteValueResultTaskOfTMethodInfo = typeof ( RequestDelegateBuilder ) . GetMethod ( nameof ( ExecuteValueTaskResult ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
32
34
private static readonly MethodInfo GetRequiredServiceMethodInfo = typeof ( ServiceProviderServiceExtensions ) . GetMethod ( nameof ( ServiceProviderServiceExtensions . GetRequiredService ) , BindingFlags . Public | BindingFlags . Static , new Type [ ] { typeof ( IServiceProvider ) } ) ! ;
33
35
private static readonly MethodInfo ResultWriteResponseAsync = typeof ( IResult ) . GetMethod ( nameof ( IResult . ExecuteAsync ) , BindingFlags . Public | BindingFlags . Instance ) ! ;
34
36
private static readonly MethodInfo StringResultWriteResponseAsync = GetMethodInfo < Func < HttpResponse , string , Task > > ( ( response , text ) => HttpResponseWritingExtensions . WriteAsync ( response , text , default ) ) ;
@@ -44,6 +46,11 @@ internal static class MapActionExpressionTreeBuilder
44
46
private static readonly MemberExpression HttpResponseExpr = Expression . Property ( HttpContextParameter , nameof ( HttpContext . Response ) ) ;
45
47
private static readonly MemberExpression RequestAbortedExpr = Expression . Property ( HttpContextParameter , nameof ( HttpContext . RequestAborted ) ) ;
46
48
49
+ /// <summary>
50
+ /// Builds a <see cref="RequestDelegate"/> implementation for <paramref name="action"/>.
51
+ /// </summary>
52
+ /// <param name="action">A request handler with any number of custom parameters that often produces a response with its return value.</param>
53
+ /// <returns>The <see cref="RequestDelegate"/></returns>
47
54
public static RequestDelegate BuildRequestDelegate ( Delegate action )
48
55
{
49
56
// Non void return type
0 commit comments