mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
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));
|
|
}
|
|
}
|
|
}
|