Posted by: Sourav | September 2, 2016

Reflection Example in VB,VB Teacher Sourav,Kolkata 09748184075


Public Class customer
Private id As Integer
Private name As String
Public Property manipulateid(ByVal id As Integer) As Integer
Get
Return Me.id

End Get
Set(ByVal value As Integer)
Me.id = value

End Set
End Property
Public Property manipulatename(ByVal name As String) As String
Get
Return Me.name

End Get
Set(ByVal value As String)
Me.name = value

End Set
End Property
Sub New()
Me.id = -1
Me.name = String.Empty

End Sub
Sub New(ByVal id As Integer, ByVal name As String)
Me.id = id
Me.name = name

End Sub
Public Sub printid()
Console.WriteLine(“ID= {0}”, Me.id)

End Sub
Public Sub printname()
Console.WriteLine(“Name= {0}”, Me.name)

End Sub
End Class

 

Option Strict On
Option Explicit On
Imports System
Imports System.Reflection
Module Module1

Sub Main()
‘Dim t As Type = Type.GetType(“Sourav.customer”)
Dim t As Type = GetType(customer)

Console.WriteLine(“The full name of the class by reflection ” + t.FullName)
Console.WriteLine(“Just the name of the class by reflection ” + t.Name)
Console.WriteLine(“The namespace of the class by reflection ” + t.Namespace)
Console.WriteLine(“The properties of the class by reflection “)
Dim properties() As PropertyInfo = t.GetProperties()
For Each propertyelem As PropertyInfo In properties

Console.WriteLine(propertyelem.PropertyType.Name & ” ” & propertyelem.Name)
Next
Console.WriteLine(“The methods of the class by reflection “)
Dim methods() As MethodInfo = t.GetMethods()
For Each method As MethodInfo In methods

Console.WriteLine(method.ReturnType.Name & ” ” & method.Name)
Next

Console.WriteLine(“The constructors of the class by reflection “)
Dim constructors() As ConstructorInfo = t.GetConstructors()
For Each constructor As ConstructorInfo In constructors

Console.WriteLine(constructor.ToString)
Next

Console.ReadLine()

End Sub

End Module

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: