/// <summary> /// Constructs a new NativeLibrary using the specified library loader. /// </summary> /// <param name="names">An ordered list of names to attempt to load.</param> /// <param name="loader">The loader used to open and close the library, and to load function pointers.</param> /// <param name="pathResolver">The path resolver, used to identify possible load targets for the library.</param> public UnmanagedLibrary(string[] names, LibraryLoader loader, PathResolver pathResolver) { _loader = loader; Handle = _loader.LoadNativeLibrary(names, pathResolver); }
private static void ThrowLibNotFoundAny(string[] names, PathResolver pathResolver) { throw new FileNotFoundException ($"Could not find or load the native library from any name: [ {string.Join(", ", names.Select(x => x + " Attempted: (" + string.Join(", ", pathResolver.EnumeratePossibleLibraryLoadTargets(x).Select(x2 => "\"" + x2 + "\"")) + ")"))} ]", names[0]); }
/// <summary> /// Loads a native library by name and returns an operating system handle to it. /// </summary> /// <param name="name">The name of the library to open.</param> /// <param name="pathResolver">The path resolver to use.</param> /// <returns>The operating system handle for the shared library.</returns> public nint LoadNativeLibrary(string name, PathResolver pathResolver) { if (string.IsNullOrEmpty(name)) { ThrowParameterNotNullOrEmpty(nameof(name)); return(default);
private static void ThrowLibNotFound(string name, PathResolver resolver) { throw new FileNotFoundException($"Could not find or load the native library: {name} Attempted: {string.Join(", ", resolver.EnumeratePossibleLibraryLoadTargets(name).Select(x => "\"" + x + "\""))}", name); }