饭太稀
This commit is contained in:
41
Entity/AssemblyHelper.cs
Normal file
41
Entity/AssemblyHelper.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
public static class AssemblyHelper
|
||||
{
|
||||
private const string HotfixDll = "Hotfix";
|
||||
private static AssemblyLoadContext? _assemblyLoadContext = null;
|
||||
|
||||
public static System.Reflection.Assembly[] Assemblies
|
||||
{
|
||||
get
|
||||
{
|
||||
var assemblies = new System.Reflection.Assembly[2];
|
||||
assemblies[0] = LoadEntityAssembly();
|
||||
assemblies[1] = LoadHotfixAssembly();
|
||||
return assemblies;
|
||||
}
|
||||
}
|
||||
|
||||
private static System.Reflection.Assembly LoadEntityAssembly()
|
||||
{
|
||||
return typeof(AssemblyHelper).Assembly;
|
||||
}
|
||||
|
||||
private static System.Reflection.Assembly LoadHotfixAssembly()
|
||||
{
|
||||
if (_assemblyLoadContext != null)
|
||||
{
|
||||
_assemblyLoadContext.Unload();
|
||||
System.GC.Collect();
|
||||
}
|
||||
|
||||
_assemblyLoadContext = new AssemblyLoadContext(HotfixDll, true);
|
||||
var dllBytes = File.ReadAllBytes(Path.Combine(Environment.CurrentDirectory, $"{HotfixDll}.dll"));
|
||||
var pdbBytes = File.ReadAllBytes(Path.Combine(Environment.CurrentDirectory, $"{HotfixDll}.pdb"));
|
||||
return _assemblyLoadContext.LoadFromStream(new MemoryStream(dllBytes), new MemoryStream(pdbBytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user