Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Simple reflection question

Posted on 2008-10-07
3
Medium Priority
?
198 Views
Last Modified: 2010-05-18
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
Comment
Question by:craigdev
3 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 22659992
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
 
LVL 12

Accepted Solution

by:
ShazbotOK earned 2000 total points
ID: 22660222

        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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question