有没有一种简单的方法来识别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阻塞?
发布于 2010-09-15 04:27:22
这应该是可行的:
if (assembly is System.Reflection.Emit.AssemblyBuilder) {
// It's dynamic
//...
}发布于 2010-09-15 04:23:03
Assembly.IsDynamic没有回答你的问题吗?这可能是.Net 4.0中的新特性。
https://stackoverflow.com/questions/3712559
复制相似问题