MemberInfo.ReflectedType 属性

定义

获取用于获取 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中获取的 和MemberInfoMemberInfo类本身获取的 查看成员时,这些成员Object.ToString将如何ReflectedType更改,后者继承Object但不会替代 Object.ToStringMemberInfo

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

适用于