Saturday, August 12, 2006

Reflection in .NET

Recenty I was doing some research on reflection in .NET. Questions I was looking at were: When is it to be used? What costs are there to using reflection? What alternatives are there to reflection? Here are some websites that I found to answer these questions: Reflection (A chapter from the book Programming C#) http://www.oreilly.com/catalog/progcsharp/chapter/ch18.html Reflection Demystified http://www.dotnetdevs.com/articles/ReflectionDemystified.aspx Dodge Common Performance Pitfalls to Craft Speedy Applications http://msdn.microsoft.com/msdnmag/issues/05/07/Reflection/ This article compares CodeDOM to Emit (The major difference is that Emit, emits IL code, whereas CodeDOM can generates code in .NET languages like C#, VB....) http://www.fawcette.com/reports/vslivesf/2004/holmes/ In .NET 2.0, there is an alternative to Reflection called Dynamic Code Generation (sort of a light weight Emit) This article from CodeProject talks about it with some good examples: http://www.codeproject.com/useritems/Dynamic_Code_Generation.asp Here is a code project article on using this method to work around the issue of calling properties in a loop using reflection (which is very slow). Fast Dynamic Property/Field Accessors http://www.codeproject.com/csharp/DynamicCodeVsReflection.asp In VS2005, one can use visualizer and here is one for use with Reflection Debugger Visualizer for MethodInfo, DynamicMethod, and MethodBase http://weblogs.asp.net/rosherove/archive/2006/04/25/MethodsVisualizer.aspx ---------------------------------------------------------------------------- One major use of Reflection is for the loading of plugin dlls, using the mechanism of loading a DLL and then using reflection to query and find those types that implement a certain interface. Here is some information regarding this use of Reflection. Remember to scroll down to the "Oops a small problem" part of the article (which talks about doing this querying in a different appdomain). http://weblogs.asp.net/rosherove/pages/8048.aspx

No comments: