Reflection Question..

G

gary

Given an assembly loaded into memory, I can call GetTypes() to get a
list of types that are defined in the assembly.

However, how can I get a list of types that are used in the assembly
that are defined in other assemblies?
 
M

Mattias Sjögren

However, how can I get a list of types that are used in the assembly
that are defined in other assemblies?

You can't do that with reflection. The closest thing is that you can
get a list of assemblies it depends on with
Assembly.GetReferencedAssemblies.

The information about which types in those assemblies are used is
available in metadata so it can be retrieved by other means, but not
with reflection.



Mattias
 
G

Guest

Further to my previous post.... You could get a list of assemblies referenced
by the current assembly and then enumerate the types in each of those
although this will more then likley contain lots of typs that are not
actually used by the types in the first assembly.

Anyway, if you want to do that, call
"Assembly.GetExecutingAssembly().GetReferencedAssemblied()".

--
Brian Delahunty
Ireland

http://briandela.com/blog

INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
started in the southeast of Ireland.
 
E

Erick Sgarbi

It would not be very neat doing this using reflection because there are
no interfaces that will give direct information from classes in external
assemblies... only referenced assemblies.

However you could read the Assembly's metadata and do a lookup on
TypeDef and TypeRef tables. Have a look at
http://www.jbrowse.com/products/asmex/download.shtml or SharpAssembly by
downloading the source code for SharpDevelop
(http://www.sharpdevelop.com/OpenSource/SD/Default.aspx) and looking at
the path src\Libraries\SharpAssembly. These libraries will give you what
you need but there is some work involved in understanding how it all
works... it is definitely harder than calling a couple of methods from
the Reflection API.

HTH
Erick Sgarbi
www.blog.csharpbox.com
 

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