<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>C# By Design - A Programmers Adventure</title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/" />
    <link rel="self" type="application/atom+xml" href="http://www.csharpbydesign.com/atom.xml" />
    <id>tag:www.csharpbydesign.com,2008-12-07://2</id>
    <updated>2011-12-21T22:21:51Z</updated>
    <subtitle>This blog is all about.. well, whatever I decide that it&apos;s about !  Sometimes I like to write about programming, technology, politics, my mood -- really, it&apos;s whatever strikes me at the moment.  Primarily, I&apos;ll be writing about C# programming!</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.23-en</generator>

<entry>
    <title><![CDATA[Devart&rsquo;s SQL Complete&ndash;A Fantastic Tool!]]></title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2011/12/devarts-sql-completea-fantastic-tool.html" />
    <id>tag:www.csharpbydesign.com,2011://2.37</id>

    <published>2011-12-21T22:21:49Z</published>
    <updated>2011-12-21T22:21:51Z</updated>

    <summary>Blah, blah, blah.. I haven’t been blogging in forever I hear you say. Well, as is with just about everyone – I’ve been busy.&#160; The new job panned out extremely well and I’m very happy and otherwise have been tied...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>Blah, blah, blah.. I haven’t been blogging in forever I hear you say. Well, as is with just about everyone – I’ve been busy.&#160; The new job panned out extremely well and I’m very happy and otherwise have been tied up working hard.&#160; Life is good.</p>  <p>So I discovered a new tool recently called SQL Complete by Devart.&#160; Now, if you know anything about them.. they make pretty good products and also have reasonable prices.&#160; I’ve been using their free version of CodeCompare for quite awhile now with Visual Studio and it’s miles above others that I’ve tried (esp. the built on TFS comparison tool!).&#160; So their software quality is definitely high!</p>  <p>And that brings us to SQL Complete – I’ve been trying out this application and it’s definitely a metric ton better than the built in IntelliSense in SSMS – not only does it update and improve SSMS, it also integrates into Visual Studio (2010, though others are supported).</p>  <p>One feature in particular that I find absolutely terrific – you can configure document formatting!&#160; I work with a lot of ugly stored procedures – and with a simple command, it pretties up my SQL.</p>  <p>The only complaint that I have so far (and I haven’t reported this to support) is that it appends “dbo.'” in front of everything, regardless of the option I select.&#160; Otherwise, I don’t have a single complaint.&#160; It’s really nice having a complete list of columns/tables/etc. popup while I’m typing, with field types and lengths.&#160; SQL Complete beats the built in SSMS IntelliSense, hands down.</p>  <p>All-in-all, SQL Complete is a great tool and I whole heartedly recommend it.&#160; Their free version doesn’t have all of the bells and whistles of the paid ($99) version, but definitely assists.&#160; One of my favorite features – you can configure the time to display its IntelliSense !&#160; Without, SSMS would freqently pop-up the wrong thing at the wrong time immediately after typing something.&#160; With the configuration settings in SQL Complete you’re able to control that.</p>  <p>I’m definitely adding this to my useful tools list, and I wish I could afford all of their <strong><em>other</em></strong> tools (Query Builder, Schema/Data Compare, Data Studio, I’m looking at you guys!).</p>  <p>URL: <a href="http://www.devart.com/dbforge/sql/sqlcomplete/">http://www.devart.com/dbforge/sql/sqlcomplete/</a></p>  <p>- Matthew</p>]]>
        
    </content>
</entry>

<entry>
    <title>LINQBugging - Using LINQPad For WinForms Testing</title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2009/07/linqbugging---using-linqpad-for-winforms-testing.html" />
    <id>tag:www.csharpbydesign.com,2009://2.36</id>

    <published>2009-07-17T02:42:00Z</published>
    <updated>2011-12-28T15:46:55Z</updated>

    <summary><![CDATA[Did you know that you can use LINQPad to test your WinForms app while you're doing development, and easily ?&nbsp; I don't think that this is a feature that's widely used (and in fact, I don't think that the author...]]></summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>Did you know that you can use <a href="http://www.linqpad.net" target="_blank">LINQPad</a> to test your WinForms app while you're doing development, and easily ?&nbsp; I don't think that this is a feature that's widely used (and in fact, I don't think that the author himself thought of that idea!&nbsp; ::grins, hi Joe!::) while using LINQPad.&nbsp; </p>  <p>So, how do you do it ?</p>  <p>Right click in your query window and select Advanced Properties.&nbsp; On the Additional References tab select "Add" and then "Browse".&nbsp; Find the assembly that you wish to test.&nbsp; Also make sure you add any other necessary assemblies, and especially System.Windows.Forms.dll.&nbsp; You'll then want to switch to the Additional Namespace Imports tab and type in the Namespace of your assembly that you wish to test, so that you'll have IntelliSense.&nbsp; <br />*&nbsp; <strong>Important Note:&nbsp; Make sure you list your namespaces in the "most dependant ones last."&nbsp; i.e., start with System.Windows.Forms so that you'll get proper IntelliSense.</strong></p>  <p>Now, with something similar to the following code (make sure to switch the language to C# Program and put this in the Main {} method):</p>  <p>using(MyFormThatIWantToTest myForm = new MyFormThatIWantToTest()) {   <br />&nbsp; myForm.ShowInTaskbar = true;    <br />&nbsp; myForm.ShowDialog();    <br />}</p>  <p>It's important to set your form to show in the taskbar because if you open it as a Dialog without, it will be very easy for you to lose you form.&nbsp; The reason for opening it as a Dialog.. if you don't, the form will immediately close.</p>  <p>You can use this technique (I call it "LINQBugging") to test a lot of different scenarios and in some cases, save yourself a lot of time.&nbsp; Why does this save you time ?&nbsp; You can jump straight to your form/dialog without having to go through any unnecessary steps that you might otherwise if you launch your application directly, or from Visual Studio.&nbsp; I use this technique all the time.&nbsp; Couple this with <a href="http://hawkeye.codeplex.com/" target="_blank">Hawkeye</a> to quickly prototype and test forms within your application and bypass the tedious navigation and security of your application to get there.</p>  <p>Also, make sure you open up your project in Visual Studio!&nbsp; You can make changes and recompile your application and then execute (something similar to the above code) your LINQPad "Query" again.&nbsp; One note, you need to close you form if you have it opened with LINQPad, otherwise the executable will become locked.&nbsp; After that, once you make changes to your source code and recompile, LINQPad will execute the new code the next time you run the "query".</p>  <p>There are a lot of other things that you can do with this technique.. testing libraries, writing test procedures, etc.&nbsp; Now that you know how to do this, what other tips and tricks do you have that I haven't thought of ?</p>  <p>* Note:&nbsp; Yes, you can have a lot of fun with applications that aren't your own.. a little Reflector, and a little LINQPad can go a long way.&nbsp; Don't abuse it. :)</p>  <p>Thanks for reading,</p>  <p>Matthew MacSuga</p>]]>
        
    </content>
</entry>

