CompiledAssemblyFromFile simplified

This commit is contained in:
vis2k 2021-08-28 20:51:07 +08:00
parent 523fcdec88
commit e481a3fba5

View File

@ -13,30 +13,19 @@ namespace Mirror.Weaver
public class CompiledAssemblyFromFile : ICompiledAssembly public class CompiledAssemblyFromFile : ICompiledAssembly
{ {
readonly string assemblyPath; readonly string assemblyPath;
InMemoryAssembly inMemoryAssembly;
public string Name => Path.GetFileNameWithoutExtension(assemblyPath); public string Name => Path.GetFileNameWithoutExtension(assemblyPath);
public string[] References { get; set; } public string[] References { get; set; }
public string[] Defines { get; set; } public string[] Defines { get; set; }
public InMemoryAssembly InMemoryAssembly { get; }
public CompiledAssemblyFromFile(string assemblyPath) public CompiledAssemblyFromFile(string assemblyPath)
{ {
this.assemblyPath = assemblyPath; this.assemblyPath = assemblyPath;
}
public InMemoryAssembly InMemoryAssembly
{
get
{
if (inMemoryAssembly == null)
{
byte[] peData = File.ReadAllBytes(assemblyPath); byte[] peData = File.ReadAllBytes(assemblyPath);
string pdbFileName = Path.GetFileNameWithoutExtension(assemblyPath) + ".pdb"; string pdbFileName = Path.GetFileNameWithoutExtension(assemblyPath) + ".pdb";
byte[] pdbData = File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(assemblyPath), pdbFileName)); byte[] pdbData = File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(assemblyPath), pdbFileName));
inMemoryAssembly = new InMemoryAssembly(peData, pdbData); InMemoryAssembly = new InMemoryAssembly(peData, pdbData);
}
return inMemoryAssembly;
}
} }
} }
} }