zoukankan      html  css  js  c++  java
  • 调用的方法里接收一个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 
  • 相关阅读:
    切片
    类型断言
    方法表达式
    接口
    函数式编程
    多人聊天室
    反射
    yarn基础解释
    webpack基础概念
    ssh登陆报错:packet_write_wait: Connection to x.x.x.x port 22: Broken pipe
  • 原文地址:https://www.cnblogs.com/hedianzhan/p/8986937.html
Copyright © 2011-2022 走看看