473,385 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reflection Question..


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?

Aug 11 '05 #1
4 1183
>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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Aug 11 '05 #2
Not really possible. Short of disassembling the code on the fly to MSIL and
then searching for all the call, callvirt, newobj, etc. MSIL instructions.

--
Brian Delahunty
Ireland

http://briandela.com/blog

INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
started in the southeast of Ireland.
"ga**@designercontrols.com" wrote:

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?

Aug 11 '05 #3
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().GetReferencedAsse mblied()".

--
Brian Delahunty
Ireland

http://briandela.com/blog

INDA SouthEast - http://southeast.developers.ie/ - The .NET usergroup I
started in the southeast of Ireland.
"ga**@designercontrols.com" wrote:

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?

Aug 11 '05 #4
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

"ga**@designercontrols.com" <ga**@designercontrols.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com:
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?


Aug 11 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: A. Wiebenga | last post by:
Hi all! I am a student at the Hogeschool van Arnhem en Nijmegen in Holland. I am currently involved in a research project regarding Reflection. Purpose of the research project is to document...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
2
by: Dan | last post by:
Let's say I have a class like: class Dummy { public const string CONE = "one"; public const string CTWO = "two"; ... other stuff .... }
7
by: John | last post by:
I have a class the reads in a file and sets the values of the file into its properties. This class is used to populate the data onto a form. This form has controls created at runtime based on...
1
by: Pieter Breed | last post by:
Hi All, I am trying to use the attribute/reflection system to as much potential as I can think of, but I've run into a snag. I would appreciate it if someone would point me in the right...
5
by: heddy | last post by:
I understand that reflection allows me to discover the metadata of a class at runtime (properties, methods etc). What I don't understand is where this is useful. For example: If I am the sole...
5
by: =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?= | last post by:
Hi, is it faster to access the fields from an object directly by using reflection than accessing them by their properties using reflection? Thanks Christian
17
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.