<?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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0" xml:base="http://www.csharptocsharp.com">
<channel>
 <title>From C Sharp to C Sharp - dirges and developers</title>
 <link>http://www.csharptocsharp.com</link>
 <description>A classical musician turned programmer... or something</description>
 <language>en</language>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/CSharpToCSharp" type="application/rss+xml" /><item>
 <title>A Better string.IsNullOrEmpty and more...</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/fepzv-_j8-Q/better-string-IsNullOrEmpty</link>
 <description>&lt;p&gt;Here's a better version of string.IsNullOrEmpty(). Why is it better you say? Well my friend, this one checks the string for spaces... It also returns a positive statement (true if it is NOT null and NOT empty)&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;    &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;static&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;class&lt;/span&gt; Extensions
    &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;static&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;bool&lt;/span&gt; IsSafe&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0600FF;"&gt;this&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; s&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
            &lt;span style="color: #0600FF;"&gt;return&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;s &lt;span style="color: #008000;"&gt;!=&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;null&lt;/span&gt; &lt;span style="color: #008000;"&gt;&amp;amp;&amp;amp;&lt;/span&gt; s.&lt;span style="color: #0000FF;"&gt;Trim&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;Length&lt;/span&gt; &lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
    &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;And some unit tests...&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;       &lt;span style="color: #000000;"&gt;&amp;#91;&lt;/span&gt;Test&lt;span style="color: #000000;"&gt;&amp;#93;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;void&lt;/span&gt; IsSafeStringTest&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
            &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; cheese &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;is good&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            Assert.&lt;span style="color: #0000FF;"&gt;IsTrue&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;cheese.&lt;span style="color: #0000FF;"&gt;IsSafe&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            cheese &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            Assert.&lt;span style="color: #0000FF;"&gt;IsFalse&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;cheese.&lt;span style="color: #0000FF;"&gt;IsSafe&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            cheese &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;   &amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            Assert.&lt;span style="color: #0000FF;"&gt;IsFalse&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;cheese.&lt;span style="color: #0000FF;"&gt;IsSafe&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            cheese &lt;span style="color: #008000;"&gt;=&lt;/span&gt; null&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            Assert.&lt;span style="color: #0000FF;"&gt;IsFalse&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;cheese.&lt;span style="color: #0000FF;"&gt;IsSafe&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&amp;nbsp;
            &lt;span style="color: #008080; font-style: italic;"&gt;//-------------------------------&lt;/span&gt;
            cheese &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;yum&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            Assert.&lt;span style="color: #0000FF;"&gt;IsFalse&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;IsNullOrEmpty&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;cheese&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            cheese &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            Assert.&lt;span style="color: #0000FF;"&gt;IsTrue&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;IsNullOrEmpty&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;cheese&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            cheese &lt;span style="color: #008000;"&gt;=&lt;/span&gt; null&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            Assert.&lt;span style="color: #0000FF;"&gt;IsTrue&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;IsNullOrEmpty&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;cheese&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&amp;nbsp;
            &lt;span style="color: #008080; font-style: italic;"&gt;// rut roh... &lt;/span&gt;
            &lt;span style="color: #008080; font-style: italic;"&gt;// string.IsNullOrEmpty() and spaces are not nice together.&lt;/span&gt;
            cheese &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;   &amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            &lt;span style="color: #008080; font-style: italic;"&gt;// should be true!&lt;/span&gt;
            Assert.&lt;span style="color: #0000FF;"&gt;IsFalse&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;IsNullOrEmpty&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;cheese&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
        &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;While the following might be nice, we know that we can't do it because of the null reference exception we might get (if cheese were to be null)...&lt;/p&gt;
&lt;p&gt;string.IsNullOrEmpty(cheese.Trim());&lt;/p&gt;
&lt;p&gt;Anyway, while we're doing some extension methods, here's a similarly named one I also use when working with generic lists.&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;static&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;bool&lt;/span&gt; IsSafe&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;T&lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0600FF;"&gt;this&lt;/span&gt; List&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;T&lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt; t&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
            &lt;span style="color: #0600FF;"&gt;return&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;t &lt;span style="color: #008000;"&gt;!=&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;null&lt;/span&gt; &lt;span style="color: #008000;"&gt;&amp;amp;&amp;amp;&lt;/span&gt; t.&lt;span style="color: #0000FF;"&gt;Count&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;And some unit tests...&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;       &lt;span style="color: #000000;"&gt;&amp;#91;&lt;/span&gt;Test&lt;span style="color: #000000;"&gt;&amp;#93;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;void&lt;/span&gt; IsSafeListTest&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
            var objectList &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; List&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;object&lt;/span&gt;&lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            Assert.&lt;span style="color: #0000FF;"&gt;IsFalse&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;objectList.&lt;span style="color: #0000FF;"&gt;IsSafe&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&amp;nbsp;
            List&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;int&lt;/span&gt;&lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt; intList &lt;span style="color: #008000;"&gt;=&lt;/span&gt; null&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            Assert.&lt;span style="color: #0000FF;"&gt;IsFalse&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;intList.&lt;span style="color: #0000FF;"&gt;IsSafe&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&amp;nbsp;
            var stringList &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; List&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt;&lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;cheese&amp;quot;&lt;/span&gt;,&lt;span style="color: #666666;"&gt;&amp;quot;beer&amp;quot;&lt;/span&gt;,&lt;span style="color: #666666;"&gt;&amp;quot;nachos&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            Assert.&lt;span style="color: #0000FF;"&gt;IsTrue&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;stringList.&lt;span style="color: #0000FF;"&gt;IsSafe&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/fepzv-_j8-Q" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/better-string-IsNullOrEmpty#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/3">C#</category>
 <pubDate>Fri, 19 Jun 2009 19:40:09 -0600</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">35 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/better-string-IsNullOrEmpty</feedburner:origLink></item>
<item>
 <title>NUnit Talk Goods</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/PUIj941i7lQ/nunit-intro-ctdotnet-materials</link>
 <description>&lt;p&gt;As promised, &lt;a href="/nunit-talk.zip"&gt;the materials&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/PUIj941i7lQ" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/nunit-intro-ctdotnet-materials#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/20">Testing</category>
 <pubDate>Sun, 14 Jun 2009 08:16:12 -0600</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">34 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/nunit-intro-ctdotnet-materials</feedburner:origLink></item>
<item>
 <title>Giving a Presentation on NUnit at CTDOTNET '09</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/aRwRcqaEMB8/nunit-intro-ctdotnet-2009</link>
 <description>&lt;p&gt;Yo yo howdy-doody. I'm doing a talk on NUnit (and friends) with VS 2008 at CTDOTNET's second CodeCamp -- June 13th, 2009.&lt;/p&gt;
