未验证 提交 5ca80ce2 编写于 作者: J Julien Couvreur 提交者: GitHub

Add CompilationVerifier.Dump utility method (#27003)

上级 52492ac7
......@@ -78,6 +78,24 @@ internal Metadata GetMetadata()
}
}
#if NET46
public string Dump()
{
using (var testEnvironment = RuntimeEnvironmentFactory.Create(_dependencies))
{
string mainModuleFullName = Emit(testEnvironment, manifestResources: null, EmitOptions.Default);
IList<ModuleData> moduleDatas = testEnvironment.GetAllModuleData();
string mainModuleSimpleName = moduleDatas.Single(md => md.FullName == mainModuleFullName).SimpleName;
RuntimeEnvironmentUtilities.DumpAssemblyData(moduleDatas, out var dumpDir);
string modulePath = Path.Combine(dumpDir, mainModuleSimpleName + ".dll");
var decompiler = new ICSharpCode.Decompiler.CSharp.CSharpDecompiler(modulePath, new ICSharpCode.Decompiler.DecompilerSettings());
var syntaxTree = decompiler.DecompileWholeModuleAsSingleFile();
return syntaxTree.ToString();
}
}
#endif
public void Emit(string expectedOutput, int? expectedReturnCode, string[] args, IEnumerable<ResourceDescription> manifestResources, EmitOptions emitOptions, Verification peVerify, SignatureDescription[] expectedSignatures)
{
using (var testEnvironment = RuntimeEnvironmentFactory.Create(_dependencies))
......
......@@ -102,4 +102,7 @@
<PackageReference Include="System.Threading.Thread" Version="$(SystemThreadingThreadVersion)" />
<PackageReference Include="System.Xml.XmlDocument" Version="$(SystemXmlXmlDocumentVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
<PackageReference Include="ICSharpCode.Decompiler" Version="$(ICSharpCodeDecompilerVersion)" />
</ItemGroup>
</Project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册