How to tell if a .NET assembly is dynamic?

后端 未结 3 1342
渐次进展
渐次进展 2021-02-06 20:57

When iterating through a set of assemblies, e.g. AppDomain.CurrentDomain.GetAssemblies(), dynamic assemblies will throw a NotSuportedException if you try to access properties li

3条回答
  •  悲&欢浪女
    2021-02-06 21:45

    To check if the assembly is dynamic:

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

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

    Update:

    In .NET 4.0, there is now a property:

    if (assembly.IsDynamic)
    

提交回复
热议问题