In this article I will show you how can we get the information related to some type/class using Type Class programatically like how many constructors are there in Class , which Data Members are there names of methods in the class etc .
Technology
CSharp .net 2.0/3.5
Implementation
Type Class Provides methods for getting information related to some type like,
Constructors in Class
Method Names of Class
Properties of Class
For this sample we will create one class like below and try to get all those information like constuctors in class, methods in class and properties related to that class
Type.GetConstructor() method returns Array of ConstructorInfo
Type.GetMethods() method returns Array of MethodInfo
Type.GetProperties() method returns Array of PropertyInfo

For example below is our class1
class code
------------
public class Class1
{
int Var1;
int Var2;
public Class1()
{
throw new System.NotImplementedException();
}
public int GetSetVar1
{
get
{
return Var1;
}
set
{
Var1 = value;
}
}
public int GetSetVar2
{
get
{
return Var2;
}
set
{
Var2 = value;
}
}
public void Method1()
{
}
public void Method2()
{
}
}

Join the conversation! Your thoughts help the community grow.