-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add class to load assembly and resolve dependencies for each plugin
- Loading branch information
Showing
2 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.Loader; | ||
|
||
namespace Flow.Launcher.Core.Plugin | ||
{ | ||
internal class PluginAssemblyLoader : AssemblyLoadContext | ||
{ | ||
private readonly AssemblyDependencyResolver dependencyResolver; | ||
|
||
private readonly AssemblyName assemblyName; | ||
|
||
internal PluginAssemblyLoader(string assemblyFilePath) | ||
{ | ||
dependencyResolver = new AssemblyDependencyResolver(assemblyFilePath); | ||
assemblyName = new AssemblyName(Path.GetFileNameWithoutExtension(assemblyFilePath)); | ||
} | ||
|
||
internal Assembly LoadAssemblyAndDependencies() | ||
{ | ||
return LoadFromAssemblyName(assemblyName); | ||
} | ||
|
||
protected override Assembly Load(AssemblyName assemblyName) | ||
{ | ||
string assemblyPath = dependencyResolver.ResolveAssemblyToPath(assemblyName); | ||
|
||
if (assemblyPath != null) | ||
{ | ||
return LoadFromAssemblyPath(assemblyPath); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
internal Type FromAssemblyGetTypeOfInterface(Assembly assembly, Type type) | ||
{ | ||
var allTypes = assembly.ExportedTypes; | ||
|
||
return allTypes.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(type)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters