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
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
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

获取适用于此实例的Assembly相应Module实例。

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, BindingFlags)

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

GetField(String)

返回具有指定名称的字段。

GetFields()

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

GetFields(BindingFlags)

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

GetHashCode()

返回此实例的哈希代码。

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

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

GetMethod(String, Type[])

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

GetMethod(String)

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

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

根据指定的条件返回方法实现。

GetMethods()

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

GetMethods(BindingFlags)

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

GetObjectData(SerializationInfo, StreamingContext)
已过时.

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

GetPEKind(PortableExecutableKinds, ImageFileMachine)

获取一对值,该值指示模块中的代码的性质以及模块面向的平台。

GetSignerCertificate()

返回一个 X509Certificate 对象,该对象对应于此模块所属程序集的 Authenticode 签名中包含的证书。 如果程序集尚未签名验证码, null 则返回。

GetType()

获取当前实例的 Type

(继承自 Object)
GetType(String, Boolean, Boolean)

返回指定的类型,指定是否对模块进行区分大小写的搜索,以及是否在找不到该类型时引发异常。

GetType(String, Boolean)

返回指定类型,使用指定的大小写搜索模块。

GetType(String)

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

GetTypes()

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

IsDefined(Type, Boolean)

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

IsResource()

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

MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ResolveField(Int32, Type[], Type[])

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

ResolveField(Int32)

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

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

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

ResolveMember(Int32)

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

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

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

ResolveMethod(Int32)

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

ResolveSignature(Int32)

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

ResolveString(Int32)

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

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

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

ResolveType(Int32)

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

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, Type)

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

GetCustomAttributes(Module)

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

GetCustomAttributes<T>(Module)

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

GetModuleVersionId(Module)

对模块执行反射。

HasModuleVersionId(Module)

对模块执行反射。

IsDefined(Module, Type)

指示指定类型的自定义属性是否应用于指定的模块。

适用于