&lt;p&gt;It's an intro to unit testing, but I'll talk about reasons why testing is beneficial, how to setup a unit testing environment, and tools (friends) to use along the way. &lt;/p&gt;
&lt;p&gt;Get the &lt;a href="http://ctdotnet.org/codecamp2.aspx"&gt;deets&lt;/a&gt; about the day.&lt;/p&gt;
&lt;p&gt;Hope to see you there!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/aRwRcqaEMB8" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/nunit-intro-ctdotnet-2009#comments</comments>
 <pubDate>Sun, 24 May 2009 09:35:49 -0600</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">33 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/nunit-intro-ctdotnet-2009</feedburner:origLink></item>
<item>
 <title>Unit Test a DataReader with NUnit, Moq and Stubs</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/RqlrWCkkRnM/unit-test-datareader-with-mocks-and-stubs</link>
 <description>&lt;p&gt;This post will allow you to unit test objects that have a dependency on a SqlDataReader by mocking/stubbing a data reader.&lt;/p&gt;
&lt;p&gt;Here I've made a 'wrapper' of sorts for the good ol' Microsoft SqlHelper class, which is ancient now, ya? Since the SqlHelper.ExecuteReader's method class implements the IDataReader interface we're in luck. &lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;&lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;interface&lt;/span&gt; IFetch &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
&lt;span style="color: #008080; font-style: italic;"&gt;//add members as necessary&lt;/span&gt;
IDataReader ExecuteDataReader&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; connectionString, 
&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; storedProcedureName,SqlParameter&lt;span style="color: #000000;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#93;&lt;/span&gt; parameters&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;class&lt;/span&gt; Fetch &lt;span style="color: #008000;"&gt;:&lt;/span&gt; IFetch &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; IDataReader ExecuteDataReader&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; connectionString, 
&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; storedProcedureName, SqlParameter&lt;span style="color: #000000;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#93;&lt;/span&gt; parameters&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;return&lt;/span&gt; SqlHelper.&lt;span style="color: #0000FF;"&gt;ExecuteReader&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;connectionString, 
CommandType.&lt;span style="color: #0000FF;"&gt;StoredProcedure&lt;/span&gt;,storedProcedureName, 
parameters&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Next we create our object from the results of our IDataReader. The SqlHelper class removes the worry about mocking SqlCommand and SqlConnection classes. All you need to worry about are the results (SqlDataReader).&lt;/p&gt;
&lt;p&gt;(You can make your own RockStar object, fo sho.)&lt;/p&gt;
&lt;p&gt;Whether you call it constructor initialization or constructor chaining, we have it here, and will allow us to inject the correct dependency, in this case, an interface that defines an ExecuteReader method. (&lt;em&gt;I've never gotten into DI/IoC frameworks, should I, and which??&lt;/em&gt;)&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;&lt;span style="color: #0600FF;"&gt;private&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;readonly&lt;/span&gt; RockStar rs&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;private&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;readonly&lt;/span&gt; IFetch fetch&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #008080; font-style: italic;"&gt;//here's the magic sauce for the unittests&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; FetchCms&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;IFetch fetch, RockStar rs&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;this&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;fetch&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; fetch&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;this&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;rs&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; rs&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
&lt;span style="color: #008080; font-style: italic;"&gt;//production code calls this which calls &lt;/span&gt;
&lt;span style="color: #008080; font-style: italic;"&gt;//the other constructor. mmm.&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; FetchRockStar&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #008000;"&gt;:&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;this&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; Fetch&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;, &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; RockStar&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; RockStar GetRockStar&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; urlToLookup&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;try&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
var parms &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt;&lt;span style="color: #000000;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#93;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; SqlParameter&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;@urlName&amp;quot;&lt;/span&gt;, urlToLookup&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;using&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;IDataReader reader &lt;span style="color: #008000;"&gt;=&lt;/span&gt; 
fetch.&lt;span style="color: #0000FF;"&gt;ExecuteDataReader&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;localhell&amp;quot;&lt;/span&gt;, &lt;span style="color: #666666;"&gt;&amp;quot;rockstar_page_get&amp;quot;&lt;/span&gt;,parms&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;if&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;reader &lt;span style="color: #008000;"&gt;!=&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;null&lt;/span&gt; &lt;span style="color: #008000;"&gt;&amp;amp;&amp;amp;&lt;/span&gt; reader.&lt;span style="color: #0000FF;"&gt;Read&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
rs.&lt;span style="color: #0000FF;"&gt;Name&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; reader&lt;span style="color: #000000;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#93;&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;ToString&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
rs.&lt;span style="color: #0000FF;"&gt;Guitar&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; reader&lt;span style="color: #000000;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;guitar&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#93;&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;ToString&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #008080; font-style: italic;"&gt;//add some logic... and so on...                       &lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;catch&lt;/span&gt; &lt;span style="color: #008080; font-style: italic;"&gt;//swine flu&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;return&lt;/span&gt; fs&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;ok, so now your production code is hawt, but how do you 'fake' a reader, or 'fake' its results? Good question, but never fear, &lt;a rel="nofollow" href="http://haacked.com/"&gt;Phil Haack&lt;/a&gt; has you covered with his totally rock-tacular &lt;a href="http://haacked.com/archive/2006/05/31/UnitTestingDataAccessCodeWithTheStubDataReader.aspx"&gt;StubDataReader class&lt;/a&gt;. Get it.&lt;/p&gt;
&lt;p&gt;so now, in your UnitTest project...&lt;/p&gt;
&lt;p&gt;I'm creating some fake results that I can use to test my expectations, using the StubDataReader class you've downloaded above and added to your UnitTest project.&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;&lt;span style="color: #0600FF;"&gt;private&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;static&lt;/span&gt; StubDataReader getData_Kerry_King&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
var resultSet &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; StubResultSet&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;, &lt;span style="color: #666666;"&gt;&amp;quot;guitar&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
resultSet.&lt;span style="color: #0000FF;"&gt;AddRow&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;Kerry King&amp;quot;&lt;/span&gt;, &lt;span style="color: #666666;"&gt;&amp;quot;B.C. Rich&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;return&lt;/span&gt; &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; StubDataReader&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;resultSet&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;I'm using the &lt;a href="http://code.google.com/p/moq/"&gt;Moq framework&lt;/a&gt; to mock my interfaces. (it's from an older release, hence the Expect calls rather than the Setup calls [&lt;b&gt;anyone: what does the new version get me?&lt;/b&gt;])&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;&lt;span style="color: #000000;"&gt;&amp;#91;&lt;/span&gt;Test&lt;span style="color: #000000;"&gt;&amp;#93;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;void&lt;/span&gt; Execute_DataReader_Test&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
var m &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; Mock&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;IFetch&lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #008080; font-style: italic;"&gt;//here i'm expecting that my ExecuteReader implementation&lt;/span&gt;
&lt;span style="color: #008080; font-style: italic;"&gt;//return my 'fake' data&lt;/span&gt;
m.&lt;span style="color: #0000FF;"&gt;Expect&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;
x &lt;span style="color: #008000;"&gt;=&amp;gt;&lt;/span&gt; x.&lt;span style="color: #0000FF;"&gt;ExecuteReader&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;
It.&lt;span style="color: #0000FF;"&gt;IsAny&lt;/span&gt;&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt;&lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;, 
It.&lt;span style="color: #0000FF;"&gt;IsAny&lt;/span&gt;&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt;&lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;, 
It.&lt;span style="color: #0000FF;"&gt;IsAny&lt;/span&gt;&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;SqlParameter&lt;span style="color: #000000;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;Returns&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;getData_Kerry_King&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&amp;nbsp;
var rockStar &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; RockStar&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #008080; font-style: italic;"&gt;// pass IN the interface using the special constructor.&lt;/span&gt;
var fetch &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; FetchRockStar&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;m.&lt;span style="color: #FF0000;"&gt;Object&lt;/span&gt;, rockStar&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
rockStar &lt;span style="color: #008000;"&gt;=&lt;/span&gt; fetch.&lt;span style="color: #0000FF;"&gt;GetRockStar&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;kerry-king&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #008080; font-style: italic;"&gt;//assert&lt;/span&gt;
Assert.&lt;span style="color: #0000FF;"&gt;AreEqual&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;Kerry King&amp;quot;&lt;/span&gt;,rockStar.&lt;span style="color: #0000FF;"&gt;Name&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
Assert.&lt;span style="color: #0000FF;"&gt;AreEqual&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;B.C. Rich&amp;quot;&lt;/span&gt;,rockStar.&lt;span style="color: #0000FF;"&gt;Guitar&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Even Kerry thinks you should be testing!&lt;br /&gt;
&lt;center&gt;&lt;br /&gt;
&lt;img src="/files/kerry-king-unit-testing-chaos.jpg" title="Kerry King of Slayer" style="border:1px solid #222; padding:1px;" /&gt;&lt;br /&gt;
&lt;/center&gt;&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.csharptocsharp.com%2funit-test-datareader-with-mocks-and-stubs"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.csharptocsharp.com%2funit-test-datareader-with-mocks-and-stubs" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/RqlrWCkkRnM" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/unit-test-datareader-with-mocks-and-stubs#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/3">C#</category>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/20">Testing</category>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/16">Tools</category>
 <pubDate>Sat, 02 May 2009 08:36:17 -0600</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">31 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/unit-test-datareader-with-mocks-and-stubs</feedburner:origLink></item>
