Solved

Simple reflection question

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

11 Experts available now in Live!

Get 1:1 Help Now