是否可以将动态程序集保存到磁盘? [英] Is it possible to save a dynamic assembly to disk?

查看:216
本文介绍了是否可以将动态程序集保存到磁盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近买了Ayende的书籍在Boo建立DSLs (购买,阅读它,真棒)但是我反对实现问题,我想看看生成的代码是什么样的。我通常会使用反射器来查看代码,但在这种情况下,程序集是动态的,只在内存中。有没有办法将动态程序集保存到磁盘,以便我可以反映出来?



编辑/我的答案

$ b哇,花一点时间回到这个。不幸的是,我从原来的问题中留下了重要的一点。



重要位:我正在使用 Ayende的RhinoDSL库,正如他在书中所推荐的那样。我可以访问我的DslEngine子类中的boo编译器,如下所示:

  public class JobEngine:DslEngine 
{
protected override void CustomizeCompiler(Boo.Lang.Compiler.BooCompiler compiler,Boo.Lang.Compiler.CompilerPipeline pipeline,string [] urls)
{
pipeline.Insert(1,new ImplicitBaseClassCompilerStep (typeof(JobBase),Prepare,JobLanguage,log4net,Quartz));
}
}

要改变最少,得到我想要的东西添加一行...

  public class JobEngine:DslEngine 
{
protected override void CustomizeCompiler Boo.Lang.Compiler.BooCompiler编译器,Boo.Lang.Compiler.CompilerPipeline管道,string [] urls)
{
compiler.Parameters.GenerateInMemory = false; //< --- This one。
pipeline.Insert(1,new ImplicitBaseClassCompilerStep(typeof(JobBase),Prepare,JobLanguage,log4net,Quartz));
}
}

这导致编译器将程序集输出到〜 \LocalSettings\Temp目录,然后我可以反映它。重要的是要注意,这种改变会导致程序的其余部分中断(RhinoDSL可能不再在内存中找到程序集,因为我将它们输出到磁盘),所以这只能用作调试工具。

解决方案

查找BooCompiler实例化的位置,从 CompileToMemory CompileToFile


I recently bought Ayende's book Building DSLs in Boo (buy it, read it, it's awesome) but I'm coming up against an implementation problem and I want to see what the generated code looks like. I would normally use reflector to look at the code but in this case the assemblies are dynamic and only in memory. Is there a way to save dynamic assemblies to disk so that I can reflect them?

EDIT / My Answer:

Wow, it took awhile to come back to this one. Unfortunately I left an important bit out from the original question.

Important Bit: I'm using Ayende's RhinoDSL library as he recommends in the book. I have access to the boo compiler in my subclass of DslEngine which looks like this:

public class JobEngine : DslEngine
{
    protected override void CustomizeCompiler(Boo.Lang.Compiler.BooCompiler compiler, Boo.Lang.Compiler.CompilerPipeline pipeline, string[] urls)
    {
        pipeline.Insert(1, new ImplicitBaseClassCompilerStep(typeof (JobBase), "Prepare", "JobLanguage", "log4net", "Quartz"));
    }
}

To change the least and get what I wanted I needed to add one line...

public class JobEngine : DslEngine
{
    protected override void CustomizeCompiler(Boo.Lang.Compiler.BooCompiler compiler, Boo.Lang.Compiler.CompilerPipeline pipeline, string[] urls)
    {
        compiler.Parameters.GenerateInMemory = false; // <--- This one.
        pipeline.Insert(1, new ImplicitBaseClassCompilerStep(typeof (JobBase), "Prepare", "JobLanguage", "log4net", "Quartz"));
    }
}

This caused the compiler to output the assembly to my ~\LocalSettings\Temp directory and then I could then reflect it. It's important to note that making that change caused the rest of the program to break (RhinoDSL could no longer find the assemblies in memory because I output them to disk), so this is only useful as a debugging tool.

解决方案

Look up where BooCompiler is instantiated, change the pipeline from CompileToMemory to CompileToFile

这篇关于是否可以将动态程序集保存到磁盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