Enumerating Classes/functions from library??

PasmanM

New member
Joined
Oct 9, 2007
Messages
2
Programming Experience
10+
Hi there everybody..

Hope you can help me with the following. This question may already have been asked before, but I can not seem to find anything relating to this problem I got.

I am building this code editor for delivery with a piece of software we have wrote, now to have this part of software complete I would like to have to user presented with a intellisense combobox showing classes and functions within a certain DotNet library (as for example system.dll or system.data.dll). So that the user does not need to know every single class or function within that library by heart.

Now I know there must be a way to enumerate all classes and functions from a library file (the object editor does it to...)

Can anyone show me the way to do this???

I am using at this moment VB.NET at VS2003

Thanks,


Michel
 
System.Reflection namespace is what you need, and Assembly class your starting point. LoadFrom method can be used to load an assembly from file. If the assembly is already loaded you can also get it from AppDomain.CurrentDomain.GetAssemblies(). Assembly class has GetTypes method to get the classes, and Type class has methods like GetMembers, GetMethods, GetFields, GetEvents, GetProperties. Then you have to find some way of organizing and filter all that info.
 
The code below goes a little deeper than you asked for in that it will show all properties and fields as well. Reflection can be very useful and is well doucumented

VB.NET:
Expand Collapse Copy
Public Class Asy
    Shared Public  Sub Main()
        Dim asy As Assembly =  Nothing 
        Try
            asy = Assembly.Load ("[B]Assembly you wish to retrieve information from as string[/B]")  
      Catch e As Exception
            Console.WriteLine (e.Message)
            Return
        End Try
        Dim types() As Type =  asy.GetTypes() 
        Dim t As Type
        For Each t In types
            ShowTypeInfo (t)
        Next
    End Sub
    Shared  Sub ShowTypeInfo(ByVal t As Type)
            Console.WriteLine ("{0} is a member of the {1} namespace", t.Name, t.Namespace)
            Console.WriteLine ("\r\nMethods in {0}:", t.Name)
            Dim methods() As MethodInfo =  t.GetMethods() 
            Dim m As MethodInfo
            For Each m In methods
                Console.WriteLine ("\t" + m.Name)
            Next
            Console.WriteLine ("\r\nProperties in {0}:", t.Name)
            Dim props() As PropertyInfo =  t.GetProperties() 
            Dim p As PropertyInfo
            For Each p In props
                Console.WriteLine ("\t" + p.Name)
            Next
            Console.WriteLine ("\r\nFields in {0}:", t.Name)
            Dim fields() As FieldInfo =  t.GetFields() 
            Dim f As FieldInfo
            For Each f In fields
                Console.WriteLine ("\t" + f.Name)
            Next
    End Sub
End Class
 
Thank you ever so much..

b.t.w. I was already playing around with system.reflection... but could not find what I was looking for. But it did give me a bit more insight in the way this stuff works... :D

Thank you.

Michel
 
Back
Top