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 对象的 属性。