是否有一种简单的方法来识别Reflection.Emit生成的程序集?处理加载到应用程序域中的所有程序集时,动态生成的程序集的Assembly
实例的行为与标准程序集的行为不同。例如,访问CodeBase
属性会导致异常:
string codeBase;
try
{
codeBase = assembly.CodeBase;
}
catch(NotSupportedException)
{
// assemblies generated via Reflection.Emit throw an exception when CodeBase is accessed
codeBase = null;
}
有没有更好的方法来识别这种情况并避免try … catch
阻止?
答案 0 :(得分:1)
Assembly.IsDynamic不回答你的问题吗?它可能是.Net 4.0中的新功能。
答案 1 :(得分:0)
这应该有效:
if (assembly is System.Reflection.Emit.AssemblyBuilder) {
// It's dynamic
//...
}