Sunday, January 17, 2010

Reflection in c#

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace Reflection
{
class Program
{
static void Main(string[] args)
{
Type t = typeof(string);
Console.WriteLine("ClassName:"+ t.Name);
Console.WriteLine();
MethodInfo[] M = t.GetMethods();
foreach (MethodInfo m in M)
{
Console.Read();
Console.WriteLine();

Console.WriteLine("MethodName: " + m.Name);
Console.WriteLine("ReturnType: "+ m.ReturnType );
Console.WriteLine("Parameter:");
ParameterInfo[] P = m.GetParameters();
if (P.Length != 0)
{
for (int i = 0; i < P.Length; i++)
{
Console.WriteLine(P[i].ParameterType + P[i].Name);
}
}
else
{
Console.WriteLine("No Input parameter:");
}

}

}
}
}

No comments:

Post a Comment