- object obj = new object();
- //反射创建普通对象
- object o = Activator.CreateInstance(obj.GetType());
- //反射创建泛型集合
- Type generic = typeof(List<>);
- Type[] typeArgs1 = { obj.GetType() };
- generic=generic.MakeGenericType(typeArgs1);
- var list=Activator.CreateInstance (generic) as IList;
- //反射创建泛型字典
- generic = typeof(Dictionary<,>);
- Type[] typeArgs2 = { typeof(string), obj.GetType() };
- generic = generic.MakeGenericType(typeArgs2);
- var dic = Activator.CreateInstance(generic) as IDictionary;
本文转自 virusswb 51CTO博客,原文链接:http://blog.51cto.com/virusswb/461962如需转载请自行联系原作者