Reviews

Review: Reflector 4.0

Lutz Roeder's .NET Reflector 4.0.0.0
Free
www.aisto.com/roeder

Reflector is a free utility that many .NET developers consider an essential. It's quite simple in concept: it uses the metadata embedded in .NET assemblies to show you what the assembly actually does. Perhaps this is simplest to explain by example. Suppose you're trying to figure out exactly what a particular method in the .NET Framework does - say, System.Text.RegularExpressions.Regex.IsMatch(string). To do so, you can fire up Reflector, load the appropriate DLL, navigate down to the method in question, and select Decompiler from the Tools menu. The result:


public bool IsMatch(string input)
  {
    if (input == null)
    {
      throw new ArgumentNullException("input");
 	}
  return (null == this.Run(true, -1, input, 0, input.Length,
   (this.UseOptionR() ? input.Length : 0)));
}
 

Or, if you'd prefer, switch the language to VB .NET (Delphi is also supported) and decompile again:


Public Function IsMatch(ByVal input As String) As Boolean
  If (input Is Nothing) Then 
    Throw New ArgumentNullException("input")
  End If 
  Return (Nothing Is Me.Run(True, -1, input, 0, input.Length,
   IIf(Me.UseOptionR, input.Length, 0)))
End Function 

You can also disassemble straight into MSIL, or see caller or callee graphs for the method. Single keystrokes will search Google or MSDN for relevant information, or you can just view the member documentation directly within Reflector (assuming that there is XML documentation in the assembly).

This latest version is improved over previous revisions in several ways, notably by using its own code model instead of stock .NET reflection to get the metadata. This removes any chance of Reflector locking an assembly in memory, and also means it can work on any version of the .NET Framework, including current builds of the 1.5 and 2.0 versions. Reflector also has an add-in model to allow extending its use; in particular, you may want to grab the add-in that integrates Reflector directly with Visual Studio .NET (although at the moment it only works with C# projects). In any case, if you run into knotty problems in the .NET Framework, or in other assemblies to which you do not have the source, Reflector is a lifesaver.

About the Author

Mike Gunderloy has been developing software for a quarter-century now, and writing about it for nearly as long. He walked away from a .NET development career in 2006 and has been a happy Rails user ever since. Mike blogs at A Fresh Cup.