是否可以从我的 AppDomain 导出 dll 定义? [英] Is it possible to export a dll definition from my AppDomain?

查看:33
本文介绍了是否可以从我的 AppDomain 导出 dll 定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码库中有我不熟悉的代码,我希望用测试用例清理和锁定.

I have code in my codebase I'm unfamiliar with that I'm looking to clean up and lock down with test cases.

我面临的问题是

A) 编写它的开发人员已经不在公司了,看起来没有使用标准,也没有进行代码审查,所以甚至没有注释(变量名为 a、b 和 c 以及函数有 200 行长......呃)

A) the developer who wrote it is no longer with the company, and it looks like no standards were used and no code review took place, so there aren't even comments (variables are named a, b, and c and functions are 200 lines long...ugh)

B) 编写它的开发人员有一种方钉圆孔的心态(即嘿,我刚刚了解到的这个新功能真的很酷,我想我会滥用它")

B) the developer who wrote it had a square-peg-round-hole mentality (i.e. "hey, this new feature I just learned about is really cool, I think I'll abuse the heck out of it")

C) 重写其功能非常混乱、无证且并非易事

C) it's incredibly messy, undocumented, and a non-trivial task to rewrite its functionality

也就是说,代码是意大利面我已经缩小了一个部分,该部分进行了大量的 Reflection.Emit 调用以动态地制作一个执行工作的 dll.完成手头的任务是难以置信的,但请参见 B 点).

That said, the code is spaghetti I've narrowed down a section that makes a large number of Reflection.Emit calls to dynamically make a dll that performs the work. This is hokey beyond belief to accomplish the task at hand, but see point B).

一半的人想说忘记这一点",只需重写代码,这样我就可以通过测试将其锁定.另一半想挽救现有的东西,因为我知道它有效,我的客户每天都在使用代码,这并不容易.

Half of me wants to say "forget this" and just rewrite the code so I can lock it down with tests. The other half wants to salvage what's there, because I know it works, my customers use the code on a daily basis, and it's not going to be easy.

有什么办法可以做类似下面的事情吗?

Is there any way to do something like the following?

foreach(Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
    if(IS_Assembly_IM_LOOKING_FOR(a))
    {
        SaveToFile(a, @"C:\Temp\MyAssembly.dll")
    }
}

这样我就可以有一个锁定"版本的程序集,我可以单独为它编写单元测试,并且有 0% 的机会因为意外修改动态创建它的代码而破坏它?

so that I can have a "locked down" version of the assembly and I can write unit tests for it in isolation and have a 0 percent chance of ever breaking it by accidentally modifying the code that dynamically creates it?

推荐答案

  1. 您可以修改创建程序集的代码,以便将其保存到磁盘(请参阅 这个问题)
  2. 您也可以使用调试器(例如 WinDbg)成功地做到这一点,它可以将程序集从内存转储到文件中.

这篇关于是否可以从我的 AppDomain 导出 dll 定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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