MemberInfo.MemberType 属性

定义

在派生类中重写时,获取 MemberTypes 值,该值指示成员类型 - 方法、构造函数、事件等。

public:
 abstract property System::Reflection::MemberTypes MemberType { System::Reflection::MemberTypes get(); };
public abstract System.Reflection.MemberTypes MemberType { get; }
member this.MemberType : System.Reflection.MemberTypes
Public MustOverride ReadOnly Property MemberType As MemberTypes

属性值

指示成员类型的 MemberTypes 值。

实现

示例

以下示例显示指定类的成员名称和类型。

using namespace System;
using namespace System::Reflection;
int main()
{
   Console::WriteLine( "\nReflection.MemberInfo" );
   
   // Get the Type and MemberInfo.
   Type^ MyType = Type::GetType( "System.Reflection.PropertyInfo" );
   array<MemberInfo^>^Mymemberinfoarray = MyType->GetMembers();
   
   // Get the MemberType method and display the elements.
   Console::Write( "\nThere are {0} members in ", Mymemberinfoarray->GetLength( 0 ) );
   Console::Write( "{0}.", MyType->FullName );
   for ( int counter = 0; counter < Mymemberinfoarray->Length; counter++ )
   {
      Console::Write( "\n{0}. {1} Member type - {2}", counter, Mymemberinfoarray[ counter ]->Name, Mymemberinfoarray[ counter ]->MemberType );

   }
   return 0;
}
using System;
using System.Reflection;

class Mymemberinfo
{
    public static int Main()
    {
        Console.WriteLine ("\nReflection.MemberInfo");

        // Get the Type and MemberInfo.
        Type MyType = Type.GetType("System.Reflection.PropertyInfo");
        MemberInfo[] Mymemberinfoarray = MyType.GetMembers();

        // Get the MemberType method and display the elements.
        Console.Write("\nThere are {0} members in ", Mymemberinfoarray.GetLength(0));
        Console.Write("{0}.", MyType.FullName);

        for (int counter = 0; counter < Mymemberinfoarray.Length; counter++)
        {
            Console.Write("\n" + counter + ". "
                + Mymemberinfoarray[counter].Name
                + " Member type - " +
                Mymemberinfoarray[counter].MemberType.ToString());
        }
        return 0;
    }
}
Imports System.Reflection

Class Mymemberinfo

    Public Shared Function Main() As Integer
        Console.WriteLine(ControlChars.Cr + "Reflection.MemberInfo")

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

        ' Get the MemberType method and display the elements.
        Console.Write(ControlChars.Cr + "There are {0} members in ", _
           Mymemberinfoarray.GetLength(0))
        Console.Write("{0}.", MyType.FullName)

        Dim counter As Integer
        For counter = 0 To Mymemberinfoarray.Length - 1
            Console.Write(ControlChars.CrLf + counter.ToString() + ". " _
               + Mymemberinfoarray(counter).Name _
               + " Member type - " _
               + Mymemberinfoarray(counter).MemberType.ToString())
        Next counter
        Return 0
    End Function
End Class

注解

此属性在派生类中重写,重写返回相应的成员类型。 因此,在检查一组 MemberInfo 对象(例如返回的数组 GetMembers )时, MemberType 可以使用 属性来确定任何给定成员的成员类型。

若要获取 MemberType 属性,请获取 类 Type。 从 中 Type获取 MethodInfo 数组。 从 数组中MethodInfoMemberTypes获取 。

适用于

另请参阅