<entry>
    <title><![CDATA[Reflection based IEnumerable&lt;T&gt; TrimAll() function]]></title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2009/07/reflection-based-ienumerablet-trimall-function.html" />
    <id>tag:www.csharpbydesign.com,2009://2.35</id>

    <published>2009-07-16T03:50:34Z</published>
    <updated>2009-07-16T03:50:39Z</updated>

    <summary>Sorry for the too-long delay in updating my blog.&#160; As usual, I’ve been pretty busy with a lot of things lately!! … you know, with the new job, summer activities, reading books.. stuff you probably don’t care a lot about.&#160;...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>Sorry for the too-long delay in updating my blog.&#160; As usual, I’ve been pretty busy with a lot of things lately!! … you know, with the new job, summer activities, reading books.. stuff you probably don’t care a lot about.&#160; </p>  <p>Today’s entry is going to deal with a pretty snazzy function I wrote as an Extension method called TrimAll().&#160; This extension method is used when I’m gathering data from a database that has a lot of CHAR(x) fields in it and I’d rather not deal with space padding cluttering my code or UI’s.</p>  <div style="font-family: fixedsys; background: black; color: #e0e0e0; font-size: 8pt">   <pre style="margin: 0px"><span style="color: #adadad">///</span><span style="color: #ff80c0"> </span><span style="color: #adadad">&lt;summary&gt;</span></pre>

  <pre style="margin: 0px"><span style="color: #adadad">///</span><span style="color: #ff80c0"> Dictionary that serves as a cache for cached PropertyInfo[] arrays</span></pre>

  <pre style="margin: 0px"><span style="color: #ff80c0"></span><span style="color: #adadad">///</span><span style="color: #ff80c0"> </span><span style="color: #adadad">&lt;/summary&gt;</span></pre>

  <pre style="margin: 0px"><span style="color: #40c4ff">static</span> <span style="color: #66cdaa">Dictionary</span><span style="color: silver">&lt;</span><span style="color: #66cdaa">Type</span>, <span style="color: #66cdaa">PropertyInfo</span>[]<span style="color: silver">&gt;</span> <span style="color: white">trimCache</span>;</pre>

  <pre style="margin: 0px"><span style="color: #adadad">///</span><span style="color: #ff80c0"> </span><span style="color: #adadad">&lt;summary&gt;</span></pre>

  <pre style="margin: 0px"><span style="color: #adadad">///</span><span style="color: #ff80c0"> This function trims all public properties on an Enumerable object </span></pre>

  <pre style="margin: 0px"><span style="color: #adadad">///</span><span style="color: #ff80c0"> except those specified as optional parameters</span></pre>

  <pre style="margin: 0px"><span style="color: #adadad">///</span><span style="color: #ff80c0"> </span><span style="color: #adadad">&lt;/summary&gt;</span></pre>

  <pre style="margin: 0px"><span style="color: #adadad">///</span><span style="color: #ff80c0"> </span><span style="color: #adadad">&lt;typeparam name=&quot;T&quot;&gt;</span><span style="color: #ff80c0">The type of object</span><span style="color: #adadad">&lt;/typeparam&gt;</span></pre>

  <pre style="margin: 0px"><span style="color: #adadad">///</span><span style="color: #ff80c0"> </span><span style="color: #adadad">&lt;param name=&quot;sourceList&quot;&gt;</span><span style="color: #ff80c0">A list of items</span><span style="color: #adadad">&lt;/param&gt;</span></pre>

  <pre style="margin: 0px"><span style="color: #adadad">///</span><span style="color: #ff80c0"> </span><span style="color: #adadad">&lt;param name=&quot;ignoredFields&quot;&gt;P</span><span style="color: #ff80c0">rops that should not be trimmed</span><span style="color: #adadad">&lt;/param&gt;</span></pre>

  <pre style="margin: 0px"><span style="color: #adadad">///</span><span style="color: #ff80c0"> </span><span style="color: #adadad">&lt;returns&gt;</span><span style="color: #ff80c0">A cleaned up list with all string padding removed</span><span style="color: #adadad">&lt;/returns&gt;</span></pre>

  <pre style="margin: 0px"><span style="color: #40c4ff">public</span> <span style="color: #40c4ff">static</span> <span style="color: #2b91af">List</span><span style="color: silver">&lt;</span><span style="color: white">T</span><span style="color: silver">&gt;</span> <span style="color: white">TrimAll</span><span style="color: silver">&lt;</span><span style="color: white">T</span><span style="color: silver">&gt;</span>(<span style="color: #40c4ff">this</span> <span style="color: #2b91af">IEnumerable</span><span style="color: silver">&lt;</span><span style="color: white">T</span><span style="color: silver">&gt;</span> <span style="color: white">sourceList</span>, </pre>

  <pre style="margin: 0px"><span style="color: #40c4ff">params</span> <span style="color: #40c4ff">string</span>[] <span style="color: white">ignoredFields</span>)</pre>

  <pre style="margin: 0px">{&#160;&#160;&#160;&#160;&#160;&#160;&#160; </pre>

  <pre style="margin: 0px">&#160; <span style="color: #40c4ff">if</span> (<span style="color: white">trimCache</span> <span style="color: silver">==</span> <span style="color: #40c4ff">null</span>)</pre>

  <pre style="margin: 0px">&#160;&#160;&#160; <span style="color: white">trimCache</span> <span style="color: silver">=</span> <span style="color: #40c4ff">new</span> <span style="color: #66cdaa">Dictionary</span><span style="color: silver">&lt;</span><span style="color: #66cdaa">Type</span>, <span style="color: #66cdaa">PropertyInfo</span>[]<span style="color: silver">&gt;</span>();</pre>

  <pre style="margin: 0px">&#160;</pre>

  <pre style="margin: 0px">&#160; <span style="color: gray">//&#160; The list that we will be returning</span></pre>

  <pre style="margin: 0px">&#160; <span style="color: #66cdaa">List</span><span style="color: silver">&lt;</span><span style="color: white">T</span><span style="color: silver">&gt;</span> <span style="color: white">rList</span> <span style="color: silver">=</span> <span style="color: #40c4ff">new</span> <span style="color: #66cdaa">List</span><span style="color: silver">&lt;</span><span style="color: white">T</span><span style="color: silver">&gt;</span>();</pre>

  <pre style="margin: 0px">&#160;</pre>

  <pre style="margin: 0px">&#160; <span style="color: gray">//&#160; Added for performance</span></pre>

  <pre style="margin: 0px">&#160; <span style="color: #66cdaa">PropertyInfo</span>[] <span style="color: white">props</span> <span style="color: silver">=</span> <span style="color: #40c4ff">null</span>;</pre>

  <pre style="margin: 0px">&#160;</pre>

  <pre style="margin: 0px">&#160; <span style="color: gray">//&#160; Try to get a value from the dictionary if it exists</span></pre>

  <pre style="margin: 0px">&#160; <span style="color: #40c4ff">if</span> (<span style="color: silver">!</span><span style="color: white">trimCache</span><span style="color: silver">.</span><span style="color: white">TryGetValue</span>(<span style="color: #40c4ff">typeof</span>(<span style="color: white">T</span>), <span style="color: #40c4ff">out</span> <span style="color: white">props</span>)) </pre>

  <pre style="margin: 0px">&#160; {</pre>

  <pre style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">//&#160; Get the properties for the type</span></pre>

  <pre style="margin: 0px">&#160;&#160;&#160; <span style="color: white">props</span> <span style="color: silver">=</span> <span style="color: #40c4ff">typeof</span>(<span style="color: white">T</span>)</pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: silver">.</span><span style="color: white">GetProperties</span>()</pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: silver">.</span><span style="color: white">Where</span>(<span style="color: white">c</span> <span style="color: silver">=&gt;</span> <span style="color: silver">!</span><span style="color: white">ignoredFields</span><span style="color: silver">.</span><span style="color: white">Contains</span>(<span style="color: white">c</span><span style="color: silver">.</span><span style="color: white">Name</span>) <span style="color: silver">&amp;&amp;</span> </pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: white">c</span><span style="color: silver">.</span><span style="color: white">CanWrite</span> <span style="color: silver">&amp;&amp;</span> </pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: white">c</span><span style="color: silver">.</span><span style="color: white">PropertyType</span> <span style="color: silver">==</span> <span style="color: #40c4ff">typeof</span>(<span style="color: white">System</span><span style="color: silver">.</span><span style="color: #66cdaa">String</span>))</pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: silver">.</span><span style="color: white">ToArray</span>();</pre>

  <pre style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">//&#160; Add it to the array</span></pre>

  <pre style="margin: 0px">&#160;&#160;&#160; <span style="color: white">trimCache</span><span style="color: silver">.</span><span style="color: white">Add</span>(<span style="color: #40c4ff">typeof</span>(<span style="color: white">T</span>), <span style="color: white">props</span>);</pre>

  <pre style="margin: 0px">&#160; }</pre>

  <pre style="margin: 0px">&#160;</pre>

  <pre style="margin: 0px">&#160; <span style="color: gray">//&#160; Iterate over each item in the source list</span></pre>

  <pre style="margin: 0px">&#160; <span style="color: #40c4ff">foreach</span> (<span style="color: white">T</span> <span style="color: white">obj</span> <span style="color: #40c4ff">in</span> <span style="color: white">sourceList</span>) </pre>

  <pre style="margin: 0px">&#160; {</pre>

  <pre style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">//&#160; Iterate over each of the filtered properties</span></pre>

  <pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #40c4ff">for</span> (<span style="color: #40c4ff">int</span> <span style="color: white">i</span> <span style="color: silver">=</span> <span style="color: #60ff60">0</span>; <span style="color: white">i</span> <span style="color: silver">&lt;</span> <span style="color: white">props</span><span style="color: silver">.</span><span style="color: white">Length</span>; <span style="color: white">i</span><span style="color: silver">++</span>) </pre>

  <pre style="margin: 0px">&#160;&#160;&#160; {</pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160; <span style="color: gray">//&#160; Get the value </span></pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160; <span style="color: #40c4ff">string</span> <span style="color: white">o</span> <span style="color: silver">=</span> (<span style="color: #40c4ff">string</span>)<span style="color: white">props</span>[<span style="color: white">i</span>]<span style="color: silver">.</span><span style="color: white">GetValue</span>(<span style="color: white">obj</span>, <span style="color: #40c4ff">null</span>);</pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160; <span style="color: gray">//&#160; If it's not null, .Trim() it, otherwise leave it alone</span></pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160; <span style="color: #40c4ff">if</span> (<span style="color: white">o</span> <span style="color: silver">!=</span> <span style="color: #40c4ff">null</span>)</pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; (<span style="color: white">props</span>[<span style="color: white">i</span>])<span style="color: silver">.</span><span style="color: white">SetValue</span>(<span style="color: white">obj</span>, <span style="color: white">o</span><span style="color: silver">.</span><span style="color: white">TrimEnd</span>(</pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #60ff60">' '</span>, </pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #60ff60">'\t'</span>, </pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #60ff60">'\n'</span>, </pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #60ff60">'\v'</span>, </pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #60ff60">'\f'</span>, </pre>

  <pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #60ff60">'\r'</span>), <span style="color: #40c4ff">null</span>);</pre>

  <pre style="margin: 0px">&#160;&#160;&#160; }</pre>

  <pre style="margin: 0px">&#160;</pre>

  <pre style="margin: 0px">&#160;&#160;&#160; <span style="color: gray">//&#160; Add to the list</span></pre>

  <pre style="margin: 0px">&#160;&#160;&#160; <span style="color: white">rList</span><span style="color: silver">.</span><span style="color: white">Add</span>(<span style="color: white">obj</span>);</pre>

  <pre style="margin: 0px">&#160; }</pre>

  <pre style="margin: 0px">&#160;</pre>

  <pre style="margin: 0px">&#160; <span style="color: gray">//&#160; Return the list!</span></pre>

  <pre style="margin: 0px">&#160; <span style="color: #40c4ff">return</span> <span style="color: white">rList</span>;</pre>

  <pre style="margin: 0px">}</pre>
</div>

<p>&#160;</p>

<p>So, there you have it.&#160; I did do a bit of editing to make this fit within the constraints of my blog theme, but you should get the idea.</p>

<p>Explanation:</p>

