RSS

Reflection in .Net

11 Mar

Reflection

All .NET assemblies have metadata information stored about the types defined in modules. This
metadata information can be accessed by mechanism called as “Reflection”.System. Reflection
can be used to browse through the metadata information.
Using reflection you can also dynamically invoke methods using System.Type.Invokemember.
Below is sample source code 

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Pobjtype As Type
        Dim PobjObject As Object
        Dim PobjButtons As New Windows.Forms.Button()
        Pobjtype = PobjButtons.GetType()
        For Each PobjObject In Pobjtype.GetMembers
            LstDisplay.Items.Add(PobjObject.ToString())
        Next
    End Sub
End Class

Sample source code uses reflection to browse through “Button” class of “Windows.Forms”. If
you compile and run the program following is output as shown in “Sample Reflection Display”.
Using reflection you can also dynamically invoke a method using “System.Type.InvokeMember”.

Advertisements
 
Leave a comment

Posted by on March 11, 2011 in Uncategorized

 

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

 
%d bloggers like this: