Solved

Simple reflection question

Posted on 2008-10-07
3
186 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 55

Expert Comment

by:Jaime Olivares
ID: 22660153
0
 
LVL 12

Accepted Solution

by:
ShazbotOK earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bulid json format 3 46
Connecting database in Xamarin? 6 54
ADO.NET ENTITY DATA MODEL 3 32
scanning dentists xray (the small ones) 3 45
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now