<item>
 <title>My Site's Analytics Graph as a Stock Graph</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/9VdVcGPLhMY/my-site-traffic-as-stock-graph</link>
 <description>&lt;p&gt;After looking at google analytics (ga) graphs all these months, I've come to the conclusion that &lt;b&gt;if my site's ga graph were that of a stock/eft/etc I'd be a &lt;b style="color:green;"&gt;RICH&lt;/b&gt; dude&lt;/b&gt;. I'm guessing you'd be too since it's not a terribly new phenomenon; &lt;b&gt;traffic or sales dropping off on the weekend&lt;/b&gt;. Akin to the turmoil on wall street, &lt;a rel="nofollow" href="http://www.google.com/search?q=afraid+hold+stocks+over+weekend"&gt;investors are often afraid to hold securities over the weekend&lt;/a&gt;. I don't blame them.&lt;/p&gt;
&lt;p&gt;But really &lt;a rel="nofollow" href="http://www.google.com/search?q=what+do+people+do+on+the+weekends"&gt;what do people do on the weekends&lt;/a&gt;? Beats me. I guess they don't read my blog! Granted it is &lt;em&gt;somewhat&lt;/em&gt; technical-related. I don't read anyone's on the w/e either so whatev.&lt;/p&gt;
&lt;p&gt;Ok, so here is the ga graph... (this is a snapshot from a month ago... by week)&lt;/p&gt;
&lt;p&gt;&lt;center&gt;&lt;img src="http://www.csharptocsharp.com/files/hottest-stock.jpg" alt="my site as stock graph" /&gt;&lt;/center&gt;&lt;/p&gt;
&lt;p&gt;I can assure you, this continues on for months...and months.... and months.&lt;/p&gt;
&lt;p&gt;"So what does this all mean?" you ask. Well, in the next highly technically list, I will tell you the secret to becoming rich in this psuedo website exchange.&lt;/p&gt;
&lt;p&gt;1. Know the future (which I &lt;i&gt;clearly&lt;/i&gt; know regarding this site's traffic)&lt;br /&gt;
2. Buy / Cover low.&lt;br /&gt;
3. Sell / Short high.&lt;/p&gt;
&lt;p&gt;&lt;center&gt;&lt;img src="http://www.csharptocsharp.com/files/hottest-stock-buy-sell.jpg" alt="short high, cover low" /&gt;&lt;/center&gt;&lt;br /&gt;
Here I've clearly laid out the points for which actions should be taken! Depending on your strategy, buying, shorting or &lt;i&gt;both&lt;/i&gt; (just not at the same time :)) you too can be richy!&lt;/p&gt;
&lt;p&gt;happy trading.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/9VdVcGPLhMY" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/my-site-traffic-as-stock-graph#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/1">General</category>
 <pubDate>Fri, 10 Apr 2009 06:42:58 -0600</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">30 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/my-site-traffic-as-stock-graph</feedburner:origLink></item>
<item>
 <title>Tips for Decreasing the Size of Dynamically Created HTML</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/xHJBJRZJYpc/tips-for-decreasing-size-dynamic-html-net</link>
 <description>&lt;p&gt;If you're like me, and make all of your data-related html bits yourself because you want full control of its output or you enjoy &lt;a href="http://www.codinghorror.com/blog/archives/001218.html" rel="nofollow"&gt;micro optimization&lt;/a&gt;... read on.&lt;/p&gt;
&lt;p&gt;You're doing your loop thing with your StringBuilder thing because your specs say all the data needs to be on the same page (no paging, more-data-as-you-scroll (or other ajax) [bad specs, eh? Or &lt;a href="http://www.codinghorror.com/blog/archives/001223.html" rel="nofollow"&gt;you're just doing it wrong&lt;/a&gt;]. &lt;/p&gt;
&lt;p&gt;You finally got your page finished, loaded and hot DAMN it's 950kb. That's CRAZY! You gotta do something about that! You'll definitely want to optimize the html that is created during the looping operation. You know, it looks something like this...&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;StringBuilder sb &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; StringBuilder&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
sb.&lt;span style="color: #0000FF;"&gt;Append&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;&amp;lt;table&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;for&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;int&lt;/span&gt; i&lt;span style="color: #008000;"&gt;=&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;0&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt; i&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;aZillion&lt;span style="color: #008000;"&gt;;&lt;/span&gt; i&lt;span style="color: #008000;"&gt;++&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
sb.&lt;span style="color: #0000FF;"&gt;Append&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;@&amp;quot;&amp;lt;tr class=&amp;quot;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;oddTableDataRow&amp;quot;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;&amp;gt;&amp;lt;td align=&amp;quot;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;center&amp;quot;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot; valign=&amp;quot;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;middle&amp;quot;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;&amp;gt;blah&amp;lt;/td&amp;gt;
&amp;lt;td class=&amp;quot;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;bottomBorderDarkest&amp;quot;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;&amp;gt;&amp;lt;strong&amp;gt;zonk&amp;lt;/strong&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
sb.&lt;span style="color: #0000FF;"&gt;Append&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;&amp;lt;/table&amp;gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Ok, so that was very simple. Obviously most cases are much more complicated, but still, it can be optimized. Some of these are general, others are very specific... some might not even be 100% html standards compliant. But hey, no one likes a slow loading page?&lt;/p&gt;
&lt;p&gt;here we go:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;middot; Make sure all css classes are actually used, and necessary.&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;middot; NO, I repeat, NO inline styles or style-like attributes. Everything should be done in your style sheet(s).&lt;/b&gt;&lt;br /&gt;
&lt;span style="text-decoration:line-through;"&gt;&lt;br /&gt;
sb.Append(@"&amp;lt;tr&amp;gt;&amp;lt;td width=""500"" align=""left"" valign=""top""&amp;gt;...);&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;middot; Use the smallest possible names for css classes, css ids, and javascript function names&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Instead of id="header" use id=hdr&lt;br /&gt;
Instead of class="topBorderNew" use class=tbn&lt;br /&gt;
Instead of SomeJsFunctionThatIsPairedWithEachRow(); use s();&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;middot; If you have to make words 'stand out,' use &amp;lt;b&amp;gt; instead of &amp;lt;strong&amp;gt;, it's shorter&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;b&amp;gt;a&amp;lt;/b&amp;gt; = 8 characters.&lt;br /&gt;
&amp;lt;strong&amp;gt;a&amp;lt;/strong&amp;gt; = 18 characters.&lt;/p&gt;
&lt;p&gt;We're on an html diet, so sorry semantics!&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;middot; use &amp;lt;i&amp;gt; instead of &amp;lt;em&amp;gt;&lt;/b&gt;&lt;br /&gt;
(same logic as above)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;middot; Use the innerHTML of a dropdown (&amp;lt;select&amp;gt;, rather than its value)&lt;/b&gt; (unless innerHTML and value are wildly different). &amp;lt;select&amp;gt; boxes are notorious for using up lots of Kbs.&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;middot; don't use double quotes (or any quotes for that matter).&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;img src=image.jpg /&amp;gt; rather than &amp;lt;img src="image.jpg" /&amp;gt;&lt;br /&gt;
&amp;lt;td class=blah&amp;gt; instead of &amp;lt;td class="blah"&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;middot; if you have lots of line breaks, use &amp;lt;br&amp;gt; instead of &amp;lt;br /&amp;gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;google does it all the time.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;middot; limit the use of &amp;lt;span&amp;gt; tags&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Use a parent container/selector to modify a would-be span-wrapped item.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;middot; Don't use an 'odd' and an 'even' class for row highlighting.&lt;/b&gt;&lt;br /&gt;
Use one of them. You pick. (You could argue that this can easily be done client-side, but with large datasets you will notice the striping applied &lt;i&gt;after&lt;/i&gt; the page is loaded.)&lt;/p&gt;
&lt;p&gt;With some of these strategies, I turned a 950kb dynamically-generated page into 603kb page. That's a 36% savings! You could argue that, it's still pretty hefty, or most of this now can be done client-side, or hey "use a templating language" dumbo... but it isn't always an option.&lt;/p&gt;
&lt;p&gt;&lt;center&gt;&lt;br /&gt;
&lt;h2&gt;$$cha-ching!$$&lt;/h2&gt;
&lt;p&gt;&lt;/center&gt;&lt;br /&gt;
&lt;center&gt;&lt;img src="/files/250px-Moneybillscoins3.jpg" alt="cha-ching!" align="center" /&gt;&lt;/center&gt;&lt;br /&gt;
&lt;br /&gt;
If you tried any of these and they worked for you, let me know how many kbs you saved! Or please give any of your own.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/xHJBJRZJYpc" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/tips-for-decreasing-size-dynamic-html-net#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/3">C#</category>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/10">HTML</category>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/9">Javascript</category>
 <pubDate>Sun, 15 Feb 2009 18:26:16 -0700</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">26 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/tips-for-decreasing-size-dynamic-html-net</feedburner:origLink></item>
<item>
 <title>Google's Font is smaller?</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/CMm_v1OI998/google-fonts-smaller</link>
 <description>&lt;p&gt;Is it me... or did today, about perhaps 2-3pm EST, google made all their fonts a tad bit smaller?&lt;/p&gt;
&lt;p&gt;UPDATE: I'm a dumbsky :)&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/CMm_v1OI998" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/google-fonts-smaller#comments</comments>
 <pubDate>Mon, 19 Jan 2009 16:48:57 -0700</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">28 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/google-fonts-smaller</feedburner:origLink></item>
<item>
 <title>OMG I could save if I bundle my services!?</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/tZh031p9KvU/save-with-bundling-your-services</link>
 <description>&lt;p&gt;Really? Yeah you bet!&lt;/p&gt;
&lt;p&gt;I usually just toss that junk snailmail from the cable/phone company, but this time, they made me a &lt;i&gt;special&lt;/i&gt; deal with part of my name in the url! We'll call this company pomcast (no disrespect to the real pomcast.com). I couldn't resist.&lt;/p&gt;
&lt;p&gt;Something like &lt;a href="http://www.mypomcastsavings.com/MYNAMEHERE0321" title="http://www.mypomcastsavings.com/MYNAMEHERE0321"&gt;http://www.mypomcastsavings.com/MYNAMEHERE0321&lt;/a&gt;... (like that sort of dynamic url has never been done before. dumbskys).&lt;/p&gt;
&lt;p&gt;So in my clicking around the site &lt;i&gt;specifically made for me&lt;/i&gt; and all my bundled needs, i noticed a nifty little savings calculator! &lt;/p&gt;
&lt;p&gt;Since I don't have cable (minus the ~8 channels that comes with my internet), I entered $59.00 for internet and $0.00 for telephone (mobile phone is all I need)...&lt;/p&gt;
&lt;p&gt;&lt;center&gt;&lt;img src="/files/images/monthlysavings2.jpg" /&gt;&lt;/center&gt;&lt;/p&gt;
&lt;p&gt;
And look at my savings...&lt;br /&gt;
&lt;center&gt;&lt;br /&gt;
&lt;img src="/files/images/monthlysavings1.jpg" style="border:2px dotted red;" /&gt;&lt;/center&gt;&lt;br /&gt;
&lt;br /&gt;
that's right, $-7.00. I would have the amazing privilege of paying them more per month for a service completely useless to me! &lt;b style="text-decoration:blink;color:red;"&gt;HOT&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Not a terribly great marketing tactic. &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/tZh031p9KvU" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/save-with-bundling-your-services#comments</comments>
 <pubDate>Sat, 03 Jan 2009 12:03:20 -0700</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">27 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/save-with-bundling-your-services</feedburner:origLink></item>
<item>
 <title>Dynamically Add UserControls based on the Request URL</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/VT4dAp5_tvw/dynamically-add-usercontrols-based-on-url</link>
 <description>&lt;p&gt;You have a data-driven site and you like to keep the number of .aspx files to a minimum, so you opt for UserControls. Ok cool!&lt;/p&gt;
&lt;p&gt;&lt;img src="/files/WebUserControlIcon.gif" alt="user controls are hot!" align="left" style="padding:2px;border:1px solid #777;margin:4px;" /&gt;Something you can do to be more dynamic-y is to name a UserControl the same as the requesting url, then check its existence on PageLoad. If it exists, load it into an asp:PlaceHolder control (or some other control). This can help keep your site more modular, and perhaps increase the chances that you'll reuse a UserControl in another project...or not.&lt;/p&gt;
&lt;p&gt;Here the UserControls are stored in the /UserControls/dynamic folder on my site. &lt;/p&gt;
&lt;p&gt;In your aspx page, we make an asp:PlaceHolder...&lt;/p&gt;
&lt;p&gt;&lt;span class="geshifilter"&gt;&lt;code class="geshifilter-csharp"&gt;&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;asp&lt;span style="color: #008000;"&gt;:&lt;/span&gt;PlaceHolder ID&lt;span style="color: #008000;"&gt;=&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;PHUserControls&amp;quot;&lt;/span&gt; runat&lt;span style="color: #008000;"&gt;=&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;asp&lt;span style="color: #008000;"&gt;:&lt;/span&gt;PlaceHolder&lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
And in code behind, on PageLoad... we make the path of the UserControl and see if it exists. If it does, we add it to the placeholder.&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;&lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; path &lt;span style="color: #008000;"&gt;=&lt;/span&gt; AppDomain.&lt;span style="color: #0000FF;"&gt;CurrentDomain&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;BaseDirectory&lt;/span&gt; &lt;span style="color: #008000;"&gt;+&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;UserControls&lt;span style="color: #008080; font-weight: bold;"&gt;\\&lt;/span&gt;dynamic&lt;span style="color: #008080; font-weight: bold;"&gt;\\&lt;/span&gt;&amp;quot;&lt;/span&gt; &lt;span style="color: #008000;"&gt;+&lt;/span&gt; PageUrl &lt;span style="color: #008000;"&gt;+&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;.ascx&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #0600FF;"&gt;if&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;File.&lt;span style="color: #0000FF;"&gt;Exists&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;path&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
Control c &lt;span style="color: #008000;"&gt;=&lt;/span&gt; LoadControl&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;~/UserControls/dynamic/&amp;quot;&lt;/span&gt; &lt;span style="color: #008000;"&gt;+&lt;/span&gt; PageUrl &lt;span style="color: #008000;"&gt;+&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;.ascx&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
PHUserControls.&lt;span style="color: #0000FF;"&gt;Controls&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;Add&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;c&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/VT4dAp5_tvw" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/dynamically-add-usercontrols-based-on-url#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/2">ASP.NET</category>
 <pubDate>Tue, 16 Dec 2008 20:47:05 -0700</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">24 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/dynamically-add-usercontrols-based-on-url</feedburner:origLink></item>
<item>
 <title>Beginning Extension Methods</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/fkAzm03QsiY/beginning-extension-methods</link>
 <description>&lt;p&gt;Extension methods have been around since C# 3.0 came out, which I guess was some time ago. I really like using them. The syntax is short and neat. Notice how the example below lives in a static class. Nutty eh!?&lt;/p&gt;
&lt;p&gt;This example is for all you foos out there that might not be checking input before it's passed down into the database. It checks the input string for null/empty and if there's something, it will replace a single quote with two single quotes (since the single quote is arguably the most devastating character in user inputs / SQL inserts)&lt;/p&gt;
&lt;pre&gt;
&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;   &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;static&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;class&lt;/span&gt; StringUtils
    &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;static&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; ToSafeSql&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0600FF;"&gt;this&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; s&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
            &lt;span style="color: #0600FF;"&gt;return&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;s &lt;span style="color: #008000;"&gt;==&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;null&lt;/span&gt; &lt;span style="color: #008000;"&gt;||&lt;/span&gt; s.&lt;span style="color: #0000FF;"&gt;Trim&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;Length&lt;/span&gt; &lt;span style="color: #008000;"&gt;==&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; 
            &lt;span style="color: #008000;"&gt;?&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;&amp;quot;&lt;/span&gt; 
            &lt;span style="color: #008000;"&gt;:&lt;/span&gt; s.&lt;span style="color: #0000FF;"&gt;Replace&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;'&amp;quot;&lt;/span&gt;, &lt;span style="color: #666666;"&gt;&amp;quot;''&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
    &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
 &lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/fkAzm03QsiY" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/beginning-extension-methods#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/3">C#</category>
 <pubDate>Sun, 14 Dec 2008 14:56:00 -0700</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">25 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/beginning-extension-methods</feedburner:origLink></item>
<item>
 <title>Intro to Pre-processing Directives</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/OHRI5wA2elA/pre-processor-directives-intro</link>
 <description>&lt;p&gt;So, I totally dig pre-processor directives. Use them all the time. Do you? I hope so! It can make a Debug build ready for a Release build with the change of a dropdown in Visual Studio.&lt;/p&gt;
&lt;p&gt;Here's an example to change the logPath string if you're building in Debug mode (or anything else). This could be very handy with &lt;a href="http://www.csharptocsharp.com/log4net-configuration-for-rockin-loggin-part-2"&gt;programmatically creating a log4net config&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;        &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; logPath&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #008080;"&gt;#if DEBUG&lt;/span&gt;
        logPath &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;@&amp;quot;C:\csharptocsharp.com\log.txt&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
&lt;span style="color: #008080;"&gt;#else&lt;/span&gt;
        logPath &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;@&amp;quot;Q:\sites\csharptocsharp.com\logs\log.txt&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;              
&lt;span style="color: #008080;"&gt;#endif&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;
Anyway, if you're not using preprocessor directives in your code, then what are you waiting for?&lt;br /&gt;
&lt;br /&gt;
Other References:&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/3sxhs2ty.aspx" rel="nofollow"&gt;MSDN Preprocessor directives&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/OHRI5wA2elA" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/pre-processor-directives-intro#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/3">C#</category>
 <pubDate>Mon, 08 Dec 2008 20:31:37 -0700</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">23 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/pre-processor-directives-intro</feedburner:origLink></item>
<item>
 <title>Log4Net Config to Make Your Log4Net Loggin' Kickin' [Part 2]</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/ydaidC5ilVs/log4net-configuration-for-rockin-loggin-part-2</link>
 <description>&lt;p&gt;&lt;img src="/files/images/logcutter.jpg" align="left" style="margin:5px; padding:3px; border:1px solid #777;" /&gt;So in my first &lt;a href="http://www.csharptocsharp.com/log4net-configuration-for-rockin-loggin"&gt;Log4Net Config&lt;/a&gt; post a weee time back, I talked about a hot way to configure your log4net settings using a composite, rolling logging model.&lt;/p&gt;
&lt;p&gt;Here, I have that same log4net config, but done in code! It doesn't have the same flexibility of the web.config or an xml file if you're frequently changing values--since you'd have to push code for any changes--but it does make any logic easier. &lt;/p&gt;
&lt;p&gt;It begs the usage of preprocessor directives for setting File [location], PatternLayout, or Threshold.&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;log4net.&lt;span style="color: #0000FF;"&gt;Appender&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;RollingFileAppender&lt;/span&gt; a &lt;span style="color: #008000;"&gt;=&lt;/span&gt; 
&lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; log4net.&lt;span style="color: #0000FF;"&gt;Appender&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;RollingFileAppender&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
a.&lt;span style="color: #0000FF;"&gt;Name&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;RollingFileAppender&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
a.&lt;span style="color: #0000FF;"&gt;File&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;@&amp;quot;c:\blah.com\log.txt&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
a.&lt;span style="color: #0000FF;"&gt;AppendToFile&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; true&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
a.&lt;span style="color: #0000FF;"&gt;RollingStyle&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; log4net.&lt;span style="color: #0000FF;"&gt;Appender&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;RollingFileAppender&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;RollingMode&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;Composite&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
a.&lt;span style="color: #0000FF;"&gt;MaxSizeRollBackups&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;14&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
a.&lt;span style="color: #0000FF;"&gt;CountDirection&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;1&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
a.&lt;span style="color: #0000FF;"&gt;MaximumFileSize&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;15000KB&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
a.&lt;span style="color: #0000FF;"&gt;StaticLogFileName&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; true&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
a.&lt;span style="color: #0000FF;"&gt;Layout&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; log4net.&lt;span style="color: #0000FF;"&gt;Layout&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;PatternLayout&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;@&amp;quot;{%level}%date{MM/dd HH:mm:ss} - %message%newline&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
a.&lt;span style="color: #0000FF;"&gt;ActivateOptions&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
a.&lt;span style="color: #0000FF;"&gt;Threshold&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; log4net.&lt;span style="color: #0000FF;"&gt;Core&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;Level&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;Debug&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
log4net.&lt;span style="color: #0000FF;"&gt;Config&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;BasicConfigurator&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;Configure&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;a&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;
(Thanks to my buddy J.A. for showing me this). &lt;/p&gt;
&lt;p&gt;Enjoy!&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.csharptocsharp.com%2flog4net-configuration-for-rockin-loggin-part-2"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.csharptocsharp.com%2flog4net-configuration-for-rockin-loggin-part-2" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/ydaidC5ilVs" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/log4net-configuration-for-rockin-loggin-part-2#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/16">Tools</category>
 <pubDate>Mon, 08 Dec 2008 20:03:52 -0700</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">22 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/log4net-configuration-for-rockin-loggin-part-2</feedburner:origLink></item>
<item>
 <title>The Magic Behind MVP / MVC Frameworks</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/rh4JpxwpJXQ/asp-net-mvp-and-mvc-magic</link>
 <description>&lt;p&gt;One of the things I learned at DevConnections 08 is the magic behind ASP.NET MVC, and how it actually works. Beside the UrlRouting (which you can do with HttpModule stuff), it's pretty easy and relies a lot on Activator.CreateInstance(). As seen in my post about &lt;a href="http://www.csharptocsharp.com/generate-csv-from-generic-list" target="_blank"&gt;creating a csv from list&lt;/a&gt;, you can read about it &lt;a href="http://msdn.microsoft.com/en-us/library/system.activator.createinstance.aspx" rel="nofollow"&gt;here&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;The magic is...shhh... &lt;/p&gt;
&lt;table border="0" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;blockquote&gt;&lt;p&gt;To programmatically create the worker class based on the url.&lt;/p&gt;&lt;/blockquote&gt;
&lt;/td&gt;
&lt;td&gt;&lt;img src="/files/images/magicwand.gif" alt="magic mvc" align="right" /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;Yeah, no-DUH you say. Well it took MS this long to come up with it for public consumption when MVC has been around for decades. Anyhooo.&lt;/p&gt;
&lt;p&gt;&lt;b style="color:#000;"&gt;NOTE:&lt;/b&gt; I'm more of an MVP guy, so this is geared toward using the MVP's Presenter rather than the MVC's Controller. They're similar patterns, 'cept MVP is a bit more decoupled (and deprecated...), so in my example below, you can replace 'Presenter' with 'Controller' if it makes you fuzzy, because really, that's where all the work gets done. &lt;/p&gt;
&lt;p&gt;Here we go.&lt;/p&gt;
&lt;p&gt;&lt;img src="/files/images/guitaronfire.jpg" alt="mvc is on fire!" align="left" style="padding:2px; border:1px solid #000; margin:5px;" /&gt;A request comes in for blah.com/hotguitars.aspx. Your UrlRouting can match the url up with the correct view [handler] and rewrite its path to &lt;i&gt;that&lt;/i&gt; page handler. In this case, I'd most likely use the DefaultView since the page lives off of the root (/).&lt;/p&gt;
&lt;p&gt;On PageLoad the presenter factory is going to take the url and try to figure out which class to instantiate [return] to make the contents for the view. Each of the classes returned implement Presenter, which implements IPresenter... so I can code to the interface, which is nicer. (Notice the interfaces. I'm an interface kinda dude, because they're hot when it comes to testing).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Ok, so here's the little POC for you.&lt;/p&gt;
&lt;p&gt;&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;    &lt;span style="color: #008080; font-style: italic;"&gt;// Presenter class implements this because all *Presenter&lt;/span&gt;
    &lt;span style="color: #008080; font-style: italic;"&gt;// classes need to have a DoIt() method&lt;/span&gt;
    &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;interface&lt;/span&gt; IPresenter
    &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;void&lt;/span&gt; DoIt&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
    &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;class&lt;/span&gt; Presenter &lt;span style="color: #008000;"&gt;:&lt;/span&gt; IPresenter
    &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; Presenter&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;virtual&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;void&lt;/span&gt; DoIt&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
    &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
    &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;class&lt;/span&gt; PresenterFactory
    &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; 
        &lt;span style="color: #008080; font-style: italic;"&gt;//return the url minus hyphens&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;private&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;static&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; GetPresenterName&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;Regex re, &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; url&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
            &lt;span style="color: #0600FF;"&gt;return&lt;/span&gt; re.&lt;span style="color: #0000FF;"&gt;Match&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;url&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;Groups&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;1&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#93;&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;Value&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;Replace&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;,&lt;span style="color: #666666;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
        &lt;span style="color: #008080; font-style: italic;"&gt;//get the url&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;private&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;static&lt;/span&gt; Regex rePage &lt;span style="color: #008000;"&gt;=&lt;/span&gt; 
&lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; Regex&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;@&amp;quot;/(.+?)\.aspx&amp;quot;&lt;/span&gt;, RegexOptions.&lt;span style="color: #0000FF;"&gt;IgnoreCase&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;This is the sexiness....&lt;/b&gt;&lt;br /&gt;
&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;static&lt;/span&gt; Presenter GetPresenter&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;Page page&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
            &lt;span style="color: #008080; font-style: italic;"&gt;// this is blah.com/hotguitars.aspx&lt;/span&gt;
            &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; rewrittenUrl &lt;span style="color: #008000;"&gt;=&lt;/span&gt; page.&lt;span style="color: #0000FF;"&gt;Request&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;RawUrl&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; presenterName &lt;span style="color: #008000;"&gt;=&lt;/span&gt; GetPresenterName&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;rePage, rewrittenUrl&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;    
            &lt;span style="color: #008080; font-style: italic;"&gt;//here is where you make sure you have a HotGuitarsPresenter&lt;/span&gt;
            &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; className &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;BunchaJunk.Presenters.&amp;quot;&lt;/span&gt; &lt;span style="color: #008000;"&gt;+&lt;/span&gt; presenterName &lt;span style="color: #008000;"&gt;+&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;Presenter&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            &lt;span style="color: #008080; font-style: italic;"&gt;// get the type, throw error, and ignore case&lt;/span&gt;
            Type type &lt;span style="color: #008000;"&gt;=&lt;/span&gt; Type.&lt;span style="color: #0000FF;"&gt;GetType&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;className, &lt;span style="color: #0600FF;"&gt;true&lt;/span&gt;, &lt;span style="color: #0600FF;"&gt;true&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            &lt;span style="color: #008080; font-style: italic;"&gt;// create an instance of the correct Presenter/Controller and return it&lt;/span&gt;
            &lt;span style="color: #0600FF;"&gt;return&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;Presenter&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;Activator.&lt;span style="color: #0000FF;"&gt;CreateInstance&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;type, &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="color: #008000;"&gt;new&lt;/span&gt;&lt;/a&gt; &lt;span style="color: #FF0000;"&gt;object&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#93;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; page &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
    &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
    &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;interface&lt;/span&gt; IBasicPage
    &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
        &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; HtmlTitle &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; get&lt;span style="color: #008000;"&gt;;&lt;/span&gt; set&lt;span style="color: #008000;"&gt;;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
        &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; HtmlMetaKeywords &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; get&lt;span style="color: #008000;"&gt;;&lt;/span&gt; set&lt;span style="color: #008000;"&gt;;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
        &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; HtmlMetaDescription &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; get&lt;span style="color: #008000;"&gt;;&lt;/span&gt; set&lt;span style="color: #008000;"&gt;;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
        &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; MainContent &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; get&lt;span style="color: #008000;"&gt;;&lt;/span&gt; set&lt;span style="color: #008000;"&gt;;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
    &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
    &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;class&lt;/span&gt; HotGuitarsPresenter &lt;span style="color: #008000;"&gt;:&lt;/span&gt; Presenter
    &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;private&lt;/span&gt; IBasicPage ibp&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; HotGuitarsPresenter&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;IBasicPage ibp&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
            &lt;span style="color: #0600FF;"&gt;this&lt;/span&gt;.&lt;span style="color: #0000FF;"&gt;ibp&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; ibp&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;override&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;void&lt;/span&gt; DoIt&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
            ibp.&lt;span style="color: #0000FF;"&gt;HtmlMetaDescription&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;Hot stuff!&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            ibp.&lt;span style="color: #0000FF;"&gt;HtmlMetaKeywords&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;jackson, paul reed smith&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            ibp.&lt;span style="color: #0000FF;"&gt;HtmlTitle&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;Here are the hottest guitars at csharptocsharp!&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            ibp.&lt;span style="color: #0000FF;"&gt;MainContent&lt;/span&gt; &lt;span style="color: #008000;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;"&gt;&amp;quot;paul reed smith, jackson, gibson&amp;quot;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
    &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Here is how it is called from aspx code behind&lt;/b&gt;&lt;br /&gt;
&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;    &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;partial&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;class&lt;/span&gt; _Default &lt;span style="color: #008000;"&gt;:&lt;/span&gt; Page, IBasicPage
    &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;  
        &lt;span style="color: #0600FF;"&gt;protected&lt;/span&gt; &lt;span style="color: #0600FF;"&gt;void&lt;/span&gt; Page_Load&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;object&lt;/span&gt; sender, EventArgs e&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;
            &lt;span style="color: #008080; font-style: italic;"&gt;//coding to the interface is the cat's meoooooooooooow&lt;/span&gt;
            IPresenter p &lt;span style="color: #008000;"&gt;=&lt;/span&gt; PresenterFactory.&lt;span style="color: #0000FF;"&gt;GetPresenter&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0600FF;"&gt;this&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
            p.&lt;span style="color: #0000FF;"&gt;DoIt&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #008000;"&gt;;&lt;/span&gt;
        &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; HtmlTitle &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; get&lt;span style="color: #008000;"&gt;;&lt;/span&gt; set&lt;span style="color: #008000;"&gt;;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; HtmlMetaKeywords&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;get&lt;span style="color: #008000;"&gt;;&lt;/span&gt;set&lt;span style="color: #008000;"&gt;;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; HtmlMetaDescription &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt; get&lt;span style="color: #008000;"&gt;;&lt;/span&gt; set&lt;span style="color: #008000;"&gt;;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
        &lt;span style="color: #0600FF;"&gt;public&lt;/span&gt; &lt;span style="color: #FF0000;"&gt;string&lt;/span&gt; MainContent&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;get&lt;span style="color: #008000;"&gt;;&lt;/span&gt;set&lt;span style="color: #008000;"&gt;;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;
    &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Here is how it's used in the aspx&lt;/b&gt;&lt;br /&gt;
&lt;div class="geshifilter"&gt;&lt;pre class="csharp geshifilter-csharp" style="font-family:monospace;"&gt;&lt;span style="color: #008000;"&gt;&amp;lt;&lt;/span&gt;title&lt;span style="color: #008000;"&gt;&amp;gt;&amp;lt;%=&lt;/span&gt;HtmlTitle&lt;span style="color: #008000;"&gt;%&amp;gt;&amp;lt;/&lt;/span&gt;title&lt;span style="color: #008000;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;That is all!&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.csharptocsharp.com%2fasp-net-mvp-and-mvc-magic"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.csharptocsharp.com%2fasp-net-mvp-and-mvc-magic" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/rh4JpxwpJXQ" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/asp-net-mvp-and-mvc-magic#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/2">ASP.NET</category>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/3">C#</category>
 <pubDate>Sun, 07 Dec 2008 09:52:14 -0700</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">21 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/asp-net-mvp-and-mvc-magic</feedburner:origLink></item>
<item>
 <title>Ubuntu 8.10 / Vista and VMWare Fusion</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/YT40yKKm9-M/ubuntu-and-vista-with-vmware-fusion</link>
 <description>&lt;p&gt;Since I'm a .NET dude, you might find this post a wee bit odd, because, I should worship MS, right?... well I don't :), so in any case...&lt;/p&gt;
