<?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:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" 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:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" version="2.0">
  <channel>
    <title>Matt Lowrance</title>
    <description />
    <link>http://www.matthewlowrance.com/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 1.6.1.0</generator>
    <language>en-GB</language>
    <blogChannel:blogRoll>http://www.matthewlowrance.com/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.dotnetblogengine.net/syndication.axd</blogChannel:blink>
    <dc:creator>Matt Lowrance</dc:creator>
    <dc:title>Matt Lowrance</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/MattLowrance" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="mattlowrance" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <title>WPF DataBinding with slow loading ItemSource</title>
      <description>&lt;p&gt;I discovered an interesting WPF databinding issue recently.&amp;#160; Say we have this simple example WPF form for editing a customer:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/WPF-DataBinding-with-slow-loading-ItemSo_121D1/image.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/WPF-DataBinding-with-slow-loading-ItemSo_121D1/image_thumb.png" width="244" height="185" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Label &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;First Name:&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Column&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot; /&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Column&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;MinWidth&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;125&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;SelectedCustomer&lt;/span&gt;&lt;span style="color: blue"&gt;.FirstName}&amp;quot;/&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Label &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Last Name:&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Column&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot; /&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Column&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;MinWidth&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;125&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;SelectedCustomer&lt;/span&gt;&lt;span style="color: blue"&gt;.LastName}&amp;quot;/&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Label &lt;/span&gt;&lt;span style="color: red"&gt;Content&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Contact Flag:&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;2&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Column&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;0&amp;quot; /&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ComboBox &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;2&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Column&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;1&amp;quot;
     &lt;/span&gt;&lt;span style="color: red"&gt;Margin&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;5&amp;quot;
     &lt;/span&gt;&lt;span style="color: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;ContactFlags&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot;
     &lt;/span&gt;&lt;span style="color: red"&gt;DisplayMemberPath&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Value&amp;quot;
     &lt;/span&gt;&lt;span style="color: red"&gt;SelectedValuePath&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Key&amp;quot;
     &lt;/span&gt;&lt;span style="color: red"&gt;SelectedValue&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;SelectedCustomer&lt;/span&gt;&lt;span style="color: blue"&gt;.ContactFlag}&amp;quot;
        /&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;In particular we are interested in the Contact Flag combobox.&amp;#160; We have a viewmodel with a SelectedCustomer (which for the sake of this post is just being instantiated in the constructor, but would probably come from a DB, etc), however the Contact Flag comes from a list of key value pairs, being a code and a description. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/WPF-DataBinding-with-slow-loading-ItemSo_121D1/image_3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/WPF-DataBinding-with-slow-loading-ItemSo_121D1/image_thumb_3.png" width="383" height="89" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Say for example though, that the list of contact flags comes from a slow source such as a web service.&amp;#160; As you can see above the databinding fails.&amp;#160; Seems obvious, the list of items hasn’t loaded, so the item isn’t able to display in the list.&amp;#160; However the comboxbox has now pushed a null value back to the customer:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/WPF-DataBinding-with-slow-loading-ItemSo_121D1/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/WPF-DataBinding-with-slow-loading-ItemSo_121D1/image_thumb_4.png" width="405" height="283" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Double Whammy!&amp;#160; Not only is the item not bound, but if this customer had a previous value for Contact Flag, it has now been wiped out and if a user hits the OK button to save, it would be lost for good.&lt;/p&gt;

&lt;p&gt;So in our viewmodel instead of doing this:&lt;/p&gt;

&lt;pre class="code"&gt;SelectedCustomer = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Customer
              &lt;/span&gt;{
                  FirstName = &lt;span style="color: #a31515"&gt;&amp;quot;John&amp;quot;&lt;/span&gt;,
                  LastName = &lt;span style="color: #a31515"&gt;&amp;quot;Smith&amp;quot;&lt;/span&gt;,
                  ContactFlag = &lt;span style="color: #a31515"&gt;&amp;quot;e&amp;quot;
              &lt;/span&gt;};

              &lt;span style="color: #2b91af"&gt;FlagService &lt;/span&gt;fs = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FlagService&lt;/span&gt;();
              fs.GetContactFlagsAsync(OnFlagsReceived);&lt;/pre&gt;

&lt;p&gt;we would want to save off the customer in a private variable and then set it once the callback for the list (OnFlagsReceived) has happened.&amp;#160; (Another option would be to simply wait to retrieve the customer until the callback if possible).&lt;/p&gt;

&lt;p&gt;By doing so we then set the binding only after the values in the combobox exist and get the outcome we want:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;OnFlagsReceived(&lt;span style="color: #2b91af"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;,&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; flags)
      {
          ContactFlags.AddRange(flags);

          SelectedCustomer = _customerToSave;
      }&lt;/pre&gt;

&lt;p&gt;A simple change, but an important difference.&amp;#160; Not only did we correct the binding issue, but we also kept the domain object from accidentally getting updated and saved some poor unsuspecting end user from accidentally calling a difficult tech savvy customer who prefers email. &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://www.matthewlowrance.com/Images/blog/WPF-DataBinding-with-slow-loading-ItemSo_121D1/wlEmoticon-winkingsmile.png" /&gt;&lt;/p&gt;

&lt;p&gt;You can download the sample code for this project &lt;a href="http://www.matthewlowrance.com/samplecode/ComboboxBinding.zip"&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
      <link>http://www.matthewlowrance.com/post/2011/07/12/WPF-DataBinding-with-slow-loading-ItemSource.aspx</link>
      <author>matt</author>
      <comments>http://www.matthewlowrance.com/post/2011/07/12/WPF-DataBinding-with-slow-loading-ItemSource.aspx#comment</comments>
      <guid>http://www.matthewlowrance.com/post.aspx?id=25c51b34-532a-459d-a313-9dd171a565e8</guid>
      <pubDate>Tue, 12 Jul 2011 21:38:43 -0500</pubDate>
      <dc:publisher>matt</dc:publisher>
      <pingback:server>http://www.matthewlowrance.com/pingback.axd</pingback:server>
      <pingback:target>http://www.matthewlowrance.com/post.aspx?id=25c51b34-532a-459d-a313-9dd171a565e8</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.matthewlowrance.com/trackback.axd?id=25c51b34-532a-459d-a313-9dd171a565e8</trackback:ping>
      <wfw:comment>http://www.matthewlowrance.com/post/2011/07/12/WPF-DataBinding-with-slow-loading-ItemSource.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.matthewlowrance.com/syndication.axd?post=25c51b34-532a-459d-a313-9dd171a565e8</wfw:commentRss>
    </item>
    <item>
      <title>MVVM and closing a View from the ViewModel</title>
      <description>&lt;p&gt;One of the &lt;a href="http://stackoverflow.com/questions/1484233/wpf-mvvm-closing-a-view-from-viewmodel"&gt;common questions&lt;/a&gt; when working with MVVM is how do you close a view from the viewmodel?&lt;/p&gt;  &lt;p&gt;The answer is usually send a message to the view from the viewmodel, but this ends up with an ugly message registration in the view’s code behind.&amp;#160; For Blend users, custom behaviors are a great way to avoid this ugliness.&amp;#160; (I think all you really need to make this work is the System.Windows.Interactivity.dll assembly which I’m pretty sure is in the &lt;a href="http://www.softpedia.com/get/Programming/SDK-DDK/Expression-Blend-SDK.shtml"&gt;Blend SDK&lt;/a&gt;, but having actual Blend will make attaching behaviors, etc. a lot easier).&lt;/p&gt;  &lt;p&gt;In this example I will be using MVVM Light and its associated Messenger/Message classes, but the same concepts should work in your favorite MVVM framework as well.&lt;/p&gt;  &lt;p&gt;First create your custom behavior, which registers for the message in OnAttached:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CloseWindowBehavior &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;Behavior&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Window&lt;/span&gt;&amp;gt;
    {

        &lt;span style="color: blue"&gt;protected override void &lt;/span&gt;OnAttached()
        {
            &lt;span style="color: blue"&gt;base&lt;/span&gt;.OnAttached();

            &lt;span style="color: #2b91af"&gt;Messenger&lt;/span&gt;.Default.Register&amp;lt;&lt;span style="color: #2b91af"&gt;CloseWindowMessage&lt;/span&gt;&amp;gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.AssociatedObject,
                   m =&amp;gt;
                   {
                        &lt;span style="color: blue"&gt;this&lt;/span&gt;.AssociatedObject.DialogResult = m.Content;
                        &lt;span style="color: blue"&gt;this&lt;/span&gt;.AssociatedObject.Close();
                   }
                );

        }

    }&lt;/pre&gt;

