private static TLibrary FindMatchingLibrary <TLibrary>(IEnumerable <TLibrary> libraries, AssemblyName name
                                                               , StringBinaryPredicate predicate)
            where TLibrary : Library
        {
            foreach (var l in libraries)
            {
                if (predicate(l.Name, name.Name))
                {
                    return(l);
                }

                /* If the Package Name does not exactly match the Predicate,
                 * then we verify whether the Assembly File Name is a match. */

                if (l is RuntimeLibrary rl &&
                    rl.RuntimeAssemblyGroups.Any(
                        g => g.AssetPaths.Select(GetFileNameWithoutExtension)
                        .Any(x => predicate(x, name.Name))
                        )
                    )
                {
                    return(l);
                }
            }

            return(null);
        }
        private Assembly OnResolvingLoadContextAssemblyReference(AssemblyLoadContext loadContext, AssemblyName assemblyName
                                                                 , StringBinaryPredicate predicate)
        {
            bool TryResolveAssemblyPaths(out IEnumerable <string> assemblyPaths)
            {
                // ReSharper disable once RedundantEmptyObjectOrCollectionInitializer
                var paths = (List <string>)(assemblyPaths = new List <string> {
                });

                var rl = FindMatchingLibrary(Context.RuntimeLibraries, assemblyName, predicate);

                if (rl == null)
                {
                    return(false);
                }

                var groups = rl.RuntimeAssemblyGroups;

                var cl = new CompilationLibrary(rl.Type, rl.Name, rl.Version, rl.Hash
                                                , groups.SelectMany(g => g.AssetPaths), rl.Dependencies, rl.Serviceable);

                return(Resolver.TryResolveAssemblyPaths(cl, paths) && assemblyPaths.Any());
            }

            if (TryResolveAssemblyPaths(out var resolvedPaths))
            {
                return(resolvedPaths.Select(loadContext.LoadFromAssemblyPath).FirstOrDefault());
            }

            // TODO: TBD: which, it would seem, `additional´ reference paths are intended to augment the naturally resolved DC.
            return(AdditionalReferencePaths.Select(GetFileNameWithoutExtension)
                   .Where(f => predicate(f, assemblyName.Name))
                   .Select(loadContext.LoadFromAssemblyPath).FirstOrDefault());
        }