By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,856 Members | 2,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,856 IT Pros & Developers. It's quick & easy.

List all classes in .NET

P: n/a
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
May 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Reflection is your friend!

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

--
-Demetri
"martin" wrote:
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

May 18 '06 #2

P: n/a
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

May 18 '06 #3

P: n/a
>> 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.
How do I list/enumerate all classes in a namespace?

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.

May 18 '06 #4

P: n/a
Hi,
"martin" <ma****@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...
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

May 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.