<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stefano Ricciardi &#187; Visual Studio 2008</title>
	<atom:link href="http://stefanoricciardi.com/tag/visual-studio-2008/feed/" rel="self" type="application/rss+xml" />
	<link>http://stefanoricciardi.com</link>
	<description>On Software Development and Thereabouts</description>
	<lastBuildDate>Tue, 15 Nov 2011 07:57:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>See Your XML Docs As You Type With CR Documentor</title>
		<link>http://stefanoricciardi.com/2010/01/22/see-your-xml-docs-as-you-type-with-cr-documentor/</link>
		<comments>http://stefanoricciardi.com/2010/01/22/see-your-xml-docs-as-you-type-with-cr-documentor/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 19:39:29 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Documentor]]></category>
		<category><![CDATA[Ghost-Doc]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.wordpress.com/?p=701</guid>
		<description><![CDATA[Introduction Almost 10 years ago now I used to be a Java developer in Motorola. After a long hiatus in the embedded systems and a job change, I have come back to enterprise development, this time in .Net. I remembered that in the good ol’ days it required 2 steps to see the final rendering [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F01%2F22%2Fsee-your-xml-docs-as-you-type-with-cr-documentor%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F01%2F22%2Fsee-your-xml-docs-as-you-type-with-cr-documentor%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h3>Introduction</h3>
<p>Almost 10 years ago now I used to be a Java developer in Motorola. After a long hiatus in the embedded systems and a job change, I have come back to enterprise development, this time in .Net.</p>
<p>I remembered that in the good ol’ days it required 2 steps to see the final rendering of the XML documentation: firing javadoc (usually from within an ANT task) and the open up the content in a browser.</p>
<p>I was quite surprised to see that in the .Net area seeing the final output of the docs was not as straightforward as I hoped for. Yes, there was <a href="http://ndoc.sourceforge.net/">NDoc</a> to parse the XML, but its development stopped around 2005 and it’s doesn’t support anything beyond C# 2.0. There’s also <a href="http://www.codeplex.com/Sandcastle">Sandcastle</a>, but to make it work for me it has required a few downloads and a bit of tweaking here and there. And integrating it into my NAnt task had not been that easy either. But somehow in the end I have pulled that out.</p>
<p>Therefore I have been pleasantly surprised when I met <strong>CR Documentor, </strong>a little plug-in for visual studio that let’s you see your XML documentation <em>as you write it</em>. It’s almost like having a WYSIWYG editor, without having to launch Sandcastle, wait for the complete build, and open up the browser.</p>
<h3>Installation</h3>
<ul>
<li><a href="http://code.google.com/p/cr-documentor/"><img style="display:inline;border-width:0;margin:0;" title="cr_documentor-logo" src="http://stefanoricciardi.files.wordpress.com/2010/01/cr_documentorlogo.gif" border="0" alt="cr_documentor-logo" width="100" height="102" align="right" /></a>Requirements:
<ul>
<li>Visual Studio 2005 or greater (I am pretty confident that you need at least a Professional version as opposed to Express). I am running it on Visual Studio Team System 2008, not sure whether it works also on 2010.</li>
<li>The DXCore plugin framework from DevExpress. Possibly the best (and only?) way to get it is to get through the excellent free <a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/">CodeRush Xpress for C# and VB</a></li>
</ul>
</li>
<li>Download the plugin: CR Documentor is hosted at Google Code at <a href="http://code.google.com/p/cr-documentor/">this link</a>.</li>
<li>Copy the dll in your DX-Core plugin-folder (<tt>C:\Users\&lt;username&gt;\Documents\DevExpress\IDE Tools\Community\PlugIns</tt>)</li>
<li>Restart Visual Studio</li>
</ul>
<h3>Usage</h3>
<ol>
<li>CR Documentor adds itself in the right click menu, close to the bottom. From the submenu, choose “Show CR_Documentor window”.<a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/cr_documentor1.png"><img style="display:inline;margin-left:0;margin-right:0;border-width:0;" title="CR_documentor-1" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/cr_documentor1_thumb.png" border="0" alt="CR_documentor-1" width="244" height="212" /></a></li>
<li>A new window opens up in floating mode (I prefer to dock-it to the right side together with my solution explorer and luckily the plug-in remembers this choice every time I open the window after closing it and at startup).<a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/image.png"><img style="display:inline;border-width:0;" title="image" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/image_thumb.png" border="0" alt="image" width="244" height="127" /></a></li>
<li>Now every time your cursor is on an XML doc, you can see the preview in the Documentor window. See for example when I put the cursor on the XML doc of a class: I get a complete picture of the documentation for that class and its methods all in real time.<br />
<a href="http://stefanoricciardi.files.wordpress.com/2010/01/image1.png"><img style="display:inline;border-width:0;" title="image" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/image_thumb1.png" border="0" alt="image" width="229" height="244" /></a></li>
<li>There are a few other features that I don’t use very often. All of them are accessible by the right-click content sensitive menu:
<ul>
<li>Expand/Collapse all XML comments in the editor</li>
<li>Insert XML docs templates (<a href="http://stefanoricciardi.com/2009/06/19/must-have-vs-2008-free-plug-ins-2-ghost-doc/">I prefer to use GhostDoc for that</a>).</li>
<li></li>
</ul>
</li>
</ol>
<h3>Configuration</h3>
<p>Like all DXCore plugins, you can access to the configuration by pressing ALT+CTRL+SHIFT+O combination. I like to check all my options to Sandcastle because that’s the tool that I will be using to create the final XML documentation.</p>
<p><a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/image2.png"><img style="display:inline;border-width:0;" title="image" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2010/01/image_thumb2.png" border="0" alt="image" width="244" height="161" /></a></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fstefanoricciardi.com%2f2010%2f01%2f22%2fsee-your-xml-docs-as-you-type-with-cr-documentor%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fstefanoricciardi.com%2f2010%2f01%2f22%2fsee-your-xml-docs-as-you-type-with-cr-documentor%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p><a rev="vote-for" href="http://dotnetshoutout.com/See-Your-XML-Docs-As-You-Type-With-CR-Documentor-Stefano-Ricciardis-Blog"><img style="border:0;" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fstefanoricciardi.com%2F2010%2F01%2F22%2Fsee-your-xml-docs-as-you-type-with-cr-documentor%2F" alt="Shout it" /></a></p>
<p><!-- AddThis Button BEGIN --></p>
<p><a href="http://www.addthis.com/bookmark.php?v=250"><img style="border-width:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e6ceeafa-fe5c-4bd6-a48d-325da43e5abc" class="wlWriterSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Programming">Programming</a>,<a rel="tag" href="http://technorati.com/tags/C%23">C#</a>,<a rel="tag" href="http://technorati.com/tags/visual+Studio+2008">visual Studio 2008</a>,<a rel="tag" href="http://technorati.com/tags/Tools">Tools</a></div>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2010/01/22/see-your-xml-docs-as-you-type-with-cr-documentor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio Tip: No Regions Around Implemented Interfaces</title>
		<link>http://stefanoricciardi.com/2009/09/10/visual-studio-tip-no-regions-around-implemented-interfaces/</link>
		<comments>http://stefanoricciardi.com/2009/09/10/visual-studio-tip-no-regions-around-implemented-interfaces/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 10:25:59 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.net/?p=344</guid>
		<description><![CDATA[One of the (many) useful features of Visual Studio is the Implement Interface. With it, if you declare a class as implementing a particular interface, you can have Visual Studio generate stubs for all the methods declared by that interface. With default settings, Visual Studio will place regions around the stubs that it just generated: [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F09%2F10%2Fvisual-studio-tip-no-regions-around-implemented-interfaces%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F09%2F10%2Fvisual-studio-tip-no-regions-around-implemented-interfaces%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>One of the (many) useful features of Visual Studio is the Implement Interface. With it, if you declare a class as implementing a particular interface, you can have Visual Studio generate stubs for all the methods declared by that interface.</p>
<p><a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/09/testimplementinterfacenoregion1.jpg"><img class="aligncenter size-full wp-image-345" title="Visual Studio Implement Interface" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/09/testimplementinterfacenoregion1.jpg" alt="Visual Studio Implement Interface" width="522" height="176" /></a></p>
<p>With default settings, Visual Studio will place regions around the stubs that it just generated:</p>
<p>
<a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/09/testimplementinterfacenoregion21.jpg"><img src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/09/testimplementinterfacenoregion21.jpg" alt="Visual Studio putting regions around implemented interfaces" title="Visual Studio putting regions around implemented interfaces" width="480" height="305" class="aligncenter size-full wp-image-350" /></a>
</p>
<p>As you may know from previous posts, I am not a fan of using regions within C# code. I tend to favor lean classes and short methods, I find regions almost useless; worse, they tend to visually clutter the code.</p>
<p>
Luckily, there&#8217;s a way to configure Visual Studio not to put regions around implemented interfaces. It&#8217;s buried under Tools-&gt;Options-&gt;Text Editor-&gt;C#-&gt;Advanced. Simply uncheck the &#8220;Surround generated code with #region&#8221; in the &#8220;Implement interface&#8221; group: </p>
<p>
<a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/09/testimplementinterfacenoregion3.jpg"><img src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/09/testimplementinterfacenoregion3.jpg" alt="Configuring Visual Studio to remove regions around interfaces" title="Configuring Visual Studio to remove regions around interfaces" width="600" height="356" class="aligncenter size-full wp-image-352" /></a>
</p>
<p>
Voilà. You now have all your stubs ready to be implemented, without those annoying regions around:
</p>
<p>
<a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/09/testimplementinterfacenoregion4.jpg"><img src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/09/testimplementinterfacenoregion4.jpg" alt="Interfaces implemented without regions around" title="Interfaces implemented without regions around" width="486" height="248" class="aligncenter size-full wp-image-353" /></a>
</p>
<p><!-- AddThis Button BEGIN --></p>
<p><a href="http://www.addthis.com/bookmark.php?v=250"><img style="border:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a></p>
<p><!-- AddThis Button END --></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e6ceeafa-fe5c-4bd6-a48d-325da43e5abc" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Programming">Programming</a>, <a rel="tag" href="http://technorati.com/tags/visualstudio">VisualStudio</a></div>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2009/09/10/visual-studio-tip-no-regions-around-implemented-interfaces/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>More Visual Studio 2008 Shortcuts: Trasposing Characters, Words and Lines</title>
		<link>http://stefanoricciardi.com/2009/08/13/more-visual-studio-2008-shortcuts-trasposing-characters-words-and-lines/</link>
		<comments>http://stefanoricciardi.com/2009/08/13/more-visual-studio-2008-shortcuts-trasposing-characters-words-and-lines/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 16:30:25 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.net/?p=277</guid>
		<description><![CDATA[I love shortcuts. I really do. So with some excitement I have found a few in the Visual Studio Editor that may come handy once in a while. These are the shortcuts to transpose characters, words and lines: CTRL + T Transpose characters CTRL + SHIFT + T Transpose words ALT + SHIFT + T [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F08%2F13%2Fmore-visual-studio-2008-shortcuts-trasposing-characters-words-and-lines%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F08%2F13%2Fmore-visual-studio-2008-shortcuts-trasposing-characters-words-and-lines%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I love <a href="http://stefanoricciardi.com/2009/06/10/most-useful-visual-studio-2008-keyboard-shortcuts/">shortcuts</a>. I really do. So with some excitement I have found a few in the Visual Studio Editor that may come handy once in a while. These are the shortcuts to transpose characters, words and lines:</p>
<table border="0" cellspacing="0" cellpadding="2" width="580">
<tbody>
<tr>
<td width="150" valign="top">CTRL + T</td>
<td width="430" valign="top"><strong>Transpose characters</strong></td>
</tr>
<tr>
<td width="150" valign="top">CTRL + SHIFT + T</td>
<td width="430" valign="top"><strong>Transpose words</strong></td>
</tr>
<tr>
<td width="150" valign="top">ALT + SHIFT + T</td>
<td width="430" valign="top"><strong>Transpose lines</strong></td>
</tr>
</tbody>
</table>
<h3>Transposing Characters (CTRL+T)</h3>
<p>This is mostly useful if you mispelled a word. Since most code typing is done with Intellisense, I have found this useful for comments mostly.</p>
<h3>Transposing Words (CTRL + SHIFT + T)</h3>
<p>Beside the occasional typo writing comments, this is handy when after refactoring a function signature I have changed the order of the parameters.<br />
Suppose you have for example you call a function in the following way:</p>
<p><code>calculateVat(price, percentage)</code></p>
<p>if for whatever reason <code>calculateVat</code> signature has changed so that the percentage comes first, you just need to put the cursor on <code>price</code> or between the two words and pressing CTRL + SHIFT + T you&#8217;ll have the following:</p>
<p><code>calculateVat(percentage, price)</code></p>
<h3>Transposing lines (ALT + SHIFT + T)</h3>
<p>I use the following formatting to wrap long function signauters across more lines:</p>
<pre class="brush:csharp">
public void AddEmployee(
    string name,
    string surname,
    string address,
    string homePhone,
    string mobilePhone,
    string email)
{
   // implementation here
}
</pre>
<p>Suppose that I decide that I want to reorder the parameters such that the mobilePhone comes before than homePhone, for whichever reason. I just need to place the cursor somewhere on the line of &#8220;homePhone&#8221; and the two lines will swap. To remember which is the direction of swapping, my mnemonic is that the line where the cursor is will <em>fall</em>.</p>
<pre class="brush:csharp">
public void AddEmployee(
    string name,
    string surname,
    string address,
    string mobilePhone, // this line has moved up
    string homePhone,  // this line has moved down
    string email)
{
   // implementation here
}
</pre>
<p>This is especially useful if you have more overloads of the same function where you need to update the order of the parameters in each of them. It&#8217;s certainly quicker than a copy&amp;paste tecnhique.</p>
<p>If you need to move one line of more than one position down, just keep pressing the ALT + SHIFT + T combination and the line will keep falling down (the cursor automatically stays in the line that is moving).</p>
<p><!-- AddThis Button BEGIN --></p>
<p><a href="http://www.addthis.com/bookmark.php?v=250"><img style="border:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a></p>
<p><!-- AddThis Button END --></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e6ceeafa-fe5c-4bd6-a48d-325da43e5abc" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Programming">Programming</a>, <a rel="tag" href="http://technorati.com/tags/visualstudio">VisualStudio</a></div>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2009/08/13/more-visual-studio-2008-shortcuts-trasposing-characters-words-and-lines/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introduction to Microsoft Code Contracts with Visual Studio 2008</title>
		<link>http://stefanoricciardi.com/2009/06/26/introduction-to-microsoft-code-contracts-with-visual-studio-2008/</link>
		<comments>http://stefanoricciardi.com/2009/06/26/introduction-to-microsoft-code-contracts-with-visual-studio-2008/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 13:16:35 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.net/?p=131</guid>
		<description><![CDATA[(zdwfg7nay2) Design by Contract was first introduced by Bertrand Meyer, creator of the Eiffel programming language,  in his seminal book Object-oriented Software Construction. In a nutshell, DBC is based on the following principles: preconditions: a method imposes on the client a set of conditions that must be met in order for the method to be [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F06%2F26%2Fintroduction-to-microsoft-code-contracts-with-visual-studio-2008%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F06%2F26%2Fintroduction-to-microsoft-code-contracts-with-visual-studio-2008%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>(zdwfg7nay2)</p>
<p>
Design by Contract was first introduced by<a href="http://en.wikipedia.org/wiki/Bertrand_Meyer" target="_blank"> Bertrand Meyer</a>, creator of the Eiffel programming language,  in his seminal book <a href="http://www.amazon.co.uk/Object-oriented-Software-Construction-Prentice-Hall-Resource/dp/0136291554/ref=sr_1_1?ie=UTF8&amp;qid=1246018059&amp;sr=8-1" target="_blank">Object-oriented Software Construction</a>. In a nutshell, DBC is based on the following principles:</p>
<ul>
<li> <em>preconditions</em>: a method imposes on the client a set of conditions that must be met in order for the method to be invoked successfully (think about parameters validation).</li>
<li> <em>postconditions</em>: a set of properties are guaranteed by the method immediately after the execution (think about a return value that can only be positive, for example).</li>
<li> <em>invariants</em>: a set of properties on the class are assumed to hold before the method starts and are guaranteed to hold after the method completes (think about a field of the class that may not be negative, for example).</li>
</ul>
<p>A contract formalizes these three things. How can contracts, and <em>defensive programming</em> in general, help us developing better software? Bertrand Meyer explains it in this <a href="http://www.artima.com/intv/contracts.html">interview</a> from 2003:</p>
<blockquote><p>The main purpose of contracts is to help us build better software by organizing the communication between software elements through specifying, as precisely as possible, the mutual obligations and benefits that are involved in those communications. [...] relying on these  notions—that is to say, making sure when you write software that don&#8217;t just write  the implementation, but also write the more abstract properties underlying the  implementation in the form of contracts—provides a greatly added software  development experience in several respects. It helps ensure correctness in the first place,  helps debugging, helps testing, helps ensure inheritance is properly handled, helps  managers, provides a quite effective form of documentation, and a few others.</p></blockquote>
<p>Up to now, only a few languages supported DBC natively, and C# was not one of those. With .NET 4.0 Microsoft fills this gap with <a href="http://research.microsoft.com/en-us/projects/contracts/">Code Contracts</a>. It&#8217;s possible to download Code Contracts for Visual Studio 2008 for the Standard Edition and the Team System edition.</p>
<h3>A Basic Example</h3>
<p>Let&#8217;s see a basic example of how one can use Contracts in a simple class. (to try this on your own you need to install Code Contracts from <a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx">msdn web site</a>). In this case I have a class with a static method that simply inverts the content of a string (the choice of the algorithm here is irrelevant).</p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.Diagnostics.Contracts;

namespace TestContracts
{
  public class StringInverter
  {
    public static string Invert(string s)
    {
      // preconditions:
      Contract.Requires(s != null);

      // postconditions;
      Contract.Ensures(Contract.Result&amp;lt;string&amp;gt;().Length == s.Length);

      char[] reverted = new char[s.Length];
      int i = 0;
      foreach (char c in s)
      {
        reverted[s.Length - 1 - i ] = c;
        i++;
      }

      return new string(reverted);
    }
  }
}
</pre>
<p>The first thing to notice is that we have added a reference to the <tt>System.Diagnostics.Contracts</tt> namespace. This is where the new library is located. For this to work you have also to add a reference in your project to the Microsoft.Contracts assembly that has come with the Code Contracts installation.</p>
<p><img class="aligncenter size-full wp-image-137" title="Contracts_VSReferences" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/contracts_vsreferences.jpg" alt="Contracts_VSReferences" width="225" height="207" /></p>
<p>The first method that we invoke on Contracts is a <em>precondition</em> that specifies that this method cannot accept an input string which is null (it would accept an empty string though). The second method is a <em>postcondition</em> asserting that this method guarantees that the string returned by this method will have the same size as the input string.</p>
<p>Obviously you are free to add more preconditions and/or postconditions if your domain logic requires so. But what exactly happens at run-time if either a precontion or a postcondition is not met? The answer is: it depends. After installing Code Contracts, project properties displays a new tab at the bottom named &#8220;Code Contracts&#8221; where you can tweak the contracts behavior for each of the build configurations that you have defined (Debug, Release, etc&#8230;).</p>
<p><a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/contracts_projectsproperties_1.jpg"><img class="aligncenter size-medium wp-image-147" title="Contracts Project Properties" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/contracts_projectsproperties_1.jpg?w=300" alt="Contracts Project Properties" width="300" height="225" /></a></p>
<p>Let&#8217;s concentrate on Runtime Checking for now: after you have checked it, you can decide which kind of contracts to enable; you should refer to official documentation for a complete explanation of all the options. For now, let&#8217;s just pick &#8220;Full&#8221; and check &#8220;Assert on contract failures&#8221;. With this choice, pre and postconditions will be tested at runtime and if any of them is not met a dialog will be shown detailing the failing condition.</p>
<p><img class="aligncenter size-full wp-image-152" title="Contracts_ProjectsProperties_2" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/contracts_projectsproperties_2.jpg" alt="Contracts_ProjectsProperties_2" width="497" height="96" /></p>
<p>So, let&#8217;s try calling the <tt>Invert</tt> method with a null string and let&#8217;s see what happens. Add the following code to the class above, compile and run.</p>
<pre class="brush: csharp; title: ; notranslate">
public static void Main()
{
  Console.WriteLine(Invert(null));
}
</pre>
<p>This is what you should see:<br />
<img class="aligncenter size-full wp-image-155" title="ContractsAssertFailedPrecondition" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/contractsassertfailedprecondition.jpg" alt="ContractsAssertFailedPrecondition" width="496" height="347" /></p>
<p>As you can see, this looks exactly like using <tt>Debug.Assert</tt> calls from <tt>System.Diagnostics</tt> (many of us, myself included, used debug asserts in place of preconditions). In reality, contracts are much more powerful since</p>
<ul>
<li>you can not just enforce preconditions but also guarantee postconditions and other class invariants</li>
<li>contracts knows about class hierarchies: you can define contracts on interfaces and base classes and they will be inherited from derived classes</li>
<li>it&#8217;s possible to analyse compliance to contracts in a static way, even without running the code!</li>
</ul>
<p>We&#8217;ll discuss about all this in the next post. Stay tuned!</p>
<p><i>Next post in the series: <a href="http://stefanoricciardi.com/2009/07/01/code-contracts-invariants/">Code Contracts: Invariants</a></i>.</p>
<p><!-- AddThis Button BEGIN --></p>
<p><a href="http://www.addthis.com/bookmark.php?v=250"><img style="border:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a></p>
<p><!-- AddThis Button END --></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e6ceeafa-fe5c-4bd6-a48d-325da43e5abc" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Programming">Programming</a>, <a rel="tag" href="http://technorati.com/tags/C%23">C#</a>, <a rel="tag" href="http://technorati.com/tags/visual+Studio+2008">Visual Studio 2008</a>, <a rel="tag" href="http://technorati.com/tags/design">Design</a></div>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2009/06/26/introduction-to-microsoft-code-contracts-with-visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Must have VS 2008 Free Plug-ins (2): Ghost-Doc</title>
		<link>http://stefanoricciardi.com/2009/06/19/must-have-vs-2008-free-plug-ins-2-ghost-doc/</link>
		<comments>http://stefanoricciardi.com/2009/06/19/must-have-vs-2008-free-plug-ins-2-ghost-doc/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 20:29:39 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Ghost-Doc]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.wordpress.com/?p=101</guid>
		<description><![CDATA[According to the Wikipedia, a ghostwriter is a professional writer who is paid to write books, articles, stories, reports, or other texts that are officially credited to another person. As the name seems to imply, Ghost-Doc plug-in for Visual Studio is something like that: instead of typing in the XML documentation for your source code [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F06%2F19%2Fmust-have-vs-2008-free-plug-ins-2-ghost-doc%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F06%2F19%2Fmust-have-vs-2008-free-plug-ins-2-ghost-doc%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>According to the Wikipedia, a <em><a href="http://en.wikipedia.org/wiki/Ghostwriter">ghostwriter</a></em> is a</p>
<blockquote><p>professional <a href="http://en.wikipedia.org/wiki/Writer">writer</a> who is paid to write books, articles, stories, reports, or other texts that are officially credited to another person.</p></blockquote>
<p><span>As the name seems to imply, <a href="http://submain.com/products/ghostdoc.aspx">Ghost-Doc</a> plug-in for Visual Studio is something like that: instead of typing in the XML documentation for your source code yourself, Ghost-Doc does the heavy-lifting and fills it for you.</span></p>
<p>Suppose you have a very simple class like the following:</p>
<pre class="brush: csharp; title: ; notranslate">
public sealed class TestGhostDoc
{
    double CalculateVAT(double priceOfGoods, double VATPercentage)
    {
        return (priceOfGoods + priceOfGoods * VATPercentage);
    }
}
</pre>
<p>Now you want to add XML documentation for the CalculateVAT member function. All you have to do is to right-click somewhere on line 3 (I prefer to use the <tt>CTRL + SHIFT + D</tt> since <a href="http://stefanoricciardi.com/2009/06/10/most-useful-visual-studio-2008-keyboard-shortcuts/">I love shortcuts</a>), select “Document This”, and Ghost-Doc will fill the XML documentation for you like the following:</p>
<pre class="brush:csharp">
public sealed class TestGhostDoc
{
    /// &lt;summary&gt;
    /// Calculates the VAT.
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;priceOfGoods&quot;&gt;The price of goods&lt;/param&gt;
    /// &lt;param name=&quot;VATPercentage&quot;&gt;The VAT percentage&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    double CalculateVAT(double priceOfGoods, double VATPercentage)
    {
        return priceOfGoods += priceOfGoods * VATPercentage;
    }
}
</pre>
<p>As you can see, Ghost-Doc, beside filling the structure for you, also fills the contents using a set of rules based on the order of the words (the only thing that is left is filling the content of the <tt>returns</tt> tag). Note that words are recognized successfully only if you use the recommended Camel and Pascal casing appropriately (which you ought to be doing anyway because you <a href="http://stefanoricciardi.com/2009/06/12/must-have-vs-2008-free-plug-ins-1-style-cop/">follow to the naming conventions</a>).</p>
<p>Member functions is not the only place where you can use Ghost-Doc: class names, constructors, enums, properties, event, etc… they are all supported as expected.</p>
<pre class="brush:csharp">
namespace TestGhostDoc
{
    /// &lt;summary&gt;
    ///
    /// &lt;/summary&gt;
    public sealed class User
    {
        /// &lt;summary&gt;
        /// Gets or sets the first name.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The first name.&lt;/value&gt;
        public string FirstName { get; set;  }

        /// &lt;summary&gt;
        /// Gets the address.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The address.&lt;/value&gt;
        public string Address { get; }
    }
}
</pre>
<p>Can you spot the difference between the documentations of the two properties that Ghost-Doc has generated?</p>
<h3>Advanced use</h3>
<p>Ghost-Doc has a complete customization window:<br />
<a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/ghostdoc.png"><img style="display:inline;border-width:0;" title="GhostDoc" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/ghostdoc_thumb.png" border="0" alt="GhostDoc" width="490" height="397" /></a></p>
<p>In these tabs you can</p>
<ul>
<li>modify/add templates that Ghost-Doc uses to document a language element</li>
<li>define your own acronyms, that will always be rendered in all-caps by Ghost-Doc, even if you have written them in lower case inside a language element name to be compliant to the naming conventions</li>
<li>modify/add the list of words which define qualities, that Ghost-Doc will reorder in a special way. For example, since <em>size</em> is on this special list &#8220;FileBufferSize will be worded as “the size of the file buffer” instead of “the file buffer size” .</li>
<li>modify/add the list of words that shall never be preceded by “the” (the so called “no the” words).</li>
<li>Modify the way <em>true</em>, <em>false</em>, and <em>null </em>keywords are represented</li>
<li>Create a custom text that will be appended to all comments the first time they are created; this text can optionally be dynamic and include the name of the author, or the current date, etc.. (this would be a bit over the top IMHO since it would be repeated for each and every function, property, etc…).</li>
</ul>
<p>With Ghost-Doc, you have no more excuses not to write complete and accurate XML source code documentation!<br />
<!-- AddThis Button BEGIN --><br />
<a href="http://www.addthis.com/bookmark.php?v=250"><img style="border:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a><br />
<!-- AddThis Button END --></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e6ceeafa-fe5c-4bd6-a48d-325da43e5abc" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Programming">Programming</a>, <a rel="tag" href="http://technorati.com/tags/C%23">C#</a>, <a rel="tag" href="http://technorati.com/tags/visual+Studio+2008">Visual Studio 2008</a>, <a rel="tag" href="http://technorati.com/tags/plugin">Plugin</a>, <a rel="tag" href="http://technorati.com/tags/Tools">Tools</a></div>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2009/06/19/must-have-vs-2008-free-plug-ins-2-ghost-doc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Must have VS 2008 Free Plug-ins (1): Style Cop</title>
		<link>http://stefanoricciardi.com/2009/06/12/must-have-vs-2008-free-plug-ins-1-style-cop/</link>
		<comments>http://stefanoricciardi.com/2009/06/12/must-have-vs-2008-free-plug-ins-1-style-cop/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 20:59:36 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding Standards]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[StyleCop]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.wordpress.com/?p=91</guid>
		<description><![CDATA[Coding standards is one of those topics which can easily create endless discussions between developers (Steve McConnell prefers the term religious wars in his famous book Code Complete). Everybody seems to have his/her own preferences and pet peeves when it comes to the lay out of statements and naming of types and variables (not to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F06%2F12%2Fmust-have-vs-2008-free-plug-ins-1-style-cop%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F06%2F12%2Fmust-have-vs-2008-free-plug-ins-1-style-cop%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Coding standards is one of those topics which can easily create endless discussions between developers (Steve McConnell prefers the term <em>religious wars</em> in his famous book Code Complete). Everybody seems to have his/her own preferences and pet peeves when it comes to the lay out of statements and naming of types and variables (not to mention the eternal “<a href="http://www.codinghorror.com/blog/archives/001254.html">tab vs spaces</a>” argument).</p>
<p>All the programming languages that I have worked with have their own guidelines when it comes to coding standards. Or have they? The C language, father of C++, C# and Java languages, has its own share of style variations: Emacs supports half a dozen C coding styles (K&amp;R, BDS, Linux, etc…), and at least a couple C++ modes (Ellemtel, Stroustrup).</p>
<p>While the Java community can refer to a common <a href="http://java.sun.com/docs/codeconv/">standard</a>, this doesn’t seem to be the case for C# developers. The <a href="http://www.tiobe.com/standards/gemrcsharpcs.pdf">guidelines from Philips</a> (pdf) are the ones which one is most often redirected to, but one can hardly call them “official”; Microsoft has also something on the MSDN on <a href="http://msdn.microsoft.com/en-us/library/xzf533w0(VS.71).aspx">naming conventions</a>, but there doesn’t seem to be anything related to code layout (spacing, indentation, etc…).</p>
<p>Whatever the choice, though, only a few would argue that choosing one standard for the team and sticking to it is not of outmost importance to improve readability and ease maintenance for years to come.</p>
<h4>Microsoft Style Cop</h4>
<p>Enters Style Cop. <a href="http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sourceanalysis&amp;ReleaseId=1425">Style Cop</a> (not to be confused with <a href="http://blogs.msdn.com/fxcop/">Fx Cop</a>) is a free Visual Studio plug-in which is released by Microsoft itself. It can be run on a single file or entire project or solutions and reports all the variations to its predefined set of rules for naming conventions, documentation and code layout. To run it on the current file, just right click on the editor and select the corresponding menu item:</p>
<p><a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/stylecop1.png"><img style="display:inline;border-width:0;" title="StyleCop1" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/stylecop1_thumb.png" border="0" alt="StyleCop1" width="468" height="303" /></a></p>
<p>This is the output that I got running the tool on the code above:</p>
<p><a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/image.png"><img style="display:inline;border-width:0;" title="image" src="http://stefanoricciardi.files.wordpress.com/2009/06/image_thumb.png" border="0" alt="image" width="478" height="261" /></a></p>
<p>If you need additional information about how to fix a particular violation, you can right click on a StyleCop warning, select <em>Show Error Help</em> and dig in:</p>
<p><a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/image1.png"><img style="display:inline;border-width:0;" title="image" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/image_thumb1.png" border="0" alt="image" width="455" height="484" /></a></p>
<p>Default settings can be customized to some extent. To do so, right click on a Project from the Solution Explorer to invoke the settings editor:</p>
<p><a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/image2.png"><img style="display:inline;border-width:0;" title="image" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/image_thumb2.png" border="0" alt="image" width="335" height="303" /></a></p>
<p>From the Rules tab you can relax some of the rules or extend or restrict the scope according to the visibility (private/internal/protected/public).</p>
<p><a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/image3.png"><img style="display:inline;border-width:0;" title="image" src="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/06/image_thumb3.png" border="0" alt="image" width="454" height="362" /></a></p>
<p>Yes, you can remove the restriction on the Tabs if you want (but you don’t… do you?). You can even support Hungarian Notation if you wish so (God forbids…!!!).</p>
<p>Default settings are applied at a project level and saved in a file named <em>Settings.SourceAnalysis</em>; It might easily become tedious to repeat the same settings over and over (my Visual Studio solutions have typically at least 4 or 5 different projects, and not counting unit tests); luckily the settings are automatically applied to all projects located in the subdirectories of the directory where the file is. Therefore, it usually suffices to move the file in the solution directory; individual projects can ovverride the general settings by providing their own Setting.SourceAnalysis file if needed (I usually do that for the tests projects where I usually omit XML documentation for test fixtures).</p>
<p>On a final note, if you use MSBuild for integration then you can invoke StyleCop every time the solution is built. If you are interested, you can find all the details in this MSDN <a href="http://blogs.msdn.com/sourceanalysis/pages/source-analysis-msbuild-integration.aspx">page</a>.<br />
<!-- AddThis Button BEGIN --><br />
<a href="http://www.addthis.com/bookmark.php?v=250"><img style="border:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a><br />
<!-- AddThis Button END --></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e6ceeafa-fe5c-4bd6-a48d-325da43e5abc" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Programming">Programming</a>, <a rel="tag" href="http://technorati.com/tags/C%23">C#</a>, <a rel="tag" href="http://technorati.com/tags/visual+Studio+2008">Visual Studio 2008</a>, <a rel="tag" href="http://technorati.com/tags/plugin">Plugin</a>, <a rel="tag" href="http://technorati.com/tags/Coding+Standards">Coding Standards</a>, <a rel="tag" href="http://technorati.com/tags/Tools">Tools</a>, <a rel="tag" href="http://technorati.com/tags/MSBuild">MSBuild</a></div>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2009/06/12/must-have-vs-2008-free-plug-ins-1-style-cop/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Most Useful Visual Studio 2008 Keyboard Shortcuts</title>
		<link>http://stefanoricciardi.com/2009/06/10/most-useful-visual-studio-2008-keyboard-shortcuts/</link>
		<comments>http://stefanoricciardi.com/2009/06/10/most-useful-visual-studio-2008-keyboard-shortcuts/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 07:50:08 +0000</pubDate>
		<dc:creator>stefanoricciardi</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://stefanoricciardi.wordpress.com/?p=64</guid>
		<description><![CDATA[UPDATE: I have created a PDF version of the shortcuts that you can download and print. You can find it here. I have started my career as a programmer learning (and loving) the Emacs editor; later I used for quite some time the VI editor on a remote server. It’s no wonder that I have [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F06%2F10%2Fmost-useful-visual-studio-2008-keyboard-shortcuts%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fstefanoricciardi.com%2F2009%2F06%2F10%2Fmost-useful-visual-studio-2008-keyboard-shortcuts%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><strong><span style="color:#ff0000;">UPDATE</span>: I have created a <a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/08/visualstudioshortcuts.pdf">PDF version</a> of the shortcuts that you can download and print. You can find it <a href="http://69.175.59.226/~stefano3/blog/wp-content/uploads/2009/08/visualstudioshortcuts.pdf">here</a>.</strong></p>
<hr />
<p>I have started my career as a programmer learning (and loving) the <a href="http://en.wikipedia.org/wiki/Emacs">Emacs</a> editor; later I used for quite some time the <a href="http://en.wikipedia.org/wiki/Vi">VI</a> editor on a remote server. It’s no wonder that I have become accustomed to use keyboard shortcuts extensively while editing my programs. Luckily, Visual Studio 2008 IDE that I now use on a daily basis comes with its own set of keyboard shortcuts that can make my programming hours more pleasant and productive.</p>
<h3>My Favorite Shortcuts</h3>
<p>I have tried to collect here the shortcuts I use dozens of times everyday.</p>
<p>I don’t fancy regions too much (I tend to prefer classes with few and short methods, so whenever I feel like I’d need regions to me that is a <a href="http://en.wikipedia.org/wiki/Code_smell">code smell</a>); that’s why you won’t find them listed here. I also usually don’t care about shortcuts to handle files (new / open, etc…)  and adding items to a project, since I am usually quicker using the mouse there. But without further ado, her comes the list.</p>
<table border="0" cellspacing="0" cellpadding="2" width="530">
<tbody>
<tr>
<td width="100" valign="top">CTRL + K, C</td>
<td width="430" valign="top"><strong>Comment selection</strong></td>
</tr>
<tr>
<td width="100" valign="top">CTRL + K, U</td>
<td width="430" valign="top"><strong>Uncomment selection</strong></td>
</tr>
<tr>
<td width="100" valign="top">CTRL + K, D</td>
<td width="430" valign="top"><strong>Format document </strong>(according to the rules you have specified in Tools-Options-&gt;…)</td>
</tr>
<tr>
<td width="100" valign="top">CTRL + K, F</td>
<td width="430" valign="top"><strong>Format selection <strong> </strong>(according to the rules you have specified in Tools-Options-&gt;…)</strong></td>
</tr>
<tr>
<td width="100" valign="top">CTRL + I</td>
<td width="430" valign="top"><strong>Incremental search </strong>(Emacs-like search)</td>
</tr>
<tr>
<td width="100" valign="top">CTRL + TAB</td>
<td width="430" valign="top"><strong>Cycle through the IDE windows</strong></td>
</tr>
<tr>
<td width="100" valign="top">F12</td>
<td width="430" valign="top"><strong>Go to definition of symbol</strong> (class / interface / etc…)</td>
</tr>
<tr>
<td width="100" valign="top">SHIFT + F12</td>
<td width="430" valign="top"><strong>Find all references to this symbol</strong> (class / interface / etc…)</td>
</tr>
<tr>
<td width="100" valign="top">TAB</td>
<td width="430" valign="top"><strong>Insert the corresponding snippet</strong></td>
</tr>
<tr>
<td width="100" valign="top">CTRL + ]</td>
<td width="430" valign="top"><strong>Move to the matching brace </strong>(for some reason this does not work when I use an Italian mapping for the keyboard)</td>
</tr>
<tr>
<td width="100" valign="top">CTRL + -</td>
<td width="430" valign="top"><strong>Move back to previous editing point(s).</strong></td>
</tr>
<tr>
<td width="100" valign="top">F6</td>
<td width="430" valign="top"><strong>Build solution</strong></td>
</tr>
<tr>
<td width="100" valign="top">SHIFT + F6</td>
<td width="430" valign="top"><strong>Build project</strong></td>
</tr>
<tr>
<td width="100" valign="top">F5</td>
<td width="430" valign="top"><strong>Start debugger / Go to next breakpoint</strong></td>
</tr>
<tr>
<td width="100" valign="top">SHIFT + F5</td>
<td width="430" valign="top"><strong>Quit debugger</strong></td>
</tr>
<tr>
<td width="100" valign="top">F10</td>
<td width="430" valign="top"><strong>Debugger step over</strong></td>
</tr>
<tr>
<td width="100" valign="top">F11</td>
<td width="430" valign="top"><strong>Debugger step in</strong></td>
</tr>
<tr>
<td width="100" valign="top">SHIFT + F11</td>
<td width="430" valign="top"><strong>Debugger step out</strong></td>
</tr>
<tr>
<td width="100" valign="top">CTRL + F10</td>
<td width="430" valign="top"><strong>Run to cursor</strong></td>
</tr>
<tr>
<td width="100" valign="top">F9</td>
<td width="430" valign="top"><strong>Toggle breakpoint</strong></td>
</tr>
</tbody>
</table>
<p>Microsoft has a nice <a href="http://www.microsoft.com/downloads/details.aspx?familyid=E5F902A8-5BB5-4CC6-907E-472809749973&amp;displaylang=en">poster</a> with the complete list of Visual Studio 2008 C# shortcuts. There are other shortcuts that I routinely use that are related to VS plug-ins (e.g. GhostDoc), but that is the topic for  another post.</p>
<h3>Wish List</h3>
<p>There are a few shortcuts that I’d love to have readily available in Visual Studio:</p>
<ul>
<li>join a line with the previous (<tt>J</tt> in VI)</li>
<li>create an inline comment. that is, move the cursor to a specific column and insert a ‘//’ to start a new comment. (<tt>M-;</tt> in Emacs)</li>
<li>format (wrap) multiline comments (<tt>M-q</tt> in Emacs)</li>
<li>center screen at current line (<tt>CTRL+l</tt> in Emacs)</li>
<li>an interactive replace mechanism (<tt>M-%</tt> in Emacs)</li>
</ul>
<p><!-- AddThis Button BEGIN --><br />
<a href="http://www.addthis.com/bookmark.php?v=250"><img style="border:0;" src="http://s7.addthis.com/static/btn/lg-share-en.gif" alt="Bookmark and Share" width="125" height="16" /></a><br />
<!-- AddThis Button END --></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:6e6d2d1d-ab3a-4e3a-aa02-256400bf0ce5" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Visual+Studio+2008">Visual Studio 2008</a>, <a rel="tag" href="http://technorati.com/tags/Programming">Programming </a>, <a rel="tag" href="http://technorati.com/tags/C%23">C#</a>, <a rel="tag" href="http://technorati.com/tags/Tools">Tools </a></div>

]]></content:encoded>
			<wfw:commentRss>http://stefanoricciardi.com/2009/06/10/most-useful-visual-studio-2008-keyboard-shortcuts/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