&lt;p&gt;&lt;img src="/files/images/i-dont-care.jpg" alt=""/&gt;&lt;/p&gt;
&lt;p&gt;Hokay. So...&lt;/p&gt;
&lt;p&gt;I recently made the jump to be *that* much closer to an &lt;a href="http://www.apple.com/macosx/technology/unix.html" rel="nofollow"&gt;all-unix setup&lt;/a&gt; [at home]. I've had my macbook now for about a year, and it's totally dope, I love it. In fact, I just got 4 gigs of ram for $35 beans from newegg.com. &lt;/p&gt;
&lt;p&gt;&lt;img src="/files/images/vmware.png" alt="vmware rocks!" align="right" style="padding:5px;" /&gt; The reason why I got that hot upgrade was because of the &lt;a href="http://www.vmware.com/products/fusion/" rel="nofollow"&gt;VMWare Fusion&lt;/a&gt; trial I had just decided to checkout. &lt;/p&gt;
&lt;p&gt;Now, I'm very familiar with VMWare and its hotness. I used VMWare server on Ubuntu for some years as a way to tinker with a bunch of Unix and Linux OSes. &lt;/p&gt;
&lt;p&gt;After DLing and messing around with it out for some time, (I used it at DevConnections Vegas 08) I knew that hog had to be mine! After turning my boot camped-Vista-partition into a virtual machine I soon realized that it was worth every penny. Twas always such a pain to have to reboot just to tinker with some idea in Visual Studio for five minutes. Just need to find a replacement for Texter (Spotlight is a great replacement for Launchy).&lt;/p&gt;
&lt;p&gt;&lt;img src="/files/images/ubuntu.png" alt="ubuntu rocks!" align="left" style="padding:10px;" /&gt;  On that note.... a couple weeks ago I setup my older ASUS Pundit-R barebones machine to run the latest version of Ubuntu (8.10 as of today)... and it flies. With a P4 chip, 1 gig of ram, and some low-end NVidia card, it's totally acceptable for doing most webby stuff. I haven't rally monkeyed with Ubuntu since Dapper/Edgy, but I can say it has come a long way since I started w/Hoary.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/YT40yKKm9-M" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/ubuntu-and-vista-with-vmware-fusion#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/19">OSX</category>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/15">Ubuntu</category>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/17">Vista</category>
 <pubDate>Sat, 06 Dec 2008 15:35:38 -0700</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">20 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/ubuntu-and-vista-with-vmware-fusion</feedburner:origLink></item>
