参考网址:http://stackoverflow.com/questions/315231/using-reflection-to-set-a-property-with-a-type-of-listcustomclass

遇到的问题:需要反射一个方法,但是它的参数也是程序集里的一个list数组。当调用一般的传参过程会报错,使用下述的语法创建list数组可以当参数传入。
class Foo
{
public string Bar { get; set; }
}
class Program
{
static void Main()
{
Type type = typeof(Foo); // possibly from a string
IList list = (IList) Activator.CreateInstance(
typeof(List<>).MakeGenericType(type)); object obj = Activator.CreateInstance(type);
type.GetProperty("Bar").SetValue(obj, "abc", null);
list.Add(obj);
}
}

最新文章

  1. eclipse配置tomcat
  2. C++小项目:directx11图形程序(五):shadersclass
  3. python脚本基础总结
  4. c#params ref out
  5. offsetTop、clientTop、scrollTop、offsetTop
  6. c笔记
  7. 在页面中使用Eval的两种方案
  8. C++中的仿函数,std::function和bind()的用法
  9. explain 用法详解
  10. [Javascript] Get Started with LeafletJS Mapping
  11. VirtualBox设置共享文件夹和镜像访问的方法
  12. 团队介绍 | 魅动 Magic Motion
  13. 行业百科知识--Github
  14. 网络分析法(Analytic Network Process,ANP)
  15. 【SRM-09 B】撕书II
  16. vue中使用cookies和crypto-js实现记住密码和加密
  17. mysql数据库自动备份脚本
  18. struts2 常量
  19. 自定义Spark Partitioner提升es-hadoop Bulk效率——续
  20. linux性能系列--cpu

热门文章

  1. python 建立多维列表
  2. python3 十六进制字符串进行分割并累加
  3. Git上传本地代码
  4. sql day2
  5. activiti官网实例项目activiti-explorer之获取流程节点
  6. [转]NSIS 制作安装包无法创建桌面快捷方式或无法删除开始菜单项
  7. git取别名配置
  8. 剑指offer——二叉树的镜像
  9. python运行时参数m的作用
  10. 恢复oracle 11g 的System及sys用户的密码