Export (0) Print
Expand All

MemberInfo.ReflectedType Property

Gets the class object that was used to obtain this instance of MemberInfo.

[Visual Basic]
Public MustOverride ReadOnly Property ReflectedType As Type
[C#]
public abstract Type ReflectedType {get;}
[C++]
public: __property virtual Type* get_ReflectedType() = 0;
[JScript]
public abstract function get ReflectedType() : Type;

Property Value

The Type object through which this MemberInfo object was obtained.

Remarks

The ReflectedType property retrieves the Type object that was used to obtain this instance of MemberInfo. A MemberInfo object represents a member of a particular class or interface.

In order to obtain a MethodInfo object:

  • The Type object that represents the class or interface that supports the method is queried. This property holds a reference to that Type object.
  • If the reflected type is the same class as the declaring class, the member is defined on the declaring class, not on a base class.
  • If the MemberInfo object is a global member, (that is, it was obtained from Module.GetMethods, which returns global methods on a module), then the returned DeclaringType will be a null reference (Nothing in Visual Basic).

Example

[Visual Basic, C#, C++] The following example gets ReflectedType property for the specified type.

[Visual Basic] 
Imports System
Imports System.IO
Imports System.Reflection
Imports Microsoft.VisualBasic

Class Mymemberinfo

    Public Shared Sub Main()

        Console.WriteLine(ControlChars.Cr & "Reflection.MemberInfo")

        ' Get the Type and MemberInfo.
        Dim MyType As Type = Type.GetType("System.IO.BufferedStream")
        Dim Mymemberinfoarray As MemberInfo() = MyType.GetMembers()

        ' Get and display the DeclaringType method.
        Console.WriteLine(ControlChars.Cr & "There are {0} members in {1}:", _
           Mymemberinfoarray.Length, MyType.FullName)

        Dim Mymemberinfo As MemberInfo
        For Each Mymemberinfo In Mymemberinfoarray
            Console.WriteLine(ControlChars.Cr & Mymemberinfo.Name _
               & " reflected type - " & Mymemberinfo.ReflectedType.ToString())
        Next Mymemberinfo
    End Sub
End Class

[C#] 
using System;
using System.IO;
using System.Reflection;
 
class Mymemberinfo 
{ 
 
    public static void Main(string[] args) 
    { 
        Console.WriteLine ("\nReflection.MemberInfo");
 
        // Get the Type and MemberInfo.
        Type MyType =Type.GetType("System.IO.BufferedStream"); 
        MemberInfo[] Mymemberinfoarray = MyType.GetMembers(); 
 
        // Get and display the DeclaringType method.
        Console.Write("\nThere are {0} members in ", Mymemberinfoarray.Length); 
        Console.Write("{0}.", MyType.FullName); 
 
        foreach (MemberInfo Mymemberinfo in Mymemberinfoarray) 
        { 
            Console.Write("\n" + Mymemberinfo.Name + " reflected type - " +
                Mymemberinfo.ReflectedType);
        }
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
using namespace System::Reflection;

int main() 
{ 
    Console::WriteLine (S"\nReflection.MemberInfo");

    // Get the Type and MemberInfo.
    Type* MyType =Type::GetType(S"System.IO.BufferedStream"); 
    MemberInfo* Mymemberinfoarray[] = MyType->GetMembers(); 

    // Get and display the DeclaringType method.
    Console::Write(S"\nThere are {0} members in ", __box(Mymemberinfoarray->Length)); 
    Console::Write(S"{0}.", MyType->FullName); 

    System::Collections::IEnumerator* enum0 = Mymemberinfoarray->GetEnumerator();
    while (enum0->MoveNext())
    {
        MemberInfo* Mymemberinfo = __try_cast<MemberInfo*>(enum0->Current); 
        Console::Write(S"\n{0} reflected type - {1}", Mymemberinfo->Name, Mymemberinfo->ReflectedType);
    }
}

[Visual Basic, C#, C++] This code produces the following output:

[Visual Basic, C#, C++] Reflection.MemberInfo

[Visual Basic, C#, C++] There are 31 members in System.IO.BufferedStream.

[Visual Basic, C#, C++] WriteByte reflected type - System.IO.BufferedStream

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

MemberInfo Class | MemberInfo Members | System.Reflection Namespace

Show:
© 2014 Microsoft