16 lines
592 B
C#
16 lines
592 B
C#
using System.Collections.Immutable;
|
|
|
|
namespace NuGet;
|
|
|
|
public class PackageSourceMapping(ImmutableArray<PackageSource> sources)
|
|
{
|
|
private readonly ImmutableDictionary<string, Task<NuGetClient>> _clients = sources.Select(b =>
|
|
new KeyValuePair<string, Task<NuGetClient>>(b.Pattern,
|
|
NuGetClient.CreateFromIndexUrlAsync(b.Url)))
|
|
.ToImmutableDictionary();
|
|
|
|
public Task<NuGetClient> GetClientAsync(string packageId) =>
|
|
_clients.FirstOrDefault(b => packageId.StartsWith(b.Key)).Value;
|
|
}
|
|
|
|
public record PackageSource(string Pattern, string Url); |