MemberInfo、MethodInfo、FieldInfo 和 PropertyInfo
使用 MemberInfo、MethodInfo、FieldInfo 或 PropertyInfo 对象可获取有关类型的方法、属性、事件、字段的信息。
以下示例使用 MemberInfo 来列出 System.IO.File 类中的成员数量并使用 System.Type.IsPublic 属性来确定该类的可见性。
[Visual Basic]
Option Explicit
Option Strict
Imports System
Imports System.IO
Imports System.Reflection
Imports Microsoft.VisualBasic
Class Mymemberinfo
    Public Shared Sub Main()
        Console.WriteLine(ControlChars.Cr & "Reflection.MemberInfo")
        ' Gets the Type and MemberInfo.
        Dim MyType As Type = Type.GetType("System.IO.File")
        Dim Mymemberinfoarray As MemberInfo() = MyType.GetMembers()
        ' Gets and displays the DeclaringType method. 
        Console.WriteLine(ControlChars.Cr & "There are {0} members in {1}.", Mymemberinfoarray.Length, MyType.FullName)
        Console.WriteLine("{0}.", MyType.FullName)
        If MyType.IsPublic Then
            Console.WriteLine("{0} is public.", MyType.FullName)
        End If
    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");
        // Gets the Type and MemberInfo.
        Type MyType =Type.GetType("System.IO.File");
        MemberInfo[] Mymemberinfoarray = MyType.GetMembers(); 
        // Gets and displays the DeclaringType method. 
        Console.WriteLine("\nThere are {0} members in {1}.", 
            Mymemberinfoarray.Length, MyType.FullName);
        Console.WriteLine("{0}.", MyType.FullName); 
        if (MyType.IsPublic)
        {
            Console.WriteLine("{0} is public.", MyType.FullName);
        }
    }
}