次の方法で共有


MethodInfo.MemberType プロパティ

定義

このメンバーがメソッドであることを示す MemberTypes 値を取得します。

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

プロパティ値

このメンバーがメソッドであることを示す MemberTypes 値。

実装

次の例では、指定したメンバーの型を表示します。

using namespace System;
using namespace System::Reflection;
int main()
{
   Console::WriteLine( "Reflection.MethodInfo" );
   
   // Get the Type and MethodInfo.
   Type^ MyType = Type::GetType( "System.Reflection.FieldInfo" );
   MethodInfo^ Mymethodinfo = MyType->GetMethod( "GetValue" );
   Console::WriteLine( "{0}.{1}", MyType->FullName, Mymethodinfo->Name );
   
   // Get and display the MemberType property.
   MemberTypes Mymembertypes = Mymethodinfo->MemberType;
   if ( MemberTypes::Constructor == Mymembertypes )
   {
      Console::WriteLine( "MemberType is of type All." );
   }
   else
   if ( MemberTypes::Custom == Mymembertypes )
   {
      Console::WriteLine( "MemberType is of type Custom." );
   }
   else
   if ( MemberTypes::Event == Mymembertypes )
   {
      Console::WriteLine( "MemberType is of type Event." );
   }
   else
   if ( MemberTypes::Field == Mymembertypes )
   {
      Console::WriteLine( "MemberType is of type Field." );
   }
   else
   if ( MemberTypes::Method == Mymembertypes )
   {
      Console::WriteLine( "MemberType is of type Method." );
   }
   else
   if ( MemberTypes::Property == Mymembertypes )
   {
      Console::WriteLine( "MemberType is of type Property." );
   }
   else
   if ( MemberTypes::TypeInfo == Mymembertypes )
   {
      Console::WriteLine( "MemberType is of type TypeInfo." );
   }







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

class MyMethodInfo
{
    public static int Main()
    {
        Console.WriteLine("Reflection.MethodInfo");

        // Get the Type and MethodInfo.
        Type MyType = Type.GetType("System.Reflection.FieldInfo");
        MethodInfo Mymethodinfo = MyType.GetMethod("GetValue");
        Console.WriteLine(MyType.FullName + "." + Mymethodinfo.Name);

        // Get and display the MemberType property.
        MemberTypes Mymembertypes = Mymethodinfo.MemberType;

        if (MemberTypes.Constructor == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type All.");
        }
        else if (MemberTypes.Custom == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type Custom.");
        }
        else if (MemberTypes.Event == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type Event.");
        }
        else if (MemberTypes.Field == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type Field.");
        }
        else if (MemberTypes.Method == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type Method.");
        }
        else if (MemberTypes.Property == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type Property.");
        }
        else if (MemberTypes.TypeInfo == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type TypeInfo.");
        }

        return 0;
    }
}
Imports System.Reflection

Class MyMethodInfo

    Public Shared Function Main() As Integer
        Console.WriteLine("Reflection.MethodInfo")

        ' Get the Type and MethodInfo.
        Dim MyType As Type = Type.GetType("System.Reflection.FieldInfo")
        Dim Mymethodinfo As MethodInfo = MyType.GetMethod("GetValue")
        Console.WriteLine(MyType.FullName + "." + Mymethodinfo.Name)

        ' Get and display the MemberType property.
        Dim Mymembertypes As MemberTypes = Mymethodinfo.MemberType

        If MemberTypes.Constructor = Mymembertypes Then
            Console.WriteLine("MemberType is of type All.")

        ElseIf MemberTypes.Custom = Mymembertypes Then
            Console.WriteLine("MemberType is of type Custom.")

        ElseIf MemberTypes.Event = Mymembertypes Then
            Console.WriteLine("MemberType is of type Event.")

        ElseIf MemberTypes.Field = Mymembertypes Then
            Console.WriteLine("MemberType is of type Field.")

        ElseIf MemberTypes.Method = Mymembertypes Then
            Console.WriteLine("MemberType is of type Method.")

        ElseIf MemberTypes.Property = Mymembertypes Then
            Console.WriteLine("MemberType is of type Property.")

        ElseIf MemberTypes.TypeInfo = Mymembertypes Then
            Console.WriteLine("MemberType is of type TypeInfo.")

        End If
        Return 0
    End Function
End Class

注釈

このプロパティは をオーバーライドします MemberInfo.MemberType。 したがって、オブジェクトの MemberInfo セット (たとえば、 によって GetMembers 返される配列) MemberType を調べると、 プロパティは、特定の MemberTypes.Method メンバーがメソッドの場合にのみ を返します。

プロパティを MemberType 取得するには、まず クラス Typeを取得します。 から、 Typeを取得します MethodInfo。 から、 MethodInfoを取得します MemberType

適用対象