MemberInfo.ReflectedType 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得類別物件,是用來取得這個 MemberInfo
的執行個體。
public:
abstract property Type ^ ReflectedType { Type ^ get(); };
public abstract Type? ReflectedType { get; }
public abstract Type ReflectedType { get; }
member this.ReflectedType : Type
Public MustOverride ReadOnly Property ReflectedType As Type
屬性值
Type
物件,用來取得這個 MemberInfo
物件。
實作
範例
下列程式代碼範例顯示從 型別檢視成員Object.ToString時,以及從MemberInfo類別MemberInfo本身取得的 時,如何變更,這會繼承Object但不會覆寫 。ObjectMemberInfoReflectedTypeObject.ToString
using namespace System;
using namespace System::Reflection;
int main()
{
MemberInfo^ m1 = Object::typeid->GetMethod("ToString");
MemberInfo^ m2 = MemberInfo::typeid->GetMethod("ToString");
Console::WriteLine("m1.DeclaringType: {0}", m1->DeclaringType);
Console::WriteLine("m1.ReflectedType: {0}", m1->ReflectedType);
Console::WriteLine();
Console::WriteLine("m2.DeclaringType: {0}", m2->DeclaringType);
Console::WriteLine("m2.ReflectedType: {0}", m2->ReflectedType);
//Console::ReadLine();
}
/* This code example produces the following output:
m1.DeclaringType: System.Object
m1.ReflectedType: System.Object
m2.DeclaringType: System.Object
m2.ReflectedType: System.Reflection.MemberInfo
*/
using System;
using System.Reflection;
public class Example
{
static void Main()
{
MemberInfo m1 = typeof(Object).GetMethod("ToString");
MemberInfo m2 = typeof(MemberInfo).GetMethod("ToString");
Console.WriteLine("m1.DeclaringType: {0}", m1.DeclaringType);
Console.WriteLine("m1.ReflectedType: {0}", m1.ReflectedType);
Console.WriteLine();
Console.WriteLine("m2.DeclaringType: {0}", m2.DeclaringType);
Console.WriteLine("m2.ReflectedType: {0}", m2.ReflectedType);
//Console.ReadLine();
}
}
/* This code example produces the following output:
m1.DeclaringType: System.Object
m1.ReflectedType: System.Object
m2.DeclaringType: System.Object
m2.ReflectedType: System.Reflection.MemberInfo
*/
Imports System.Reflection
Module Example
Sub Main()
Dim m1 As MemberInfo = GetType(Object).GetMethod("ToString")
Dim m2 As MemberInfo = GetType(MemberInfo).GetMethod("ToString")
Console.WriteLine("m1.DeclaringType: {0}", m1.DeclaringType)
Console.WriteLine("m1.ReflectedType: {0}", m1.ReflectedType)
Console.WriteLine()
Console.WriteLine("m2.DeclaringType: {0}", m2.DeclaringType)
Console.WriteLine("m2.ReflectedType: {0}", m2.ReflectedType)
'Console.ReadLine()
End Sub
End Module
' This code example produces the following output:
'
' m1.DeclaringType: System.Object
' m1.ReflectedType: System.Object
'
' m2.DeclaringType: System.Object
' m2.ReflectedType: System.Reflection.MemberInfo
'
備註
屬性 ReflectedType
會 Type 擷取用來取得這個 實體的物件 MemberInfo
。 如果這個物件代表繼承自基類的成員,這個MemberInfo值可能會與 屬性的值DeclaringType不同。
MemberInfo
如果 物件是全域成員 (,也就是說,如果從 Module.GetMethods 方法取得,這會傳回模組上的全域方法) ,則傳DeclaringType回的 會是 null
。