<?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>JasonJackson.com &#187; .Net</title>
	<atom:link href="http://jasonjackson.com/weblog/category/programming/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://jasonjackson.com/weblog</link>
	<description>A site about programming and life.</description>
	<lastBuildDate>Thu, 08 Dec 2011 20:24:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Visual Studio 2010 Keyboard Shortcuts</title>
		<link>http://jasonjackson.com/weblog/2010/07/29/visual-studio-2010-keyboard-shortcuts/</link>
		<comments>http://jasonjackson.com/weblog/2010/07/29/visual-studio-2010-keyboard-shortcuts/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 04:01:19 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://jasonjackson.com/weblog/?p=1022</guid>
		<description><![CDATA[Back when I used to have an MSDN license, or work for a small enough company where I administered the license, I always enjoyed receiving the various Microsoft posters.  I had posters of all of the .Net System namespaces, ASCII posters, etc.  A really useful one was the keyboard shortcut poster.  Scott Guthrie just posted [...]]]></description>
			<content:encoded><![CDATA[<p>Back when I used to have an MSDN license, or work for a small enough company where I administered the license, I always enjoyed receiving the various Microsoft posters.  I had posters of all of the .Net System namespaces, ASCII posters, etc.  A really useful one was the keyboard shortcut poster.  Scott Guthrie just posted the new Visual Studio 2010 keyboard <a href="http://weblogs.asp.net/scottgu/archive/2010/07/29/visual-studio-2010-keyboard-shortcuts.aspx">shortcuts posters</a>.  Using even a few of the most productive keys will make you day coding much more enjoyable.  I encourage all programmers to pick up a copy of these posters and pick up a few new key combos.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonjackson.com/weblog/2010/07/29/visual-studio-2010-keyboard-shortcuts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The new System.Collections.Concurrent Namespace</title>
		<link>http://jasonjackson.com/weblog/2010/07/20/the-new-system-collections-concurrent-namespace/</link>
		<comments>http://jasonjackson.com/weblog/2010/07/20/the-new-system-collections-concurrent-namespace/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 21:54:50 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://jasonjackson.com/weblog/?p=1011</guid>
		<description><![CDATA[I just stumbled across the new System.Collections.Concurrent Namespace in .Net 4.0.  I needed a thread safe dictionary and a coworker suggested I check out ConcurrentDictionary.  Of course if you are attempting multiple operations against the dictionary you still need to lock or use some other type of mutex.  But if all you are doing is [...]]]></description>
			<content:encoded><![CDATA[<p>I just stumbled across the new <a title="http://msdn.microsoft.com/en-us/library/system.collections.concurrent.aspx" href="http://" target="_blank">System.Collections.Concurrent Namespace</a> in .Net 4.0.  I needed a thread safe dictionary and a coworker suggested I check out <a href="http://msdn.microsoft.com/en-us/library/dd287191.aspx" target="_blank">ConcurrentDictionary</a>.  Of course if you are attempting multiple operations against the dictionary you still need to lock or use some other type of mutex.  But if all you are doing is reading a writing from multiple threads in single, atomic statements then this is the critter for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonjackson.com/weblog/2010/07/20/the-new-system-collections-concurrent-namespace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>COM: Everytime I think I am out, it pulls me back in. (Silverlight + DLR)</title>
		<link>http://jasonjackson.com/weblog/2010/05/24/com-everytime-i-think-i-am-out-it-pulls-me-back-in/</link>
		<comments>http://jasonjackson.com/weblog/2010/05/24/com-everytime-i-think-i-am-out-it-pulls-me-back-in/#comments</comments>
		<pubDate>Mon, 24 May 2010 20:38:42 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://jasonjackson.com/weblog/?p=989</guid>
		<description><![CDATA[Silverlight 4 introduces some nice functionality on top of the Out Of Browser (OOB) capabilities introduced in Silverlight 3.  The application can now be granted a higher level of trust which allows it to operate outside the Silverlight sandbox file system, and to interact with COM.  To test the capabilities of this new functionality I [...]]]></description>
			<content:encoded><![CDATA[<p>Silverlight 4 introduces some nice functionality on top of the Out Of Browser (OOB) capabilities introduced in Silverlight 3.  The application can now be granted a higher level of trust which allows it to operate outside the Silverlight sandbox file system, and to interact with COM.  To test the capabilities of this new functionality I immediately tried to take it file system access far beyond the sandbox; I wanted to enumerate all of the drives on the client machine.  I quickly ran into a wall.  Silverlight does not expose access to drives through its IO libraries.  Why?  I read several answers to this question, none of which satisfied me, especially given the fact that the app can simply access these drives through COM!</p>
<p>Luckily .Net 4.0 / Silverlight 4.0 / C# 4.0 comes with the Dynamic Language Runtime (DLR).  I had previous used the new dynamic pseudo-type that ties into the DLR to call Iron Python.  I figured I would see if I could use this same technique to call into COM.  Back in ancient times (circa 1990s) I called into COM all the time from VB and ASP.  I knew the libraries were all there to do what I needed to do.</p>
<p>I was not surprised to find I wasn&#8217;t the first person down this path, and quickly encountered multiple articles and postings about working with the file system via COM this exact way.  With the knowledge that it was possible I plowed forward.</p>
<p>To access COM from Silverlight one uses the AutomationFactory to instantiate a COM library.  I wanted to use the good ol&#8217; Scripting.FileSystemObject.  In my test case I had a Silverlight app running locally OOB with elevated privileges.  This Silverlight app has a single list box which will display the drive letters once I can get access.  Via COM, the code looks like this:</p>
<pre class="brush: csharp; title: ;">
dynamic fs = AutomationFactory.CreateObject(&quot;Scripting.FileSystemObject&quot;);

foreach (dynamic drive in fs.Drives)
{
  filesListBox.Items.Add(drive.DriveLetter);
}
</pre>
<p>Its really that simple.  The dynamic keyword and COM do all the heavy lifting.  The most work I had to do was lookup the object model to use in the FSO, as no intellisense is available.  The runtime does late binding onto these properties via the DLR.  This did a nice end-route around the missing Silverlight IO libraries and provided me with a nice list of drives.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonjackson.com/weblog/2010/05/24/com-everytime-i-think-i-am-out-it-pulls-me-back-in/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excellent C# Threading Memory Model Article</title>
		<link>http://jasonjackson.com/weblog/2010/04/28/excellent-c-threading-memory-model-article/</link>
		<comments>http://jasonjackson.com/weblog/2010/04/28/excellent-c-threading-memory-model-article/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 15:40:56 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://jasonjackson.com/weblog/?p=979</guid>
		<description><![CDATA[I just read an excellent article on the memory model in .Net and C# as it relates to threading, written my Microsoft&#8217;s Igor Ostrovsky.  I think I had gathered most of these details over the years from various MSDN articles and CLR Via C# (1 &#38; 2) by Jeffrey Richter.  However, Ostrovsky provides a solid [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jasonjackson.com/weblog/wp-content/uploads/2010/04/multi-threading.jpg"><img class="alignleft size-full wp-image-980" title="multi-threading" src="http://jasonjackson.com/weblog/wp-content/uploads/2010/04/multi-threading.jpg" alt="" width="250" height="188" /></a>I just read an <a href="http://igoro.com/archive/volatile-keyword-in-c-memory-model-explained/" target="_blank">excellent article</a> on the memory model in .Net and C# as it relates to threading, written my Microsoft&#8217;s <a href="http://igoro.com/" target="_self">Igor Ostrovsky</a>.  I think I had gathered most of these details over the years from various MSDN articles and <a href="http://www.amazon.com/CLR-Via-C-Pro-Developer/dp/0735621632" target="_self">CLR Via C#</a> (1 &amp; 2) by Jeffrey Richter.  However, Ostrovsky provides a solid narration of how the model works.  I was unaware that the local thread cache (conceptually) is all or nothing on reads and writes.  There are a lot of misconceptions of how threads, locks, and volatile variables work and this article does a pretty good job of nailing it all down.  There are some pieces of information that I had previously found slightly contradictory that really make sense when reading the article.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonjackson.com/weblog/2010/04/28/excellent-c-threading-memory-model-article/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net 4.0 and VS 2010 GA</title>
		<link>http://jasonjackson.com/weblog/2010/04/12/net-4-0-and-vs-2010-ga/</link>
		<comments>http://jasonjackson.com/weblog/2010/04/12/net-4-0-and-vs-2010-ga/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 13:46:29 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://jasonjackson.com/weblog/?p=952</guid>
		<description><![CDATA[Microsoft has released the 4.0 version of the .Net Framework and Visual Studio 2010.  The release includes several framework enhancements.  The Dynamic Language Runtime has been added, which will act as a useful bridge to such languages as IronPython and IronRuby.  The DLR optimizes dynamic languages at runtime for better performance with .Net.  Also added [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft has <a href="http://www.microsoft.com/Presspass/press/2010/apr10/04-11VS10PR.mspx" target="_blank">released</a> the 4.0 version of the .Net Framework and Visual Studio 2010.  The release includes several framework enhancements.  The Dynamic Language Runtime has been added, which will act as a useful bridge to such languages as IronPython and IronRuby.  The DLR optimizes dynamic languages at runtime for better performance with .Net.  Also added is the dynamic pseudo-type, which allows run-time lookup of properties and methods on dynamic and compiled types.  This will assist in the usage of dynamic code from compiled code, and also fits into some polymorphism scenarios.  There are also a number of <a href="http://blogs.msdn.com/bclteam/archive/2009/10/21/what-s-new-in-the-bcl-in-net-4-beta-2-justin-van-patten.aspx" target="_blank">Base Core Library changes</a>.</p>
<p>C# will be gaining some new language functionality with the .Net 4.0 release.  C# now supports option parameters, named parameters and default parameter values to assist with those situations where overloads are cumbersome.  C# 4.0 also supports a type of covariance and contravariance for collections.</p>
<p>The .Net 4.0 framework was delayed because of performance issues.  I am glad they waited to get it right.</p>
<p>Silverlight 4.0 is scheduled to be released later this week.  ASP.Net MVC 2.0 was released a couple of weeks ago, which takes advantages of a couple of new .Net 4.0 scenarios.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonjackson.com/weblog/2010/04/12/net-4-0-and-vs-2010-ga/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight, REST, and Unhandled Exception</title>
		<link>http://jasonjackson.com/weblog/2010/03/19/silverlight-rest-and-unhandled-exception/</link>
		<comments>http://jasonjackson.com/weblog/2010/03/19/silverlight-rest-and-unhandled-exception/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 20:06:32 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://jasonjackson.com/weblog/?p=893</guid>
		<description><![CDATA[As part of the final push to finish up our brand-new, Silverlight 3, MVVM application I have been writing a lot of logging and instrumentation code.  Any new platform is a risk, and while we believe we have taken a solid approach using MVVM and the unit testing it allows, we still don&#8217;t really know [...]]]></description>
			<content:encoded><![CDATA[<p>As part of the final push to finish up our brand-new, Silverlight 3, MVVM application I have been writing a lot of logging and instrumentation code.  Any new platform is a risk, and while we believe we have taken a solid approach using MVVM and the unit testing it allows, we still don&#8217;t really know how this thing will perform in the field.  With this in mind, I am trying to be rather liberal in the logging.</p>
<p>In Silverlight, one can write code to handle any unhandled exception in the application.  This type of functionality exists in Winforms, WPF and ASP.Net, so I wasn&#8217;t terrible surprised to find it available.  This is incredibly convenient.  I can attack areas likely to cause exceptions such as web service calls with specific logging and exception handling code, and catch everything else with a few lines of general-purpose logging.</p>
<p>As soon as I implemented this catch all I immediately started getting log messages stating:</p>
<blockquote><p>No XAML was found at the location &#8221;.</p>
<p>at System.Windows.Navigation.PageResourceContentLoader.EndLoad(IAsyncResult asyncResult)</p>
<p>at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)</p>
<p>at System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result)</p>
<p>at System.Windows.Navigation.PageResourceContentLoader.&lt;&gt;c__DisplayClass4.&lt;BeginLoad&gt;b__0(Object args)</p></blockquote>
<p>Well, that was really helpful.  And after some Google searches I soon realized that I wasn&#8217;t going to find a solution on the web.  Well, I guess this is why I actually get paid to program.  After some testing I discovered that the only time I saw this error (and it was just logging, it never bubbled up to the UI) it was when leaving the Silverlight app for another page in our web application.</p>
<p>Our app takes advantage of Silverlight&#8217;s Frame + Page navigation handling, which can map one URI to another.  In practice this is basically REST.  When the frame &#8220;hears&#8221; a new URI entered it converts the URI  to an internal, component-based URI with the location of the Silverlight page to display.  These mappings are configured during our bootstrap process which rides on top of Prism.</p>
<p>As it turns out, when the user (me) clicks on a link to leave the Silverlight app, the frame &#8220;hears&#8221; a new URI.  The browser is navigating, and the frame tries to handle it.  But it doesn&#8217;t have a mapping for the URI, which is curiously an empty string no matter where outside the Silverlight app one is navigating.  The frame barf, and produces the above exception.  But no one sees it because the app is closed within a split second of all this happening.</p>
<p>After poking and prodding with various ways of squashing this, I finally figured out that in the Navigating event of the Frame I can just set e.Cancel = true, which tells the frame to not navigate.  My conditional logic simply checks to see if the URI is empty.  The browser continues on with its business, and the Silverlight app ignores the navigation from that point on.</p>
<p>Hopefully this entry helps someone else doing REST in Silverlight.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonjackson.com/weblog/2010/03/19/silverlight-rest-and-unhandled-exception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.Net MVC 2 Is GA</title>
		<link>http://jasonjackson.com/weblog/2010/03/12/asp-net-mvc-2-is-ga/</link>
		<comments>http://jasonjackson.com/weblog/2010/03/12/asp-net-mvc-2-is-ga/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 14:13:17 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://jasonjackson.com/weblog/?p=887</guid>
		<description><![CDATA[Scott Guthrie just posted on his blog that ASP.Net MVC 2 has been released.  Looks like I am going to have to buy a new ASP.Net MVC book, and I didn&#8217;t even finish the last one!]]></description>
			<content:encoded><![CDATA[<p>Scott Guthrie <a href="http://weblogs.asp.net/scottgu/archive/2010/03/11/asp-net-mvc-2-released.aspx" target="_blank">just posted</a> on his blog that ASP.Net MVC 2 has been released.  Looks like I am going to have to buy a new ASP.Net MVC book, and I didn&#8217;t even finish the last one!</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonjackson.com/weblog/2010/03/12/asp-net-mvc-2-is-ga/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Snippet Editor</title>
		<link>http://jasonjackson.com/weblog/2009/12/30/code-snippet-editor/</link>
		<comments>http://jasonjackson.com/weblog/2009/12/30/code-snippet-editor/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 18:53:32 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://jasonjackson.com/weblog/?p=784</guid>
		<description><![CDATA[I stumbled across this great Visual Studio code snippet editor and thought I should share the link.  I have already created a few snippets with it, and it my development time is benefiting from it. The editor allows one to highlight existing code and export it into a snippet file.  This is a great launch [...]]]></description>
			<content:encoded><![CDATA[<p>I stumbled across this great Visual Studio <a href="http://www.codeplex.com/SnippetDesigner" target="_self">code snippet editor</a> and thought I should share the link.  I have already created a few snippets with it, and it my development time is benefiting from it.</p>
<p>The editor allows one to highlight existing code and export it into a snippet file.  This is a great launch pad for snippet development.  The editor runs in Visual Studio, and once a snippet is saved with a shortcut it is immediately available in the IDE.  The editor also allows the editing of existing snippet files.</p>
<p><img id="myFxSearchImg" style="border: medium none; position: absolute; z-index: 2147483647; opacity: 0.6; display: none;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAADsElEQVR4nK2VTW9VVRSGn33OPgWpYLARbKWhQlCHTogoSkjEkQwclEQcNJEwlfgD/AM6NBo1xjhx5LyJ0cYEDHGkJqhtBGKUpm3SFii3vb2956wPB/t+9raEgSs52fuus89613rftdcNH8/c9q9++oe/Vzb5P+3McyNcfm2CcPj9af9w6gwjTwzvethx3Bx3x8xwd1wNM8dMcTNUHTfFLPnX6nVmZpeIYwf3cWD/PhbrvlPkblAzVFurKS6GmmGqqComaS+qmBoTI0Ncu3mXuGvWnrJ+ZSxweDgnkHf8ndVTdbiT3M7cQp2Z31dRTecHAfqydp4ejhwazh6Zezfnu98E1WIQwB3crEuJ2Y45PBTAQUVR9X4At66AppoEVO1Q8sgAOKJJjw6Am6OquDmvHskZ3R87gW+vlHz98zpmiqphkkRVbQtsfPTOC30lJKFbFTgp83bWh7Zx/uX1B6w3hI3NkkZTqEpBRDBRzG2AQHcwcYwEkOGkTERREbLQ/8HxJwuW7zdYrzfZ2iopy4qqEspKaDYravVm33k1R91Q69FA1VBRzFIVvXbx5AgXT44A8MWP81yfu0utIR2aVK3vfCnGrcUNxp8a7gKYKiLCvY2SUvo/aNtnM3e49ucK9S3p0aDdaT0UAVsKi2tVi6IWwNL9JvdqTdihaz79/l+u/rHMxmaJVMLkS2OoKKLWacdeE3IsSxctc2D5Qcl6vUlVVgNt+fkPPcFFmTw1xruvT7SCd7nuVhDQvECzJH90h0azRKoKFRkAmP5lKTWAGRdefoZL554FQNUxB92WvYeA5UN4PtSqwB2phKqsqMpBgAunRhFR3j49zuU3jnX8k6fHEQKXzh1jbmGDuYU6s4t1rt6socUeLLZHhYO2AHSHmzt19ihTZ48O8Hzl/AmunD/BjTvrvPfNX3hWsNpwJCvwYm+ngug4UilSCSq6k8YPtxDwfA+WRawIWFbgscDiULcCEaWqBFOlrLazurupOSHLqGnEKJAY8TwBEHumqUirAjNm52vEPPRV4p01XXMPAQhUBjcWm9QZwijwokgAeYHlHYA06KR1cT6ZvoV56pDUJQEjw0KeaMgj1hPEY4vz2A4eW0/e1qA7KtQdsxTYAG0H3iG4xyK1Y+xm7XmEPOJZDiENzLi2WZHngeOjj2Pe+sMg4GRYyLAsx7ME4FnsyTD9pr0PEc8zPGRAwKXBkYOPEd96cZRvf11g9MDe7e3R4Z4Q+vyEnn3P4t0XzK/W+ODN5/kPfRLewAJVEQ0AAAAASUVORK5CYII%3D" alt="" width="24" height="24" /></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonjackson.com/weblog/2009/12/30/code-snippet-editor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# 4.0 Goodness: The dynamic Type, The DLR, and The ExpandoObject Type</title>
		<link>http://jasonjackson.com/weblog/2009/11/10/c-4-0-goodness-the-dynamic-type-the-dlr-and-the-expandoobject-type/</link>
		<comments>http://jasonjackson.com/weblog/2009/11/10/c-4-0-goodness-the-dynamic-type-the-dlr-and-the-expandoobject-type/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 03:26:40 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://jasonjackson.com/weblog/?p=610</guid>
		<description><![CDATA[I have been playing around with C# 4.0 Beta 2 and stumbled onto the ExpandoObject (in the System.Dynamic namespace, System.Core assembly).  The object is built to be used in the DRL (Dynamic Language Runtime).  The DLR is a way for strongly-typed code to play nicely with weakly-typed code like IronPython, and vice-versa.  In C# 4.0 [...]]]></description>
			<content:encoded><![CDATA[<p>I have been playing around with C# 4.0 Beta 2 and stumbled onto the ExpandoObject (in the System.Dynamic namespace, System.Core assembly).  The object is built to be used in the DRL (Dynamic Language Runtime).  The DLR is a way for strongly-typed code to play nicely with weakly-typed code like IronPython, and vice-versa.  In C# 4.0 the <em>dynamic</em> keyword is used to reference objects that are weakly typed, and the ExandoObject is a .Net class that pretends to be a weakly-typed object.</p>
<p>ExpandoObject allows for addition of member properties and methods are run-time similar to popular scripting languages like Javascript.  Yet ExpandoObject is a real .Net type, and implements a couple of  interesting .Net interfaces: IDictionary&lt;string, object&gt; and INotifyPropertyChanged.  A dictionary of members is provides through the dictionary interface, and property changed events are fired through the property changed interface.  The only way to really leverage the power of ExpandoObject is with the <em>dynamic</em> keyword/type, which skips compile-time checking.  Method and property calls are not shown in intellisense.  You don&#8217;t know if your code will execute property until run-time.  So to access the above mentioned interfaces, the ExpandoObject&#8217;s dynamic reference must be cast to the interface type.</p>
<p>Here is some very simple, sample code that illustrates the concepts discussed (runs in Visual Studio 2010 / .Net 4.0 Beta 2):</p>
<pre class="brush: csharp; title: ; wrap-lines: false;">

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;

namespace DynamcMethodExample
{
    class Program
    {
        static void Main(string[] args)
        {
            dynamic person = new ExpandoObject();
            person.Name = &quot;John&quot;;
            person.Gender = 'm';
            person.Age = 10;

            Console.WriteLine(person);
            Console.WriteLine(person.Name);
            Console.WriteLine(person.Gender);
            Console.WriteLine(person.Age);
            Console.ReadKey();

            person.MakeTacos = (Func&lt;string&gt;)(() =&gt; &quot;Tacos are ready!&quot;);
            Console.WriteLine(person.MakeTacos());
            Console.ReadKey();

            ((INotifyPropertyChanged)person).PropertyChanged += (s, e) =&gt;
                {
                    IDictionary&lt;string, object&gt; personAsDictionary = (IDictionary&lt;string, object&gt;)person;
                    Console.WriteLine(&quot;Property {0} changed to {1}.&quot;, e.PropertyName, personAsDictionary[e.PropertyName]);
                };

            person.Name = &quot;Jane&quot;;
            person.Gender = 'f';
            person.Age = 11;
            Console.ReadKey();

        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jasonjackson.com/weblog/2009/11/10/c-4-0-goodness-the-dynamic-type-the-dlr-and-the-expandoobject-type/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Types in .Net 4.0</title>
		<link>http://jasonjackson.com/weblog/2009/10/29/new-types-in-net-4-0/</link>
		<comments>http://jasonjackson.com/weblog/2009/10/29/new-types-in-net-4-0/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 23:27:58 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://jasonjackson.com/weblog/?p=598</guid>
		<description><![CDATA[A lot of the hype around .Net 4.0 is surrounding new features such as the Dynamic Language Runtime (DLR), and C# 4.0 features such as the dynamic type and co/contra-variance.  Something not getting as much press, but in many ways more helpful is the inclusion of many new, useful types included in 4.0.  The BCL [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of the hype around .Net 4.0 is surrounding new features such as the <a href="http://www.codeplex.com/dlr" target="_blank">Dynamic Language Runtime (DLR)</a>, and <a href="http://code.msdn.microsoft.com/csharpfuture" target="_blank">C# 4.0 features</a> such as the dynamic type and co/contra-variance.  Something not getting as much press, but in many ways more helpful is the inclusion of many new, useful types included in 4.0.  The BCL team has a <a href="http://blogs.msdn.com/bclteam/archive/2009/10/21/what-s-new-in-the-bcl-in-net-4-beta-2-justin-van-patten.aspx" target="_blank">blog article</a> about many of these types.  Here are a couple of my favorites:</p>
<ul>
<li>Enum.HasFlag(Enum enum)<br />
I have written this code a couple of times before.  It detects whether a bit is set in an enum Flag value.</li>
<li>Enum.TryParse&lt;EnumType&gt;(string value, out EnumType result)<br />
I have also had to write this.  I think every core value-type should have a TryParse, which leads to:</li>
<li>Guid.TryParse(string value, out Guid result)</li>
<li>String.Join and String.Concat now take IEnumerable&lt;T&gt;!  I have written string.Join(&#8220;,&#8221;, values.Select(v=&gt;v.ToString()).ToArray()) more that a few times.</li>
</ul>
<p>I am really looking forward to .Net 4.0.  If you want to get your hands on it now .Net 4.0 and Visual Studio 2010 are available for <a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target="_blank">download here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonjackson.com/weblog/2009/10/29/new-types-in-net-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

