|
1 | 1 | /* |
2 | 2 | * COPYRIGHT: See COPYING in the top level directory |
3 | | - * PROJECT: Plugin |
4 | | - * FILE: PluginLoader/PluginLoadContext.cs |
| 3 | + * PROJECT: PluginLoader |
| 4 | + * FILE: PluginLoadContext.cs |
5 | 5 | * PURPOSE: Basic Plugin Support, Load all Plugins |
6 | 6 | * PROGRAMER: Peter Geinitz (Wayfarer) |
7 | 7 | * SOURCES: https://docs.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support |
8 | 8 | */ |
9 | 9 |
|
10 | | -using System; |
11 | 10 | using System.Reflection; |
12 | 11 | using System.Runtime.Loader; |
13 | 12 |
|
14 | | -namespace PluginLoader; |
15 | | - |
16 | | -internal sealed class PluginLoadContext : AssemblyLoadContext |
| 13 | +namespace PluginLoader |
17 | 14 | { |
18 | 15 | /// <summary> |
19 | | - /// The resolver |
20 | | - /// </summary> |
21 | | - private readonly AssemblyDependencyResolver _resolver; |
22 | | - |
23 | | - /// <inheritdoc /> |
24 | | - /// <summary> |
25 | | - /// Initializes a new instance of the <see cref="T:PluginLoader.PluginLoadContext" /> class. |
| 16 | + /// Plugin Load Context. |
26 | 17 | /// </summary> |
27 | | - /// <param name="pluginPath">The plugin path.</param> |
28 | | - public PluginLoadContext(string pluginPath) |
| 18 | + /// <seealso cref="System.Runtime.Loader.AssemblyLoadContext" /> |
| 19 | + internal sealed class PluginLoadContext : AssemblyLoadContext |
29 | 20 | { |
30 | | - _resolver = new AssemblyDependencyResolver(pluginPath); |
31 | | - } |
| 21 | + /// <summary> |
| 22 | + /// The resolver |
| 23 | + /// </summary> |
| 24 | + private readonly AssemblyDependencyResolver _resolver; |
32 | 25 |
|
33 | | - /// <inheritdoc /> |
34 | | - /// <summary> |
35 | | - /// When overridden in a derived class, allows an assembly to be resolved and loaded based on its |
36 | | - /// <see cref="AssemblyName" />. |
37 | | - /// </summary> |
38 | | - /// <param name="assemblyName">The object that describes the assembly to be loaded.</param> |
39 | | - /// <returns> |
40 | | - /// The loaded assembly, or <see langword="null" />. |
41 | | - /// </returns> |
42 | | - protected override Assembly Load(AssemblyName assemblyName) |
43 | | - { |
44 | | - var assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName); |
| 26 | + /// <inheritdoc /> |
| 27 | + /// <summary> |
| 28 | + /// Initializes a new instance of the <see cref="T:PluginLoader.PluginLoadContext" /> class. |
| 29 | + /// </summary> |
| 30 | + /// <param name="pluginPath">The plugin path.</param> |
| 31 | + public PluginLoadContext(string pluginPath) |
| 32 | + { |
| 33 | + _resolver = new AssemblyDependencyResolver(pluginPath); |
| 34 | + } |
45 | 35 |
|
46 | | - return assemblyPath != null ? LoadFromAssemblyPath(assemblyPath) : null; |
47 | | - } |
| 36 | + /// <inheritdoc /> |
| 37 | + /// <summary> |
| 38 | + /// When overridden in a derived class, allows an assembly to be resolved and loaded based on its |
| 39 | + /// <see cref="AssemblyName" />. |
| 40 | + /// </summary> |
| 41 | + /// <param name="assemblyName">The object that describes the assembly to be loaded.</param> |
| 42 | + /// <returns> |
| 43 | + /// The loaded assembly, or <see langword="null" />. |
| 44 | + /// </returns> |
| 45 | + protected override Assembly Load(AssemblyName assemblyName) |
| 46 | + { |
| 47 | + var assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName); |
48 | 48 |
|
49 | | - /// <inheritdoc /> |
50 | | - /// <summary> |
51 | | - /// Allows derived class to load an unmanaged library by name. |
52 | | - /// </summary> |
53 | | - /// <param name="unmanagedDllName"> |
54 | | - /// Name of the unmanaged library. Typically this is the filename without its path or |
55 | | - /// extensions. |
56 | | - /// </param> |
57 | | - /// <returns> |
58 | | - /// A handle to the loaded library, or <see cref="IntPtr.Zero" />. |
59 | | - /// </returns> |
60 | | - protected override IntPtr LoadUnmanagedDll(string unmanagedDllName) |
61 | | - { |
62 | | - var libraryPath = _resolver.ResolveUnmanagedDllToPath(unmanagedDllName); |
| 49 | + return assemblyPath != null ? LoadFromAssemblyPath(assemblyPath) : null; |
| 50 | + } |
| 51 | + |
| 52 | + /// <inheritdoc /> |
| 53 | + /// <summary> |
| 54 | + /// Allows derived class to load an unmanaged library by name. |
| 55 | + /// </summary> |
| 56 | + /// <param name="unmanagedDllName"> |
| 57 | + /// Name of the unmanaged library. Typically this is the filename without its path or |
| 58 | + /// extensions. |
| 59 | + /// </param> |
| 60 | + /// <returns> |
| 61 | + /// A handle to the loaded library, or <see cref="nint.Zero" />. |
| 62 | + /// </returns> |
| 63 | + protected override nint LoadUnmanagedDll(string unmanagedDllName) |
| 64 | + { |
| 65 | + var libraryPath = _resolver.ResolveUnmanagedDllToPath(unmanagedDllName); |
63 | 66 |
|
64 | | - return libraryPath != null ? LoadUnmanagedDllFromPath(libraryPath) : IntPtr.Zero; |
| 67 | + return libraryPath != null ? LoadUnmanagedDllFromPath(libraryPath) : nint.Zero; |
| 68 | + } |
65 | 69 | } |
66 | 70 | } |
0 commit comments