<p>1.&#160; I created a Dictionary of type Dictionary&lt;Type,PropertyInfo[]&gt; to improve performance of the TrimAll function on subsequent calls.&#160; The first call will grab all of the public <em><strong>string</strong></em> properties of the input enumerable object and cache the reflection for future uses.</p>

<p>2.&#160; When the function is called, it checks to see if the type of the current object &lt;T&gt; has already been entered into the cache.&#160; For this, I use the TryGetValue object on the Dictionary class.&#160; This is a very handy function that will return true/false if the Key is present in the dictionary.&#160; In this case, the Type of the object is the key.&#160; If the value is not present in the dictionary, then it will be created and added to the dictionary.</p>

<p>3.&#160; You’ll notice that I’m using LINQ to search through all of the public properties of the source type.&#160; I am also <em>filtering</em> the list if there are any optional string parameters passed in for properties that you would not want filtered.. as well as making sure that the property is writable, and that it is a string.</p>

<p>4.&#160; Once the PropertyInfo[] props object is populated it is added to the cache for future use.</p>

<p>5.&#160; With the new array of PropertyInfo objects for the source list, I start iterating over each object in the list.&#160; For each object, I iterate over each item in the props[] array.&#160; If the value is not null I update the Property in the object with a Trimmed version of the string.&#160; You’ll notice that I am using “TrimEnd” with the specific fields I want to have trimmed explicitly specified.&#160; I’m doing this to save a little bit of processing time and make the function slightly more efficient.&#160; If you look at the TrimEnd method in Reflector, you’ll notice that it would cause several more iterations over each character.. this way I am saving those extra cycles.</p>

<p>6.&#160; Finally, the updated object is added to the storage List&lt;T&gt; (rList) and returned to the calling function.</p>

<p>I hope you find this as useful as I have.. it’s saved me quite a few headaches and it’s nice having an easy way to Trim all of the values from my database in one fell swoop.</p>

<p>Usage:
  <br /></p>

<blockquote>
  <p>using(…DataContext dc = new …DataContext()) {
    <br />&#160; // With a Stored Procedure

    <br />&#160; var dataList = dc.spSomeSproc().TrimAll();

    <br />&#160; // 

    <br />&#160; var dataList2 = myTable.Where(c =&gt; c.SomeVal == “SearchVal”).TrimAll();

    <br />}</p>
</blockquote>

<p>
  <br />One of the nice features of this function is that it saves you the extra step of converting your returned Enumerable sequence to a List using .ToList().&#160; I don’t know about you, but I quite often find myself doing that.&#160; Of course, if your database is “normal” and isn’t full of CHAR fields (vs. VARCHAR) then you won’t have to worry about this at all.&#160; </p>

<p>Knowing that most people probably don’t worry about CHAR fields, I still thought this made a nice blog post given that I am a huge fan of Reflection and finding neat ways to solve problems using it.&#160; As usual, YMMV.</p>

<p><strong>Question:&#160; Do you think there is anyway to optimize this method further ?</strong></p>

<p>Thanks for reading!</p>

<p>P.S.&#160; You can now find me on Twitter.&#160; Link:&#160; <a href="http://www.twitter.com/csharpbydesign" target="_blank">http://www.twitter.com/csharpbydesign</a></p>

<p>Matthew MacSuga</p>]]>
        
    </content>
</entry>

<entry>
    <title>LINQ-To-SQL: Updating Disconnected Entity Objects</title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2009/02/linq-to-sql-updating-disconnected-entity-objects.html" />
    <id>tag:www.csharpbydesign.com,2009://2.34</id>

    <published>2009-02-10T06:31:14Z</published>
    <updated>2009-02-10T06:31:18Z</updated>

    <summary>Here’s the skinny:&#160; Don’t get into a situation where you have to update an object from a disconnected DataContext.&#160; You will fail, and miserably. Sure, you can do some Googling and find some resources on the subject, and even find...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>Here’s the skinny:&#160; Don’t get into a situation where you have to update an object from a disconnected DataContext.&#160; You will fail, and miserably.</p>  <p>Sure, you can do some Googling and find some resources on the subject, and even find some slightly tolerable solutions.. but even those require some nasty stuff, some hard coding of methods in the DataContext class itself, and/or adding versioning field to your database table.</p>  <p>Google:&#160; “linq disconnected updates” and “LINQ Update Disconnected Entity Objects” </p>  <p>The best solution that I found, that worked for me – was a bit more of tightly coupling what was happening, and passing around an open DataContext from start-to-finish through the various methods.</p>  <p>It seems to me that the best way would be something hypothetical like this:</p>  <blockquote>   <p>[your]DataContext.Update&lt;[YourTable]&gt;([YourEntityObject]);     <br />[your]DataContext.SubmitChanges();</p> </blockquote>  <p>Of course, that “Update” method doesn’t exist, only the “Attach” method that seems like it should do what we want, but doesn’t really.&#160; The “Update” method of course, would update using only the primary key of the entity to perform the update.&#160; I suppose I see why this might not exist due to complications with child entity objects.</p>  <p>The other alternative AFAIK is to create a CopyFromEntityToEntity extension method or class method to copy from the object you wish to update, to an object acquired from the database during the update method.&#160; Something like the following:</p>  <blockquote>   <p>//Warning, this is pseduo-code and will not work for various reasons and should be a generic method.&#160; This also assumes the PK is a GUID[uniqueidentifier] field.&#160; There is no error checking, etc.     <br />void Update(orders_mainTable updateEntity, Guid identifier) {      <br />&#160; myDataContext dc = new myDataContext();      <br />&#160;&#160; <br />&#160; var original = dc.Table.Where(o =&gt; o.Guid == identifier).SingleOrDefault();      <br />&#160; if (original == null)       <br />&#160;&#160;&#160; throw new Exception(“Original Entry in Database Not Found.”);</p>    <p>&#160; // Some Extension Method?     <br />&#160; original.CopyFrom(updateEntity);</p>    <p>&#160; // Update the database     <br />&#160; dc.SubmitChanges();      <br />}</p> </blockquote>  <p>The CopyFrom method would iterate over the reflected values of the objects and copy the data from the “updateEntity” object to the original object.&#160; This way, you’re not going to run into any issues issuing an update to a 'disconnected’ object.</p>  <p>Good luck!&#160; This one sure makes me mad though.. LINQ-to-SQL should be smart enough to take care of this for [us] automatically in my opinion.&#160; This is going to be a huge issue for n-tier disconnected architectures.&#160; Instead of being able to fully take advantage of X,Y,Z those portions that do the updating will have to go through hoops like the example above to be able to update something.</p>  <p>Note:&#160; My example above does not address child objects that may be stored along with the entity.</p>  <p>P.S.&#160; I absolutely love LINQ [with the exception of this!].&#160; I had to re-write a substantial part of the application I am working on after some major database changes for features requested by the client.. well, I made a decision to replace portions of code that were already written that needed to be update with LINQ-To-SQL stuff.. and wow!&#160; I was able to write the new LINQ-based code with more features than the original code had.. and implement it <strong><em><u>faster than</u></em></strong> I would have been able to modify the existing code to update it to the new requirements.&#160; </p>  <p>Wow.</p>  <p>Further Reading:&#160; </p>  <p>Rick Strahl has some interesting information on this topic as well but offers some more detail in the suggestions such as adding a timestamp field, etc.   <br />Link:&#160; <a href="http://www.west-wind.com/Weblog/posts/135659.aspx" target="_blank">LINQ to SQL and Disconnected Entities Follow-up</a></p>  <p>Omar Al Zabir has some ideas as well.   <br />LINK:&#160; <a href="http://msmvps.com/blogs/omar/archive/2007/12/08/linq-to-sql-how-to-attach-object-to-a-different-data-context.aspx" target="_blank">Linq to SQL: How to Attach object to a different data context</a></p>  <p><strong>Here are some other generic Google results that I found during research:     <br /></strong><a title="http://msdn.microsoft.com/en-us/bb546187.aspx" href="http://msdn.microsoft.com/en-us/bb546187.aspx">http://msdn.microsoft.com/en-us/bb546187.aspx</a>    <br />    <br /><a title="http://geekswithblogs.net/michelotti/archive/2007/12/30/118076.aspx" href="http://geekswithblogs.net/michelotti/archive/2007/12/30/118076.aspx">http://geekswithblogs.net/michelotti/archive/2007/12/30/118076.aspx</a>    <br />    <br /><a title="http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/6f42d725-4540-4044-be86-afc7bc2d2b46/" href="http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/6f42d725-4540-4044-be86-afc7bc2d2b46/">http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/6f42d725-4540-4044-be86-afc7bc2d2b46/</a>    <br />    <br /><a title="http://stackoverflow.com/questions/273578/linq-to-sql-disconnected-updating-object-from-different-data-context" href="http://stackoverflow.com/questions/273578/linq-to-sql-disconnected-updating-object-from-different-data-context">http://stackoverflow.com/questions/273578/linq-to-sql-disconnected-updating-object-from-different-data-context</a></p>  <p>Thanks!</p>  <p>Matthew MacSuga</p>]]>
        
    </content>
</entry>

