Files
se-launcher/NuGet/PackageSourceMapping.cs
2024-10-22 21:40:32 +07:00

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);