List all classes in .NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • martin

    List all classes in .NET

    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
  • Demetri

    #2
    RE: List all classes in .NET

    Reflection is your friend!

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

    --
    -Demetri


    "martin" wrote:
    [color=blue]
    > 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[/color]

    Comment

    • Tasos Vogiatzoglou

      #3
      Re: List all classes in .NET

      Hello martin,

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

      The class System.Reflecti on.Assembly provides methods do load an
      assembly (by name, file etc) and get the types by GetTypes();
      [color=blue]
      >From there also you can get the referenced assemblies[/color]
      (GetReferencedA ssemblies).

      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

      Comment

      • james.curran@gmail.com

        #4
        Re: List all classes in .NET

        >> How do I list/enumerate all classes in a assembly?

        Read in the Assembly using the Assembly.Load or Assembly.LoadFi le
        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.
        [color=blue][color=green]
        >> How do I list/enumerate all classes in a namespace?[/color][/color]
        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.

        Comment

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

          #5
          Re: List all classes in .NET

          Hi,


          "martin" <martin@discuss ions.microsoft. com> wrote in message
          news:FF4FECEA-28B7-4475-A1AC-BD1F4825DA47@mi crosoft.com...[color=blue]
          > 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?[/color]

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

          You could also load them dynimically



          Comment

          Working...