MethodInfo.MemberType 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个 MemberTypes 值,该值指示此成员是方法。
public:
 virtual property System::Reflection::MemberTypes MemberType { System::Reflection::MemberTypes get(); };public override System.Reflection.MemberTypes MemberType { get; }member this.MemberType : System.Reflection.MemberTypesPublic Overrides ReadOnly Property MemberType As MemberTypes属性值
一个 MemberTypes 值,指示此成员是方法。
实现
示例
以下示例显示指定成员的类型。
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。