MemberInfo.MemberType プロパティ

フィールド、メソッドなどのメンバの型を取得します。

Public MustOverride ReadOnly Property MemberType As MemberTypes
[C#]
public abstract MemberTypes MemberType {get;}
[C++]
public: __property virtual MemberTypes get_MemberType() = 0;
[JScript]
public abstract function get MemberType() : MemberTypes;

プロパティ値

コンストラクタ、イベント、フィールド、メソッド、プロパティ、型情報、すべてのメンバ型、またはカスタムのメンバ型を指定する、 MemberTypes クラスの列挙値。

解説

MemberType プロパティを取得するには、 Type クラスを取得します。type から MethodInfo 配列を取得します。最後に、 MethodInfo 配列から MemberTypes を取得します。

使用例

指定したクラスのメンバの名前と型を表示する例を次に示します。

 
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

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

[C#] 
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;
    }
}


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

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

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

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

    for (int counter = 0; counter < Mymemberinfoarray->Length; counter++)
    {
        Console::Write(S"\n{0}. {1} Member type - {2}",
            __box(counter), Mymemberinfoarray[counter]->Name, __box(Mymemberinfoarray[counter]->MemberType));
    }
    return 0;
}


[JScript] 
import System;
import System.Reflection;
 
 class Mymemberinfo
 {
    public static function Main() : void
    {
       Console.WriteLine ("\nReflection.MemberInfo");
       
       //Get the Type and MemberInfo.
       var MyType : Type = Type.GetType("System.Reflection.PropertyInfo");
       var Mymemberinfoarray : MemberInfo[] = 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 (var counter : int in Mymemberinfoarray)
       {
          Console.Write("\n" + counter + ". " 
             + Mymemberinfoarray[counter].Name
             + " Member type - " +
             Mymemberinfoarray[counter].MemberType.ToString());
       }
    }
 }
 Mymemberinfo.Main();

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

MemberInfo クラス | MemberInfo メンバ | System.Reflection 名前空間 | MemberTypes