Possible Duplicate:
Finding all Namespaces in an assembly using Reflection (DotNET)
let us consider that i am having list of 10 to 30 dll with me i need to list out all the namespaces imported by those dll.
I have tried with following code using reflection as
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);
}
}
}
but it only retrives the only the namespace of those dll.
for example let us consider a program
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);
}
}
}
based on the above code it retrives only sample but i need to retrive all namespaces used as
**
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
**
can you guide me regarding it..
waiting for your valuable comments