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

指示此成员是属性的一个 MemberTypes 值。

实现

示例

下面的示例显示指定成员的类型。

using namespace System;
using namespace System::Reflection;
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 = {0}", Mypropertyinfo->MemberType );
   return 0;
}
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 值。

适用于