<entry>
    <title><![CDATA[LINQ-to-SQL &ndash; Love it, or Hate It]]></title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2009/02/linq-to-sql-love-it-or-hate-it.html" />
    <id>tag:www.csharpbydesign.com,2009://2.33</id>

    <published>2009-02-05T04:44:09Z</published>
    <updated>2009-02-05T04:44:52Z</updated>

    <summary>I choose to love it. Here is a post that I posted on Stack Over Flow, asking for some assistance in generating the following query seen below:&#160; Complicated query with aggregate data for a report from multiple tables for an...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
        <category term="C#" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>I choose to love it.</p>  <p>Here is a post that I posted on Stack Over Flow, asking for some assistance in generating the following query seen below:&#160; </p>  <p><a href="http://stackoverflow.com/questions/512984/linq-to-sql-complicated-query-with-aggregate-data-for-a-report-from-multiple-tab" target="_blank">Complicated query with aggregate data for a report from multiple tables for an ordering system</a></p>  <pre class="code"><span style="color: blue">from </span>pmt <span style="color: blue">in </span><span style="color: #2b91af">products_mainTable
</span><span style="color: blue">join </span>opt <span style="color: blue">in </span><span style="color: #2b91af">orders_productsTable </span><span style="color: blue">on </span>pmt.guid <span style="color: blue">equals </span>opt.products_mainTableGUID <span style="color: blue">into </span>tempProducts
<span style="color: blue">from </span>orderedProducts <span style="color: blue">in </span>tempProducts.DefaultIfEmpty()
<span style="color: blue">join </span>omt <span style="color: blue">in </span><span style="color: #2b91af">orders_mainTable </span><span style="color: blue">on </span>orderedProducts.orders_mainTableGUID <span style="color: blue">equals </span>omt.guid <span style="color: blue">into </span>tempOrders
<span style="color: blue">from </span>ordersMain <span style="color: blue">in </span>tempOrders.DefaultIfEmpty()
<span style="color: blue">group </span>pmt <span style="color: blue">by new </span>{ pmt.sku, orderedProducts.color, orderedProducts.size } <span style="color: blue">into </span>g
<span style="color: blue">orderby </span>g.FirstOrDefault().sku
<span style="color: blue">select new </span>{
    g.FirstOrDefault().guid,
    g.Key.sku,
    g.Key.size,
    QTY = g.FirstOrDefault().orders_productsTable.Sum(c =&gt; c.qty),
    SUM = g.FirstOrDefault().orders_productsTable.Sum(c =&gt; c.itemprice * c.qty),
    AVG = g.FirstOrDefault().orders_productsTable.Average(c =&gt; c.itemprice * c.qty),
    Some = g.FirstOrDefault().orders_productsTable.Average(p =&gt; p.qty).GetValueOrDefault(0),
};</pre>
<a href="http://11011.net/software/vspaste"></a>

<p>I’ve got to say that working with LINQ-TO-SQL has been an absolute pleasure.&#160; I even fired up LINQPad and have really been enjoying the use of that program.&#160; The $19 for the IntelliSense was definitely worth it.&#160; What a great tool.</p>

<p>I can now take the query above into my code, and render it into reports, grids, etc. and whatever else I need it for using my DevExpress framework.&#160; Exciting stuff, to be sure.</p>

<p>I’ll write some more on this topic when I have some additional time, but since I had a difficult time Googling for the answer on my Stackoverflow question, I thought I’d write about it here.</p>

<p>The above represents how to do a full LEFT OUTER JOIN in LINQ and C# while performing GROUPING and AGGREGATE functions.&#160; Hopefully this will be a good starting place for someone else looking to do the same thing.</p>

<p>The important bits here are DefaultIfEmpty() which helps to perform the LEFT OUTER JOIN and FirstOrDetaulf() which allows you access to the underlying type.&#160; While I knew about DefaultIfEmpty() I did not know about FirstOrDefault().. using FoD was the real key to making this query work the way that I wanted it to.</p>

<p>Now I am able to quickly and easily query my sales data.&#160; This query for instance queries the products table, finds products that have sold and generates a quick report that I can use as a DataSource for other components.</p>

<p>Viva la LINQ!</p>

<p>Matthew MacSuga</p>]]>
        
    </content>
</entry>

<entry>
    <title>Automatically Generating Dynamic Enumerations</title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2009/01/automatically-generating-dynamic-enumerations.html" />
    <id>tag:www.csharpbydesign.com,2009://2.32</id>

    <published>2009-01-29T22:47:57Z</published>
    <updated>2009-01-29T22:47:59Z</updated>

    <summary>I use a product from Developer Express called XtraGrid.&#160; It has some pretty remarkable features, one of which is a “flags” editor. Say for instance that I have a bit flag enumeration: [Serializable] [Flags] public enum ColorFlags { Red =...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>I use a product from Developer Express called XtraGrid.&#160; It has some pretty remarkable features, one of which is a “flags” editor.</p>  <p>Say for instance that I have a bit flag enumeration:</p>  <pre class="code">[<span style="color: #2b91af">Serializable</span>]
[<span style="color: #2b91af">Flags</span>]
<span style="color: blue">public enum </span><span style="color: #2b91af">ColorFlags </span>{
    Red = 1,
    Green = 2,
    Blue = 4
}</pre>

<p><a href="http://11011.net/software/vspaste"></a>Now, if I want that to show up in my grid with a popup for a field like the following:</p>

<p><a href="http://www.csharpbydesign.com/WindowsLiveWriter/AutomaticallyGeneratingDynamicEnumeratio_D018/image_2.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="214" alt="image" src="http://www.csharpbydesign.com/WindowsLiveWriter/AutomaticallyGeneratingDynamicEnumeratio_D018/image_thumb.png" width="236" border="0" /></a> </p>

<p>I have to do something very simple..</p>

<p>repositoryItemCheckedComboBox_colors.SetFlags(typeof(ColorFlags));</p>

<p>The DevExpress tools will enumerate over the enumeration (ha!) and gather all of the appropriate values, create the checked list edit, and display it to the user.&#160; When the user finishes their edit, they are left with the numerical value of the bitwise operation.</p>

<p>That’s all and well, but what if my enumerations are stored in a <strong><em>database</em></strong> ?&#160; I simply can’t use the .SetFlags method by itself, because there is no hard-coded enumeration to pull from! </p>

<p>What I needed to do was to create the enumeration dynamically, at runtime, to pull the information from the database and construct a dynamic enum. </p>

<p>Here is the code I created:</p>

<pre class="code">[<span style="color: #2b91af">Serializable</span>]
<span style="color: blue">public enum </span><span style="color: #2b91af">FlagsType </span>{
    Color = 1,
    Size = 2
}</pre>
<a href="http://11011.net/software/vspaste"></a>

<pre class="code"><span style="color: blue">private </span><span style="color: #2b91af">Type </span>GenerateEnumerations(<span style="color: #2b91af">FlagsType </span>f) {
    <span style="color: blue">string </span>asmNameString = <span style="color: #2b91af">String</span>.Empty;
    <span style="color: blue">switch</span>(f) {
        <span style="color: blue">case </span><span style="color: #2b91af">FlagsType</span>.Color:
            asmNameString = <span style="color: #a31515">&quot;flags_color&quot;</span>;
            <span style="color: blue">break</span>;
        <span style="color: blue">case </span><span style="color: #2b91af">FlagsType</span>.Size:
            asmNameString = <span style="color: #a31515">&quot;flags_size&quot;</span>;
            <span style="color: blue">break</span>;
    }
    <span style="color: green">//    Create Base Assembly Objects
    </span><span style="color: #2b91af">AppDomain </span>appDomain = <span style="color: #2b91af">AppDomain</span>.CurrentDomain;
    <span style="color: #2b91af">AssemblyName </span>asmName = <span style="color: blue">new </span><span style="color: #2b91af">AssemblyName</span>(asmNameString);
    <span style="color: #2b91af">AssemblyBuilder </span>asmBuilder = appDomain.<br />      DefineDynamicAssembly(asmName, <span style="color: #2b91af">AssemblyBuilderAccess</span>.Run);

    <span style="color: green">//    Create Module and Enumeration Builder Objects
    </span><span style="color: #2b91af">ModuleBuilder </span>modBuilder = asmBuilder.<br />      DefineDynamicModule(asmNameString + <span style="color: #a31515">&quot;_module&quot;</span>);
    <span style="color: #2b91af">EnumBuilder </span>enumBuilder = modBuilder.<br />      DefineEnum(asmNameString, <span style="color: #2b91af">TypeAttributes</span>.Public, <span style="color: blue">typeof</span>(<span style="color: blue">int</span>));
    
    <span style="color: green">//    Query the database for the value of the flags enumerations
    </span><span style="color: blue">using </span>(lsDataContext dbObj = <span style="color: blue">new </span>lsDataContext()) {
        <span style="color: blue">var </span>enumerations = (<span style="color: blue">from </span>j <span style="color: blue">in </span>dbObj.flags_mainTable
                            <span style="color: blue">where </span>j.type == (<span style="color: blue">int</span>)f
                            <span style="color: blue">orderby </span>j.name
                            <span style="color: blue">select </span>j).ToList();

        <span style="color: blue">foreach </span>(<span style="color: #2b91af">flags_mainTable </span>fmtObj <span style="color: blue">in </span>enumerations)
            enumBuilder.DefineLiteral(fmtObj.name, fmtObj.flag);
    }
    
    <span style="color: blue">return </span>enumBuilder.CreateType();
}</pre>
<a href="http://11011.net/software/vspaste"></a>

<p>&#160;</p>

<p>Now I simply use the .SetFlags method, but this time like this:</p>

<pre class="code">repoItemCheckedCombo_color.SetFlags(<br />   GenerateEnumerations(<span style="color: #2b91af">FlagsType</span>.Color)</pre>

<pre class="code">);</pre>

<pre class="code">&#160;</pre>

<p>I doubt this sort of scenario crops up often, but if it does I </p>

<p></p>

<p>hope this helps!</p>&#160;&#160; <p>Matthew MacSuga</p>
<a href="http://11011.net/software/vspaste"></a>]]>
        
    </content>
</entry>

