【发布时间】:2016-02-13 23:02:29
【问题描述】:
我能够从当前域中收集所有类型调用这个:
var types = AppDomain.CurrentDomain
.GetAssemblies()
.SelectMany(x => x.GetTypes())
.ToList();
假设没有抛出异常。不过,我想模拟ReflectionTypeLoadException 在该过程中被抛出。
如何破坏我的代码中的任何现有类型以使此异常发生?
或者,如果无法实现上述目标,我如何动态创建具有某些损坏类型的人工程序集来感染域(当前或新)?特别是,我正在寻找有关以下Infect() 方法实施的一些线索:
Infect(AppDomain.CurrentDomain); // inject corrupted type
try
{
var types = AppDomain.CurrentDomain
.GetAssemblies()
.SelectMany(x => x.GetTypes())
.ToList();
}
catch (ReflectionTypeLoadException e)
{
// done
}
【问题讨论】:
-
是为了单元测试吗?
标签: c# .net reflection .net-assembly appdomain