Monday, April 9, 2007

Reflection in .Net

How to use Reflection in our applications?

System.Reflection namespace contains all the Reflection related classes. These classes are used to get information from any of the class under .NET framework. The Type class is the root of all reflection operations. Type is an abstract base class that acts as means to access metadata though the reflection classes. Using Type object, any information related to methods, implementation details and manipulating information can be obtained. The types include the constructors, methods, fields, properties, and events of a class, along with this the module and the assembly in which these information are present can be accessed and manipulated easily.


Namespace Required : using System.Reflection;

get Methods Inside the Object

Type type = typeof(Employee);
MemberInfo[] m = type.GetMethods();
foreach (MemberInfo m1 in m)
{
MessageBox.show(m1.Name);
}


get Constructors Inside the Object

Type type = typeof(Employee);
MemberInfo[] m = type.GetConstructors();
foreach (MemberInfo m1 in m)
{
MessageBox.show(m1.Name);
}

Reference : http//aspalliance.com/778