<entry>
    <title>OMG WOW!</title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2009/01/omg-wow.html" />
    <id>tag:www.csharpbydesign.com,2009://2.31</id>

    <published>2009-01-23T02:13:15Z</published>
    <updated>2009-01-23T02:13:17Z</updated>

    <summary>Today, I finally achieved one of my many little dreams as a software developer. Throughout the years, I have wanted one thing.. one tiny, small, insignificant little thing that would make things just a little easier on me.. allow me...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>Today, I finally achieved one of my many little dreams as a software developer.</p>  <p>Throughout the years, I have wanted one thing.. one tiny, small, insignificant little thing that would make things just a little easier on me.. allow me to have some fun.. be completely legal [not that I wasn’t already!].. and have access to some of the greatest software tools and systems known to man.</p>  <p>I got my MSDN Premium Subscription today with Visual Studio Team Suite !!</p>  <p>I’ve been downloading all of the neatest applications all day, and planning how, what, and where I am going to install things to make the perfect development environment!&#160; I can’t believe after all of these years of wishing someone would buy it for me.. of wishing I had access to the latest operating systems.. today, I finally have it all!&#160; I absolutely can’t wait to dig into all of the features of VSTS Edition!&#160; </p>  <p>So dear reader, you might ask, how did I get this subscription ?&#160; Did I steal it ?&#160; Did I kill someone ?&#160; Did I lie, or cheat ?&#160; Did I bribe someone at Microsoft ?&#160; No.</p>  <p>Microsoft has this incredible program called <a href="http://www.microsoft.com/BizSpark" target="_blank">BizSpark</a> !&#160; </p>  <p>With BizSpark, a startup company can acquire all of the tools necessary to develop software using the best Microsoft tools, applications, and operating systems.&#160; The requirements are not steep (less than 3 years, make less than $1,000,000 dollars, be privately held, and be developing software that forms the core of your business) and all you have to do is find a Network partner to help you join the program.&#160; *Note:&#160; The network partner should not charge you for anything, so if someone wants too.. find someone else!&#160; Oh, and one other thing.&#160; You may remain in the program for 3 years, and upon your exit, you are required to pay a $100 exit fee.&#160; Cake.</p>  <p>All in all, I highly recommend this program to anyone looking to have the best development tools that Microsoft has to offer.&#160; I can only assume that I will also get Visual Studio 2010 Team Suite Edition as well, when it’s released.&#160; Let me just tell you something, I absolutely can not wait.&#160; You also get PRODUCTION licenses for SQL Server, and Windows 2008 Server [up to 3 years].</p>  <p>Oh, and did I mention these licenses are perpetual ?&#160; Even after you leave the program, your licenses are valid and will remain so.. with the exception that the server products (SQL Server, Server 2008, etc.) will no longer be licensed.&#160; </p>  <p>All I have to say is this:&#160; Thank you Microsoft, for making my little dream come true.&#160; </p>  <p>I am so happy to finally have access to all of their tools and operating systems.&#160; I am going to have so much fun learning all of the new features in VSTS, and Team Foundation Server.&#160; I can only hope that this will increase my output and make me an even better developer.&#160; </p>  <p>Sounds like fun to me. :)</p>  <p>P.S.&#160; Original Blog Article That I Read to Find Out About This:&#160; <a href="http://vistadb.net/blog/news/hats-off-to-47-hats-and-microsoft-bizspark/" target="_blank">http://vistadb.net/blog/news/hats-off-to-47-hats-and-microsoft-bizspark/</a>    <br />Thanks Jason[, and Bob!]!!!</p>  <p>Matthew MacSuga</p>]]>
        
    </content>
</entry>

<entry>
    <title>Core Programming Exercises</title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2009/01/core-programming-exercises.html" />
    <id>tag:www.csharpbydesign.com,2009://2.30</id>

    <published>2009-01-11T22:08:27Z</published>
    <updated>2009-01-11T22:08:30Z</updated>

    <summary>During the course of researching something.. I came across an excellent free e-book:&#160; “Data Structures and Algorithms” (http://dotnetslackers.com/projects/Data-Structures-And-Algorithms/) written by Granville Barnett and Luca Del Tongo.&#160; While it is a little difficult to follow in places, it is an excellent...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>During the course of researching something.. I came across an excellent free e-book:&#160; “Data Structures and Algorithms” (<a href="http://dotnetslackers.com/projects/Data-Structures-And-Algorithms/" target="_blank">http://dotnetslackers.com/projects/Data-Structures-And-Algorithms/</a>) written by <a href="http://msmvps.com/blogs/gbarnett/">Granville Barnett</a> and <a href="http://blogs.ugidotnet.org/wetblog/Default.aspx">Luca Del Tongo</a>.&#160; While it is a little difficult to follow in places, it is an excellent resource for programmers who want to “get back to basics”.</p>  <p>It’s been a long time since I’ve written things like Linked Lists and Sorting algorithms from scratch. This book really does a good job of laying out pseduo code for what you need to do to implement a particular algorithm.&#160; </p>  <p>Programming in C# has really made me lazy when it comes down to fundamental programming principals!&#160; I would be willing to bed that a lot of programmers today don’t know how to write a lot of these things from scratch anymore.. so much is provided to us to use by others.. that we forget <em>how</em> they’re actually built.&#160; </p>  <p>Using the .NET framework I have hardly had a need to do anything like write a Bubble Sort or a Linked List from scratch.&#160; I suppose that I’m fortunate as well in that I started on the .NET bandwagon late.. a lot of the functionality that is in this book is built into the framework now.</p>  <p>I’m currently working through each of the examples and having quite a bit of fun doing it.&#160; I created my own Singly and Doubly Linked List, from scratch.&#160; While not as powerful or efficient perhaps as the built in Linked Lists and others that are built into the framework.. It’s about learning something old, and applying it to something new. I dug up some old C code that I had written years and years ago that implemented a LL.. now I’ve done it in C# as well.</p>  <p>So, I’m working on getting back to basics.. relearning stuff that I learned a long time ago, and having fun implementing the algorithms in C#.&#160; It’s good exercise for the mind and is making me re-think some of the things that I’ve been writing lately.&#160; Creating these in C# is really making me think more in the OOP world.</p>  <p>Check out the book!</p>  <p>- Matthew&#160; </p>]]>
        
    </content>
</entry>

<entry>
    <title>How to ORDER BY a Bitwise Field in SQL</title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2008/12/how-to-order-by-a-bitwise-field-in-sql.html" />
    <id>tag:www.csharpbydesign.com,2008://2.29</id>

    <published>2008-12-12T05:43:51Z</published>
    <updated>2008-12-12T05:43:53Z</updated>

    <summary>So, I had an interesting problem crop up a little while ago.&#160; If you are storing a bitwise “flags” field in your database, and you need to order by a particular flag or flags of that field, how do you...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>So, I had an interesting problem crop up a little while ago.&#160; If you are storing a bitwise “flags” field in your database, and you need to order by a particular flag or flags of that field, how do you do it ?</p>  <p>It turns out the answer is relatively simple.</p>  <p><strong>Table Structure</strong>: id, name, flags    <br /><strong>Flag Values</strong>:&#160; 1 = <strong>Enemy</strong>, 2 = <strong>Friend</strong>, 4 = <strong>Owe Money</strong> To, 8 = <strong>Owes Me Money</strong></p>  <p><strong>Sample Data:     <br /></strong>1, Matthew, 2 // Friend    <br />2, Josh, 6 // Friend, I Owe Money    <br />3, Thomas, 10 // Friend, Owes Me Money    <br />4, John, 9 // Enemy, Owes Me Money    <br />5, Abe, 2    <br />6, Becky, 6    <br />7, Jimmy, 10    <br />8, Jason, 9    <br />9, Dean, 1    <br />10,Joseph, 5    <br />11,Frank, 6    <br />12,Julie, 11 // Frenemy, Owes me Money    <br />13,Hannah, 10    <br />14,Sam, 5    <br />15,Q, 9</p>  <p>So we have a list of people in the database that are fall under a few different categories [flags] as referenced above.&#160; Now I want to query from this table to find out various things about the people contained within.</p>  <p>Now I want to see all of the people in the table that are my friends, ordered by those that owe me money, followed by those that I owe money to, followed by any others.</p>  <p><strong>SQL:      <br /></strong>SELECT *, (flags &amp; 4 = 4) AS owesme, (flags &amp; 8 = 8) AS iowethem FROM temp WHERE (flags &amp; 2 = 2) ORDER BY owesme DESC, iowethem DESC, name</p>  <p><strong>RESULT:     <br /><a href="http://www.csharpbydesign.com/WindowsLiveWriter/HowtoORDERBYaBitwiseFieldinSQL_1318B/image_4.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="227" alt="image" src="http://www.csharpbydesign.com/WindowsLiveWriter/HowtoORDERBYaBitwiseFieldinSQL_1318B/image_thumb_1.png" width="504" border="0" /></a> </strong></p>  <p></p>  <p>I’m pretty happy with that.&#160; I had a need, and figured out how to scratch it.&#160; I am a little surprised that I had never needed this before, but it certainly does work!&#160; I hope this helps those that might be trying to Google for this.. I did not find a single entry, luckily my hunch paid off.&#160; I wonder if not a lot of people do this sort of thing ?&#160; I love storing flags, and now I can use those for easy ordering as well.</p>  <p><strong>VistaDB Rocks:     <br /></strong>I wasn’t completely sure that I was going to be able to pull this off in VisatDB, but sure enough, it worked like a charm and the first time.&#160; I’m quite impressed!&#160; Yet something else that VistaDB does well.&#160; I also tried it in MySQL to make sure I wasn’t on drugs either.&#160; </p>  <p>Experiment, play around with it, see if you can find a use for something like this.</p>  <p>Happy programming!</p>  <p>Matthew MacSuga</p>]]>
        
    </content>
