VisualBuilder
  Home > Dotnet > Tutorials > Reflection: Inspection of a Type\'s Metadata - .NET Tutorial
Tell a friend
Link to us
Total Members
      Members: 84606
     
Sitemap Forum Chat
Home
.NET Tutorial Home
1 . Overview of .Net Framework
2 . .Net Components:
3 . CLR (Common Language Runtime)
4 . Steps to Run a program in CLR
5 . Assembly
6 . GAC (Global Assembly CACHE)
7 . Strong Name in .Net Assembly
8 . ILDASM: Intermediate Language Disassembler in .Net
9 . Custom Attributes in .Net
10 . Application Domain in .Net
11 . Code Access Security in .Net
12 . Type System in .Net -1
13 . Type System in .Net -2
14 . Reflection: Inspection of a Type\'s Metadata
15 . Introduction to Generics
16 . Generic Classes and Methods
17 . Generic Methods in .Net 2.0
18 . Overview of Inheritance in Generics classes
19 . Connection pooling in .Net Applications
20 . Deployment in .Net
 
Dotnet Group Home
Dotnet Discussion (9)
Dotnet Members (2825)
Dotnet Resources
Dotnet Source Code (0)
Dotnet Articles (0)
Dotnet Blogs
Dotnet Jobs
Dotnet Components (2)
Dotnet Books
Dotnet Websites (43)
Dotnet News (186)
Dotnet Q & A (3)
- Dotnet Ask Question
- Dotnet Questions
- Dotnet Unanswered Questions
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (432 )
Source Code (3217 )
Articles (11 )
Components (1589 )
News (880 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise


Dotnet Tutorial
 Reflection: Inspection of a Type\'s Metadata
  << Prev: Type System in .Net -2 Next: Introduction to Generics >>

The act of inspecting a type's metadata at runtime is called reflection, and it is a fundamental facility of the CLR. 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.


 


In fact, reflection is so fundamental that the type system's base class, System.Object , has a method GetType specifically designed to facilitate this inspection. The GetType() method returns a singleton Type object for the type on which it was invoked. The Type class provides a means for developers to access the metadata of the type it describes.Reflection provides dynamically invoke methods using System.Type.Invokemember and access the metadata information at runtime.


 


Reflection Classes


 


The MemberInfo and Type classes are the foundation for the reflection facilities. The Type class provides several methods and properties to permit inspection of a type's metadata. It inherits from the MemberInfo class, which in turn inherits from Object . The diagram shows the reflection class hirarchy.


 




 


MemberInfo Class


The MemberInfo class serves as a base class for many of the reflection " Info " classes. The MemberInfo class is abstract. Subtypes of MemberInfo which include the following classes:



  • EventInfo:- a class whose objects represent events of a type. Example properties and methods of this type include Name , GetAddMethod , GetRaiseMethod , and GetRemoveMethod.

  • FieldInfo:- a class whose objects represent fields of the type. Example properties and methods of this type include Name , FieldType , and GetValue.

  • MethodBase:- a base class for representing methods on a class, such as constructors and methods. Example properties and methods include IsConstructor , GetParameters , and Invoke.

  • PropertyInfo:- a class whose objects represent properties of the type. Example properties and methods of this type include Name , CanRead , CanWrite , and GetAccessors.

  • Type:- a class whose objects represent types in the CLR


 


MethodBase Class


This is an abstract base class for ConstructorInfo and MethodInfo.



  • ConstructorInfo:- a class whose objects represent constructors available on the type. A ConstructorInfo object exists for each constructor that a class has.

  • MemberInfo:- a class whose objects represent methods of the type. Example properties and methods of this type include IsAbstract , ReturnType , and GetBaseDefinition , which is used to access the overridden method definition from the class's base type .


ParameterInfo


A class whose objects represent parameters of a method of the type. This class inherits from Object , Example properties and methods of this type include IsIn , IsOut , and IsDefined .


 


Type Class


 


The Type Class is an abstract class. The methods and properties provide by the Type Class is as follows:



  • Get methods:- Methods that start with the word Get and return information about one aspect of the type.

  • Is Method or properties:- Methods or properties that return a Boolean value indicating whether the type satisfies a condition.

  • Properties:- Properties of the type, such as AssemblyQualifiedName.

  • Static Fields:- Fields holding information required to process the type.


 


Example: Demonstrate Reflection


 




using System;


using System.Collections.Generic;


using System.ComponentModel;


using System.Data;


using System.Drawing;


using System.Text;


using System.Windows.Forms;


using System.Reflection;


 


namespace cSHARPEXAMPLES


{


public partial class Form21 : Form


{


public Form21()


{


  InitializeComponent();


}


private void button2_Click( object sender, EventArgs e)


{


  //Get Type


    Type t = Type .GetType( "System.Object" );


  //Type Info.


  textBox1.Text = textBox1.Text + "FullName: " + t.FullName + "\n" ;


  textBox1.Text = textBox1.Text + "Qualified Name:" + t.AssemblyQualifiedName + "\n" ;


  textBox1.Text = textBox1.Text + "GUID:" + t.GUID + "\n" ;


  textBox1.Text = textBox1.Text + "IsAbstract:" + t.IsAbstract + "\n" ;


  textBox1.Text = textBox1.Text + "IsClass:" + t.IsClass +"\n" ;


  textBox1.Text = textBox1.Text + "IsInterface:" + t.IsInterface + "\n" ;


  textBox1.Text = textBox1.Text + "IsSealed:" + t.IsSealed + "\n" ;


  //Members Info


    MemberInfo [] members = t.GetMembers();


  foreach ( MemberInfo m in members)


    textBox2.Text = textBox2.Text + m + "\n" ;


    }


  }


}


 


Output:





  << Prev: Type System in .Net -2 Next: Introduction to Generics >>
Dotnet Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
LINKS
MSN
Video Surveillance
Skype vs. sipcall
Gift to Pakistan
 
ADVERTISEMENT
 
PARTNER LIST

More
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising