Mega Code Archive

 
Categories / VB.Net Tutorial / Reflection
 

Displays the public or non-public get accessor for the specified property

Imports System Imports System.Reflection Imports Microsoft.VisualBasic Public Class Myproperty     Private myCaption As String = "A Default caption"     Public Property Caption() As String         Get             Return myCaption         End Get         Set(ByVal Value As String)             If myCaption <> value Then                 myCaption = value             End If         End Set     End Property End Class Class Mypropertyinfo     Public Shared Function Main() As Integer         ' Get the type and PropertyInfo for two separate properties.         Dim MyTypea As Type = Type.GetType("Myproperty")         Dim Mypropertyinfoa As PropertyInfo = MyTypea.GetProperty("Caption")         Dim MyTypeb As Type = Type.GetType("System.Reflection.MethodInfo")         Dim Mypropertyinfob As PropertyInfo = MyTypeb.GetProperty("MemberType")         Console.WriteLine(MyTypea.FullName)         Console.WriteLine(Mypropertyinfoa.Name)         Console.WriteLine(Mypropertyinfoa.GetGetMethod().ToString())                  Console.WriteLine(MyTypeb.FullName)         Console.WriteLine(Mypropertyinfob.Name)         Console.WriteLine(Mypropertyinfob.GetGetMethod().ToString())         Dim Mygetmethodinfoa As MethodInfo = Mypropertyinfoa.GetGetMethod()         Console.WriteLine(Mypropertyinfoa.Name)         Console.WriteLine(Mygetmethodinfoa.ReturnType.ToString())         Dim Mygetmethodinfob As MethodInfo = Mypropertyinfob.GetGetMethod()         Console.WriteLine(Mypropertyinfob.Name)         Console.WriteLine(Mygetmethodinfob.ReturnType.ToString())         Return 0     End Function End Class