<?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>Richards blog</title>
	<atom:link href="http://richardwilburn.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://richardwilburn.wordpress.com</link>
	<description>Blog about WPF, .NET events and Application Architecture</description>
	<lastBuildDate>Sun, 07 Aug 2011 04:53:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='richardwilburn.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Richards blog</title>
		<link>http://richardwilburn.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://richardwilburn.wordpress.com/osd.xml" title="Richards blog" />
	<atom:link rel='hub' href='http://richardwilburn.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Adding a controller to JQueryMobile</title>
		<link>http://richardwilburn.wordpress.com/2011/08/01/adding-a-controller-to-jquerymobile/</link>
		<comments>http://richardwilburn.wordpress.com/2011/08/01/adding-a-controller-to-jquerymobile/#comments</comments>
		<pubDate>Mon, 01 Aug 2011 08:57:02 +0000</pubDate>
		<dc:creator>rhwilburn</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JQuery Mobile]]></category>

		<guid isPermaLink="false">https://richardwilburn.wordpress.com/2011/08/01/adding-a-controller-to-jquerymobile/</guid>
		<description><![CDATA[JQuery Mobile highlights the power of HTML5 data attributes. An example div element with such an attribute could be: &#60;div data-role="header"&#62; This new feature introduced in HTML5 – but backwards compatible with previous versions – is able to provide us with the flexibility to say what we mean rather than impreatively tell the code to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=117&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>JQuery Mobile highlights the power of HTML5 data attributes. An example div element with such an attribute could be:</p>
<blockquote>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">div</span> <span class="attr">data-role</span><span class="kwrd">="header"</span><span class="kwrd">&gt;</span></pre>
</blockquote>
<p>This new feature introduced in HTML5 – but backwards compatible with previous versions – is able to provide us with the flexibility to say what we mean rather than impreatively tell the code to do something. Im talking about declarative vs imperative programming.</p>
<h4>Why Controllers in javascript?</h4>
<p>Controllers are a part of the MVC pattern and are quite common in many areas of programming, however in my experience not so common in javascript development. This is possibly due to the requirement of javascript growing more and more as time goes on, and possibly due to the small scale in which it is usually used. Mobile <span style="color:#666666;">development with phone gap tends to challenge this perspective of javascript by enabling large javascript applications to be developed in the mainstream.</span></p>
<h4></h4>
<h4><span style="color:#666666;">Proposed approach</span></h4>
<pre class="csharpcode"><span class="kwrd"><span style="text-decoration:underline;"><span style="color:#666666;">The Html</span></span></span></pre>
<pre class="csharpcode"></pre>
<blockquote>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">a </span><span class="attr">data-action</span><span class="kwrd">="postForm"</span><span class="kwrd">&gt;</span></pre>
</blockquote>
<pre class="csharpcode"></pre>
<pre class="csharpcode"><span class="kwrd"><span style="color:#666666;"><span style="text-decoration:underline;">The JQuery</span></span></span></pre>
<pre class="csharpcode"></pre>
<blockquote>
<pre class="csharpcode">$(<span class="str">'a[data-action*=""]'</span>).live(<span class="str">'click'</span>, <span class="kwrd">function</span> () {
      Log(<span class="str">"Click -&gt; Action"</span>);
      pageController.processAction($(<span class="kwrd">this</span>));
});</pre>
</blockquote>
<blockquote>
<pre class="csharpcode"><span class="kwrd">var</span> pageController = <span class="kwrd">new</span> PageController();

<span class="kwrd">function</span> PageController() {
    <span class="kwrd">this</span>.processAction = <span class="kwrd">function</span> (itemWithAction) {

        <span class="kwrd">var</span> action = itemWithAction.attr(<span class="str">'data-action'</span>);

        <span class="rem">//Log("action = " + action);</span>

        <span class="rem">//Do something with the action here!!!</span>
}</pre>
</blockquote>
<pre class="csharpcode"></pre>
<pre class="csharpcode"><span style="text-decoration:underline;">Performance benefits</span></pre>
<pre class="csharpcode"></pre>
<pre class="csharpcode">Subscribing one click event to all necessary elements of the DOM for an application will be quite the performance hit. Instead this solution is subscribing to the root element of the DOM once. For more information see: <a title="http://api.jquery.com/live/" href="http://api.jquery.com/live/">http://api.jquery.com/live/</a></pre>
<pre class="csharpcode"></pre>
<pre class="csharpcode"><span style="text-decoration:underline;">Reusability</span></pre>
<pre class="csharpcode"></pre>
<pre class="csharpcode">The actions are able to be reused across multiple pages. They are fully separated from the page, with a reference to the triggering element.</pre>
<pre class="csharpcode"></pre>
<pre class="csharpcode"><span style="text-decoration:underline;">Readability</span></pre>
<pre class="csharpcode"></pre>
<pre class="csharpcode">Html elements that use data attributes to call actions make tracing event-action mappings much easier</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/richardwilburn.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/richardwilburn.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/richardwilburn.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/richardwilburn.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/richardwilburn.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/richardwilburn.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/richardwilburn.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/richardwilburn.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/richardwilburn.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/richardwilburn.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/richardwilburn.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/richardwilburn.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/richardwilburn.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/richardwilburn.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=117&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://richardwilburn.wordpress.com/2011/08/01/adding-a-controller-to-jquerymobile/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ffe8ab5bc0cb86bd1cb53167b02529c0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rhwilburn</media:title>
		</media:content>
	</item>
		<item>
		<title>Jquery Mobile &#8211; Dynamic Pages</title>
		<link>http://richardwilburn.wordpress.com/2011/04/09/jquery-mobile-dynamic-pages/</link>
		<comments>http://richardwilburn.wordpress.com/2011/04/09/jquery-mobile-dynamic-pages/#comments</comments>
		<pubDate>Sat, 09 Apr 2011 20:49:49 +0000</pubDate>
		<dc:creator>rhwilburn</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JQuery Mobile]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[DocumentFragment]]></category>
		<category><![CDATA[getAttr()]]></category>
		<category><![CDATA[getAttribute()]]></category>
		<category><![CDATA[HTML 5]]></category>

		<guid isPermaLink="false">https://richardwilburn.wordpress.com/2011/04/09/jquery-mobile-dynamic-pages/</guid>
		<description><![CDATA[Recently, I decided to make a mobile application. I have chosen to use a combination of Jquery Mobile and phone gap in order to achieve this goal. I have found Jquery Mobile to be a good framework for making mobile applications however it is not long before discovering its abilities to dynamically generate content are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=113&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, I decided to make a mobile application. I have chosen to use a combination of Jquery Mobile and phone gap in order to achieve this goal.</p>
<p>I have found Jquery Mobile to be a good framework for making mobile applications however it is not long before discovering its abilities to dynamically generate content are not well documented. This is possibly because at the time of writing this, Jquery Mobile is in alpha status.</p>
<p>After googling round for quite a while, I discovered that there is a function called page(). That when applied to the end of an HTML fragment, it will convert the HTML into JQuery mobile appropriate HTML. The concepts of using this that are important are as follows</p>
<ol>
<li>Jquery mobile does not restrict functionality of Jquery.</li>
<li>Jquery mobile parses an HTML document with the page() function to convert HTML to jquery mobile HTML (for better control/css theming etc).</li>
<li>Jquery mobile will not parse updated html fragments added to the document unless you explicitly call the .page() function on that HTML fragment.</li>
<li>In modern browsers, Jquery/java-script often  treats html blobs as a ‘documentFragment’ type which has virtually no functionality[<a href="http://www.w3.org/2003/01/dom2-javadoc/org/w3c/dom/DocumentFragment.html">W3C</a>]. This can cause some confusion when calling the page function as the page function will fail on documentFragment types as discussed by me [<a href="http://forum.jquery.com/topic/jquery-mobile-falls-over-when-calling-page-function-on-nested-select-tag">Jquery Forum</a>].</li>
<li>Jquery mobile allows us to build phone gap and internet browser applications, allowing us to reach many markets with one solution.</li>
<li>Jquery mobile is built on HTML 5. It uses the new meta data functionality for tags, i.e. &lt;div data-tag=”taginfo” /&gt; is valid in HTML 5 as any attribute on any tag that starts with data- is treated as meta-data (its not executed, but is recognized as valid by HTML 5 browsers).</li>
<li>Jquery mobile has good examples but not always a good discussion of the concepts behind it, maybe I skipped over that part in my enthusiasm to get developing.</li>
<li>Regular Updates. Currently they seem to release a new version of the alpha every 3 months.</li>
</ol>
<p>An example of how to use the page function:</p>
<p>1) make sure you have a “page” on your html document:</p>
<pre style="padding-left:30px;">&lt;body&gt;
   &lt;div id="MyFirstMobilePage" data-role="page"&gt;&lt;/div&gt;
&lt;/body&gt;</pre>
<p>2) add the following to the head of the document:</p>
<pre style="padding-left:30px;">&lt;head&gt;
&lt;link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.css" /&gt;
&lt;script src="http://code.jquery.com/jquery-1.5.min.js"&gt;&lt;/script&gt;
&lt;script src="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
   $(function(){
      $('&lt;select&gt;&lt;option&gt;test 1&lt;/option&gt;&lt;/select&gt;').appendTo('#MyFirstMobilePage).page();
   });
&lt;/script&gt;
&lt;/head&gt;</pre>
<p>If you run this code with <a href="http://getfirebug.com/">firebug</a> etc. installed in your browser you will observe that the HTML gets updated, not only inserting the select tag, but also other tags that are required by the mobile framework.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/richardwilburn.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/richardwilburn.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/richardwilburn.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/richardwilburn.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/richardwilburn.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/richardwilburn.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/richardwilburn.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/richardwilburn.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/richardwilburn.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/richardwilburn.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/richardwilburn.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/richardwilburn.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/richardwilburn.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/richardwilburn.wordpress.com/113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=113&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://richardwilburn.wordpress.com/2011/04/09/jquery-mobile-dynamic-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ffe8ab5bc0cb86bd1cb53167b02529c0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rhwilburn</media:title>
		</media:content>
	</item>
		<item>
		<title>WCF Windows Service Deployment</title>
		<link>http://richardwilburn.wordpress.com/2010/12/01/wcf-windows-service-deployment/</link>
		<comments>http://richardwilburn.wordpress.com/2010/12/01/wcf-windows-service-deployment/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 08:49:56 +0000</pubDate>
		<dc:creator>rhwilburn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Batch file install wcf windows service]]></category>

		<guid isPermaLink="false">https://richardwilburn.wordpress.com/2010/12/01/wcf-windows-service-deployment/</guid>
		<description><![CDATA[I recently started work on a personal project to make a WCF Windows Service using the following tutorial: [1]. I soon realised that I would need to write a batch file to not be hugely disadvantaged by manual deployment. I also wanted my deployment batch scripts to be re-useable by other developers on the project. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=101&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently started work on a personal project to make a WCF Windows Service using the following tutorial: <a title="http://msdn.microsoft.com/en-us/library/ms733069.aspx" href="http://msdn.microsoft.com/en-us/library/ms733069.aspx">[1]</a>. I soon realised that I would need to write a batch file to not be hugely disadvantaged by manual deployment. I also wanted my deployment batch scripts to be re-useable by other developers on the project.</p>
<p>The batch files I came up with were:</p>
<p>Install.bat:</p>
<blockquote><p>@ECHO OFF</p>
<p>:: Known issues -<br />
:: 1) if services window is open (ie the one when u start-&gt;run-&gt;services.msc) then the process will not close. You must close this window.<br />
:: 2) if you don&#8217;t do a clean build then it will just install old version of service. Make sure you uninstall then do a clean build.</p>
<p>cd..</p>
<p>SET projectDirectory=%CD%</p>
<p>cd /d &#8220;%WinDir%\Microsoft.NET\Framework\v4.0.*&#8221;</p>
<p>SET net4Path=%CD%</p>
<p>@ECHO ON</p>
<p>%net4Path%\installutil &#8220;%PROJECTDIRECTORY%\bin\Debug\OrderServices.exe&#8221;</p>
<p>net start OrderServices</p></blockquote>
<p>Uninstall.bat:</p>
<blockquote><p>REM @ECHO OFF</p>
<p>cd..</p>
<p>SET projectDirectory=%CD%</p>
<p>cd /d &#8220;%WinDir%\Microsoft.NET\Framework\v4.0.*&#8221;</p>
<p>SET net4Path=%CD%</p>
<p>net stop OrderServices</p>
<p>%net4Path%\installutil /u &#8220;%PROJECTDIRECTORY%\bin\Debug\OrderServices.exe&#8221;</p>
<p>pause</p></blockquote>
<p>Reinstall.bat (untested):</p>
<blockquote><p>@echo off<br />
CALL Unistall.bat<br />
CALL Install.bat</p></blockquote>
<p>Those batch files assume the following file structure in your service project:</p>
<p><a href="http://richardwilburn.files.wordpress.com/2010/12/projectstructure1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="ProjectStructure" src="http://richardwilburn.files.wordpress.com/2010/12/projectstructure_thumb1.png?w=269&#038;h=434" border="0" alt="ProjectStructure" width="269" height="434" /></a></p>
<p>Update:</p>
<p>The following link adds reference information as to how to forcefully play with services with the SC command: <a title="http://ss64.com/nt/sc.html" href="http://ss64.com/nt/sc.html">http://ss64.com/nt/sc.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/richardwilburn.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/richardwilburn.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/richardwilburn.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/richardwilburn.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/richardwilburn.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/richardwilburn.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/richardwilburn.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/richardwilburn.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/richardwilburn.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/richardwilburn.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/richardwilburn.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/richardwilburn.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/richardwilburn.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/richardwilburn.wordpress.com/101/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=101&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://richardwilburn.wordpress.com/2010/12/01/wcf-windows-service-deployment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ffe8ab5bc0cb86bd1cb53167b02529c0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rhwilburn</media:title>
		</media:content>

		<media:content url="http://richardwilburn.files.wordpress.com/2010/12/projectstructure_thumb1.png" medium="image">
			<media:title type="html">ProjectStructure</media:title>
		</media:content>
	</item>
		<item>
		<title>Dependency Property Basics</title>
		<link>http://richardwilburn.wordpress.com/2010/03/05/dependency-property-basics/</link>
		<comments>http://richardwilburn.wordpress.com/2010/03/05/dependency-property-basics/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 22:34:04 +0000</pubDate>
		<dc:creator>rhwilburn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://richardwilburn.wordpress.com/2010/03/05/dependency-property-basics/</guid>
		<description><![CDATA[When working with WPF it can be necessary to extend a control to enable data-binding to a property that isn’t bind-able (because it is not a dependency property etc.). The following code demonstrates an example I have made where I override a Text property and give it a dependency property to enable data-binding. &#160; public [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=98&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<p style="margin:0;">When working with WPF it can be necessary to extend a control to enable data-binding to a property that isn’t bind-able (because it is not a dependency property etc.). The following code demonstrates an example I have made where I override a Text property and give it a dependency property to enable data-binding.</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">readonly</span> <span style="color:#2b91af;">DependencyProperty</span> TextProperty = <span style="color:#2b91af;">DependencyProperty</span>.Register(<span style="color:#a31515;">&quot;Text&quot;</span>, <span style="color:blue;">typeof</span>(<span style="color:blue;">string</span>), <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">TextEditorControl</span>), <span style="color:blue;">new</span> <span style="color:#2b91af;">FrameworkPropertyMetadata</span>(OnTextPropertyChanged));</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> OnTextPropertyChanged(<span style="color:#2b91af;">DependencyObject</span> dp, <span style="color:#2b91af;">DependencyPropertyChangedEventArgs</span> e)</p>
<p style="margin:0;">{</p>
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<p style="margin:0;"><span style="color:green;">&#160;&#160;&#160; //TODO: action handler here</span></p>
</p></div>
<p style="margin:0;">}</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">override</span> <span style="color:blue;">string</span> Text</p>
<p style="margin:0;">{</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">get</span></p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">return</span> (<span style="color:blue;">string</span>)GetValue(TextProperty) ?? <span style="color:blue;">string</span>.Empty;</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">set</span></p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">base</span>.Text = <span style="color:blue;">value</span>;</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; SetValue(TextProperty, <span style="color:blue;">value</span>);</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">}</p>
<p style="margin:0;">&#160;</p>
<p>The code also shows how to handle the event raised when the binding source (the view model) is updated. I recommend using dependency properties for WPF controls; as for view model classes I recommend implementing the INotifyPropertyChanged interface instead.</p>
</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/richardwilburn.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/richardwilburn.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/richardwilburn.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/richardwilburn.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/richardwilburn.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/richardwilburn.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/richardwilburn.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/richardwilburn.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/richardwilburn.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/richardwilburn.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/richardwilburn.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/richardwilburn.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/richardwilburn.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/richardwilburn.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=98&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://richardwilburn.wordpress.com/2010/03/05/dependency-property-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ffe8ab5bc0cb86bd1cb53167b02529c0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rhwilburn</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Castle&#8217;s Dynamic Proxy</title>
		<link>http://richardwilburn.wordpress.com/2009/12/17/using-castles-dynamic-proxy/</link>
		<comments>http://richardwilburn.wordpress.com/2009/12/17/using-castles-dynamic-proxy/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 07:38:26 +0000</pubDate>
		<dc:creator>rhwilburn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://richardwilburn.wordpress.com/2009/12/17/using-castles-dynamic-proxy/</guid>
		<description><![CDATA[As a user of Rhino Mocks, Ninject and certain parts of the Castle Project, I found myself wondering what the Castle Project’s dynamic proxy was. I have since learned and love the idea of, dynamic proxies. What does a dynamic proxy do A dynamic proxy is a way of generating a subclass from a class [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=84&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As a user of <a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino Mocks</a>, <a href="http://ninject.org/">Ninject</a> and certain parts of the <a href="http://www.castleproject.org/">Castle Project</a>, I found myself wondering what the <a href="http://www.castleproject.org/dynamicproxy/index.html">Castle Project’s dynamic proxy</a> was. I have since learned and love the idea of, dynamic proxies.</p>
<p><u>What does a dynamic proxy do</u></p>
<p>A dynamic proxy is a way of generating a subclass from a class or interface of which is generally a model. That subclass overrides every method that it can (make your methods virtual to allow to do it). This provides the ability to intercept calls to all methods on your class/interface because the sub-classed methods route requests to an interface which dictates whether a call can proceed. You could implement that functionality yourself, however you would need to cater for all method calls. The dynamic proxy provides one interceptor handler for all methods, and you can have many interceptors on one class.</p>
<p><u>Cross cutting concerns</u></p>
<p>One of the major benefits of using proxy objects is the ability to separate cross cutting concerns such as logging. Take the following diagram as an example. It shows how the logging interceptor which takes care of the logging can log calls made to the person object without the person object having a reference or knowing about the logging interceptor. The person object also doesn’t know about the dynamic proxy library.</p>
<p><a href="http://richardwilburn.files.wordpress.com/2009/12/dynamicproxydiagram.png"><img title="DynamicProxyDiagram" style="display:inline;border-width:0;" height="313" alt="DynamicProxyDiagram" src="http://richardwilburn.files.wordpress.com/2009/12/dynamicproxydiagram_thumb.png?w=492&#038;h=313" width="492" border="0" /></a></p>
</p>
<p>An argument for separating out logging from our classes could be that we might want to turn logging on or off, or that we want to replace our logging library at a later date. Both of those scenarios could be catered for by having a logging class which is directly called by our Person object. The advantage of doing that could be minor performance gains, and the disadvantage of not using a proxy is that the person object would be polluted with unnecessary code. Ideally a class would have a single purpose, and logging would not conform to the purpose of the person business object in my opinion because logging is an environmental aspect regarding person as opposed to actually defining what a person is. A strong example of this is using a dynamic proxy to add permission based access to calls on third party libraries without modifying the external library.</p>
<p><u>Interceptors</u></p>
<p>The following code shows how a logging interceptor might look. It logs the method name of the method that is currently being accessed, then it allows the method request to proceed. Without invocation.proceed, the call would not proceed to the person object in the previous example, and would instead be consumed.</p>
</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:rgb(43,145,175);">LoggingInterceptor</span> : <span style="color:rgb(43,145,175);">IInterceptor</span></p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">void</span> Intercept(<span style="color:rgb(43,145,175);">IInvocation</span> invocation)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:rgb(43,145,175);">Console</span>.Write(<span style="color:rgb(163,21,21);">&quot;Log: Method Called: &quot;</span>+ invocation.Method.Name);</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; invocation.Proceed();</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p>&#160;</p>
<p><u>Boxing and Un-boxing proxies</u></p>
<p>To create a proxy you can do the following:</p>
<p style="margin:0;"><span style="color:rgb(43,145,175);">ProxyGenerator</span> generator = <span style="color:blue;">new</span> <span style="color:rgb(43,145,175);">ProxyGenerator</span>();</p>
<p style="margin:0;"><span style="color:rgb(43,145,175);">Person </span>person = generator.CreateClassProxy&lt;<span style="color:rgb(43,145,175);">Person</span>&gt;(<span style="color:blue;">new</span> <span style="color:rgb(43,145,175);">LoggingInterceptor</span>());</p>
<p>&#160;</p>
<p>If you are developing in a situation where you have a network boundary and you need to send your business objects across a network you will probably want to shed your proxies and possibly recreate the proxies on the other side of the network boundary.</p>
<p style="margin:0;"><span style="color:rgb(43,145,175);">var</span> proxyTarget = personProxyObject as <span style="color:rgb(43,145,175);">IProxyTargetAccessor</span></p>
<p style="margin:0;"><span style="color:rgb(43,145,175);">var</span> person = proxyTarget.DynProxyGetTarget() as <span style="color:rgb(43,145,175);">Person;</span></p>
<p>&#160;</p>
<p><u>More Information</u></p>
<ul>
<li><a title="http://kozmic.pl/archive/2008/12/30/castle-dynamic-proxy-tutorial-part-ii-the-what-why-and.aspx" href="http://kozmic.pl/archive/2008/12/30/castle-dynamic-proxy-tutorial-part-ii-the-what-why-and.aspx">http://kozmic.pl/archive/2008/12/30/castle-dynamic-proxy-tutorial-part-ii-the-what-why-and.aspx</a>       </li>
<li><a title="http://kozmic.pl/Tags/Dynamic%20Proxy/default.aspx" href="http://kozmic.pl/Tags/Dynamic%20Proxy/default.aspx">http://kozmic.pl/Tags/Dynamic%20Proxy/default.aspx</a>       </li>
<li><a title="http://en.wikipedia.org/wiki/Factory_method_pattern" href="http://en.wikipedia.org/wiki/Factory_method_pattern">http://en.wikipedia.org/wiki/Factory_method_pattern</a> </li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/richardwilburn.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/richardwilburn.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/richardwilburn.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/richardwilburn.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/richardwilburn.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/richardwilburn.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/richardwilburn.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/richardwilburn.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/richardwilburn.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/richardwilburn.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/richardwilburn.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/richardwilburn.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/richardwilburn.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/richardwilburn.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=84&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://richardwilburn.wordpress.com/2009/12/17/using-castles-dynamic-proxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ffe8ab5bc0cb86bd1cb53167b02529c0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rhwilburn</media:title>
		</media:content>

		<media:content url="http://richardwilburn.files.wordpress.com/2009/12/dynamicproxydiagram_thumb.png" medium="image">
			<media:title type="html">DynamicProxyDiagram</media:title>
		</media:content>
	</item>
		<item>
		<title>C# Actions part 2: Lazy evaluation</title>
		<link>http://richardwilburn.wordpress.com/2009/07/14/c-actions-part-2-lazy-evaluation/</link>
		<comments>http://richardwilburn.wordpress.com/2009/07/14/c-actions-part-2-lazy-evaluation/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 10:32:23 +0000</pubDate>
		<dc:creator>rhwilburn</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[C# Action Lazy Evaluation Func Delegate List]]></category>

		<guid isPermaLink="false">http://richardwilburn.wordpress.com/2009/07/14/c-actions-part-2-lazy-evaluation/</guid>
		<description><![CDATA[Lazy Evaluation example: In a previous post I talked about C# Actions and how they are a useful feature that could provide new shorthand for lazy evaluation. I have since found an excellent article [1] which demonstrates lazy evaluation with LINQ. The advantages in that article show how LINQ queries can minimize memory usage by [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=75&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration:underline;">Lazy Evaluation example:</span></p>
<p>In a <a href="http://richardwilburn.wordpress.com/2009/07/05/c-actions/">previous post</a> I talked about C# Actions and how they are a useful feature that could provide new shorthand for lazy evaluation. I have since found an excellent article <a title="http://blogs.msdn.com/pedram/archive/2007/06/02/lazy-evaluation-in-c.aspx" href="http://blogs.msdn.com/pedram/archive/2007/06/02/lazy-evaluation-in-c.aspx">[1]</a> which demonstrates lazy evaluation with LINQ. The advantages in that article show how LINQ queries can minimize memory usage by evaluating upon enumeration rather than just allocating memory for everything the query would return.</p>
<p><span style="text-decoration:underline;">Func</span></p>
<p>Actions are delegates that have a void return type. This makes sense if you are using Actions as event handlers, but for other use cases you will want a return type. In these cases you will want to use Func. One issue I have seen with Func is when you want don’t know how many parameters your function is going to take. If the number is variable then you must implement up to the amount of parameters you want (if overloading). I noticed a few examples of that in the <a href="http://ninject.org/">Ninject</a> 1.x source code. To generalize Func and Actions you can use the ‘Delegate’ type (note: the captialization).</p>
<p><span style="text-decoration:underline;">A real world use case</span></p>
<p>A reason for lazy evaluation could be that you want to perform a group of service calls at one time. The service calls could be a transaction style interaction which would want to be disposed afterwards and some of the service calls could be surplus to requirement. If I had a user interface which required a list of products to be loaded, then that screen may not need that data reloaded if it is moving from a screen which has that data loaded. That service call could be pre-evaluated (ie lazy evaluation) to check to see if it is necessary.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/richardwilburn.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/richardwilburn.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/richardwilburn.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/richardwilburn.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/richardwilburn.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/richardwilburn.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/richardwilburn.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/richardwilburn.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/richardwilburn.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/richardwilburn.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/richardwilburn.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/richardwilburn.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/richardwilburn.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/richardwilburn.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=75&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://richardwilburn.wordpress.com/2009/07/14/c-actions-part-2-lazy-evaluation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ffe8ab5bc0cb86bd1cb53167b02529c0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rhwilburn</media:title>
		</media:content>
	</item>
		<item>
		<title>Observable Dictionary</title>
		<link>http://richardwilburn.wordpress.com/2009/07/13/observable-dictionary/</link>
		<comments>http://richardwilburn.wordpress.com/2009/07/13/observable-dictionary/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 09:21:16 +0000</pubDate>
		<dc:creator>rhwilburn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Observable Dictionary Collection Databinding]]></category>

		<guid isPermaLink="false">http://richardwilburn.wordpress.com/2009/07/13/observable-dictionary/</guid>
		<description><![CDATA[As a fan of ObservableCollections, I have created an observable dictionary. I have provided the code below. I have implemented interfaces that should allow for WPF databinding. The reason I needed such a class is because I needed an event to indicate when the dictionary was updated. I kept this class small (it is just [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=74&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<p>As a fan of <a href="http://msdn.microsoft.com/en-us/library/ms668604.aspx">ObservableCollections</a>, I have created an observable dictionary. I have provided the code below. I have implemented interfaces that should allow for WPF databinding. The reason I needed such a class is because I needed an event to indicate when the dictionary was updated. I kept this class small (it is just a wrapper over a dictionary).</p>
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ObservableDictionary</span>&lt;TKey, TValue&gt; :</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; IDictionary&lt;TKey, TValue&gt;,</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; INotifyCollectionChanged,</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; INotifyPropertyChanged</p>
<p style="margin:0;">{</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">event</span> NotifyCollectionChangedEventHandler CollectionChanged;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">event</span> PropertyChangedEventHandler PropertyChanged;</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">readonly</span> IDictionary&lt;TKey, TValue&gt; _dictionary = <span style="color:blue;">new</span> Dictionary&lt;TKey, TValue&gt;();</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> IEnumerator&lt;KeyValuePair&lt;TKey, TValue&gt;&gt; GetEnumerator()</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">return</span> _dictionary.GetEnumerator();</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; IEnumerator IEnumerable.GetEnumerator()</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">return</span> GetEnumerator();</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">void</span> Add(KeyValuePair&lt;TKey, TValue&gt; item)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; _dictionary.Add(item);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (CollectionChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CollectionChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add));</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (PropertyChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Keys&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Values&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">void</span> Clear()</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">int</span> keysCount = _dictionary.Keys.Count;</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; _dictionary.Clear();</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (keysCount == 0) <span style="color:blue;">return</span>; <span style="color:green;">//dont trigger changed event if there was no change.</span></p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (CollectionChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CollectionChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (PropertyChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Keys&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Values&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">bool</span> Contains(KeyValuePair&lt;TKey, TValue&gt; item)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">return</span> _dictionary.Contains(item);</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">void</span> CopyTo(KeyValuePair&lt;TKey, TValue&gt;[] array, <span style="color:blue;">int</span> arrayIndex)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; _dictionary.CopyTo(array, arrayIndex);</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">bool</span> Remove(KeyValuePair&lt;TKey, TValue&gt; item)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">bool</span> remove = _dictionary.Remove(item);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (!remove) <span style="color:blue;">return</span> <span style="color:blue;">false</span>; <span style="color:green;">//don&#8217;t trigger change events if there was no change.</span></p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (CollectionChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CollectionChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove));</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (PropertyChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Keys&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Values&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">return</span> <span style="color:blue;">true</span>;</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">int</span> Count</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">get</span> { <span style="color:blue;">return</span> _dictionary.Count; }</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">bool</span> IsReadOnly</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">get</span> { <span style="color:blue;">return</span> _dictionary.IsReadOnly; }</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">bool</span> ContainsKey(TKey key)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">return</span> _dictionary.ContainsKey(key);</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">void</span> Add(TKey key, TValue value)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; _dictionary.Add(key, value);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (CollectionChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CollectionChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add));</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (PropertyChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Keys&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Values&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">bool</span> Remove(TKey key)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">bool</span> remove = _dictionary.Remove(key);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (!remove) <span style="color:blue;">return</span> <span style="color:blue;">false</span>;</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (CollectionChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CollectionChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove));</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (PropertyChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Keys&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Values&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">return</span> <span style="color:blue;">true</span>;</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">bool</span> TryGetValue(TKey key, <span style="color:blue;">out</span> TValue value)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">return</span> _dictionary.TryGetValue(key, <span style="color:blue;">out</span> value);</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> TValue <span style="color:blue;">this</span>[TKey key]</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">get</span> { <span style="color:blue;">return</span> _dictionary[key]; }</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">set</span></p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">bool</span> changed = _dictionary[key].Equals(<span style="color:blue;">value</span>);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (!changed) <span style="color:blue;">return</span>; <span style="color:green;">//if there are no changes then we don&#8217;t need to update the value or trigger changed events.</span></p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _dictionary[key] = <span style="color:blue;">value</span>;</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (CollectionChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CollectionChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace));</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (PropertyChanged != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Keys&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> PropertyChangedEventArgs(<span style="color:#a31515;">&quot;Values&quot;</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> ICollection&lt;TKey&gt; Keys</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">get</span> { <span style="color:blue;">return</span> _dictionary.Keys; }</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> ICollection&lt;TValue&gt; Values</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">get</span> { <span style="color:blue;">return</span> _dictionary.Values; }</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">}</p>
</p></div>
<p>&#160;</p>
<p>A link to another (Larger) implementation of an Observable Dictionary: <a title="http://www.drwpf.com/Blog/Default.aspx?tabid=36&amp;EntryID=8" href="http://www.drwpf.com/Blog/Default.aspx?tabid=36&amp;EntryID=8">http://www.drwpf.com/Blog/Default.aspx?tabid=36&amp;EntryID=8</a></p>
<p><a style="text-decoration:none;" href="http://creativecommons.org/publicdomain/zero/1.0/" rel="license"><img alt="CC0" src="http://i.creativecommons.org/l/zero/1.0/88x31.png" border="0" /> </a>    <br />To the extent possible under law, <a href="http://richardwilburn.wordpress.com" rel="dct:publisher"><span>Richard Wilburn</span></a> has waived all copyright and related or neighboring rights to <span>Observable Dictionary</span>. This work is published from <span>New Zealand</span>. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/richardwilburn.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/richardwilburn.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/richardwilburn.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/richardwilburn.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/richardwilburn.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/richardwilburn.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/richardwilburn.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/richardwilburn.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/richardwilburn.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/richardwilburn.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/richardwilburn.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/richardwilburn.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/richardwilburn.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/richardwilburn.wordpress.com/74/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=74&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://richardwilburn.wordpress.com/2009/07/13/observable-dictionary/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ffe8ab5bc0cb86bd1cb53167b02529c0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rhwilburn</media:title>
		</media:content>

		<media:content url="http://i.creativecommons.org/l/zero/1.0/88x31.png" medium="image">
			<media:title type="html">CC0</media:title>
		</media:content>
	</item>
		<item>
		<title>C# Action’s</title>
		<link>http://richardwilburn.wordpress.com/2009/07/05/c-actions/</link>
		<comments>http://richardwilburn.wordpress.com/2009/07/05/c-actions/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 08:54:22 +0000</pubDate>
		<dc:creator>rhwilburn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C# Action delegate]]></category>

		<guid isPermaLink="false">http://richardwilburn.wordpress.com/2009/07/05/c-actions/</guid>
		<description><![CDATA[When playing around with UI events it is sometimes handy to use lambda notations of actions to do a tidy inline event-action handler definition such as: Button1.Click += (sender, args) =&#62; Debug.WriteLine("Button Click"); &#160; If we delve a little deeper into Actions, we can use them to pass around code snippets/functions. Action&#60;String&#62; action = (input) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=65&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<p>When playing around with UI events it is sometimes handy to use lambda notations of actions to do a tidy inline event-action handler definition such as:</p>
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<pre style="margin:0;">Button1.Click += (sender, args) =&gt; <span style="color:#2b91af;">Debug</span>.WriteLine(<span style="color:#a31515;">"Button Click"</span>);</pre>
<pre style="margin:0;">&nbsp;</pre>
</div>
<p>If we delve a little deeper into Actions, we can use them to pass around code snippets/functions. </p>
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<pre style="margin:0;"><span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">String</span>&gt; action = (input) =&gt; <span style="color:#2b91af;">Debug</span>.WriteLine(<span style="color:#a31515;">"Testing"</span> + input); </pre>
<pre style="margin:0;">&nbsp;</pre>
</div>
</div>
<p>I have heard many arguments against functional features such as actions in C# however I do feel that they are very useful in edge cases. One such case could be the mass adding of items to a dictionary, such as:</p>
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<pre style="margin:0;"><span style="color:blue;">var</span> namesDictionary = <span style="color:blue;">new</span> <span style="color:#2b91af;">Dictionary</span>&lt;<span style="color:blue;">int</span>, <span style="color:blue;">string</span>&gt;();</pre>
<pre style="margin:0;">&nbsp;</pre>
<pre style="margin:0;">namesDictionary.Add(1,<span style="color:#a31515;">"One"</span>);</pre>
<pre style="margin:0;">namesDictionary.Add(2,<span style="color:#a31515;">"Two"</span>);</pre>
<pre style="margin:0;">namesDictionary.Add(3,<span style="color:#a31515;">"Three"</span>);</pre>
<pre style="margin:0;">&nbsp;</pre>
</div>
<p>If we wanted to keep our code maintainable we might want to reduce our dependency to the Add method (especially if we had lots of dictionary add statements). </p>
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<pre style="margin:0;"><span style="color:#2b91af;">Action</span>&lt;<span style="color:blue;">int</span>,<span style="color:blue;">string</span>&gt; addAction = (key,value) =&gt; namesDictionary.Add(key,value);</pre>
<pre style="margin:0;"><span style="color:green;">//Action&lt;int,string&gt; addAction = namesDictionary.Add; //short syntax</span><span style="color:green;"></pre>
<p></span></div>
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<pre style="margin:0;">addAction(1, <span style="color:#a31515;">"One"</span>);&nbsp; <span style="color:green;">//etc</span></pre>
<pre style="margin:0;"><span style="color:green;"></span><span style="color:green;">&nbsp;</pre>
</div>
</div>
<p></span></p>
<p>Note that this dictionary example is a bad example as the collection initialization could be used here which is likely the most optimal solution. The following shows how the collection initialization could have been used:</p>
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<pre style="margin:0;"><span style="color:blue;">var</span> namesDictionary = <span style="color:blue;">new</span> <span style="color:#2b91af;">Dictionary</span>&lt;<span style="color:blue;">int</span>, <span style="color:blue;">string</span>&gt; {{1, <span style="color:#a31515;">"One"</span>}, {2, <span style="color:#a31515;">"Two"</span>}, {3, <span style="color:#a31515;">"Three"</span>}};</pre>
<pre style="margin:0;">&nbsp;</pre>
</div>
<p>This example also could have been solved more optimally using extension method(s), by extending the dictionary, dependency injection, lambda foreach statement, foreach loop etc. With that said, Actions are important in allowing for lazy evaluation/delayed invocation. I am not going to get into lazy evaluation in this post, but I recommend checking out the Haskell language community for lazy evaluation ideas. I highly recommend the following link for understanding how evaluation/manipulation of lambda expressions work.</p>
<p><a title="http://msdn.microsoft.com/en-us/library/bb397951.aspx" href="http://msdn.microsoft.com/en-us/library/bb397951.aspx">http://msdn.microsoft.com/en-us/library/bb397951.aspx</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/richardwilburn.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/richardwilburn.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/richardwilburn.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/richardwilburn.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/richardwilburn.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/richardwilburn.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/richardwilburn.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/richardwilburn.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/richardwilburn.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/richardwilburn.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/richardwilburn.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/richardwilburn.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/richardwilburn.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/richardwilburn.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=65&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://richardwilburn.wordpress.com/2009/07/05/c-actions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ffe8ab5bc0cb86bd1cb53167b02529c0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rhwilburn</media:title>
		</media:content>
	</item>
		<item>
		<title>Boosting Visual Studio Performance</title>
		<link>http://richardwilburn.wordpress.com/2009/03/06/boosting-visual-studio-performance/</link>
		<comments>http://richardwilburn.wordpress.com/2009/03/06/boosting-visual-studio-performance/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 22:11:23 +0000</pubDate>
		<dc:creator>rhwilburn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Visual Studio 2008 Performance]]></category>

		<guid isPermaLink="false">http://richardwilburn.wordpress.com/2009/03/06/boosting-visual-studio-performance/</guid>
		<description><![CDATA[Visual Studio has always worked fairly well for me at home, but at work where many of our projects/solutions are very large Visual Studio struggles. At home I still find that my Visual Studio is better than the one I use at work and I believe this is because at home I have my hard-drives [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=63&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Visual Studio has always worked fairly well for me at home, but at work where many of our projects/solutions are very large Visual Studio struggles. At home I still find that my Visual Studio is better than the one I use at work and I believe this is because at home I have my hard-drives in a performance RAID (Raid 0) and my OS is Vista x64 rather than XP x86.</p>
<p>Two things I suspect are: </p>
<p>Vista manages memory much better and doesn’t struggle with the out of memory exceptions that I frequently get at work. Note: Out of memory exceptions are actually to do with the .NET runtime not being able to garbage collect all of its generations properly. But the size of Visual Studio and the number of objects it is using is the cause of this.</p>
<p>Hard-drive speed affects Visual Studio more greatly than CPU and potentially even RAM. When I get out of memory exceptions at work (we all get this too btw) my PC is not using all of its 2 gigs of ram. Visual Studio is limited by default to 2 gigs, but this can be overcome.</p>
<h2>Remedies:</h2>
<p>&#160;</p>
<p>Faster harddrives, lowerlatency hard drives:</p>
<blockquote><p>On Vista with my RAID 0 my experience is better but is still latent. My IDE can load lots of data fast but often takes a while to do so. This means waits are still a small amount of time due to latency issues but large amounts of data are not really an issue.</p>
<p>I am starting to think that the ideal solution is a performance raid of Solid State Drives (SSD).&#160; A link on performance improvements for a Java IDE are available here: <a title="http://jexp.de/blog/archives/18-On-Boosting-My-IDEA-Jetbrains-IntelliJ-IDEA-is-fast-again.html" href="http://jexp.de/blog/archives/18-On-Boosting-My-IDEA-Jetbrains-IntelliJ-IDEA-is-fast-again.html">http://jexp.de/blog/archives/18-On-Boosting-My-IDEA-Jetbrains-IntelliJ-IDEA-is-fast-again.html</a></p>
<p>If you have an infinite money pool, a RAID card would be recommended too. These can have RAM on them to cache disk access which would further reduce latency.</p>
</blockquote>
<p>Upgrade OS:</p>
<blockquote><p>Upgrade to Vista and make sure you upgrade to the 64 bit version. It is silly not to take advantage of your CPU being x64.</p>
</blockquote>
<h2>Myths:</h2>
<p>&#160;</p>
<p>Resharper:</p>
<blockquote><p>Myth: Reshaper significantly degrades performance, and causes out of memory exceptions.</p>
<p>Interestingly resharper shows the out of memory exceptions (which can be a pain) where as Visual Studio virtually hides it from the user. Resharper is not causing these issues, and from what I have seen there is no significant performance difference apart from when the project is being loaded. That is because resharper loads its cache then by analysing assemblies.</p>
</blockquote>
<p>RAM:</p>
<blockquote><p>Myth: Increasing RAM will increase Visual Studio’s performance</p>
<p>I think that if Visual Studio is running out of memory then a RAM increase will help, but for us at work our RAM is not being fully utilized so on XP increasing our RAM won’t help us as the OS will not use it. On Vista however the OS endeavours to use as much free RAM as it can to cache and pre-allocate so it is possible this will help a little bit. I think the biggest myth about personal computing is that upgarding CPU and RAM makes the biggest difference. My computer at home is 4 years old and my computer at work is 6 months old. My computer at home that is 4 years old is faster in practical usage. If it came down to a number crunching war then the new computer would win but there is virtually no use case for that in personal computing.</p>
</blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/richardwilburn.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/richardwilburn.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/richardwilburn.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/richardwilburn.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/richardwilburn.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/richardwilburn.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/richardwilburn.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/richardwilburn.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/richardwilburn.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/richardwilburn.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/richardwilburn.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/richardwilburn.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/richardwilburn.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/richardwilburn.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=63&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://richardwilburn.wordpress.com/2009/03/06/boosting-visual-studio-performance/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ffe8ab5bc0cb86bd1cb53167b02529c0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rhwilburn</media:title>
		</media:content>
	</item>
		<item>
		<title>Updating an item in a list without a reference with lambdas</title>
		<link>http://richardwilburn.wordpress.com/2009/02/15/updating-an-item-in-a-list-without-a-reference-with-lambdas/</link>
		<comments>http://richardwilburn.wordpress.com/2009/02/15/updating-an-item-in-a-list-without-a-reference-with-lambdas/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 05:18:09 +0000</pubDate>
		<dc:creator>rhwilburn</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Update list reference]]></category>

		<guid isPermaLink="false">http://richardwilburn.wordpress.com/2009/02/15/updating-an-item-in-a-list-without-a-reference-with-lambdas/</guid>
		<description><![CDATA[I have to confess I am enjoying lambdas a bit much. I am making this post to show a cool way of avoiding code loops (there are still loops in CLR of course). private void UpdatePerson(Person updatedPersonObject) {     var outOfDatePerson = _people .First(person =&#62; person.Id == updatedPersonObject.Id);     int index = _people.IndexOf(outOfDatePersonObject);     _people[index] [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=61&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have to confess I am enjoying lambdas a bit much. I am making this post to show a cool way of avoiding code loops (there are still loops in CLR of course).</p>
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<pre style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">void</span> UpdatePerson(<span style="color:#2b91af;">Person</span> updatedPersonObject)</pre>
<pre style="margin:0;">{</pre>
<pre style="margin:0;">    <span style="color:blue;">var</span> outOfDatePerson = _people</pre>
<pre style="margin:0;">            .First(person =&gt; person.Id == updatedPersonObject.Id);</pre>
<pre style="margin:0;">    <span style="color:blue;">int</span> index = _people.IndexOf(outOfDatePersonObject);</pre>
<pre style="margin:0;">    _people[index] = updatedPersonObject;</pre>
<pre style="margin:0;">}</pre>
<pre style="margin:0;"></pre>
</div>
<div style="font-size:10pt;background:white;color:black;font-family:courier new;">
<pre style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">void</span> UpdatePerson_OldCSharp(<span style="color:#2b91af;">Person </span>updatedPersonObject)</pre>
<pre style="margin:0;">{</pre>
<pre style="margin:0;">    <span style="color:blue;">int</span> outOfDatePersonIndex = 0;</pre>
<pre style="margin:0;">    <span style="color:blue;">for</span> (<span style="color:blue;">int</span> i = 0; i &lt; _people.Count ; i++ )</pre>
<pre style="margin:0;">    {</pre>
<pre style="margin:0;">        <span style="color:blue;">if</span> (_people[i].Id == updatedPersonObject.Id)</pre>
<pre style="margin:0;">        {</pre>
<pre style="margin:0;">            outOfDatePersonIndex = i;</pre>
<pre style="margin:0;">            <span style="color:blue;">break</span>;</pre>
<pre style="margin:0;">        }</pre>
<pre style="margin:0;">    }</pre>
<pre style="margin:0;">    _people[outOfDatePersonIndex] = updatedPersonObject;</pre>
<pre style="margin:0;">}</pre>
</div>
<p>From the two code samples it is worth noticing the difference in the number of lines and in the hierarchical nature of the code. The traditional C# for loop approach (the second method) leads me to cringe from a maintenance point of view. Each line of code is highly contextual and relies heavily on multiple levels of language constructs.</p>
<p>The first method (the lambda way) to me is much more readable and also maintainable. There is a flat hierarchy which is much easier to read as it doesn’t involve following the loop through code. I argue it is easier to maintain as the lines can change order more and will still be doing the same thing. It is also easier to update as there is less code.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/richardwilburn.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/richardwilburn.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/richardwilburn.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/richardwilburn.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/richardwilburn.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/richardwilburn.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/richardwilburn.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/richardwilburn.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/richardwilburn.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/richardwilburn.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/richardwilburn.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/richardwilburn.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/richardwilburn.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/richardwilburn.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=richardwilburn.wordpress.com&amp;blog=4921264&amp;post=61&amp;subd=richardwilburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://richardwilburn.wordpress.com/2009/02/15/updating-an-item-in-a-list-without-a-reference-with-lambdas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ffe8ab5bc0cb86bd1cb53167b02529c0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">rhwilburn</media:title>
		</media:content>
	</item>
	</channel>
</rss>
