|
15 | 15 | using System.Text.Json.Serialization.Metadata;
|
16 | 16 | using Microsoft.AspNetCore.Builder;
|
17 | 17 | using Microsoft.AspNetCore.Http.Features;
|
| 18 | +using Microsoft.AspNetCore.Http.HttpResults; |
18 | 19 | using Microsoft.AspNetCore.Http.Json;
|
19 | 20 | using Microsoft.AspNetCore.Http.Metadata;
|
20 | 21 | using Microsoft.AspNetCore.Internal;
|
@@ -96,11 +97,7 @@ public static partial class RequestDelegateFactory
|
96 | 97 | private static readonly MemberExpression FormFilesExpr = Expression.Property(FormExpr, typeof(IFormCollection).GetProperty(nameof(IFormCollection.Files))!);
|
97 | 98 | private static readonly MemberExpression StatusCodeExpr = Expression.Property(HttpResponseExpr, typeof(HttpResponse).GetProperty(nameof(HttpResponse.StatusCode))!);
|
98 | 99 | private static readonly MemberExpression CompletedTaskExpr = Expression.Property(null, (PropertyInfo)GetMemberInfo<Func<Task>>(() => Task.CompletedTask));
|
99 |
| - // Due to https://github.com/dotnet/aspnetcore/issues/41330 we cannot reference the EmptyHttpResult type |
100 |
| - // but users still need to assert on it as in https://github.com/dotnet/aspnetcore/issues/45063 |
101 |
| - // so we temporarily work around this here by using reflection to get the actual type. |
102 |
| - private static readonly object? EmptyHttpResultInstance = Type.GetType("Microsoft.AspNetCore.Http.HttpResults.EmptyHttpResult, Microsoft.AspNetCore.Http.Results")?.GetProperty("Instance")?.GetValue(null, null); |
103 |
| - private static readonly NewExpression EmptyHttpResultValueTaskExpr = Expression.New(typeof(ValueTask<object>).GetConstructor(new[] { typeof(IResult) })!, Expression.Constant(EmptyHttpResultInstance)); |
| 100 | + private static readonly NewExpression EmptyHttpResultValueTaskExpr = Expression.New(typeof(ValueTask<object>).GetConstructor(new[] { typeof(EmptyHttpResult) })!, Expression.Property(null, typeof(EmptyHttpResult), nameof(EmptyHttpResult.Instance))); |
104 | 101 | private static readonly ParameterExpression TempSourceStringExpr = ParameterBindingMethodCache.TempSourceStringExpr;
|
105 | 102 | private static readonly BinaryExpression TempSourceStringNotNullExpr = Expression.NotEqual(TempSourceStringExpr, Expression.Constant(null));
|
106 | 103 | private static readonly BinaryExpression TempSourceStringNullExpr = Expression.Equal(TempSourceStringExpr, Expression.Constant(null));
|
@@ -397,7 +394,6 @@ private static Expression[] CreateArgumentsAndInferMetadata(MethodInfo methodInf
|
397 | 394 | private static EndpointFilterDelegate? CreateFilterPipeline(MethodInfo methodInfo, Expression? targetExpression, RequestDelegateFactoryContext factoryContext, Expression<Func<HttpContext, object?>>? targetFactory)
|
398 | 395 | {
|
399 | 396 | Debug.Assert(factoryContext.EndpointBuilder.FilterFactories.Count > 0);
|
400 |
| - Debug.Assert(EmptyHttpResultInstance is not null, "The EmptyHttpResult type could not be found."); |
401 | 397 | // httpContext.Response.StatusCode >= 400
|
402 | 398 | // ? Task.CompletedTask
|
403 | 399 | // : {
|
@@ -487,7 +483,6 @@ targetExpression is null
|
487 | 483 |
|
488 | 484 | private static Expression MapHandlerReturnTypeToValueTask(Expression methodCall, Type returnType)
|
489 | 485 | {
|
490 |
| - Debug.Assert(EmptyHttpResultInstance is not null, "The EmptyHttpResult type could not be found."); |
491 | 486 | if (returnType == typeof(void))
|
492 | 487 | {
|
493 | 488 | return Expression.Block(methodCall, EmptyHttpResultValueTaskExpr);
|
@@ -2209,34 +2204,32 @@ static async Task ExecuteAwaited(ValueTask task)
|
2209 | 2204 |
|
2210 | 2205 | private static ValueTask<object?> ExecuteTaskWithEmptyResult(Task task)
|
2211 | 2206 | {
|
2212 |
| - Debug.Assert(EmptyHttpResultInstance is not null, "The EmptyHttpResult type could not be found."); |
2213 | 2207 | static async ValueTask<object?> ExecuteAwaited(Task task)
|
2214 | 2208 | {
|
2215 | 2209 | await task;
|
2216 |
| - return EmptyHttpResultInstance; |
| 2210 | + return EmptyHttpResult.Instance; |
2217 | 2211 | }
|
2218 | 2212 |
|
2219 | 2213 | if (task.IsCompletedSuccessfully)
|
2220 | 2214 | {
|
2221 |
| - return new ValueTask<object?>(EmptyHttpResultInstance); |
| 2215 | + return new ValueTask<object?>(EmptyHttpResult.Instance); |
2222 | 2216 | }
|
2223 | 2217 |
|
2224 | 2218 | return ExecuteAwaited(task);
|
2225 | 2219 | }
|
2226 | 2220 |
|
2227 | 2221 | private static ValueTask<object?> ExecuteValueTaskWithEmptyResult(ValueTask valueTask)
|
2228 | 2222 | {
|
2229 |
| - Debug.Assert(EmptyHttpResultInstance is not null, "The EmptyHttpResult type could not be found."); |
2230 | 2223 | static async ValueTask<object?> ExecuteAwaited(ValueTask task)
|
2231 | 2224 | {
|
2232 | 2225 | await task;
|
2233 |
| - return EmptyHttpResultInstance; |
| 2226 | + return EmptyHttpResult.Instance; |
2234 | 2227 | }
|
2235 | 2228 |
|
2236 | 2229 | if (valueTask.IsCompletedSuccessfully)
|
2237 | 2230 | {
|
2238 | 2231 | valueTask.GetAwaiter().GetResult();
|
2239 |
| - return new ValueTask<object?>(EmptyHttpResultInstance); |
| 2232 | + return new ValueTask<object?>(EmptyHttpResult.Instance); |
2240 | 2233 | }
|
2241 | 2234 |
|
2242 | 2235 | return ExecuteAwaited(valueTask);
|
|
0 commit comments