Currently I'm reading Jon Skeet's book: C# in Depth: What you need to master C# 2 and 3 - which I highly recommend. For a learning tool, Jon created a utility named Snippy (you can download it from his site's Downloads page). Snippy is a light weight snippet compiler you can use to follow along with the examples in his book (BTW: all the sippets are also downloadable from his site). After using Jon's Snippy a little while, I found myself opening the assemblies in Reflector to see what was really being created by the C# compiler ... which started me thinking about moving the Snippy code to a Reflector addin to save myself one step (plus I was working on the Reflector addin presentation for the Seattle Code Camp).
Addin Download Link: Reflector.Snippy.zip or Reflector.Snippy.dll (latest version is 0.9.2.0 - you can verify your version in the About dialog)
If you are reading Jon's book and want to be able to run the Chapter 8 and Chapter 11 snippets, you'll want to read the section below on "Settings".
Reflector.Snippy adds a submenu named 'Snippy' to the Tools menu and a couple of buttons to the ToolBar (a button for toggling the display of Snippy and another button to cause a build).
||Toggles the display of the Snippy Window|
||Attempts to build the code in the Snippy Window. Any build messages (including error messages from the build) are written to the Output Window - which only shows after a Build has been called for.|
||Not really used - it was something the publisher used. If you really want to know - look at the code.|
||Clears the Snippy (source) window to create a new Snippet|
||Opens an existing snippet file. See the setting section below on how to default the Snippet directory.|
||Saves the code in the Snippy window as a snippet file. This is designed to save a temporary snippet - if you want to reopen later, you should use the Save As snippet. See the setting section below on how this file is named.|
||Allows you to assign a snippet name and pick the location to save the snippet.|
||Exports or allows the user to save the code in the Snippy window (wrapped with the templated code) as a C# file.|
||Displays the credits for the addin.|
The screen below is an example of opening and building an existing snippet from Jon's book (the snippet shown is from Chapter 11). As you can see, Reflector shows you all the details of the tricks the compiler performs ... which is exactly the kind of stuff Jon talks about in his book.
In order to match all the functionality Jon's Snippy has, I created a couple of options dialogs. You can get to the settings page by going to the View menu and choosing the Options item. Once the options dialog is visible, you'll need to choose Snippy in the list to see the settings page.
||Allows the user to set the default directory the addin looks for and/or saves snippets.|
NOTE: if you have downloaded Jon's snippets, you'll want to set this directory to where you saved those snippets.
||Allows the user to set the default directory the dll/exe will be saved in|
||The assembly name to give the compiled snippet|
||The .Net framework to target (only 2.0 and 3.5)|
||Allows the user to either create a dll or an exe|
|Select snippet Main after compile
||Indicates whether the Main method should be automatically selected after a successful build occurs.|
||Launches the References and Namespaces dialog|
The purpose of the References and Namespace dialog is to provide the same options that Jon offers with his Snippy (shown here in the combo box):
The options are provided for determining three things at compile time: the version of the framework to compile for, the assembly references to set and the namespace imports to add (for the code to compile without typing all the fully qualified names).
If you are using Reflector.Snippy and not really running Jon's snippets, then you can type the references and the namespace imports you want to use. All entries should only take a single line (the code uses an Environment.NewLine string for a delimiter).
NOTE: to add references that are not the System.* dll's, you'll need to include the complete path to the dll in the text box.
Example: If you want to use the "Chapter8" option for the compiler settings, then you have 2 options to reference the Chapter8.exe:
1. Save the Chapter8.exe into the directory you have set as the Output Path on the Options dialog.
2. Change the "Chapter8.exe" line in the text box to the complete path of the Chapter8.exe
If you have any feedback or problems with the addin, please email or leave a comment on this blog entry. If anyone is interested in adding color coding or intellisense type functionality to a RichTextbox - please contact me :)