Sunday, January 17, 2010

Using reflection to get types in another asseembly With C#

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

namespace Calling_Class_at_runtime_with_reflection
{
class Program
{
static void Main(string[] args)
{
Assembly asm = Assembly.LoadFrom(@"C:\Documents and Settings\USER\My Documents\Visual Studio 2005\Projects\ClassWithConstructor\ClassWithConstructor\bin\Debug\ClassWithConstructor.exe");
Type[] alltype = asm.GetTypes();
foreach (Type temp in alltype )
{
Type t = temp ;
Console.WriteLine("Type Name:"+t.Name);
Console.Write(Environment.NewLine);
ConstructorInfo[] Ci = t.GetConstructors();

foreach (ConstructorInfo C in Ci)
{
Console.WriteLine("Name of Constructor:" + C.Name);
ParameterInfo[] PI = C.GetParameters();
Console.WriteLine();
Console.WriteLine("This is {0}Parameter Constructor:", PI.Length );
for (int i = 0; i < PI.Length; i++)
{
Console.WriteLine("ParameterType:" + PI[i].ParameterType);
Console.WriteLine("Parameter:" + PI[i].Name);
Console.WriteLine();
}


}
}
Console.ReadKey();
}

}
}

No comments:

Post a Comment