<?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/"
	>

<channel>
	<title>Over It. &#187; .NET</title>
	<atom:link href="http://jason.diamond.name/weblog/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://jason.diamond.name/weblog</link>
	<description>(a Weblog by Jason Diamond)</description>
	<lastBuildDate>Mon, 30 Jan 2012 20:08:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>WebSocket Webinar Demo Code</title>
		<link>http://jason.diamond.name/weblog/2012/01/30/websocket-webinar-demo-code/</link>
		<comments>http://jason.diamond.name/weblog/2012/01/30/websocket-webinar-demo-code/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 20:08:01 +0000</pubDate>
		<dc:creator>Jason Diamond</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WebSocket]]></category>

		<guid isPermaLink="false">http://jason.diamond.name/weblog/?p=175</guid>
		<description><![CDATA[Thanks to those who attended today&#8217;s webinar. The demo code is located here until it (and the recording) get uploaded to the DM website later this week. Feel free to email with questions!]]></description>
			<content:encoded><![CDATA[<p>Thanks to those who attended today&#8217;s webinar. The demo code is located <a href="http://dl.dropbox.com/u/4389817/WebSocketsDemo.zip">here</a> until it (and the recording) get uploaded to the DM website later this week.</p>
<p>Feel free to email with questions!</p>
]]></content:encoded>
			<wfw:commentRss>http://jason.diamond.name/weblog/2012/01/30/websocket-webinar-demo-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why won&#8217;t my iterator throw?</title>
		<link>http://jason.diamond.name/weblog/2010/10/27/why-wont-my-iterator-throw/</link>
		<comments>http://jason.diamond.name/weblog/2010/10/27/why-wont-my-iterator-throw/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 23:56:19 +0000</pubDate>
		<dc:creator>Jason Diamond</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://jason.diamond.name/weblog/?p=116</guid>
		<description><![CDATA[I ran into a spot of confusion last night doing some TDD on a method that returns an IEnumerable&#60;T>. I was using multiple yield return statements in it which made the method an iterator and not just a normal method. Even though I know how iterators work, I don&#8217;t use them enough to remember their [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a spot of confusion last night doing some TDD on a method that returns an <code>IEnumerable&lt;T></code>. I was using multiple <code>yield return</code> statements in it which made the method an <a href="http://msdn.microsoft.com/en-us/library/dscyy5s0.aspx">iterator</a> and not just a normal method.</p>
<p>Even though I <em>know</em> how iterators work, I don&#8217;t use them enough to remember their idiosyncrasies. The main one being that it&#8217;s easy to &#8220;invoke&#8221; them without actually executing any of the code inside them!</p>
<p>To illustrate this using a highly contrived example, imagine you wrote the following test:</p>
<pre class="brush:csharp">[Test]
public void It_throws_when_you_pass_in_null()
{
    Assert.Throws&lt;ArgumentNullException>(
        () => MyObject.MyMethod(null));
}</pre>
<p>And then implemented the method it tests it like so:</p>
<pre class="brush:csharp">public static IEnumerable&lt;object> MyMethod(object arg)
{
    if (arg == null)
        throw new ArgumentNullException("arg");

    yield return "whatever";
}</pre>
<p>Surprise! Your test fails.</p>
<p>Why? Because the code in your iterator doesn&#8217;t start executing until you invoke <code>GetEnumerator</code> on its return value then invoke <code>MoveNext</code> on that.</p>
<p>One really quick way to force these method calls to happen is to use the <code>ToArray</code> extension method:</p>
<pre class="brush:csharp">[Test]
public void It_throws_when_you_pass_in_null()
{
    Assert.Throws&lt;ArgumentNullException>(
        () => MyObject.MyMethod(null).ToArray());
}</pre>
<p><code>ToList</code> or manually iterating over the result with <code>foreach</code> would work just as well.</p>
<p>A better way to fix this is to change your implementation so that it uses two methods:</p>
<pre class="brush:csharp">public static IEnumerable&lt;object> MyMethod(object arg)
{
    if (arg == null)
        throw new ArgumentNullException("arg");

    return MyMethodHelper(arg);
}

private static IEnumerable&lt;object> MyMethodHelper(object arg)
{
    yield return "whatever";
}</pre>
<p>Written this way, <code>MyMethod</code> isn&#8217;t an iterator anymore. It&#8217;s just a plain old method that gets executed the way you&#8217;d expect it to. <code>MyMethodHelper</code> becomes the iterator. Its code won&#8217;t get executed until you start calling <code>MoveNext</code>, but that&#8217;s OK because the validation code you care about already ran.</p>
<p>Problem solved, right? Unfortunately, this wasn&#8217;t quite my <em>exact</em> problem.</p>
<p>My method was actually throwing <em>after</em> it did its argument checking and <em>while</em> it was yielding values. There&#8217;s really no solution (that I know of) to handle this without invoking <code>MoveNext</code> (or something else that will invoke it for you like <code>ToArray</code>) until whatever condition throws your exception is triggered.</p>
<p>Adding <code>ToArray</code> to my test wasn&#8217;t a big deal, but it took me a bit of time to figure out why it was failing. I was actually setting breakpoints in my method, running the test in the debugger, and tripping out when my breakpoints weren&#8217;t hitting.</p>
<p>Maybe going through the trouble of writing this post will save me 10 minutes next time I write an iterator.</p>
]]></content:encoded>
			<wfw:commentRss>http://jason.diamond.name/weblog/2010/10/27/why-wont-my-iterator-throw/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New BehaveN Release</title>
		<link>http://jason.diamond.name/weblog/2010/09/03/new-behaven-release/</link>
		<comments>http://jason.diamond.name/weblog/2010/09/03/new-behaven-release/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 23:59:05 +0000</pubDate>
		<dc:creator>Jason Diamond</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[BehaveN]]></category>

		<guid isPermaLink="false">http://jason.diamond.name/weblog/?p=113</guid>
		<description><![CDATA[This is a minor, bug fix release. You can see the changes here. I&#8217;ve also updated the wiki with some more documentation.]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/behaven/downloads/detail?name=BehaveN-2.0.1.102.zip">This</a> is a minor, bug fix release. You can see the changes <a href="http://code.google.com/p/behaven/source/browse/HISTORY.txt?spec=svnd804cddd71ef23bd7254c9f018ce3264cf12d343&#038;r=d804cddd71ef23bd7254c9f018ce3264cf12d343">here</a>.</p>
<p>I&#8217;ve also updated the <a href="http://code.google.com/p/behaven/w/list">wiki</a> with some more documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://jason.diamond.name/weblog/2010/09/03/new-behaven-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BehaveN</title>
		<link>http://jason.diamond.name/weblog/2010/07/11/behaven/</link>
		<comments>http://jason.diamond.name/weblog/2010/07/11/behaven/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 00:58:14 +0000</pubDate>
		<dc:creator>Jason Diamond</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[BehaveN]]></category>

		<guid isPermaLink="false">http://jason.diamond.name/weblog/?p=110</guid>
		<description><![CDATA[I&#8217;ve been using a Cucumber-inspired BDD framework for .NET called BehaveN at work for the past year. Today, I just released the next major version. There&#8217;s a little documentation on the wiki, including a tutorial, but there&#8217;s a lot left that I haven&#8217;t documented yet. I&#8217;ll be getting more and more documentation up as time [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using a <a href="http://cukes.info/">Cucumber</a>-inspired BDD framework for .NET called <a href="http://code.google.com/p/behaven/">BehaveN</a> at work for the past year. Today, I just released the next major version.</p>
<p>There&#8217;s a little documentation on the wiki, including a <a href="http://code.google.com/p/behaven/wiki/Tutorial">tutorial</a>, but there&#8217;s a lot left that I haven&#8217;t documented yet. I&#8217;ll be getting more and more documentation up as time goes on.</p>
<p>It&#8217;s been pretty positively received by our product owners, QA, and most of the developers who&#8217;ve been exposed to it. It&#8217;s being used by a few outside my company, but I haven&#8217;t made any effort on &#8220;advertising&#8221; it. If anybody&#8217;s interested in giving it a try, let me know and I&#8217;ll try to fill in any of the blanks you might have.</p>
]]></content:encoded>
			<wfw:commentRss>http://jason.diamond.name/weblog/2010/07/11/behaven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AutoRunner Downloads</title>
		<link>http://jason.diamond.name/weblog/2009/09/28/autorunner-downloads/</link>
		<comments>http://jason.diamond.name/weblog/2009/09/28/autorunner-downloads/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 04:23:06 +0000</pubDate>
		<dc:creator>Jason Diamond</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[AutoRunner]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://jason.diamond.name/weblog/?p=75</guid>
		<description><![CDATA[I took some time tonight to throw together a build script for producing proper releases of AutoRunner. If you don&#8217;t feel like compiling it yourself, you can get a pre-compiled version here. I used ILMerge to merge the Growl for Windows assemblies into the executable so it&#8217;s basically a single file now. By the way, [...]]]></description>
			<content:encoded><![CDATA[<p>I took some time tonight to throw together a build script for producing proper releases of <a href="http://github.com/jdiamond/autorunner">AutoRunner</a>. If you don&#8217;t feel like compiling it yourself, you can get a pre-compiled version <a href="http://github.com/jdiamond/autorunner/downloads">here</a>.</p>
<p>I used <a href="http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx">ILMerge</a> to merge the <a href="http://www.growlforwindows.com/">Growl for Windows</a> assemblies into the executable so it&#8217;s basically a single file now.</p>
<p>By the way, last night on Twitter, <a href="http://blog.unhandled-exceptions.com/">Steve Bohlen</a> pointed me to <a href="http://averyblog.com/net/announcing-autotest-net-0-1/">this port of the original autotest to .NET</a>. I took a look at the code and it was much more complex than I was looking for. It actually builds and runs your tests every time you save which is much more often than I want.</p>
<p>I had AutoRunner turned on all day at work today and was loving how it would catch me breaking the tests when I wasn&#8217;t expecting it to. =)</p>
]]></content:encoded>
			<wfw:commentRss>http://jason.diamond.name/weblog/2009/09/28/autorunner-downloads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AutoRunner</title>
		<link>http://jason.diamond.name/weblog/2009/09/27/autorunner/</link>
		<comments>http://jason.diamond.name/weblog/2009/09/27/autorunner/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 23:13:28 +0000</pubDate>
		<dc:creator>Jason Diamond</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[AutoRunner]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://jason.diamond.name/weblog/?p=66</guid>
		<description><![CDATA[I recently came across this awesome code kata performance by Corey Haines here. Besides enjoying and learning from his actual performance, I was really impressed by his use of a Ruby tool called autotest. (I&#8217;m not sure, but it looks like it has become autospec.) Not being a Ruby developer, I wanted the same thing [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across this awesome code kata performance by Corey Haines <a href="http://charlesmaxwood.com/8-lessons-from-corey-haines-performance-kata/">here</a>.</p>
<p>Besides enjoying and learning from his actual performance, I was really impressed by his use of a Ruby tool called <a href="http://ph7spot.com/articles/getting_started_with_autotest">autotest</a>. (I&#8217;m not sure, but it looks like it has become <a href="http://www.nateclark.com/articles/2008/09/17/_autotest_-is-now-_autospec_-how-to-set-up-autospec-for-rspec-and-rails-with-zentest">autospec</a>.)</p>
<p>Not being a Ruby developer, I wanted the same thing for .NET. I did some searching, but my Google-fu failed me so I spent an hour hacking together my own.</p>
<p>The result is called <a href="http://github.com/jdiamond/autorunner">AutoRunner</a> (I know&#8211;way creative) and its source is available on GitHub.</p>
<p>If you want it, you have to download the source and compile it yourself for now. (UPDATE: You can now download it <a href="http://github.com/jdiamond/autorunner/downloads">here</a>!) Run it from your favorite console (PowerShell, right?) without any arguments to see what options it accepts.</p>
<p>AutoRunner is a little more general purpose than autotest/autospec is. Basically, it can run any executable when any file changes.</p>
<p>What I wanted it for was to run nunit-console.exe whenever my current tests assembly was rebuilt. To do that, I just invoke it with the right arguments.</p>
<p>If you have <a href="http://www.growlforwindows.com/">Growl for Windows</a> running, it will send it a notification which is pure eye candy and not necessary to actually get it to run your tests.</p>
<p>It&#8217;s not a Visual Studio add-in. It&#8217;s just a plain old console application. Using Visual Studio&#8217;s External Tools feature, however, it&#8217;s almost as good as an add-in. I set up an external tool with the appropriate arguments and it&#8217;s good to go for all of my projects.</p>
<p>To set this up for yourself, you&#8217;d create a new external tool with its command set to the path where you built AutoRunner.exe and its arguments set to something like the following (I&#8217;ve separated the options on their own lines, but you wouldn&#8217;t do that in Visual Studio):</p>
<pre>--target $(BinDir)\$(TargetName)$(TargetExt)
--exe C:\path\to\nunit-console.exe
--pass "$(TargetName) FTW!"
--fail "Oh noes! $(TargetName) is FAIL!"</pre>
<p>You can use whatever test runner you like, of course. Please note that you must have a file from your tests project open or selected in Solution Explorer when you activate the tool or your AutoRunner instance will be watching the wrong DLL!</p>
<p>It doesn&#8217;t support plug-ins the way autotest does and most of its functionality is hard-coded for now. If anybody finds it useful, let me know and maybe we can work on improving it together.</p>
]]></content:encoded>
			<wfw:commentRss>http://jason.diamond.name/weblog/2009/09/27/autorunner/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SharpTestsEx</title>
		<link>http://jason.diamond.name/weblog/2009/09/26/sharptestsex/</link>
		<comments>http://jason.diamond.name/weblog/2009/09/26/sharptestsex/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 23:12:10 +0000</pubDate>
		<dc:creator>Jason Diamond</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://jason.diamond.name/weblog/?p=61</guid>
		<description><![CDATA[I&#8217;ve been using Fabio Maulo&#8216;s NUnitEx project to get fluent assertions on a personal project recently and have been loving it. He then went and moved on to a new project called SharpTestsEx, which he intended to be framework-agnostic, but currently only worked with MSTest which prevented me from being able to use it (since [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="http://fabiomaulo.blogspot.com/">Fabio Maulo</a>&#8216;s <a href="http://code.google.com/p/nunitex/">NUnitEx</a> project to get fluent assertions on a personal project recently and have been loving it.</p>
<p>He then went and moved on to a new project called <a href="http://sharptestex.codeplex.com/">SharpTestsEx</a>, which he intended to be framework-agnostic, but currently only worked with MSTest which prevented me from being able to use it (since I never saw a compelling reason to switch to MSTest).</p>
<p>Fabio was kind enough to let me make the changes necessary to remove the dependency on MSTest. A also made framework-specific versions of SharpTestsEx for MSTest, NUnit, and xUnit. The framework-specific versions aren&#8217;t really necessary, but they make the error messages a tiny bit prettier if you use the right one for the test framework you&#8217;re using.</p>
<p>You can read Fabio&#8217;s announcement <a href="http://fabiomaulo.blogspot.com/2009/09/sharp-tests-ex-030-fluent-and-lambda.html">here</a>.</p>
<p>I plan on updating my personal project to using SharpTestsEx next.</p>
<p>I just realized I never posted about that project; I&#8217;ll have to get around to that soon. If you&#8217;re curious, it&#8217;s a <a href="http://dannorth.net/introducing-bdd">behaviour-driven development</a> framework for .NET called <a href="http://code.google.com/p/behaven/">BehaveN</a>. I&#8217;m using it at my work and we&#8217;re loving it.</p>
]]></content:encoded>
			<wfw:commentRss>http://jason.diamond.name/weblog/2009/09/26/sharptestsex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nesting NHibernate Mapping Files</title>
		<link>http://jason.diamond.name/weblog/2009/09/07/nesting-nhibernate-mapping-files/</link>
		<comments>http://jason.diamond.name/weblog/2009/09/07/nesting-nhibernate-mapping-files/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 06:07:17 +0000</pubDate>
		<dc:creator>Jason Diamond</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://jason.diamond.name/weblog/?p=51</guid>
		<description><![CDATA[The problem: Hiding Your hbm.xml files in Visual Studio (or not) The solution: How to nest NHibernate mapping files in Visual Studio projects I&#8217;m doing this in Visual Studio 2008. I don&#8217;t know if this is a &#8220;bug&#8221; or not, but it sure is annoying. The fix Timo posted does work, but it requires editing [...]]]></description>
			<content:encoded><![CDATA[<p>The problem: <a href="http://www.primedigit.com/2008/04/08/hiding-your-hbmxml-files-in-visual-studio-or-not/">Hiding Your hbm.xml files in Visual Studio (or not)</a></p>
<p>The solution: <a href="http://theiterator.com/2009/02/how-to-nest-nhibernate-mapping-files-in-visual-studio-projects/">How to nest NHibernate mapping files in Visual Studio projects</a></p>
<p>I&#8217;m doing this in Visual Studio 2008. I don&#8217;t know if this is a &#8220;bug&#8221; or not, but it sure is annoying. The fix Timo posted does work, but it requires editing your .csproj file by hand which is both tedious and error-prone.</p>
]]></content:encoded>
			<wfw:commentRss>http://jason.diamond.name/weblog/2009/09/07/nesting-nhibernate-mapping-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TestDriven.NET Keyboard Shortcuts</title>
		<link>http://jason.diamond.name/weblog/2009/09/04/testdriven-dot-net-keyboard-shortcuts/</link>
		<comments>http://jason.diamond.name/weblog/2009/09/04/testdriven-dot-net-keyboard-shortcuts/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 20:57:21 +0000</pubDate>
		<dc:creator>Jason Diamond</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://jason.diamond.name/weblog/?p=44</guid>
		<description><![CDATA[I&#8217;m so sick of Ctrl+Tab&#8217;ing back to my test file, finding the test I want to run, right-clicking it with the mouse, and selecting Run Test(s) or Test With. How come nobody told me that TestDriven.NET came with keyboard shortcuts? They have to be manually mapped, but once I did that, I&#8217;ve found them indispensible. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m so sick of Ctrl+Tab&#8217;ing back to my test file, finding the test I want to run, right-clicking it with the mouse, and selecting Run Test(s) or Test With.</p>
<p>How come nobody told me that <a href="http://www.testdriven.net/">TestDriven.NET</a> came with keyboard shortcuts? They have to be manually mapped, but once I did that, I&#8217;ve found them indispensible.</p>
<ul>
<li>Alt+1 : TestDriven.NET.RunTests</li>
<li>Alt+2 : TestDriven.NET.RerunWithDefault</li>
<li>Alt+3 : TestDriven.NET.Debugger</li>
<li>Alt+4 : TestDriven.NET.RerunWithDebugger</li>
</ul>
<p>I especially love the two shortcuts that repeat the most recent test run for me. Yeah, I know you can right-click in any file and select Repeat Test Run, but if I want to alternate between running inside or outside the debugger, I have to go find the test again. With my shortcuts, I can just hit Alt+2 or Alt+4 no matter where I am.</p>
]]></content:encoded>
			<wfw:commentRss>http://jason.diamond.name/weblog/2009/09/04/testdriven-dot-net-keyboard-shortcuts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Splitting CamelCase With Regular Expressions</title>
		<link>http://jason.diamond.name/weblog/2009/08/15/splitting-camelcase-with-regular-expressions/</link>
		<comments>http://jason.diamond.name/weblog/2009/08/15/splitting-camelcase-with-regular-expressions/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 22:22:40 +0000</pubDate>
		<dc:creator>Jason Diamond</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://jason.diamond.name/weblog/?p=27</guid>
		<description><![CDATA[On my new project, I needed to split a method name up into its constituent parts. For Ruby programmers, this is easy: just split on underscores. For us .NET programmers, we need something a little fancier since we like to SquashOurMethodNamesTogetherLikeThis. Here&#8217;s a little regular expression that can do exactly that: (?&#60;!^)(?=[A-Z]) That basically says [...]]]></description>
			<content:encoded><![CDATA[<p>On my new project, I needed to split a method name up into its constituent parts.</p>
<p>For Ruby programmers, this is easy: just split on underscores. For us .NET programmers, we need something a little fancier since we like to <code>SquashOurMethodNamesTogetherLikeThis</code>.</p>
<p>Here&#8217;s a little regular expression that can do exactly that:</p>
<pre>(?&lt;!^)(?=[A-Z])</pre>
<p>That basically says to match right before every capital letter unless the capital letter is at the beginning of the string.</p>
<p>You can use the Regex.Split method to do the actual work of turning the method name into a string array:</p>
<pre class="brush:csharp">
Regex splitter = new Regex(@"(?&lt;!^)(?=[A-Z])");
string[] words = splitter.Split(methodName);
</pre>
<p>My friend, <a href="http://www.michaelckennedy.net/">Michael Kennedy</a>, demoed in class recently how to use <a href="http://www.linqpad.net/">LINQPad</a> to test regular expressions. It came in really handy while working on this:</p>
<p><img src="http://jason.diamond.name/weblog/wp-content/uploads/2009/08/linqpad-with-regex.png" alt="linqpad-with-regex" title="linqpad-with-regex" width="667" height="362" class="alignnone size-full wp-image-32" /></p>
<p>I really need to click that &#8220;Activate Autocompletion&#8221; button so I can give <a href="http://www.albahari.com/">Joseph Albahari</a> the money he deserves for creating such a useful tool.</p>
<p>By the way, I used to think that &#8220;camel case&#8221; was for words like &#8220;camelCase&#8221; and &#8220;pascal case&#8221; was for words like &#8220;PascalCase&#8221;, but <a href="http://en.wikipedia.org/wiki/PascalCase">Wikipedia</a> doesn&#8217;t make that distinction.</p>
]]></content:encoded>
			<wfw:commentRss>http://jason.diamond.name/weblog/2009/08/15/splitting-camelcase-with-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