&lt;p&gt;Note that I have created a custom MVVM Light message type CloseWindowMessage:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CloseWindowMessage &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;GenericMessage&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;bool&lt;/span&gt;?&amp;gt; 
   {

       &lt;span style="color: blue"&gt;public &lt;/span&gt;CloseWindowMessage(&lt;span style="color: blue"&gt;bool&lt;/span&gt;? dialogResult)
           :&lt;span style="color: blue"&gt;base &lt;/span&gt;(dialogResult) { }
       
       &lt;span style="color: blue"&gt;public &lt;/span&gt;CloseWindowMessage(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: blue"&gt;bool&lt;/span&gt;? dialogResult)
           :&lt;span style="color: blue"&gt;base&lt;/span&gt;(sender,dialogResult) { }
       
       &lt;span style="color: blue"&gt;public &lt;/span&gt;CloseWindowMessage(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: blue"&gt;object &lt;/span&gt;target, &lt;span style="color: blue"&gt;bool&lt;/span&gt;? dialogResult)
           : &lt;span style="color: blue"&gt;base&lt;/span&gt;(sender, target, dialogResult) { }

   }&lt;/pre&gt;

&lt;p&gt;I prefer this since it allows me to send along the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.window.dialogresult.aspx"&gt;DialogResult&lt;/a&gt;, however you could use the normal &lt;a href="http://www.galasoft.ch/mvvm/getstarted/"&gt;NotificationMessage&lt;/a&gt; (Sorry not the best link, but currently all I can find) with a “CloseWindow” message if you aren’t concerned with that.&lt;/p&gt;

&lt;p&gt;Now if you attach this behavior to your window, then in your viewmodel all you have to do is:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;Messenger&lt;/span&gt;.Default.Send&amp;lt;&lt;span style="color: #2b91af"&gt;CloseWindowMessage&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;MainWindow&lt;/span&gt;&amp;gt;(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CloseWindowMessage&lt;/span&gt;(&lt;span style="color: blue"&gt;true&lt;/span&gt;));&lt;/pre&gt;

&lt;p&gt;Note, be sure you specify the target when using this method.&amp;#160; If all your windows have this behavior and you simply blast this message, you will be in for a surprise. ;)&lt;/p&gt;

&lt;p&gt;Bonus coverage:&lt;/p&gt;

&lt;p&gt;For those using MVVM Light, here is a behavior for its DialogMessage:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DialogMessageBehavior &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;Behavior&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Window&lt;/span&gt;&amp;gt;
  {

      &lt;span style="color: blue"&gt;protected override void &lt;/span&gt;OnAttached()
      {
          &lt;span style="color: blue"&gt;base&lt;/span&gt;.OnAttached();

          &lt;span style="color: #2b91af"&gt;Messenger&lt;/span&gt;.Default.Register&amp;lt;&lt;span style="color: #2b91af"&gt;DialogMessage&lt;/span&gt;&amp;gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.AssociatedObject,
              (dm) =&amp;gt; &lt;span style="color: #2b91af"&gt;MessageBox&lt;/span&gt;.Show(&lt;span style="color: blue"&gt;this&lt;/span&gt;.AssociatedObject, dm.Content, dm.Caption, dm.Button, dm.Icon));
              

      }

  }&lt;/pre&gt;</description>
      <link>http://www.matthewlowrance.com/post/2011/02/17/MVVM-and-closing-a-View-from-the-ViewModel.aspx</link>
      <author>matt</author>
      <comments>http://www.matthewlowrance.com/post/2011/02/17/MVVM-and-closing-a-View-from-the-ViewModel.aspx#comment</comments>
      <guid>http://www.matthewlowrance.com/post.aspx?id=e95c56b3-9f25-472a-8ba7-ef6d695d4372</guid>
      <pubDate>Thu, 17 Feb 2011 20:35:29 -0500</pubDate>
      <category>WPF</category>
      <dc:publisher>matt</dc:publisher>
      <pingback:server>http://www.matthewlowrance.com/pingback.axd</pingback:server>
      <pingback:target>http://www.matthewlowrance.com/post.aspx?id=e95c56b3-9f25-472a-8ba7-ef6d695d4372</pingback:target>
      <slash:comments>5</slash:comments>
      <trackback:ping>http://www.matthewlowrance.com/trackback.axd?id=e95c56b3-9f25-472a-8ba7-ef6d695d4372</trackback:ping>
      <wfw:comment>http://www.matthewlowrance.com/post/2011/02/17/MVVM-and-closing-a-View-from-the-ViewModel.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.matthewlowrance.com/syndication.axd?post=e95c56b3-9f25-472a-8ba7-ef6d695d4372</wfw:commentRss>
    </item>
    <item>
      <title>Custom Schema and ICustomTypeDescriptor</title>
      <description>&lt;p&gt;In our project we support custom schema on our tables.&amp;#160; We support both extending the domain tables and allow the creation of completely ad hoc tables.&amp;#160; Currently in the project to display a list of these records we use the custom schema framework which returns a wrapper object and usually then build a datatable on the client side out of the results and bind a grid to that.&amp;#160; Recently I discover &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.icustomtypedescriptor.aspx"&gt;ICustomTypeDescriptor&lt;/a&gt; which allows an object to provide its own type information.&lt;/p&gt;  &lt;p&gt;The default databinding implementation uses reflection to get the properties and values for those properties from an object.&amp;#160; The ICustomTypeDescriptor interface allows an object to step in and provide this information dynamically.&lt;/p&gt;  &lt;p&gt;So say for example I have a custom “ad hoc” table (I use quotes here because in the case of this post its actually just the Employee table from the Chinook database, but we’ll suspend disbelief and say its ad hoc.&amp;#160; &lt;/p&gt;  &lt;p&gt;I then have a custom field schema implementation, again for the sake of the post I have a very naïve implementation that just reads a datareader into a dictionary.&amp;#160; Obviously a real implementation would probably need metadata, etc., for the post I’m keeping it simple.&lt;/p&gt;  &lt;p&gt;So I run a simple select statement and end up with a list of CustomSchemaTableRecord objects:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;CustomSchemaTableRecord&lt;/span&gt;&amp;gt; records = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;CustomSchemaTableRecord&lt;/span&gt;&amp;gt;();

           &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;SqlConnection &lt;/span&gt;connection = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlConnection&lt;/span&gt;(Properties.&lt;span style="color: #2b91af"&gt;Settings&lt;/span&gt;.Default.ConnectionString))
           {
               &lt;span style="color: #2b91af"&gt;SqlCommand &lt;/span&gt;command = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlCommand&lt;/span&gt;(
                 &lt;span style="color: #a31515"&gt;&amp;quot;SELECT * FROM Employee&amp;quot;&lt;/span&gt;,
                 connection);

               connection.Open();

               &lt;span style="color: #2b91af"&gt;SqlDataReader &lt;/span&gt;reader = command.ExecuteReader();

               &lt;span style="color: blue"&gt;while &lt;/span&gt;(reader.Read())
               {
                   records.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CustomSchemaTableRecord&lt;/span&gt;(reader));
               }

               reader.Close();
           }

           dataGridView1.DataSource = records;&lt;/pre&gt;

