Analyzing Assemblies with Reflector
Pages: 1, 2
You can research system interactions by using the Tools→Analyze (Ctrl-R) option to display all the dependencies of a class or method, as well as who is calling that item. This helps you to develop a great understanding of the system's dynamic behavior. Figure 3 shows what methods make use of the
Find( ) method selected in the browser pane. Such information is very useful, as you can see how various callers are making use of any particular resource in an assembly.
Figure 3. Dependencies and callers for a method
Reflector also greatly improves your ability to do quick research on classes or methods. Highlight a method in the browser pane and select Tools→Search MSDN (or press Ctrl-M), and the appropriate MSDN help page will pop up in the righthand pane (Figure 4). Tools→Search Google (Ctrl-G) does the same thing with a Google search.
Figure 4. MSDN search results right inside Reflector
Some assemblies and namespaces contain an enormous number of members. Sometimes it's nearly impossible to find the exact class or method you're looking for. Pressing F3 will launch Reflector's Search function and populate the righthand pane with the member names of all loaded assemblies. You can quickly narrow down the results by typing in parts of a search phrase in the Search field. Figure 5 shows a search for members whose type names or namespaces contain the text "validation."
Figure 5. Using Reflector's Search feature
Doing the Disassembly Thing
Another benefit of Reflector is its ability to disassemble compiled assemblies. Selecting an assembly in the browser pane and pressing the Space bar or selecting Tools→Disassembler will reveal the source code used to create those assemblies (Figure 6). This is very handy if you've gotten an assembly from a third party and you need to understand its inner workings to better use it.
Figure 6. Disassembling a method from ObjectMapper
This is a powerful feature of Reflector, but it's also easily misused. Just because you have a tool that can reveal someone's intellectual property doesn't mean you should use it for that purpose. (And if you do, you might be breaking the law!)
One of the best features of Reflector is the amazing wealth of add-ins that have been created for it (Roeder maintains a list at http://aisto.com/incoming/reflector/addins/). There are Reflector add-ins to help you with everything from differencing files to creating code metrics for assemblies. Be sure to read section 9.1 in Chapter 9 of Windows Developer Power Tools for examples of some of the cool extensions available for Reflector.
Reflector in a Nutshell
Reflector is perhaps the single most important tool for .NET developers. Sure, it will disassemble files if you need it to, but its primary focus is to help you learn how to best use the assemblies you have on hand. It's multipurpose, it's powerful, and it's a tremendous aid for research and education. Reflector and its add-ins help thousands of developers around the globe each day.
James Avery has been programming with Microsoft technologies for the last 7 years and has been working with .NET since the second beta release.
Jim Holmes has nearly 25 years experience in the IT industry, including network management, systems analysis, and software development in Perl, Java, C++, and .NET.
Return to WindowsDevCenter.com.
Works on mono too!
2007-02-21 01:48:30 TomPotts [View]