C# 利用发射动态创建泛型类型的对象,泛型类型支持带惨的构造函数
static class Program { static void Main(string[] args) { var aaa = Create<AAA>("aaa"); aaa.AAAAAA(); var bbb = Create<BBB>("bbb"); bbb.BBBBBB(); Console.ReadKey(); } static T Create<T>(string connString) { return (T)Activator.CreateInstance(typeof(T), new object[] { connString }); } } public class AAA { private string str; public AAA(string input) { str = input; } public string AAAAAA() { return "AAA" + str; } } public class BBB { private string str; public BBB(string input) { str = input; } public string BBBBBB() { return "BBB" + str; } }