&lt;p&gt;Which as you can see really is just a dictionary internally (again naïve implementation for simplicity):&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/Custom-Schema-and_11C16/image.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/Custom-Schema-and_11C16/image_thumb.png" width="628" height="304" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However when I databind these records to the datagrid in the last line I get:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/Custom-Schema-and_11C16/image_3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/Custom-Schema-and_11C16/image_thumb_3.png" width="640" height="345" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nothing…great post right?&lt;/p&gt;

&lt;p&gt;Why do we get nothing?&amp;#160; CustomSchemaTableRecord has no properties.&amp;#160; In fact it has basically no external interface at all.&amp;#160; All it has is a constructor and a private dictionary to store its values in.&amp;#160; No external interface means nothing returned to reflection and so nothing to databind to.&lt;/p&gt;

&lt;p&gt;But, if we implement ICustomTypeDescriptor on CustomSchemaTableRecord (this is snipped to just the interesting parts, see the link above to the MSDN documentation to see all the required methods):&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;#region &lt;/span&gt;ICustomTypeDescriptor Members


      &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PropertyDescriptorCollection &lt;/span&gt;GetProperties(&lt;span style="color: #2b91af"&gt;Attribute&lt;/span&gt;[] attributes)
      {
          &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;PropertyDescriptor&lt;/span&gt;&amp;gt; properties = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;PropertyDescriptor&lt;/span&gt;&amp;gt;();

          &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;kvp &lt;span style="color: blue"&gt;in &lt;/span&gt;values)
          {

              properties.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CustomSchemaTypePropertyDescriptor&lt;/span&gt;(kvp.Key, kvp.Value.GetType()));

          }

          &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PropertyDescriptorCollection&lt;/span&gt;(properties.ToArray());

      }&lt;/pre&gt;

&lt;p&gt;Note: This code is not checking for nulls, etc. its probably not safe to copy and paste directly…&lt;/p&gt;