</entry>

<entry>
    <title>A Move to a New Host</title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2008/12/a-move-to-a-new-host.html" />
    <id>tag:www.csharpbydesign.com,2008://2.28</id>

    <published>2008-12-08T04:16:29Z</published>
    <updated>2008-12-08T04:16:31Z</updated>

    <summary>I moved the site to a new hosting facility, and had a few problems along the way!&#160; It’s up and running now and should be in good shape.&#160; If anyone notices any problems, please let me know :P P.S.&#160; I’m...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>I moved the site to a new hosting facility, and had a few problems along the way!&#160; It’s up and running now and should be in good shape.&#160; If anyone notices any problems, please let me know :P</p>  <p>P.S.&#160; I’m going to try and write a few more articles this week and post some pretty cool code.&#160; While this is called “C# By Design”, I’ll probably be writing a bit about PHP and how to consume .NET web services!&#160; I had a lot of issues with Google while developing my solutions so I think they’ll be of use.</p>  <p>Thanks,   <br />    <br />Matthew MacSuga</p>]]>
        
    </content>
</entry>

<entry>
    <title>Maintaining a Blog is Hard, and So is Coding</title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2008/12/maintaining-a-blog-is-hard-and.html" />
    <id>tag:www.csharpbydesign.com,2008://2.27</id>

    <published>2008-12-06T12:32:35Z</published>
    <updated>2008-12-08T01:25:31Z</updated>

    <summary>I’ve decided that maintaining a blog is hard work.&#160; You might be prompted to ask, “Matthew, why is maintaining a blog hard wokr?”&#160; I would answer, “Because you’re supposed to write in it!” My original intention was to write about...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>I’ve decided that maintaining a blog is hard work.&#160; You might be prompted to ask, “Matthew, why is maintaining a blog hard wokr?”&#160; I would answer, “Because you’re supposed to write in it!”</p>  <p>My original intention was to write about the things that I’m working on.&#160; Unfortunately, this means that I have to actually <em>take the time to do so</em>.&#160; Lately, time has been very limited because I’ve been working on a lot of really difficult and completely cool stuff!&#160; That means, I have a back-log of things to write about.</p>  <p><strong>Things I’ve been working on lately</strong></p>  <p>1.&#160; Creating a new .NET based Ski Reporting &amp; Faxing System    <br />2.&#160; Writing API’s for the ski reporting system     <br />3.&#160; Writing applications in PHP to consume the data from the ski reporting system     <br />4.&#160; Writing PHP again!     <br />5.&#160; Learning a new database (VistaDB) [<a href="http://www.vistadb.net" target="_blank">http://www.vistadb.net</a>]     <br />6.&#160; Learning more about Developer Express’ XtraReporting Suite     <br />7.&#160; Learning about Windows Workflow Foundation&#160; (WF)    <br />8.&#160; Learning how to use Ra-Ajax [<a href="http://www.ra-ajax.org" target="_blank">http://www.ra-ajax.org</a>]     <br />9.&#160; Writing Multi-Threaded Windows Management Applications for said ski system!     <br />10.&#160; Not skiing     <br />11.&#160; Learning how to use Click Once deployment     <br />12.&#160; Reading the web, reading books, learning new things, participating in newsgroups</p>  <p><strong>What do I intend to blog about next?</strong></p>  <p>Namely, the above.    <br />I’ve been doing so much programming, learning so many new things, it’s just been crazy.&#160; I can’t wait to share some of the neat PHP code that I wrote that uses NuSOAP and calls remote web services written in .NET.&#160; I learned some new things, and came up with some code that I had an extremely hard time finding the answer to on Google.&#160; In fact, I did <strong>not find</strong> the answer on Google!&#160; A co-worker and I found the solution.&#160; So I will definitely be writing about that (Hint:&#160; Passing List&lt;T&gt; data TO/FROM a Web Service) experience as it may help some.</p>  <p>I’m going to write a white-paper style article on the ski reporting system, how it all works.. the challenges I faced.. what new things I created to solve problems.. I did (in my opinion) some seriously nice work on that system.&#160; I can’t wait to explain it all to everyone.&#160; It’s based in both Linux (PHP) and Windows (C#/.NET) with Web Services being the interface between both.&#160; I also developed new database code to work with VistaDB, which is a new database I found that I absolutely love.&#160; I’ll be writing about that as well.</p>  <p><strong>Developer Express     <br /></strong>The Developer Express [<a href="http://www.devexpress.com" target="_blank">http://www.devexpress.com</a>] products are absolutely amazing.&#160; I discover more and more neat stuff about the product suite every day.&#160; I learned that you can use the XtraReporting suite to create really NICE web pages [example:&#160; <a href="http://www.skiidaho.us/cnew_summary.php" target="_blank">Ski Idaho Conditions Report Summary</a>] without creating all of the HTML yourself.&#160; In my opinion, this is one of the nicest features of the entire product line.. not only can you create PDFs and Images, but flawless HTML.&#160; The things that I can do absolutely amaze me, and I still don’t think I’ve scratched the surface of everything that I can do.&#160; I will be writing a separate post about that, and how the solution works in both .NET and PHP.</p>  <p><strong>Ra-Ajax</strong>    <br />I’m also investigating Ra-Ajax [<a href="http://www.ra-ajax.org" target="_blank">http://www.ra-ajax.org</a>] for doing all of my AJAX related stuff.&#160; I’ve been a huge jQuery fan lately, but Thomas Hansen is a friend of mine and I really believe in the work that he’s doing.&#160; He is a top-notch programmer, and he’s been a huge help to me since I’ve known him!&#160; You’ll remember that I previously suggest Gaia Ajax Widgets – I do not anymore.. in addition, Ra-Ajax is a far superior product.&#160; Thomas fixed everything that he did wrong in Gaia, and made it all better in Ra.&#160; Huge kudos go out to him for what he’s doing and giving to the .NET community, and those that want to develop cutting edge FAST AJAX applications with a minimal amount of JavaScript code creation.</p>  <p>I will most likely be writing a separate series of articles on Ra-Ajax at a later time detailing my experiences with it.&#160; You might be prompted to ask why I would use Ra, when I have the Developer Express product.. well, DX does some things really well, but like most ASP.NET toolkits, they are to heavy.&#160; Ra-Ajax is lightweight, open source, and easy to implement.&#160; Much faster than the other guys.. even though it might not look as good, looks can be fixed.. trimming the fat off of heavy is much harder to do.</p>  <p>Disclaimer:&#160; I’m friends with Thomas, and I support him and his endeavors.&#160;&#160;&#160; I sound like I’m writing marketing speak, and getting paid for it – but I’m not, honest!!&#160; I just write about what I use, and believe in.&#160; If I think something about it sucks, I’ll write about that too!</p>  <p><strong>Windows Workflow (WF)     <br /></strong>One last thing before I go – I discovered <strong>Windows Workflow Foundation</strong>, and absolutely recommend <a href="http://www.amazon.com/gp/product/1430209755?ie=UTF8&amp;tag=cbydeaprad-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1430209755">Pro WF: Windows Workflow in .NET 3.5 (Pro)</a><img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=cbydeaprad-20&amp;l=as2&amp;o=1&amp;a=1430209755" width="1" border="0" />.&#160; This book really helped me understand Windows Workflow (WF) and I actually implemented it in my ski reporting system.&#160; Unfortunately, I had to remove the code later-down-the-road because I had some issues, and being under pressure and all.. it was very easy to “remove” though, because it just encapsulates logic.&#160; I love the technology, and can’t wait for the next release.</p>  <p><strong>Microsoft Charts!     <br /></strong>Oh, by the way, did you know Microsoft released a Charting Suite (by the Dundas people) for free, as part of .NET 3.5 SP1 ?&#160; <br />Blog by Jason at VistaDB:&#160; <a href="http://vistadb.net/blog/news/free-chart-control-from-microsoft-for-net-3-5/" target="_blank">Free Chart Control from Microsoft For .NET 3.5</a>    <br />Direct Microsoft Download:&#160; <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=130F7986-BF49-4FE5-9CA8-910AE6EA442C&amp;displaylang=en" target="_blank">Download Charts Control</a></p>  <p>I won’t ever use them, but still cool that they did that.&#160; (I won’t use because I have charts in Developer Express XtraCharts suite – heh, having an Enterprise subscription sure helps!)</p>  <p><strong>Writing Too Much Again</strong>    <br />Sorry for being so long winded.    <br />Upcoming posts will be chalked full of code and interesting tidbits of information that I’ve learned over the last few months.&#160; Will be worth it!</p>  <p><strong>Amazon Affiliate Program [ I sold out ! ]</strong>    <br />P.S.&#160; I am embedding Amazon.com links now (Pro WF) link.&#160; I will not link to anything I don’t own, but if you buy something – I sure wouldn’t mind a kickback, so I joined their referral program.</p>  <p>Matthew MacSuga</p>]]>
        
    </content>
</entry>

