如我有命名空间
com现在我要取得他这个命名空间的所以子类(也就是目录树)那如何来取呢,我用反射
System.Reflection.Assembly ass = System.Reflection.Assembly.(typeof(com));
提示com是命名空间,不是类谢谢

解决方案 »

  1.   


    System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFile("path");
                Type[] types = ass.GetTypes();
                foreach (Type type in types)
                {
                    if (type.Namespace.CompareTo("com") == 0)
                    {                }
                }
      

  2.   

    现在我用    protected void Page_Load(object sender, EventArgs e)
        {
            //取出com.Entnty中的所有类型,并取出表名
            AppDomainSetup info = new AppDomainSetup();
            info.ApplicationBase = Server.MapPath("~/bin/");
            AppDomain dom = AppDomain.CreateDomain("com", null, info);
            System.Reflection.Assembly asm = dom.Load("com");
            Type[] types = asm.GetTypes();
            foreach (Type type in types)
            {
                if (type.Namespace.IndexOf("com.Entity") > -1)
                {
                    Response.Write(type.FullName + "<br />");
                }
            }
            AppDomain.Unload(dom);
        }这样的方法,是可以找出来的,
    但是感觉这样查询的方法不好,我只要找出一个dll中的某一个命名空间
    但是上面的方法的话要循环整个dll的所有类,感觉效率不是很好谢谢
      

  3.   

    System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFile("path");
                Type[] types = ass.GetTypes();
      

  4.   

    Assembly asm= Assembly.GetAssembly(this.GetType()); 
                Type[] t= _Assembyle.GetTypes(); 
                for (int i = 0; i != t.Length; i++) 
                { 
                    if (t[i].Namespace == "A") 
                    { 
                        MessageBox.Show(t[i].Name); 
                    } 
                } 
    Assembly.Load("程序集").CreateInstance("命名空间.类")