&lt;p&gt;Here I return a &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.propertydescriptorcollection.aspx"&gt;PropertyDescriptorCollection&lt;/a&gt;.&amp;#160; &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.propertydescriptor.aspx"&gt;PropertyDescriptor&lt;/a&gt; is an abstract class that I implemented with my CustomSchemaTypePropertyDescriptor class (again snipped for brevity, see link above etc., etc.):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CustomSchemaTypePropertyDescriptor &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;PropertyDescriptor
   &lt;/span&gt;{

       &lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;type;

       &lt;span style="color: blue"&gt;public &lt;/span&gt;CustomSchemaTypePropertyDescriptor(&lt;span style="color: blue"&gt;string &lt;/span&gt;key, &lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;type)
           :&lt;span style="color: blue"&gt;base&lt;/span&gt;(key,&lt;span style="color: blue"&gt;null&lt;/span&gt;)
       {
           &lt;span style="color: blue"&gt;this&lt;/span&gt;.type = type;
       }


       &lt;span style="color: blue"&gt;public override object &lt;/span&gt;GetValue(&lt;span style="color: blue"&gt;object &lt;/span&gt;component)
       {
           &lt;span style="color: #2b91af"&gt;CustomSchemaTableRecord &lt;/span&gt;record = component &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CustomSchemaTableRecord&lt;/span&gt;;

           &lt;span style="color: blue"&gt;return &lt;/span&gt;record.GetValueForKey(&lt;span style="color: blue"&gt;this&lt;/span&gt;.Name);
       }
         &lt;/pre&gt;

&lt;p&gt;Again here null checks, etc…&lt;/p&gt;

&lt;p&gt;For the keen eyed, you’ll notice when GetValue is called I am calling the GetValueForKey method on my CustomSchemaTableRecord, which is simply this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public object &lt;/span&gt;GetValueForKey(&lt;span style="color: blue"&gt;string &lt;/span&gt;key)
      {
          &lt;span style="color: blue"&gt;return &lt;/span&gt;values[key];
      }&lt;/pre&gt;

&lt;p&gt;Now that I have implemented ICustomTypeDescriptor to provide my list of dynamic properties and created my custom PropertyDescriptor to provide the value back to the databinding when asked, when we rerun the app we now get:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/Custom-Schema-and_11C16/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/Custom-Schema-and_11C16/image_thumb_4.png" width="624" height="342" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since this implementation just works against my ad hoc custom field framework, I can simply change my selection criteria to say “SELECT * FROM Customer” and I get:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/Custom-Schema-and_11C16/image_5.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/Custom-Schema-and_11C16/image_thumb_5.png" width="626" height="313" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Perfect databinding for an table with dynamic schema.&lt;/p&gt;

&lt;p&gt;A little snag I ran into along the way was that databinding (or maybe just the grid itself) seems to be picky about the list of items, it must be a list that implements ITypedList.&amp;#160; At first I was just using an array and it did not work.&amp;#160; However once I switched to a generic List&amp;lt;T&amp;gt;, all was right.&lt;/p&gt;

&lt;p&gt;In our project we seldom databind directly to the domain objects that support custom schema.&amp;#160; However, this new implementation will decrease the amount of code in the ad hoc table implementation.&amp;#160; No need any longer to build ugly in memory datatables to databind to.&amp;#160; Just take the custom schema records that are returned out of the business logic and implement ICustomTypeDescriptor directly on them, or write a wrapper to implement it and&amp;#160; hand them off as the datasource, that simple.&lt;/p&gt;</description>
      <link>http://www.matthewlowrance.com/post/2010/12/03/Custom-Schema-and-ICustomTypeDescriptor.aspx</link>
      <author>matt</author>
      <comments>http://www.matthewlowrance.com/post/2010/12/03/Custom-Schema-and-ICustomTypeDescriptor.aspx#comment</comments>
      <guid>http://www.matthewlowrance.com/post.aspx?id=1a105f94-fa83-4ef0-8d38-64ae828a5cf9</guid>
      <pubDate>Fri, 03 Dec 2010 22:07:37 -0500</pubDate>
      <dc:publisher>matt</dc:publisher>
      <pingback:server>http://www.matthewlowrance.com/pingback.axd</pingback:server>
      <pingback:target>http://www.matthewlowrance.com/post.aspx?id=1a105f94-fa83-4ef0-8d38-64ae828a5cf9</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://www.matthewlowrance.com/trackback.axd?id=1a105f94-fa83-4ef0-8d38-64ae828a5cf9</trackback:ping>
      <wfw:comment>http://www.matthewlowrance.com/post/2010/12/03/Custom-Schema-and-ICustomTypeDescriptor.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.matthewlowrance.com/syndication.axd?post=1a105f94-fa83-4ef0-8d38-64ae828a5cf9</wfw:commentRss>
    </item>
    <item>
      <title>Visual Studio Brace Matching</title>
      <description>&lt;p&gt;I’ve noticed that since I installed VS 2010 I now longer had brace matching, the handy feature where if you put your cursor on one brace, VS will automatically highlight the matching one.&amp;#160; Then I realized that I had installed the Visual Studio power tools, which has line highlighting like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/VisualStudioBraceMatching_F457/image.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/VisualStudioBraceMatching_F457/image_thumb.png" width="632" height="169" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Its really handy since it quickly draws your eye to the line that the cursor is currently on.&amp;#160; No more hunting around the screen to find it.&amp;#160; However as you can see above there is no brace matching.&amp;#160; It finally dawned on me that the simple problem is that the default color for both the line highlighting and brace matching is the same.&lt;/p&gt;  &lt;p&gt;A quick trip to Tools –&amp;gt; Options –&amp;gt; Fonts and Colors and a change to the Brace Matching (Rectangle) color and I was able to have the best of both worlds:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/VisualStudioBraceMatching_F457/image_3.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/VisualStudioBraceMatching_F457/image_thumb_3.png" width="621" height="163" /&gt;&lt;/a&gt;&lt;/p&gt;</description>
      <link>http://www.matthewlowrance.com/post/2010/10/02/Visual-Studio-Brace-Matching.aspx</link>
      <author>matt</author>
      <comments>http://www.matthewlowrance.com/post/2010/10/02/Visual-Studio-Brace-Matching.aspx#comment</comments>
      <guid>http://www.matthewlowrance.com/post.aspx?id=8e6bb9cb-7dce-4dd0-b701-5c5f0ff0035b</guid>
      <pubDate>Sat, 02 Oct 2010 17:25:27 -0500</pubDate>
      <dc:publisher>matt</dc:publisher>
      <pingback:server>http://www.matthewlowrance.com/pingback.axd</pingback:server>
      <pingback:target>http://www.matthewlowrance.com/post.aspx?id=8e6bb9cb-7dce-4dd0-b701-5c5f0ff0035b</pingback:target>
      <slash:comments>3</slash:comments>
      <trackback:ping>http://www.matthewlowrance.com/trackback.axd?id=8e6bb9cb-7dce-4dd0-b701-5c5f0ff0035b</trackback:ping>
      <wfw:comment>http://www.matthewlowrance.com/post/2010/10/02/Visual-Studio-Brace-Matching.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.matthewlowrance.com/syndication.axd?post=8e6bb9cb-7dce-4dd0-b701-5c5f0ff0035b</wfw:commentRss>
    </item>
    <item>
      <title>The Command Pattern and Extension Methods</title>
      <description>&lt;p&gt;When using the &lt;a href="http://en.wikipedia.org/wiki/Command_pattern"&gt;Command Pattern&lt;/a&gt; recently to implement Undo in an application, I ran into an interesting issue.&amp;#160; When implementing the pattern more than likely there will end up being some object with a method that looks like this:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;ApplyCommand(&lt;span style="color: #2b91af"&gt;ICommand &lt;/span&gt;command);&lt;/pre&gt;

&lt;p&gt;Its not hard to understand, you need some instance of an object that implements ICommand.&amp;#160; You pass it in and then the object will execute the command.&amp;#160; However sometimes finding those (especially when buried 3 or 4 namespaces deep in a third party library) can be a hassle.&amp;#160; &lt;/p&gt;

&lt;p&gt;For example, let’s assume we have a simple Document object (in this case, just the Interface for it) that looks like this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IDocument
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;void &lt;/span&gt;Save(&lt;span style="color: blue"&gt;string &lt;/span&gt;fileName);
        &lt;span style="color: blue"&gt;bool &lt;/span&gt;AutoSave { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;int &lt;/span&gt;WordCount { &lt;span style="color: blue"&gt;get&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;int &lt;/span&gt;PageCount { &lt;span style="color: blue"&gt;get&lt;/span&gt;; }
        
    }&lt;/pre&gt;

&lt;p&gt;Eventually the request to support Undo (and probably Redo) comes in for the application.&amp;#160; We come up with a list of commands that we want to support Undo for, such as Changing font size, indenting a large area of text, etc.&amp;#160; ICommand is implemented for each of them and the above ApplyCommand method is added to the IDocument interface.&lt;/p&gt;

&lt;p&gt;However in the consuming code from now on whenever someone needs to change the font they now have to create a FontSizeCommand and then pass that to the ApplyCommand method, which will internally store the command in its undo stack and execute the command on itself.&amp;#160; It would be nicer if the consuming code could simply call:&lt;/p&gt;

&lt;pre class="code"&gt;document.FontSize(12);&lt;/pre&gt;

&lt;p&gt;We could pollute the interface with a new convenience method for each of these commands, but that would get out of hand extremely quickly (as well make the interface a huge hassle to implement on another type).&amp;#160; Instead, this is a great opportunity to use extension methods.&amp;#160; Simply define extension methods in a class in the same namespace as the IDocument interface itself and then anytime you add a using statement for it, you will also get the extension methods along with it automatically:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IDocumentExtensions
    &lt;/span&gt;{

        &lt;span style="color: blue"&gt;public static void &lt;/span&gt;FontSize(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IDocument &lt;/span&gt;document, &lt;span style="color: blue"&gt;int &lt;/span&gt;fontSize)
        {
            &lt;span style="color: #2b91af"&gt;ICommand &lt;/span&gt;command = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FontSizeCommand&lt;/span&gt;(fontSize);
            document.ApplyCommand(command);
        }

        &lt;span style="color: blue"&gt;public static void &lt;/span&gt;Indent(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IDocument &lt;/span&gt;document, &lt;span style="color: blue"&gt;string &lt;/span&gt;textBlock)
        {
            &lt;span style="color: #2b91af"&gt;IndentCommand &lt;/span&gt;command = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IndentCommand&lt;/span&gt;(textBlock);
            document.ApplyCommand(command);
        }

    }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;and you will see:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/CommandPatternandExtensionMethods_42FE/image.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/CommandPatternandExtensionMethods_42FE/image_thumb.png" width="442" height="256" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Writing extension methods on your own code always seems a little strange.&amp;#160; When you think about it, you own the code, you could just edit the class directly.&amp;#160; However many times providing your own extension methods can help provide an easy to use outward facing API but allow for clean implementation. &lt;/p&gt;

&lt;p&gt;My note about a third party library above is actually what lead me to using this code myself.&amp;#160; The 3rd party library had a nice Command Pattern implementation, but the various commands were spread out all over the namespaces (of which there are many).&amp;#160; I always end up have to resort to Intellisense spelunking to find what I want.&amp;#160; Next time you’re writing a Command based, or really any separated API, consider providing extension methods along with it, the consuming code (and developer) will thank you.&lt;/p&gt;</description>
      <link>http://www.matthewlowrance.com/post/2010/09/27/The-Command-Pattern-and-Extension-Methods.aspx</link>
      <author>matt</author>
      <comments>http://www.matthewlowrance.com/post/2010/09/27/The-Command-Pattern-and-Extension-Methods.aspx#comment</comments>
      <guid>http://www.matthewlowrance.com/post.aspx?id=c22a94c0-8949-4da6-a9ec-218548349b15</guid>
      <pubDate>Mon, 27 Sep 2010 05:10:56 -0500</pubDate>
      <category>Extension Methods</category>
      <category>Design Patterns</category>
      <dc:publisher>matt</dc:publisher>
      <pingback:server>http://www.matthewlowrance.com/pingback.axd</pingback:server>
      <pingback:target>http://www.matthewlowrance.com/post.aspx?id=c22a94c0-8949-4da6-a9ec-218548349b15</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://www.matthewlowrance.com/trackback.axd?id=c22a94c0-8949-4da6-a9ec-218548349b15</trackback:ping>
      <wfw:comment>http://www.matthewlowrance.com/post/2010/09/27/The-Command-Pattern-and-Extension-Methods.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.matthewlowrance.com/syndication.axd?post=c22a94c0-8949-4da6-a9ec-218548349b15</wfw:commentRss>
    </item>
    <item>
      <title>Fun with StructureMap</title>
      <description>&lt;p&gt;At work we use Linq2SQL and loosely support multi-tenancy.&amp;#160; As a result our UnitOfWork takes a DataContext/Repository strategy instead of taking a DataContext directly (actually there are both an IRepository &amp;amp; IDataContext interface that somewhat hide the L2S datacontext).&amp;#160; A somewhat simplified example looks like this:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IRepository
    &lt;/span&gt;{
        &lt;span style="color: #2b91af"&gt;IQueryable&lt;/span&gt;&amp;lt;T&amp;gt; SelectAll&amp;lt;T&amp;gt;();
        &lt;span style="color: blue"&gt;void &lt;/span&gt;Add&amp;lt;T&amp;gt;(T entity);
        &lt;span style="color: blue"&gt;void &lt;/span&gt;Remove&amp;lt;T&amp;gt;(T entity);
        &lt;span style="color: blue"&gt;void &lt;/span&gt;SubmitChanges();
    }


    &lt;span style="color: blue"&gt;interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IUnitOfWork
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;void &lt;/span&gt;SubmitChanges();

    }

    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;UnitOfWork &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;IUnitOfWork
    &lt;/span&gt;{
        &lt;span style="color: #2b91af"&gt;IRepository &lt;/span&gt;repository; 

        &lt;span style="color: blue"&gt;public &lt;/span&gt;UnitOfWork(Func&amp;lt;&lt;span style="color: #2b91af"&gt;IRepository&lt;/span&gt;&amp;gt; repositoryStrategy)
        {
            &lt;span style="color: blue"&gt;this&lt;/span&gt;.repository = repositoryStrategy();
        }
        
        &lt;span style="color: blue"&gt;public void &lt;/span&gt;SubmitChanges()
        {
            &lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NotImplementedException&lt;/span&gt;();
        }

    }&lt;/pre&gt;

&lt;p&gt;As you can see instead of taking an IRepository directly the UnitOfWork actually takes a Func&amp;lt;IRepository&amp;gt; which allows us to change out the datacontext per tenant (to be honest its probably more complicated and fragile than it needs to be, once there are more unit tests surrounding it, I may swap it all out).&lt;/p&gt;

&lt;p&gt;Speaking of Unit Tests I’ve been playing with StructureMap to make some of the setup of my tests a little simpler.&amp;#160; When I want to test our classes that hold the business logic a lot startup code has to be written.&amp;#160; &lt;/p&gt;

&lt;p&gt;I wrote some Factory methods that basically do this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;IRepository &lt;/span&gt;repository = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FakeRepository&lt;/span&gt;();

           &lt;span style="color: #2b91af"&gt;IUnitOfWork &lt;/span&gt;unitOfWork = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;UnitOfWork&lt;/span&gt;(() =&amp;gt; repository);

           &lt;span style="color: #2b91af"&gt;AccountService &lt;/span&gt;service = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;AccountService&lt;/span&gt;(unitOfWork);&lt;/pre&gt;

&lt;p&gt;The fun thing here is that if the ObjectFactory is initialized correctly I can just use the it as the Repository strategy:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;ObjectFactory&lt;/span&gt;.Initialize(x =&amp;gt; 
          {
              x.For&amp;lt;&lt;span style="color: #2b91af"&gt;IRepository&lt;/span&gt;&amp;gt;().Use&amp;lt;&lt;span style="color: #2b91af"&gt;FakeRepository&lt;/span&gt;&amp;gt;();
              x.For&amp;lt;&lt;span style="color: #2b91af"&gt;IUnitOfWork&lt;/span&gt;&amp;gt;().Use&amp;lt;&lt;span style="color: #2b91af"&gt;UnitOfWork&lt;/span&gt;&amp;gt;()
                  .Ctor&amp;lt;Func&amp;lt;&lt;span style="color: #2b91af"&gt;IRepository&lt;/span&gt;&amp;gt;&amp;gt;(&lt;span style="color: #a31515"&gt;&amp;quot;repositoryStrategy&amp;quot;&lt;/span&gt;)
                  .Is(() =&amp;gt; &lt;span style="color: #2b91af"&gt;ObjectFactory&lt;/span&gt;.GetInstance&amp;lt;&lt;span style="color: #2b91af"&gt;IRepository&lt;/span&gt;&amp;gt;());
                  
          });&lt;/pre&gt;

&lt;p&gt;Now I can use this like so:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;AccountService &lt;/span&gt;service = &lt;span style="color: #2b91af"&gt;ObjectFactory&lt;/span&gt;.GetInstance&amp;lt;&lt;span style="color: #2b91af"&gt;AccountService&lt;/span&gt;&amp;gt;();&lt;/pre&gt;

&lt;p&gt;and the service gets a valid UnitOfWork:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/FunwithStructureMap_FFB7/image.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/FunwithStructureMap_FFB7/image_thumb.png" width="647" height="117" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;In production you would need to be very careful of your objects lifetime, for example in this example the L2S datacontext would probably never get disposed.&amp;#160; Since I’m just using this to spin up my classes in my Unit Tests, that’s probably not a huge concern.&amp;#160; YMMV.&lt;/p&gt;

&lt;p&gt;That aside I thought the interesting thing here was the ability to call the ObjectFactory itself again to complete the strategy and get the needed object.&amp;#160; I wasn’t sure if it would work, but after a little playing I was able to get it working.&amp;#160; Now that this important task is out of the way I can actually write more tests ;)&lt;/p&gt;</description>
      <link>http://www.matthewlowrance.com/post/2010/08/17/Fun-with-StructureMap.aspx</link>
      <author>matt</author>
      <comments>http://www.matthewlowrance.com/post/2010/08/17/Fun-with-StructureMap.aspx#comment</comments>
      <guid>http://www.matthewlowrance.com/post.aspx?id=9e0a8f73-8f7f-4a7f-a350-78ad46178fbd</guid>
      <pubDate>Tue, 17 Aug 2010 18:56:32 -0500</pubDate>
      <category>Unit Testing</category>
      <category>IoC</category>
      <dc:publisher>matt</dc:publisher>
      <pingback:server>http://www.matthewlowrance.com/pingback.axd</pingback:server>
      <pingback:target>http://www.matthewlowrance.com/post.aspx?id=9e0a8f73-8f7f-4a7f-a350-78ad46178fbd</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://www.matthewlowrance.com/trackback.axd?id=9e0a8f73-8f7f-4a7f-a350-78ad46178fbd</trackback:ping>
      <wfw:comment>http://www.matthewlowrance.com/post/2010/08/17/Fun-with-StructureMap.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.matthewlowrance.com/syndication.axd?post=9e0a8f73-8f7f-4a7f-a350-78ad46178fbd</wfw:commentRss>
    </item>
    <item>
      <title>Lost Visual Studio Icon</title>
      <description>&lt;p&gt;At some point on my machine Visual Studio 2010 lost its icon.&amp;#160; It wasn’t a huge deal, just an annoyance since every time I would look down at the taskbar instead of seeing the VS icon I would see the generic Windows “document” icon.&lt;/p&gt;  &lt;p&gt;I would end up opening several copies of VS not realizing I already had it open.&amp;#160; I also keep it pinned to my taskbar and would forget that the default blob down there was VS so I would hunt all over the start menu to open a new instance.&amp;#160; &lt;/p&gt;  &lt;p&gt;Finally today I found the problem, somehow I had associated .csproj files with Notepad.&amp;#160; I’m not sure how it happened and I’m not sure why it broke my VS icon (and actually I can’t seem to recreate it anymore) but once I fixed the settings to match below and chose VS as the default for the file type, all was well.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/LostVisualStudioIcon_E89A/image.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/LostVisualStudioIcon_E89A/image_thumb.png" width="560" height="463" /&gt;&lt;/a&gt;&lt;/p&gt;</description>
      <link>http://www.matthewlowrance.com/post/2010/08/12/Lost-Visual-Studio-Icon.aspx</link>
      <author>matt</author>
      <comments>http://www.matthewlowrance.com/post/2010/08/12/Lost-Visual-Studio-Icon.aspx#comment</comments>
      <guid>http://www.matthewlowrance.com/post.aspx?id=a7464e3a-1df4-4718-9175-7f74ecf38735</guid>
      <pubDate>Thu, 12 Aug 2010 16:32:36 -0500</pubDate>
      <dc:publisher>matt</dc:publisher>
      <pingback:server>http://www.matthewlowrance.com/pingback.axd</pingback:server>
      <pingback:target>http://www.matthewlowrance.com/post.aspx?id=a7464e3a-1df4-4718-9175-7f74ecf38735</pingback:target>
      <slash:comments>5</slash:comments>
      <trackback:ping>http://www.matthewlowrance.com/trackback.axd?id=a7464e3a-1df4-4718-9175-7f74ecf38735</trackback:ping>
      <wfw:comment>http://www.matthewlowrance.com/post/2010/08/12/Lost-Visual-Studio-Icon.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.matthewlowrance.com/syndication.axd?post=a7464e3a-1df4-4718-9175-7f74ecf38735</wfw:commentRss>
    </item>
    <item>
      <title>Logging to Trace, Verbose, etc. with log4net</title>
      <description>&lt;p&gt;The default &lt;a href="http://svn.apache.org/viewvc/logging/log4net/trunk/src/ILog.cs?view=markup"&gt;ILog&lt;/a&gt; interface for log4net only presents forward 7 logging levels (ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF”).&amp;#160; In a few projects I have for a long time wanted to a level between INFO and DEBUG.&amp;#160; There is information that I would like to log for my purposes, but for others it is simply clutter.&lt;/p&gt;  &lt;p&gt;In researching how to write a custom level I started poking around &lt;a href="http://svn.apache.org/viewvc/logging/log4net/trunk/src/Core/Level.cs?view=markup"&gt;Level.cs&lt;/a&gt; and noticed toward the bottom (around line 500) there are already a large number of default logging levels define, its jus that as mentioned above the default ILog interface doesn’t present them forward.&lt;/p&gt;  &lt;p&gt;I started considering writing my own ILog implementation but then it hit me, extension methods to the rescue:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public static class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ILogExtentions
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;private static readonly &lt;/span&gt;log4net.&lt;span style="color: #2b91af"&gt;ILog &lt;/span&gt;log = 
            log4net.&lt;span style="color: #2b91af"&gt;LogManager&lt;/span&gt;.GetLogger(System.Reflection.&lt;span style="color: #2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod().DeclaringType);
        
        &lt;span style="color: blue"&gt;public static void &lt;/span&gt;Trace(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ILog &lt;/span&gt;log, &lt;span style="color: blue"&gt;string &lt;/span&gt;message, &lt;span style="color: #2b91af"&gt;Exception &lt;/span&gt;exception)
        {
            log.Logger.Log(System.Reflection.&lt;span style="color: #2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod().DeclaringType, 
                log4net.Core.&lt;span style="color: #2b91af"&gt;Level&lt;/span&gt;.Trace, message, exception);
        }

        &lt;span style="color: blue"&gt;public static void &lt;/span&gt;Trace(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ILog &lt;/span&gt;log, &lt;span style="color: blue"&gt;string &lt;/span&gt;message)
        {
            log.Trace(message, &lt;span style="color: blue"&gt;null&lt;/span&gt;);
        }

        &lt;span style="color: blue"&gt;public static void &lt;/span&gt;Verbose(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ILog &lt;/span&gt;log, &lt;span style="color: blue"&gt;string &lt;/span&gt;message, &lt;span style="color: #2b91af"&gt;Exception &lt;/span&gt;exception)
        {
            log.Logger.Log(System.Reflection.&lt;span style="color: #2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod().DeclaringType, 
                log4net.Core.&lt;span style="color: #2b91af"&gt;Level&lt;/span&gt;.Verbose, message, exception);
        }

        &lt;span style="color: blue"&gt;public static void &lt;/span&gt;Verbose(&lt;span style="color: blue"&gt;this &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ILog &lt;/span&gt;log, &lt;span style="color: blue"&gt;string &lt;/span&gt;message)
        {
            log.Verbose(message, &lt;span style="color: blue"&gt;null&lt;/span&gt;);
        }



    }&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These extension methods should probably actually go on &lt;a href="http://svn.apache.org/viewvc/logging/log4net/trunk/src/Core/ILogger.cs?view=markup"&gt;ILogger&lt;/a&gt;, (which as you can see above is where the actual Log method is) but since I always use the default ILog implementation this makes calling the methods feel more natural.&lt;/p&gt;

&lt;p&gt;Now I can simply call log.Trace or log.Verbose and get log output.&amp;#160; So instead of having a level between DEBUG and INFO, I have just started logging my stuff at a level below debug.&amp;#160; Now the technical users can review the DEBUG log without having to see my very fine level messages.&lt;/p&gt;

&lt;p&gt;As I mentioned there are a large number of additional levels defined that the same methods could easily be implemented for.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/LoggingtoTraceVerboseetc.withlog4net_52E1/image.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.matthewlowrance.com/Images/blog/LoggingtoTraceVerboseetc.withlog4net_52E1/image_thumb.png" width="621" height="315" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Note: Don’t forget to update your log4net config to turn on these additional levels.&amp;#160; I spent a while thinking these methods weren’t working until I figured out I just hadn’t turned them on. Enjoy!&lt;/p&gt;</description>
      <link>http://www.matthewlowrance.com/post/2010/07/14/Logging-to-Trace-Verbose-etc-with-log4net.aspx</link>
      <author>matt</author>
      <comments>http://www.matthewlowrance.com/post/2010/07/14/Logging-to-Trace-Verbose-etc-with-log4net.aspx#comment</comments>
      <guid>http://www.matthewlowrance.com/post.aspx?id=de7ae878-3bb7-4e58-95b7-615201094ee7</guid>
      <pubDate>Wed, 14 Jul 2010 05:53:50 -0500</pubDate>
      <category>log4net</category>
      <dc:publisher>matt</dc:publisher>
      <pingback:server>http://www.matthewlowrance.com/pingback.axd</pingback:server>
      <pingback:target>http://www.matthewlowrance.com/post.aspx?id=de7ae878-3bb7-4e58-95b7-615201094ee7</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://www.matthewlowrance.com/trackback.axd?id=de7ae878-3bb7-4e58-95b7-615201094ee7</trackback:ping>
      <wfw:comment>http://www.matthewlowrance.com/post/2010/07/14/Logging-to-Trace-Verbose-etc-with-log4net.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.matthewlowrance.com/syndication.axd?post=de7ae878-3bb7-4e58-95b7-615201094ee7</wfw:commentRss>
    </item>
    <item>
      <title>Snippets</title>
      <description>&lt;p&gt;A few months back &lt;a href="http://www.marshalledthoughts.com/"&gt;Chad&lt;/a&gt; did a presentation for our local &lt;a href="http://sgfdotnet.org/"&gt;.Net users group&lt;/a&gt; (&lt;a href="http://groups.google.com/group/sgfdotnet"&gt;Mailing List&lt;/a&gt;) on Snippets (by the way, he will be presenting it at &lt;a href="http://www.sharepointsaturday.org/ozarks/default.aspx"&gt;SharePoint Saturday Ozarks&lt;/a&gt;).&amp;#160; I hadn’t really played with snippets much before then, but since I have found them to be a pretty big time saver.&amp;#160; I thought there’s no reason to keep them to myself, so from time to I’ll post the interesting ones here.&lt;/p&gt;  &lt;p&gt;During the presentation he suggested storing your snippets in an online store so you can share them across locations.&amp;#160; So I have put mine into a &lt;a href="https://www.dropbox.com/"&gt;Dropbox&lt;/a&gt; folder, added those into my VS instances at home and work (Tools –&amp;gt; Code Snippets Manager) and now my snippets are synchronized across my machines.&lt;/p&gt;  &lt;p&gt;(Note some of these include long line of unbroken code with will probably not render very well in the browser, you’ll be better off just cutting and pasting them into VS.)&lt;/p&gt;  &lt;p&gt;So with out further ado: &lt;/p&gt;  &lt;p&gt;We use Log4Net in a couple of projects at work, and I always end up looking up the&amp;#160; line of code to initialize the logger, now a simple “log4net” [TAB][TAB] does the job:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;encoding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;utf-8&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;CodeSnippet &lt;/span&gt;&lt;span style="color: red"&gt;Format&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Log4Net&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Author&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Matt Lowrance&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Author&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Shortcut&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;log4net&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Shortcut&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Inserts the log4net logging information &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetTypes&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Expansion&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetTypes&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Snippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Code &lt;/span&gt;&lt;span style="color: red"&gt;Language&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;CSharp&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;![CDATA[&lt;/span&gt;&lt;span style="color: gray"&gt;private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);$end$&lt;/span&gt;&lt;span style="color: blue"&gt;]]&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Code&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Snippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;CodeSnippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private static readonly &lt;/span&gt;log4net.ILog log = 
            log4net.LogManager.GetLogger(System.Reflection.&lt;span style="color: #2b91af"&gt;MethodBase&lt;/span&gt;.GetCurrentMethod().DeclaringType);&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;encoding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;utf-8&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;CodeSnippet &lt;/span&gt;&lt;span style="color: red"&gt;Format&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Console ENTER to Continue&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Author&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Matt Lowrance&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Author&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Shortcut&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;entercontinue&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Shortcut&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Prints &amp;quot;Please press ENTER to continue&amp;quot; and reads a line to provide a pause&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetTypes&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Expansion&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetTypes&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Snippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Code &lt;/span&gt;&lt;span style="color: red"&gt;Language&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;CSharp&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;![CDATA[&lt;/span&gt;&lt;span style="color: gray"&gt;Console.WriteLine(&amp;quot;Press ENTER to continue&amp;quot;);
            Console.ReadLine();&lt;/span&gt;&lt;span style="color: blue"&gt;]]&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Code&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Snippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;CodeSnippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;


&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This one is just a simple helper when writing a command line tool:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;Press ENTER to continue&amp;quot;&lt;/span&gt;);
           &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/pre&gt;

