List all classes in .NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have some rather unusual questions?

How do I list/enumerate all classes in a namespace?
How do I list/enumerate all classes in a assembly?
How do I list/enumerate all classes in .NET?

For the last part I guess I would enumrate the files in the GAC or something
and then work from there? But how can I load information about a particular
..NET .DLL file given that I know where it's located on disk? Does every .DLL
file contain exactly one assembly and/or namespace or how does it work?

Someone might wonder _why_ I would want to do this.. Basically, I'm just
gonna generate some statistics out of curiousity.


regards,
martin
 
Reflection is your friend!

Check out the System.Reflection and System.Reflection.Emit namespaces for
classes that will do what you are asking.
 
Hello martin,

You can use reflection (System.Reflection) for what you need starting
at the assembly level. From there you can query the entire assembly for
declared types.

The class System.Reflection.Assembly provides methods do load an
assembly (by name, file etc) and get the types by GetTypes();
From there also you can get the referenced assemblies
(GetReferencedAssemblies).

For the namespace part you will have to add some logic because there is
no direct way to get all the types defined in a namespace.

Regards,
Tasos
 
How do I list/enumerate all classes in a assembly?

Read in the Assembly using the Assembly.Load or Assembly.LoadFile
methods. Then call the GetTypes() method on that assembly, and
enumerate through the array of Type objects it returns. Each type
object should have all the information you need.
There no real way of doing this, as a namespace could easily be spread
out over multiple assemblies. You just have to use the above method
for each assembly, and sort the results by namespace.
 
Hi,


martin said:
Hi,

I have some rather unusual questions?

How do I list/enumerate all classes in a namespace?
How do I list/enumerate all classes in a assembly?
How do I list/enumerate all classes in .NET?

You will have to include a reference to ALL the assemblies.

You could also load them dynimically
 
Back
Top