473,473 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1184
>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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.