&lt;p&gt;I’ve been writing some integration tests lately and found that a large number of them were tests to ensure a proper exception was thrown under the correct circumstances:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;encoding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;utf-8&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;CodeSnippet &lt;/span&gt;&lt;span style="color: red"&gt;Format&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Expected Exception&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Author&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Matt Lowrance&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Author&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Shortcut&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;ee&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Shortcut&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Creates an ExpectedException attribute for Unit Tests&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetTypes&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Expansion&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetTypes&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Snippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Declarations&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Literal&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;TypeOfException&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Default&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;ArgumentNullException&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Default&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Literal&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Declarations&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Code &lt;/span&gt;&lt;span style="color: red"&gt;Language&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;CSharp&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;![CDATA[&lt;/span&gt;&lt;span style="color: gray"&gt;[ExpectedException(typeof($TypeOfException$))]$end$&lt;/span&gt;&lt;span style="color: blue"&gt;]]&amp;gt;
      
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Code&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Snippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;CodeSnippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;

&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This outputs the test attribute:&lt;/p&gt;

&lt;pre class="code"&gt;[ExpectedException(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ArgumentNullException&lt;/span&gt;))]&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Similar to one above VS come with cw for “Console.WriteLine();”, so I wrote and simple “cr” for “Console.ReadLine();”:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;encoding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;utf-8&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;CodeSnippet &lt;/span&gt;&lt;span style="color: red"&gt;Format&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Console.ReadLine&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Author&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Matthew Lowrance&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Author&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Shortcut&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;cr&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Shortcut&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Outputs Console.Readling()&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetTypes&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Expansion&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetTypes&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Snippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Code &lt;/span&gt;&lt;span style="color: red"&gt;Language&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;CSharp&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;![CDATA[&lt;/span&gt;&lt;span style="color: gray"&gt;Console.ReadLine();&lt;/span&gt;&lt;span style="color: blue"&gt;]]&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Code&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Snippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;CodeSnippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;

