解决方案 »

  1.   

    GetGenericArgumentshttp://msdn.microsoft.com/zh-cn/library/system.type.getgenericarguments(v=vs.110).aspx
      

  2.   


    获取表示泛型类型的类型实参的 Type 对象的数组,这个只不过是获取泛型中的参数类型,我是想遍历出所有值得啊,这个弄出来了有啥用
      

  3.   


    获取表示泛型类型的类型实参的 Type 对象的数组,这个只不过是获取泛型中的参数类型,我是想遍历出所有值得啊,这个弄出来了有啥用
    对象才有值,类哪有。
      

  4.   


    获取表示泛型类型的类型实参的 Type 对象的数组,这个只不过是获取泛型中的参数类型,我是想遍历出所有值得啊,这个弄出来了有啥用
    对象才有值,类哪有。
    就是因为反射后很难获取那个反射的对象,所以才头疼。
      

  5.   

    比如说
    class A<T>
    {
        public T value { get; set; }
    }A<int> a = new A<int>();
    a.value = 1;
    那么
    int i = (int)a.GetType().GetProperty("value").GetValue(a, null);一样就可以获得。
      

  6.   


    你那个是实例化好就知道类型了,我来贴个代码,你帮忙参谋参谋吧
    Public Class Test
    {
        public string Name = “hello”;
         public int id = 1 ;
        public List<int> list {get;set;}
        public Dictionary<int,List<int>> dictionary {get;set}
        public Test()
        {
          list = new List<int>();
          list.add(11);
          list.add(22);
          dictionary = new Dictionary<int,List<int>>();
          dictionary.add(1,list);
        }
    }
    现在就是要用反射,获取类Test中的所有属性和其值!
      

  7.   

    Test t = new Test();
    var list = t.GetType().GetProperty("list").GetValue(t, null);
    foreach (object o in (list as IEnumerable))
    {
        Console.WriteLine(o);
    }
      

  8.   


    好神奇的写法,object o in (list as IEnumerable)
    可以解释一下吗,如果要搞定那个Dictionary,该怎么办?
      

  9.   


    好神奇的写法,object o in (list as IEnumerable)
    可以解释一下吗,如果要搞定那个Dictionary,该怎么办?
    一样的,反射得到Keys Values,然后枚举。
      

  10.   


    好神奇的写法,object o in (list as IEnumerable)
    可以解释一下吗,如果要搞定那个Dictionary,该怎么办?
    一样的,反射得到Keys Values,然后枚举。
    我的意思是,如果你获取的那个objec o,不是值类型,而是一个引用,那你打出的o就有问题了,如何区分呢?
      

  11.   


    Test t = new Test();
                var list = t.GetType().GetProperty("dictionary").GetValue(t, null);
                foreach (object o in (list as IEnumerable))
                {
                    var itemKey = o.GetType().GetProperty("Key").GetValue(o, null);
                    Console.WriteLine(itemKey);                var itemValue = o.GetType().GetProperty("Value").GetValue(o, null);
                    foreach (object subItem in (itemValue as IEnumerable))
                        Console.WriteLine(subItem);
                }