<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
    <channel>
        <title>AbstractCode</title>
        <link>http://abstractcode.com/abstractblog/Default.aspx</link>
        <description>Code too abstract to instantiate</description>
        <language>en-AU</language>
        <copyright>Colin David Scott</copyright>
        <generator>Subtext Version 2.1.0.5</generator>
        <image>
            <title>AbstractCode</title>
            <url>http://abstractcode.com/abstractblog/images/RSS2Image.gif</url>
            <link>http://abstractcode.com/abstractblog/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/Abstractcode" type="application/rss+xml" /><item>
            <title>Chain of responsibility using LINQ Extension methods</title>
            <category>C#</category>
            <link>http://feedproxy.google.com/~r/Abstractcode/~3/JhKeQjemz-w/172.aspx</link>
            <description>&lt;p&gt;I recently had reason to implement a simple chain of responsibility in order to simplify some logic. Rather than a large number of sequential &lt;em&gt;if&lt;/em&gt; statements to implement a sequence of conditional exclusive actions I used this structure to simplify the logic.&lt;/p&gt;  &lt;p&gt;The basis of the implementation is a field that is a collection of delegates. The delegate take parameters as needed to determine if an action is applicable and also to implement the action. It also returns &lt;em&gt;bool&lt;/em&gt;. For example:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d72f8b48-ebf5-4583-9c3e-e3552628ced7" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: none;"&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;readonly&lt;/span&gt;&lt;span style="color: #000000;"&gt; ICollection&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; _chain &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; List&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    {
        FirstHandler, SecondHandler, FallbackHandler
    };
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;This is a simple chain consisting of three actions. Each of &lt;em&gt;FirstHandler&lt;/em&gt;, &lt;em&gt;SecondHandler&lt;/em&gt; and &lt;em&gt;FallbackHandler&lt;/em&gt; are methods that match the delegate signature. In this example they are each methods on the same class but this is not mandatory. I’ve defined them as:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:9e2bce95-6ef8-4c86-90b5-fe6f604fa78e" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: none;"&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt; FirstHandler(TestObject testObject)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (testObject.TestValue &lt;/span&gt;&lt;span style="color: #000000;"&gt;!=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;1&lt;/span&gt;&lt;span style="color: #000000;"&gt;)
    {
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;false&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    }

    Console.WriteLine(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;First Handler&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;true&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt; SecondHandler(TestObject testObject)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (testObject.TestValue &lt;/span&gt;&lt;span style="color: #000000;"&gt;!=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;2&lt;/span&gt;&lt;span style="color: #000000;"&gt;)
    {
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;false&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    }

    Console.WriteLine(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Second Handler&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;true&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt; FallbackHandler(TestObject testObject)
{
    Console.WriteLine(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt;.Format(CultureInfo.CurrentCulture, &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Fallback: {0}&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, testObject.TestValue));
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;true&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;The first two methods do a check to see if they are applicable, returning &lt;em&gt;false&lt;/em&gt; if this is not the case and &lt;em&gt;true&lt;/em&gt; if it is. FallbackHandler is different and always returns &lt;em&gt;true&lt;/em&gt; and applies its action. This makes it the last link in the chain.&lt;/p&gt;

&lt;p&gt;In order to execute the chain we use the &lt;a href="http://msdn.microsoft.com/en-us/library/bb535050.aspx"&gt;First&lt;/a&gt; method from the LINQ &lt;a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.aspx"&gt;Enumerable&lt;/a&gt; class. The following example shows the use of the chain to execute (in order) the &lt;em&gt;SecondHandler&lt;/em&gt;, &lt;em&gt;FirstHandler&lt;/em&gt; and &lt;em&gt;FallbackHandler&lt;/em&gt; methods.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:22fd9599-54ed-42bb-8a44-c8f43ff8911b" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: none;"&gt;&lt;span style="color: #000000;"&gt;_chain.First(c &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; c(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; TestObject {TestValue &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;2&lt;/span&gt;&lt;span style="color: #000000;"&gt;}));
_chain.First(c &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; c(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; TestObject {TestValue &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;1&lt;/span&gt;&lt;span style="color: #000000;"&gt;}));
_chain.First(c &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; c(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; TestObject {TestValue &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;5&lt;/span&gt;&lt;span style="color: #000000;"&gt;}));
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;This works by enumerating through the &lt;em&gt;_chain&lt;/em&gt; collection, executing each delegate in turn. Each method will check whether it wishes to handle the call, returning a value indicating whether it has chosen to do so. A return value of &lt;em&gt;true&lt;/em&gt; indicates that a link has handled the request and that no further processing is required. This causes &lt;em&gt;First&lt;/em&gt; to stop enumerating. It also returns to matching delegate but this may be ignored. The last handler is a fallback as it handles everything that was not otherwise handled. This is necessary as the First method will throw an exception if no match is found. It is appropriate to do this when there is always an action to be applied. If it is valid that no action be performed then you can substitute &lt;a href="http://msdn.microsoft.com/en-us/library/bb549039.aspx"&gt;FirstOrDefault&lt;/a&gt; which will not error when a match is not found.&lt;/p&gt;

&lt;p&gt;Note that the chain does not need to be fixed. It is entirely valid to modify it dynamically at runtime. Care should be taken to ensure that there are no threading issues as a result. You can change the &lt;a href="http://msdn.microsoft.com/en-us/library/bb549151.aspx"&gt;Func&lt;/a&gt; delegate used provided you continue to return true.&lt;/p&gt;

&lt;p&gt;This works well but is not particularly useful when you need the chain to return a value. In this case we can split the check and the action into separate methods. We can make the chain a collection of &lt;a href="http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx"&gt;KeyValuePair&lt;/a&gt; values where the key and value types are delegates. In this case the key is a delegate returning true that performs the check and the value is a delegate that performs the action and returns the required value. The chain becomes:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:43ae5fb8-bac0-4b37-84ff-f37e68b0121f" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: none;"&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;readonly&lt;/span&gt;&lt;span style="color: #000000;"&gt; ICollection&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;KeyValuePair&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;, Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; _chain
    &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; List&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;KeyValuePair&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;, Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    {
        CreateLink(FirstCheck, FirstAction),
        CreateLink(SecondCheck, SecondAction),
        CreateLink(FallbackCheck, FallbackAction)
    };

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; KeyValuePair&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;, Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; CreateLink(Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; key,
    Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; value)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; KeyValuePair&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;, Func&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TestObject, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(key, value);
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p /&gt;

&lt;p /&gt;

&lt;p /&gt;

&lt;p&gt;We use a helper method here to simplify things given the nested generics. We define the checks and actions as separate methods:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:5d20e295-6679-46ea-99cb-3d0e04b7fb99" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: none;"&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt; FirstCheck(TestObject testObject)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; testObject.TestValue &lt;/span&gt;&lt;span style="color: #000000;"&gt;==&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;1&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt; FirstAction(TestObject testObject)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; testObject.TestValue &lt;/span&gt;&lt;span style="color: #000000;"&gt;*&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;2&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt; SecondCheck(TestObject testObject)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; testObject.TestValue &lt;/span&gt;&lt;span style="color: #000000;"&gt;==&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;2&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt; SecondAction(TestObject testObject)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; testObject.TestValue &lt;/span&gt;&lt;span style="color: #000000;"&gt;*&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;3&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;bool&lt;/span&gt;&lt;span style="color: #000000;"&gt; FallbackCheck(TestObject testObject)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;true&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt; FallbackAction(TestObject testObject)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; testObject.TestValue;
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Invoking the new chain is slightly more complicated and looks like:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:7e23db3b-e06b-4211-ba0f-231fb7020a3b" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: none;"&gt;&lt;span style="color: #000000;"&gt;var testObject &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; TestObject {TestValue &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;2&lt;/span&gt;&lt;span style="color: #000000;"&gt;};
var result &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; _chain.First(c &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; c.Key(testObject)).Value(testObject);
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Again the chain may be dynamically altered at runtime provided that this is done in a threadsafe manner. I would recommend reconstructing the entire chain then substituting it for the existing chain rather than attempting to modify an existing chain in place. Modification in place will generally be more complex and require a more complex locking strategy.&lt;/p&gt;

&lt;p&gt;This approach demonstrates an implementation that is suitable for many circumstances where a classic chain of responsibility is called for. The use of LINQ methods may have performance implications in some applications and this should be considered before committing to it. In general use however this is a simple way to apply this pattern and avoid verbose &lt;em&gt;for&lt;/em&gt;/&lt;em&gt;foreach&lt;/em&gt; statements.&lt;/p&gt;&lt;img src="http://abstractcode.com/abstractblog/aggbug/172.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/Abstractcode/~4/JhKeQjemz-w" height="1" width="1"/&gt;</description>
            <dc:creator>Colin David Scott</dc:creator>
            <guid isPermaLink="false">http://abstractcode.com/abstractblog/archive/2009/07/03/172.aspx</guid>
            <pubDate>Fri, 03 Jul 2009 15:45:07 GMT</pubDate>
            <wfw:comment>http://abstractcode.com/abstractblog/comments/172.aspx</wfw:comment>
            <comments>http://abstractcode.com/abstractblog/archive/2009/07/03/172.aspx#feedback</comments>
            <wfw:commentRss>http://abstractcode.com/abstractblog/comments/commentRss/172.aspx</wfw:commentRss>
        <feedburner:origLink>http://abstractcode.com/abstractblog/archive/2009/07/03/172.aspx</feedburner:origLink></item>
        <item>
            <title>Conditional references using MSBuild</title>
            <link>http://feedproxy.google.com/~r/Abstractcode/~3/qWXzXDXNpC4/171.aspx</link>
            <description>&lt;p&gt;I’ve been using SQLite in a personal project and have encountered an issue with referencing the assembly. The .NET assembly references the unmanaged SQLite proper assembly, and this varies between 32 and 64 bit systems. Hence when building the project on my netbook a number of tests fail.&lt;/p&gt;  &lt;p&gt;The solution lies in the following XML places in the project file.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:b63c0ea1-eb2f-470d-8fdf-8871330f2001" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Choose&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;When &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;Condition&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="$(PROCESSOR_ARCHITEW6432) == 'AMD64'"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;ItemGroup&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Reference &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;Include&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="System.Data.SQLite, Version=1.0.62.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;SpecificVersion&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;False&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;SpecificVersion&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;HintPath&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;..\..\..\external-lib\x64\System.Data.SQLite.DLL&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;HintPath&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;Reference&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;ItemGroup&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;When&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Otherwise&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;ItemGroup&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;Reference &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;Include&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="System.Data.SQLite, Version=1.0.62.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;SpecificVersion&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;False&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;SpecificVersion&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;HintPath&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;..\..\..\external-lib\x86\System.Data.SQLite.DLL&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;HintPath&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;Reference&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;ItemGroup&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;Otherwise&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;Choose&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;This conditionally includes the 32 or 64 bit SQLite assembly based on evaluating the PROCESSOR_ARCHITEW6432 variable which contains the current processor architecture. Checking the PROCESSOR_ARCHITECTURE environment variable was a seemingly obvious choice but evaluates incorrectly (for this purpose) in 32 bit MSBuild on a 64 bit system.&lt;/p&gt;&lt;img src="http://abstractcode.com/abstractblog/aggbug/171.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/Abstractcode/~4/qWXzXDXNpC4" height="1" width="1"/&gt;</description>
            <dc:creator>Colin David Scott</dc:creator>
            <guid isPermaLink="false">http://abstractcode.com/abstractblog/archive/2009/07/03/171.aspx</guid>
            <pubDate>Fri, 03 Jul 2009 12:22:41 GMT</pubDate>
            <wfw:comment>http://abstractcode.com/abstractblog/comments/171.aspx</wfw:comment>
            <comments>http://abstractcode.com/abstractblog/archive/2009/07/03/171.aspx#feedback</comments>
            <wfw:commentRss>http://abstractcode.com/abstractblog/comments/commentRss/171.aspx</wfw:commentRss>
        <feedburner:origLink>http://abstractcode.com/abstractblog/archive/2009/07/03/171.aspx</feedburner:origLink></item>
        <item>
            <title>Measuring developer productivity</title>
            <category>Development Practices</category>
            <link>http://feedproxy.google.com/~r/Abstractcode/~3/MLrXDmvwNMo/170.aspx</link>
            <description>&lt;p&gt;Much has been written on the failure of counting lines of code (LOC) as a metric for productivity. I won’t further expand on this except to note that what I consider the most compelling argument against LOC is that it will penalise a superior design that can be expressed more succinctly. But if we don’t use LOC, what do we use?&lt;/p&gt;  &lt;p&gt;I’m of the opinion that the best low level metric for the development of new features is the rate at which unit tests are being added or modified. Unit tests form an executable specification of the behaviour of software which is built up over time. Each test specifies a behaviour of the software independent of the amount of code we actually end up using to provide the behaviour. We can therefore correlate development progress with the number of unit tests we have.&lt;/p&gt;  &lt;p&gt;That sounds great, a metric that relates directly to what we want. Unfortunately its not really that simple. Tracking the number of unit tests produced for new features may track the development of those features but not all development activity is adding features. Maintenance is critical concern and when modifying a system we may not end up modifying many tests at all. In some cases we may even remove them as they become irrelevant to the new shape of the application. Clearly implying a developer has negative productivity in this scenario is invalid yet this is what the metric would have us believe. &lt;/p&gt;  &lt;p&gt;Defect resolution is similarly problematic. You may write some tests to prevent the reoccurrence of an issue but the total number of tests added per unit time will be significantly below that experienced with developing new code.&lt;/p&gt;  &lt;p&gt;Additionally there are some types of code that do not readily lend themselves to unit testing such as UI or integration code. Developers are still productive when writing this code yet would not be writing tests.&lt;/p&gt;  &lt;p&gt;To return to my contention that unit tests are “the best low level metric for the development of new features”, I make this claim with an assumption that the metric is used primarily for tracking new development and that it is used in context with other information. In particular it is important to understand that the raw unit test numbers are by themselves potentially misleading. This is due to differing styles of writing tests and differing levels of complexity.&lt;/p&gt;  &lt;p&gt;I personally favour many small tests that each validate a single criteria, with multiple tests for each element of an action that I wish to validate. On raw numbers this would indicate hugely increased productivity over someone who writes larger, heavier tests. I would argue such tests are less effective, but not that they necessarily represent many times lower productivity. Scaling to account for these differences may be necessary and the resultant numbers will need intelligent interpretation. Using the metric on its own would also be open to abuse by less scrupulous developers who could write many unnecessary tests.&lt;/p&gt;  &lt;p&gt;What this ultimately means is that unit test velocity can be an effective guide provided that it may be correctly interpreted. As such it is a good local measure to help teams track their progress. Individual developers may consider their velocity to identify potential problems. This provides team members and direct project management with useful information to track the state of their project and take early corrective action. However given the limitations above it is not a suitable measure against which ultimate performance can be judged.&lt;/p&gt;&lt;img src="http://abstractcode.com/abstractblog/aggbug/170.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/Abstractcode/~4/MLrXDmvwNMo" height="1" width="1"/&gt;</description>
            <dc:creator>Colin David Scott</dc:creator>
            <guid isPermaLink="false">http://abstractcode.com/abstractblog/archive/2009/07/02/170.aspx</guid>
            <pubDate>Thu, 02 Jul 2009 14:09:19 GMT</pubDate>
            <wfw:comment>http://abstractcode.com/abstractblog/comments/170.aspx</wfw:comment>
            <comments>http://abstractcode.com/abstractblog/archive/2009/07/02/170.aspx#feedback</comments>
            <wfw:commentRss>http://abstractcode.com/abstractblog/comments/commentRss/170.aspx</wfw:commentRss>
        <feedburner:origLink>http://abstractcode.com/abstractblog/archive/2009/07/02/170.aspx</feedburner:origLink></item>
        <item>
            <title>Installing Windows 7 on a HP Mini 2140</title>
            <category>Misc</category>
            <link>http://feedproxy.google.com/~r/Abstractcode/~3/eFN5dy6EWhs/169.aspx</link>
            <description>&lt;p&gt;As the 2140 does not contain a DVD drive it’s necessary to do the install off a USB key. The interblag contains a number of articles describing how to accomplish this (for instance &lt;a href="http://www.maximumpc.com/article/howtos/how_to_install_windows_7_beta_a_usb_key"&gt;here&lt;/a&gt;) however to install I found a small modification to be necessary. The USB key I was using is 4Gb which the BIOS turns out to be unable to read. During the partition of the USB key specifying &lt;em&gt;SIZE=3072&lt;/em&gt; enables the BIOS to read it and is sufficient to contain the Windows 7 install files.&lt;/p&gt;&lt;img src="http://abstractcode.com/abstractblog/aggbug/169.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/Abstractcode/~4/eFN5dy6EWhs" height="1" width="1"/&gt;</description>
            <dc:creator>Colin David Scott</dc:creator>
            <guid isPermaLink="false">http://abstractcode.com/abstractblog/archive/2009/06/27/169.aspx</guid>
            <pubDate>Sat, 27 Jun 2009 08:27:27 GMT</pubDate>
            <wfw:comment>http://abstractcode.com/abstractblog/comments/169.aspx</wfw:comment>
            <comments>http://abstractcode.com/abstractblog/archive/2009/06/27/169.aspx#feedback</comments>
            <wfw:commentRss>http://abstractcode.com/abstractblog/comments/commentRss/169.aspx</wfw:commentRss>
        <feedburner:origLink>http://abstractcode.com/abstractblog/archive/2009/06/27/169.aspx</feedburner:origLink></item>
        <item>
            <title>Switching to Windows 7 for communications</title>
            <link>http://feedproxy.google.com/~r/Abstractcode/~3/1q77N9tEu08/168.aspx</link>
            <description>&lt;p&gt;I recently accidentally purchased a HP Mini 2140&lt;sup&gt;*&lt;/sup&gt; onto which I have installed Windows 7. I’ve decided to try using it for all my primary communication; including instant messaging, Skype, email and blogging. So far its working pretty well. My only concerns at the moment are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Windows 7 seems convinced that I have a minimum 2 Live Messenger windows open at any point, one of which is my display picture.&lt;/li&gt;    &lt;li&gt;Live Writer won’t display correctly using my blog’s theme (which works fine on Vista)&lt;/li&gt;    &lt;li&gt;The carry case for the Mini looks rather too much like a purse.&lt;/li&gt;    &lt;li&gt;The doubling of home/end/page up/page down on the cursor keys will take some getting used to.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Windows 7 itself works very well. I’m one of the (apparently few) people who prefer Vista to XP (on decent hardware) and 7 is an improvement again. Very fast on what is a fairly low spec machine. &lt;/p&gt;  &lt;p style="font-size: small"&gt;&lt;sup&gt;*&lt;/sup&gt; By accidentally driving to the store, accidentally asking for one, accidentally paying for it and accidentally driving off with it.&lt;/p&gt;&lt;img src="http://abstractcode.com/abstractblog/aggbug/168.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/Abstractcode/~4/1q77N9tEu08" height="1" width="1"/&gt;</description>
            <dc:creator>Colin David Scott</dc:creator>
            <guid isPermaLink="false">http://abstractcode.com/abstractblog/archive/2009/06/27/168.aspx</guid>
            <pubDate>Sat, 27 Jun 2009 08:21:03 GMT</pubDate>
            <wfw:comment>http://abstractcode.com/abstractblog/comments/168.aspx</wfw:comment>
            <comments>http://abstractcode.com/abstractblog/archive/2009/06/27/168.aspx#feedback</comments>
            <wfw:commentRss>http://abstractcode.com/abstractblog/comments/commentRss/168.aspx</wfw:commentRss>
        <feedburner:origLink>http://abstractcode.com/abstractblog/archive/2009/06/27/168.aspx</feedburner:origLink></item>
        <item>
            <title>On the building of frameworks</title>
            <category>Development Practices</category>
            <link>http://feedproxy.google.com/~r/Abstractcode/~3/WpGe2EsHEbI/167.aspx</link>
            <description>&lt;p&gt;Over the years I’ve written or maintained a number of frameworks for a variety of projects. From this I have come to the following conclusions:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Unless no third party framework exists to cover your scenario you are in almost all scenarios better off using an existing framework than writing your own&lt;/li&gt;    &lt;li&gt;When building an application the most effective framework code is that used to apply existing third party frameworks to the application. This will often consist of code to make multiple frameworks play nicely together.&lt;/li&gt;    &lt;li&gt;Building a reusable framework is difficult. Build the system to meet the needs of your own application and consider making it more generically applicable only as necessary.&lt;/li&gt;    &lt;li&gt;Concepts and design patterns are of much greater utility than framework code.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Organisations will sometimes build their own frameworks (something I’ve been guilty of in the past). It is my contention that an organisation will get more benefit from internal knowledge transfer and training on existing frameworks than will generally be returned from a similar effort to construct them. This may not hold for bleeding edge practitioners where existing frameworks may be incomplete, buggy or non-existent. However when a practice or technology becomes more mainstream an organisation should consider whether their own custom systems continue to deliver value in excess of that provided by now (hopefully more common, stable and feature rich) third party options.&lt;/p&gt;&lt;img src="http://abstractcode.com/abstractblog/aggbug/167.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/Abstractcode/~4/WpGe2EsHEbI" height="1" width="1"/&gt;</description>
            <dc:creator>Colin David Scott</dc:creator>
            <guid isPermaLink="false">http://abstractcode.com/abstractblog/archive/2009/06/27/167.aspx</guid>
            <pubDate>Sat, 27 Jun 2009 08:05:20 GMT</pubDate>
            <wfw:comment>http://abstractcode.com/abstractblog/comments/167.aspx</wfw:comment>
            <comments>http://abstractcode.com/abstractblog/archive/2009/06/27/167.aspx#feedback</comments>
            <wfw:commentRss>http://abstractcode.com/abstractblog/comments/commentRss/167.aspx</wfw:commentRss>
        <feedburner:origLink>http://abstractcode.com/abstractblog/archive/2009/06/27/167.aspx</feedburner:origLink></item>
        <item>
            <title>NDepend tip: Exclude that which the code generator hath wrought</title>
            <category>C#</category>
            <category>Development Tools</category>
            <link>http://feedproxy.google.com/~r/Abstractcode/~3/rODcOQl3Vq4/166.aspx</link>
            <description>&lt;p&gt;I’ve been running &lt;a href="http://www.ndepend.com/"&gt;NDepend&lt;/a&gt; over some of my projects recently and have noticed a tendency for it to pick up on things in code generated by Visual Studio (which admittedly is of highly variable quality). I’m not going to write my own version of the generated code but I would like to clear out the noise. You can do so by editing the CQL and adding something like:&lt;/p&gt; &lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;     &lt;p&gt;AND&lt;/p&gt;   &lt;/font&gt;&lt;font color="#000000" size="2"&gt; !&lt;/font&gt;&lt;font color="#000064" size="2"&gt;&lt;font color="#000064" size="2"&gt;FullNameLike&lt;/font&gt;&lt;/font&gt;&lt;font color="#000000" size="2"&gt; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;".*Properties.Resources.*"&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;  &lt;p&gt;This criteria excludes anything that matches the common pattern of the standard resource files produced by Visual Studio. You can substitute your own regular expression (just be careful not to exclude your own types) .&lt;/p&gt;  &lt;p&gt;This is mainly a post so I don’t have to work out how to do this again. Hopefully someone will either point out where the option to exclude this generated code is in NDepend or add such a feature to the next version.&lt;/p&gt;&lt;img src="http://abstractcode.com/abstractblog/aggbug/166.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/Abstractcode/~4/rODcOQl3Vq4" height="1" width="1"/&gt;</description>
            <dc:creator>Colin David Scott</dc:creator>
            <guid isPermaLink="false">http://abstractcode.com/abstractblog/archive/2009/06/20/166.aspx</guid>
            <pubDate>Sat, 20 Jun 2009 14:14:47 GMT</pubDate>
            <wfw:comment>http://abstractcode.com/abstractblog/comments/166.aspx</wfw:comment>
            <comments>http://abstractcode.com/abstractblog/archive/2009/06/20/166.aspx#feedback</comments>
            <wfw:commentRss>http://abstractcode.com/abstractblog/comments/commentRss/166.aspx</wfw:commentRss>
        <feedburner:origLink>http://abstractcode.com/abstractblog/archive/2009/06/20/166.aspx</feedburner:origLink></item>
        <item>
            <title>Today&amp;rsquo;s Simple Question: Should I use the GAC?</title>
            <category>Development Practices</category>
            <link>http://feedproxy.google.com/~r/Abstractcode/~3/MuRADX1Jpzo/165.aspx</link>
            <description>&lt;p&gt;No.&lt;/p&gt;  &lt;p&gt;Look around you. Are you working at Microsoft? If so, are you working on .NET itself? Congratulations, your assembly may actually be justified going into the GAC. If you answered No to either of these questions it’s highly unlikely that your assembly is going to be sufficiently widely used that software using it will assume its presence rather than include it with its own binaries.&lt;/p&gt;  &lt;p&gt;The benefits of installing into the GAC in the general case are relatively small and doing so incurs additional complexity. It also prevents scenarios such as allowing your application to be dropped into a directory and run without installation. Just say no.&lt;/p&gt;&lt;img src="http://abstractcode.com/abstractblog/aggbug/165.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/Abstractcode/~4/MuRADX1Jpzo" height="1" width="1"/&gt;</description>
            <dc:creator>Colin David Scott</dc:creator>
            <guid isPermaLink="false">http://abstractcode.com/abstractblog/archive/2009/06/16/165.aspx</guid>
            <pubDate>Tue, 16 Jun 2009 14:40:05 GMT</pubDate>
            <wfw:comment>http://abstractcode.com/abstractblog/comments/165.aspx</wfw:comment>
            <comments>http://abstractcode.com/abstractblog/archive/2009/06/16/165.aspx#feedback</comments>
            <wfw:commentRss>http://abstractcode.com/abstractblog/comments/commentRss/165.aspx</wfw:commentRss>
        <feedburner:origLink>http://abstractcode.com/abstractblog/archive/2009/06/16/165.aspx</feedburner:origLink></item>
        <item>
            <title>My current development platform and tools of choice</title>
            <category>Development Tools</category>
            <category>Visual Studio</category>
            <category>Resharper</category>
            <link>http://feedproxy.google.com/~r/Abstractcode/~3/Re9on3jij80/164.aspx</link>
            <description>&lt;p&gt;Effective software development is all about leveraging the effort of others so that you can focus the majority of effort on the problem your system is to address. The following are the frameworks and tools that I choose to use (as is appropriate) when I get to decide what goes into a system.&lt;/p&gt;  &lt;p&gt;I’m not going to try to enumerate all the features, advantages and disadvantages of my choices. I’m always looking for additional or improved options for my list so make any suggestions in the comments below.&lt;/p&gt;  &lt;h4&gt;Frameworks&lt;/h4&gt;  &lt;h5&gt;NHibernate&lt;/h5&gt;  &lt;p&gt;Although I’ll acknowledge it has a near vertical learning curve in places nothing else I’ve seen comes close to the power and feature set of NHibernate. I’m currently working on a project with LINQ-to-SQL and I miss the additional features a lot (I do like LINQ though, but only for a certain query complexity).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://nhforge.org/"&gt;http://nhforge.org/&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;StructureMap&lt;/h5&gt;  &lt;p&gt;Currently my DI framework of choice. I’m particularly fond of the Registry DSL and Auto Registration and Type Scanning, which is so much more effective than long and difficult to maintain XML files. These features aren’t unique to StructureMap but it provides a simple and effective solution that works well in the scenarios I’ve encountered.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://structuremap.sourceforge.net/"&gt;http://structuremap.sourceforge.net/&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;Tools&lt;/h4&gt;  &lt;h5&gt;Integrated Development Environment&lt;/h5&gt;  &lt;h6&gt;Visual Studio 2008&lt;/h6&gt;  &lt;p&gt;Visual Studio is a relatively solid IDE (at least as of Visual Studio 2008, 2005 had some significant quality issues). By itself it’s fairly average; the code navigation options are limited and the refactoring support so weak it’d be preferable not to have it at all. Its redeeming virtue is that it supports extensions and is sufficiently popular that a great many exist. Plug in in a few extensions and what was an average environment becomes something highly productive.&lt;/p&gt;  &lt;p&gt;I use Team Edition for Software Developers. Of the additional features this provides over time I’ve reduced my usage to Team Coverage only (and that used through an extension). Unless you have an unlimited budget, go for the Professional edition.&lt;/p&gt;  &lt;h6&gt;ReSharper 4.5&lt;/h6&gt;  &lt;p&gt;If you add no other extension to Visual Studio, add ReSharper. The additional options it gives to navigate your code are alone worth the price. On top of this it has effective refactoring, improvements to Intellisense, code analysis, improved templates, code cleanup, editing enhancements and more. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jetbrains.com/resharper/"&gt;http://www.jetbrains.com/resharper/&lt;/a&gt;&lt;/p&gt;  &lt;h6&gt;TestDriven.Net&lt;/h6&gt;  &lt;p&gt;ReSharper provides a test runner which is superior to that in Visual Studio. TestDriven.Net is a Visual Studio extension superior to them both. It supports a wide variety of test frameworks and integrates with a number of coverage tools. I’m particularly impressed with how it integrates Team Coverage with non-Microsoft unit test frameworks.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.testdriven.net/"&gt;http://www.testdriven.net/&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;Utilities&lt;/h5&gt;  &lt;h6&gt;Beyond Compare&lt;/h6&gt;  &lt;p&gt;My comparison tool of choice. Powerful, easy to use and excellent value. Also has amusing price breaks where an additional licence seems to have a large negative cost (try changing from 99 to 100 licences). Works with every source control system I’ve used.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.scootersoftware.com/"&gt;http://www.scootersoftware.com/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Static Code Analysis&lt;/p&gt;  &lt;h6&gt;FxCop&lt;/h6&gt;  &lt;p&gt;This is the standalone version of the static code analysis tool built into Visual Studio Team Edition for Software Developers and Team Suite. When working with Continuous Integration I find the standalone version to be easier to work with. It’s important to remember that as a static analysis tool it’s not always right and intelligence is required in interpreting its results. Despite this its a valuable tool for finding potential issues and ensuring the quality of your code.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb429476.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb429476.aspx&lt;/a&gt;&lt;/p&gt;  &lt;h6&gt;NDepend&lt;/h6&gt;  &lt;p&gt;For analysing code structure and examining how code fits together I turn to NDepend.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.ndepend.com/"&gt;http://www.ndepend.com/&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;Continuous Integration&lt;/h5&gt;  &lt;h6&gt;TeamCity&lt;/h6&gt;  &lt;p&gt;It’s hard to go past TeamCity. It’s easy to install and configure and supports a wide variety of build agents. It supports a variety of build tools for multiple platforms as well as many source control systems. Plus it has a free professional edition that supports up to 20 build configurations. I’m particularly fond of the ability to have a dependent build that automatically runs FxCop over the output of my primary build.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.jetbrains.com/teamcity/"&gt;http://www.jetbrains.com/teamcity/&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;Unit Testing&lt;/h5&gt;  &lt;h6&gt;Gallio and MbUnit&lt;/h6&gt;  &lt;p&gt;I’ve used (and abused) a number of unit testing frameworks, including NUnit and MSTest. MbUnit is my current preference due to effective design and a powerful feature set. When combined with Gallio it provides an effective and easily automatable unit testing solution. It also includes integration with my preferred team runner and CI server (TestDriven.Net and TeamCity).&lt;/p&gt;  &lt;h5&gt;Source Control&lt;/h5&gt;  &lt;p&gt;My current source control preference can be best expressed as “Not Visual Source Safe”. I’ve used Team Foundation Server and Subversion on projects with a fair amount of success, although I consider neither ideal. I’m also considering Mercurial although tool support may be an issue. Really the important thing here is to have a solid source control system and to ensure your team uses it well.&lt;/p&gt;&lt;img src="http://abstractcode.com/abstractblog/aggbug/164.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/Abstractcode/~4/Re9on3jij80" height="1" width="1"/&gt;</description>
            <dc:creator>Colin David Scott</dc:creator>
            <guid isPermaLink="false">http://abstractcode.com/abstractblog/archive/2009/06/07/164.aspx</guid>
            <pubDate>Sun, 07 Jun 2009 06:08:10 GMT</pubDate>
            <wfw:comment>http://abstractcode.com/abstractblog/comments/164.aspx</wfw:comment>
            <comments>http://abstractcode.com/abstractblog/archive/2009/06/07/164.aspx#feedback</comments>
            <wfw:commentRss>http://abstractcode.com/abstractblog/comments/commentRss/164.aspx</wfw:commentRss>
        <feedburner:origLink>http://abstractcode.com/abstractblog/archive/2009/06/07/164.aspx</feedburner:origLink></item>
        <item>
            <title>Naming and Redundancy</title>
            <category>Development Tools</category>
            <category>Development Practices</category>
            <link>http://feedproxy.google.com/~r/Abstractcode/~3/A0XiARxr65c/163.aspx</link>
            <description>&lt;p&gt;I’ve just encountered one of those wonderful bugs caused by Windows path length limits. In this case a large part of the problem was a file with a name over 100 characters long. Most of this name duplicated information already known due to its context, such as the namespace it belonged to. When moving between environments a longer base path in the new environment resulted in an over-long file path and hence breakage in what was previously a working codebase. The base path in the new environment was not excessively long, the fault here is purely with a poorly chosen filename.&lt;/p&gt;  &lt;p&gt;Another area I see this is naming projects within Visual Studio solutions. I’ve always favoured short(ish) names comprised or two or three words describing the purpose of the project. This conveys some relevant meaning and can be kept reasonably concise. I’ve also worked on systems where the project name matches the base namespace of the generated assembly. I find a number of problems with this approach:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;This immediately introduces duplicate information. Generally the first elements of a namespace are the client and/or project. This is almost always identifiable by the solution in which the project resides. Adding it to every project adds no value.&lt;/li&gt;    &lt;li&gt;The more relevant component to a developer is the specific project but this information is given less precedence than the common (irrelevant) portions. Depending on tool window size it may be obscured.&lt;/li&gt;    &lt;li&gt;Not all projects contain a single root namespace. (Such projects should be minimised but are not always avoidable).&lt;/li&gt;    &lt;li&gt;Adding the redundant information wastes character from a sometimes limiting 260 character maximum. This increases the risk that moving to a different environment (say a development machine to a build server) will fail due to path lengths.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I’ve mostly encountered this problem with build servers, but it can be a problem even if you never chose to automate your build process (note: you should automate your build process). In the past I’ve had issues caused by an installer generator that ran out of path length when building its own temporary directory structure while I was attempting to build an installer for a relatively standard system that had some excessive file lengths.&lt;/p&gt;  &lt;p&gt;In an ideal world we could assign names as long as we’d like and everything would just work. Windows is not this ideal world and we need to deal with its reality. Additionally the kind of redundancy I’ve just discussed does nothing to convey useful information and may therefore be considered overhead. Pruning it to size is therefore a win in multiple ways.&lt;/p&gt;&lt;img src="http://abstractcode.com/abstractblog/aggbug/163.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/Abstractcode/~4/A0XiARxr65c" height="1" width="1"/&gt;</description>
            <dc:creator>Colin David Scott</dc:creator>
            <guid isPermaLink="false">http://abstractcode.com/abstractblog/archive/2009/06/02/163.aspx</guid>
            <pubDate>Tue, 02 Jun 2009 14:15:31 GMT</pubDate>
            <wfw:comment>http://abstractcode.com/abstractblog/comments/163.aspx</wfw:comment>
            <comments>http://abstractcode.com/abstractblog/archive/2009/06/02/163.aspx#feedback</comments>
            <wfw:commentRss>http://abstractcode.com/abstractblog/comments/commentRss/163.aspx</wfw:commentRss>
        <feedburner:origLink>http://abstractcode.com/abstractblog/archive/2009/06/02/163.aspx</feedburner:origLink></item>
    </channel>
</rss>
