File: PackagesFolder\NuGetv3LocalRepositoryUtility.cs
Web Access
Project: src\nuget-client\src\NuGet.Core\NuGet.Protocol\NuGet.Protocol.csproj (NuGet.Protocol)
// 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 NuGet.Versioning;

namespace NuGet.Repositories
{
    public static class NuGetv3LocalRepositoryUtility
    {
        /// <summary>
        /// Take the first match on id and version.
        /// </summary>
        public static LocalPackageSourceInfo? GetPackage(
            IReadOnlyList<NuGetv3LocalRepository> repositories,
            string id,
            NuGetVersion version)
        {
            _ = repositories ?? throw new ArgumentNullException(nameof(repositories));
            _ = id ?? throw new ArgumentNullException(nameof(id));
            _ = version ?? throw new ArgumentNullException(nameof(version));

            LocalPackageInfo? package = null;

            for (var i = 0; i < repositories.Count; i++)
            {
                var repository = repositories[i];

                package = repository.FindPackage(id, version);

                if (package != null)
                {
                    return new LocalPackageSourceInfo(repository, package);
                }
            }

            return null;
        }
    }
}