Bagikan melalui


PropertyInfo.MemberType Properti

Definisi

Mendapatkan nilai yang MemberTypes menunjukkan bahwa anggota ini adalah properti.

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

Nilai Properti

Nilai MemberTypes yang menunjukkan bahwa anggota ini adalah properti.

Penerapan

Contoh

Contoh berikut menampilkan jenis anggota yang ditentukan.

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

Keterangan

Properti ini mengambil alih MemberType. Oleh karena itu, ketika Anda memeriksa sekumpulan MemberInfo objek - misalnya, array yang dikembalikan oleh GetMembers - MemberType properti hanya mengembalikan Property ketika anggota tertentu adalah properti.

MemberType adalah kelas turunan dari MemberInfo dan menentukan jenis anggota ini. Jenis anggota adalah konstruktor, properti, bidang, dan metode. Karena ini adalah PropertyInfo properti, jenis yang dikembalikan adalah properti .

Untuk mendapatkan MemberType properti, pertama-tama dapatkan kelas Type. TypeDari , dapatkan PropertyInfo. PropertyInfoDari , dapatkan nilainyaMemberType.

Berlaku untuk