&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Last, and luckily I haven’t actually ever had to use this one, but I just thought it would be a fun one to have available:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;encoding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;utf-8&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;CodeSnippet &lt;/span&gt;&lt;span style="color: red"&gt;Format&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Abandon All Hope&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Author&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Matt Lowrance&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Author&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Shortcut&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;aah&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Shortcut&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Displays an ASCII art skull and Cross Bones with the quote &amp;quot;Abandon all hope, all ye who enter here&amp;quot;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetTypes&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Expansion&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;SnippetTypes&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Header&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Snippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Code &lt;/span&gt;&lt;span style="color: red"&gt;Language&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;CSharp&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;![CDATA[
&lt;/span&gt;&lt;span style="color: gray"&gt;/*************************************************************
 *                                                           *
 *   .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.      *
 *   |                     ______                     |      *
 *   |                  .-&amp;quot;      &amp;quot;-.                  |      *
 *   |                 /            \                 |      *
 *   |     _          |              |          _     |      *
 *   |    ( \         |,  .-.  .-.  ,|         / )    |      *
 *   |     &amp;gt; &amp;quot;=._     | )(__/  \__)( |     _.=&amp;quot; &amp;lt;     |      *
 *   |    (_/&amp;quot;=._&amp;quot;=._ |/     /\     \| _.=&amp;quot;_.=&amp;quot;\_)    |      *
 *   |           &amp;quot;=._&amp;quot;(_     ^^     _)&amp;quot;_.=&amp;quot;           |      *
 *   |               &amp;quot;=\__|IIIIII|__/=&amp;quot;               |      *
 *   |              _.=&amp;quot;| \IIIIII/ |&amp;quot;=._              |      *
 *   |    _     _.=&amp;quot;_.=&amp;quot;\          /&amp;quot;=._&amp;quot;=._     _    |      *
 *   |   ( \_.=&amp;quot;_.=&amp;quot;     `--------`     &amp;quot;=._&amp;quot;=._/ )   |      *
 *   |    &amp;gt; _.=&amp;quot;                            &amp;quot;=._ &amp;lt;    |      *
 *   |   (_/                                    \_)   |      *
 *   |                                                |      *
 *   '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='      *
 *                                                           *
 *        ABANDON ALL HOPE, ALL YE WHO ENTER HERE            *
 *************************************************************/&lt;/span&gt;&lt;span style="color: blue"&gt;]]&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Code&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Snippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;CodeSnippet&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;

