Module 類別

定義

在模組上進行反射。

public ref class Module abstract
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 ref class Module abstract : System::Reflection::ICustomAttributeProvider
public ref class Module abstract : System::Reflection::ICustomAttributeProvider, System::Runtime::Serialization::ISerializable
public abstract class Module
[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
public abstract class Module : System.Reflection.ICustomAttributeProvider
public abstract class Module : System.Reflection.ICustomAttributeProvider, System.Runtime.Serialization.ISerializable
type Module = class
[<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
type Module = class
    interface ICustomAttributeProvider
type Module = class
    interface ICustomAttributeProvider
    interface ISerializable
Public MustInherit Class Module
Public Class Module
Implements _Module, ICustomAttributeProvider, ISerializable
Public MustInherit Class Module
Implements _Module, ICustomAttributeProvider, ISerializable
Public MustInherit Class Module
Implements ICustomAttributeProvider
Public MustInherit Class Module
Implements 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 中的模組不同,後者是程式設計師用來組織應用程式中的函式與子程式。

建構函式

名稱 Description
Module()

初始化 Module 類別的新執行個體。

欄位

名稱 Description
FilterTypeName

一個 TypeFilter 根據名稱過濾本模組中定義型別清單的物件。 此欄位以大小寫區分且唯讀。

FilterTypeNameIgnoreCase

一個 TypeFilter 根據名稱過濾本模組中定義型別清單的物件。 此欄位不區分大小寫且唯讀。

屬性

名稱 Description
Assembly

在此實例Module中,得到適當的Assembly

CustomAttributes

會得到一個包含該模組自訂屬性的集合。

FullyQualifiedName

會得到一個字串,代表這個模組的完全限定名稱和路徑。

MDStreamVersion

取得元資料串流版本。

MetadataToken

會獲得一個標記,用來識別模組的元資料。

ModuleHandle

拿到模組的控制權。

ModuleVersionId

獲得一個通用唯一識別碼(UUID),可用來區分模組的兩個版本。

Name

會得到 String 代表移除路徑的模組名稱的 。

ScopeName

會得到一個代表模組名稱的字串。

方法

名稱 Description
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 簽章中所包含的憑證。 若集會尚未簽署 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)

回傳由元資料標記識別的簽名塊。

ResolveString(Int32)

回傳由指定元資料標記所識別的字串。

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

回傳由指定元資料標記所識別的類型,並在指定的通用類型參數所定義的上下文中。

ResolveType(Int32)

回傳由指定元資料標記所識別的類型。

ToString()

回傳模組名稱。

操作員

名稱 Description
Equality(Module, Module)

表示兩個 Module 物體是否相等。

Inequality(Module, Module)

表示兩個 Module 物體是否不相等。

明確介面實作

名稱 Description
_Module.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

_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 實例。

擴充方法

名稱 Description
GetCustomAttribute(Module, Type)

擷取指定型別的自訂屬性,套用到指定模組。

GetCustomAttribute<T>(Module)

擷取指定型別的自訂屬性,套用到指定模組。

GetCustomAttributes(Module, Type)

擷取一組指定型別的自訂屬性,這些屬性套用到指定模組上。

GetCustomAttributes(Module)

擷取一套套用到指定模組的自訂屬性集合。

GetCustomAttributes<T>(Module)

擷取一組指定型別的自訂屬性,這些屬性套用到指定模組上。

IsDefined(Module, Type)

表示是否套用特定類型的自訂屬性於特定模組。

適用於