<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Didactic Code</title>
	<atom:link href="http://davefancher.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://davefancher.com</link>
	<description>Learn By Doing</description>
	<lastBuildDate>Fri, 24 Feb 2012 04:42:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='davefancher.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Didactic Code</title>
		<link>http://davefancher.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://davefancher.com/osd.xml" title="Didactic Code" />
	<atom:link rel='hub' href='http://davefancher.com/?pushpress=hub'/>
		<item>
		<title>Nesting Files in Visual Studio</title>
		<link>http://davefancher.com/2012/02/23/nesting-files-in-visual-studio/</link>
		<comments>http://davefancher.com/2012/02/23/nesting-files-in-visual-studio/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 03:04:06 +0000</pubDate>
		<dc:creator>Dave Fancher</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tools & Utilities]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[DependentUpon]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://davefancher.com/?p=1765</guid>
		<description><![CDATA[A neat trick that I&#8217;ve used a few times to help organize files in a project is nest some under a related &#8220;master&#8221; file just like an aspx file and its code-behind.  I&#8217;ve mostly done this to group some page-specific &#8230; <a href="http://davefancher.com/2012/02/23/nesting-files-in-visual-studio/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1765&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A neat trick that I&#8217;ve used a few times to help organize files in a project is nest some under a related &#8220;master&#8221; file just like an <kbd>aspx</kbd> file and its code-behind.  I&#8217;ve mostly done this to group some page-specific JavaScript files with the page but also to group some partial classes for a WCF service together under a single &#8220;master&#8221; file.  This is hardly new (I think I did it for the first time with a project file from VS2008 and I know it has been around even longer than that) but every once in a while it comes up in a conversation so I thought it was worth sharing.<br />
<span id="more-1765"></span><br />
Grouping files in this manner is pretty straightforward but short of using an extension (we&#8217;ll look at that in a moment) there&#8217;s no way to group arbitrary files directly within Visual Studio.  That means that for this exercise we&#8217;ll be manually editing a project file.</p>
<div id="attachment_1806" class="wp-caption alignright" style="width: 213px"><img class="size-full wp-image-1806" title="Ungrouped Files" src="http://davefancher.files.wordpress.com/2012/02/filestogroup.png?w=500" alt="Ungrouped Files"   /><p class="wp-caption-text">Ungrouped Files</p></div>
<p>Let&#8217;s assume that we have a <kbd>Default.js</kbd> file that we want to nest under <kbd>Default.aspx</kbd>.  To edit the project file I usually use the Edit Project File option included with the PowerCommands extension to streamline the Unload Project and Edit [project].csproj options.  Once the project file is open in the code editor we need to find <kbd>Default.js</kbd>.  Because <kbd>Default.js</kbd> is simply included content it will be in a <kbd>&lt;content&gt;</kbd> element like the following:</p>
<p><pre class="brush: xml;">
&lt;Content Include=&quot;Default.js&quot; /&gt;
</pre></p>
<p>Once we&#8217;ve located the element we need to insert a child <kbd>DependentUpon</kbd> element to identify <kbd>Default.aspx</kbd> its parent. You&#8217;ll probably see plenty of examples in the project file but our finished XML should look like this:</p>
<p><pre class="brush: xml;">
&lt;Content Include=&quot;Default.js&quot;&gt;
	&lt;DependentUpon&gt;Default.aspx&lt;/DependentUpon&gt;
&lt;/Content&gt;
</pre></p>
<p><em><strong>Note:</strong> Check the <a href="http://msdn.microsoft.com/en-us/library/bb629388.aspx">Common MSBuild Project Items</a> documentation on MSDN to see which elements <kbd>DependentUpon</kbd> can be applied to.</em></p>
<div id="attachment_1807" class="wp-caption alignright" style="width: 221px"><img class="size-full wp-image-1807" title="Grouped Files" src="http://davefancher.files.wordpress.com/2012/02/groupedfiles.png?w=500" alt="Grouped Files"   /><p class="wp-caption-text">Grouped Files</p></div>
<p>With the changes made, save the file and reload the project in the IDE. When the project loads <kbd>Default.js</kbd> should no longer appear in the main tree but instead be nested under Default.aspx.</p>
<p>If you&#8217;re not comfortable editing the project file directly there are some extensions that can streamline this process:</p>
<ul>
<li><a title="NestIn Extension" href="http://visualstudiogallery.msdn.microsoft.com/9d6ef0ce-2bef-4a82-9a84-7718caa5bb45/">NestIn</a></li>
<li><a title="VSCommands 2010" href="http://visualstudiogallery.msdn.microsoft.com/d491911d-97f3-4cf6-87b0-6a2882120acf/">VSCommands 2010</a></li>
</ul>
<p>I haven&#8217;t tried either extension but they&#8217;re both highly rated in the gallery.  If you know of any others let me know and I&#8217;ll add them to the list.</p>
<br /> Tagged: <a href='http://davefancher.com/tag/dependentupon/'>DependentUpon</a>, <a href='http://davefancher.com/tag/visual-studio/'>Visual Studio</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davefancher.wordpress.com/1765/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davefancher.wordpress.com/1765/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davefancher.wordpress.com/1765/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davefancher.wordpress.com/1765/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davefancher.wordpress.com/1765/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davefancher.wordpress.com/1765/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davefancher.wordpress.com/1765/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davefancher.wordpress.com/1765/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davefancher.wordpress.com/1765/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davefancher.wordpress.com/1765/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davefancher.wordpress.com/1765/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davefancher.wordpress.com/1765/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davefancher.wordpress.com/1765/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davefancher.wordpress.com/1765/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1765&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davefancher.com/2012/02/23/nesting-files-in-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad02f59c6c342c3788b9439c53bbf242?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">davefancher</media:title>
		</media:content>

		<media:content url="http://davefancher.files.wordpress.com/2012/02/filestogroup.png" medium="image">
			<media:title type="html">Ungrouped Files</media:title>
		</media:content>

		<media:content url="http://davefancher.files.wordpress.com/2012/02/groupedfiles.png" medium="image">
			<media:title type="html">Grouped Files</media:title>
		</media:content>
	</item>
		<item>
		<title>JustDecompile &#8211; One More Time</title>
		<link>http://davefancher.com/2012/02/22/justdecompile-one-more-time/</link>
		<comments>http://davefancher.com/2012/02/22/justdecompile-one-more-time/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 05:28:04 +0000</pubDate>
		<dc:creator>Dave Fancher</dc:creator>
				<category><![CDATA[JustDecompile]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tools & Utilities]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Decompile]]></category>
		<category><![CDATA[Telerik]]></category>

		<guid isPermaLink="false">http://davefancher.com/?p=1777</guid>
		<description><![CDATA[I&#8217;ve looked at JustDecompile a few times over the past year, following its progress from its early beta stages.  When I saw that it was officially released yesterday (14 Feb 2012) I remembered telling Vladimir Dragoev from the JustDecompile team &#8230; <a href="http://davefancher.com/2012/02/22/justdecompile-one-more-time/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1777&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve looked at <a title="JustDecompile" href="http://www.telerik.com/products/decompiler.aspx">JustDecompile</a> a few times over the past year, following its progress from its early beta stages.  When I saw that it was officially released yesterday (14 Feb 2012) I remembered telling <a href="http://davefancher.com/2011/09/06/justdecompile-revisited/#comment-268">Vladimir Dragoev</a> from the JustDecompile team that I&#8217;d give it another look.  I&#8217;ve been very critical of this product in the past but given that everything I&#8217;ve looked at so far has been pre-release software it&#8217;s only fair that I give it one more chance to redeem itself.  Can this version finally handle my tests?</p>
<p><span id="more-1777"></span></p>
<h2>The Journey</h2>
<p>When I first looked at JustDecompile <a title="JustDecompile – First Impressions" href="http://davefancher.com/2011/05/25/justdecompile-first-impressions/">last May</a> (v2011.1.516.2) I had really high hopes for it but back then its output was far from acceptable.  Many of my tests resulted in code that in no way resembled the original source and more often than not the result wasn&#8217;t even valid C#.  To top it off, the application crashed frequently in easily reproducible ways.  Given what I observed I had no choice but to call it unusable.  That said, it was a beta so I provided some feedback to the team and moved on.</p>
<p>My second look was in <a title="JustDecompile Revisited" href="http://davefancher.com/2011/09/06/justdecompile-revisited/">September</a> (v2011.1.829.2).  The team had been working on fixing defects and I&#8217;d seen several notices that the issues I&#8217;d reported were either fixed or being fixed.  This seemed like as good of a time as any to give it another chance.  The first thing I noticed was that the application no longer crashed with the predictability I&#8217;d noticed in May.  When I reran my original tests I found that although the code it generated had certainly improved (sometimes to the point of being almost identical to the original source) it still had a number of issues that ultimately left me saying it still wasn&#8217;t a viable alternative to the other solutions already available.</p>
<p>For this review I&#8217;m using version 2012.1.214.2.  When I read about some of the new features in this release I was pretty surprised to see that <a title="Telerik" href="http://www.telerik.com/">Telerik</a> had completely rebuilt the decompilation engine.  For consistency across all three reviews I&#8217;ll be sticking with my original series of tests so we&#8217;ll see how well the new version fares.</p>
<h2>User Interface</h2>
<p>I didn&#8217;t notice many changes in the UI from the last review.  From what I remember, most everything is in the same place.  The stand-out feature here has to be the Create Project button.</p>
<p>Create Project (also accessible from a context menu) lets us create a new Visual Studio project from a decompiled assembly.  For my simple project I found that although the formatting left something to be desired the generated project was adequate.  I did have to remove the generated <kbd>_Module_.cs</kbd> file from the project to get it to compile but otherwise it worked fine.  I can see this being a useful tool for recovering lost code.</p>
<p><em><strong>Note:</strong> Create Project only supports creating projects in C#.  If Visual Basic or IL are selected the button will be disabled.</em></p>
<div id="attachment_1786" class="wp-caption alignright" style="width: 126px"><a href="http://davefancher.files.wordpress.com/2012/02/multiple-node-selections.png"><img class="size-thumbnail wp-image-1786" title="Multiple Node Selections" src="http://davefancher.files.wordpress.com/2012/02/multiple-node-selections.png?w=116&#038;h=150" alt="Multiple Node Selections" width="116" height="150" /></a><p class="wp-caption-text">Multiple Node Selections</p></div>
<p>I found navigating the assembly panel a but frustrating due to some inconsistencies.  For example, double-clicking will expand or collapse  assembly and namespace nodes  but not individual types.  I also somehow managed to get multiple nodes to appear as selected.  Sometimes collapsing the parent node would clear the selection, other times it wouldn&#8217;t.  At one point I even managed to crash JustDecompile just clicking around in the assembly panel but I couldn&#8217;t reproduce it.</p>
<h2>Code Tests</h2>
<p>As I mentioned earlier, this version has a completely rewritten decompilation engine.  Decompilation had come a long way between my last two looks so I was really interested in whether the new engine closed the gap between some of the competing products.  I have to say that this version surprised me a bit.</p>
<p>First, it got most of the decompilations correct &#8211; including the conditional operator tests that it choked on before.  What surprised me even more though was some of the code it produced.  The code wasn&#8217;t necessarily wrong per se, just&#8230;unusual.  Let&#8217;s take a look.</p>
<p>Just like before we&#8217;ll start with the switch statements.  I&#8217;ll be pointing out some of the oddities as we encounter them.  Also assume the following enumeration for all code samples:</p>
<p><pre class="brush: csharp;">
public enum SampleEnum
{
	Unknown,
	Item1,
	Item2
}
</pre></p>
<h3>Switch Statements</h3>
<p>The last version I looked at did really well with the switch statements.  It had really come a long way from including MSIL labels and misplacing case bodies.  Although I&#8217;m pleased to report that the released version also handles each test correctly I think in some cases quality of the emitted code has taken a step backwards. Take the first test as an example.</p>
<p>In this test I simply return a string from each case:</p>
<p><pre class="brush: csharp;">
public string SampleMethod(SampleEnum enumValue)
{
	switch (enumValue)
	{
		case SampleEnum.Item1:
			return &quot;Item 1&quot;;

		case SampleEnum.Item2:
			return &quot;Item 2&quot;;

		case SampleEnum.Unknown:
			return &quot;Unknown&quot;;
	}

	return String.Empty;
}
</pre></p>
<p>JustDecompile produces code that is functionally equivalent but introduces a <kbd>default</kbd> case:</p>
<p><pre class="brush: csharp;">
public string SampleMethod(SampleEnum enumValue)
{
	string empty;
	SampleEnum sampleEnum = enumValue;
	switch (sampleEnum)
	{
		case SampleEnum.Unknown:
		{
			empty = &quot;Unknown&quot;;
			break;
		}
		case SampleEnum.Item1:
		{
			empty = &quot;Item 1&quot;;
			break;
		}
		case SampleEnum.Item2:
		{
			empty = &quot;Item 2&quot;;
			break;
		}
		default:
		{
			empty = string.Empty;
			break;
		}
	}
	return empty;
}
</pre></p>
<p>Interestingly, this code from JustDecompile is almost identical to what <a href="http://wiki.sharpdevelop.net/ILSpy.ashx">ILSpy</a> produces. I&#8217;m guessing that&#8217;s not coincidental since they&#8217;re both based on <a href="http://www.mono-project.com/Cecil">Cecil</a>. Notice I said that the output is almost identical to what ILSpy produces though. The one thing that JustDecompile&#8217;s output has that ILSpy&#8217;s doesn&#8217;t is line 4 &#8211; <kbd>SampleEnum sampleEnum = enumValue;</kbd>. Again, it&#8217;s not necessarily wrong, I don&#8217;t understand why it&#8217;s there.</p>
<p>The second <kbd>switch</kbd> test by adding a variable to store the string from each case rather than returning the string:</p>
<p><pre class="brush: csharp;">
public string SampleMethod(SampleEnum enumValue)
{
	var val = String.Empty;

	switch (enumValue)
	{
		case SampleEnum.Item1:
			val = &quot;Item 1&quot;;
			break;

		case SampleEnum.Item2:
			val = &quot;Item 2&quot;;
			break;

		case SampleEnum.Unknown:
			val = &quot;Unknown&quot;;
			break;
	}

	return val;
}
</pre></p>
<p>Again, JustDecompile&#8217;s result is acceptable:</p>
<p><pre class="brush: csharp;">
public string SampleMethod(SampleEnum enumValue)
{
	string val = string.Empty;
	SampleEnum sampleEnum = enumValue;
	switch (sampleEnum)
	{
		case SampleEnum.Unknown:
		{
			val = &quot;Unknown&quot;;
			break;
		}
		case SampleEnum.Item1:
		{
			val = &quot;Item 1&quot;;
			break;
		}
		case SampleEnum.Item2:
		{
			val = &quot;Item 2&quot;;
			break;
		}
	}
	string str = val;
	return str;
}
</pre></p>
<p>This decompilation is also functionally correct but this time not only do we have the extra enum declaration and assignment, we also have an extra string declaration and assignment. These variables weren&#8217;t present the last time I tried JustDecompile and they&#8217;re not present in ILSpy&#8217;s output either. They&#8217;re unnecessary and I&#8217;m not sure where they&#8217;re coming from. We see this pattern repeat for the next two tests.</p>
<p>Switch with default test:</p>
<p><pre class="brush: csharp;">
public string SampleMethod(SampleEnum enumValue)
{
	var val = String.Empty;

	switch (enumValue)
	{
		case SampleEnum.Item1:
			val = &quot;Item 1&quot;;
			break;

		case SampleEnum.Item2:
			val = &quot;Item 2&quot;;
			break;

		default:
			val = &quot;Unknown&quot;;
			break;
	}

	return val;
}
</pre></p>
<p>JustDecompile Result:</p>
<p><pre class="brush: csharp;">
public string SampleMethod(SampleEnum enumValue)
{
	string val = string.Empty;
	SampleEnum sampleEnum = enumValue;
	switch (sampleEnum)
	{
		case SampleEnum.Item1:
		{
			val = &quot;Item 1&quot;;
			break;
		}
		case SampleEnum.Item2:
		{
			val = &quot;Item 2&quot;;
			break;
		}
		default:
		{
			val = &quot;Unknown&quot;;
			break;
		}
	}
	string str = val;
	return str;
}
</pre></p>
<p>Switch with different default case body:</p>
<p><pre class="brush: csharp;">
public string SampleMethod(SampleEnum enumValue)
{
	var val = String.Empty;

	switch (enumValue)
	{
		case SampleEnum.Item1:
			val = &quot;Item 1&quot;;
			break;

		case SampleEnum.Item2:
			val = &quot;Item 2&quot;;
			break;

		default:
			Console.WriteLine(&quot;Unknown&quot;);
			break;
	}

	return val;
}
</pre></p>
<p>JustDecompile Result:</p>
<p><pre class="brush: csharp;">
public string SampleMethod(SampleEnum enumValue)
{
	string val = string.Empty;
	SampleEnum sampleEnum = enumValue;
	switch (sampleEnum)
	{
		case SampleEnum.Item1:
		{
			val = &quot;Item 1&quot;;
			break;
		}
		case SampleEnum.Item2:
		{
			val = &quot;Item 2&quot;;
			break;
		}
		default:
		{
			Console.WriteLine(&quot;Unknown&quot;);
			break;
		}
	}
	string str = val;
	return str;
}
</pre></p>
<p>Despite the extraneous variables the generated code is doing the right thing.</p>
<h3>Conditional Operator</h3>
<p>Saying JustDecompile has failed miserably on the conditional operator would be too generous. Before looking at what this version generates let&#8217;s review where we&#8217;re coming from.</p>
<p>The first test is a simple conditional check against a variable:</p>
<p><pre class="brush: csharp;">
public void SampleMethod(int arg)
{
	var isEven = arg % 2 == 0;
	var val = isEven ? SampleEnum.Item1 : SampleEnum.Item2;
}
</pre></p>
<p>The last time I used JustDecompile it produced the following:</p>
<p><pre class="brush: csharp;">
public void SampleMethod(int arg)
{
	bool isEven = arg % 2 == 0;
	SampleEnum val = isEven || SampleEnum.Item2;
}
</pre></p>
<p>As you can see, it got the variable assignment correct but that was about it. The code it generated wouldn&#8217;t even compile. This time around though I was surprised in more ways than one.</p>
<p>First, the team has taken a completely different approach by emitting an <kbd>if/else</kbd> rather than a conditional operator. This approach deviates significantly even from that ILSpy (which I noted in the last review was actually worse than what JustDecompile did). Furthermore, the code is actually, (finally!) functionally equivalent!</p>
<p><pre class="brush: csharp;">
public void SampleMethod(int arg)
{
	byte num;
	bool isEven = arg % 2 == 0;
	if (isEven)
	{
		num = 1;
	}
	else
	{
		num = 2;
	}
	SampleEnum val = (SampleEnum)num;
}
</pre></p>
<p>It may not use a conditional operator but the result is the same.</p>
<p>The other test eliminated the <kbd>isEven</kbd> variable to flatten the expression:</p>
<p><pre class="brush: csharp;">
public void SampleMethod(int arg)
{
	var val = arg % 2 == 0 ? SampleEnum.Item1 : SampleEnum.Item2;
}
</pre></p>
<p>JustDecompile also got it right too!</p>
<p><pre class="brush: csharp;">
public void SampleMethod(int arg)
{
	byte num;
	if (arg % 2 == 0)
	{
		num = 1;
	}
	else
	{
		num = 2;
	}
	SampleEnum val = (SampleEnum)num;
}
</pre></p>
<p>As you can see, JustDecompile has come a long way when it comes to handling conditional operators.</p>
<h3>Other Tests</h3>
<p>Just as before I ran some older production code through JustDecompile. Although some of the code it produced left me scratching my head a bit (for the same reasons described above) JustDecompile performed much better this time around.</p>
<p>The first method I retested was my old IsNull method I wrote to check if a value in a DataRow was null before I knew about DataRow.IsNull:</p>
<p><pre class="brush: csharp;">
public static bool IsNull(object value)
{
	return (value == null || value == DBNull.Value || value.ToString().Length == 0);
}
</pre></p>
<p>This time JustDecompile got it right. Of course, the generated code doesn&#8217;t look anything like the original and it introduces a really, really poorly named variable but at least the result is the same.</p>
<p><pre class="brush: csharp;">
public static bool IsNull(object value)
{
	bool length;
	if (value == null || value == DBNull.Value)
	{
		length = true;
	}
	else
	{
		length = value.ToString().Length == 0;
	}
	bool flag = length;
	return flag;
}
</pre></p>
<p><em><strong>Note:</strong> ILSpy&#8217;s output matches the original source almost exactly.</em></p>
<p>The other method I tested has had some serious problems in the past. For example, case blocks were mismatched or intermixed, and the code included MSIL variable names. The decompilation of that method still isn&#8217;t perfect but it seems to fail in the same ways as ILSpy. For instance, somewhere in the process an enumeration value initialized to 24 is misrepresented as 25. ILSpy handles this a little better since it tries to cast 25 to the enum but JustDecompile doesn&#8217;t.</p>
<h2>The Bottom Line</h2>
<p>I&#8217;ll readily admit that after having seen JustDecompile fail so miserably in the past I didn&#8217;t have very high expectations for this release. I&#8217;ve never expected a decompilation tool to generate code that matches all of my code verbatim (especially when considering any compiler optimizations) but in the past JustDecompile has generated code that in no way represented the original source. After seeing how well the rebuilt decompilation engine handled these tests I have to say that I&#8217;m impressed with how far the tool has come since I first looked at it.</p>
<p>Truth be told though, despite the improvements JustDecompile still feels a bit rough around the edges. As I said, I still managed to crash it once and some of the generated code is a bit questionable.  Overall though, I think it now has it&#8217;s place in the toolkit if only for getting a second opinion about how an assembly works.</p>
<p><em>As a final note, I recently learned about <a href="http://www.jetbrains.com/decompiler/?dotnetblog">dotPeek</a>, a free decompilation tool from <a href="http://www.jetbrains.com/index.html">JetBrains</a>. I ran all of my tests against the version 1.0.0.7999 (early access program) and it handled them all <strong>perfectly</strong>. If you&#8217;re still mad at Red Gate and/or are looking for other decompilers, dotPeek looks like it&#8217;ll be a very good alternative.</em></p>
<br /> Tagged: <a href='http://davefancher.com/tag/net/'>.NET</a>, <a href='http://davefancher.com/tag/c/'>C#</a>, <a href='http://davefancher.com/tag/decompile/'>Decompile</a>, <a href='http://davefancher.com/tag/justdecompile/'>JustDecompile</a>, <a href='http://davefancher.com/tag/telerik/'>Telerik</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davefancher.wordpress.com/1777/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davefancher.wordpress.com/1777/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davefancher.wordpress.com/1777/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davefancher.wordpress.com/1777/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davefancher.wordpress.com/1777/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davefancher.wordpress.com/1777/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davefancher.wordpress.com/1777/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davefancher.wordpress.com/1777/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davefancher.wordpress.com/1777/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davefancher.wordpress.com/1777/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davefancher.wordpress.com/1777/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davefancher.wordpress.com/1777/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davefancher.wordpress.com/1777/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davefancher.wordpress.com/1777/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1777&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davefancher.com/2012/02/22/justdecompile-one-more-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad02f59c6c342c3788b9439c53bbf242?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">davefancher</media:title>
		</media:content>

		<media:content url="http://davefancher.files.wordpress.com/2012/02/multiple-node-selections.png?w=116" medium="image">
			<media:title type="html">Multiple Node Selections</media:title>
		</media:content>
	</item>
		<item>
		<title>Operation could destabilize the runtime</title>
		<link>http://davefancher.com/2012/02/15/operation-could-destabilize-the-runtime/</link>
		<comments>http://davefancher.com/2012/02/15/operation-could-destabilize-the-runtime/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 01:00:48 +0000</pubDate>
		<dc:creator>Dave Fancher</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Libraries]]></category>
		<category><![CDATA[Json.NET]]></category>
		<category><![CDATA[IntelliTrace]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[VS2010]]></category>
		<category><![CDATA[VerificationException]]></category>

		<guid isPermaLink="false">http://davefancher.com/?p=1766</guid>
		<description><![CDATA[Today I was trying to run the code for a project I&#8217;ve just been assigned to.  I&#8217;d brought down the code from SVN, built the common libraries, and punched F5.  Build succeeded.  Before long the browser loaded and the beautiful &#8230; <a href="http://davefancher.com/2012/02/15/operation-could-destabilize-the-runtime/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1766&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I was trying to run the code for a project I&#8217;ve just been assigned to.  I&#8217;d brought down the code from SVN, built the common libraries, and punched <kbd>F5</kbd>.  Build succeeded.  Before long the browser loaded and the beautiful new UI stared back and virtually begged me to start clicking around.  Before I could do anything though Visual Studio rudely interrupted with an unhandled exception dialog.  This one looked nasty, particularly since I&#8217;d never seen it before: <a href="http://msdn.microsoft.com/en-us/library/system.security.verificationexception.aspx"><kbd>System.Security.VerificationException</kbd></a> - Operation could destabilize the runtime&#8230;</p>
<p>I found a <a title="Stack Overflow" href="http://stackoverflow.com/">Stack Overflow</a> <a title="Json.NET + VerificationException Operation could destabilize the runtime" href="http://stackoverflow.com/questions/5968084/json-net-verificationexception-operation-could-destabilize-the-runtime">question</a> about this that pointed to <a title="Json.NET" href="http://json.codeplex.com/">Json.NET</a> as a possible culprit.  Sure enough, the source of the exception was <kbd>Newtonsoft.Json</kbd>.  It seems that Visual Studio Ultimate&#8217;s <a title="IntelliTrace" href="http://msdn.microsoft.com/en-us/library/dd264915.aspx">IntelliTrace</a> didn&#8217;t like something Json.NET was doing and would throw that exception.  The issue is said to be resolved as of <a title="Json.NET 4.0 Release 6 – Serialization Performance" href="http://james.newtonking.com/archive/2012/01/23/json-net-4-0-release-6-serialization-performance.aspx">release 6</a> but I haven&#8217;t upgraded the assembly yet.</p>
<p>For the time being I&#8217;ve added a rule to exclude <kbd>*Newtonsoft.*</kbd> from the IntelliTrace modules list as recommended by in the Stack Overflow answer.  Since excluding the assembly I haven&#8217;t seen the problem again.</p>
<br /> Tagged: <a href='http://davefancher.com/tag/intellitrace/'>IntelliTrace</a>, <a href='http://davefancher.com/tag/json-net/'>Json.NET</a>, <a href='http://davefancher.com/tag/verificationexception/'>VerificationException</a>, <a href='http://davefancher.com/tag/visual-studio/'>Visual Studio</a>, <a href='http://davefancher.com/tag/visual-studio-2010/'>Visual Studio 2010</a>, <a href='http://davefancher.com/tag/vs2010/'>VS2010</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davefancher.wordpress.com/1766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davefancher.wordpress.com/1766/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davefancher.wordpress.com/1766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davefancher.wordpress.com/1766/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davefancher.wordpress.com/1766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davefancher.wordpress.com/1766/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davefancher.wordpress.com/1766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davefancher.wordpress.com/1766/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davefancher.wordpress.com/1766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davefancher.wordpress.com/1766/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davefancher.wordpress.com/1766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davefancher.wordpress.com/1766/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davefancher.wordpress.com/1766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davefancher.wordpress.com/1766/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1766&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davefancher.com/2012/02/15/operation-could-destabilize-the-runtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad02f59c6c342c3788b9439c53bbf242?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">davefancher</media:title>
		</media:content>
	</item>
		<item>
		<title>IndyNDA &#8211; Testing Code From The Pit Of Despair</title>
		<link>http://davefancher.com/2012/02/06/indy-nda-testing-code-from-the-pit-of-despair/</link>
		<comments>http://davefancher.com/2012/02/06/indy-nda-testing-code-from-the-pit-of-despair/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 01:39:10 +0000</pubDate>
		<dc:creator>Dave Fancher</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[IndyNDA]]></category>
		<category><![CDATA[Practices]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[User Groups]]></category>
		<category><![CDATA[Panel Discussion]]></category>
		<category><![CDATA[Technical Screening]]></category>

		<guid isPermaLink="false">http://davefancher.com/?p=1758</guid>
		<description><![CDATA[It&#8217;s the second week of February so if you read this blog with any frequency you know what that means.  That&#8217;s right, IndyNDA is this Thursday (9 February)!  This month we&#8217;re fortunate to have Phil Japikse returning to discuss testing &#8230; <a href="http://davefancher.com/2012/02/06/indy-nda-testing-code-from-the-pit-of-despair/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1758&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s the second week of February so if you read this blog with any frequency you know what that means.  That&#8217;s right, <a title="Testing Code From The Pit Of Despair" href="http://www.indynda.com/RecentMeetings/tabid/62/EntryId/31/Thursday-February-9th-133rd-Meeting.aspx">IndyNDA is this Thursday</a> (9 February)!  This month we&#8217;re fortunate to have <a title="Phil Japikse" href="https://twitter.com/#!/skimedic">Phil Japikse</a> returning to discuss testing legacy code.</p>
<blockquote><p>Michael Feathers defines Legacy Code as any code that doesn’t have automated tests, and you agree that automated tests are an important facet of successful software development. Then it happens – you get your next assignment, and it’s your worst nightmare! You have to maintain and enhance a large application that has no tests in place, and there are parts that are just plain scary. Where do you start? Traditional Test Driven Development techniques don’t typically work, since they focus on an inside-out development paradigm.</p>
<p>I will show you the patterns and practices that will help you turn the scary big ball of mud into a tested code base.</p></blockquote>
<p>I&#8217;m excited to have Phil back.  I&#8217;ve heard him speak many times and have always found his talks both informative and entertaining.</p>
<p>This month we&#8217;re meeting in the 2nd floor conference room at 900 E. 96th Street.  Registration begins at 5:30 and the main event kicks off at 6:00.  Snacks and soft drinks will be provided.</p>
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=900 E 96th Street, Indianapolis, IN 46240&amp;aq=&amp;sll=37.0625,-95.677068&amp;sspn=67.334709,107.138672&amp;vpsrc=0&amp;ie=UTF8&amp;hnear=900 E 96th St, Indianapolis, Marion, Indiana 46240&amp;t=m&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=900 E 96th Street, Indianapolis, IN 46240&amp;aq=&amp;sll=37.0625,-95.677068&amp;sspn=67.334709,107.138672&amp;vpsrc=0&amp;ie=UTF8&amp;hnear=900 E 96th St, Indianapolis, Marion, Indiana 46240&amp;t=m&amp;z=14&amp;iwloc=A&amp;source=embed" style="text-align:left">View Larger Map</a></small>
<p>I hope to see you there!</p>
<br /> Tagged: <a href='http://davefancher.com/tag/community/'>Community</a>, <a href='http://davefancher.com/tag/indynda/'>IndyNDA</a>, <a href='http://davefancher.com/tag/panel-discussion/'>Panel Discussion</a>, <a href='http://davefancher.com/tag/technical-screening/'>Technical Screening</a>, <a href='http://davefancher.com/tag/user-groups/'>User Groups</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davefancher.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davefancher.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davefancher.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davefancher.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davefancher.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davefancher.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davefancher.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davefancher.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davefancher.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davefancher.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davefancher.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davefancher.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davefancher.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davefancher.wordpress.com/1758/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1758&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davefancher.com/2012/02/06/indy-nda-testing-code-from-the-pit-of-despair/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad02f59c6c342c3788b9439c53bbf242?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">davefancher</media:title>
		</media:content>
	</item>
		<item>
		<title>Book Review: Driving Technical Change</title>
		<link>http://davefancher.com/2012/02/04/book-review-driving-technical-change/</link>
		<comments>http://davefancher.com/2012/02/04/book-review-driving-technical-change/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 21:03:19 +0000</pubDate>
		<dc:creator>Dave Fancher</dc:creator>
				<category><![CDATA[Practices]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Book Review]]></category>
		<category><![CDATA[Driving Technical Change]]></category>

		<guid isPermaLink="false">http://davefancher.com/?p=1743</guid>
		<description><![CDATA[A few nights ago I was over at my local Fry&#8217;s looking for a battery charger and a new Compact Flash card for my camera when I stumbled upon the book Driving Technical Change by Terrance Ryan.  I think it &#8230; <a href="http://davefancher.com/2012/02/04/book-review-driving-technical-change/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1743&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="attachment_1752" class="wp-caption alignright" style="width: 160px"><a href="http://davefancher.files.wordpress.com/2012/02/drivingtechnicalchange.jpg" target="_blank"><img class="size-thumbnail wp-image-1752 " title="Driving Technical Change" src="http://davefancher.files.wordpress.com/2012/02/drivingtechnicalchange.jpg?w=150&#038;h=150" alt="Driving Technical Change" width="150" height="150" /></a><p class="wp-caption-text">Driving Technical Change</p></div>
<p>A few nights ago I was over at my local <a title="Fry's Home Electronics" href="http://www.frys.com/">Fry&#8217;s</a> looking for a battery charger and a new Compact Flash card for my camera when I stumbled upon the book <a title="Driving Technical Change" href="http://pragprog.com/book/trevan/driving-technical-change">Driving Technical Change</a> by Terrance Ryan.  I think it was the distinctive look of a <a title="The Pragmatic Bookshelf" href="http://pragprog.com/">Pragmatic Bookshelf</a> title that caught my eye.  I picked it up, glanced over a few pages, said &#8220;what the hell,&#8221; and bought it.  The book weighs in a bit under 150 pages so it&#8217;s a pretty quick read.  Even with my slow reading pace and note taking I managed to make it through the book in just a few hours.</p>
<p><span id="more-1743"></span></p>
<blockquote><p>Is this good for the company?<br />
&#8211; Office Space</p></blockquote>
<p>Driving Technical Change is about learning how to &#8220;sell&#8221; new tools or techniques to your organization.  I really look at it as a marketing guide for developers.</p>
<p>The first step is to define what it is we&#8217;re trying to sell.  Is it a tool?  A technique?  Regardless, we need to recognize that we&#8217;re asking people to make some change to the way they work.  Once we&#8217;ve identified what we&#8217;re trying to sell we need to make sure that it is solving the right problem or if there even is a problem.  To do this we need to consider the skills available within the organization and consider alternative approaches.  Finally, we can start devising how we want to approach pushing this change into the organization and that is the focus of the book.</p>
<p>When I said that this book is a marketing guide for developers I wasn&#8217;t exaggerating.  Marketers define their audiences in terms of market segments.  Each segment is essentially a group people (or organizations) that share a common set of characteristics and/or behaviors which marketers use to tailor their message.  Driving Technical Change takes this approach by defining seven segments, err&#8230; skeptics:</p>
<ol>
<li>The Uninformed</li>
<li>The Herd</li>
<li>The Cynic</li>
<li>The Burned</li>
<li>The Time Crunched</li>
<li>The Boss</li>
<li>The Irrational</li>
</ol>
<p><em><strong>Note:</strong> The author emphasizes that any given person can (and probably will) simultaneously classify as multiple skeptic types.</em></p>
<p>The skeptics are for one reason or another the pockets of resistance you will face when trying to get your organization to adopt your ideas.  It&#8217;s true that categorizing people in this manner can be dangerous but I don&#8217;t really think it&#8217;s harmful here.  The goal isn&#8217;t so much about categorizing people as it is their behaviors.</p>
<p>Just like market segments, addressing each skeptic requires a different approach.  Fortunately, the book also outlines several techniques for dealing with each type:</p>
<ol>
<li>Gain Expertise</li>
<li>Deliver Your Message</li>
<li>Demonstrate Your Technique</li>
<li>Propose Compromise</li>
<li>Create Trust</li>
<li>Get Publicity</li>
<li>Focus on Synergy</li>
<li>Build a Bridge</li>
<li>Create Something Compelling</li>
</ol>
<p>Most of these techniques apply to multiple skeptics and for each technique the book describes some tactics for effectively tailoring your message to the type.</p>
<p>I found the book interesting and recommend giving it a read.  I enjoyed the author&#8217;s style and found the anecdotes not only entertaining  but useful for illustrating each point.  Although much of the advice seems obvious in retrospect, having it organized in this manner can stimulate some thought.  Ultimately though, the underlying themes are to be knowledgeable, be prepared, be respectful, recognize that showing is almost always more effective than telling, and understand that there are some people that you can&#8217;t sway no matter what you do.</p>
<br /> Tagged: <a href='http://davefancher.com/tag/book-review/'>Book Review</a>, <a href='http://davefancher.com/tag/driving-technical-change/'>Driving Technical Change</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davefancher.wordpress.com/1743/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davefancher.wordpress.com/1743/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davefancher.wordpress.com/1743/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davefancher.wordpress.com/1743/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davefancher.wordpress.com/1743/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davefancher.wordpress.com/1743/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davefancher.wordpress.com/1743/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davefancher.wordpress.com/1743/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davefancher.wordpress.com/1743/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davefancher.wordpress.com/1743/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davefancher.wordpress.com/1743/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davefancher.wordpress.com/1743/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davefancher.wordpress.com/1743/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davefancher.wordpress.com/1743/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1743&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davefancher.com/2012/02/04/book-review-driving-technical-change/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad02f59c6c342c3788b9439c53bbf242?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">davefancher</media:title>
		</media:content>

		<media:content url="http://davefancher.files.wordpress.com/2012/02/drivingtechnicalchange.jpg?w=150" medium="image">
			<media:title type="html">Driving Technical Change</media:title>
		</media:content>
	</item>
		<item>
		<title>Going Underground: Microsoft Moles</title>
		<link>http://davefancher.com/2012/01/26/going-underground-microsoft-moles/</link>
		<comments>http://davefancher.com/2012/01/26/going-underground-microsoft-moles/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 20:59:20 +0000</pubDate>
		<dc:creator>Dave Fancher</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Microsoft Moles]]></category>
		<category><![CDATA[Practices]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Isolation Framework]]></category>
		<category><![CDATA[Mole]]></category>
		<category><![CDATA[Moles]]></category>
		<category><![CDATA[Stub]]></category>

		<guid isPermaLink="false">http://davefancher.com/?p=1664</guid>
		<description><![CDATA[Despite having been around for several years I hadn&#8217;t heard about Microsoft&#8217;s Moles framework until a few months ago when one of my teammates mentioned it during the 2011 Indy GiveCamp. I was interested in learning more about it at &#8230; <a href="http://davefancher.com/2012/01/26/going-underground-microsoft-moles/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1664&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Despite having been around for several years I hadn&#8217;t heard about Microsoft&#8217;s Moles framework until a few months ago when one of my teammates mentioned it during the 2011 Indy GiveCamp.  I was interested in learning more about it at the time but given how we were running on caffeine I&#8217;m not surprised I forgot about it until he mentioned it again a few weeks ago.  This time I was much more alert and started reading about it almost immediately.  After seeing what Moles offered and not finding much in the way of resources for it on the Web I knew I needed to spread the word.</p>
<p><span id="more-1664"></span></p>
<p><em><strong>Note:</strong> For this article I used version 0.94 of the Moles Framework.</em></p>
<h2>What is the Moles Framework?</h2>
<p><a href="http://research.microsoft.com/en-us/projects/moles/">Microsoft Moles</a> is a project from Microsoft Research that came about because of work being done on Pex (another MS Research initiative).  The Microsoft Moles Reference Manual describes Moles this way:</p>
<p>“The Microsoft Moles 2010 add-in for Microsoft Visual Studio 2010 is a lightweight framework for creating delegate-based test stubs and detours in .NET Framework applications.”</p>
<p>In other words, Moles is, in a sense, Microsoft’s answer to other mocking frameworks like Rhino Mocks or Moq but Moles differs from the other frameworks in a few ways.&nbsp; One important distinction is that the Moles Framework does not provide any validation mechanisms of its own.&nbsp; In that regard Moles is not so much a testing framework as it is an isolation framework intended for use in conjunction with other testing frameworks such as MSTest or NUnit.</p>
<p><em><strong>Note:</strong> Although Moles started as part of Pex I&#8217;m not going to discuss Pex here.</em></p>
<h2>Isolation Techniques</h2>
<p>The Moles framework provides two isolation techniques:</p>
<ul>
<li>Stub Types</li>
<li>Mole Types</li>
</ul>
<p>Both types allow us to work around dependencies in different ways and have very different use cases.</p>
<h3>Stub Types</h3>
<p>Stub types are much like traditional stub or mock objects in that they allow us to test code that relies on some provided contract.&nbsp; Stubs are based on inheritance so they can only be used with interfaces or non-sealed classes with virtual members.&nbsp; Sometimes the code we want to test relies on static or non-overridable methods that can’t be stubbed.&nbsp; In those scenarios we need to use mole types instead.</p>
<h3>Mole Types</h3>
<p>Mole types use a profiler to rewrite existing method bodies thereby allowing us to circumvent (or “detour” in Moles parlance) dependencies on static or non-overridable methods.&nbsp; Mole types are generally most useful for isolating dependencies in third-party libraries.&nbsp; Unfortunately, runtime rewriting does introduce some performance issues so moles should generally be used sparingly.</p>
<p><strong><em>Note:</em></strong><em> At the time of this writing the Moles framework does not generate detour properties for auto-implemented properties although this could change in a future release (</em><a href="http://social.msdn.microsoft.com/Forums/en-IE/pex/thread/e5ce7b81-6b82-4e7c-bc99-2e7d81d9497d">http://social.msdn.microsoft.com/Forums/en-IE/pex/thread/e5ce7b81-6b82-4e7c-bc99-2e7d81d9497d</a>)<em>.</em></p>
<h3>Choosing an Approach</h3>
<p>With both stub types and mole types at our disposal it is important to understand when to use each.&nbsp; In general Microsoft recommends that we favor stubs over moles whenever possible.&nbsp; Stub types are much lighter than moles and operate over native language features.&nbsp; Some instances where mole types are required are:</p>
<ul>
<li>Private methods</li>
<li>Static methods</li>
<li>Sealed types</li>
<li>Static constructors/finalizers</li>
<li>3<sup>rd</sup> party libraries without testable APIs</li>
</ul>
<h2>Getting Started</h2>
<h3>Installation</h3>
<p>The Moles framework is available through the extension gallery as part of Pex (White box Unit Testing for .NET) or individually.&nbsp; It can also be downloaded directly from the <a href="http://research.microsoft.com/en-us/projects/pex/downloads.aspx">Microsoft Research site</a>.&nbsp; Regardless of which option you choose the functionality is made available to Visual Studio as an add-in.</p>
<h3>Generating Stubs and Moles</h3>
<p>As previously discussed, the Moles framework automatically generates the appropriate stub and mole types.&nbsp; In order for it to generate the types though we need to first tell it which assemblies to inspect via a <kbd>.moles</kbd> file.</p>
<p>The quickest way to get started is to expand the References node in the test project, select the assembly being tested, and choose “Add Moles Assembly” from the context menu.&nbsp; This will add a simple <kbd>.moles</kbd> file and automatically hook up the build action for the file.&nbsp; When the project is built (or the <kbd>.moles</kbd> file is saved) Moles will generate an assembly with the appropriate isolation types and automatically reference it along with any other necessary assemblies.</p>
<p><strong><em>Note:</em></strong><em> The Microsoft Moles Reference Manual describes adding the .moles file through the Add New Item dialog.&nbsp; I couldn&#8217;t find these templates but did find the Add Moles Assembly context menu item on individual references. It&#8217;s also possible to manually add a <kbd>.moles</kbd> file and set the build action to Moles to achieve the same behavior.</em></p>
<p>Should it be necessary to generate isolation types for the types defined in mscorlib (i.e.: <kbd>DateTime</kbd>) we can add a moles assembly for it by right-clicking on the References folder in the test project and selecting the &#8220;Add Moles Assembly for mscorlib&#8221; option.</p>
<h3>Basic Configuration</h3>
<p>The <kbd>.moles</kbd> file is the heart of the Moles Framework configuration.&nbsp; In its simplest form the <kbd>.moles</kbd> file merely identifies an assembly that will be inspected for type generation.</p>
<p><pre class="brush: xml;">
&lt;Moles xmlns=&quot;http://schemas.microsoft.com/moles/2010/&quot;&gt;
	&lt;Assembly Name=&quot;Examples&quot; /&gt;
&lt;/Moles&gt;
</pre></p>
<p>In this example we’ve instructed the system to generate the isolation types for all types defined in the Examples assembly.</p>
<p>In addition to identifying the assembly the <kbd>.moles</kbd> file can also include additional configuration information for filtering which types will be stubbed and/or moled and strong name signing.&nbsp; We’ll take a closer look at these topics later on in the Advanced Configuration section.</p>
<h3><a name="MolesNamingConventions"></a>Naming Conventions</h3>
<p>Once the types have been generated they can be referenced in your tests.&nbsp; The Moles framework follows some basic naming conventions to make the types easier to find and identify in your code.&nbsp; The full list of conventions is available in Appendix B of the Microsoft Moles Reference Manual so I’ll only note a few highlights here.</p>
<p>First, both of the isolation type implementations derive their names from their underlying types but use prefixes to distinguish them.&nbsp; A prefix of “S” denotes a stub type whereas a prefix of “M” denotes a mole type.&nbsp; For example, if you have a class named <kbd>MyClass</kbd> its corresponding stub will be named <kbd>SMyClass</kbd> and the mole type will be <kbd>MMyClass</kbd>.</p>
<p>Each of the isolation types are automatically placed in a <kbd>.Moles</kbd> sub-namespace under the namespace where the original types are located.&nbsp; This means that if you have a User class in the <kbd>Examples.Model</kbd> namespace then the isolation types would be located in <kbd>Examples.Model.Moles</kbd>.</p>
<p>The exposed detour fields or properties on each isolation type also follow some basic naming conventions depending on what the underlying member is:</p>
<table width="100%" style="border-collapse:collapse;" cellpadding="2" border="1">
<tbody>
<tr>
<td>&nbsp;</td>
<td><strong>Convention</strong></td>
<td><strong>Example(s)</strong></td>
</tr>
<tr>
<td><strong>Method</strong></td>
<td>Method name&nbsp; with parameter type names appended</td>
<td>LoadInt32</td>
</tr>
<tr>
<td><strong>Property</strong></td>
<td>Property name with Get or Set</td>
<td>FirstNameGetLastNameSet</td>
</tr>
<tr>
<td><strong>Constructor</strong></td>
<td>“Constructor” with parameter type names appended</td>
<td>ConstructorInt32</td>
</tr>
</tbody>
</table>
<h3>Delegation</h3>
<p>One thing that stub and mole types have in common is that the framework generates both types for a given assembly.&nbsp; By generating these types for us the framework saves us a great deal of time and allows us to focus on the problem at hand but if they are all generated how can we change their behavior?&nbsp; The generator can’t possibly know how we intend to use them, can it?&nbsp; Of course it can&#8217;t, but what it can do is expose fields that correspond to the various members and allow us to specify the alternate behavior with delegation.</p>
<p>Delegation is central to working with the Moles framework.&nbsp; When the framework generates the stub and mole types it exposes the customizable pieces as properties.&nbsp; One important thing to note about the delegate types Moles uses is that they’re not the standard <kbd>Action&lt;&gt;</kbd> or <kbd>Func&lt;&gt;</kbd> types that are provided by the .NET framework.&nbsp; Instead, the Moles framework provides the static <kbd>MolesDelegates</kbd> class that exposes numerous generic types that represent functionality similar to the standard <kbd>Action&lt;&gt;</kbd> and <kbd>Func&lt;&gt;</kbd> types but expands upon them with additional overloads.&nbsp; There are also some variations that accept some <kbd>out</kbd> or <kbd>ref</kbd> arguments as well.</p>
<h2>Using Stub Types</h2>
<p>As previously discussed, stub types should be used when we need to mock interfaces or virtual members of non-sealed classes.&nbsp; Because stubs rely on inheritance they can be implicitly substituted for the stubbed type.</p>
<h3>Methods</h3>
<p>Methods can be stubbed by assigning a delegate with a matching signature to the corresponding field. &nbsp;For example, if we have an interface:</p>
<p><pre class="brush: csharp;">
public interface IMyInterface
{
	int DoSomething(int value1, int value2);
}
</pre></p>
<p>&#8230;and we want to stub the DoSomething method to return the sum of its two parameters we can easily set it up using a type initializer like so:</p>
<p><pre class="brush: csharp;">
var stub = new SIMyInterface()
{
	DoSomethingInt32Int32 = (i1, i2) =&gt; i1 + i2
};
</pre></p>
<p>Generic methods are treated a bit differently than standard methods. &nbsp;Rather than creating a delegate field for generic methods Moles generates an overload of the method that accepts a delegate matches that of the generic method. &nbsp;To stub the generic method we pass a delegate for each type we want to stub to the overload and the stub class maintains an internal dictionary to track which generic instances are stubbed.</p>
<h3>Properties</h3>
<p>Because properties are really just syntactic sugar for accessor methods, stubbing properties is similar to stubbing methods. &nbsp;Stub classes expose separate delegate fields for property getters and setters. &nbsp;For instance, given a property on an interface:</p>
<p><pre class="brush: csharp;">
public interface IMyInterface
{
	string MyProperty { get; set; }
}
</pre></p>
<p>&#8230;we can provide delegates for each accessor and simulate the property behavior in our test:</p>
<p><pre class="brush: csharp;">
var value = default(string);

var stub = new SIMyInterface()
{
	MyPropertyGet = () =&gt; value,
	MyPropertySetString = v =&gt; value = v
};
</pre></p>
<p>Alternatively, Moles also generates a method to simplify this behavior:</p>
<p><pre class="brush: csharp;">
var stub = new SIMyInterface();
stub.AttachBackingFieldToMyProperty();
</pre></p>
<p><em><strong>Note:</strong> Each property with public get and set accessors will have a corresponding attach method.</em></p>
<h3>Events</h3>
<p>Stubs provide an easy way to test events by exposing a delegate field that can be invoked to raise the event.&nbsp; This can be useful for ensuring that the correct handlers are hooked up correctly. &nbsp;Stubbing an event is easiest when working with an interface since the event’s backing field will be exposed automatically but it’s also possible to stub an event on an existing class by making the event virtual.</p>
<p>To illustrate how an event is exposed through a stub consider the following:</p>
<p><pre class="brush: csharp;">
public interface IMyInterface
{
	event EventHandler MyEvent;
}
</pre></p>
<p>When the Moles Framework builds the stub types it will include an <kbd>EventHandler</kbd> delegate field called <kbd>MyEventEvent</kbd>.</p>
<h3>Partial Stubs</h3>
<p>By default, when a stubbed member is invoked but doesn&#8217;t have an attached delegate a <kbd>StubNotImplementedException</kbd> is thrown. &nbsp;This behavior makes sense when working with interfaces but what if we&#8217;re working with a class and want to use the base implementation rather than a stub? &nbsp;The Moles framework lets us achieve this with partial stubs. &nbsp;Activating partial stubs is simply a matter of setting the stub type&#8217;s <kbd>CallBase</kbd> property to true.</p>
<p><em><strong>Note:</strong> The <kbd>CallBase</kbd> property is only generated for classes.</em></p>
<h3>Behaviors</h3>
<p>In the last section we saw that the default behavior for the Moles Framework is to throw a <kbd>StubNotImplementedException</kbd> when a stubbed member is invoked but doesn&#8217;t have an attached delegate. &nbsp;This behavior is controlled through the aptly named <kbd>IBehavior</kbd> interface and can be set either globally or per stub type instance.</p>
<p>The Moles Framework includes a few built-in behaviors that are accessible through the static <kbd>BehavedBehaviors</kbd> class. &nbsp;Of note are:</p>
<ul>
<li><strong>BehavedBehaviors.NotImplemented</strong>&nbsp;- The default behavior, throws a <kbd>StubNotImplementedException</kbd></li>
<li><strong>BehavedBehaviors.DefaultValue</strong>&nbsp;- Returns the default value: <kbd>default(T)</kbd>, for the return type or does nothing for <kbd>void</kbd></li>
</ul>
<p>To set the behavior globally we just need to set the <kbd>BehavedBehaviors.Current</kbd> property:</p>
<p><pre class="brush: csharp;">
BehavedBehaviors.Current = BehavedBehaviors.DefaultValue;
</pre></p>
<p>Alternatively, we can set the behavior for an instance by setting the instance&#8217;s <kbd>InstanceBehavior</kbd> property:</p>
<p><pre class="brush: csharp;">
var stub = new SMyClass()
{
	InstanceBehavior = BehavedBehaviors.DefaultValue
};
</pre></p>
<p>We are by no means restricted to these behaviors either. &nbsp;Should we need a custom behavior we just need to define a class that implements the <kbd>IBehavior</kbd> interface.</p>
<h2>Using Mole Types</h2>
<p>Although stub types are useful for interfaces and virtual members they can&#8217;t isolate everything and that&#8217;s where mole types come in. &nbsp;As mentioned earlier, mole types allow us to detour virtually any .NET method. &nbsp;The canonical example illustrating how handy mole types are involves a dependency most of us are all too familiar with: <kbd>DateTime.Now</kbd>.</p>
<p>Let&#8217;s assume we have some code to check if the end of the world is upon us:</p>
<p><pre class="brush: csharp;">
public static class MayanApocalypse
{
	public static bool HasArrived()
	{
		return DateTime.Now &gt;= DateTime.Parse(&quot;2012-12-21T00:00:00&quot;);
	}
}
</pre></p>
<p>Testing this code is a nightmare because <kbd>DateTime.Now</kbd> is non-deterministic due to its reliance on the system clock. &nbsp;The fact that <kbd>DateTime.Now</kbd> is a static property doesn&#8217;t help matters any either. &nbsp;Wouldn&#8217;t it be nice if we could force <kbd>DateTime.Now</kbd> to return some predetermined value? &nbsp;Mole types let us do just that by injecting a callback into the MSIL body of <kbd>DateTime.Now</kbd>&#8216;s get accessor and calling our custom implementation.</p>
<p><pre class="brush: csharp;">
MDateTime.NowGet = () =&gt; DateTime.Parse(&quot;2012-12-21T00:00:00&quot;);

Assert.IsTrue(MayanApocalypse.HasArrived());
</pre></p>
<h3>Accessing the Moled Type</h3>
<p>Mole types derive from <kbd>MoleBase&lt;T&gt;</kbd>. This is an important distinction from stub types because it means that mole types don&#8217;t rely on inheritance. This has implications when we want to work with the moled type directly. Luckily <kbd>MoleBase&lt;T&gt;</kbd> provides a way to access the moled type through either the <kbd>Instance</kbd> property or an implicit conversion.</p>
<h3>Instrumenting Mole Types</h3>
<p>Due to how mole types work it&#8217;s necessary to run the tests under the Pex profiler. &nbsp;MSTest handles this nicely through the <kbd>HostTypeAttribute</kbd>. &nbsp;To instruct MSTest to run the tests under the Pex profiler simply decorate your tests:</p>
<p><pre class="brush: csharp;">
[TestMethod]
[HostType(&quot;Moles&quot;)]
public void MyTest()
{
	// ...
}
</pre></p>
<p>It&#8217;s also possible to run moles under other test frameworks but additional setup work is required. &nbsp;Refer to the Advanced Configuration section later in this guide for information about using Moles with NUnit.</p>
<p>One other consideration when using mole types is that it might be necessary to add an assembly attribute to allow some types to be instrumented, particularly for some classes in mscorlib. &nbsp;For instance, moling the <kbd>DateTime</kbd> class requires us to add:</p>
<p><pre class="brush: csharp;">
[assembly: MoledType(typeof(System.DateTime))] to our test project.
</pre></p>
<h3>Methods</h3>
<p>We already saw an example of moling a static method when we moled <kbd>DateTime.NowGet</kbd>. Moling instance methods is very similar but we have a bit more flexibility in that we can either provide delegates for individual instances or all instances of the moled type.</p>
<p>If we want to mole an instance method for all instances we hook it up through the nested <kbd>AllInstances</kbd> type. Each mole type has a nested <kbd>AllInstances</kbd> type that exposes write-only properties for setting the mole delegate.</p>
<p><em><strong>Note:</strong> The <kbd>Instance</kbd> property is not available on abstract or static classes.</em></p>
<p><pre class="brush: csharp;">
MMyClass.AllInstances.DoSomething = () =&gt; &quot;Hello world&quot;;

Assert.AreEqual(&quot;Hello world&quot;, new MyClass().DoSomething());
</pre></p>
<p>Instance specific moles look much like their stub counterparts and we can set them in the same manner:</p>
<p><pre class="brush: csharp;">
var mole1 = new MMyClass()
{
	DoSomething = () =&gt; &quot;Hello world&quot;
};

var mole2 = new MMyClass()
{
	DoSomething = () =&gt; &quot;Goodbye&quot;
};

Assert.AreEqual(&quot;Hello world&quot;, mole1.Instance.DoSomething());
Assert.AreEqual(&quot;Goodbye&quot;, ((MyClass)mole2).DoSomething());
</pre></p>
<p><em><strong>Note:</strong> The Moles Framework will also provide properties for private methods provided that each type referenced in the method signature (parameter and return types) is accessible.</em></p>
<h3>Events</h3>
<p>Mole types handle events a bit differently than stubs.&nbsp; Rather than exposing a field for the event Moles generates properties that represent the add and remove accessors.&nbsp; For example, if you have the following event definition:</p>
<p><pre class="brush: csharp;">
public&amp;nbsp;event&amp;nbsp;EventHandler&amp;nbsp;MyEvent;
</pre></p>
<p>the mole type for the class will include properties named&nbsp;<kbd>MyEventAddEventHandler</kbd> and <kbd>MyEventRemoveEventHandler</kbd>.</p>
<h3>Moling Members of Base Types</h3>
<p>For this part of the discussion let&#8217;s assume a simple class hierarchy:</p>
<p><pre class="brush: csharp;">
public abstract class MyClass
{
	public string DoSomething()
	{
		return String.Empty;
	}
}

public class MySubClass : MyClass
{
}
</pre></p>
<p>This structure poses an interesting problem for moles. The <kbd>DoSomething</kbd> method is defined on an abstract class and inherited by <kbd>MySubClass</kbd> but there is no <kbd>DoSomething</kbd> property generated for the <kbd>MMySubClass</kbd> mole so how can we mole <kbd>DoSomething</kbd>?</p>
<p><em><strong>Note:</strong> The Moles reference manual recommends that this technique be reserved for constructor moles.</em></p>
<p>Each mole type actually has two constructors. While we primarily use the default constructor the other constructor lets us pass in another instance. In this case we can mole the <kbd>DoSomething</kbd> method by passing an instance of <kbd>MMySubClass</kbd> and passing it to the constructor for <kbd>MMyClass</kbd>:</p>
<p><pre class="brush: csharp;">
var child = new MMySubClass();
var parent = new MMyClass(child)	// Note that child is implicitly converted here
{
	DoSomething = () =&gt; &quot;Hello world&quot;
};

Assert.AreEqual(&quot;Hello world&quot;, child.Instance.DoSomething());
</pre></p>
<h3>Constructors</h3>
<p>The Moles Framework also lets us mole constructors in a manner similar to how we mole static methods. Each constructor is exposed as a static write-only property named <kbd>Constructor</kbd> and following the naming conventions for parameter types as <a href="#MolesNamingConventions">described above</a>.</p>
<p><em>Note: There are no <kbd>Constructor</kbd> properties for static classes.</em></p>
<h3>Static Constructors and Finalizers</h3>
<p>Static constructors and finalizers can have some unexpected consequences when working with moles so there may be times that it&#8217;s necessary to work around them. Although we can&#8217;t mole them like we do with other members the Moles Framework provides a few attributes for simply erasing them.</p>
<p>To erase a static constructor use the following assembly attribute:</p>
<p><pre class="brush: csharp;">
[assembly: MolesEraseStaticConstructor(typeof(MyClass))]
</pre></p>
<p>Similarly, to erase a finalizer use:</p>
<p><pre class="brush: csharp;">
[assembly: MolesEraseFinalizer(typeof(MyClass))]
</pre></p>
<p><em>Note: Both of these attributes have overloads that allow specifying the assembly name and class name to identify the type.</em></p>
<h3>Behaviors</h3>
<p>Like their stub type counterparts, mole types also use behaviors to control what happens when a member hasn&#8217;t been moled. In many ways mole behaviors are just like stub behaviors in that they can be set either globally, per type, or per instance. The Moles Framework also provides several built-in behaviors for mole types. The default behavior even throws <kbd>MoleNotImplementedException</kbd>.</p>
<p>Despite their similarities though, mole and stub behaviors have very little in common. First, mole behaviors implement the <kbd>IMoleBehavior</kbd> interface. Additionally, the built-in behaviors and global behavior are all accessible through the static <kbd>MoleBehaviors</kbd> class.</p>
<p>Some of the notable built-in behaviors are:</p>
<ul>
<li><strong>MoleBehaviors.NotImplemented</strong> &#8211; The default behavior, throws <kbd>MoleNotImplementedException</kbd></li>
<li><strong>MoleBehaviors.DefaultValue</strong> -&nbsp;Returns the default value: <kbd>default(T)</kbd>, for the return type or does nothing for&nbsp;<kbd>void</kbd></li>
<li><strong>MoleBehaviors.Fallthrough</strong> &#8211; Calls into the original (unmoled) implementation</li>
</ul>
<p>The <kbd>MoleBehaviors</kbd> class also exposes some methods to set the default behavior for a given type.    For instance, if we want all mole types for <kbd>MyClass</kbd> to use the <kbd>DefaultValue</kbd> behavior we can use some code like the following:</p>
<p><pre class="brush: csharp;">
MoleBehaviors.BehaveAsDefaultValue(typeof(MyClass));

var mc = new MMyClass();
// Unmoled method returns &quot;Hello world&quot;
Assert.AreEqual(null, mc.Instance.DoSomething());
</pre></p>
<h2>Advanced Configuration</h2>
<p>So far we&#8217;ve covered the basics of using the Microsoft Moles Framework and largely stayed with the default configuration.  Moles configuration provides options to restrict which isolation types are generated, provide a strong name, and control the target platform for the moles assemblies.</p>
<p><em><strong>Note:</strong> The reference manual states that it is possible to disable compilation and add the generated code to the project but I haven&#8217;t been able to get that feature to work.  If anyone has any insight on this I&#8217;d love to see an example of it working.</em> </p>
<h3>Controlling Type Generation</h3>
<p>Generating the isolation types can be an expensive operation that greatly extends the amount of time needed to build the solution.  You can control what is generated in the <kbd>.moles</kbd> file by including the <kbd>StubGeneration</kbd> and/or <kbd>MoleGeneration</kbd> elements within the <kbd>Moles</kbd> element.  As their names imply, these elements control what will be generated for stubs and moles respectively.</p>
<p>The most basic way to restrict what is generated is to simply set the <kbd>Disabled</kbd> attribute to <kbd>true</kbd> on either element to prevent the framework from generating anything of that type.</p>
<p><pre class="brush: xml;">
&lt;Moles xmlns=&quot;http://schemas.microsoft.com/moles/2010/&quot; Diagnostic=&quot;true&quot; DisableCache=&quot;true&quot;&gt;
	&lt;MoleGeneration Disable=&quot;true&quot; /&gt;
&lt;/Moles&gt;
</pre></p>
<p>Controlling isolation type generation doesn&#8217;t have to be an all-or-nothing approach though.  Both elements also support a nested <kbd>Types</kbd> element that allows for more precise filtering based on a simple syntax.  The <kbd>Types</kbd> element is constructed with the familiar combination of <kbd>Clear</kbd>, <kbd>Add</kbd>, and <kbd>Remove</kbd> elements that are frequently used in standard configuration files.</p>
<p>The <kbd>Add</kbd> and <kbd>Remove</kbd> elements define a number of common attributes that help refine which types will be included or excluded from the code generation.</p>
<table width="100%" style="border-collapse:collapse;" cellpadding="2" border="1">
<tr>
<th>Attribute Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td>AbstractClasses</td>
<td>Boolean</td>
<td>Indicates whether to include or exclude abstract classes</td>
</tr>
<tr>
<td>Classes</td>
<td>Boolean</td>
<td>Indicates whether to include or exclude non-abstract classes</td>
</tr>
<tr>
<td>FullName</td>
<td>String</td>
<td>Identifies the full name of a type</td>
</tr>
<tr>
<td>Interfaces</td>
<td>Boolean</td>
<td>Indicates whether to include or exclude interfaces</td>
</tr>
<tr>
<td>Namespace</td>
<td>String</td>
<td>Identifies a namespace</td>
</tr>
<tr>
<td>Obsolete<sup>*</sup></td>
<td>Boolean</td>
<td>Indicates whether to include or exclude types decorated with <kbd>ObsoleteAttribute</kbd></td>
</tr>
<tr>
<td>TypeName</td>
<td>String</td>
<td>Identifies the name of a type</td>
</tr>
</table>
<p style="font-size:8pt;"><em><sup>*</sup> &#8211; Only valid on <kbd>Remove</kbd> elements</em></p>
<p>The value of each of the string typed attribute above are actually filter pattern definitions.  By default the patterns are used for case-insensitive partial matching but we can control that behavior with a few tokens.</p>
<ul>
<li>Appending <kbd>!</kbd> to the end of the pattern forces an exact, case-sensitive match</li>
<li>Appending <kbd>*</kbd> to the end of the pattern will match the beginning of the string </li>
</ul>
<p>Multiple patterns can be combined using a semi-colon delimited list.</p>
<p><pre class="brush: xml;">
&lt;AssemblyName=&quot;mscorlib&quot;/&gt;
	&lt;StubGeneration&gt;
		&lt;Types&gt;
			&lt;Clear /&gt;
			&lt;Add Namespace=&quot;System!&quot; /&gt;
			&lt;Add Namespace=&quot;System.IO!&quot;/&gt;
			&lt;Remove TypeName=&quot;Handle&quot; /&gt;
		&lt;Types&gt;
	&lt;/StubGeneration&gt;
&lt;/Assembly&gt;
</pre></p>
<p>Using the example above (taken from the reference manual), Moles would only generate stub types for the types in the <kbd>System</kbd> and <kbd>System.IO</kbd> namespaces and excludes anything containing &#8220;Handle&#8221; in the name.</p>
<h3>Strong Name Signing</h3>
<p>By default, the generated assembly will be signed with the same key as the moled assembly if it is strongly named.  If it&#8217;s necessary to use a different key we just need to specify the path to the key file in the <kbd>Compilation</kbd> element&#8217;s <kbd>KeyFile</kbd> attribute in the <kbd>.moles</kbd> file.</p>
<p><pre class="brush: xml;">
&lt;Moles xmlns=&quot;http://schemas.microsoft.com/moles/2010/&quot;&gt;
	&lt;!-- ... --&gt;
	&lt;Compilation KeyFile=&quot;key file path&quot; &gt;
&lt;/Moles&gt;
</pre></p>
<h3>Setting the Target Platform</h3>
<p>Should it be necessary to force the moles profiler to run as a 32 or 64-bit process we can do so with the <kbd>MolesAssemblySettingsAttribute</kbd> found in the <kbd>Microsoft.Moles.Framework</kbd> namespace.  We just need to include the attribute as an assembly attribute and set <kbd>Bitness</kbd> parameter accordingly.  For instance, to use a 64-bit process we could use:</p>
<p><pre class="brush: csharp;">
[assembly: MolesAssemblySettings(Bitness = MolesBitness.x64)]
</pre></p>
<p>Other valid options for Bitness are <kbd>MolesBitness.x86</kbd> and <kbd>MolesBitness.AnyCPU</kbd>.</p>
<h3>Using with NUnit</h3>
<p>Being a project from Microsoft Research it&#8217;s no surprise that Moles is easiest to use with MSTest.  As we discussed, to get Moles to work with MSTest we just need to decorate the test methods with <kbd>[HostType("Moles")]</kbd> and MSTest will set up the instrumentation accordingly.</p>
<p>Of course, not everyone is using MSTest so we need a way to run moled tests with other frameworks.  The good news is that yes, Moles can be used with other frameworks.  The bad news though is that it takes some extra effort to make it work.  Although I&#8217;m focusing on using Moles with NUnit the process is similar for other frameworks like xUnit or MbUnit.</p>
<p>NUnit requires the <kbd>Microsoft.Moles.NUnit</kbd> assembly to be registered as an add-in.  The Moles Framework ships with a copy of this assembly but it is built against a specific version of NUnit (2.5.2.922 in my case) so if you&#8217;re using a different version of NUnit (I&#8217;m on 2.5.10.11092) you&#8217;ll need to recompile the assembly with the correct NUnit assemblies.  Once you have a version of the add-in assembly that corresponds to your NUnit version you can copy into the <kbd>bin\addins</kbd> folder to register it with NUnit.</p>
<p><em><strong>Note:</strong> The source for the add-in assembly is available in the <kbd>moles.samples.zip</kbd> file located in the Documentation folder under the Moles installation folder.</em></p>
<p>The add-in assembly defines the <kbd>MoledAttribute</kbd> class that sets up the mole context in the NUnit runner.  You&#8217;ll need to reference the assembly in your test project and import the <kbd>Microsoft.Moles.Framework.NUnit</kbd> namespace.  For convenience I referenced the version of the DLL that I&#8217;d placed in my add-ins folder.</p>
<p>You might think that since you&#8217;ve registered the add-in and built the projects that you&#8217;re ready to run the tests.  In a sense, you are but there are a few nuances to be aware of first.</p>
<ol>
<li>The GUI test runner doesn&#8217;t work with Moles</li>
<li>The tests need to be run under the context of the Moles test runner</li>
</ol>
<p>To run the tests with NUnit&#8217;s console runner under the context of the Moles runner you can use the following command:</p>
<p><pre class="brush: plain;">
moles.runner.exe /r:nunit-console.exe /args=&quot;/domain=None&quot; [test assembly name]
</pre></p>
<h2>Wrapping Up</h2>
<p>So that&#8217;s Microsoft Moles in a nutshell.  If you like what you see I encourage you to download it and give it a try.  Of course, if you found any errors in what I&#8217;ve shown or think I missed something important please let me know in the comments.</p>
<br /> Tagged: <a href='http://davefancher.com/tag/isolation-framework/'>Isolation Framework</a>, <a href='http://davefancher.com/tag/microsoft-moles/'>Microsoft Moles</a>, <a href='http://davefancher.com/tag/mole/'>Mole</a>, <a href='http://davefancher.com/tag/moles/'>Moles</a>, <a href='http://davefancher.com/tag/stub/'>Stub</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davefancher.wordpress.com/1664/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davefancher.wordpress.com/1664/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davefancher.wordpress.com/1664/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davefancher.wordpress.com/1664/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davefancher.wordpress.com/1664/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davefancher.wordpress.com/1664/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davefancher.wordpress.com/1664/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davefancher.wordpress.com/1664/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davefancher.wordpress.com/1664/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davefancher.wordpress.com/1664/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davefancher.wordpress.com/1664/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davefancher.wordpress.com/1664/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davefancher.wordpress.com/1664/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davefancher.wordpress.com/1664/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1664&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davefancher.com/2012/01/26/going-underground-microsoft-moles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad02f59c6c342c3788b9439c53bbf242?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">davefancher</media:title>
		</media:content>
	</item>
		<item>
		<title>IndyNDA &#8211; Panel Discussion on Technical Screening</title>
		<link>http://davefancher.com/2012/01/10/indynda-panel-discussion-on-technical-screening/</link>
		<comments>http://davefancher.com/2012/01/10/indynda-panel-discussion-on-technical-screening/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 11:30:09 +0000</pubDate>
		<dc:creator>Dave Fancher</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[IndyNDA]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Speaking]]></category>
		<category><![CDATA[User Groups]]></category>
		<category><![CDATA[Panel Discussion]]></category>
		<category><![CDATA[Technical Screening]]></category>

		<guid isPermaLink="false">http://davefancher.com/?p=1605</guid>
		<description><![CDATA[The January IndyNDA meeting is this Thursday!  Join us for a panel discussion on technical screening.  Mark Huebner will moderate the discussion with our panelists including Ed Herceg (Robert Half Technology), Dale Brubaker (Interactive Intelligence), and yours truly.  Audience participation is &#8230; <a href="http://davefancher.com/2012/01/10/indynda-panel-discussion-on-technical-screening/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1605&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a title="Technical Screening: This Is How We Do It" href="http://www.indynda.com/RecentMeetings/tabid/62/EntryId/30/Thursday-January-12th-132nd-Meeting.aspx">January IndyNDA meeting</a> is this Thursday!  Join us for a panel discussion on technical screening.  Mark Huebner will moderate the discussion with our panelists including Ed Herceg (Robert Half Technology), Dale Brubaker (Interactive Intelligence), and yours truly.  Audience participation is encouraged.</p>
<blockquote><p>Some say companies and recruiting firms are using tests based on incorrect assumptions on how developers do their work. C# and jQuery and JavaScript and VB and the .NET framework continue to offer new capabilities. The complexity has generally not been a problem for you because you make liberal use of IntelliSense, online help, books online, reference books, Google searches, and technical online forums. You know how to quickly find information when you can’t remember specific syntax. So, can you pass that technical screening test? Should you need to be tested? Let&#8217;s find out</p></blockquote>
<p>Don&#8217;t forget about the C# and JavaScript SIGs after the main event either.  I&#8217;m not sure what the JavaScript group is covering but for the C# group Alex Gheith and I will be leading a discussion over a few of the items in chapter 1 of<a title="Effective C#" href="http://www.amazon.com/Effective-Covers-4-0-Specific-Development/dp/0321658701/ref=sr_1_1?ie=UTF8&amp;qid=1326175388&amp;sr=8-1"> Effective C# by Bill Wagner</a>.</p>
<p>As always registration begins at 5:30 with the main event starting at 6:00.  Thanks to our sponsors food and drink will be provided before the meeting.</p>
<p>Please be aware that our meeting location has changed.  For January and February we&#8217;ll be meeting in the 2<sup>nd</sup> floor conference room in Parkwood 9.  For those that remember when we had meetings in the 5<sup>th</sup> floor conference room in the same building rest assured, the 2<sup>nd</sup> floor conference room is better suited to our needs.</p>
<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=900 E 96th Street, Indianapolis, IN 46240&amp;aq=&amp;sll=37.0625,-95.677068&amp;sspn=67.334709,107.138672&amp;vpsrc=0&amp;ie=UTF8&amp;hnear=900 E 96th St, Indianapolis, Marion, Indiana 46240&amp;t=m&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=900 E 96th Street, Indianapolis, IN 46240&amp;aq=&amp;sll=37.0625,-95.677068&amp;sspn=67.334709,107.138672&amp;vpsrc=0&amp;ie=UTF8&amp;hnear=900 E 96th St, Indianapolis, Marion, Indiana 46240&amp;t=m&amp;z=14&amp;iwloc=A&amp;source=embed" style="text-align:left">View Larger Map</a></small>
<p>I hope to see you there!</p>
<br /> Tagged: <a href='http://davefancher.com/tag/community/'>Community</a>, <a href='http://davefancher.com/tag/indynda/'>IndyNDA</a>, <a href='http://davefancher.com/tag/panel-discussion/'>Panel Discussion</a>, <a href='http://davefancher.com/tag/technical-screening/'>Technical Screening</a>, <a href='http://davefancher.com/tag/user-groups/'>User Groups</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davefancher.wordpress.com/1605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davefancher.wordpress.com/1605/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davefancher.wordpress.com/1605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davefancher.wordpress.com/1605/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davefancher.wordpress.com/1605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davefancher.wordpress.com/1605/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davefancher.wordpress.com/1605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davefancher.wordpress.com/1605/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davefancher.wordpress.com/1605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davefancher.wordpress.com/1605/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davefancher.wordpress.com/1605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davefancher.wordpress.com/1605/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davefancher.wordpress.com/1605/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davefancher.wordpress.com/1605/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1605&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davefancher.com/2012/01/10/indynda-panel-discussion-on-technical-screening/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad02f59c6c342c3788b9439c53bbf242?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">davefancher</media:title>
		</media:content>
	</item>
		<item>
		<title>VS2010: Box Selections</title>
		<link>http://davefancher.com/2012/01/07/vs2010-box-selections/</link>
		<comments>http://davefancher.com/2012/01/07/vs2010-box-selections/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 07:09:38 +0000</pubDate>
		<dc:creator>Dave Fancher</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Environments]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Box Selection]]></category>
		<category><![CDATA[Box Selections]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[VS2010]]></category>

		<guid isPermaLink="false">http://davefancher.com/?p=1623</guid>
		<description><![CDATA[When I first saw the box selection capabilities in Visual Studio 2010 I thought &#8220;that&#8217;s kind of neat but I&#8217;ll probably never use it&#8221; and promptly moved on.  I couldn&#8217;t have been more mistaken.  In fact, nearly two years later, &#8230; <a href="http://davefancher.com/2012/01/07/vs2010-box-selections/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1623&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When I first saw the box selection capabilities in Visual Studio 2010 I thought &#8220;that&#8217;s kind of neat but I&#8217;ll probably never use it&#8221; and promptly moved on.  I couldn&#8217;t have been more mistaken.  In fact, nearly two years later, box selection has become one of those features that I use almost daily.  What surprises me now though is how many developers I run into that still don&#8217;t know about them.</p>
<p>Box selections let us quickly make the same change to multiple lines simultaneously.  Creating them is easy &#8211; just hold shift+alt and use the arrow keys or hold the alt key while left drag the mouse to define a rectangle.  If you just want to insert the same text onto multiple lines you can define a zero-length box by expanding the box vertically in either direction.</p>
<p><img class="size-full wp-image-1637   alignright" style="margin-left:10px;" title="Non-virtual Properties" src="http://davefancher.files.wordpress.com/2012/01/nonvirtual-properties2.png?w=500" alt="Non-virtual Properties"   /></p>
<p>So what makes box selections so useful?  Some of the things I find them most useful for are changing modifiers and making local variables implicitly typed.  To illustrate, let&#8217;s take a look at a few non-virtual properties that we&#8217;d like to make virtual.</p>
<p><img class="size-full wp-image-1639   alignright" style="margin-left:10px;" title="Zero-Length Selection" src="http://davefancher.files.wordpress.com/2012/01/zero-length-selection2.png?w=500" alt="Zero-Length Selection"   /></p>
<p>Making these properties virtual without a box selection certainly isn&#8217;t difficult but it&#8217;s definitely tedious.  A box selection lets us make them all virtual at the same time so we can get on with the task at hand.  The thin blue line immediately following the public modifier on each property identifies the zero-length box that serves as the point where we&#8217;ll insert in the virtual modifier.</p>
<p><img class="size-medium wp-image-1638 alignright" style="margin-left:10px;" title="Virtual Properties" src="http://davefancher.files.wordpress.com/2012/01/virtual-properties2.png?w=300&#038;h=62" alt="Virtual Properties" width="300" height="62" />To insert the virtual modifier we just need to type (or paste) &#8220;virtual.&#8221;  Here you can see that each property is now virtual and the zero-length box has moved to the end of the inserted text.  What if we decide later though that these properties shouldn&#8217;t be virtual after all?</p>
<p><img class="size-medium wp-image-1635 alignright" style="margin-left:10px;" title="Box Selection" src="http://davefancher.files.wordpress.com/2012/01/box-selection2.png?w=300&#038;h=66" alt="Box Selection" width="300" height="66" />We can use box selections to remove the virtual modifier from each property just as easily.  In the example to the left we see a box selection highlighting the virtual modifier on each line.  <img class="size-full wp-image-1636 alignright" style="margin-left:10px;" title="Non-virtual Properties 2" src="http://davefancher.files.wordpress.com/2012/01/nonvirtual-properties-22.png?w=500" alt="Non-virtual Properties 2"   />To remove the text we can simply delete it.  This will leave us with a zero-length box where the virtual modifiers used to be.  We can then simply click or arrow away to clear the box selection.</p>
<p>Box selections can go a long way toward increasing your productivity by reducing some of the more tedious aspects of programming.  The few seconds they save here and there can really add up over the course of a day.  More importantly though, that time can be spent on the real problems we&#8217;re trying to solve.</p>
<h2>Further Reading</h2>
<p><a title="How to: Select and Change Text" href="http://msdn.microsoft.com/en-us/library/729s2dhh.aspx">How to: Select and Change Text</a></p>
<br /> Tagged: <a href='http://davefancher.com/tag/box-selection/'>Box Selection</a>, <a href='http://davefancher.com/tag/box-selections/'>Box Selections</a>, <a href='http://davefancher.com/tag/visual-studio/'>Visual Studio</a>, <a href='http://davefancher.com/tag/visual-studio-2010/'>Visual Studio 2010</a>, <a href='http://davefancher.com/tag/vs2010/'>VS2010</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davefancher.wordpress.com/1623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davefancher.wordpress.com/1623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davefancher.wordpress.com/1623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davefancher.wordpress.com/1623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davefancher.wordpress.com/1623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davefancher.wordpress.com/1623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davefancher.wordpress.com/1623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davefancher.wordpress.com/1623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davefancher.wordpress.com/1623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davefancher.wordpress.com/1623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davefancher.wordpress.com/1623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davefancher.wordpress.com/1623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davefancher.wordpress.com/1623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davefancher.wordpress.com/1623/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1623&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davefancher.com/2012/01/07/vs2010-box-selections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad02f59c6c342c3788b9439c53bbf242?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">davefancher</media:title>
		</media:content>

		<media:content url="http://davefancher.files.wordpress.com/2012/01/nonvirtual-properties2.png" medium="image">
			<media:title type="html">Non-virtual Properties</media:title>
		</media:content>

		<media:content url="http://davefancher.files.wordpress.com/2012/01/zero-length-selection2.png" medium="image">
			<media:title type="html">Zero-Length Selection</media:title>
		</media:content>

		<media:content url="http://davefancher.files.wordpress.com/2012/01/virtual-properties2.png?w=300" medium="image">
			<media:title type="html">Virtual Properties</media:title>
		</media:content>

		<media:content url="http://davefancher.files.wordpress.com/2012/01/box-selection2.png?w=300" medium="image">
			<media:title type="html">Box Selection</media:title>
		</media:content>

		<media:content url="http://davefancher.files.wordpress.com/2012/01/nonvirtual-properties-22.png" medium="image">
			<media:title type="html">Non-virtual Properties 2</media:title>
		</media:content>
	</item>
		<item>
		<title>New Year, New Name</title>
		<link>http://davefancher.com/2012/01/02/new-year-new-name/</link>
		<comments>http://davefancher.com/2012/01/02/new-year-new-name/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 04:32:13 +0000</pubDate>
		<dc:creator>Dave Fancher</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://davefancher.com/?p=1595</guid>
		<description><![CDATA[I&#8217;ve been thinking about this for a while but the new year seemed like a good time for a fresh start.  I&#8217;ve changed the name of the blog. The best-laid plans of mice and men often go awry When I &#8230; <a href="http://davefancher.com/2012/01/02/new-year-new-name/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1595&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thinking about this for a while but the new year seemed like a good time for a fresh start.  I&#8217;ve changed the name of the blog.</p>
<blockquote><p>The best-laid plans of mice and men often go awry</p></blockquote>
<p>When I named this site Two years ago I was really serious about both software development and photography and fully intended to use this space to explore both subjects.  Over time though I began thinking that I should focus on one or the other.  Given that programming is my chosen profession it was only natural that I take the site that direction.  For that reason that I decided to retire &#8220;The Programmer&#8217;s Lens&#8221; as the name of the site.  I think the new name, Didactic Code, more accurately reflects the purpose of the blog.</p>
<blockquote><p>Didactic: intended to convey instruction and information as well as pleasure and entertainment<br />
&#8211; <a title="Didactic Definition" href="http://www.merriam-webster.com/dictionary/didactic">Merriam-Webster Dictionary</a></p></blockquote>
<p>This space is a learning tool.  I&#8217;m not ashamed to admit that I write for myself just as much as I do for others.  Writing about these topics is the most effective way for me learn about them.  I also like to share what I&#8217;ve learned so when others find benefit in my writings that&#8217;s just icing on the cake.</p>
<p>I&#8217;ve left the handful of photography related posts intact (not that they get any traffic) but I&#8217;ll no longer consider photography as part of this blog.  Should you be interested in my photos feel free to peruse my <a title="Dave Fancher's photos on Flickr" href="http://www.flickr.com/photos/davefancher/">Flickr photostream</a>.</p>
<p>So what do you think of the change?  Do you like the new name or should I change it back?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davefancher.wordpress.com/1595/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davefancher.wordpress.com/1595/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davefancher.wordpress.com/1595/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davefancher.wordpress.com/1595/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davefancher.wordpress.com/1595/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davefancher.wordpress.com/1595/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davefancher.wordpress.com/1595/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davefancher.wordpress.com/1595/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davefancher.wordpress.com/1595/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davefancher.wordpress.com/1595/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davefancher.wordpress.com/1595/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davefancher.wordpress.com/1595/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davefancher.wordpress.com/1595/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davefancher.wordpress.com/1595/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1595&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davefancher.com/2012/01/02/new-year-new-name/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad02f59c6c342c3788b9439c53bbf242?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">davefancher</media:title>
		</media:content>
	</item>
		<item>
		<title>Happy New Year!</title>
		<link>http://davefancher.com/2012/01/02/happy-new-year/</link>
		<comments>http://davefancher.com/2012/01/02/happy-new-year/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 21:15:53 +0000</pubDate>
		<dc:creator>Dave Fancher</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://davefancher.com/?p=1593</guid>
		<description><![CDATA[The WordPress.com stats helper monkeys prepared a report for this blog&#8217;s activity in 2011.  It&#8217;s pretty cool to watch my little part of the Web grow.  I already have a few posts and talks in the works for this year &#8230; <a href="http://davefancher.com/2012/01/02/happy-new-year/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1593&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a title="WordPress.com" href="http://www.wordpress.com">WordPress.com</a> stats helper monkeys prepared a report for this blog&#8217;s activity in 2011.  It&#8217;s pretty cool to watch my little part of the Web grow.  I already have a few posts and talks in the works for this year and as always, I&#8217;m still on the lookout for new topics.</p>
<p><a href="/2011/annual-report/"><img src="http://www.wordpress.com/wp-content/mu-plugins/annual-reports/img/emailteaser.jpg" alt="" width="100%" /></a></p>
<p>Here&#8217;s an excerpt from <a title="2011 Annual Report" href="/2011/annual-report/">the report</a>:</p>
<blockquote><p>The concert hall at the Syndey Opera House holds 2,700 people. This blog was viewed about <strong>22,000</strong> times in 2011. If it were a concert at Sydney Opera House, it would take about 8 sold-out performances for that many people to see it.</p></blockquote>
<p>2011 was a good year for me and my family.  We wish everyone the best for the new year.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davefancher.wordpress.com/1593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davefancher.wordpress.com/1593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davefancher.wordpress.com/1593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davefancher.wordpress.com/1593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davefancher.wordpress.com/1593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davefancher.wordpress.com/1593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davefancher.wordpress.com/1593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davefancher.wordpress.com/1593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davefancher.wordpress.com/1593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davefancher.wordpress.com/1593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davefancher.wordpress.com/1593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davefancher.wordpress.com/1593/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davefancher.wordpress.com/1593/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davefancher.wordpress.com/1593/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davefancher.com&amp;blog=12467521&amp;post=1593&amp;subd=davefancher&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davefancher.com/2012/01/02/happy-new-year/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad02f59c6c342c3788b9439c53bbf242?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">davefancher</media:title>
		</media:content>

		<media:content url="http://www.wordpress.com/wp-content/mu-plugins/annual-reports/img/emailteaser.jpg" medium="image" />
	</item>
	</channel>
</rss>
