38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
#nullable enable
|
|
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using Mono.Cecil;
|
|
|
|
namespace ShrinkEventBus.CodeGen
|
|
{
|
|
public sealed class PostProcessorReflectionImporter : DefaultReflectionImporter
|
|
{
|
|
private const string CoreLibName = "System.Private.CoreLib";
|
|
private readonly AssemblyNameReference? _corlib;
|
|
|
|
public PostProcessorReflectionImporter(ModuleDefinition module)
|
|
: base(module)
|
|
{
|
|
_corlib = module.AssemblyReferences.FirstOrDefault(
|
|
assembly => assembly.Name is "mscorlib" or "netstandard");
|
|
}
|
|
|
|
public override AssemblyNameReference ImportReference(AssemblyName reference)
|
|
{
|
|
if (_corlib != null && reference.Name == CoreLibName)
|
|
return _corlib;
|
|
|
|
return base.ImportReference(reference);
|
|
}
|
|
}
|
|
|
|
public sealed class PostProcessorReflectionImporterProvider : IReflectionImporterProvider
|
|
{
|
|
public IReflectionImporter GetReflectionImporter(ModuleDefinition module)
|
|
{
|
|
return new PostProcessorReflectionImporter(module);
|
|
}
|
|
}
|
|
}
|