Dynamically Calling Methods
page 3 of 7
by . .
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 29499/ 60

Getting Information About Types

In the following examples, I will be using a simple ASP.NET page with code-behind (because in code-behind the class is clearly defined for you).

GetType returns a Type class with information about a particular type. Examine the following code -

Public Class WebForm3
Inherits
System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim
mtype As System.Type = GetType(WebForm3)
...

mtype now contains information about WebForm3. And if it were to do something like -

Response.Write(mtype.Assembly)
Response.Write("<br>")
Response.Write(mtype.FullName)
Response.Write("<br>")
Response.Write("<table border=""1"">")
Dim
member As System.Reflection.MemberInfo
For
Each member In mtype.GetMembers
Response.Write("<tr><td>")
Response.Write(member.Name)
Response.Write("</td><td>")
Response.Write(member.MemberType.ToString())
Response.Write("</td></tr>")
Next
Response.Write("</table>")

Live Demo

You will get a table of every single member in the Type. See the live demo.

I probably jumped ahead a bit with the GetMembers call, but all you need to know about it is that it returns an array of MemberInfo objects that contain information about every member in the type. If you take a look at the demo, you will see a lot of methods and properties that you didn't know existed. This is because it not only takes WebForm3, but also -

  • System.Web.UI.Page
  • System.Web.UI.TemplateControl
  • System.Web.UI.Control
  • System.Object

Because that is how far back the inheritance goes on WebForm3.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-16 4:44:07 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search