通过反射可以获取父类的public属性,但是好像获取不到父类的public字段,有什么办法获取吗?

解决方案 »

  1.   

        public class Base
        {
            public string ID;
            private string name;        public string Name
            {
                get { return name; }
                set { name = value; }
            }
        }
        public class Children : Base
        {
        }
                Type type = typeof(Children);
                FieldInfo[] field = type.GetFields();
                foreach (FieldInfo f in field)
                    Console.WriteLine(f.Name);
                PropertyInfo[] proper = type.GetProperties();
                foreach (PropertyInfo p in proper)
                    Console.WriteLine(p.Name);
                Console.ReadLine();
    /*
    ID
    Name
    */
      

  2.   


    你确定FieldInfo[] field = type.GetFields();这句可以获取到ID和name?不可以吧