Click here to monitor SSC

Bart

Software Engineer - Red Gate Software

.NET Reflector Support: How do I view decompiled source code?

Published Friday, August 07, 2009 6:09 PM

You can view the decompilation output for both types and members in .NET Reflector.

To view a decompilation for a type, right-click on the type in the explorer treeview, and click Disassemble. This is shown in fig. 1, with the resultant decompiler output in fig.2.

Decompiling System.Collections.Hashtable

Figure 1. Generating a decompilation skeleton for a type. Here we are looking at System.Collections.Hashtable.

Decompilation output for System.Collections.Hashtable.

Figure 2. Result of decompiling the System.Collections.Hashtable class to C#.

It's also possible to decompile methods in the same way. As before, right-click on the method and then click on Disassemble. This process is illustrated by figures 3 and 4.

Decompiling the ContainsValue() method on System.Collections.Hashtable.

Figure 3. Decompiling a method. Here we are looking at the ContainsValue() method in System.Collections.Hashtable.

DecompileMethodOutput

Figure 4. Decompiled ContainsValue() method on System.Collections.Hashtable showing C# output.

The examples here have all illustrated C# output, however you can choose other languages for decompiler output using the language drop-down on the toolbar (fig. 5). In figure 6 you can see the ContainsValue() method decompiled to VB.

The language drop-down on the .NET Reflector toolbar.

Figure 5. Using the language drop-down to choose a different decompilation language.

DecompileMethodOutputVB

Figure 6. Decompiled ContainsValue() method on System.Collections.Hashtable showing VB output.

Additional language support add-ins are also available:

If you want to decompile and export source code for an entire assembly, please see the following post:

http://www.simple-talk.com/community/blogs/bart/archive/2009/07/30/74199.aspx

by Bart Read
Filed Under: , ,

Comments

 

DotNetShoutout said:

Thank you for submitting this cool story - Trackback from DotNetShoutout
August 9, 2009 12:23 AM
You need to sign in to comment on this blog

About Bart Read

Bart has done many things since he started work at Red Gate Software Ltd in August 2004, but nowadays he's (mainly) the product manager for the .NET Developer Tools. He still feels like this is a bit like admitting you were cheering for the Empire whilst watching Star Wars, but for now he's along for the ride. In a previous incarnation he was a project manager leading the .NET Reflector Pro, ANTS Memory Profiler 5, ANTS Performance Profiler 4 & 5, and SQL Prompt 3.0 - 3.6 projects. He still occasionally writes some code and, in the past, has touched the code for most of the Red Gate SQL developer tools... some of them still haven't recovered from the shock. He was born and grew up in Dorset, was educated in Nottingham and London, and likes music and real ale. His photo is extremely misleading.
<August 2009>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345
Migrating from OCS 2007 R2 to Lync: Part 4
 Having migrated the rest of our users and legacy resources across, and start getting ready to... Read more...

Automated Script-generation with Powershell and SMO
 In the first of a series of articles on automating the process of building, modifying and copying SQL... Read more...

Seth Godin: Big in the IT Business
 Seth Godin has transformed our understanding of marketing in IT. He invented the concept of 'permission... Read more...

Using SQL Test Database Unit Testing with TeamCity Continuous Integration
 With database applications, the process of test and integration can be frustratingly slow because so... Read more...

Converting String Data to XML and XML to String Data
 We all appreciate that, in general, XML documents or fragments are held in strings as text markup. In... Read more...