WindowsDevCenter.com
oreilly.comSafari Books Online.Conferences.

advertisement


AddThis Social Bookmark Button

Analyzing Assemblies with Reflector

by James Avery, Jim Holmes
02/20/2007

You'll often need to understand how a class, method, or entire assembly fits into your overall system. Maybe you're reliant upon a third-party library and you're not sure exactly what it depends on. Perhaps a legacy chunk of your own code wasn't as well documented as you'd like, so you're not sure what features of the API you can use. You're left with an unclear picture of how parts of your system interact with each other and the capabilities offered—never a good situation.

Lutz Roeder's Reflector can help clear up situations like this. Reflector lets you explore any .NET assembly to find its dependencies and callers, or dive down and explore an entire assembly. Additionally, you can use tools within Reflector to decompile an assembly to see how the code was written.

Reflector at a Glance

Tool Reflector
Version covered 4.2.42.0
Home page http://www.aisto.com/roeder/dotnet/
Power Tools page http://www.windevpowertools.com/tools/92
Summary A great tool for exploring APIs in an assembly and learning more about how that assembly is used
License type Freeware
Online resources Bug tracker, message board
Supported frameworks .NET 1.0, 1.1, 2.0;Compact Framework (CF) 1.0, 2.0
Related tools in this book ILDASM, DILE, Reflector.Diff, Peli's Reflector Addins

Getting Started

The Reflector download is a simple .zip containing a Readme file and the actual executable. Drop the executable in a convenient folder and fire it up. (Reflector runs just fine under a non-Administrator account.) Reflector works with all versions of the full and compact .NET Frameworks. The first time you start Reflector, you'll be prompted to select which version you want loaded (Figure 1).


Figure 1. Selecting the initial set of assemblies

Using Reflector

After you've selected which Framework to load, Reflector will populate its display with the applicable assemblies. At this point, you're ready to open the assemblies you want to examine.

Load additional assemblies by dragging them onto Reflector or via the File→Open menu command. Reflector's main pane provides a tree-based display for browsing loaded assemblies. A separate pane opens up on the right when you're using additional features, such as when viewing documentation, analysis information, or an assembly's source code.

Browsing Assemblies

Expanding and browsing through an assembly shows you all the information about that assembly, such as its references, contained namespaces, and physical location. You can look through each class and see not only public or internal-scoped items, but private members as well.

Tip

The "-" node shows some rather obscure internals. Here you'll find a few hidden details about classes, such as types automatically generated by the C# compiler, C++ global methods in the Module node, and various bits of versioning information plopped in by the CLR. None of this is commonly usable, but it's there. You can most likely use the knowledge to win CLR and assembly trivia games at parties.

Figure 2 shows the Documentation window, accessed by pressing F1 or selecting View→Documentation, displaying comments on the CodeExporter class of the System.Xml.Serialization namespace.


Figure 2. Browsing the System.Xml namespace

Tip

Documentation is available only if you've first created comments using the summary elements for classes, methods, properties, and so on. You'll also need to create the XML comments file by checking the "XML documentation file" option in the Output section of the Build tab in the Project Properties window.

Links in documentation from elements such as seealso will show up as hyperlinks, enabling you to quickly move between related classes, as long as the developers have helped you out with good documentation!

Pages: 1, 2

Next Pagearrow