&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;</description>
      <link>http://www.matthewlowrance.com/post/2010/06/05/Snippets.aspx</link>
      <author>matt</author>
      <comments>http://www.matthewlowrance.com/post/2010/06/05/Snippets.aspx#comment</comments>
      <guid>http://www.matthewlowrance.com/post.aspx?id=759b6a63-a5b5-4879-abf9-af0787d74635</guid>
      <pubDate>Sat, 05 Jun 2010 09:01:03 -0500</pubDate>
      <dc:publisher>matt</dc:publisher>
      <pingback:server>http://www.matthewlowrance.com/pingback.axd</pingback:server>
      <pingback:target>http://www.matthewlowrance.com/post.aspx?id=759b6a63-a5b5-4879-abf9-af0787d74635</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.matthewlowrance.com/trackback.axd?id=759b6a63-a5b5-4879-abf9-af0787d74635</trackback:ping>
      <wfw:comment>http://www.matthewlowrance.com/post/2010/06/05/Snippets.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.matthewlowrance.com/syndication.axd?post=759b6a63-a5b5-4879-abf9-af0787d74635</wfw:commentRss>
    </item>
    <item>
      <title>Unit Test Keyboard Bindings</title>
      <description>&lt;p&gt;I have been writing some integration tests lately in preparation for a refactoring effort to make our code more Unit Test friendly.&amp;nbsp; The code was not originally written with any kind of testing in mind, and as a result there are a large number of dependencies (including the Linq 2 Sql datacontext) that are currently very hard to test.&lt;/p&gt;
