MemberInfo.MemberType プロパティ

定義

派生クラスでオーバーライドされると、メンバーの種類を示す MemberTypes 値を取得します。メソッド、コンストラクター、イベント、などです。When overridden in a derived class, gets a MemberTypes value indicating the type of the member - method, constructor, event, and so on.

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 値。A MemberTypes value indicating the type of member.

実装

次の例では、指定したクラスのメンバー名と型を表示します。The following example displays the member name and type of a specified class.

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

注釈

このプロパティは派生クラスでオーバーライドされ、オーバーライドは適切なメンバー型を返します。This property is overridden in derived classes, and the override returns the appropriate member type. したがって、一連の MemberInfo オブジェクト (たとえば、GetMembers によって返される配列) を調べる場合は、MemberType プロパティを使用して、特定のメンバーのメンバーの型を特定できます。Therefore, when you examine a set of MemberInfo objects - for example, the array returned by GetMembers - the MemberType property can be used to determine the member type of any given member.

MemberType プロパティを取得するには、クラス Typeを取得します。To get the MemberType property, get the class Type. Typeから、MethodInfo 配列を取得します。From the Type, get the MethodInfo array. MethodInfo 配列から、MemberTypesを取得します。From the MethodInfo array, get the MemberTypes.

適用対象

こちらもご覧ください