This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Mono.Cecil;
|
||||
|
||||
namespace ShrinkShared.CodeGen
|
||||
{
|
||||
internal 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(reference => reference.Name is "mscorlib" or "netstandard");
|
||||
}
|
||||
|
||||
public override AssemblyNameReference ImportReference(AssemblyName reference)
|
||||
{
|
||||
if (_corlib != null && reference.Name == CoreLibName)
|
||||
return _corlib;
|
||||
|
||||
return base.ImportReference(reference);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class PostProcessorReflectionImporterProvider : IReflectionImporterProvider
|
||||
{
|
||||
public IReflectionImporter GetReflectionImporter(ModuleDefinition module)
|
||||
=> new PostProcessorReflectionImporter(module);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user