<entry>
    <title><![CDATA[JSON Webservices &amp; Null Values from Data Objects]]></title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2008/07/json-webservices-null-values-f.html" />
    <id>tag:www.csharpbydesign.com,2008://2.26</id>

    <published>2008-07-31T04:21:53Z</published>
    <updated>2008-12-08T01:25:31Z</updated>

    <summary><![CDATA[ /// &lt;summary&gt; /// Converts NULL values to String.Empty in any object /// &lt;/summary&gt; /// &lt;param name=&quot;o&quot;&gt;&lt;/param&gt; public static void ConvertNullToEmptyString(object o) { Type stringType = typeof(String); var q = from n in o.GetType().GetProperties() where n.PropertyType == stringType select n;...]]></summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p></p>  <pre class="code"><span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">Converts NULL values to String.Empty in any object
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;param name=&quot;o&quot;&gt;&lt;/param&gt;
</span><span style="color: blue">public static void </span>ConvertNullToEmptyString(<span style="color: blue">object </span>o) {
    <span style="color: #2b91af">Type </span>stringType = <span style="color: blue">typeof</span>(<span style="color: #2b91af">String</span>);

    <span style="color: blue">var </span>q = <span style="color: blue">from </span>n <span style="color: blue">in </span>o.GetType().GetProperties()
                    <span style="color: blue">where </span>n.PropertyType == stringType
                    <span style="color: blue">select </span>n;

    <span style="color: blue">foreach </span>(<span style="color: #2b91af">PropertyInfo </span>p <span style="color: blue">in </span>q)
        <span style="color: blue">if </span>(p.GetValue(o, <span style="color: blue">null</span>) == <span style="color: blue">null</span>)
            p.SetValue(o, <span style="color: #2b91af">String</span>.Empty, <span style="color: blue">null</span>);
}</pre>
<a href="http://11011.net/software/vspaste"></a>

<p></p>

<p>The above code is a little function that I wrote that converts all NULL string references in an object to String.Empty.&#160; Don’t forget to add in a Reflection using statement.</p>

<pre class="code"><span style="color: blue">public </span><span style="color: #2b91af">myTestClass </span>myTestClass() {
    <span style="color: #2b91af">myTestClass </span>n = <span style="color: blue">new </span><span style="color: #2b91af">myTestClass</span>();
    <span style="color: green">//    ?Get from Database?
    </span>n.string_1 = <span style="color: blue">null</span>;
    n.string_2 = <span style="color: #a31515">&quot;Hello&quot;</span>;

    <span style="color: green">//    Convert null values
    </span>ConvertNullToEmptyString(n);

    <span style="color: green">//    Return the new object
    </span><span style="color: blue">return </span>n;
}</pre>

<pre class="code"><span style="color: gray">/// &lt;summary&gt;
///    </span><span style="color: green">Simple class
</span><span style="color: gray">/// &lt;/summary&gt;
</span><span style="color: blue">public class </span><span style="color: #2b91af">myTestClass </span>{
    <span style="color: blue">public string </span>string_1 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
    <span style="color: blue">public string </span>string_2 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
}</pre>
<a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a>

<p></p>

<p>This example shows how it could be used.&#160; This way, when running a JSON based webservice, the data returned van be filtered through ConvertNullToEmptyString and that will make JavaScript much happier, rather than having to deal with … “string_1” : &quot;null, … we get a : “”, which is then immediately usable.</p>

<p>- Matthew</p>]]>
        
    </content>
</entry>

<entry>
    <title>ASP.NET, AJAX, and jQuery</title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2008/06/aspnet-ajax-and-jquery.html" />
    <id>tag:www.csharpbydesign.com,2008://2.25</id>

    <published>2008-06-26T10:24:26Z</published>
    <updated>2008-12-08T01:25:31Z</updated>

    <summary>I’ve been doing a lot of ASP.NET work lately, and have in fact enjoyed it very much.&#160; Since this is a new and “recent” development due to my past being in Classic ASP, then PHP I have had a lot...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>I’ve been doing a lot of ASP.NET work lately, and have in fact enjoyed it very much.&#160; Since this is a new and “recent” development due to my past being in Classic ASP, then PHP I have had a lot of new things to learn.. also, for nearly the last two years, I have been doing WinForms only programming, and have forgotten a lot of the stuff I once knew!</p>  <p>The ASP.NET model is considerably different from the PHP 4 model.&#160; Some things are far easier, and other things are just different.&#160; I wanted to learn how to use an HTML/JavaScript/ASP.NET model [like I would do in PHP] and had a few things to figure out.&#160; Fortunately, there exists a lot of places where people have pioneered this stuff before I did.</p>  <p>Here is how to use jQuery with ASP.NET 3.5.</p>  <p>Figure 1:&#160; Create a new C# .NET 3.5 Web Service [SampleService.asmx]</p>  <pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.Collections.Generic;
<span style="color: blue">using </span>System.Linq;
<span style="color: blue">using </span>System.Web;
<span style="color: blue">using </span>System.Web.Services;

<span style="color: blue">namespace </span>admin {
    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Summary description for CMSWebServices
    </span><span style="color: gray">/// &lt;/summary&gt;
    </span>[<span style="color: #2b91af">WebService</span>(Namespace = <span style="color: #a31515">&quot;http://tempuri.org/&quot;</span>)]
    [<span style="color: #2b91af">WebServiceBinding</span>(ConformsTo = <span style="color: #2b91af">WsiProfiles</span>.BasicProfile1_1)]
    [System.ComponentModel.<span style="color: #2b91af">ToolboxItem</span>(<span style="color: blue">false</span>)]    
    <span style="color: green">// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    </span>[System.Web.Script.Services.<span style="color: #2b91af">ScriptService</span>]
    <span style="color: blue">public class </span><span style="color: #2b91af">WebServices </span>: System.Web.Services.<span style="color: #2b91af">WebService </span>{

        [<span style="color: #2b91af">WebMethod</span>]
        <span style="color: blue">public string </span>HelloWorld() {
            <span style="color: blue">return </span><span style="color: #a31515">&quot;Hello World&quot;</span>;
        }
    }
}</pre>

<p>Well, that was simple.&#160; Most of the code as you can see, is already written for you by Visual Studio.</p>

<p>Figure 2:&#160; Define an ASP.NET Page [SampleConsumer.aspx], add jQuery, and this script</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">script </span><span style="color: red">language</span><span style="color: blue">=&quot;javascript&quot; </span><span style="color: red">type</span><span style="color: blue">=&quot;text/javascript&quot;&gt;
                function </span>testme() {

                    $.ajax({
                        type: <span style="color: #a31515">&quot;POST&quot;</span>,
                        url: <span style="color: #a31515">&quot;SampleService.asmx/HelloWorld&quot;</span>,
                        data: <span style="color: #a31515">&quot;{}&quot;</span>,
                        contentType: <span style="color: #a31515">&quot;application/json; charset=utf-8&quot;</span>,
                        dataType: <span style="color: #a31515">&quot;json&quot;</span>,
                        beforeSend: <span style="color: blue">function</span>(xhr) {
                            xhr.setRequestHeader(<span style="color: #a31515">&quot;Content-type&quot;</span>,
                         <span style="color: #a31515">&quot;application/json; charset=utf-8&quot;</span>);
                        },
                        success: <span style="color: blue">function</span>(msg) {
<span style="color: green">                            </span>alert(msg.d);
                        }
                    });

                }
<span style="color: blue">&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt;</span></pre>
<a href="http://11011.net/software/vspaste"></a>

<p>Figure 3:&#160; An HTML button in the ASP.NET page</p>

<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">input </span><span style="color: red">id</span><span style="color: blue">=&quot;Button1&quot; </span><span style="color: red">type</span><span style="color: blue">=&quot;button&quot; </span><span style="color: red">value</span><span style="color: blue">=&quot;button&quot; </span><span style="color: red">onclick</span><span style="color: blue">=&quot;testme();&quot;/&gt;</span></pre>
<a href="http://11011.net/software/vspaste"></a>

<p></p>

<p>Well, that was easy, eh ?&#160; Simply pushing the button will write HelloWorld in the Alert Box.</p>

<p>Figure 4:&#160; Sources
  <br /><a title="http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/" href="http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/">http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/</a>

  <br /><a title="http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/" href="http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/">http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/</a>

  <br /><a title="http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/" href="http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/">http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/</a></p>

<p>I found those series of articles to be extremely helpful in figuring all of this out.&#160; Next time, I hope to write a little bit more about what I’m doing, but wanted to make sure this information was easy to find.&#160; It took me a little while to dig up the exact ‘how-to’ and read through all of the information on the topic.</p>

<p>Note:&#160; This is a little sloppy, sorry :)&#160; I just don’t feel like going to indepth on this topic.&#160; You can find additional resources using the links above.&#160; </p>

<p>YMMV.</p>

<p>- Matthew</p>]]>
        
    </content>
</entry>

<entry>
    <title><![CDATA[The Wonders of ASP.NET &amp; C#]]></title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2008/05/the-wonders-of-aspnet-c.html" />
    <id>tag:www.csharpbydesign.com,2008://2.24</id>

    <published>2008-05-17T03:42:21Z</published>
    <updated>2008-12-08T01:25:31Z</updated>

    <summary>Recently, I&apos;ve been digging into Microsoft&apos;s ASP.NET platform.&#160; As you know [or don&apos;t] I&apos;ve been working with C# heavily for the last two years, but in a WinForms environment.&#160; Before that, I was doing all of my programming using LAMP.....</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>Recently, I've been digging into Microsoft's ASP.NET platform.&#160; As you know [or don't] I've been working with C# heavily for the last two years, but in a WinForms environment.&#160; Before that, I was doing all of my programming using LAMP.. PHP, HTML, and JavaScript - by hand, no doubt.&#160; I have spent countless hours coding JavaScript applications.&#160; Once the &quot;AJAX&quot; revolution hit {I had been doing &quot;AJAX&quot; before the term &quot;AJAX&quot; was coined, using IFRAMES, and other nifty ways of getting data back-and-forth to the server, Prototype.js was a godsend though!} I moved most of my code to JavaScript, and used PHP as a simple backend for delivering JSON formatted packets of information to the client.&#160; Instead of having a bunch of mixed code, I moved closer to the MVC model with a lot of separation.</p>  <p>Since there's a [business] need for me to move back into Web Development, I convinced the 'uppers' that it would be a wise investment to look into ASP.NET for creating our solutions.&#160; There has been a lot of grief because of that, but in my opinion -- it's a better platform, and there is no doubt in my mind about that.&#160; I am so incredibly impressed with how the .NET model works.. and if in practice, how it is in theory works out the way that I think it will, it will make us deliver better products, in a shorter amount of time.&#160; I'm currently teaching our designer how the model works, and how to effectively use it.&#160; He'll be able to produce me 'ready-designer-made' files and all I will have to do is plug in the functionality in the code-behind model, and make sure that things work.</p>  <p>Just simply writing an AJAX type-of function in ASP.NET is 100x easier than what I would have to do 'the old fashioned' way using PHP &amp; JavaScript.&#160; See below:</p>  <p>&lt;asp:UpdatePanel ID=&quot;UpdatePanel1&quot; runat=&quot;server&quot;&gt;   <br />&#160;&#160;&#160; &lt;ContentTemplate&gt;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;asp:ListBox AutoPostBack=&quot;true&quot; ID=&quot;ListBox1&quot; runat=&quot;server&quot; onselectedindexchanged=&quot;ListBox1_SelectedIndexChanged&quot; Width=&quot;343px&quot;&gt;&lt;/asp:ListBox&gt;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;asp:TextBox ID=&quot;TextBox1&quot; runat=&quot;server&quot; AutoPostBack=&quot;true&quot; ontextchanged=&quot;TextBox1_TextChanged&quot; Width=&quot;242px&quot;&gt;&lt;/asp:TextBox&gt;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; onclick=&quot;Button1_Click&quot; Text=&quot;Button&quot; Width=&quot;102px&quot; /&gt;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;br /&gt;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;br /&gt;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;asp:Label ID=&quot;Label1&quot; runat=&quot;server&quot; Text=&quot;Label&quot; BackColor=&quot;#FFFFCC&quot;&gt;&lt;/asp:Label&gt;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;br /&gt;    <br />&#160;&#160;&#160; &lt;/ContentTemplate&gt;    <br />&lt;/asp:UpdatePanel&gt;    <br /></p>  <p>Above is a sample of how AJAX is done is ASP.NET 3.5.&#160; Everything just worked, and on the first try.&#160; I'd type something in the search box, hit the button, and my listbox would be populated with data from the server.&#160; That would have taken me quite a bit more time to do if I had to code everything manually.</p>  <p>However, I am not happy with this model.</p>  <p>There exists a far superior one.</p>  <p>It's called.</p>  <p>Gaia Ajax Widgets {<a href="http://www.ajaxwidgets.com" target="_blank">Gaia Ajax Widgets</a>}.</p>  <p>I've mentioned it before in my Dev Tools.&#160; I work closely with the core developers, learning, working with, suggesting, and sometimes working on the product.&#160; It turns the ASP.NET world upside down!!&#160; Fortunately, I've had the opportunity to work with their controls from their as-yet unreleased version.&#160; They are TERRIFIC.&#160; In the above example, the JavaScript that is sent to the browser from the .NET engine is over <strong>6,000</strong> lines of code.&#160; With Ajax Widgets, only about 200 or so.</p>  <p>To recreate the above example:</p>  <p>&lt;gaia:ListBox .../&gt;   <br />&lt;gaia:TextBox .../&gt;    <br />&lt;gaia: Button.../&gt;</p>  <p>Now, their controls are much richer as well.&#160; Instead of having to rely on the user pressing the button to pass their results to the server, I am able to do something LIKE the following:</p>  <p>&lt;gaia:TextBox InputTimeLimit=&quot;200&quot; OnTimerTick=&quot;PopulateListBox&quot;/&gt;</p>  <p>The above is not exact, I'm paraphrasing because I do not have the parameters right in front of me.&#160; Simply though, I am telling the control that 200ms after the user has last entered a key, fire off a server side event.&#160; My Codebehind would look something like this:</p>  <p>protected void PopulateListBox() {</p>  <p>string input = TextBox1.Text;</p>  <p>// Do some sort of searching here</p>  <p>foreach(...) {</p>  <blockquote>   <p>ListBox1.Items.Add(...);</p> </blockquote>  <p>}</p>  <p>}</p>  <p>The server would populate the listbox, and the results would be instantly transmitted to the client.</p>  <p>This is a much cleaner, and simpler than using Microsoft's AJAX model.&#160; Less code, less confusion, faster development, better quality.&#160; The data that is sent back to the listbox by the way.. instead of what Microsoft does which is send basically the .innerHTML to a control (&lt;select..&gt;&lt;option&gt;&lt;option&gt;&lt;option&gt;...) this sends only the *data* and the JavaScript that AjaxWidgets wrote parses it and populates the listbox.&#160; This could mean substantially less time for the client to wait while fulfilling a large request.</p>  <p>There are a million other controls, and they are all top-notch.&#160; There is no way I could do in PHP/HTML/JS what I could do with ASP.NET/C#/Gaia Ajax Widgets in the same amount of time.&#160; I would have a complete, simple, entire application done before I was even done coding a login page in PHP.&#160; </p>  <p>In my opinion, ASP.NET is a better platform and with the right tools - can kick ass over any other development language, especially for rapid prototyping.</p>  <p>- Matthew</p>]]>
        
    </content>
</entry>

<entry>
    <title>Seagate Momentus 7200.2 ST9200420AS 200GB vs Hitachi Travelstar 7K100 - Review</title>
    <link rel="alternate" type="text/html" href="http://www.csharpbydesign.com/2008/04/seagate-momentus-72002-st92004.html" />
    <id>tag:www.csharpbydesign.com,2008://2.23</id>

    <published>2008-04-30T04:53:53Z</published>
    <updated>2008-12-08T01:25:31Z</updated>

    <summary>I just purchased a new hard drive for my laptop, a Seagate Momentus 7200.2 200GB drive.&#160; Let me tell you - this thing is FAST.&#160; Let me also mention that what I&apos;m saying is no means scientific, and the environment...</summary>
    <author>
        <name>Matthew M.</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.csharpbydesign.com/">
        <![CDATA[<p>I just purchased a new hard drive for my laptop, a Seagate Momentus 7200.2 200GB drive.&#160; Let me tell you - this thing is FAST.&#160; Let me also mention that what I'm saying is no means scientific, and the environment in which I did the testing was not something I would consider &quot;reliable&quot; or &quot;clean&quot;.&#160; This is anecdotal evidence at best.</p>  <p><a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16822148307" target="_blank">Seagate Momentus 7200.2 @ NewEgg</a></p>  <p><a href="http://www.csharpbydesign.com/WindowsLiveWriter/SeagateMomentus7200.2ST9200420AS200.0Gbs_C099/image_2.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="392" alt="image" src="http://www.csharpbydesign.com/WindowsLiveWriter/SeagateMomentus7200.2ST9200420AS200.0Gbs_C099/image_thumb.png" width="481" border="0" /></a> </p>  <p>Above is a picture of HDTune showing the performance of the drive.&#160; I am extremely happy with it, and it totally kicks ass over my slightly older Hitachi <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16822146053" name="CART_ITEM">HITACHI Travelstar 7K100 HTS721010G9SA00</a>.&#160; Here is an ugly comparison shot of the Hitachi drive:</p>  <p><a href="http://www.csharpbydesign.com/WindowsLiveWriter/SeagateMomentus7200.2ST9200420AS200.0Gbs_C099/image_4.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="394" alt="image" src="http://www.csharpbydesign.com/WindowsLiveWriter/SeagateMomentus7200.2ST9200420AS200.0Gbs_C099/image_thumb_1.png" width="481" border="0" /></a> </p>  <p>As you can see, the Seagate drive outperforms the Hitachi drive right from the start!</p>  <p>So, if you have a laptop and are looking for an inexpensive hard drive upgrade (@ time of purchase, $149 w/ free shipping from NewEgg) then I completely recommend the Seagate drive.&#160; Also, the software available from Seagate's website to do the transfer was extremely easy to use.</p>  <p>I hooked up my new Seagate drive to a SATA-&gt;USB Converter.   <br />I loaded up the backup software Seagate Disk Wizard.    <br />I told the software that I wanted to clone my Hitachi drive to the Seagate drive.    <br />It copied all 5 of my partitions to the new drive, including my Truecrypt partition.    <br />The system rebooted, and then started doing the file transfer (Windows did not load, just the bootloader - i.e., where checkdisk and boot time defrag runs)    <br />The system then let me know it was complete, and prompted to shutdown the computer.</p>  <p>Everything feels considerably faster now, and I am no longer waiting for the inevitable hard drive grind I usually get when I have a lot of programs active!&#160; VMWare runs a lot faster as well, and everything just seems smoother and where it is supposed to be.&#160; Additionally, the Seagate drive is Q-U-I-E-T (quiet) !!!&#160; I could hear my Hitachi drive a mile away when it was busy.. I can not hear this drive at all.&#160; Some people on the NewEgg message board mentioned vibration and other noises of which I have had no issues with.</p>  <p>I whole heartedly recommend this drive to anyone.&#160; It was inexpensive, easy to hook up, easy to transfer the data (I usually use RIP &amp; NTFSClone/Partimage/etc.), and boat loads faster.&#160; As always, YMMV, but I am extremely happy/impressed with the new drive.&#160; All is right in Matthew land. :)</p>  <p>- Matthew</p>]]>
        
    </content>
</entry>

</feed>

