Skip to content

Commit

Permalink
Avoid duplicating code and utilize the code from EndpointMetdataPopul…
Browse files Browse the repository at this point in the history
…ator
  • Loading branch information
mkArtakMSFT committed Jan 30, 2025
1 parent 5ed4937 commit 83fa23e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels;
internal class DefaultApplicationModelProvider : IApplicationModelProvider
#pragma warning restore CA1852 // Seal internal types
{
private static readonly MethodInfo PopulateMetadataForEndpointMethod = typeof(EndpointMetadataPopulator).GetMethod(nameof(PopulateMetadataForEndpoint), BindingFlags.NonPublic | BindingFlags.Static)!;

private readonly MvcOptions _mvcOptions;
private readonly IModelMetadataProvider _modelMetadataProvider;
private readonly Func<ActionContext, bool> _supportsAllRequests;
Expand Down Expand Up @@ -374,8 +372,8 @@ internal static void AddReturnTypeMetadata(IList<SelectorModel> selectors, Metho
var invokeArgs = new object[2];
invokeArgs[0] = methodInfo;
invokeArgs[1] = builder;
PopulateMetadataForEndpointMethod.MakeGenericMethod(returnType).Invoke(null, invokeArgs);

EndpointMetadataPopulator.PopulateMetadataForEndpointMethod.MakeGenericMethod(returnType).Invoke(null, invokeArgs);
// The metadata is added to the builder's metadata collection.
// We need to populate the selectors with that metadata.
foreach (var metadata in builder.Metadata)
Expand Down Expand Up @@ -712,12 +710,6 @@ private static void AddRange<T>(IList<T> list, IEnumerable<T> items)
}
}

private static void PopulateMetadataForEndpoint<T>(MethodInfo method, EndpointBuilder builder)
where T : IEndpointMetadataProvider
{
T.PopulateMetadata(method, builder);
}

private sealed class InertEndpointBuilder : EndpointBuilder
{
public override Endpoint Build()
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/EndpointMetadataPopulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Http;
internal static class EndpointMetadataPopulator
{
private static readonly MethodInfo PopulateMetadataForParameterMethod = typeof(EndpointMetadataPopulator).GetMethod(nameof(PopulateMetadataForParameter), BindingFlags.NonPublic | BindingFlags.Static)!;
private static readonly MethodInfo PopulateMetadataForEndpointMethod = typeof(EndpointMetadataPopulator).GetMethod(nameof(PopulateMetadataForEndpoint), BindingFlags.NonPublic | BindingFlags.Static)!;
internal static readonly MethodInfo PopulateMetadataForEndpointMethod = typeof(EndpointMetadataPopulator).GetMethod(nameof(PopulateMetadataForEndpoint), BindingFlags.NonPublic | BindingFlags.Static)!;

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

0 comments on commit 83fa23e

Please sign in to comment.