Follows the steps:
Step 1. Create a project with asp.net empty web application and name it "ReflectApp".
Step 2. Create a web form in it and paste following code and run it.
Public Class WebForm1 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim currentAppName = System.Reflection.Assembly.Load("ReflectApp") For Each type As Type In currentAppName.GetTypes If type.Name = "Customer" Then Dim o As Object = Activator.CreateInstance(type) Dim mInfo As System.Reflection.MethodInfo = type.GetMethod("getName") If mInfo IsNot Nothing Then Dim result As String = mInfo.Invoke(o, Nothing) Response.Write(result) End If Exit For End If Next End Sub Public Class Customer Private Property _Name As String Sub New() _Name = "John Miller" End Sub Public Function getName() As String Return _Name End Function End Class End Class
Result will be: John Miller
You can debug and see how it works.
No comments:
Post a Comment