MemberInfo.Module 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得用於定義型別的模組,該型別宣告以目前 MemberInfo 表示的成員。
public:
virtual property System::Reflection::Module ^ Module { System::Reflection::Module ^ get(); };
public virtual System.Reflection.Module Module { get; }
member this.Module : System.Reflection.Module
Public Overridable ReadOnly Property Module As Module
屬性值
用於定義型別的 Module,該型別宣告以目前 MemberInfo 表示的成員。
例外狀況
這個方法尚未實作。
範例
下列程式代碼範例會宣告繼承 Object 和覆寫 的 Object.ToString類別。 此範例會 MethodInfo 取得 類別之 ToString
方法和繼承 GetHashCode 方法的物件,並顯示宣告兩個方法之模組的名稱。
using namespace System;
using namespace System::Reflection;
public ref class Test
{
public:
virtual String^ ToString() override
{
return "An instance of class Test!";
}
};
int main()
{
Test^ target = gcnew Test();
MethodInfo^ toStringInfo = target->GetType()->GetMethod("ToString");
Console::WriteLine("{0} is defined in {1}", toStringInfo->Name,
toStringInfo->Module->Name);
MethodInfo^ getHashCodeInfo = target->GetType()->GetMethod("GetHashCode");
Console::WriteLine("{0} is defined in {1}", getHashCodeInfo->Name,
getHashCodeInfo->Module->Name);
}
/*
* This example produces the following console output:
*
* ToString is defined in source.exe
* GetHashCode is defined in mscorlib.dll
*/
using System;
using System.Reflection;
public class Test
{
public override string ToString()
{
return "An instance of class Test!";
}
}
public class Example
{
public static void Main()
{
Test t = new Test();
MethodInfo mi = t.GetType().GetMethod("ToString");
Console.WriteLine("{0} is defined in {1}", mi.Name, mi.Module.Name);
mi = t.GetType().GetMethod("GetHashCode");
Console.WriteLine("{0} is defined in {1}", mi.Name, mi.Module.Name);
}
}
/* This example produces code similar to the following:
ToString is defined in source.exe
GetHashCode is defined in mscorlib.dll
*/
Imports System.Reflection
Public Class Test
Public Overrides Function ToString() As String
Return "An instance of class Test!"
End Function
End Class
Public Class Example
Public Shared Sub Main()
Dim t As New Test()
Dim mi As MethodInfo = t.GetType().GetMethod("ToString")
Console.WriteLine(mi.Name & " is defined in " & mi.Module.Name)
mi = t.GetType().GetMethod("GetHashCode")
Console.WriteLine(mi.Name & " is defined in " & mi.Module.Name)
End Sub
End Class
' This example produces code similar to the following:
'
'ToString is defined in source.exe
'GetHashCode is defined in mscorlib.dll
備註
這個屬性會以方便的方式提供。 它相當於使用 DeclaringType 屬性來取得宣告方法的類型,然後呼叫 Module 所產生 Type 物件的屬性。