class a
{
   a()
   { 
       Type type = ...//子类的Type
   }
}
class b: a
{
}class demo()
{
   static int Main()
   {    }
}-----------------------------------------
当然不能使用:
Type type = typeof(B);
因为我写a不知道会有b存在..

解决方案 »

  1.   

    我获取type后,其实是想使用反射获取子类的字段:FieldInfo[] fields = type.GetFields();
      

  2.   

    在继承路径上,基类完全意识不到子类的行为假如 b 是你系统内预定义的类,你自然可以a()

    Type type = typeof(b);
    }否则应该考虑多态
      

  3.   

    感谢! <<<viena>>>,<<<Jinglecat>>>
    ------------------------
    那就是说,此路不通?
      

  4.   


    但每次都要在子类里写相同的代码总是不爽!
    class a
    {
       protected Type type;
       a()
       { 
           
       }
       private void GetChildrenFields()
      {
          FieldInfo[] fields = type.GetFields();
          ....
       }
    }
    class b: a
    {
        type = this.GetType();  // 这段代码每个子类都得写
    }
      

  5.   

    通过一个可以覆盖的方法,this.GetyType()就可以实现你想要的效果。
      

  6.   

    wush007 你太有才了!兄弟,感谢感谢!!
      

  7.   

    class a
    {
       private Type type;
       a()
       { 
           
       }
       protected virtual void  GetChildrenFields()
      {
          type = this.GetType();  //搞定,读出来的就是子类的类型
          FieldInfo[] fields = type.GetFields();
          ....
       }
    }
    class b: a
    {
       
    }