Skip to content

Commit dc80513

Browse files
committed
address pr feedback
1 parent 3368d23 commit dc80513

7 files changed

+18
-15
lines changed

src/Http/Http.Extensions/src/Microsoft.AspNetCore.Http.Extensions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<ItemGroup>
1414
<Compile Include="$(SharedSourceRoot)ObjectMethodExecutor\**\*.cs" />
15-
<Compile Include="$(SharedSourceRoot)RequestDelegateFactoryUtilities.cs" />
15+
<Compile Include="$(SharedSourceRoot)TryParseMethodCache.cs" />
1616
<Compile Include="..\..\Shared\StreamCopyOperationInternal.cs" />
1717
</ItemGroup>
1818

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private static Expression CreateArgument(ParameterInfo parameter, FactoryContext
225225
{
226226
return RequestAbortedExpr;
227227
}
228-
else if (parameter.ParameterType == typeof(string) || RequestDelegateFactoryUtilities.HasTryParseMethod(parameter))
228+
else if (parameter.ParameterType == typeof(string) || TryParseMethodCache.HasTryParseMethod(parameter))
229229
{
230230
return BindParameterFromRouteValueOrQueryString(parameter, parameter.Name, factoryContext);
231231
}
@@ -503,7 +503,7 @@ private static Expression BindParameterFromValue(ParameterInfo parameter, Expres
503503
var isNotNullable = underlyingNullableType is null;
504504

505505
var nonNullableParameterType = underlyingNullableType ?? parameter.ParameterType;
506-
var tryParseMethod = RequestDelegateFactoryUtilities.FindTryParseMethod(nonNullableParameterType);
506+
var tryParseMethod = TryParseMethodCache.FindTryParseMethod(nonNullableParameterType);
507507

508508
if (tryParseMethod is null)
509509
{

src/Mvc/Mvc.ApiExplorer/src/DependencyInjection/EndpointMethodInfoApiExplorerServiceCollectionExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ public static class EndpointMetadataApiExplorerServiceCollectionExtensions
1717
/// Configures ApiExplorer using <see cref="Endpoint.Metadata"/>.
1818
/// </summary>
1919
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
20-
public static void AddEndpointsApiExplorer(this IServiceCollection services)
20+
public static IServiceCollection AddEndpointsApiExplorer(this IServiceCollection services)
2121
{
2222
// Try to add default services in case MVC services aren't added.
2323
services.TryAddSingleton<IActionDescriptorCollectionProvider, DefaultActionDescriptorCollectionProvider>();
2424
services.TryAddSingleton<IApiDescriptionGroupCollectionProvider, ApiDescriptionGroupCollectionProvider>();
2525

2626
services.TryAddEnumerable(
2727
ServiceDescriptor.Transient<IApiDescriptionProvider, EndpointMetadataApiDescriptionProvider>());
28+
29+
return services;
2830
}
2931
}
3032
}

src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal class EndpointMetadataApiDescriptionProvider : IApiDescriptionProvider
2727
private readonly IHostEnvironment _environment;
2828
private readonly IServiceProviderIsService? _serviceProviderIsService;
2929

30-
// Executes before MVC's DefaultApiDescriptionProvider and GrpcHttpApiDescriptionProvider for no particular reason :D
30+
// Executes before MVC's DefaultApiDescriptionProvider and GrpcHttpApiDescriptionProvider for no particular reason.
3131
public int Order => -1100;
3232

3333
public EndpointMetadataApiDescriptionProvider(EndpointDataSource endpointDataSource, IHostEnvironment environment)
@@ -81,7 +81,7 @@ private ApiDescription CreateApiDescription(RouteEndpoint routeEndpoint, string
8181
else
8282
{
8383
// If the declaring type is null or compiler-generated (e.g. lambdas),
84-
// group the methods under a "Map" controller.
84+
// group the methods under the application name.
8585
controllerName = _environment.ApplicationName;
8686
}
8787

@@ -161,7 +161,7 @@ private ApiParameterDescription CreateApiParameterDescription(ParameterInfo para
161161
{
162162
return (BindingSource.Services, parameter.Name ?? string.Empty);
163163
}
164-
else if (parameter.ParameterType == typeof(string) || RequestDelegateFactoryUtilities.HasTryParseMethod(parameter))
164+
else if (parameter.ParameterType == typeof(string) || TryParseMethodCache.HasTryParseMethod(parameter))
165165
{
166166
// Path vs query cannot be determined by RequestDelegateFactory at startup currently because of the layering, but can be done here.
167167
if (parameter.Name is { } name && pattern.GetParameter(name) is not null)

src/Mvc/Mvc.ApiExplorer/src/Microsoft.AspNetCore.Mvc.ApiExplorer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<Compile Include="$(SharedSourceRoot)RequestDelegateFactoryUtilities.cs" />
13+
<Compile Include="$(SharedSourceRoot)TryParseMethodCache.cs" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

src/Mvc/Mvc.ApiExplorer/src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollection.Items.get ->
2323
Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.ApiDescriptionGroupCollectionProvider(Microsoft.AspNetCore.Mvc.Infrastructure.IActionDescriptorCollectionProvider! actionDescriptorCollectionProvider, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionProvider!>! apiDescriptionProviders) -> void
2424
Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.ApiDescriptionGroups.get -> Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollection!
2525
Microsoft.Extensions.DependencyInjection.EndpointMetadataApiExplorerServiceCollectionExtensions
26-
static Microsoft.Extensions.DependencyInjection.EndpointMetadataApiExplorerServiceCollectionExtensions.AddEndpointsApiExplorer(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> void
26+
static Microsoft.Extensions.DependencyInjection.EndpointMetadataApiExplorerServiceCollectionExtensions.AddEndpointsApiExplorer(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
2727
~Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiDescriptionProvider.DefaultApiDescriptionProvider(Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.MvcOptions!>! optionsAccessor, Microsoft.AspNetCore.Routing.IInlineConstraintResolver! constraintResolver, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider! modelMetadataProvider, Microsoft.AspNetCore.Mvc.Infrastructure.IActionResultTypeMapper! mapper, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Routing.RouteOptions!>! routeOptions) -> void
2828
Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiDescriptionProvider.OnProvidersExecuted(Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionProviderContext! context) -> void
2929
Microsoft.AspNetCore.Mvc.ApiExplorer.DefaultApiDescriptionProvider.OnProvidersExecuting(Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionProviderContext! context) -> void

src/Shared/RequestDelegateFactoryUtilities.cs renamed to src/Shared/TryParseMethodCache.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
using System;
55
using System.Collections.Concurrent;
6+
using System.Diagnostics;
67
using System.Reflection;
78

89
namespace Microsoft.AspNetCore.Http
910
{
10-
// REVIEW: Better name?
11-
internal static class RequestDelegateFactoryUtilities
11+
internal static class TryParseMethodCache
1212
{
1313
private static readonly MethodInfo EnumTryParseMethod = GetEnumTryParseMethod();
1414

1515
// Since this is shared source, the cache won't be shared between RequestDelegateFactory and the ApiDescriptionProvider sadly :(
16-
private static readonly ConcurrentDictionary<Type, MethodInfo?> TryParseMethodCache = new();
16+
private static readonly ConcurrentDictionary<Type, MethodInfo?> Cache = new();
1717

1818
public static bool HasTryParseMethod(ParameterInfo parameter)
1919
{
@@ -54,7 +54,7 @@ public static bool HasTryParseMethod(ParameterInfo parameter)
5454
return null;
5555
}
5656

57-
return TryParseMethodCache.GetOrAdd(type, Finder);
57+
return Cache.GetOrAdd(type, Finder);
5858
}
5959

6060
private static MethodInfo GetEnumTryParseMethod()
@@ -63,7 +63,7 @@ private static MethodInfo GetEnumTryParseMethod()
6363

6464
foreach (var method in staticEnumMethods)
6565
{
66-
if (!method.IsGenericMethod || method.Name != "TryParse" || method.ReturnType != typeof(bool))
66+
if (!method.IsGenericMethod || method.Name != nameof(Enum.TryParse) || method.ReturnType != typeof(bool))
6767
{
6868
continue;
6969
}
@@ -78,7 +78,8 @@ private static MethodInfo GetEnumTryParseMethod()
7878
}
7979
}
8080

81-
throw new Exception("static bool System.Enum.TryParse<TEnum>(string? value, out TEnum result) does not exist!!?!?");
81+
Debug.Fail("static bool System.Enum.TryParse<TEnum>(string? value, out TEnum result) not found.");
82+
throw new Exception("static bool System.Enum.TryParse<TEnum>(string? value, out TEnum result) not found.");
8283
}
8384
}
8485
}

0 commit comments

Comments
 (0)