tags:

views:

766

answers:

4

I've a DLL assembly, in which there are various classes. Each class has around 50-100 members and 4-5 functions.

How can I create a list of all the classes and their respective members using VB program. I need to show to the user for performing operation using a particular class.

Thanks Rahul

+1  A: 

Use the classes from the System.Reflection namespace, starting with Assembly.

David Schmitt
A: 

Many examples on the web, here's one (in c# though)

Yossi Dahan
+2  A: 

Hi,

See the documentation for System.Reflection.Assembly.GetTypes() and System.Type.GetMembers()

--larsw

larsw
+2  A: 

Assuming that you've your assembly loaded to thisAsm (in this ex I'm using the executing assembly),

This will get you all non abstract classes

        Assembly thisAsm = Assembly.GetExecutingAssembly();
        List<Type> types = thisAsm.GetTypes().Where(t => t.IsClass && !t.IsAbstract).ToList();

And this will get you all classes that implements a specific interface.

(Eg. If you need to get only the classes that implements IYourInterface, then)

Assembly thisAsm = Assembly.GetExecutingAssembly();
List<Type> types = thisAsm.GetTypes().Where
            (t => ((typeof(IYourInterface).IsAssignableFrom(t) 
                 && t.IsClass && !t.IsAbstract))).ToList();

Once you've this list of items, you can show the members of each type, by calling the GetProperties() and GetMethods() on each member of the types list

amazedsaint
He asked "using VB program"
TheSoftwareJedi