Module 类

定义

对模块执行反射。

public ref class Module abstract
public ref class Module abstract : System::Reflection::ICustomAttributeProvider, System::Runtime::Serialization::ISerializable
public ref class Module abstract : System::Reflection::ICustomAttributeProvider
public ref class Module : System::Reflection::ICustomAttributeProvider, System::Runtime::InteropServices::_Module, System::Runtime::Serialization::ISerializable
public ref class Module abstract : System::Reflection::ICustomAttributeProvider, System::Runtime::InteropServices::_Module, System::Runtime::Serialization::ISerializable
public abstract class Module
public abstract class Module : System.Reflection.ICustomAttributeProvider, System.Runtime.Serialization.ISerializable
public abstract class Module : System.Reflection.ICustomAttributeProvider
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
public class Module : System.Reflection.ICustomAttributeProvider, System.Runtime.InteropServices._Module, System.Runtime.Serialization.ISerializable
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class Module : System.Reflection.ICustomAttributeProvider, System.Runtime.InteropServices._Module, System.Runtime.Serialization.ISerializable
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Module : System.Reflection.ICustomAttributeProvider, System.Runtime.InteropServices._Module, System.Runtime.Serialization.ISerializable
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Module : System.Reflection.ICustomAttributeProvider, System.Runtime.Serialization.ISerializable
type Module = class
type Module = class
    interface ICustomAttributeProvider
    interface ISerializable
type Module = class
    interface ICustomAttributeProvider
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Serializable>]
type Module = class
    interface _Module
    interface ISerializable
    interface ICustomAttributeProvider
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Module = class
    interface _Module
    interface ISerializable
    interface ICustomAttributeProvider
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Module = class
    interface ISerializable
    interface ICustomAttributeProvider
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Module = class
    interface ISerializable
    interface ICustomAttributeProvider
    interface _Module
Public MustInherit Class Module
Public MustInherit Class Module
Implements ICustomAttributeProvider, ISerializable
Public MustInherit Class Module
Implements ICustomAttributeProvider
Public Class Module
Implements _Module, ICustomAttributeProvider, ISerializable
Public MustInherit Class Module
Implements _Module, ICustomAttributeProvider, ISerializable
继承
Module
派生
属性
实现

示例

下面的代码示例演示如何使用反射来获取有关模块的信息:

using System.Reflection;
using System;
public class Program {

    public static void Main() {
        Class1 c1 = new Class1();
        //  Show the current module.
        Module m = c1.GetType().Module;
        Console.WriteLine("The current module is {0}.", m.Name);

        //  List all modules in the assembly.
        Assembly curAssembly = typeof(Program).Assembly;
        Console.WriteLine("The current executing assembly is {0}.", curAssembly);

        Module[] mods = curAssembly.GetModules();
        foreach (Module md in mods) {
            Console.WriteLine("This assembly contains the {0} module", md.Name);
        }
        Console.ReadLine();
    }
}
class Class1 {
}
Imports System.Reflection

Public Class Program
    Public Shared Sub Main()

        Dim c1 As New Class1

        ' Show the current module.

        ' Note the brackets around "[Module]" to differentiate 
        ' it from the Visual Basic "Module" keyword.
        Dim m As [Module] = c1.GetType().Module
        Console.WriteLine("The current module is {0}.", m.Name)

        ' List all modules in the assembly.
        Dim curAssembly As Assembly = GetType(Program).Assembly
        Console.WriteLine("The executing assembly is {0}.", curAssembly)

        Dim mods() As [Module] = curAssembly.GetModules()

        For Each md As [Module] In mods
            Console.WriteLine("This assembly contains the {0} module", md.Name)
        Next
        Console.ReadLine()
    End Sub


End Class
Class Class1

End Class

注解

模块是可移植的可执行文件,例如 type.dll 或 application.exe,由一个或多个类和接口组成。 单个模块可包含多个命名空间,而一个命名空间可跨越多个模块。

作为一个单元部署的一个或多个模块组成一个程序集。 有关创建包含多个模块的程序集的信息,请参阅多 文件程序集

请注意,.NET Framework 模块与 Visual Basic 中的模块不同,程序员使用它在应用程序中组织函数和子例程。

构造函数

Module()

初始化 Module 类的新实例。

字段

FilterTypeName

一个 TypeFilter 对象,该对象根据名称筛选在此模块中定义的类型列表。 此字段区分大小写且为只读。

FilterTypeNameIgnoreCase

一个 TypeFilter 对象,该对象根据名称筛选在此模块中定义的类型列表。 此字段不区分大小写且为只读。

属性

Assembly

为此 Module 实例获取适当的 Assembly

CustomAttributes

获取包含此模型自定义属性的集合。

FullyQualifiedName

获取表示此模块的完全限定名和路径的字符串。

MDStreamVersion

获取元数据流版本。

MetadataToken

获取一个令牌,该令牌用于标识元数据中的模块。

ModuleHandle

获取模块的图柄。

ModuleVersionId