&lt;p&gt;Since most of these test are fairly straight forward they usually pass on the first run.&amp;nbsp; The default keyboard binding for Run-&amp;gt; Tests in the Current Context and Debug &amp;ndash;&amp;gt; Tests in the Current Context are the same: Ctril+R,T.&amp;nbsp; This means that each time a test is run the full debug environment is spun up, which is slow when you are fairly sure the test is going to pass.&lt;/p&gt;
&lt;p&gt;On the other hand the &amp;ldquo;Run Tests&amp;rdquo; in the context menu runs much more quickly:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/UnitTestKeyboardBindings_11DA1/image.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" src="http://www.matthewlowrance.com/Images/blog/UnitTestKeyboardBindings_11DA1/image_thumb.png" border="0" alt="image" width="429" height="392" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have &lt;a href="http://weblogs.asp.net/infinitiesloop/archive/2008/07/18/visual-studio-tip-disable-f1.aspx"&gt;lived in fear of the F1 key&lt;/a&gt; for a long time so I thought this would be a good opportunity to kill two birds with one stone.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Remapping Visual Studio keyboard shortcuts is pretty straight forward.&amp;nbsp; First follow the directions in the link above to remove the default F1 binding (Tools &amp;ndash;&amp;gt; Options, Keyboard,&amp;nbsp; Search for &amp;ldquo;Help&amp;rdquo; then remove the Help.F1Help command).&amp;nbsp; The search for &amp;ldquo;RunTests&amp;rdquo; and choose EditorContextMenus.CodeWindow.RunTests from the list.&amp;nbsp; Below in the &amp;ldquo;Press shortcut keys&amp;rdquo; textbox press the F1 (or any other key combination you would want to use) and click &amp;ldquo;Assign&amp;rdquo;:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/UnitTestKeyboardBindings_11DA1/image_3.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" src="http://www.matthewlowrance.com/Images/blog/UnitTestKeyboardBindings_11DA1/image_thumb_3.png" border="0" alt="image" width="538" height="311" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now F1 will run the tests in the current context without needing the context menu (you can see it mapped in the screenshot below):&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.matthewlowrance.com/Images/blog/UnitTestKeyboardBindings_11DA1/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" src="http://www.matthewlowrance.com/Images/blog/UnitTestKeyboardBindings_11DA1/image_thumb_4.png" border="0" alt="image" width="532" height="253" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have actually found this to be a pretty big time saver.&amp;nbsp; Since on these integration tests I don&amp;rsquo;t often need to debug and I run them fairly often just one at a time, using this short cut saves 5-10 seconds for each test run over the debug version and keep my hands off the mouse (which is probably the largest time saver of all).&lt;/p&gt;</description>
      <link>http://www.matthewlowrance.com/post/2010/06/02/Unit-Test-Keyboard-Bindings.aspx</link>
      <author>matt</author>
      <comments>http://www.matthewlowrance.com/post/2010/06/02/Unit-Test-Keyboard-Bindings.aspx#comment</comments>
      <guid>http://www.matthewlowrance.com/post.aspx?id=7ccdf20e-88be-4fe9-947c-2fcfe973e043</guid>
      <pubDate>Wed, 02 Jun 2010 20:19:00 -0500</pubDate>
      <dc:publisher>matt</dc:publisher>
      <pingback:server>http://www.matthewlowrance.com/pingback.axd</pingback:server>
      <pingback:target>http://www.matthewlowrance.com/post.aspx?id=7ccdf20e-88be-4fe9-947c-2fcfe973e043</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://www.matthewlowrance.com/trackback.axd?id=7ccdf20e-88be-4fe9-947c-2fcfe973e043</trackback:ping>
      <wfw:comment>http://www.matthewlowrance.com/post/2010/06/02/Unit-Test-Keyboard-Bindings.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.matthewlowrance.com/syndication.axd?post=7ccdf20e-88be-4fe9-947c-2fcfe973e043</wfw:commentRss>
    </item>
  </channel>
</rss>
