get namespace & classes in other projects

H

hdjim

Hello, I have a solution with several projects. Is there a way to get
the namespace.class of each namespace.classes in all the projects from
a single project? I have added a project reference to the main
project and have tried using Assembly assembly =
System.Reflection.Assembly.GetExecutingAssembly(); but it only gets
the namespace.classes in the executing assembly...as the name
suggests :( How to get the ns.classes in other projects. Would
appreciate any help.

TIA
hd
 
J

Jeff Johnson

Hello, I have a solution with several projects. Is there a way to get
the namespace.class of each namespace.classes in all the projects from
a single project? I have added a project reference to the main
project and have tried using Assembly assembly =
System.Reflection.Assembly.GetExecutingAssembly(); but it only gets
the namespace.classes in the executing assembly...as the name
suggests :( How to get the ns.classes in other projects. Would
appreciate any help.

Are you trying to do this at run-time or do you want to get this information
inside the IDE?
 
S

Stanimir Stoyanov

The following code will walk recursively through all assemblies referenced
in the current AppDomain, including MsCorLib, System et cetera where
applicable. It keeps a list of each assembly's hash code in
"walkedAssemblies" to avoid doubling. You can replace the calls to
Console.WriteLine to suit your assembly- or type-manipulating logic.

static void Main(string[] args)
{
List<int> walkedAssemblies = new List<int>();

WalkAssembly(Assembly.GetEntryAssembly(), walkedAssemblies);
}

private static void WalkAssembly(Assembly assembly, List<int>
walkedAssemblies)
{
int hashCode = assembly.GetHashCode();

if (walkedAssemblies.Contains(hashCode))
return;

walkedAssemblies.Add(hashCode);

Console.WriteLine("> {0}", assembly.GetName().Name);

foreach (Type type in assembly.GetTypes())
Console.WriteLine(" {0}", type.FullName);

foreach (AssemblyName refAssemblyName in
assembly.GetReferencedAssemblies())
WalkAssembly(Assembly.Load(refAssemblyName), walkedAssemblies);
}
 
J

Jeff Johnson

run-time.

The problem is that a solution is a concept that is only meaningful inside
Visual Studio. Once a solution is compiled the assemblies have no idea that
they were included in the solution, so without explicit code there's no way
one "project" can say "give me a list of all the other projects that I was
compiled with."
 
H

hdjim

The following code will walk recursively through all assemblies referenced
in the current AppDomain, including MsCorLib, System et cetera where
applicable. It keeps a list of each assembly's hash code in
"walkedAssemblies" to avoid doubling. You can replace the calls to
Console.WriteLine to suit your assembly- or type-manipulating logic.

Thanks, I'll run it and see what I get.
 
H

hdjim

The problem is that a solution is a concept that is only meaningful inside
Visual Studio. Once a solution is compiled the assemblies have no idea that
they were included in the solution, so without explicit code there's no way
one "project" can say "give me a list of all the other projects that I was
compiled with."

bummer...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top