// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Routing.Matching; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Routing { internal class NameBasedEndpointFinder : IEndpointFinder { private readonly CompositeEndpointDataSource _endpointDatasource; private readonly ILogger _logger; public NameBasedEndpointFinder( CompositeEndpointDataSource endpointDataSource, ILogger logger) { _endpointDatasource = endpointDataSource; _logger = logger; } public IEnumerable FindEndpoints(string endpointName) { if (string.IsNullOrEmpty(endpointName)) { return Array.Empty(); } var endpoints = _endpointDatasource.Endpoints.OfType(); foreach (var endpoint in endpoints) { var nameMetadata = endpoint.Metadata.GetMetadata(); if (nameMetadata != null && string.Equals(endpointName, nameMetadata.Name, StringComparison.OrdinalIgnoreCase)) { return new[] { endpoint }; } } return Array.Empty(); } } }