语言

PropertyInfo.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 System;
using System.Reflection;

class Mypropertyinfo
{
    public static int Main()
    {
        Console.WriteLine("\nReflection.PropertyInfo");

        // Get the type and PropertyInfo.
        Type MyType = Type.GetType("System.Reflection.MemberInfo");
        PropertyInfo Mypropertyinfo = MyType.GetProperty("Name");

        // Read and display the MemberType property.
        Console.Write("\nMemberType = " + Mypropertyinfo.MemberType.ToString());

        return 0;
    }
}
Imports System.Reflection

Class Mypropertyinfo

    Public Shared Function Main() As Integer
        Console.WriteLine(ControlChars.CrLf & "Reflection.PropertyInfo")

        ' Get the type and PropertyInfo.
        Dim MyType As Type = Type.GetType("System.Reflection.MemberInfo")
        Dim Mypropertyinfo As PropertyInfo = MyType.GetProperty("Name")

        ' Read and display the MemberType property.
        Console.WriteLine("MemberType = " & _
           Mypropertyinfo.MemberType.ToString())

        Return 0
    End Function
End Class

注解

此属性重写 MemberType。 因此,当你检查一组 MemberInfo 对象时(例如,返回的 GetMembers 数组)时,该 MemberType 属性仅当给定成员是一个属性时才返回 Property 。

MemberType 是派生类, MemberInfo 指定此类型的成员类型。 成员类型是构造函数、属性、字段和方法。 由于这是一个 PropertyInfo 属性,因此返回的类型是一个属性。

若要获取 MemberType 属性,请先获取类 Type。 从中 Type获取 PropertyInfo。 从中 PropertyInfo获取 MemberType 值。

适用于