Mega Code Archive

 
Categories / VB.Net / Reflection
 

Type GetProperty (String) searches for the public property with the specified name

Imports System Imports System.Reflection Class MyClass1     Private myProperty1 As Integer     Public Property MyProperty() As Integer         Get             Return myProperty1         End Get         Set(ByVal Value As Integer)             myProperty1 = Value         End Set     End Property End Class Public Class MyTypeClass     Public Shared Sub Main(ByVal args() As String)         Try             Dim myType As Type = GetType(MyClass1)             Dim myPropInfo As PropertyInfo = myType.GetProperty("MyProperty")             Console.WriteLine(myPropInfo.Name)         Catch e As NullReferenceException             Console.WriteLine("The property does not exist in MyClass.", e.Message.ToString())         End Try     End Sub End Class