How to enumerate classes from a DLL

B

bz

Hi,
I need to create a sort of dll inspector, for NET, and I need to
receive the filename of a dll, then check if it is a NET dll and if
so, enumerate all classes defined in it
I know how to enumerate all types from an assemble, with

Assembly assembly;
foreach(Type type in assembly.GetTypes()) {

but I don't know how to find if the dll is actually a NET dll and how
to create a variable of type Assembly from dll filename

Thanks
 
F

Family Tree Mike

bz said:
Hi,
I need to create a sort of dll inspector, for NET, and I need to
receive the filename of a dll, then check if it is a NET dll and if
so, enumerate all classes defined in it
I know how to enumerate all types from an assemble, with

Assembly assembly;
foreach(Type type in assembly.GetTypes()) {

but I don't know how to find if the dll is actually a NET dll and how
to create a variable of type Assembly from dll filename

Thanks

Assembly.LoadFile("c:\path\filename.dll") will return an assembly for you to
call GetTypes. I'm not sure if there is a way other than trapping an
exception on the call to LoadFile (BadImageFormatException).

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top