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)
    {

    }

    }

  • 相关阅读:
    Linux cron
    web报表工具FineReport常用函数的用法总结(文本函数)
    web报表工具FineReport常用函数的用法总结(文本函数)
    oracle instr函数
    死锁的例子和 synchronized 嵌套使用
    死锁的例子和 synchronized 嵌套使用
    Perl 监控批量错误
    Linux以百万兆字节显示内存大小
    Linux以GB显示内存大小
    Linux以KB显示内存大小
  • 原文地址:https://www.cnblogs.com/kennyliu/p/3584937.html
Copyright © 2011-2022 走看看