是否有可能保存动态组装到磁盘? [英] Is it possible to save a dynamic assembly to disk?

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

问题描述

我最近买了Ayende的书建筑的DSL在嘘(买它,阅读它,它的真棒)但我来面对一个实施的问题,我想看看生成的code样子。我通常会使用反射器来看看code,但在这种情况下,组件是动态的,只在存储器中。有没有一种方法来保存动态组装到磁盘上,这样我可以反映出他们?

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?

修改/我的答案

哇,它花了一段时间回来这一个。不幸的是我留下了重要的位从原来的问题。

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

重要的一点:我使用的是 Ayende的RhinoDSL库,他建议在书上。我有机会获得嘘编译器在我DslEngine的子类,它是这样的:

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"));
    }
}

这引起编译器输出装配了我的〜\ LocalSettings \ Temp目录,然后我便可以体现出这一点。重要的是要注意,对这种变化导致程序突破的其余部分(RhinoDSL再也无法找到在内存中的程序集,因为我把它们输出到磁盘),所以这是唯一有用的作为调试工具。

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.

推荐答案

查找那里BooCompiler实例化,变的 CompileToMemory 到的 CompileToFile

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

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

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