PropertyInfoからはプロパティのget
アクセサ/set
アクセサに対応するMethodInfoをそれぞれ個別に取得することができます。 それぞれGetMethodプロパティ/SetMethodプロパティプロパティを参照することでMethodInfoとして取得できます。 読み取り専用/書き込み専用プロパティの場合はnull
/Nothing
が返されます。
PropertyInfoからプロパティのアクセサメソッドを取得する
Imports System
Imports System.Reflection
Class C
Public Property P As Integer
End Class
Class Sample
Shared Sub Main()
Dim t As Type = GetType(C)
Dim p As PropertyInfo = t.GetProperty("P") ' プロパティPのPropertyInfoを取得
Dim getter As MethodInfo = p.GetMethod ' プロパティPのGetアクセサメソッドを取得
Dim setter As MethodInfo = p.SetMethod ' プロパティPのSetアクセサメソッドを取得
Console.WriteLine(getter)
Console.WriteLine(setter)
End Sub
End Class
実行結果
Int32 get_P() Void set_P(Int32)