Diyelim ki elinizde bir Type var. Bu Type'dan nesne oluşturmak isterseniz hemen Activator.CreateInstance(typeof(...),params) ile belirlediğimiz bir yapıcı metod ile nesneniz oluşturulur. Bunun bir başka yolu için buyrunuz...
class A
{
private int x;
public void Hede()
{
Console.WriteLine(x);
}
public A()
{
Console.WriteLine("default");
}
public A(int a)
{
x = a;
}
}
class Program
{
private static void Main(string[] args)
{
Type t = typeof(A);
ConstructorInfo ci = t.GetConstructor(new Type[] {typeof(int)});
A a = (A)ci.Invoke(new object[] {2});
a.Hede();
}
}