可能重複:
Finding all Namespaces in an assembly using Reflection (DotNET)列明的命名空間中的DLL使用
讓我們考慮我有我的10至30 DLL列表,我需要列出所有的命名空間由這些DLL導入。
我試圖與下面使用反射代碼
string[] fileEntries = Directory.GetFiles(sDir, "*.dll");
foreach (string fileName in fileEntries)
{
Assembly assembly = Assembly.LoadFrom(fileName);
List<string> namespaces = new List<string>();
foreach (var type in assembly.GetTypes())
{
string ns = type.Namespace;
if (!namespaces.Contains(ns))
{
namespaces.Add(ns);
Console.WriteLine(ns);
}
}
}
但它只retrives這些DLL的唯一的命名空間。
例如,讓我們考慮一個程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace sample
{
public partial class sample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string pth = filepth("D:/sample1/s.txt");
createfile(pth);
Response.Write("File created on path :" + pth);
}
}
}
基礎上,上面的代碼retrives只樣本,但我需要retrive作爲
**
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
所有命名空間
**
你能引導我把它..
等待着您的寶貴意見
@Cory,topicstarter希望找到所有類型,在彙編中使用,並使用它們構建名稱空間列表,而不僅僅是由他自己創建的類型。 – Dennis 2012-08-09 05:40:55
@丹尼斯:點了點。據稱重複取消! – 2012-08-09 05:45:42