Skip to content

Commit 83fa23e

Browse files
committed
Avoid duplicating code and utilize the code from EndpointMetdataPopulator
1 parent 5ed4937 commit 83fa23e

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

src/Mvc/Mvc.Core/src/ApplicationModels/DefaultApplicationModelProvider.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels;
2121
internal class DefaultApplicationModelProvider : IApplicationModelProvider
2222
#pragma warning restore CA1852 // Seal internal types
2323
{
24-
private static readonly MethodInfo PopulateMetadataForEndpointMethod = typeof(EndpointMetadataPopulator).GetMethod(nameof(PopulateMetadataForEndpoint), BindingFlags.NonPublic | BindingFlags.Static)!;
25-
2624
private readonly MvcOptions _mvcOptions;
2725
private readonly IModelMetadataProvider _modelMetadataProvider;
2826
private readonly Func<ActionContext, bool> _supportsAllRequests;
@@ -374,8 +372,8 @@ internal static void AddReturnTypeMetadata(IList<SelectorModel> selectors, Metho
374372
var invokeArgs = new object[2];
375373
invokeArgs[0] = methodInfo;
376374
invokeArgs[1] = builder;
377-
PopulateMetadataForEndpointMethod.MakeGenericMethod(returnType).Invoke(null, invokeArgs);
378-
375+
EndpointMetadataPopulator.PopulateMetadataForEndpointMethod.MakeGenericMethod(returnType).Invoke(null, invokeArgs);
376+
379377
// The metadata is added to the builder's metadata collection.
380378
// We need to populate the selectors with that metadata.
381379
foreach (var metadata in builder.Metadata)
@@ -712,12 +710,6 @@ private static void AddRange<T>(IList<T> list, IEnumerable<T> items)
712710
}
713711
}
714712

715-
private static void PopulateMetadataForEndpoint<T>(MethodInfo method, EndpointBuilder builder)
716-
where T : IEndpointMetadataProvider
717-
{
718-
T.PopulateMetadata(method, builder);
719-
}
720-
721713
private sealed class InertEndpointBuilder : EndpointBuilder
722714
{
723715
public override Endpoint Build()

src/Shared/EndpointMetadataPopulator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Http;
1616
internal static class EndpointMetadataPopulator
1717
{
1818
private static readonly MethodInfo PopulateMetadataForParameterMethod = typeof(EndpointMetadataPopulator).GetMethod(nameof(PopulateMetadataForParameter), BindingFlags.NonPublic | BindingFlags.Static)!;
19-
private static readonly MethodInfo PopulateMetadataForEndpointMethod = typeof(EndpointMetadataPopulator).GetMethod(nameof(PopulateMetadataForEndpoint), BindingFlags.NonPublic | BindingFlags.Static)!;
19+
internal static readonly MethodInfo PopulateMetadataForEndpointMethod = typeof(EndpointMetadataPopulator).GetMethod(nameof(PopulateMetadataForEndpoint), BindingFlags.NonPublic | BindingFlags.Static)!;
2020

2121
public static void PopulateMetadata(MethodInfo methodInfo, EndpointBuilder builder, IEnumerable<ParameterInfo>? parameters = null)
2222
{

0 commit comments

Comments
 (0)