zoukankan      html  css  js  c++  java
  • 获取一个Assembly中的命名空间列表

    通过System.Reflection.Assembly类中提供的方法和属性不能直接获取组件中的命名空间列表。但有方法可以直接获得Assembly中的所有类型,我们便可以通过获取的类型来得到命名空间名称。

    具体代码如下所示:

    GetNamespaceListOfAssemly.Program

    其中的Assembly.GetCallingAssembly()是获取当前的Assembly对象,也可以通过Assembly.LoadFrom等方法载入dll获取Assembly对像。

    protected void ChooseDLL_Click(object sender, EventArgs e)
    {
    //string fullPath = Path.GetFullPath(this.FileUpload_DLL.PostedFile.FileName);
    //string name = this.FileUpload_DLL.PostedFile.FileName;
    //string path = Server.MapPath(name);
    //Response.Write(fullPath+"--"+path+"--");
    System.Reflection.Assembly dllFile;
    Type type;
    try
    {
    dllFile = System.Reflection.Assembly.Load("TangramServer");

    Type[] typeList = dllFile.GetTypes();

    IList<string> namespacelist = new List<string>();
    foreach (Type type1 in typeList)
    {
    if (!namespacelist.Contains(type1.Namespace))
    {
    namespacelist.Add(type1.Namespace);
    }
    }

    foreach (string name in namespacelist)
    {
    Response.Write(name+"~");
    }

    type = dllFile.GetType();
    string Namespac = type.Namespace;

    //string dllName = dllFile.GetName().ToString();
    //Response.Write(Namespac + "--" + type.Name+"--="+type.FullName);

    foreach (Type className in dllFile.ExportedTypes)
    {
    //ComponentEntity entity = new ComponentEntity();
    //entity.Component_Name = className.Name.ToString();
    //entity.Component_Feature = "";
    //libraryBll.Add(entity);
    Response.Write(className.Namespace.ToString()+" **"+className.Name);
    }
    }
    catch (Exception ex)
    {

    }

    }

  • 相关阅读:
    对 Service中sqlsession对象的优化
    mybatis 接口绑定 和 动态SQL
    添加指定的日志信息
    数据库优化
    MyBatis 实现新增
    MyBatis中log4j 和 参数 和 分页和别名 功能
    OpenGL_混合
    android应用开发揭秘第13章01示例,移动图像,opengl绘制星星问题解决!
    《关于个人承接项目的注意事项》读后感
    Android OpenGL ES教程 第二部分 构建多边形
  • 原文地址:https://www.cnblogs.com/kennyliu/p/3584937.html
Copyright © 2011-2022 走看看