获取可用于区分模块的两个版本的全局唯一标识符 (UUID)。

Name

获取 String,它表示移除了路径的模块名。

ScopeName

获取表示模块名的字符串。

方法

Equals(Object)

确定此模块和指定的对象是否相等。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
FindTypes(TypeFilter, Object)

返回给定筛选器和筛选条件接受的类数组。

GetCustomAttributes(Boolean)

返回所有自定义属性。

GetCustomAttributes(Type, Boolean)

获取指定类型的自定义属性。

GetCustomAttributesData()

返回当前模块的 CustomAttributeData 对象列表,这些对象可以在只反射上下文中使用。

GetField(String)

返回具有指定名称的方法。

GetField(String, BindingFlags)

返回具有指定名称和绑定特性的字段。

GetFields()

返回在模块上定义的全局字段。

GetFields(BindingFlags)

返回在与指定绑定标志匹配的模块上定义的全局字段。

GetHashCode()

返回此实例的哈希代码。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetMethod(String)

返回具有指定名称的方法。

GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

返回具有指定名称、绑定信息、调用约定和参数类型及修饰符的方法。

GetMethod(String, Type[])

返回具有指定名称和参数类型的方法。

GetMethodImpl(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

返回符合指定条件的方法实现。

GetMethods()

返回在模块中定义的全局方法。

GetMethods(BindingFlags)

返回在与指定的绑定标志匹配的模块上定义的全局方法。

GetObjectData(SerializationInfo, StreamingContext)

提供序列化对象的 ISerializable 实现。

GetPEKind(PortableExecutableKinds, ImageFileMachine)

获取一对值,这一对值指示某个模块中代码的性质和该模块的目标平台。

GetSignerCertificate()

返回与证书(包括在此模块所属的程序集的验证码签名中)对应的 X509Certificate 对象。 如果此程序集没有进行验证码签名,则返回 null

GetType()

获取当前实例的 Type

(继承自 Object)
GetType(String)

返回指定的类型,执行区分大小写的搜索。

GetType(String, Boolean)

返回指定的类型,通过指定的区分大小写搜索模块。

GetType(String, Boolean, Boolean)

返回指定的类型,指定是否对该模块进行区分大小写的搜索;如果找不到该类型,则指定是否引发异常。

GetTypes()

返回在此模块中定义的所有类型。

IsDefined(Type, Boolean)

返回一个值,该值指示是否已将指定的特性类型应用于此模块。

IsResource()

获取一个值,该值指示此对象是否是资源。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ResolveField(Int32)

返回由指定的元数据令牌标识的字段。

ResolveField(Int32, Type[], Type[])

在由指定的泛型类型参数定义的上下文中,返回由指定的元数据令牌标识的字段。

ResolveMember(Int32)

返回由指定的元数据令牌标识的类型或成员。

ResolveMember(Int32, Type[], Type[])

在由指定的泛型类型参数定义的上下文中,返回由指定的元数据令牌标识的类型或成员。

ResolveMethod(Int32)

返回由指定的元数据令牌标识的方法或构造函数。

ResolveMethod(Int32, Type[], Type[])

在由指定的泛型类型参数定义的上下文中,返回由指定的元数据令牌标识的方法或构造函数。

ResolveSignature(Int32)

返回由元数据令牌标识的签名 Blob。

ResolveString(Int32)

返回由指定元数据令牌标识的字符串。

ResolveType(Int32)

返回由指定的元数据令牌标识的类型。

ResolveType(Int32, Type[], Type[])

在由指定的泛型类型参数定义的上下文中,返回由指定的元数据令牌标识的类型。

ToString()

返回模块的名称。

运算符

Equality(Module, Module)

指示两个 Module 对象是否相等。

Inequality(Module, Module)

指示两个 Module 对象是否不相等。

显式接口实现

_Module.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

_Module.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

_Module.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

_Module.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

ICustomAttributeProvider.GetCustomAttributes(Boolean)

返回在该成员上定义的所有自定义特性的数组(已命名的特性除外),如果没有自定义特性,则返回空数组。

ICustomAttributeProvider.GetCustomAttributes(Type, Boolean)

返回在该成员上定义、由类型标识的自定义属性数组,如果没有该类型的自定义属性,则返回空数组。

ICustomAttributeProvider.IsDefined(Type, Boolean)

指示是否在该成员上定义了一个或多个 attributeType 实例。

扩展方法

GetCustomAttribute(Module, Type)

检索应用于指定模块的指定类型的自定义特性。

GetCustomAttribute<T>(Module)

检索应用于指定模块的指定类型的自定义特性。

GetCustomAttributes(Module)

检索应用于指定模块的自定义特性集合。

GetCustomAttributes(Module, Type)

检索应用于指定模块的指定类型的自定义特性集合。

GetCustomAttributes<T>(Module)

检索应用于指定模块的指定类型的自定义特性集合。

IsDefined(Module, Type)

确定是否将指定类型的任何自定义属性应用于指定的模块。

GetModuleVersionId(Module)
HasModuleVersionId(Module)

适用于