Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi this is dinakar. i want to know where and how do we use reflection
Posted
Comments
Sergey Alexandrovich Kryukov 28-May-11 15:42pm    
When it comes to Reflection, there is no such thing as ASP.NET. Reflection if fundamental .NET (and not only) concept and technology, it has nothing to do with ASP or other application technologies.
--SA

Start from here[^] and also have a look at this MSDN article[^].

This CP article might be of interest too: Using reflection to extend .NET programs[^]

P.S: Try a sample application. If you encounter any difficulties post on CP and you will get lots of suggestions & improvements.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 28-May-11 15:40pm    
Make sense, my 5.

Please see my answer, more detailed.
--SA
TweakBird 29-May-11 13:42pm    
Thanks Manfred R.Bihy for Edit.
Monjurul Habib 29-May-11 14:32pm    
Nice links.my 5.
TweakBird 29-May-11 14:34pm    
Thank you Monjurul.
The class or structure is code. The data about what members every type has, their names and types, what are the signature of each method — all this is meta-data.

Take a initialized variable of any type. It always has a method object.GetType which returns the object of the class System.Type. For a type, you can use typeof operator which also returns the instance of the class System.Type. Look a this class: http://msdn.microsoft.com/en-us/library/system.type.aspx[^], see also http://en.wikipedia.org/wiki/Type_class[^].

You will find that all the meta-data is available through this class. It's also possible to instantiate new objects of the type based on the Type's invocation methods, read or modify properties of the instance. All this is called Reflection. See http://en.wikipedia.org/wiki/Reflection_(computer_science)[^].

It has many application. Using just meta-data approach one can persist data, generate IU on the fly based on pure data (and meta-data added with the use of .NET attributes, see http://msdn.microsoft.com/en-us/library/system.attribute.aspx[^]). One can load assemblies dynamically (see the class System.Reflection.Assembly, http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx[^]) and use it for developing and using plug-ins.

See my past answers explaining a skeleton of plug-in architecture based on Reflection:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^],
code generating using CodeDom[^],
Create WPF Application that uses Reloadable Plugins...[^].

One can even compile code on the fly and use it immediately in the application, see last two of my links above. Finally, one can even generate (emit) code on the fly, see System.Reflection.Emit, http://msdn.microsoft.com/en-us/library/system.reflection.emit.aspx[^].

There is a number of CodeProject articles on the interesting topic of System.Reflection.Emit, see:
http://www.codeproject.com/search.aspx?doctypeid=1&q=Reflection.Emit[^].

—SA
 
Share this answer
 
v3
Comments
TweakBird 29-May-11 6:59am    
Huge Information.My 5!
Sergey Alexandrovich Kryukov 29-May-11 13:29pm    
Thank you very much,
--SA
thatraja 29-May-11 11:30am    
Answer or what? Huge bunch. I have bookmarked this. 5!
Sergey Alexandrovich Kryukov 29-May-11 13:36pm    
Thank you Raja.

Huge or not, but for practical introduction all items do belong here as they show some important practical applications.

Sorry the only field I haven't used in real projects is Reflection.Emit, so I added the CodeProjet keyword search link.
--SA
Monjurul Habib 29-May-11 14:32pm    
all are here..my 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900