<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Enumerate this!</title>
	<atom:link href="http://enumeratethis.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://enumeratethis.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Mon, 02 Apr 2012 04:22:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='enumeratethis.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Enumerate this!</title>
		<link>http://enumeratethis.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://enumeratethis.com/osd.xml" title="Enumerate this!" />
	<atom:link rel='hub' href='http://enumeratethis.com/?pushpress=hub'/>
		<item>
		<title>Hosting your own poker tournament with LINQPad &amp; Reactive Extensions</title>
		<link>http://enumeratethis.com/2012/03/24/hosting-your-own-poker-tournament-with-linqpad-reactive-extensions/</link>
		<comments>http://enumeratethis.com/2012/03/24/hosting-your-own-poker-tournament-with-linqpad-reactive-extensions/#comments</comments>
		<pubDate>Sat, 24 Mar 2012 12:51:13 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=401</guid>
		<description><![CDATA[Playing poker next Saturday night &#38; want to impress your friends with your programming skills? The following solution requires LINQPad Beta release; It uses the new DumpLive feature allowing you to render reactive streams of WPF UI Elements! Enjoy! (from round in new[] { new{Small = 5, Big = 10, Length = 16}, new{Small = [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=401&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Playing poker next Saturday night &amp; want to impress your friends with your programming skills?</p>
<p>The following solution requires LINQPad Beta release; It uses the new DumpLive feature allowing you to render reactive streams of WPF UI Elements!</p>
<p>Enjoy!</p>
<pre class="csharpcode">(from round <span class="kwrd">in</span> <span class="kwrd">new</span>[]
{
    <span class="kwrd">new</span>{Small = 5, Big = 10, Length = 16},
    <span class="kwrd">new</span>{Small = 10, Big = 20, Length = 20},
    <span class="kwrd">new</span>{Small = 20, Big = 40, Length = 20},
    <span class="kwrd">new</span>{Small = 100, Big = 200, Length = 20},
    <span class="kwrd">new</span>{Small = 300, Big = 600, Length = 20},
    <span class="kwrd">new</span>{Small = 600, Big = 1200, Length = 20},
    <span class="kwrd">new</span>{Small = 1000, Big = 2000, Length = 20},
    <span class="kwrd">new</span>{Small = 5000, Big = 10000, Length = 20},
    <span class="kwrd">new</span>{Small = 30000, Big = 60000, Length = 20},
    <span class="kwrd">new</span>{Small = 100000, Big = 200000, Length = 20},
}
let ts = TimeSpan.FromMinutes(round.Length)
select from tick <span class="kwrd">in</span> Observable.Interval(TimeSpan.FromSeconds(1)).TakeUntil(Observable.Timer(ts))
let remaining = ts.Subtract(TimeSpan.FromSeconds(tick))
select <span class="kwrd">new</span>{
    text = <span class="kwrd">string</span>.Format(<span class="str">&quot;Small: {0}\r\nBig: {1}\r\nRemaining: {2}&quot;</span>, round.Small, round.Big, remaining),
    colour = remaining &lt; TimeSpan.FromMinutes(1) ? Brushes.Red : Brushes.Black
})
.Concat()
.ObserveOnDispatcher()
.Select(x =&gt; <span class="kwrd">new</span> TextBlock{Text = x.text, FontSize = 80, Foreground = x.colour})
.DumpLive();</pre>
<p><u>OUTPUT</u></p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/03/image9.png"><img title="image" style="margin:0 0 0 10px;display:inline;" alt="image" src="http://jamesmiles.files.wordpress.com/2012/03/image_thumb9.png?w=240&#038;h=120" width="240" height="120" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmiles.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmiles.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmiles.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmiles.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmiles.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmiles.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmiles.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmiles.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmiles.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmiles.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmiles.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmiles.wordpress.com/401/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=401&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/03/24/hosting-your-own-poker-tournament-with-linqpad-reactive-extensions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/03/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Rxx 1.3 Released (Rx Contribution Project)</title>
		<link>http://enumeratethis.com/2012/03/10/rxx-1-3-released-rx-contribution-project/</link>
		<comments>http://enumeratethis.com/2012/03/10/rxx-1-3-released-rx-contribution-project/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 09:07:33 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=399</guid>
		<description><![CDATA[See; http://rxx.codeplex.com/ There are lots of new features, fixes &#38; improvements. Release notes here; http://rxx.codeplex.com/wikipage?title=Release%20Notes<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=399&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>See; <a title="http://rxx.codeplex.com/" href="http://rxx.codeplex.com/">http://rxx.codeplex.com/</a></p>
<p>There are lots of new features, fixes &amp; improvements. Release notes here;</p>
<p><a title="http://rxx.codeplex.com/wikipage?title=Release%20Notes" href="http://rxx.codeplex.com/wikipage?title=Release%20Notes">http://rxx.codeplex.com/wikipage?title=Release%20Notes</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmiles.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmiles.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmiles.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmiles.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmiles.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmiles.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmiles.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmiles.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmiles.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmiles.wordpress.com/399/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmiles.wordpress.com/399/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmiles.wordpress.com/399/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=399&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/03/10/rxx-1-3-released-rx-contribution-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>
	</item>
		<item>
		<title>Reactive Extensions 2.0 Beta: Portable Libraries</title>
		<link>http://enumeratethis.com/2012/03/08/reactive-extensions-2-0-beta-portable-libraries/</link>
		<comments>http://enumeratethis.com/2012/03/08/reactive-extensions-2-0-beta-portable-libraries/#comments</comments>
		<pubDate>Thu, 08 Mar 2012 10:24:55 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=394</guid>
		<description><![CDATA[Further to my last post about Rx 2.0 assemblies. Have you ever worked on a project that required shared contracts between different Microsoft platforms? For example you might have the following architecture; Speaking from experience, this can become quite painful as you need a “multi-targeted compilation strategy”. Good news! .NET 4.5 allows you to create [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=394&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Further to my <a href="http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta-assembly-references/">last post about Rx 2.0 assemblies</a>.</p>
<p>Have you ever worked on a project that required shared contracts between different Microsoft platforms? For example you might have the following architecture;</p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/03/image6.png"><img style="display:inline;margin:0 0 0 10px;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/03/image_thumb6.png?w=400&#038;h=250" width="400" height="250" /></a></p>
<p>Speaking from experience, this can become quite painful as you need a “multi-targeted compilation strategy”. Good news! .NET 4.5 allows you to create “<a href="http://msdn.microsoft.com/en-us/library/gg597391(v=vs.110).aspx">portable class libraries</a>” that work on multiple .NET Framework platforms.</p>
<p>The even better news is that this has not been neglected by the Rx team. This diagram shows you which Rx assemblies can be referenced by your own portable class libraries.</p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/03/image8.png"><img style="display:inline;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/03/image_thumb8.png?w=400&#038;h=163" width="400" height="163" /></a></p>
<p>Presumably this means you can create libraries of Rx operators and share them between metro, desktop, phone &amp; xbox applications. That’s awesome!</p>
<p>*UPDATE* I wonder if people would be interested in a portable version of <a href="http://rxx.codeplex.com/">Rxx</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmiles.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmiles.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmiles.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmiles.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmiles.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmiles.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmiles.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmiles.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmiles.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmiles.wordpress.com/394/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmiles.wordpress.com/394/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmiles.wordpress.com/394/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=394&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/03/08/reactive-extensions-2-0-beta-portable-libraries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/03/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/03/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Reactive Extensions 2.0 Beta: Assembly References</title>
		<link>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta-assembly-references/</link>
		<comments>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta-assembly-references/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 03:56:21 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Rx]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=377</guid>
		<description><![CDATA[Before you jump into Rx 2.0 Beta you should know about some of the changes to the hierarchy of assemblies. Rx 1.0 assemblies were structured like this; &#160; Rx 2.0 assemblies are structured like this; The big change here is the addition of the System.Reactive.Interfaces &#38; System.Reactive.PlatformServices. I’m guessing that the thinking behind this change [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=377&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Before you jump into Rx 2.0 Beta you should know about some of the changes to the hierarchy of assemblies.</p>
<p>Rx 1.0 assemblies were structured like this;</p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/03/image4.png"><img style="display:inline;margin:0;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/03/image_thumb4.png?w=500&#038;h=88" width="500" height="88" /></a></p>
<p>&#160;</p>
<p>Rx 2.0 assemblies are structured like this;</p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/03/image5.png"><img style="display:inline;margin:0;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/03/image_thumb5.png?w=500&#038;h=169" width="500" height="169" /></a></p>
<p>The big change here is the addition of the System.Reactive.Interfaces &amp; System.Reactive.PlatformServices.</p>
<p>I’m guessing that the thinking behind this change but;</p>
<p><strong>System.Reactive.Interfaces</strong> </p>
<p>This will allow people to define “service contracts” without bringing in the entire Rx stack.</p>
<p><strong>System.Reactive.PlatformServices</strong></p>
<p>This eliminates a hard dependency on platform specific scheduling, concurrency &amp; timing including low level components such as the thread pool &amp; high resolution timers.</p>
<p>More soon   <br />James</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmiles.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmiles.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmiles.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmiles.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmiles.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmiles.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmiles.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmiles.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmiles.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmiles.wordpress.com/377/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmiles.wordpress.com/377/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmiles.wordpress.com/377/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=377&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta-assembly-references/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/03/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/03/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Reactive Extensions 2.0 Beta</title>
		<link>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta/</link>
		<comments>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 01:43:29 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=371</guid>
		<description><![CDATA[Rx 2.0 is coming! http://www.microsoft.com/download/en/details.aspx?id=29058 http://social.msdn.microsoft.com/Forums/en-US/rx/thread/c8aa306a-2627-4b04-9b2f-d3154876894b<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=371&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Rx 2.0 is coming!</p>
<p><a href="http://www.microsoft.com/download/en/details.aspx?id=29058">http://www.microsoft.com/download/en/details.aspx?id=29058</a>    <br /><a href="http://social.msdn.microsoft.com/Forums/en-US/rx/thread/c8aa306a-2627-4b04-9b2f-d3154876894b">http://social.msdn.microsoft.com/Forums/en-US/rx/thread/c8aa306a-2627-4b04-9b2f-d3154876894b</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmiles.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmiles.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmiles.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmiles.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmiles.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmiles.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmiles.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmiles.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmiles.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmiles.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmiles.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmiles.wordpress.com/371/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=371&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/03/07/reactive-extensions-2-0-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>
	</item>
		<item>
		<title>Rx &#8211; Awaiting events &amp; observables in C# 5</title>
		<link>http://enumeratethis.com/2012/02/17/rx-awaiting-events-observables-in-c-5/</link>
		<comments>http://enumeratethis.com/2012/02/17/rx-awaiting-events-observables-in-c-5/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 04:02:48 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=367</guid>
		<description><![CDATA[So everyone is now using C# 5 to write asynchronous methods to await tasks right Did you know you can also await other things? Like events &#38; observables!? The following code demonstrates how you can “await” items being added to an observable collection. using System; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Reactive; using System.Reactive.Linq; namespace ConsoleApplication11 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=367&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So everyone is now using C# 5 to write asynchronous methods to await tasks right <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Did you know you can also await other things? Like events &amp; observables!?</p>
<p>The following code demonstrates how you can “await” items being added to an observable collection.</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.ObjectModel;
<span class="kwrd">using</span> System.Collections.Specialized;
<span class="kwrd">using</span> System.Reactive;
<span class="kwrd">using</span> System.Reactive.Linq;

<span class="kwrd">namespace</span> ConsoleApplication11
{
    <span class="kwrd">class</span> Program
    {
        <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">readonly</span> ObservableCollection&lt;<span class="kwrd">int</span>&gt; Collection = <span class="kwrd">new</span> ObservableCollection&lt;<span class="kwrd">int</span>&gt;();

        <span class="kwrd">static</span> <span class="kwrd">void</span> Main()
        {
            Test();
            Collection.Add(42);
        }

        <span class="kwrd">public</span> <span class="kwrd">static</span> async <span class="kwrd">void</span> Test()
        {
            Console.WriteLine(<span class="str">"awaiting event..."</span>);
            var itemsAdded = await
                (
                    from collectionChanged <span class="kwrd">in</span> Collection.ToNotifyCollectionChangedObservable()
                    <span class="kwrd">where</span> collectionChanged.EventArgs.Action == NotifyCollectionChangedAction.Add
                    select collectionChanged.EventArgs.NewItems
                )
                .Take(1);

            Console.WriteLine(<span class="str">"items added;"</span>);
            <span class="kwrd">foreach</span> (var item <span class="kwrd">in</span> itemsAdded)
                Console.WriteLine(item);
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> Extensions
    {
        <span class="kwrd">public</span> <span class="kwrd">static</span> IObservable&lt;EventPattern&lt;NotifyCollectionChangedEventArgs&gt;&gt;
            ToNotifyCollectionChangedObservable(<span class="kwrd">this</span> INotifyCollectionChanged source)
        {
            <span class="kwrd">return</span> Observable.FromEventPattern&lt;NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs&gt;
                (h =&gt; source.CollectionChanged += h,
                h =&gt; source.CollectionChanged -= h);
        }
    }
}
</pre>
<p>Enjoy!</p>
<p>*UPDATE* make sure you have Rx-experimental release. The GetAwaiter method is not in the stable release yet!</p>
<pre class="csharpcode">&nbsp;</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmiles.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmiles.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmiles.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmiles.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmiles.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmiles.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmiles.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmiles.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmiles.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmiles.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmiles.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmiles.wordpress.com/367/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=367&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/02/17/rx-awaiting-events-observables-in-c-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>
	</item>
		<item>
		<title>Pop Quiz: Asynchronous Methods &amp; Contract Errors</title>
		<link>http://enumeratethis.com/2012/02/13/pop-quiz-asynchronous-methods-contract-errors/</link>
		<comments>http://enumeratethis.com/2012/02/13/pop-quiz-asynchronous-methods-contract-errors/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 12:04:09 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=364</guid>
		<description><![CDATA[This is for people wanting to expand their asynchronous brains! Pop Quiz Here is a question for you; What will this seemly trivial program segment do? void X() { try { Y(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } async void Y() { throw new NotImplementedException(); } Before you answer, consider another question; Is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=364&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is for people wanting to expand their asynchronous brains!</p>
<h3>Pop Quiz</h3>
<p>Here is a question for you; What will this seemly trivial program segment do?</p>
<pre class="csharpcode"><span class="kwrd">void</span> X()
{
    <span class="kwrd">try</span>
    {
        Y();
    }
    <span class="kwrd">catch</span> (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

async <span class="kwrd">void</span> Y()
{
    <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
}</pre>
<p>Before you answer, consider another question; Is there a behavioral difference between these two methods?</p>
<pre class="csharpcode">IEnumerable&lt;<span class="kwrd">int</span>&gt; J()
{
    <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
}

IEnumerable&lt;<span class="kwrd">int</span>&gt; K()
{
    <span class="kwrd">throw</span> <span class="kwrd">new</span> NotImplementedException();
    <span class="kwrd">yield</span> <span class="kwrd">return</span> -1;
}</pre>
<p>Don’t worry some Rx posts are coming soon!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/364/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmiles.wordpress.com/364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmiles.wordpress.com/364/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmiles.wordpress.com/364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmiles.wordpress.com/364/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmiles.wordpress.com/364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmiles.wordpress.com/364/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmiles.wordpress.com/364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmiles.wordpress.com/364/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmiles.wordpress.com/364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmiles.wordpress.com/364/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmiles.wordpress.com/364/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmiles.wordpress.com/364/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=364&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/02/13/pop-quiz-asynchronous-methods-contract-errors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>
	</item>
		<item>
		<title>Reactive Extensions utilizing 64 cores</title>
		<link>http://enumeratethis.com/2012/02/07/reactive-extensions-utilizing-64-cores/</link>
		<comments>http://enumeratethis.com/2012/02/07/reactive-extensions-utilizing-64-cores/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 05:08:15 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=352</guid>
		<description><![CDATA[Saw this on Facebook… welcome to the future;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=352&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Saw this on Facebook… welcome to the future;</p>
<p><a href="http://jamesmiles.files.wordpress.com/2012/02/image.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;margin:0 0 0 10px;" title="image" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2012/02/image_thumb.png?w=600&#038;h=522" width="600" height="522" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmiles.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmiles.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmiles.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmiles.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmiles.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmiles.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmiles.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmiles.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmiles.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmiles.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmiles.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmiles.wordpress.com/352/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=352&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/02/07/reactive-extensions-utilizing-64-cores/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/02/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Hostile to friendly type names</title>
		<link>http://enumeratethis.com/2012/01/10/hostile-to-friendly-type-names/</link>
		<comments>http://enumeratethis.com/2012/01/10/hostile-to-friendly-type-names/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 04:41:28 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=343</guid>
		<description><![CDATA[Have you ever written some code that dumps type names using reflection and run into annoyances like this? Query new[] { typeof(List&#60;int&#62;), typeof(List&#60;List&#60;int&#62;&#62;), typeof(int?), typeof(bool), }.Select(t =&#62; t.Name).Dump(&#34;hostile type names&#34;); Output &#160; This can be problematic if you are trying to generate C# code via T4 templates or something similar. A colleague and I recently [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=343&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Have you ever written some code that dumps type names using reflection and run into annoyances like this? </p>
<h5>Query</h5>
<pre class="csharpcode"><span class="kwrd">new</span>[]
{
    <span class="kwrd">typeof</span>(List&lt;<span class="kwrd">int</span>&gt;),
    <span class="kwrd">typeof</span>(List&lt;List&lt;<span class="kwrd">int</span>&gt;&gt;),
    <span class="kwrd">typeof</span>(<span class="kwrd">int</span>?),
    <span class="kwrd">typeof</span>(<span class="kwrd">bool</span>),
}.Select(t =&gt; t.Name).Dump(<span class="str">&quot;hostile type names&quot;</span>);</pre>
<h5>Output</h5>
<p><a href="http://jamesmiles.files.wordpress.com/2012/01/image.png"><img style="display:inline;margin:0 0 0 10px;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/01/image_thumb.png?w=226&#038;h=133" width="226" height="133" /></a></p>
<p>&#160;</p>
<p>This can be problematic if you are trying to generate C# code via T4 templates or something similar.</p>
<p>A colleague and I recently solved this problem using the C# CodeDom (handy extension method included).</p>
<h5>Query</h5>
<pre class="csharpcode"><span class="kwrd">new</span>[]
{
    <span class="kwrd">typeof</span>(List&lt;<span class="kwrd">int</span>&gt;),
    <span class="kwrd">typeof</span>(List&lt;List&lt;<span class="kwrd">int</span>&gt;&gt;),
    <span class="kwrd">typeof</span>(<span class="kwrd">int</span>?),
    <span class="kwrd">typeof</span>(<span class="kwrd">bool</span>),
}
.Select(t =&gt; <span class="kwrd">new</span>
{
    HostileName = t.Name,
    FriendlyName = t.GetFriendlyName()
})
.Dump(<span class="str">&quot;hostile -&gt; friendly type names&quot;</span>);</pre>
<h5>Output</h5>
<p><a href="http://jamesmiles.files.wordpress.com/2012/01/image1.png"><img style="display:inline;margin:0 0 0 10px;" title="image" alt="image" src="http://jamesmiles.files.wordpress.com/2012/01/image_thumb1.png?w=500&#038;h=129" width="500" height="129" /></a></p>
<h5>&#160;</h5>
<h5>Extension method</h5>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> TypeEx
{
    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span> GetFriendlyName(<span class="kwrd">this</span> Type t)
    {
        <span class="kwrd">using</span> (var provider = <span class="kwrd">new</span> CSharpCodeProvider())
        {
            var typeRef = <span class="kwrd">new</span> CodeTypeReference(t);
            <span class="kwrd">return</span> provider.GetTypeOutput(typeRef);
        }
    }
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmiles.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmiles.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmiles.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmiles.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmiles.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmiles.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmiles.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmiles.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmiles.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmiles.wordpress.com/343/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmiles.wordpress.com/343/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmiles.wordpress.com/343/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=343&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2012/01/10/hostile-to-friendly-type-names/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/01/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2012/01/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Structs that implement IEnumerator</title>
		<link>http://enumeratethis.com/2011/11/30/structs-that-implement-ienumerator/</link>
		<comments>http://enumeratethis.com/2011/11/30/structs-that-implement-ienumerator/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 10:39:56 +0000</pubDate>
		<dc:creator>James Miles</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">https://jamesmiles.wordpress.com/?p=324</guid>
		<description><![CDATA[OK. Lets just revise the query we had in the previous post. I’m going to change it so that is finds enumerators that are also value types; from f in Directory.GetFiles ( Path.Combine ( Environment.GetFolderPath (System.Environment.SpecialFolder.ProgramFilesX86), @&#34;Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0&#34;), &#34;*.dll&#34;) where !f.ToLowerInvariant().Contains (&#34;thunk&#34;) where !f.ToLowerInvariant().Contains (&#34;wrapper&#34;) select Assembly.LoadFrom (f) into a from t in a.GetExportedTypes() where [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=324&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>OK. Lets just revise the query we had in the <a href="http://enumeratethis.com/2011/11/22/structs-that-implement-idisposable/">previous post</a>. I’m going to change it so that is finds enumerators that are also value types;</p>
<pre class="csharpcode">from f <span class="kwrd">in</span> Directory.GetFiles (
       Path.Combine (
             Environment.GetFolderPath (System.Environment.SpecialFolder.ProgramFilesX86),
             <span class="str">@&quot;Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0&quot;</span>),
       <span class="str">&quot;*.dll&quot;</span>)
<span class="kwrd">where</span> !f.ToLowerInvariant().Contains (<span class="str">&quot;thunk&quot;</span>)
<span class="kwrd">where</span> !f.ToLowerInvariant().Contains (<span class="str">&quot;wrapper&quot;</span>)
select Assembly.LoadFrom (f) into a
from t <span class="kwrd">in</span> a.GetExportedTypes()
<span class="kwrd">where</span> t.IsValueType &amp;&amp; <span class="kwrd">typeof</span>(IEnumerator).IsAssignableFrom (t)
select <span class="kwrd">new</span> { a.GetName().Name, t.FullName }</pre>
<p>Running the query in LINQPad will yield the following results.</p>
<p><a href="http://jamesmiles.files.wordpress.com/2011/11/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;margin:0 0 0 10px;" title="image" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2011/11/image_thumb1.png?w=400&#038;h=478" width="400" height="478" /></a></p>
<p>It would seem like a CRAZY! thing to do given that an enumerator, is by its very nature, mutable… I’ll try to reason why this might be beneficial; then we will look at why it sucks.</p>
<p><strong>Possible Reasoning</strong></p>
<p>I can think of two possible reasons why they might have chosen to do this.</p>
<p>1. It could be considered a “feature” in that if you ever wanted to remember or save the current state of a collection’s enumerator, you could just copy it to another field. I’m going to rule this out, the behaviour isn’t consistent with other enumerators (arrays, non-generic collections and then later, iterator blocks).</p>
<p>2. Another possibility is performance. Perhaps the BCL team were looking to avoid the heap allocation caused by calling GetEnumerator.</p>
<p>It would seem like a “micro optimisation”; does that tiny heap allocation really cause an issue? I’m going to look at a popular design pattern that I think might expose the problem they were trying to solve. </p>
<p><strong>The Composite Design Pattern</strong></p>
<p>Consider a C# implementation of the Composite pattern;</p>
<pre class="csharpcode"><span class="rem">// Composite design pattern</span>
<span class="kwrd">class</span> Node
{
    <span class="kwrd">public</span> <span class="kwrd">readonly</span> ArrayList Children = <span class="kwrd">new</span> ArrayList();

    <span class="kwrd">public</span> <span class="kwrd">void</span> Recurse()
    {
        <span class="kwrd">foreach</span>(Node child <span class="kwrd">in</span> Children)
        {
            child.Recurse();
        }
    }
}</pre>
<p>Now lets consider a simple usage (1000 nodes with 1000 children).</p>
<pre class="csharpcode">var root = <span class="kwrd">new</span> Node();
<span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; 1000; i++)
{
    var child = <span class="kwrd">new</span> Node();
    <span class="kwrd">for</span> (<span class="kwrd">int</span> j = 0; j &lt; 1000; j++)
    {
        child.Children.Add(<span class="kwrd">new</span> Node());
    }
    root.Children.Add(child);
}

var before = GC.CollectionCount(0);
root.Recurse();
var after = GC.CollectionCount(0);
Console.WriteLine(<span class="str">&quot;Collection Count: &quot;</span> + (after - before));</pre>
<p><u>OUTPUT</u></p>
<p><a href="http://jamesmiles.files.wordpress.com/2011/11/image2.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2011/11/image_thumb2.png?w=244&#038;h=86" width="244" height="86" /></a></p>
<p>That’s right 7 GCs just to recurse our composite tree structure! Yikes!</p>
<p>If we change from ArrayList to List&lt;object&gt;, you can see the difference.</p>
<p><a href="http://jamesmiles.files.wordpress.com/2011/11/image3.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;margin:0;" title="image" border="0" alt="image" src="http://jamesmiles.files.wordpress.com/2011/11/image_thumb3.png?w=244&#038;h=77" width="244" height="77" /></a></p>
<p>Is this a realistic scenario? Can anyone think of a LARGE instance of the composite design pattern present in many of today’s .NET applications? I’ll give you a clue, it starts with W… and ends in PF.</p>
<p>WPF &amp; Silverlight are text book implementations of the composite design pattern; can you imagine how many times the tree is traversed in this manner? Can you imagine how deep the tree is for a complex user interface? In my mind, this is a good theory for explaining why, at the very least the “presentation core” enumerators have been implemented in this manner. I think most developers would have implemented a composite design pattern using List&lt;T&gt; at some stage or another.</p>
<p><strong>Possible Problems</strong></p>
<p>So is it likely that someone would trip over this optimisation? Lets start with the obvious ones before moving to hell.</p>
<pre class="csharpcode">List&lt;<span class="kwrd">int</span>&gt;.Enumerator e1 = <span class="kwrd">new</span> List&lt;<span class="kwrd">int</span>&gt;{1,2,3,4,5}.GetEnumerator();
List&lt;<span class="kwrd">int</span>&gt;.Enumerator e2 = e1;
e1.MoveNext();
Console.WriteLine(e1.Current);
Console.WriteLine(e2.Current);</pre>
<p>This will output 1 &amp; 0. The team probably decided to take this hit, after all any normal person would write this.</p>
<pre class="csharpcode">IEnumerator&lt;<span class="kwrd">int</span>&gt; e1 = <span class="kwrd">new</span> List&lt;<span class="kwrd">int</span>&gt;{1,2,3,4,5}.GetEnumerator();
IEnumerator&lt;<span class="kwrd">int</span>&gt; e2 = e1;
e1.MoveNext();
Console.WriteLine(e1.Current);
Console.WriteLine(e2.Current);</pre>
<p>This causes the value type to be boxed, meaning the “copy by value” semantics disappear and we get two references to the same enumerator, giving us the expected output of 1 &amp; 1. But wait a second, most developers in .NET 3.5 / C# 3.0 will write this;</p>
<pre class="csharpcode">var e1 = <span class="kwrd">new</span> List&lt;<span class="kwrd">int</span>&gt;{1,2,3,4,5}.GetEnumerator();
var e2 = e1;
e1.MoveNext();
Console.WriteLine(e1.Current);
Console.WriteLine(e2.Current);</pre>
<p>Uh oh! GetEnumerator returns List&lt;int&gt;.Enumerator meaning the inferred type is the value type, we’re back to square one!</p>
<p>I guess you could argue, well at least the problem is localised to this statement; it isn’t like people are passing these around from one method to another.</p>
<p>Oh wait, but what about the interference of generic type parameters! This is heavily leveraged by technologies like LINQ &amp; Rx (NOTE: This is how I came up with <a href="http://enumeratethis.com/2011/10/26/observable-generate-pop-quiz/">my recent pop quiz</a>!).</p>
<p>Consider the following;</p>
<pre class="csharpcode">    <span class="kwrd">public</span> <span class="kwrd">class</span> Wrapper&lt;T&gt; <span class="kwrd">where</span> T : IEnumerator
    {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> T enumerator;

        <span class="kwrd">public</span> Wrapper(T enumerator)
        {
            <span class="kwrd">this</span>.enumerator = enumerator;
        }

        <span class="kwrd">public</span> <span class="kwrd">object</span> Current
        {
            get { <span class="kwrd">return</span> enumerator.Current; }
        }

        <span class="kwrd">public</span> <span class="kwrd">bool</span> MoveNext()
        {
            <span class="kwrd">return</span> enumerator.MoveNext();
        }
    }</pre>
<p>&#160;</p>
<p><strong>Impromptu Pop Quiz</strong></p>
<p>I don’t want to box the enumerator… we only have one storage location. </p>
<p><span class="kwrd">private</span> <span class="kwrd">readonly</span> T enumerator; </p>
<p>Will this wrapper work for enumerators that are value types?</p>
<p>Here is a complete program for you to play with.</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Collections;

<span class="kwrd">namespace</span> ConsoleApplication30
{
    <span class="kwrd">class</span> Program
    {
        <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Main()
        {
            var w = Wrapper.Create(<span class="kwrd">new</span> List&lt;<span class="kwrd">int</span>&gt; { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }.GetEnumerator());
            w.MoveNext();
            Console.WriteLine(<span class="str">&quot;Expected value: 1&quot;</span>);
            Console.WriteLine(<span class="str">&quot;Actual value: &quot;</span> + w.Current);
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> Wrapper
    {
        <span class="kwrd">public</span> <span class="kwrd">static</span> Wrapper&lt;T&gt; Create&lt;T&gt;(T enumerator)
            <span class="kwrd">where</span> T : IEnumerator
        {
            <span class="kwrd">return</span> <span class="kwrd">new</span> Wrapper&lt;T&gt;(enumerator);
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">class</span> Wrapper&lt;T&gt; <span class="kwrd">where</span> T : IEnumerator
    {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> T enumerator;

        <span class="kwrd">public</span> Wrapper(T enumerator)
        {
            <span class="kwrd">this</span>.enumerator = enumerator;
        }

        <span class="kwrd">public</span> <span class="kwrd">object</span> Current
        {
            get { <span class="kwrd">return</span> enumerator.Current; }
        }

        <span class="kwrd">public</span> <span class="kwrd">bool</span> MoveNext()
        {
            <span class="kwrd">return</span> enumerator.MoveNext();
        }
    }
}</pre>
<p>Look forward to your replies!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jamesmiles.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jamesmiles.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jamesmiles.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jamesmiles.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jamesmiles.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jamesmiles.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jamesmiles.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jamesmiles.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jamesmiles.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jamesmiles.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jamesmiles.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jamesmiles.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jamesmiles.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jamesmiles.wordpress.com/324/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=enumeratethis.com&amp;blog=12887106&amp;post=324&amp;subd=jamesmiles&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://enumeratethis.com/2011/11/30/structs-that-implement-ienumerator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48817ecff33b122ba3ab38257be683b8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jamesmiles</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2011/11/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2011/11/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://jamesmiles.files.wordpress.com/2011/11/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>
