feat: autoreg in runtime
This commit is contained in:
12 files changed
+357
-3
No files matched your search
@@ -0,0 +1,32 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Mono.Cecil;
|
||||
|
||||
namespace ShrinkEventBus.CodeGen
|
||||
{
|
||||
internal class PostProcessorReflectionImporter : DefaultReflectionImporter
|
||||
{
|
||||
private const string CoreLibName = "System.Private.CoreLib";
|
||||
private readonly AssemblyNameReference _corlib;
|
||||
|
||||
public PostProcessorReflectionImporter(ModuleDefinition module) : base(module)
|
||||
{
|
||||
_corlib = module.AssemblyReferences.FirstOrDefault(
|
||||
a => a.Name is "mscorlib" or "netstandard");
|
||||
}
|
||||
|
||||
public override AssemblyNameReference ImportReference(AssemblyName reference)
|
||||
{
|
||||
if (_corlib != null && reference.Name == CoreLibName)
|
||||
return _corlib;
|
||||
|
||||
return base.ImportReference(reference);
|
||||
}
|
||||
}
|
||||
|
||||
internal class PostProcessorReflectionImporterProvider : IReflectionImporterProvider
|
||||
{
|
||||
public IReflectionImporter GetReflectionImporter(ModuleDefinition module)
|
||||
=> new PostProcessorReflectionImporter(module);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user