List all classes in .NET

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
 
G

Guest

Reflection is your friend!

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

Tasos Vogiatzoglou

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
 
J

james.curran

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.
 
I

Ignacio Machin \( .NET/ C# MVP \)

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
 

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