คำถามเก่ามาก แต่คำตอบใหม่ ;-)
รุ่น ExpressionTree : (ฉันคิดว่าเร็วที่สุดและวิธีแก้ปัญหาที่สะอาดที่สุด)
เหมือนWelly Tambunanกล่าวว่า"เราสามารถใช้ต้นไม้แสดงผลเพื่อสร้างวัตถุ"
สิ่งนี้จะสร้าง 'ตัวสร้าง' (ฟังก์ชัน) สำหรับประเภท / พารามิเตอร์ที่กำหนด มันจะส่งกลับผู้รับมอบสิทธิ์และยอมรับประเภทพารามิเตอร์เป็นอาร์เรย์ของวัตถุ
นี่มันคือ:
// this delegate is just, so you don't have to pass an object array. _(params)_
public delegate object ConstructorDelegate(params object[] args);
public static ConstructorDelegate CreateConstructor(Type type, params Type[] parameters)
{
    // Get the constructor info for these parameters
    var constructorInfo = type.GetConstructor(parameters);
    // define a object[] parameter
    var paramExpr = Expression.Parameter(typeof(Object[]));
    // To feed the constructor with the right parameters, we need to generate an array 
    // of parameters that will be read from the initialize object array argument.
    var constructorParameters = parameters.Select((paramType, index) =>
        // convert the object[index] to the right constructor parameter type.
        Expression.Convert(
            // read a value from the object[index]
            Expression.ArrayAccess(
                paramExpr,
                Expression.Constant(index)),
            paramType)).ToArray();
    // just call the constructor.
    var body = Expression.New(constructorInfo, constructorParameters);
    var constructor = Expression.Lambda<ConstructorDelegate>(body, paramExpr);
    return constructor.Compile();
}
ตัวอย่าง MyClass:
public class MyClass
{
    public int TestInt { get; private set; }
    public string TestString { get; private set; }
    public MyClass(int testInt, string testString)
    {
        TestInt = testInt;
        TestString = testString;
    }
}
การใช้งาน:
// you should cache this 'constructor'
var myConstructor = CreateConstructor(typeof(MyClass), typeof(int), typeof(string));
// Call the `myConstructor` function to create a new instance.
var myObject = myConstructor(10, "test message");

อีกตัวอย่างหนึ่ง: ส่งผ่านชนิดเป็นอาร์เรย์
var type = typeof(MyClass);
var args = new Type[] { typeof(int), typeof(string) };
// you should cache this 'constructor'
var myConstructor = CreateConstructor(type, args);
// Call the `myConstructor` fucntion to create a new instance.
var myObject = myConstructor(10, "test message");
DebugView ของนิพจน์
.Lambda #Lambda1<TestExpressionConstructor.MainWindow+ConstructorDelegate>(System.Object[] $var1) {
    .New TestExpressionConstructor.MainWindow+MyClass(
        (System.Int32)$var1[0],
        (System.String)$var1[1])
}
นี่เทียบเท่ากับรหัสที่สร้างขึ้น:
public object myConstructor(object[] var1)
{
    return new MyClass(
        (System.Int32)var1[0],
        (System.String)var1[1]);
}
ข้อเสียเล็ก ๆ
พารามิเตอร์ประเภทค่าทั้งหมดจะถูกทำเครื่องหมายเมื่อถูกส่งผ่านเหมือนอาร์เรย์วัตถุ
ทดสอบประสิทธิภาพง่าย ๆ :
private void TestActivator()
{
    Stopwatch sw = Stopwatch.StartNew();
    for (int i = 0; i < 1024 * 1024 * 10; i++)
    {
        var myObject = Activator.CreateInstance(typeof(MyClass), 10, "test message");
    }
    sw.Stop();
    Trace.WriteLine("Activator: " + sw.Elapsed);
}
private void TestReflection()
{
    var constructorInfo = typeof(MyClass).GetConstructor(new[] { typeof(int), typeof(string) });
    Stopwatch sw = Stopwatch.StartNew();
    for (int i = 0; i < 1024 * 1024 * 10; i++)
    {
        var myObject = constructorInfo.Invoke(new object[] { 10, "test message" });
    }
    sw.Stop();
    Trace.WriteLine("Reflection: " + sw.Elapsed);
}
private void TestExpression()
{
    var myConstructor = CreateConstructor(typeof(MyClass), typeof(int), typeof(string));
    Stopwatch sw = Stopwatch.StartNew();
    for (int i = 0; i < 1024 * 1024 * 10; i++)
    {
        var myObject = myConstructor(10, "test message");
    }
    sw.Stop();
    Trace.WriteLine("Expression: " + sw.Elapsed);
}
TestActivator();
TestReflection();
TestExpression();
ผล:
Activator: 00:00:13.8210732
Reflection: 00:00:05.2986945
Expression: 00:00:00.6681696
การใช้เร็วกว่าการเรียกใช้Expressions+/- 8 เท่าConstructorInfoและ +/- เร็วขึ้น 20 เท่าเมื่อใช้งานActivator