8.2版本上传
This commit is contained in:
@@ -1,20 +1,23 @@
|
||||
using dnlib.DotNet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HybridCLR.Editor.Meta
|
||||
{
|
||||
public abstract class AssemblyCacheBase : IDisposable
|
||||
public abstract class AssemblyCacheBase
|
||||
{
|
||||
private readonly IAssemblyResolver _assemblyPathResolver;
|
||||
private readonly ModuleContext _modCtx;
|
||||
private readonly AssemblyResolver _asmResolver;
|
||||
private bool disposedValue;
|
||||
private bool _loadedNetstandard;
|
||||
|
||||
|
||||
public ModuleContext ModCtx => _modCtx;
|
||||
|
||||
public Dictionary<string, ModuleDefMD> LoadedModules { get; } = new Dictionary<string, ModuleDefMD>();
|
||||
|
||||
private readonly List<ModuleDefMD> _loadedModulesIncludeNetstandard = new List<ModuleDefMD>();
|
||||
@@ -28,6 +31,17 @@ namespace HybridCLR.Editor.Meta
|
||||
_asmResolver.UseGAC = false;
|
||||
}
|
||||
|
||||
|
||||
public ModuleDefMD TryLoadModule(string moduleName, bool loadReferenceAssemblies = true)
|
||||
{
|
||||
string dllPath = _assemblyPathResolver.ResolveAssembly(moduleName, false);
|
||||
if (string.IsNullOrEmpty(dllPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return LoadModule(moduleName, loadReferenceAssemblies);
|
||||
}
|
||||
|
||||
public ModuleDefMD LoadModule(string moduleName, bool loadReferenceAssemblies = true)
|
||||
{
|
||||
// Debug.Log($"load module:{moduleName}");
|
||||
@@ -75,33 +89,11 @@ namespace HybridCLR.Editor.Meta
|
||||
private ModuleDefMD DoLoadModule(string dllPath)
|
||||
{
|
||||
//Debug.Log($"do load module:{dllPath}");
|
||||
ModuleDefMD mod = ModuleDefMD.Load(dllPath, _modCtx);
|
||||
ModuleDefMD mod = ModuleDefMD.Load(File.ReadAllBytes(dllPath), _modCtx);
|
||||
mod.EnableTypeDefFindCache = true;
|
||||
_asmResolver.AddToCache(mod);
|
||||
_loadedModulesIncludeNetstandard.Add(mod);
|
||||
return mod;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
foreach (var mod in _loadedModulesIncludeNetstandard)
|
||||
{
|
||||
mod.Dispose();
|
||||
}
|
||||
_loadedModulesIncludeNetstandard.Clear();
|
||||
LoadedModules.Clear();
|
||||
}
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user