Mega Code Archive

 
Categories / VB.Net / Reflection
 

Type GetProperty (String, BindingFlags) searches property, using the specified binding constraints

Imports System Imports System.Reflection Module Module1     Public 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         Public Shared Sub Main()             Try                 Dim myType As Type = GetType(MyClass1)                 Dim myPropInfo As PropertyInfo = myType.GetProperty("MyProperty", BindingFlags.Public Or BindingFlags.Instance)                 Console.WriteLine(myPropInfo.Name)             Catch e As NullReferenceException                 Console.WriteLine("MyProperty does not exist in MyClass.", e.Message.ToString())             End Try         End Sub 'Main     End Class 'MyClass1 End Module 'Module1