反射

// 反射生成泛型对象 重点关注Type对象的构建
Console.WriteLine("********************GenericClass********************");
Assembly assembly = Assembly.Load("Ruanmou.DB.SqlServer");
Type type = assembly.GetType("Ruanmou.DB.SqlServer.GenericClass`3");
Type typeMake = type.MakeGenericType(new Type[] { typeof(string), typeof(int), typeof(DateTime) });
object oGeneric = Activator.CreateInstance(typeMake);

 

 

 

 

namespace Ruanmou.DB.SqlServer
{
public class GenericClass<T, W, X>
{
public void Show(T t, W w, X x)
{
Console.WriteLine("t.type={0},w.type={1},x.type={2}", t.GetType().Name, w.GetType().Name, x.GetType().Name);
}
}

 

posted @ 2021-12-23 16:04  FiberHomer  阅读(5)  评论(0编辑  收藏  举报