<item>
 <title>Fix WordPress Blank Screen [of DEATH!] After Upgrade</title>
 <link>http://feedproxy.google.com/~r/CSharpToCSharp/~3/u35WUjHKYNQ/wordpress-blank-screen-fix-upgrade</link>
 <description>&lt;p&gt;You have a site, a blog, a something. And you're using WordPress. Ok, that's cool. It's free and nifty, but you &lt;b&gt;HAVE&lt;/b&gt; to keep it up-to-date. Nutty hackers and their b0ts are all over the net, HOPING people like YOU don't upgrade your site(s). &lt;/p&gt;
&lt;p&gt;So after that warning, you want to upgrade to the latest version of WordPress. You upload your junk and go to your site and BOOM! Blank screen.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Make sure your wp-config.php file has no white space(s) after the closing ?&amp;gt; mark.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ok fixed that...&lt;/p&gt;
&lt;p&gt;Next you try to login... and WHAMMMMMM! You're bounced back to the login screen. No errors, no messages in the UI... nuttin.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Make sure that the wp-content/plugins folder has been renamed to something else, like wp-content/plugins_butt&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once you have logged in, rename that folder back to 'plugins' (you can also turn off the active plugins in the db, but it requires that you save its contents)&lt;/p&gt;
&lt;p&gt;Those things helped me, I hope it helps you too!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/CSharpToCSharp/~4/u35WUjHKYNQ" height="1" width="1"/&gt;</description>
 <comments>http://www.csharptocsharp.com/wordpress-blank-screen-fix-upgrade#comments</comments>
 <category domain="http://www.csharptocsharp.com/taxonomy/term/5">PHP</category>
 <pubDate>Sat, 06 Dec 2008 14:55:31 -0700</pubDate>
 <dc:creator>brian</dc:creator>
 <guid isPermaLink="false">19 at http://www.csharptocsharp.com</guid>
<feedburner:origLink>http://www.csharptocsharp.com/wordpress-blank-screen-fix-upgrade</feedburner:origLink></item>
</channel>
</rss>
