• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

Simple reflection question

How do I loop through every class in a namespace?


eg. the namespace MySolution.DataAccess.Components contains objects for accessing data from sql tables - I want to loop through all the classes in this namespace.

0
craigdev
Asked:
craigdev
1 Solution
 
crazymanCommented:
When you say all classes in a namespace, are these classes in the same assembly ?
Since you can have merged namespaces in seperate assemblies....
0
 
Jaime OlivaresSoftware ArchitectCommented:
0
 
ShazbotOKCommented:

        public class ListedModules : System.Collections.Generic.List<System.Reflection.Module> { }
        public class ListedMethods : System.Collections.Generic.List<System.Reflection.MethodInfo> { }
        public ListedModules GetModules(System.Reflection.Assembly asm)
        {
            ListedModules lst = new ListedModules();
            lst.AddRange(asm.GetModules());
 
            return lst;
        }
        public ListedMethods GetMethods(System.Reflection.Module mod)
        {
            ListedMethods lst = new ListedMethods();
            lst.AddRange(mod.GetMethods());
 
            return lst;
        }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now