如何判断一个.NET程序集是动态的? [英] How to tell if a .NET assembly is dynamic?

查看:203
本文介绍了如何判断一个.NET程序集是动态的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在通过一系列的组件,如迭代AppDomain.CurrentDomain.GetAssemblies(),动态组件会如果您尝试访问诸如codeBase的物业抛出NotSuportedException。你如何判断一个程序集是动态的,而不会触发和捕捉NotSupportedException异常?

When iterating through a set of assemblies, e.g. AppDomain.CurrentDomain.GetAssemblies(), dynamic assemblies will throw a NotSuportedException if you try to access properties like CodeBase. How can you tell that an assembly is dynamic without triggering and catching the NotSupportedException?

推荐答案

要检查组件是动态的:

if (assembly.ManifestModule is System.Reflection.Emit.ModuleBuilder)

这花了我一段时间才能弄清楚,所以这里的提问和回答。

This took me a while to figure out, so here it is asked and answered.

更新:

在.NET 4.0中,现在有一个特性:

In .NET 4.0, there is now a property:

if (assembly.IsDynamic)

这篇关于如何判断一个.NET程序集是动态的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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