reflection_class_constructor_names.htm

using System;
using System.Reflection;
//using string_module;
//csc get_assembly_constructor_type.cs
namespace ex_indexer_1
{
public class get_type
{
public void process(string str)
{
Assembly asm = Assembly.LoadFrom(str);
Type[] all_type = asm.GetTypes();
foreach(Type e in all_type)
{
Console.WriteLine("Found : {0} ", e);
}
Type t_cl = all_type[0];
Type t_cl_1 = all_type[1];
Console.WriteLine("\t Class Name {0} ",t_cl.Name);
Console.WriteLine("\t Class Name {0} ",t_cl_1.Name);
//
ConstructorInfo[] all_ct = t_cl.GetConstructors();
foreach(ConstructorInfo c in all_ct)
{ Console.WriteLine("\t Constructor {0} ",t_cl.Name);}

}
}//end of get_type
class test
{
static void Main()
{
String str = "";
Console.WriteLine("You may use either of two or any exe");
Console.WriteLine(@"C:\MySharp\reflection\ex1\reflection_typeof_operator.exe");
Console.WriteLine(@"C:\MySharp\reflection\ex1\get_assembly_constructor_type.exe");
Console.WriteLine(@"C:\MySharp\reflection\ex1\instance_constructor.exe");
Console.Write("Enter Here : " );
str =Console.ReadLine();
if (str !="")
{ get_type gt = new get_type();
gt.process(str);
}
else return;
Console.ReadLine();
}
}
}//end of namespace
 

In the example show below we browsed through an example where we did not create constructor, and programm uses default construcotr by it's class name.

public class SampleClass
{
public int sampleMember;
public int SampleMethod() { int n = 2, m = 4; return n * m ;}
public SampleClass(){ Console.WriteLine("Constructor evoked ");}
~SampleClass(){ Console.WriteLine("Desstructor evoked ");}
}
class test
{
static void Main()
{
Type t = typeof(SampleClass);
// Alternatively, you could use
// SampleClass obj = new SampleClass();
// Type t = obj.GetType();
SampleClass sc = new SampleClass();
Console.WriteLine(" did something in the method : " + sc.SampleMethod());
Console.WriteLine("Methods:");
MethodInfo[] mi = t.GetMethods();
foreach (MethodInfo mInfo in mi)
Console.WriteLine(mInfo.ToString());
Console.WriteLine("Members:");
MemberInfo[] memi = t.GetMembers();
foreach (MemberInfo mInfo in memi)
Console.WriteLine(mInfo.ToString());
}
}

You may plug a path and get information about the class and constructor.