<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Neo Fight!</title>
	<atom:link href="http://neofight.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://neofight.wordpress.com</link>
	<description>The constant battle of learning that you have more to learn</description>
	<lastBuildDate>Fri, 08 May 2009 16:00:08 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='neofight.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/15cc17f20721c19d88c18bf77f7aba09?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Neo Fight!</title>
		<link>http://neofight.wordpress.com</link>
	</image>
			<item>
		<title>Microsoft Parallel Extensions &#8211; Hard&#8221;core&#8221; code made easy!</title>
		<link>http://neofight.wordpress.com/2009/05/07/microsoft-parallel-extensions-hardcore-code-made-easy/</link>
		<comments>http://neofight.wordpress.com/2009/05/07/microsoft-parallel-extensions-hardcore-code-made-easy/#comments</comments>
		<pubDate>Thu, 07 May 2009 20:55:22 +0000</pubDate>
		<dc:creator>Shaun McCarthy</dc:creator>
				<category><![CDATA[C# / .Net]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DataWarehouse]]></category>
		<category><![CDATA[Microsoft Parallel Extensions]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://neofight.wordpress.com/?p=79</guid>
		<description><![CDATA[Ok, so I must admit that I was a little disappointed last night. I was really looking forward to implementing a threaded Consumer / Producer to try and take advantage of our 16 core datawarehouse server. Instead, I ended up changing one line of code &#8211; welcome to the world of Microsoft Parallel Extensions.
The Background [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=79&subd=neofight&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Ok, so I must admit that I was a little disappointed last night. I was really looking forward to implementing a threaded Consumer / Producer to try and take advantage of our 16 core datawarehouse server. Instead, I ended up changing one line of code &#8211; welcome to the world of Microsoft Parallel Extensions.</p>
<p><strong>The Background (feel free to skip this)</strong></p>
<p>At my work, it&#8217;s really important for us to be able to detect if people are sharing their accounts. We do this via storing a permanent cookie on the users machine with a &#8220;Machine ID&#8221; (a guid we generate). When they log in from that machine, we log the id so we know the user was on a particular machine. The more machines, the more likely they are sharing their account.</p>
<p>This worked well, apart from the fact that people tend to clear their cookies, leading to an artificial rise of &#8220;Machine IDs&#8221; over time. Three years ago, I came up with an algorithm to find out how to work out what machine IDs were due to cookie clearing, and what ones weren&#8217;t. So I don&#8217;t bore you to death with the details, I will leave that for another post.</p>
<p><strong>The Details</strong></p>
<p>At the core of my problem was the following loop:</p>
<pre>foreach (string user in userlist)
{
  // Do some stuff
  // Commit it to the database
}</pre>
<p>This was going through around 60,000 users and 4mil+ records and running a pretty complex algorithm on them. It took around 10 minutes to run, but when I looked at the performance monitor, I noticed that the total CPU usage rarely got over 4% and that only one CPU process spiked &#8211; hmm, a common sign that threads would help <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  One of my pet hates is having to write really complicated and unintelligble code just to &#8220;increase&#8221; performance, and threads, not matter how hard you try, always end up looking ugly!</p>
<p><strong>The Solution</strong></p>
<p>Some neuron at the back of my brain started firing, and I got this feeling that I knew a better way. F# &#8211; nope, that&#8217;s not it &#8211; would be helpful, but it would take me a long time to convert everything into Functional Programming. A quick google search bore fruit: this article I read <a href="http://msdn.microsoft.com/en-us/magazine/cc163340.aspx" target="_blank">Microsoft Parallel Extensions</a> library back in 2007! Microsoft are now planning on releasing this as part of .Net 4.0; but a <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=348F73FD-593D-4B3C-B055-694C50D2B0F3&amp;displaylang=en" target="_blank">CTP for 3.5 still exists</a>.</p>
<p>After installing the MSI and then adding the reference to System.Threading, all I needed to do was to make this simple change:</p>
<pre>Parallel.ForEach(userlist, (username) =&gt;
{
 // Same code as before
});</pre>
<p>It was that simple! Voila, multi-threading code. If you want more control over the threads created, you can use the TaskManagerPolicy object &#8211; <a href="http://social.msdn.microsoft.com/Forums/en-US/parallelextensions/thread/94e55100-d1ac-4500-88ff-a57b491bb961" target="_blank">a simple way to do this is outlined here</a>.</p>
<p>Caveat: You&#8217;re code inside the loop has to be thread safe &#8211; since none of my code was modifying shared objects, this wasn&#8217;t a concern for me.</p>
<p><strong>The Result</strong></p>
<p><strong><img class="alignnone size-full wp-image-80" title="TaskMonitory" src="http://neofight.files.wordpress.com/2009/05/tasks.png?w=500&#038;h=130" alt="TaskMonitory" width="500" height="130" /></strong></p>
<p>Beautiful! The task now takes under a minute instead of 10.</p>
Posted in C# / .Net, SQL  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/neofight.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/neofight.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/neofight.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/neofight.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/neofight.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/neofight.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/neofight.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/neofight.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/neofight.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/neofight.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=79&subd=neofight&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://neofight.wordpress.com/2009/05/07/microsoft-parallel-extensions-hardcore-code-made-easy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8e6119a20d308b835456e0391d8c6229?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shaun</media:title>
		</media:content>

		<media:content url="http://neofight.files.wordpress.com/2009/05/tasks.png" medium="image">
			<media:title type="html">TaskMonitory</media:title>
		</media:content>
	</item>
		<item>
		<title>MarketClose Twitterobot &#8211; Step 1: Yahoo!</title>
		<link>http://neofight.wordpress.com/2009/04/24/marketbot-1/</link>
		<comments>http://neofight.wordpress.com/2009/04/24/marketbot-1/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 01:06:27 +0000</pubDate>
		<dc:creator>Shaun McCarthy</dc:creator>
				<category><![CDATA[C# / .Net]]></category>
		<category><![CDATA[MarketClose]]></category>
		<category><![CDATA[Yahoo]]></category>
		<category><![CDATA[Stocks]]></category>
		<category><![CDATA[Dow]]></category>
		<category><![CDATA[Finance]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Rest]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[StockMarket]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://neofight.wordpress.com/?p=33</guid>
		<description><![CDATA[Creating your very own twitter bot - step 1, getting something to write about<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=33&subd=neofight&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>So, I am a recovering stockoholic. I&#8217;ve been out of the markets for about 2 years now, but I am still facsinated by their daily fluctuations. I found myself hovering over the address bar and habitually typing finance.google.com to find out what was happening. But that only satiated my fix when I was firefox. So, I added the keyword &#8220;stocks&#8221; to <a title="Awesome utility for quickly launching things" href="http://www.bayden.com/SlickRun/" target="_blank">slickrun</a> so I could quickly open up <a href="http://finance.google.com" target="_blank">finance.google.com</a> from anywhere. Bah &#8211; too many keystrokes &#8211; I used <a title="Finally, a use for the windows key" href="http://www.pcworld.com/downloads/file/fid,5506-order,1-page,1-c,alldownloads/description.html" target="_blank">winkey</a> to assign it to Win+C.  But what to do before 10am? I started checking the future markets before getting to work.</p>
<p>It was too much &#8211; I had to go cold turkey! I changed Win+C back to being a command prompt, and re-aliased stocks to take me to <a href="http://www.reddit.com/r/programming" target="_blank">proggit</a>. I decided that instead, I would write a simple C# program to send me the stock price at the end of the day. I&#8217;ve been meaning to play around with the Twitter API for a while now, so it finally gave me an excuse.</p>
<p>However, before the fun started, I first had to get the data.</p>
<p><strong>Step 1 &#8211; Yahoo!</strong></p>
<p>Yahoo have a nice little rest based CSV generation system for stock quotes. Basically, all you need to do is request urls in the following format:</p>
<p>http://download.finance.yahoo.com/d/quotes.csv?s=<em>ticker1</em>+<em>ticker2</em>&amp;f=<em>othercomands</em></p>
<p>The s query string parameter defines the tickers you want to retrieve (separated by spaces) and the f defines what fields you want back &#8211; you can find a listing of all those commands <a href="http://www.gummy-stuff.org/Yahoo-data.htm" target="_blank">here</a>.</p>
<p>So, for my needs, I just needed to request:</p>
<p><a href="http://download.finance.yahoo.com/d/quotes.csv?s=^IXIC+^DJI+^GSPC&amp;f=sl1o">http://download.finance.yahoo.com/d/quotes.csv?s=^IXIC+^DJI+^GSPC&amp;f=sl1o</a></p>
<p>Fortunately, .net makes rest request a piece of cake:</p>
<p><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">using</span></span><span style="font-size:x-small;"> (</span><span style="font-size:x-small;color:#2b91af;"><span style="font-size:x-small;color:#2b91af;">WebClient</span></span><span style="font-size:x-small;"> wc = </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">new</span></span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#2b91af;"><span style="font-size:x-small;color:#2b91af;">WebClient</span></span><span style="font-size:x-small;">())<br />
{<br />
    </span><span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">return</span></span><span style="font-size:x-small;"> wc.DownloadString(</span><span style="font-size:x-small;color:#a31515;"><span style="font-size:x-small;color:#a31515;">@&#8221;http://download.finance.yahoo.com/d/quotes.csv?s=^IXIC+^DJI+^GSPC&amp;f=sl1o&#8221;</span></span><span style="font-size:x-small;">);<br />
</span>}</p>
<p>So all that was left to do was to write something to quickly parse the csv (unit tests are your friend for things like this) and to move some things out to config files (such as the url)</p>
<p>Next Step &#8211; Twitter!</p>
Posted in C# / .Net, MarketClose  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/neofight.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/neofight.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/neofight.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/neofight.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/neofight.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/neofight.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/neofight.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/neofight.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/neofight.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/neofight.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=33&subd=neofight&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://neofight.wordpress.com/2009/04/24/marketbot-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8e6119a20d308b835456e0391d8c6229?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shaun</media:title>
		</media:content>
	</item>
		<item>
		<title>Extending yourself&#8230;</title>
		<link>http://neofight.wordpress.com/2008/03/20/extending-yourself/</link>
		<comments>http://neofight.wordpress.com/2008/03/20/extending-yourself/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 01:14:51 +0000</pubDate>
		<dc:creator>Shaun McCarthy</dc:creator>
				<category><![CDATA[C# / .Net]]></category>
		<category><![CDATA[TestListGenerator]]></category>

		<guid isPermaLink="false">http://neofight.wordpress.com/?p=16</guid>
		<description><![CDATA[How many times have you found yourself doing this for enums:
public enum Role
{
  Guest,
  User,
  Privileged,
  Administrator
}
public class RoleHelper
{
  public static string GetName(Role role)
  {
    return Enum.GetName(typeof(Role), role);
  }
}
Wouldn&#8217;t it be a lot nicer just to be able to go role.GetName()? As promised, I am now going to explain what Extension Methods are. Extensions Methods are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=16&subd=neofight&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>How many times have you found yourself doing this for enums:</p>
<p><font size="2"></font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">public</font><font size="2"> </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">enum</font><font size="2"> </font><font size="2" color="#2b91af"></font><font size="2" color="#2b91af">Role<br />
</font><font size="2">{<br />
  Guest,<br />
  User,<br />
  Privileged,<br />
  </font><font size="2">Administrator<br />
}</p>
<p></font><font size="2"></font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">public</font><font size="2"> </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">class</font><font size="2"> </font><font size="2" color="#2b91af"></font><font size="2" color="#2b91af">RoleHelper<br />
</font><font size="2">{<br />
  </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">public</font><font size="2"> </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">static</font><font size="2"> </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">string</font><font size="2"> GetName(</font><font size="2" color="#2b91af"></font><font size="2" color="#2b91af">Role</font><font size="2"> role)<br />
  </font><font size="2">{<br />
    </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">return</font><font size="2"> </font><font size="2" color="#2b91af"></font><font size="2" color="#2b91af">Enum</font><font size="2">.GetName(</font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">typeof</font><font size="2">(</font><font size="2" color="#2b91af"></font><font size="2" color="#2b91af">Role</font><font size="2">), role);<br />
  </font><font size="2">}<br />
}</font></p>
<p>Wouldn&#8217;t it be a lot nicer just to be able to go role.GetName()? As promised, I am now going to explain what Extension Methods are. Extensions Methods are a blessing <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Basically, they allow you to add new methods to existing classes, so that the appear as if they were defined in the class. It&#8217;s almost as if you were adding the method inside of the class definition (though see the caveat below).</p>
<p>The syntax is pretty straight forward:</p>
<p><font size="2"></font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">public</font><font size="2"> </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">static</font><font size="2"> </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">class</font><font size="2"> </font><font size="2" color="#2b91af"></font><font size="2" color="#2b91af">RoleHelper<br />
</font><font size="2">{<br />
  </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">public</font><font size="2"> </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">static</font><font size="2"> </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">string</font><font size="2"> GetName(</font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">this</font><font size="2"> </font><font size="2" color="#2b91af"></font><font size="2" color="#2b91af">Enum</font><font size="2"> e)<br />
  {<br />
    </font><font size="2" color="#0000ff"></font><font size="2" color="#0000ff">return</font><font size="2"> </font><font size="2" color="#2b91af"></font><font size="2" color="#2b91af">Enum</font><font size="2">.GetName(e.GetType(), e);<br />
  }<br />
}</font></p>
<p>Notice the &#8220;this&#8221; in front of the class name. That&#8217;s the secret sauce. The only other thing you need to remeber is that the methods must be declared inside public static classes.</p>
<p>So now, all your enum&#8217;s will have a handy GetName method which returns the name of the enum instead of having to write a helper method for each one!</p>
<p>Caveat: Even though it looks like you are just declaring another method for a class, you are not executing in the context of the class &#8211; this means you do not have access to the class&#8217; private or protected members.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/neofight.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/neofight.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/neofight.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/neofight.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/neofight.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/neofight.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/neofight.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/neofight.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/neofight.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/neofight.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/neofight.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/neofight.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=16&subd=neofight&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://neofight.wordpress.com/2008/03/20/extending-yourself/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8e6119a20d308b835456e0391d8c6229?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shaun</media:title>
		</media:content>
	</item>
		<item>
		<title>Friend of C#</title>
		<link>http://neofight.wordpress.com/2008/03/10/friend-of-c/</link>
		<comments>http://neofight.wordpress.com/2008/03/10/friend-of-c/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 20:56:58 +0000</pubDate>
		<dc:creator>Shaun McCarthy</dc:creator>
				<category><![CDATA[C# / .Net]]></category>
		<category><![CDATA[TestListGenerator]]></category>

		<guid isPermaLink="false">http://neofight.wordpress.com/?p=15</guid>
		<description><![CDATA[In the world of Test Driven Development (TDD) the revivial of the need for a &#8220;friend&#8221; access modifier is becoming more and more apparent. Typically, you want to have all your tests in a different assembly (project) to your actual code &#8211; for cleanness, security and responsibility reasons. However, this presents a dilema &#8211; you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=15&subd=neofight&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In the world of Test Driven Development (TDD) the revivial of the need for a &#8220;friend&#8221; access modifier is becoming more and more apparent. Typically, you want to have all your tests in a different assembly (project) to your actual code &#8211; for cleanness, security and responsibility reasons. However, this presents a dilema &#8211; you want to be able to write test cases for all those internal methods. By default, &#8220;internal&#8221; methods are only exposed to other classes in the same project.</p>
<p>So, the typical approach is to make the methods &#8220;public&#8221; and either (forget to) change them at go live, or have a cluttered API full of methods that are not meant to be called directly. The same goes for variables. C++ had the ever useful &#8220;friend&#8221; language embelishment to handle these types of scenarios, but C# is caught lacking.</p>
<p>Fortunately, as of .Net 2.0, there is the wonderfully named &#8220;InternalsVisibleToAttribute&#8221;. This is an assembly wide (read: AssemblyInfo.cs) attribute that states that all items with the &#8220;internal&#8221; modifier are accessable to the assemblies identified with this attribute. So how do you identify them? Easy: open up the AssemblyInfo.cs of the assembly you want to expose the internals of (hmm, that almost sounds, well, awkward), and add the following line:</p>
<p>[assembly: InternalsVisibleToAttribute("TestListGenerator.Tests")]</p>
<p>Where TestListGenerator.Tests is the name of the library that you want to have to access to this assemblies internals. Of course, you&#8217;ll probably want to move to the world of strong naming to prevent people from getting to friendly with your internals. In which case, after you&#8217;ve signed all your projects (it&#8217;s easy: right click Project &gt; Properties &gt; Signing &gt; new) you need to get the _full_ public key of the calling project. You can do this with Visual Studio&#8217;s sn.exe (included in the path when you use the VS Command Prompt):</p>
<p>sn.exe -T TestListGenerator.Tests.dll</p>
<p>NB: the case of the T matters. This will give you something like:</p>
<p>Public key is<br />
0&#215;0024000004800000940000000602000000240000525341310004000001000100adfedd2329a0f8<br />
3e057f0b14e47f02ec865e542c2dcca6349177fe3530edd5080276c48c6d02fa0a6f67738cc1a0<br />
793be3322cf17b8995acc15055c00fa61b67a203c7eb2516922810ff0b17cd2e08492bdcafc4a9<br />
23e6fff4caba672a4c2d0d0f5cac9aea95c3dce3717bb733d852c387f5f025c42c14ec8d759f7e<br />
b13689be</p>
<p>Strip out the 0x, and copy the rest of the string. Update your InternalsVisibleTo attribute to be:</p>
<p>[assembly: InternalsVisibleTo("TestListGenerator.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100adfedd2329a0f8<br />
3e057f0b14e47f02ec865e542c2dcca6349177fe3530edd5080276c48c6d02fa0a6f67738cc1a0<br />
793be3322cf17b8995acc15055c00fa61b67a203c7eb2516922810ff0b17cd2e08492bdcafc4a9<br />
23e6fff4caba672a4c2d0d0f5cac9aea95c3dce3717bb733d852c387f5f025c42c14ec8d759f7e<br />
b13689be"]</p>
<p>Warning: If you use the public key token instead of the full public key, you&#8217;ll end up with an error like the following:</p>
<p><em>warning CS1700: Assembly reference &#8216;TestListGenerator.Tests, PublicKey=32ab4ba45e0a69a1&#8242; is invalid and cannot be resolved</em></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/neofight.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/neofight.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/neofight.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/neofight.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/neofight.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/neofight.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/neofight.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/neofight.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/neofight.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/neofight.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/neofight.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/neofight.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=15&subd=neofight&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://neofight.wordpress.com/2008/03/10/friend-of-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8e6119a20d308b835456e0391d8c6229?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shaun</media:title>
		</media:content>
	</item>
		<item>
		<title>Lamda Expressions and Tests</title>
		<link>http://neofight.wordpress.com/2008/03/05/lamda-expressions-and-tests/</link>
		<comments>http://neofight.wordpress.com/2008/03/05/lamda-expressions-and-tests/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 15:04:20 +0000</pubDate>
		<dc:creator>Shaun McCarthy</dc:creator>
				<category><![CDATA[C# / .Net]]></category>
		<category><![CDATA[TestListGenerator]]></category>

		<guid isPermaLink="false">http://neofight.wordpress.com/?p=13</guid>
		<description><![CDATA[One of tests I am currently writing for TestListGenreator is checking to see if the function that gets a list of all the Tests in a DLL returns the right amount of category associations. The tests come back as a Dictionary&#60;MethodInfo, HashSet&#60;string&#62;&#62; collection. Counting the number of tests returns is easy:
Dictionary&#60;MethodInfo, HashSet&#60;string&#62;&#62; results = ReflectionHelper.GetTestsFromAssembly(&#8220;TestListGenerator.Tests.TestSubject.dll&#8221;);
int numberOfTests [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=13&subd=neofight&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>One of tests I am currently writing for <a target="_blank" href="http://www.codeplex.com/testlistgenerator">TestListGenreator</a> is checking to see if the function that gets a list of all the Tests in a DLL returns the right amount of category associations. The tests come back as a Dictionary&lt;MethodInfo, HashSet&lt;string&gt;&gt; collection. Counting the number of tests returns is easy:</p>
<p><font size="2" color="#2b91af">Dictionary</font><font size="2">&lt;</font><font size="2" color="#2b91af">MethodInfo</font><font size="2">, </font><font size="2" color="#2b91af">HashSet</font><font size="2">&lt;</font><font size="2" color="#0000ff">string</font><font size="2">&gt;&gt; results = </font><font size="2" color="#2b91af">ReflectionHelper</font><font size="2">.GetTestsFromAssembly(</font><font size="2" color="#a31515">&#8220;TestListGenerator.Tests.TestSubject.dll&#8221;</font><font size="2">);<br />
<font size="2" color="#0000ff">int </font><font size="2">numberOfTests = results.Count</font><font size="2">;</font></font></p>
<p>However, counting the total amount of hashset entries is a little more difficult. In the past, I would have written something like this</p>
<p><font color="#0000ff">int </font>count = 0;<br />
foreach(<font color="#2b91af">HashSet</font> &lt;string&gt; value <font color="#0000ff">in</font> results.Values)<br />
{<br />
  count += value.Count;<br />
}</p>
<p>It works, but it just adds to the mess that is already my test cases logic. I am a great believer in <a target="_blank" href="http://www.moserware.com/2008/03/what-does-it-take-to-become-grandmaster.html"><font size="2">chunking</font></a><font size="2">; however, coming from a background in Perl, I am fully aware that there is a point where chunking (writing code succinctly as possible) becomes obsfication. I think Lamda Expressions walk a narrow line in this regard (especially when it comes to understanding the method signatures!). Here&#8217;s the above code summed up in a lambda expression:</font></p>
<p><font color="#0000ff">int </font>count = results.Sum(f =&gt; f.Value.Count);</p>
<p><font size="2">The first thing to note is the .Sum() function. You would have noticed that code completion on generic collection objects now list a whole bunch of methods that have the following icon in front of them: <img src="http://neofight.files.wordpress.com/2008/03/extension.gif" alt="Extension Method" />. These are extension methods &#8211; I&#8217;ll cover them in a later blog post. For now, just view them as extra methods. </font></p>
<p><font size="2">For example, Sum, will sum all the objects in the collection. But wait! It takes in this weird &#8220;Func&lt;KeyValuePair&lt;keyObject, valueObject&gt;, int&gt; selector&#8221; parameter. What is this? Well, it&#8217;s a delegate signature. The &#8220;Func&#8221; means delegate, and what appears inside the &lt;&gt; is a list of parameters. The last parameter is always what the function should return. So, in this case, you need to define a function that takes in a KeyValuePair and returns an int. Then the Sum function will do all the work of adding all the integers you return.</font></p>
<p><font size="2">Fortunately, .net allows you to define delegates inline. So you can do the following: kvp =&gt; kvp.Values.Count. What this means is that kvp is your name for the KeyValuePair&lt;keyObject, valueObject&gt; parameter, and what follows the =&gt; is what you want to do with it. So, the Sum object, calls kvp.Values.Count for each object in the dictionary, and then sums up all those integers. </font></p>
<p><font size="2"></font><font size="2"><font size="+0"><font size="+0"></font></font></font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/neofight.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/neofight.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/neofight.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/neofight.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/neofight.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/neofight.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/neofight.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/neofight.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/neofight.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/neofight.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/neofight.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/neofight.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=13&subd=neofight&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://neofight.wordpress.com/2008/03/05/lamda-expressions-and-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8e6119a20d308b835456e0391d8c6229?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shaun</media:title>
		</media:content>

		<media:content url="http://neofight.files.wordpress.com/2008/03/extension.gif" medium="image">
			<media:title type="html">Extension Method</media:title>
		</media:content>
	</item>
		<item>
		<title>Alpha released</title>
		<link>http://neofight.wordpress.com/2008/03/03/alpha-released/</link>
		<comments>http://neofight.wordpress.com/2008/03/03/alpha-released/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 03:00:11 +0000</pubDate>
		<dc:creator>Shaun McCarthy</dc:creator>
				<category><![CDATA[C# / .Net]]></category>
		<category><![CDATA[TestListGenerator]]></category>

		<guid isPermaLink="false">http://neofight.wordpress.com/?p=12</guid>
		<description><![CDATA[Woo hoo   So I spent some time in B Cup today finishing off a few coffees and some of the loose ends of my Test List Generator project. I am happy to say, that today I released the first version.
You can download the alpha from here: https://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=testlistgenerator&#38;ReleaseId=11195
The alpha allows you to specify a DLL [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=12&subd=neofight&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Woo hoo <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  So I spent some time in B Cup today finishing off a few coffees and some of the loose ends of my Test List Generator project. I am happy to say, that today I released the first version.</p>
<p>You can download the alpha from here: <a href="https://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=testlistgenerator&amp;ReleaseId=11195">https://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=testlistgenerator&amp;ReleaseId=11195</a></p>
<p>The alpha allows you to specify a DLL you wish to run a category of tests from. You can then specify the list of categories you want to include; as well as a list of categories you wish not to include. The code will then search your DLL for tests that match that criteria and generate a mstest compatible test list.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/neofight.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/neofight.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/neofight.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/neofight.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/neofight.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/neofight.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/neofight.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/neofight.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/neofight.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/neofight.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/neofight.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/neofight.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=12&subd=neofight&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://neofight.wordpress.com/2008/03/03/alpha-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8e6119a20d308b835456e0391d8c6229?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shaun</media:title>
		</media:content>
	</item>
		<item>
		<title>Parsing Command Line Arguments</title>
		<link>http://neofight.wordpress.com/2008/03/02/parsing-command-line-arguments/</link>
		<comments>http://neofight.wordpress.com/2008/03/02/parsing-command-line-arguments/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 17:13:02 +0000</pubDate>
		<dc:creator>Shaun McCarthy</dc:creator>
				<category><![CDATA[C# / .Net]]></category>
		<category><![CDATA[TestListGenerator]]></category>

		<guid isPermaLink="false">http://neofight.wordpress.com/?p=11</guid>
		<description><![CDATA[If you&#8217;ve ever had to write a console application, you&#8217;ve probably always just quickly hacked together a command line parser. This is fine when you are the only person who is using the application, because you implicitly understand that the inputfile should be declared after the outputfile. Try explaining this wisdom to your colleague who [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=11&subd=neofight&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you&#8217;ve ever had to write a console application, you&#8217;ve probably always just quickly hacked together a command line parser. This is fine when you are the only person who is using the application, because you implicitly understand that the inputfile should be declared after the outputfile. Try explaining this wisdom to your colleague who just blew away their config file they had been working on for the last couple of hours beause they got the arguments the wrong way around <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Or, even worse, WYouWroteThisCode syndrome, where you realise the incompetent programmer who put the parameters this weird way around was you several years ago.</p>
<p>Fortunately, <a target="_blank" href="http://sourceforge.net/projects/csharpoptparse/">CSharpOptParse</a> comes to the rescue. If you&#8217;ve ever played with Perl (who hasn&#8217;t?) it&#8217;s based on GetOpt, one of the best command line processing libraries in existance. Basically, you define a really simple object to store all your paramers (Very simple, comments axed for brevity on web):</p>
<p><font size="2"></font><font size="2" color="#0000ff">public</font><font size="2"> </font><font size="2" color="#0000ff">class</font><font size="2"> </font><font size="2" color="#2b91af">Arguments<br />
</font><font size="2">{<br />
    </font><font size="2" color="#0000ff">public</font><font size="2"> </font><font size="2" color="#0000ff">string</font><font size="2"> InputFile { </font><font size="2" color="#0000ff">get</font><font size="2">; </font><font size="2" color="#0000ff">set</font><font size="2">; }<br />
    </font><font size="2" color="#0000ff">public</font><font size="2"> </font><font size="2" color="#0000ff">string</font><font size="2"> OutputFile { </font><font size="2" color="#0000ff">get</font><font size="2">; </font><font size="2" color="#0000ff">set</font><font size="2">; }<br />
</font><font size="2">}</font></p>
<p>Then by using attributes, you define how to map the command line on to each of these parameters:</p>
<p><font size="2"></font><font size="2"><font size="2">[</font><font size="2" color="#2b91af">ShortOptionName</font><font size="2">(</font><font size="2" color="#a31515">'i'</font><font size="2">)]<br />
[</font><font size="2" color="#2b91af">LongOptionName</font><font size="2">(</font><font size="2" color="#a31515">"input-file"</font><font size="2">)]<br />
[</font><font size="2" color="#2b91af">UseNameAsLongOption</font><font size="2">(</font><font size="2" color="#0000ff">false</font><font size="2">)]<br />
[</font><font size="2" color="#2b91af">OptDef</font><font size="2">(</font><font size="2" color="#2b91af">OptValType</font><font size="2">.ValueReq)]<br />
[</font><font size="2" color="#2b91af">Category</font><font size="2">(</font><font size="2" color="#a31515">"Files"</font><font size="2">)]<br />
[</font><font size="2" color="#2b91af">Description</font><font size="2">(</font><font size="2" color="#a31515">"The input file to process."</font><font size="2">)]<br />
<font size="2" color="#0000ff">public</font><font size="2"> </font><font size="2" color="#0000ff">string</font><font size="2"> InputFile { </font><font size="2" color="#0000ff">get</font><font size="2">; </font><font size="2" color="#0000ff">set</font><font size="2">; }<br />
</font></font><br />
So pretty straight forward right? Then all you need to do is the following magic to parse the parameters:</p>
<p></font><font size="2"></font><font size="2"><font size="2"></font><font size="2"><font size="2"></font><font size="2" color="#2b91af">Arguments</font><font size="2"> arguments = </font><font size="2" color="#0000ff">new</font><font size="2"> </font><font size="2" color="#2b91af">Arguments</font><font size="2">();<br />
</font><font size="2" color="#2b91af">Parser</font><font size="2"> p = </font><font size="2" color="#2b91af">ParserFactory</font><font size="2">.BuildParser(arguments);<br />
</font><font size="2" color="#008000">// Parse the args<br />
</font><font size="2">args = p.Parse(args);</p>
<p></font></font></font><font size="2"><font size="2"><font size="2">The parse takes all kinds of other options, such as to use &#8211; (unix) style or / (windows) style for specifying parameters. It also supports populating items from the enivronment if they are not specified on the command line &#8211; cool <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Oh, and if you want to suppot multiple options like I do in <a target="_blank" href="http://www.codeplex.com/testlistgenerator">TestListGenerator</a>, all you need to do is use a StringCollection, and tell the Parser about it via attributes:</font></font><font size="2"><font size="2"></font></font></font><font size="2"><font size="2"><font size="2"><font size="2"><font size="2">[</font><font size="2"></font><font size="2" color="#2b91af">ShortOptionName</font><font size="2">(</font><font size="2" color="#a31515">'i'</font><font size="2">)]<br />
[</font><font size="2" color="#2b91af">LongOptionName</font><font size="2">(</font><font size="2" color="#a31515">"include"</font><font size="2">)]<br />
[</font><font size="2" color="#2b91af">UseNameAsLongOption</font><font size="2">(</font><font size="2" color="#0000ff">false</font><font size="2">)]<br />
[</font><font size="2" color="#2b91af">OptDef</font><font size="2">(</font><font size="2" color="#2b91af">OptValType</font><font size="2">.MultValue, ValueType = </font><font size="2" color="#0000ff">typeof</font><font size="2">(</font><font size="2" color="#0000ff">string</font><font size="2">))]<br />
[</font><font size="2" color="#2b91af">Description</font><font size="2">(</font><font size="2" color="#a31515">"A list of categories that should be included in the test list generated. NB: You can define multiple categories by repeating the parameter - see examples."</font><font size="2">)]<br />
[</font><font size="2" color="#2b91af">Category</font><font size="2">(</font><font size="2" color="#a31515">"Criteria"</font><font size="2">)]<br />
</font><font size="2" color="#0000ff">public</font><font size="2"> </font><font size="2" color="#2b91af">StringCollection</font><font size="2"> IncludedCategories = <font size="2" color="#0000ff">new</font><font size="2"> </font><font size="2" color="#2b91af">StringCollection</font><font size="2">();</font></font></font><font size="2"></font></p>
<p></font></font></font><font size="2"><font size="2"></font>NB: Note the gotchya &#8211; you need to make sure the StringCollection is instantiated.</font><font size="2">As a little bonus, there is also a really easy way to generate usage information (works like an XmlTextWriter):</font><font size="2"><font size="2"><font size="2"><font size="2"></font></font><font size="2"><font size="2" color="#2b91af">UsageBuilder</font><font size="2"> usage = </font><font size="2" color="#0000ff">new</font><font size="2"> </font><font size="2" color="#2b91af">UsageBuilder</font><font size="2">();<br />
usage.GroupOptionsByCategory = </font><font size="2" color="#0000ff">true</font><font size="2">;<br />
</font><font size="2">usage.BeginSection(<font size="2" color="#a31515">&#8220;Name&#8221;</font><font size="2">);<br />
usage.AddParagraph(</font><font size="2" color="#a31515">&#8220;tlg.exe  &#8211; Test List Generator for Visual Studio&#8221;</font><font size="2">);<br />
usage.EndSection();<br />
<font size="2" color="#008000"><br />
// Generate the list of arguments and descriptions automagically<br />
</font><font size="2">usage.BeginSection(</font><font size="2" color="#a31515">&#8220;Arguments&#8221;</font><font size="2">);<br />
usage.AddOptions(p);<br />
usage.EndSection();</p>
<p></font></font></font></font></font><font size="2"><font size="2"><font size="2"><font size="2"><font size="2"><font size="2"><font size="2">So there you have it &#8211; a simple but elegant solution to your command line woes. Slowly but surely, your code will become less arcane &#8211; you&#8217;ll thank your past self later.</font></font></font></font></font></font></font></p>
<p></font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/neofight.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/neofight.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/neofight.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/neofight.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/neofight.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/neofight.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/neofight.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/neofight.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/neofight.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/neofight.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/neofight.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/neofight.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=11&subd=neofight&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://neofight.wordpress.com/2008/03/02/parsing-command-line-arguments/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8e6119a20d308b835456e0391d8c6229?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shaun</media:title>
		</media:content>
	</item>
		<item>
		<title>Console.ReadLine();</title>
		<link>http://neofight.wordpress.com/2008/03/01/consolereadline/</link>
		<comments>http://neofight.wordpress.com/2008/03/01/consolereadline/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 19:49:25 +0000</pubDate>
		<dc:creator>Shaun McCarthy</dc:creator>
				<category><![CDATA[C# / .Net]]></category>
		<category><![CDATA[TestListGenerator]]></category>

		<guid isPermaLink="false">http://neofight.wordpress.com/?p=10</guid>
		<description><![CDATA[Do you quite often find yourself putting Console.ReadLine() at the end of each of your console programs so you can see the output before Visual Studio closes the window? And then you find yourself in the embarrasing situation of leaving the code in when it&#8217;s deployed so that whenever you run the application from the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=10&subd=neofight&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Do you quite often find yourself putting Console.ReadLine() at the end of each of your console programs so you can see the output before Visual Studio closes the window? And then you find yourself in the embarrasing situation of leaving the code in when it&#8217;s deployed so that whenever you run the application from the command line, it ends up sitting there waiting for you to press a key? Well, next time, wrap it in the following:</p>
<p><code><br />
<font color="#0000ff">if</font> (System.Diagnostics.<font color="#2b91af">Debugger</font>.IsAttached)<br />
{<br />
<font color="#2b91af">Console</font>.WriteLine(<font color="#a31515">"Press a key to quit...");<br />
<font color="#2b91af">Console</font>.ReadKey(<font color="#0000ff">true</font>);<br />
}<br />
</code></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/neofight.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/neofight.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/neofight.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/neofight.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/neofight.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/neofight.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/neofight.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/neofight.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/neofight.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/neofight.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/neofight.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/neofight.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=10&subd=neofight&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://neofight.wordpress.com/2008/03/01/consolereadline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8e6119a20d308b835456e0391d8c6229?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shaun</media:title>
		</media:content>
	</item>
		<item>
		<title>Ahhh, Code Generation&#8230;</title>
		<link>http://neofight.wordpress.com/2008/03/01/ahhh-code-generation/</link>
		<comments>http://neofight.wordpress.com/2008/03/01/ahhh-code-generation/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 00:47:37 +0000</pubDate>
		<dc:creator>Shaun McCarthy</dc:creator>
				<category><![CDATA[C# / .Net]]></category>
		<category><![CDATA[TestListGenerator]]></category>

		<guid isPermaLink="false">http://neofight.wordpress.com/?p=9</guid>
		<description><![CDATA[So the VSMDI config file is xml&#8230; That&#8217;s a good thing, because VisualStudio gives you a few tools for code generation when it comes to XML. Are you sick and tired of writing code to traverese an XML document, or sick of writing lines to create nodes and elements and insert them in the right [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=9&subd=neofight&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>So the VSMDI config file is xml&#8230; That&#8217;s a good thing, because VisualStudio gives you a few tools for code generation when it comes to XML. Are you sick and tired of writing code to traverese an XML document, or sick of writing lines to create nodes and elements and insert them in the right order? Well, if you&#8217;ve already got a sample of the format you want, you can perform this useful shortcut:</p>
<ul>
<li>
<div>Fire up Visual Studio, and add the xml file to your project</div>
</li>
<li>
<div>Xml &gt; Create Schema</div>
</li>
<li>
<div>Add the new XSD file to your project</div>
</li>
<li>
<div>Open a command prompt and navigate to the XSD file</div>
</li>
<li>
<div>xsd.exe -c -l:c# -n:NAMESPACE nameofxsd.xsd</div>
</li>
</ul>
<p>And voila, a class to interface with <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Instantiate, manipulate, and then write it out with:</p>
<p><code><br />
<font color="#2b91af">XmlSerializer</font> ser =<br />
<font color="#0000ff">new</font> <font color="#2b91af">XmlSerializer</font>(<font color="#0000ff">typeof</font>(<font color="#2b91af">TestLists</font>));<br />
ser.Serialize(<font color="#0000ff">new</font><font color="#2b91af">StreamWriter</font>(<font color="#a31515">"out.xml"</font>), testList);<br />
</code></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/neofight.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/neofight.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/neofight.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/neofight.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/neofight.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/neofight.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/neofight.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/neofight.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/neofight.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/neofight.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/neofight.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/neofight.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=9&subd=neofight&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://neofight.wordpress.com/2008/03/01/ahhh-code-generation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8e6119a20d308b835456e0391d8c6229?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shaun</media:title>
		</media:content>
	</item>
		<item>
		<title>VSMDI / TestLists</title>
		<link>http://neofight.wordpress.com/2008/03/01/vsmdi-testlists/</link>
		<comments>http://neofight.wordpress.com/2008/03/01/vsmdi-testlists/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 00:27:39 +0000</pubDate>
		<dc:creator>Shaun McCarthy</dc:creator>
				<category><![CDATA[C# / .Net]]></category>
		<category><![CDATA[TestListGenerator]]></category>

		<guid isPermaLink="false">http://neofight.wordpress.com/?p=8</guid>
		<description><![CDATA[Ok, so I had my first look at a test list today&#8230; It doesn&#8217;t look to scary:

&#60;?xml version="1.0" encoding="UTF-8"?&#62;
&#60;TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2006"&#62;
  &#60;TestList name="Test" id="4965f8d9-7c75-44ec-a6a7-1ddc90be355c" parentListId="8c43106b-9dc1-4907-a29f-aa66a61bf5b6"&#62;
    &#60;TestLinks&#62;
      &#60;TestLink id="0c16c787-7ced-9874-280d-95763867baa5" name="OneCategory" storage="testlistgenerator.tests.testsubjectbindebugtestlistgenerator.tests.testsubject.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" /&#62;
    &#60;/TestLinks&#62;
  &#60;/TestList&#62;
  &#60;TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6"&#62;
    &#60;RunConfiguration id="d0fd86fa-f02f-47a6-ac94-1e966ef3564e" name="Local Test Run" storage="localtestrun.testrunconfig" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common,   PublicKeyToken=b03f5f7f11d50a3a" /&#62;
  &#60;/TestList&#62;
  &#60;TestList name="Test 2" id="d2c82856-b727-489a-97ee-21e164e205ed" [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=8&subd=neofight&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Ok, so I had my first look at a test list today&#8230; It doesn&#8217;t look to scary:<br />
<code><br />
&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;TestLists xmlns="<a href="http://microsoft.com/schemas/VisualStudio/TeamTest/2006">http://microsoft.com/schemas/VisualStudio/TeamTest/2006</a>"&gt;<br />
  &lt;TestList name="Test" id="4965f8d9-7c75-44ec-a6a7-1ddc90be355c" parentListId="8c43106b-9dc1-4907-a29f-aa66a61bf5b6"&gt;<br />
    &lt;TestLinks&gt;<br />
      &lt;TestLink id="0c16c787-7ced-9874-280d-95763867baa5" name="OneCategory" storage="testlistgenerator.tests.testsubjectbindebugtestlistgenerator.tests.testsubject.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" /&gt;<br />
    &lt;/TestLinks&gt;<br />
  &lt;/TestList&gt;<br />
  &lt;TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6"&gt;<br />
    &lt;RunConfiguration id="d0fd86fa-f02f-47a6-ac94-1e966ef3564e" name="Local Test Run" storage="localtestrun.testrunconfig" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common,   PublicKeyToken=b03f5f7f11d50a3a" /&gt;<br />
  &lt;/TestList&gt;<br />
  &lt;TestList name="Test 2" id="d2c82856-b727-489a-97ee-21e164e205ed" parentListId="8c43106b-9dc1-4907-a29f-aa66a61bf5b6"&gt;<br />
    &lt;TestLinks&gt;<br />
      &lt;TestLink id="aebae68c-f6ca-a80b-2c43-c4ddd95e4109" name="RepeatedCategories" storage="testlistgenerator.tests.testsubjectbindebugtestlistgenerator.tests.testsubject.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" /&gt;<br />
      &lt;TestLink id="7c44089f-5995-0c35-6e3b-21a742dd47a9" name="TestGetTestCategories_Class1" storage="testlistgenerator.testsbindebugtestlistgenerator.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel,   PublicKeyToken=b03f5f7f11d50a3a" /&gt;<br />
    &lt;/TestLinks&gt;<br />
  &lt;/TestList&gt;<br />
&lt;/TestLists&gt;<br />
</code><br />
List of Tests is the default Test List in Visual Studio. The other two are tests that I made. From the looks of things, each TestList has a parent TestList as well as a list of Tests (TestLinks) that are in the TestList. My concerns are the ids - what exactly are they, and how are they generated?</p>
<p>A quick search on google turns up <a target="_blank" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=157039&amp;SiteID=1">this thread</a>. Hmm, helpful &#8211; I even commented on it. So now I know how the ids are generated for TestLinks. However, I can&#8217;t seem to work out how they are generated for TestLists &#8211; this could be a problem <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/neofight.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/neofight.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/neofight.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/neofight.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/neofight.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/neofight.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/neofight.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/neofight.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/neofight.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/neofight.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/neofight.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/neofight.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=neofight.wordpress.com&blog=3022366&post=8&subd=neofight&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://neofight.wordpress.com/2008/03/01/vsmdi-testlists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8e6119a20d308b835456e0391d8c6229?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shaun</media:title>
		</media:content>
	</item>
	</channel>
</rss>