调用的方法里接收一个List<>类型的参数,里面是自定义的EC类, 我要通过反射构建这List对象

          public static object CreateGeneric(Type generic, Type innerType, params object[] args)
        {
            Type specificType = generic.MakeGenericType(new System.Type[] { innerType });
            return Activator.CreateInstance(specificType, args);
        }
        object genericList = CreateGeneric(typeof(List<>), typeof(EC));
 
 
获取List<T>中T的类型
 
    public class MyClass
        {
        }
        Type t = typeof(List<MyClass>).GetGenericArguments()[0];
        Console.WriteLine(t.Name);
        //输出
         //MyClass
bloodish 
posted @ 2018-05-03 18:43  核电站  阅读(1123)  评论(0编辑  收藏  举报