1

Possible Duplicate:
C#: List All Classes in Assembly

How I can get all class names in specific project using reflection?


Edit 1)

Is it possible to distinguish between programmer defined class and built-in classes?

Community
  • 1
  • 1
Arian
  • 12,793
  • 66
  • 176
  • 300
  • 2
    @Heinzi Right if we consider a project to be an assembly (something that normally is) – xanatos Oct 27 '11 at 07:03
  • 1
    @xanatos: Of course. Since reflection can only be applied to assemblies and not to projects, I assumed that this is what Nima meant. – Heinzi Oct 27 '11 at 07:20
  • 1
    @Heinzi There is a good chance the OP didn't know this. I think it was important enough to point it out – xanatos Oct 27 '11 at 07:22
  • Is it possible to distinguish between programmer defined class and built-in classes? – Arian Oct 27 '11 at 08:11
  • @Nima: I suggest you start a different SO question for that. – Heinzi Oct 27 '11 at 11:48

3 Answers3

5

You can use Type[] types = Assembly.GetExecutingAssembly().GetTypes() to get all types in the assembly that contains this line of code; the Type class has the Name property.

C.Evenhuis
  • 25,996
  • 2
  • 58
  • 72
2

The two previous posters are correct. However, if you wanted a list of all referenced assemblies and their types, you could do:

var referencedAssemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
var referencedTypes = referencedAssemblies.SelectMany(x => Assembly.Load(x.FullName).GetTypes());

This would give a list of all Types from the core libraries, third-parties etc which are referenced and used, if you are not using an assembly but have it referenced it wouldn't list its types.

It isn't greatly useful as it lists thousands of types from System and System.Core etc, but i'm not entirely sure what you're trying to achieve, so it may be a start.

dashton
  • 2,684
  • 1
  • 18
  • 15
0

use Assembly.GetTypesmethod

4b0
  • 21,981
  • 30
  • 95
  • 142