get namespace & classes in other projects

  • Thread starter Thread starter hdjim
  • Start date Start date
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
 
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?
 
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);
}
 
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."
 
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.
 
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...
 
Back
Top