473,387 Members | 1,844 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,387 software developers and data experts.

Reflection....

UJ
Can somebody point me to an explanation of what Reflection is? I've tried
looking in the help and it's not very helpful.

TIA - Jeff.
Nov 22 '05 #1
2 1622
You can start from
http://msdn.microsoft.com/msdnmag/is...s/default.aspx

"UJ" <fr**@nowhere.com> wrote in message
news:OH*************@TK2MSFTNGP10.phx.gbl...
Can somebody point me to an explanation of what Reflection is? I've tried
looking in the help and it's not very helpful.

TIA - Jeff.

Nov 22 '05 #2
UJ wrote:
Can somebody point me to an explanation of what Reflection is? I've
tried looking in the help and it's not very helpful.


..NET code is self describing, each class has metadata that describes the
members of the class, their types and parameters. This metadata is
stored in the assembly where the class is defined, so it is always
available. Metadata is a bit like a type library for a COM class, or a
header file for a C++ class.

The metadata format is actually a relational database: there are many
tables which refer to each other. To get access to this data you can use
the unmanaged COM object, so for example to get the types in an assembly
I ask for table 0x02 (TypeDef) and for each type there is a row that
lists the name, namespace, the start index in the MethodDef table (0x06)
for the methods this type implements and the index in the Field table
(0x04). To get the list of methods you use the index and read each row
in the MethodDef table until you get to the methods of the next type
(hence you need to read the method index of the next type before you do
this). The same can be said for fields. The metadata COM object just
reads the metadata tables directly from the assmbly file, and you can do
this yourseld, if you know the position of the tables in the file and
the metadata schema (the .NET spec define both).

Does this sound complicated? Well it isn't, but it is tedious.
Especially since the method definition table does not give an indication
of the type that implements the method, so to do this you have to
iterate through all types, get the range of methods that type implements
and see if your method is in that range.

So that is the physical representation of the metadata. Reflection is a
*logical* representation, and the framework has gone through all the
effort of reading the appropriate metadata tables. So if you have a
MethodInfo for a method you simply have to access the DeclaringType to
get the type that contains the method.

What's the use of reflection?

Well metadata is vitally important in .NET security because metadata
about the *called* type is added to the assembly of the calling type
(MemberRef, TypeRef tables) and when .NET calls the method it compares
the metadata in the calling assembly with the metadata of the type in
the assembly that is being called. These have to match *exactly* for the
method to be called. This prevents the problems that Win32 has with
GetProcAddress.

The main use that you will find for reflection is to have scripting-like
access. The Reflection API gives you information about a type *and* it
allows you to execute instances of that type.

Richard
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Nov 22 '05 #3

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...
2
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray...
2
by: Mark | last post by:
Am I out of my mind if I use Reflection everytime someone logs into our site to get and track the current Major/Minor/Build/Revision version that the person is viewing our site through? This...
0
by: Shawn Hogan | last post by:
Hi everyone, I've been trying to execute a control's private event code via reflection from another class with the goal of potentially doing some unit testing. The examples below are trying to...
3
by: HL | last post by:
The requirement is to send some information to other objects. The objects to whom the information has to be sent is not available at compile time. The names of the types (objects) will be provided...
9
by: Kuberan Naganathan | last post by:
Hello all Does anyone know of a good way to use reflection in c++? I don't mean simply using rtti or dynamic casting. I'm talking about java/c# style reflection where an actual instance of...
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: Gustavo Arriola | last post by:
Hola a todos! Estoy intentando ejecutar un método usando Reflection. El código es el siguiente: public static void SoapHandler(Exception Error) { try { Type assemblyType;
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.