<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><!-- generator="wordpress/2.3.2" --><rss 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/" version="2.0">

<channel>
	<title>parallelthinking</title>
	<link>http://www.acorns.com.au/blog</link>
	<description>Work Every job is a self portrait of the person who does it. Autograph your work with excellence.</description>
	<pubDate>Thu, 14 May 2009 11:55:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/parallelthinking" type="application/rss+xml" /><item>
		<title>Do you want to “change” your Optus details? Just login. Here are the usernames &amp; passwords.</title>
		<link>http://www.acorns.com.au/blog/?p=146</link>
		<comments>http://www.acorns.com.au/blog/?p=146#comments</comments>
		<pubDate>Thu, 14 May 2009 11:54:27 +0000</pubDate>
		<dc:creator>Corneliu</dc:creator>
		
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=146</guid>
		<description><![CDATA[For reasons I’ll detail in a separate post I had to enter today in an Optus shop.
And, in a pure display of ignorance to any basic security measures, they had all the usernames and passwords for all the systems where the dealers could connect and do changes to accounts, create new accounts or remove them [...]]]></description>
			<content:encoded><![CDATA[<p>For reasons I’ll detail in a separate post I had to enter today in an Optus shop.</p>
<p>And, in a pure display of ignorance to any basic security measures, they had all the <strong>usernames and passwords for all the systems</strong> where the dealers could connect and do changes to accounts, create new accounts or remove them <strong>printed and stuck at the top of the screen</strong>.</p>
<p>An no, this was not on a computer somewhere in the back of the store but on a computer in the middle of the room full of people.</p>
<p><a href="http://www.acorns.com.au/Images/blog/DoyouwanttochangeyourOptusdetailsJustlo_13407/optus.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="optus" border="0" alt="optus" src="http://www.acorns.com.au/Images/blog/DoyouwanttochangeyourOptusdetailsJustlo_13407/optus_thumb.jpg" width="404" height="304" /></a>&#160; </p>
<p>(I’ve reduced the size and quality of the image enough to have all the information impossible to read.)</p>
<p>Not only that I took this picture with my mobile but I managed to get friendly enough to play with the computer after the dealer logged in to a system that I could use to change my personal details (or anyone else’s details). I even did a view source on the (poorly coded) code and tried to hack some URLs together to avoid a post back on the page. </p>
<p>Uh, who, me? Never…</p>
<p><strong>So where do you keep your passwords?</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.acorns.com.au/blog/?feed=rss2&amp;p=146</wfw:commentRss>
		</item>
		<item>
		<title>Microsoft SDC Open Day</title>
		<link>http://www.acorns.com.au/blog/?p=145</link>
		<comments>http://www.acorns.com.au/blog/?p=145#comments</comments>
		<pubDate>Fri, 01 May 2009 00:07:27 +0000</pubDate>
		<dc:creator>Corneliu</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Readify]]></category>

		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=145</guid>
		<description><![CDATA[On Monday the 6th of April Microsoft Australia organized the SDC Open Day 2009 event (SDC stands for [Microsoft] Software Development Centre, part of the Microsoft Services (Australia).
For over six years, Microsoft Australia’s Solutions Development Centre has been successfully delivering complex custom-developed applications for customers. We follow a set of processes that have enabled us [...]]]></description>
			<content:encoded><![CDATA[<p>On Monday the 6th of April Microsoft Australia organized the <a href="https://www.microsoft.com/australia/services/microsoftservices/sdc_openday.mspx" target="_blank">SDC Open Day 2009</a> event (SDC stands for [Microsoft] <a href="https://www.microsoft.com/australia/services/microsoftservices/srv_msdc.mspx" target="_blank">Software Development Centre</a>, part of the <a href="http://www.microsoft.com/australia" target="_blank">Microsoft Services (Australia)</a>.</p>
<blockquote><p>For over six years, Microsoft Australia’s Solutions Development Centre has been successfully delivering complex custom-developed applications for customers. We follow a set of processes that have enabled us to build high-performing teams delivering quality solutions. At the SDC Open Day we talked about how we have achieved this success, sharing our processes and techniques with an audience of software development professionals. </p>
<p>In the presentations below we provide an overview of the SDC, a day in the life for the team and details on how we approach each of the key disciplines in an SDC project team.</p>
</blockquote>
<p>Together with few others like <a href="http://blogs.msdn.com/tomholl/" target="_blank">Tom Hollander</a>, Prasadi de Silva (they are Microsoft so they don’t really count), , <a href="http://www.teknologika.com/blog/im-presenting-at-the-microsoft-sdc-open-day/" target="_blank">Bruce</a>, Sarah from <a href="http://www.devtest.com/" target="_blank">DevTest</a> and Simon and Emma from <a href="http://www.avanade.com" target="_blank">Avanade</a> we were invited to do talks on different aspects of the software development process in the SDC from Project Management, Development, Testing to Setup and Deployment.</p>
<p>The videos from the day <a href="https://www.microsoft.com/australia/services/microsoftservices/sdc_openday.mspx" target="_blank">are all published now</a>. The fifth one in the list is my presentation <img src='http://www.acorns.com.au/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> however I can’t seem to be able to play it as I continuously get an error.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acorns.com.au/blog/?feed=rss2&amp;p=145</wfw:commentRss>
		</item>
		<item>
		<title>Leaving Readify: Got a new job &amp; new responsibilities</title>
		<link>http://www.acorns.com.au/blog/?p=144</link>
		<comments>http://www.acorns.com.au/blog/?p=144#comments</comments>
		<pubDate>Sun, 26 Apr 2009 08:33:44 +0000</pubDate>
		<dc:creator>Corneliu</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Readify]]></category>

		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=144</guid>
		<description><![CDATA[It’s public now that as of the 15th of May I’ve resigned from the position of Senior Consultant in Readify.
I’ve worked with some of the best minds in the industry from Darren, Mitch, PaulG and PaulS (who is still Temporarily Offline), Philip, Damian, Tatham, Francois (who’s now enjoying his trip around the world), Aymeric and [...]]]></description>
			<content:encoded><![CDATA[<p>It’s public now that as of the 15th of May I’ve resigned from the position of Senior Consultant in <a href="http://www.readify.net" target="_blank">Readify</a>.</p>
<p>I’ve worked with some of the best minds in the industry from <a href="http://showusyourcode.spaces.live.com/" target="_blank">Darren</a>, <a href="http://www.notgartner.com" target="_blank">Mitch</a>, <a href="http://weblogs.asp.net/pglavich/" target="_blank">PaulG</a> and <a href="http://www.paulstovell.net/" target="_blank">PaulS</a> (who is still Temporarily Offline), <a href="http://www.philipbeadle.net/" target="_blank">Philip</a>, <a href="http://damianedwards.wordpress.com/" target="_blank">Damian</a>, <a href="http://blog.tatham.oddie.com.au/" target="_blank">Tatham</a>, <a href="http://www.mytb.org/francoisbeaussier" target="_blank">Francois</a> (who’s now enjoying his trip around the world), Aymeric and lots, lots more.</p>
<p>I’ve worked with some great people from outside Readify like <a href="http://blogs.msdn.com/tomholl/" target="_blank">Tom Hollander</a>, <a href="http://blogs.msdn.com/rockyh/" target="_blank">Rocky Heckman</a>, <a href="http://www.teknologika.com/" target="_blank">Bruce McLeod</a>, to mention only a few.. </p>
<p>I think this was the best, coolest and most enjoyable job I’ve ever had, with involvement in various projects from fixing simple (sometimes crappy) VB.Net apps to technical lead of large projects, performance reviews and improvements, security reviews and guidance, threat modelling new or existing systems, architecture and design of new systems, architecture reviews, complete or partial refactoring and rewrites of applications, mentoring, guidance, training, talking, presenting or attending loads of conferences, whinging, crying (not really) and contesting or challenging technical decisions (most of the times offering alternatives), building awesome relationships with my teams and my customers (oh, well, at least that’s what I believe I did :))</p>
<p>Even more I also received an <a href="http://www.acorns.com.au/blog/?p=137" target="_blank">MVP award in Development Security</a>.</p>
<p>I’ve loved my position and the people I’ve been working with.</p>
<p>But now it’s time to move on to a new challenge and a new role. I’ve accepted a new role as a (full-time) Solutions Architect and 2IC with <a href="http://www.classfinancialsystems.com.au/" target="_blank">Class Financial Systems</a>. More or less I’m going back into financial systems where most of my background and experience was before I’ve joined Readify.</p>
<p>I’ll have a great new set of challenges from leading a new team to delivering a new project from zero to hero (or great success). I kind of started to forget what it means to be part of a project form end to end. I’ll also try to use this opportunity to learn, apply, present and (cross-fingers) be approved as a <a href="http://www.microsoft.com/learning/mcp/architect/solutions/default.mspx" target="_blank">Microsoft Certified Architect: Solutions</a>.</p>
<p>I truly hope I’ll keep in good contact with all Readify, Microsoft, friends and partners and I hope to see most of you at user groups, TechEd, CodeCamp, MVP Summit and other conferences.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acorns.com.au/blog/?feed=rss2&amp;p=144</wfw:commentRss>
		</item>
		<item>
		<title>WCF Dynamic Client Proxy – Implementing IDisposable</title>
		<link>http://www.acorns.com.au/blog/?p=143</link>
		<comments>http://www.acorns.com.au/blog/?p=143#comments</comments>
		<pubDate>Thu, 19 Feb 2009 09:28:33 +0000</pubDate>
		<dc:creator>Corneliu</dc:creator>
		
		<category><![CDATA[WCF]]></category>

		<category><![CDATA[WCF Dynamic Proxy]]></category>

		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=143</guid>
		<description><![CDATA[As my good friend and Readify colleague Buddhike observed the generated WCF Dynamic Proxy was not implementing IDisposable. This is a bit scary as I was quite sure I had that implementation prepared done already so all I can image is that for some reason (no source control?) I’ve been working on an older code [...]]]></description>
			<content:encoded><![CDATA[<p>As my good friend and Readify colleague <a href="http://geeksdiary.com/default.aspx">Buddhike</a> observed the generated <a href="http://www.acorns.com.au/blog/?p=142">WCF Dynamic Proxy</a> was not implementing IDisposable. This is a bit scary as I was quite sure I had that implementation <strike>prepared</strike> done already so all I can image is that for some reason (no source control?) I’ve been working on an older code base.</p>
<p>So, here is a new implementation that is implementation that implements IDisposable. The only trick is that you have to cast the received proxy to IDisposable in order to use it in a using statement. As a difference from the WCF implementation, the dynamic proxy does not throw at all from the implementation of the IDisposable so it’s safe to use in a using statement:</p>
<pre class="code"><span style="color: #2b91af">IService1 </span>service = <span style="color: #2b91af">WCFClientProxy</span>&lt;<span style="color: #2b91af">IService1</span>&gt;.GetReusableFaultUnwrappingInstance(<span style="color: #a31515">&quot;Service1&quot;</span>);
<span style="color: blue">using </span>(service <span style="color: blue">as </span><span style="color: #2b91af">IDisposable</span>)
{
    service.MyOperation1(<span style="color: #a31515">&quot;a&quot;</span>, 0);
}</pre>
<p><a href="http://11011.net/software/vspaste"></a>Please download the new version of <a href="http://www.acorns.com.au/files/ACorns.WCF.DynamicProxy.1.3.1.zip">WCF Client Proxy 1.3.1</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acorns.com.au/blog/?feed=rss2&amp;p=143</wfw:commentRss>
		</item>
		<item>
		<title>WCF Dynamic (ClientBase) Proxy part three: Connection Pooling and Automatic Disposing</title>
		<link>http://www.acorns.com.au/blog/?p=142</link>
		<comments>http://www.acorns.com.au/blog/?p=142#comments</comments>
		<pubDate>Tue, 17 Feb 2009 04:14:23 +0000</pubDate>
		<dc:creator>Corneliu</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[WCF]]></category>

		<category><![CDATA[WCF Dynamic Proxy]]></category>

		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=142</guid>
		<description><![CDATA[A while ago I published a small and neat Dynamic Proxy that could be used to automatically create for you implementation of the (WCF) ClientBase&#60;T&#62; so you would not have to generate that from the service interface and hand-coded or even bother to maintain.
One of it’s great advantages was that you could ask for a [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago <a href="http://www.acorns.com.au/blog/?p=113">I published a small and neat Dynamic Proxy</a> that could be used to automatically create for you implementation of the (WCF) ClientBase&lt;T&gt; so you would not have to generate that from the service interface and hand-coded or even bother to maintain.</p>
<p>One of it’s great advantages was that you could ask for a “Reusable” proxy which was basically a wrapper around the proxy that you didn’t have to close/dispose in case of a fault.</p>
<p>As <a href="http://safari.oreilly.com/0596526997/orm9780596526993-APP-C-SECT-7">you might know WCF requires</a> that you dispose of the proxy if there is any type of fault detected. Doing this is a pain in any type of code as you have to manage that connection life-time while actually all you care most of the times is that you talk to the service and not the life-time of your connection. The WCF Client Proxy was also doing this management for you allowing you so simply focus on your business and not on opening/closing your connections.</p>
<p>However there are moments in which you also want to specifically close your proxy for example using a <em>using</em> statement. Because the WCF Client Proxy was returning you the exact interface that you requested and if that interface was not implementing IDisposable you had to reside on a trick and cast the received proxy to IDisposable (as the proxy generates that behinds the scenes for you anyway) and use it like this:</p>
<pre class="code"><span style="color: #2b91af">IService1 </span>service = <span style="color: #2b91af">WCFClientProxy</span>&lt;<span style="color: #2b91af">IService1</span>&gt;.GetReusableInstance(<span style="color: #a31515">&quot;Service1&quot;</span>);
<span style="color: blue">using</span>((<span style="color: #2b91af">IDisposable</span>)service)
{
    service.MyOperation1();
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>This was again a bit ugly as you have to care about the connection and you can’t just use it as any other interface. You do have to be aware that your interface represents a WCF service that you want to dispose of.</p>
<p>One other potential scenario that several people hit is in websites that talk to external WCF services and you use the same service from within the same page several times (for example from different controls). In practice in this scenario you will open/close the same proxy multiple times during the lifetime of the page.</p>
<h2>Connection Pooling</h2>
<p>In order to simplify the management of WCF connections during the lifetime of a webpage or even a WCF Operation Call and reduce the overhead of caring to dispose of proxies I’ve now added a <em>ProxyConnectionPool</em> class to the dynamic proxy that can be enabled to automatically pickup all the created WCF connections and pool them (as in return the same one back to you if you use it from the same thread and it’s safe to reuse).</p>
<p>To enable the connection pooling all you have to do is:</p>
<pre class="code"><span style="color: #2b91af">ProxyConnectionPool</span>.EnableConnectionPool = <span style="color: blue">true</span>;</pre>
<p><a href="http://11011.net/software/vspaste"></a>Now every time you do a call do GetReusableInstance or other methods on the WCFClientProxy the connection you receive might be a pooled one (same tread only pooling) or a new one just registered with the pool. This should improve your performance as <a href="http://weblogs.asp.net/pglavich/archive/2007/02/24/wcf-proxy-performance-vs-wse-v3.aspx">creating WCF Proxies is an expensive process</a> that you want to avoid as much as possible.</p>
<h2>Disposing the pool</h2>
<p>Once you finish your work on that thread you can simply ask the connection pool to dispose all the WCF connections from the pool using:</p>
<pre class="code"><span style="color: #2b91af">ProxyConnectionPool</span>.Current.Dispose();</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<h2>Automatic disposing</h2>
<p>If you use WCF inside a website to call other WCF services you should then simply include the following module in your web.config so you get automatic disposing of all WCF connections created on each page request (with peace of mind included).</p>
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">system.web</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">httpModules</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">add </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">WcfConnectionPool</span>&quot; <span style="color: red">type</span><span style="color: blue">=</span>&quot;<span style="color: blue">ACorns.WCF.DynamicClientProxy.Pool.WcfConnectionPoolHandler,</span><span style="color: blue">ACorns.WCF.DynamicClientProxy</span>&quot;<span style="color: blue">/&gt;
    &lt;/</span><span style="color: #a31515">httpModules</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">system.web</span><span style="color: blue">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>This module will automatically enable the connection pool for you and make sure all the WCF proxies created are nicely disposed at the end of each page request. This truly allows you to focus on writing your business code and not bothering about connection management of your WCF services. Your code will now become:</p>
<pre class="code"><span style="color: #2b91af">IService1 </span>service = <span style="color: #2b91af">WCFClientProxy</span>&lt;<span style="color: #2b91af">IService1</span>&gt;.GetReusableInstance(<span style="color: #a31515">&quot;Service1&quot;</span>);
service.MyOperation1();</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Let someone else deal with the fact that you use WCF <img src='http://www.acorns.com.au/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Licence</h2>
<p>I was requested several times about the licence this code is. Here is my official statement:</p>
<p><em>This package is provided &quot;AS IS,&quot; without express or implied warranty of any kind, and may be used and modified.<br />
    <br />This package may be used in corporate applications without any pretence.</em></p>
<p>However I would appreciate if you would drop me a line to let me know you are using it to corneliu at acorns.com.au or even donate some money by PayPal to the same address <img src='http://www.acorns.com.au/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Download</h2>
<p>Here is the latest version of the <a href="http://www.acorns.com.au/files/ACorns.WCF.DynamicProxy.1.3.zip">WCF Client Proxy 1.3.0</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.acorns.com.au/blog/?feed=rss2&amp;p=142</wfw:commentRss>
		</item>
		<item>
		<title>Writing a super fast deep-property reader/writer using delegates</title>
		<link>http://www.acorns.com.au/blog/?p=141</link>
		<comments>http://www.acorns.com.au/blog/?p=141#comments</comments>
		<pubDate>Mon, 16 Feb 2009 12:24:26 +0000</pubDate>
		<dc:creator>Corneliu</dc:creator>
		
		<category><![CDATA[.Net]]></category>

		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=141</guid>
		<description><![CDATA[For a while now I’ve been writing to write a non-reflection based property reader that allows me to read properties of an object in a deep hierarchy.
So lets say you have the following simple class hierarchy:
public class FirstLevel
{
    public string Leaf { get; set; }
}
public class SecondLevel
{
    public FirstLevel [...]]]></description>
			<content:encoded><![CDATA[<p>For a while now I’ve been writing to write a non-reflection based property reader that allows me to read properties of an object in a deep hierarchy.</p>
<p>So lets say you have the following simple class hierarchy:</p>
<pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">FirstLevel
</span>{
    <span style="color: blue">public string </span>Leaf { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
}
<span style="color: blue">public class </span><span style="color: #2b91af">SecondLevel
</span>{
    <span style="color: blue">public </span><span style="color: #2b91af">FirstLevel </span>First { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
}
<span style="color: blue">public class </span><span style="color: #2b91af">Root
</span>{
    <span style="color: blue">public </span><span style="color: #2b91af">SecondLevel </span>Prop { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Then you want to read the Leaf from the FirstLevel by looking at the Root level and all you have is the path to the property: “SecondLevel.FirstLevel.Leaf”.</p>
<p>Using reflection is a simple process of recursively going through the object, finding the proper property doing a GetValue on it and then repeating the process until you find your property. This is ok but it’s very slow. Very very slow.</p>
<p>Your other two alternatives if you don’t want the bear the hit of reflection is to code emit a method that would resemble something like this:</p>
<pre class="code"><span style="color: blue">public static string </span>GetLeaf(<span style="color: #2b91af">Root </span>root)
{
    <span style="color: #2b91af">SecondLevel </span>secondLevel = root.Prop;
    <span style="color: blue">if </span>( secondLevel != <span style="color: blue">null </span>)
    {
        <span style="color: #2b91af">FirstLevel </span>firstLevel = secondLevel.First;
        <span style="color: blue">if </span>( firstLevel != <span style="color: blue">null </span>)
        {
            <span style="color: blue">return </span>firstLevel.Leaf;
        }
    }
    <span style="color: blue">return null</span>;
}</pre>
<p>Or use dynamically created delegates to map to the get_Property and set_Property methods generated for each property.</p>
<p>&#160;</p>
<pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.Reflection;

<span style="color: blue">namespace </span>ACorns.Utils
{
    <span style="color: blue">public interface </span><span style="color: #2b91af">IPropertyAccessor
    </span>{
        <span style="color: blue">object </span>GetValue(<span style="color: blue">object </span>target);
        <span style="color: blue">void </span>SetValue(<span style="color: blue">object </span>target, <span style="color: blue">object </span>value);
    }

    <span style="color: blue">public interface </span><span style="color: #2b91af">IPropertyAccessor</span>&lt;TargetObject, FinalProperty&gt;
    {
        FinalProperty GetValue(TargetObject target);
        <span style="color: blue">void </span>SetValue(TargetObject target, FinalProperty value);
    }

    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Super-dooper, super-fact deep property extractor.
    </span><span style="color: gray">/// </span><span style="color: green">You can use it to get/set properties deep in an object hierarchy without using reflection.
    </span><span style="color: gray">/// </span><span style="color: green">Please cache the returned IPropertyAccessor if you want to reuse it.
    </span><span style="color: gray">/// </span><span style="color: green">Good performance is only achived with cached IPropertyAccessor(s)!
    </span><span style="color: gray">///
    /// </span><span style="color: green">Usage: IPropertyAccessor accessor = PropertyExtractor.GetAccessor(typeof(Root), &quot;Prop.First.Leaf&quot;, true);
    </span><span style="color: gray">/// </span><span style="color: green">accessor.GetValue(target);
    </span><span style="color: gray">/// &lt;/summary&gt;
    </span><span style="color: blue">public static class </span><span style="color: #2b91af">PropertyExtractor
    </span>{
        <span style="color: blue">public static </span>IPropertyAccessor&lt;TargetObject, FinalProperty&gt;
            GetAccessor&lt;TargetObject, FinalProperty&gt;(<span style="color: #2b91af">Type </span>targetType, <span style="color: blue">string </span>propertyNames)
        {
            <span style="color: blue">return </span>GetAccessor&lt;TargetObject, FinalProperty&gt;(targetType, propertyNames, <span style="color: blue">true</span>);
        }
        <span style="color: blue">public static </span>IPropertyAccessor&lt;TargetObject, FinalProperty&gt;
            GetAccessor&lt;TargetObject, FinalProperty&gt;(<span style="color: #2b91af">Type </span>targetType, <span style="color: blue">string </span>propertyNames, <span style="color: blue">bool </span>throwOnNull)
        {
            IPropertyAccessor internalPropertyAccessor = GetAccessor(targetType, propertyNames, throwOnNull);

            <span style="color: #2b91af">Type </span>accessorType = <span style="color: blue">typeof</span>(TypedPropertyAccessor&lt;,&gt;).MakeGenericType(<span style="color: blue">typeof</span>(TargetObject), <span style="color: blue">typeof</span>(FinalProperty));
            IPropertyAccessor&lt;TargetObject, FinalProperty&gt; propertyAccessor =
                (IPropertyAccessor&lt;TargetObject, FinalProperty&gt;)<span style="color: #2b91af">Activator</span>.CreateInstance(accessorType, internalPropertyAccessor);

            <span style="color: blue">return </span>propertyAccessor;
        }
        <span style="color: blue">public static </span>IPropertyAccessor GetAccessor(<span style="color: #2b91af">Type </span>targetType, <span style="color: blue">string </span>propertyNames, <span style="color: blue">bool </span>throwOnNull)
        {
            <span style="color: blue">string</span>[] deepPropertyNames = propertyNames.Split(<span style="color: #a31515">&#8216;.&#8217;</span>);
            IPropertyAccessor internalPropertyAccessor = GetAccessor(targetType, deepPropertyNames, 0, throwOnNull);
            <span style="color: blue">return </span>internalPropertyAccessor;
        }

        <span style="color: blue">private static </span>IPropertyAccessor GetAccessor(<span style="color: #2b91af">Type </span>targetType, <span style="color: blue">string</span>[] deepPropertyNames, <span style="color: blue">int </span>level, <span style="color: blue">bool </span>throwOnNull)
        {
            <span style="color: blue">string </span>property = deepPropertyNames[level];

            <span style="color: #2b91af">PropertyInfo </span>propertyInfo = targetType.GetProperty(property);

            <span style="color: green">// Create a delegate to a get_ method. The delegate looks like
            // Func&lt;TargetType, PropertyType&gt; func to a property like class TargetType { public PropertyType { get; } }
            </span><span style="color: #2b91af">Type </span>getterDelegateType = <span style="color: blue">typeof</span>(Func&lt;,&gt;).MakeGenericType(targetType, propertyInfo.PropertyType);
            <span style="color: #2b91af">Delegate </span>getDelegate = <span style="color: #2b91af">Delegate</span>.CreateDelegate(getterDelegateType, propertyInfo.GetGetMethod());

            IPropertyAccessor accessor;

            level++;
            <span style="color: blue">if </span>(level &lt; deepPropertyNames.Length)
            {
                <span style="color: green">// Recursive detect the down the property
                </span>IPropertyAccessor nextLevelAccessor = GetAccessor(propertyInfo.PropertyType, deepPropertyNames, level, throwOnNull);

                <span style="color: #2b91af">Type </span>accessorType = <span style="color: blue">typeof</span>(PropertyAccessor&lt;,&gt;).MakeGenericType(targetType, propertyInfo.PropertyType);
                accessor = (IPropertyAccessor)<span style="color: #2b91af">Activator</span>.CreateInstance(accessorType, getDelegate, nextLevelAccessor, throwOnNull);
            }
            <span style="color: blue">else
            </span>{
                <span style="color: #2b91af">Type </span>setterDelegateType = <span style="color: blue">typeof</span>(Action&lt;,&gt;).MakeGenericType(targetType, propertyInfo.PropertyType);
                <span style="color: #2b91af">Delegate </span>setDelegate = <span style="color: #2b91af">Delegate</span>.CreateDelegate(setterDelegateType, propertyInfo.GetSetMethod());

                <span style="color: #2b91af">Type </span>accessorType = <span style="color: blue">typeof</span>(LeafPropertyAccessor&lt;,&gt;).MakeGenericType(targetType, propertyInfo.PropertyType);
                accessor = (IPropertyAccessor)<span style="color: #2b91af">Activator</span>.CreateInstance(accessorType, getDelegate, setDelegate);
            }

            <span style="color: blue">return </span>accessor;
        }

        <span style="color: blue">#region </span>TypedPropertyAccessor
        <span style="color: blue">internal sealed class </span><span style="color: #2b91af">TypedPropertyAccessor</span>&lt;T, U&gt; : IPropertyAccessor&lt;T, U&gt;
        {
            <span style="color: blue">private readonly </span>IPropertyAccessor _next;

            <span style="color: blue">public </span>TypedPropertyAccessor(IPropertyAccessor next)
            {
                _next = next;
            }

            <span style="color: blue">public </span>U GetValue(T target)
            {
                <span style="color: blue">return </span>(U) _next.GetValue(target);
            }

            <span style="color: blue">public void </span>SetValue(T target, U value)
            {
                _next.SetValue(target, value);
            }
        }
        <span style="color: blue">#endregion

        #region </span>Recursive Property Accessors
        <span style="color: blue">internal sealed class </span><span style="color: #2b91af">PropertyAccessor</span>&lt;T, U&gt; : IPropertyAccessor
        {
            <span style="color: blue">private readonly </span>Func&lt;T,U&gt; _readDelegate;
            <span style="color: blue">private readonly </span>IPropertyAccessor _next;
            <span style="color: blue">private readonly bool </span>_throwOnNull;

            <span style="color: blue">public </span>PropertyAccessor(Func&lt;T, U&gt; readDelegate, IPropertyAccessor next, <span style="color: blue">bool </span>throwOnNull)
            {
                _readDelegate = readDelegate;
                _throwOnNull = throwOnNull;
                _next = next;
            }
            <span style="color: blue">public object </span>GetValue(<span style="color: blue">object </span>target)
            {
                <span style="color: blue">object </span>result = _readDelegate((T)target);
                <span style="color: blue">if </span>(result == <span style="color: blue">null</span>)
                {
                    <span style="color: blue">if </span>(_throwOnNull)
                        <span style="color: blue">throw new </span><span style="color: #2b91af">NullReferenceException</span>(<span style="color: #a31515">&quot;Property &#8216;&quot; </span>+ _readDelegate.Method.Name + <span style="color: #a31515">&quot;&#8217; on &#8216;&quot; </span>+
                            <span style="color: blue">typeof</span>(T).Name + <span style="color: #a31515">&quot;&#8217; returned null.&quot;</span>);
                    <span style="color: blue">else
                        return default</span>(U);
                }
                <span style="color: blue">return </span>_next.GetValue(result);
            }
            <span style="color: blue">public void </span>SetValue(<span style="color: blue">object </span>target, <span style="color: blue">object </span>value)
            {
                <span style="color: blue">object </span>result = _readDelegate((T)target);
                <span style="color: blue">if </span>(result == <span style="color: blue">null</span>)
                {
                    <span style="color: blue">if </span>(_throwOnNull)
                        <span style="color: blue">throw new </span><span style="color: #2b91af">NullReferenceException</span>(<span style="color: #a31515">&quot;Property &#8216;&quot; </span>+ _readDelegate.Method.Name + <span style="color: #a31515">&quot;&#8217; on &#8216;&quot; </span>+
                            <span style="color: blue">typeof</span>(T).Name + <span style="color: #a31515">&quot;&#8217; returned null.&quot;</span>);
                    <span style="color: blue">else
                        return</span>;
                }
                _next.SetValue((U)result, value);
            }
        }
        <span style="color: blue">internal sealed class </span><span style="color: #2b91af">LeafPropertyAccessor</span>&lt;T, U&gt; : IPropertyAccessor
        {
            <span style="color: blue">private readonly </span>Func&lt;T, U&gt; _readDelegate;
            <span style="color: blue">private readonly </span>Action&lt;T, U&gt; _setDelegate;

            <span style="color: blue">public </span>LeafPropertyAccessor(Func&lt;T, U&gt; readDelegate, Action&lt;T, U&gt; setDelegate)
            {
                _readDelegate = readDelegate;
                _setDelegate = setDelegate;
            }
            <span style="color: blue">public object </span>GetValue(<span style="color: blue">object </span>target)
            {
                <span style="color: blue">object </span>result = _readDelegate((T)target);
                <span style="color: blue">return </span>result;
            }
            <span style="color: blue">public void </span>SetValue(<span style="color: blue">object </span>target, <span style="color: blue">object </span>value)
            {
                _setDelegate((T)target, (U)value);
            }
        }
        <span style="color: blue">#endregion
    </span>}
}</pre>
<p>To use it you would request an IPropertyExtractor and then ask it to do a GetValue for you:</p>
<p>[TestMethod]<br />
  <br /><span style="color: blue">public void </span>ExtractPropertyFromLeafFixture()</p>
<p>{</p>
<p>&#160;&#160;&#160; Root r = <span style="color: blue">new </span>Root();</p>
<p>&#160;&#160;&#160; r.Prop = <span style="color: blue">new </span>SecondLevel();</p>
<p>&#160;&#160;&#160; r.Prop.First = <span style="color: blue">new </span>FirstLevel();</p>
<p>&#160;&#160;&#160; r.Prop.First.Leaf = <span style="color: #a31515">&quot;original value&quot;</span>;</p>
<p>&#160;&#160;&#160; IPropertyAccessor accessor = PropertyExtractor.GetAccessor(<span style="color: blue">typeof</span>(Root), <span style="color: #a31515">&quot;Prop.First.Leaf&quot;</span>, <span style="color: blue">false</span>);</p>
<p>&#160;&#160;&#160; Assert.IsNotNull(accessor);</p>
<p>&#160;&#160;&#160; <span style="color: blue">object </span>value = accessor.GetValue(r);</p>
<p>&#160;&#160;&#160; Assert.AreEqual(<span style="color: #a31515">&quot;original value&quot;</span>, value.ToString());</p>
<p>&#160;&#160;&#160; accessor.SetValue(r, <span style="color: #a31515">&quot;new value&quot;</span>);</p>
<p>&#160;&#160;&#160; <br />&#160;&#160;&#160; value = accessor.GetValue(r);</p>
<p>&#160;&#160;&#160; Assert.AreEqual(<span style="color: #a31515">&quot;new value&quot;</span>, value.ToString());</p>
<p>}</p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The beauty of this approach is that once the IPropertyAccessor is created (using Reflection) in the beginning,&#160; the Get/Set on it is done via a set of direct delegate calls to the property and calls via the interface to the next level.</p>
<p>The callstack is thus very small and efficient:</p>
<p><a href="http://www.acorns.com.au/Images/blog/Writingasuperfastdeeppropertyreaderwrite_12CE2/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.acorns.com.au/Images/blog/Writingasuperfastdeeppropertyreaderwrite_12CE2/image_thumb.png" width="727" height="160" /></a></p>
<p>Make sure you cache this accessor if you need it again at a later time as creating it is expensive.</p>
<p>The performance should be as good as you can get without using code emitting. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.acorns.com.au/blog/?feed=rss2&amp;p=141</wfw:commentRss>
		</item>
		<item>
		<title>CodeCampOz 2009 is on: 04th of April – 05th of April</title>
		<link>http://www.acorns.com.au/blog/?p=140</link>
		<comments>http://www.acorns.com.au/blog/?p=140#comments</comments>
		<pubDate>Mon, 02 Feb 2009 00:03:18 +0000</pubDate>
		<dc:creator>Corneliu</dc:creator>
		
		<category><![CDATA[Readify]]></category>

		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=140</guid>
		<description><![CDATA[CodeCampOz is again on this year in the good old same Wagga-Wagga.
Mitch just announced the dates for this year’s CodeCampOz: 04th of April to 05th of April.
Attendance is free and we are open for registrations.
I’ll see you all there.
]]></description>
			<content:encoded><![CDATA[<p>CodeCampOz is again on this year in the good old same Wagga-Wagga.</p>
<p><a href="http://notgartner.wordpress.com/2009/02/01/code-camp-oz-2009-registrations-open/">Mitch just announced the dates</a> for this year’s CodeCampOz: 04th of April to 05th of April.</p>
<p>Attendance is free and <a href="http://codecampoz2009.eventbrite.com/">we are open for registrations</a>.</p>
<p>I’ll see you all there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acorns.com.au/blog/?feed=rss2&amp;p=140</wfw:commentRss>
		</item>
		<item>
		<title>Windows 7 Beta Now Available</title>
		<link>http://www.acorns.com.au/blog/?p=139</link>
		<comments>http://www.acorns.com.au/blog/?p=139#comments</comments>
		<pubDate>Thu, 08 Jan 2009 03:09:58 +0000</pubDate>
		<dc:creator>Corneliu</dc:creator>
		
		<category><![CDATA[Readify]]></category>

		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=139</guid>
		<description><![CDATA[It&#8217;s official: Just minutes ago Steve Balmer declared that Windows 7 Beta is available now for download. For now it will be available to MSDN subscribers only.
Head now to MSDN and get your own copy.
Feedback can be provided on the Microsoft TechNet Forums in the newly created Windows 7 Beta forums.
The installation package for Windows [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s official: Just minutes ago <a target="_blank" href="http://www.microsoft.com/presspass/events/ces/default.mspx">Steve Balmer declared</a> that <strong>Windows 7 Beta</strong> is available now for download. For now it will be available to MSDN subscribers only.</p>
<p>Head now to <a target="_blank" href="https://msdn.microsoft.com/en-us/subscriptions/">MSDN</a> and get your own copy.</p>
<p>Feedback can be provided on the Microsoft TechNet Forums in the newly created <a target="_blank" href="http://social.technet.microsoft.com/Forums/en/category/w7itpro/">Windows 7 Beta forums</a>.</p>
<p>The installation package for Windows 7 Beta x86 is just 2.4Gb. I&#8217;ve just started my download &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acorns.com.au/blog/?feed=rss2&amp;p=139</wfw:commentRss>
		</item>
		<item>
		<title>How to get a discount on your next Microsoft Exam?</title>
		<link>http://www.acorns.com.au/blog/?p=138</link>
		<comments>http://www.acorns.com.au/blog/?p=138#comments</comments>
		<pubDate>Wed, 07 Jan 2009 13:34:15 +0000</pubDate>
		<dc:creator>Corneliu</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Readify]]></category>

		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=138</guid>
		<description><![CDATA[The best discount for your next exam can be obtained via Andrew Coates who has 15 vouchers for free MCP exams. 
If you&#8217;ve missed his offer I then have another offer for you: 10% off your next Microsoft exam and a free re-take (if God forbidden you fail the first attempt).
To get your 10% discount [...]]]></description>
			<content:encoded><![CDATA[<p>The best discount for your next exam can be obtained via Andrew Coates who has <strong><a target="_blank" href="http://blogs.msdn.com/acoat/archive/2009/01/07/want-help-with-that-new-years-resolution-take-a-free-certification-test.aspx">15 vouchers for free MCP</a></strong> exams. </p>
<p>If you&#8217;ve missed his offer I then have another offer for you: <strong>10% off your next Microsoft exam and a free re-take</strong> (if God forbidden you fail the first attempt).</p>
<p>To get your 10% discount head over to <a title="http://www.learnandcertify.com/" target="_blank" href="http://www.learnandcertify.com/">http://www.learnandcertify.com/</a>, click on &#8220;Get My Exam Offer Voucher code today&#8221; and enter the <em>MVP Certification Promotion Code:</em> <strong>AUD68E69</strong> to receive the voucher code for your next exam. (Offer valid for Australia only.)</p>
<p>Please also drop me an email once you do the exam so I can congratulate you.</p>
<p><small>(all the other <a target="_blank" href="http://www.learnandcertify.com/Terms.aspx">Terms and Conditions and legal small print</a> will apply)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.acorns.com.au/blog/?feed=rss2&amp;p=138</wfw:commentRss>
		</item>
		<item>
		<title>I’m now a Microsoft MVP: Developer Security</title>
		<link>http://www.acorns.com.au/blog/?p=137</link>
		<comments>http://www.acorns.com.au/blog/?p=137#comments</comments>
		<pubDate>Wed, 07 Jan 2009 13:02:40 +0000</pubDate>
		<dc:creator>Corneliu</dc:creator>
		
		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Readify]]></category>

		<guid isPermaLink="false">http://www.acorns.com.au/blog/?p=137</guid>
		<description><![CDATA[Happy New Year everyone. I hope the Christmas &#38; New Year break was good for you and Santa brought you loads of presents.
Santa was a bit late for me but it arrived on the 2nd of January with an MVP Award.
So I&#8217;m officially a &#8220;Developer Security MVP&#8221; (in the Developer Tools category).
My thanks go to [...]]]></description>
			<content:encoded><![CDATA[<p>Happy New Year everyone. I hope the Christmas &amp; New Year break was good for you and Santa brought you loads of presents.</p>
<p>Santa was a bit late for me but it arrived on the 2nd of January with an MVP Award.</p>
<p>So I&#8217;m officially a &#8220;Developer Security MVP&#8221; (in the Developer Tools category).</p>
<p>My thanks go to <a href="http://msmvps.com/blogs/robfarley/default.aspx">Rob Farley</a> from <a target="_blank" href="http://www.lobsterpot.com.au">LobsterPot</a> for nominating me, the great <a target="_blank" href="http://readify.net/tech-zone/readify-bloggers/">Readify Team</a> for their continuous support and to <a target="_blank" href="http://www.ssw.com.au/ssw/Employees/employeesprofile.aspx?EmpID=AC">Adam Cogan</a> for challenging and inspiring me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.acorns.com.au/blog/?feed=rss2&amp;p=137</wfw:commentRss>
		</item>
	</channel>
</rss>
