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#) Reflection Demystified Dodge Common Performance Pitfalls to Craft Speedy Applications 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....) 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: 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 In VS2005, one can use visualizer and here is one for use with Reflection Debugger Visualizer for MethodInfo, DynamicMethod, and MethodBase ---------------------------------------------------------------------------- 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).

No comments: