<?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>John Marks</title>
	<atom:link href="http://johnhmarks.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnhmarks.wordpress.com</link>
	<description>Just Another Code Monkey</description>
	<lastBuildDate>Fri, 21 Jan 2011 09:53:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='johnhmarks.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>John Marks</title>
		<link>http://johnhmarks.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://johnhmarks.wordpress.com/osd.xml" title="John Marks" />
	<atom:link rel='hub' href='http://johnhmarks.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Getting Mono.Cecil to rewrite PDB files to enable debugging</title>
		<link>http://johnhmarks.wordpress.com/2011/01/19/getting-mono-cecil-to-rewrite-pdb-files-to-enable-debugging/</link>
		<comments>http://johnhmarks.wordpress.com/2011/01/19/getting-mono-cecil-to-rewrite-pdb-files-to-enable-debugging/#comments</comments>
		<pubDate>Wed, 19 Jan 2011 16:45:54 +0000</pubDate>
		<dc:creator>johnhmarks</dc:creator>
				<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[Mono.Cecil]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://johnhmarks.wordpress.com/?p=52</guid>
		<description><![CDATA[I was asked how to get Mono.Cecil to rewrite PDB files so that VS can step through source when debugging.  Here&#8217;s an excerpt of the code I&#8217;m using to do this.  It works fine for me! var assemblyResolver = new DefaultAssemblyResolver(); var assemblyLocation = Path.GetDirectoryName(AssemblyPath); assemblyResolver.AddSearchDirectory(assemblyLocation); if (!string.IsNullOrEmpty(HintPath)) { assemblyResolver.AddSearchDirectory(HintPath); } var silverlightAssemblyPath = Environment.ExpandEnvironmentVariables(@&#8221;%ProgramFiles%\Reference [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=52&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was asked how to get Mono.Cecil to rewrite PDB files so that VS can step through source when debugging.  Here&#8217;s an excerpt of the code I&#8217;m using to do this.  It works fine for me!</p>
<p>var assemblyResolver = new DefaultAssemblyResolver();<br />
var assemblyLocation = Path.GetDirectoryName(AssemblyPath);<br />
assemblyResolver.AddSearchDirectory(assemblyLocation);<br />
if (!string.IsNullOrEmpty(HintPath))<br />
{<br />
assemblyResolver.AddSearchDirectory(HintPath);<br />
}<br />
var silverlightAssemblyPath = Environment.ExpandEnvironmentVariables(@&#8221;%ProgramFiles%\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\&#8221;);<br />
assemblyResolver.AddSearchDirectory(silverlightAssemblyPath);<br />
var readerParameters = new ReaderParameters { AssemblyResolver = assemblyResolver };<br />
var writerParameters = new WriterParameters();<br />
var pdbName = Path.ChangeExtension(AssemblyPath, &#8220;pdb&#8221;);<br />
if (File.Exists(pdbName))<br />
{<br />
var symbolReaderProvider = new PdbReaderProvider();<br />
readerParameters.SymbolReaderProvider = symbolReaderProvider;<br />
readerParameters.ReadSymbols = true;<br />
writerParameters.WriteSymbols = true;<br />
}<br />
var assemblyDefinition = AssemblyDefinition.ReadAssembly(AssemblyPath, readerParameters);<br />
var weaver = new NotifyPropertyChangedWeaver();<br />
weaver.Weave(assemblyDefinition);<br />
assemblyDefinition.Write(AssemblyPath, writerParameters);</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnhmarks.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnhmarks.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnhmarks.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnhmarks.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnhmarks.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnhmarks.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnhmarks.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnhmarks.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnhmarks.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnhmarks.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnhmarks.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnhmarks.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnhmarks.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnhmarks.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=52&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnhmarks.wordpress.com/2011/01/19/getting-mono-cecil-to-rewrite-pdb-files-to-enable-debugging/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/91dd3a69d9075a4dad05674398a0cb82?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnhmarks</media:title>
		</media:content>
	</item>
		<item>
		<title>Debugging Pain of INotifyPropertyChanged with Mono Cecil</title>
		<link>http://johnhmarks.wordpress.com/2010/12/08/debugging-pain-of-inotifypropertychanged-with-mono-cecil/</link>
		<comments>http://johnhmarks.wordpress.com/2010/12/08/debugging-pain-of-inotifypropertychanged-with-mono-cecil/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 17:48:41 +0000</pubDate>
		<dc:creator>johnhmarks</dc:creator>
				<category><![CDATA[Mono.Cecil]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://johnhmarks.wordpress.com/?p=49</guid>
		<description><![CDATA[So I officially hate my life!  I just lost a day of my life trying to get NotifyPropertyChanged weaving working with Mono.Cecil.  It worked brilliantly in .Net, but blew up in Silverlight with a VerificationException (&#8220;Operation could destabilize the runtime&#8221;) as soon as I tried to invoke my rewritten Property Setters. I literally combed through [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=49&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So I officially hate my life!  I just lost a day of my life trying to get NotifyPropertyChanged weaving working with <a href="http://www.mono-project.com/Cecil" target="_blank">Mono.Cecil</a>.  It worked brilliantly in .Net, but blew up in Silverlight with a <strong>VerificationException </strong>(&#8220;Operation could destabilize the runtime&#8221;) as soon as I tried to invoke my rewritten Property Setters.</p>
<p>I literally combed through every IL instruction in both <a href="http://www.red-gate.com/products/reflector/" target="_blank">Reflector</a> and <a href="http://msdn.microsoft.com/en-us/library/f7dy01k1(VS.80).aspx" target="_blank">ILDASM</a> and verified everything was as it should be.  In the end the issue was a peculiarity with the CoreCLR as oposed to the full blown CLR.  The CoreCLR requires all locals to be flagged as <strong><em>init</em></strong> even if play by the rules and assign to the local before reading from it.</p>
<p>Here&#8217;s the offending IL:</p>
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td colspan="2" valign="top">
<pre><span style="color:#1000a0;">.method</span> <span style="color:#1000a0;">public</span> <span style="color:#1000a0;">hidebysig</span> <span style="color:#1000a0;">specialname</span> <span style="color:#1000a0;">instance</span> <a title="void" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Void">void</a> <strong><a href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://SynerG.Weaving.Tests.Silverlight:1.0.0.0/SynerG.Weaving.Tests.DecoratedClass/set_Property(String)">set_Property</a></strong>(<a title="string" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.String">string</a> 'value')<span style="color:#1000a0;"> </span><span style="color:#1000a0;">cil</span><span style="color:#1000a0;"> </span><span style="color:#1000a0;">managed</span>
{
    <span style="color:#1000a0;">.custom</span> <span style="color:#1000a0;">instance</span> <a title="void" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Void">void</a> [<a title="mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e">mscorlib</a>]<a title="[mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Runtime.CompilerServices.CompilerGeneratedAttribute">System.Runtime.CompilerServices.CompilerGeneratedAttribute</a>::<a title=".ctor" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Runtime.CompilerServices.CompilerGeneratedAttribute/.ctor()">.ctor</a>()
    <span style="color:#1000a0;">.maxstack</span> 2
    <span style="color:#1000a0;">.locals</span> <strong><span style="color:#1000a0;">init</span> </strong>(
        [<span style="color:#800000;">0</span>] <a title="string" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.String">string</a> <strong>str</strong>,
        [<span style="color:#800000;">1</span>] <a title="bool" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Boolean">bool</a> <strong>flag</strong>)
    L_0000: <a title="nop (0x0000): Fills space if bytecodes are patched. No meaningful operation is performed although a processing cycle can be consumed.">nop</a>
    L_0001: <a title="ldarg.0 (0x0002): Loads the argument at index 0 onto the evaluation stack.">ldarg.0</a>
    L_0002: <a title="call (0x0028): Calls the method indicated by the passed method descriptor.">call</a> <span style="color:#1000a0;">instance</span> <a title="string" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.String">string</a> <a title="SynerG.Weaving.Tests.DecoratedClass" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://SynerG.Weaving.Tests.Silverlight:1.0.0.0/SynerG.Weaving.Tests.DecoratedClass">SynerG.Weaving.Tests.DecoratedClass</a>::<a title="get_Property" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://SynerG.Weaving.Tests.Silverlight:1.0.0.0/SynerG.Weaving.Tests.DecoratedClass/get_Property():String">get_Property</a>()
    L_0007: <a title="stloc.0 (0x000a): Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 0.">stloc.0</a>
    L_0008: <a title="ldarg.0 (0x0002): Loads the argument at index 0 onto the evaluation stack.">ldarg.0</a>
    L_0009: <a title="ldarg.1 (0x0003): Loads the argument at index 1 onto the evaluation stack.">ldarg.1</a>
    L_000a: <a title="stfld (0x007d): Replaces the value stored in the field of an object reference or pointer with a new value.">stfld</a> <a title="string" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.String">string</a> <a title="SynerG.Weaving.Tests.DecoratedClass" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://SynerG.Weaving.Tests.Silverlight:1.0.0.0/SynerG.Weaving.Tests.DecoratedClass">SynerG.Weaving.Tests.DecoratedClass</a>::<a title=".field &lt;Property&gt;k__BackingField" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://SynerG.Weaving.Tests.Silverlight:1.0.0.0/SynerG.Weaving.Tests.DecoratedClass/&lt;Property&gt;k__BackingField:String">&lt;Property&gt;k__BackingField</a>
    L_000f: <a title="ldarg.1 (0x0003): Loads the argument at index 1 onto the evaluation stack.">ldarg.1</a>
    L_0010: <a title="ldloc.0 (0x0006): Loads the local variable at index 0 onto the evaluation stack.">ldloc.0</a>
    L_0011: <a title="call (0x0028): Calls the method indicated by the passed method descriptor.">call</a> <a title="bool" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Boolean">bool</a> [<a title="mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e">mscorlib</a>]<a title="[mscorlib]System.Object" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Object">System.Object</a>::<a title="Equals" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Object/Equals(Object,Object):Boolean">Equals</a>(<a title="object" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Object">object</a>, <a title="object" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Object">object</a>)
    L_0016: <a title="stloc.1 (0x000b): Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 1.">stloc.1</a>
    L_0017: <a title="ldloc.1 (0x0007): Loads the local variable at index 1 onto the evaluation stack.">ldloc.1</a>
    L_0018: <a title="brtrue.s (0x002d): Transfers control to a target instruction (short form) if value is true, not null, or non-zero.">brtrue.s</a> L_0028
    L_001a: <a title="nop (0x0000): Fills space if bytecodes are patched. No meaningful operation is performed although a processing cycle can be consumed.">nop</a>
    L_001b: <a title="ldarg.0 (0x0002): Loads the argument at index 0 onto the evaluation stack.">ldarg.0</a>
    L_001c: <a title="ldstr (0x0072): Pushes a new object reference to a string literal stored in the metadata.">ldstr</a> <span style="color:#800000;">"Property"</span>
    L_0021: <a title="callvirt (0x006f): Calls a late-bound method on an object, pushing the return value onto the evaluation stack.">callvirt</a> <span style="color:#1000a0;">instance</span> <a title="void" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.Void">void</a> [<a title="SynerG.Silverlight, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://SynerG.Silverlight">SynerG.Silverlight</a>]<a title="[SynerG.Silverlight]SynerG.Notification.NotifyingBase" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://SynerG.Silverlight/SynerG.Notification.NotifyingBase">SynerG.Notification.NotifyingBase</a>::<a title="OnPropertyChanged" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://SynerG.Silverlight/SynerG.Notification.NotifyingBase/OnPropertyChanged(String)">OnPropertyChanged</a>(<a title="string" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.5.0:7cec85d7bea7798e/System.String">string</a>)
    L_0026: <a title="nop (0x0000): Fills space if bytecodes are patched. No meaningful operation is performed although a processing cycle can be consumed.">nop</a>
    L_0027: <a title="nop (0x0000): Fills space if bytecodes are patched. No meaningful operation is performed although a processing cycle can be consumed.">nop</a>
    L_0028: <a title="ret (0x002a): Returns from the current method, pushing a return value (if present) from the caller's evaluation stack onto the callee's evaluation stack.">ret</a>
}</pre>
</td>
</tr>
</tbody>
</table>
<p> You can fix this with a cheeky:</p>
<p>methodBody.InitLocals = true;</p>
<p>Phew.  That&#8217;s a day of my life that I&#8217;m never going to get back again!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnhmarks.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnhmarks.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnhmarks.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnhmarks.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnhmarks.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnhmarks.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnhmarks.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnhmarks.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnhmarks.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnhmarks.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnhmarks.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnhmarks.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnhmarks.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnhmarks.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=49&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnhmarks.wordpress.com/2010/12/08/debugging-pain-of-inotifypropertychanged-with-mono-cecil/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/91dd3a69d9075a4dad05674398a0cb82?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnhmarks</media:title>
		</media:content>
	</item>
		<item>
		<title>INotifyPropertyChanged Weaving</title>
		<link>http://johnhmarks.wordpress.com/2010/12/02/inotifypropertychanged-weaving/</link>
		<comments>http://johnhmarks.wordpress.com/2010/12/02/inotifypropertychanged-weaving/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 14:27:52 +0000</pubDate>
		<dc:creator>johnhmarks</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://johnhmarks.wordpress.com/?p=43</guid>
		<description><![CDATA[A common gripe with WPF and Silverlight development is having to implement INotifyPropertyChanged in your Models and ViewModels. You then have to remember (most of the time) to fire the PropertyChanged event whenever you change a property. On the project I&#8217;m working on we&#8217;ve been using PostSharp for a while to automatically weave in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=43&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A common gripe with WPF and Silverlight development is having to implement INotifyPropertyChanged in your Models and ViewModels. You then have to remember (most of the time) to fire the PropertyChanged event whenever you change a property.</p>
<p>On the project I&#8217;m working on we&#8217;ve been using <a href="http://www.sharpcrafters.com/">PostSharp </a>for a while to automatically weave in the code to do this for us. The other day I set about converting our app to .Net 4 and Silverlight 4. Sadly, the version of PostSharp we were using (1.5) doesn&#8217;t play nicely with .Net 4. Fine I thought, I&#8217;ll simple update to version 2.0. I then found out that the functionality we need is only available in the licensed version. Although PostSharp is a great product, we only use it for this exact problem and it doesn&#8217;t justify forking out for a license for all the devs on my team.</p>
<p>So I decided to set out weaving in the IL myself. I tried various different methods including Microsoft&#8217;s <a href="http://ccimetadata.codeplex.com/">CCI</a> and <a href="http://ccisamples.codeplex.com/wikipage?title=CciSharp&amp;referringTitle=Home">CciSharp</a>. I found these to be very powerful, but fiendishly complicated. Then I tried out <a href="http://www.mono-project.com/Cecil">Mono.Cecil</a>. This is a fantastic bit of software and is very easy to use.</p>
<p>I stumbled upon a great <a href="http://justinangel.net/AutomagicallyImplementingINotifyPropertyChanged">blog post</a> by Justin Angel. It describes exactly how you can achieve this using Mono.Cecil. The only problem is that if you rewrite a silverlight application assembly in the AfterBuild Target as Justin describes, the XAP file generated contains the DLL before the rewrite and therefore doesn&#8217;t work.</p>
<p>I managed to get around this problem by hacking my .csproj file thusly:</p>
<p>  &lt;UsingTask TaskName=&#8221;CecilPropertyChanged.MSBuild.WeaveNotifyPropertyChangedTask&#8221; AssemblyFile=&#8221;$(SolutionDir)Lib\CecilPropertyChanged.MSBuild.dll&#8221; /&gt;<br />
  &lt;Target Name=&#8221;WeaveNotifyPropertyChanged&#8221;&gt;<br />
    &lt;CecilPropertyChanged.MSBuild.WeaveNotifyPropertyChangedTask AssemblyPath=&#8221;$(IntermediateOutputPath)$(AssemblyName).dll&#8221; /&gt;<br />
    &lt;Copy SourceFiles=&#8221;$(IntermediateOutputPath)$(AssemblyName).dll&#8221; DestinationFolder=&#8221;$(OutputPath)&#8221; /&gt;<br />
  &lt;/Target&gt;</p>
<p>  &lt;PropertyGroup&gt;<br />
    &lt;XapPackagerDependsOn&gt;<br />
      _CreateSLProperties;<br />
      MarkupCompilePass1;<br />
      ValidateXaml;<br />
      WeaveNotifyPropertyChanged;<br />
      FilesToXap;<br />
      CreateSilverlightAppManifest;<br />
    &lt;/XapPackagerDependsOn&gt;<br />
  &lt;/PropertyGroup&gt;</p>
<p>Works like a charm!</p>
<div id="_mcePaste" class="mcePaste" style="position:absolute;width:1px;height:1px;overflow:hidden;top:0;left:-10000px;">﻿</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnhmarks.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnhmarks.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnhmarks.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnhmarks.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnhmarks.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnhmarks.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnhmarks.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnhmarks.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnhmarks.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnhmarks.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnhmarks.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnhmarks.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnhmarks.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnhmarks.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=43&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnhmarks.wordpress.com/2010/12/02/inotifypropertychanged-weaving/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/91dd3a69d9075a4dad05674398a0cb82?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnhmarks</media:title>
		</media:content>
	</item>
		<item>
		<title>Regionerate Rocks!</title>
		<link>http://johnhmarks.wordpress.com/2009/09/15/regionerate-rocks/</link>
		<comments>http://johnhmarks.wordpress.com/2009/09/15/regionerate-rocks/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 17:31:26 +0000</pubDate>
		<dc:creator>johnhmarks</dc:creator>
				<category><![CDATA[Regionerate]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://johnhmarks.wordpress.com/?p=39</guid>
		<description><![CDATA[I&#8217;ve just stumbled across Regionerate.  It&#8217;s a fantastic little tool that automatically applies regions to C# code.  For a code nazi like me this is invaluable and will likely spare me from RSI and lifetime of misery! I also wrote a custom configuration file that matches my particular form of OCD (obsessive code disorder):<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=39&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just stumbled across <a href="http://www.rauchy.net/regionerate/">Regionerate</a>.  It&#8217;s a fantastic little tool that automatically applies regions to C# code.  For a code nazi like me this is invaluable and will likely spare me from RSI and lifetime of misery!</p>
<p>I also wrote a custom configuration file that matches my particular form of OCD (obsessive code disorder):<br />
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;
&lt;CodeLayout xmlns=&quot;http://regionerate.net/schemas/0.7.0.0/CodeLayout.xsd&quot;&gt;
  &lt;ForEach Type=&quot;Class&quot;&gt;
    &lt;CreateRegion Title=&quot;Public Static Fields&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutFields&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;true&quot;/&gt;
          &lt;Access Equals=&quot;Public&quot; /&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutFields&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Internal Static Fields&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutFields&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;true&quot;/&gt;
          &lt;Access Equals=&quot;Internal&quot; /&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutFields&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Protected Static Fields&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutFields&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;true&quot;/&gt;
          &lt;Access Equals=&quot;Protected&quot; /&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutFields&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Private Static Fields&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutFields&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;true&quot;/&gt;
          &lt;Access Equals=&quot;Private&quot; /&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutFields&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Public Fields&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutFields&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;false&quot;/&gt;
          &lt;Access Equals=&quot;Public&quot; /&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutFields&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Internal Fields&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutFields&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;false&quot;/&gt;
          &lt;Access Equals=&quot;Internal&quot; /&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutFields&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Protected Fields&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutFields&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;false&quot;/&gt;
          &lt;Access Equals=&quot;Protected&quot; /&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutFields&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Private Fields&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutFields&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;false&quot;/&gt;
          &lt;Access Equals=&quot;Private&quot; /&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutFields&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Static Ctor&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutMethods&gt;
        &lt;Where&gt;
          &lt;IsConstructor Equals=&quot;true&quot; /&gt;
          &lt;Static Equals=&quot;true&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;ParametersCount /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutMethods&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Ctor&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutMethods&gt;
        &lt;Where&gt;
          &lt;IsConstructor Equals=&quot;true&quot; /&gt;
          &lt;Static Equals=&quot;false&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;ParametersCount /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutMethods&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Public Static Methods&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutMethods&gt;
        &lt;Where&gt;
          &lt;IsConstructor Equals=&quot;false&quot; /&gt;
          &lt;Static Equals=&quot;true&quot; /&gt;
          &lt;Access Equals=&quot;Public&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;ParametersCount /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutMethods&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Internal Static Methods&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutMethods&gt;
        &lt;Where&gt;
          &lt;IsConstructor Equals=&quot;false&quot; /&gt;
          &lt;Static Equals=&quot;true&quot; /&gt;
          &lt;Access Equals=&quot;Internal&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;ParametersCount /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutMethods&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Protected Static Methods&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutMethods&gt;
        &lt;Where&gt;
          &lt;IsConstructor Equals=&quot;false&quot; /&gt;
          &lt;Static Equals=&quot;true&quot; /&gt;
          &lt;Access Equals=&quot;Protected&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;ParametersCount /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutMethods&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Private Static Methods&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutMethods&gt;
        &lt;Where&gt;
          &lt;IsConstructor Equals=&quot;false&quot; /&gt;
          &lt;Static Equals=&quot;true&quot; /&gt;
          &lt;Access Equals=&quot;Private&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;ParametersCount /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutMethods&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Public Methods&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutMethods&gt;
        &lt;Where&gt;
          &lt;IsConstructor Equals=&quot;false&quot; /&gt;
          &lt;Static Equals=&quot;false&quot; /&gt;
          &lt;Access Equals=&quot;Public&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;ParametersCount /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutMethods&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Internal Methods&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutMethods&gt;
        &lt;Where&gt;
          &lt;IsConstructor Equals=&quot;false&quot; /&gt;
          &lt;Static Equals=&quot;false&quot; /&gt;
          &lt;Access Equals=&quot;Internal&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;ParametersCount /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutMethods&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Protected Methods&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutMethods&gt;
        &lt;Where&gt;
          &lt;IsConstructor Equals=&quot;false&quot; /&gt;
          &lt;Static Equals=&quot;false&quot; /&gt;
          &lt;Access Equals=&quot;Protected&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;ParametersCount /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutMethods&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Private Methods&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutMethods&gt;
        &lt;Where&gt;
          &lt;IsConstructor Equals=&quot;false&quot; /&gt;
          &lt;Static Equals=&quot;false&quot; /&gt;
          &lt;Access Equals=&quot;Private&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;ParametersCount /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutMethods&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Events&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutEvents&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutEvents&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Public Static Properties&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutProperties&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;true&quot; /&gt;
          &lt;Access Equals=&quot;Public&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutProperties&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Internal Static Properties&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutProperties&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;true&quot; /&gt;
          &lt;Access Equals=&quot;Internal&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutProperties&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Protected Static Properties&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutProperties&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;true&quot; /&gt;
          &lt;Access Equals=&quot;Protected&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutProperties&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Private Static Properties&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutProperties&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;true&quot; /&gt;
          &lt;Access Equals=&quot;Private&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutProperties&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Public Properties&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutProperties&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;false&quot; /&gt;
          &lt;Access Equals=&quot;Public&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutProperties&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Internal Properties&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutProperties&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;false&quot; /&gt;
          &lt;Access Equals=&quot;Internal&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutProperties&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Protected Properties&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutProperties&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;false&quot; /&gt;
          &lt;Access Equals=&quot;Protected&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutProperties&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Private Properties&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutProperties&gt;
        &lt;Where&gt;
          &lt;Static Equals=&quot;false&quot; /&gt;
          &lt;Access Equals=&quot;Private&quot;/&gt;
        &lt;/Where&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutProperties&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Delegates&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutDelegates&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutDelegates&gt;
    &lt;/CreateRegion&gt;
    &lt;CreateRegion Title=&quot;Nested Classes&quot; PadFirstChild=&quot;0&quot; PadLastChild=&quot;0&quot; ShowCount=&quot;false&quot; Style=&quot;Visible&quot;&gt;
      &lt;PutNestedClasses&gt;
        &lt;OrderBy&gt;
          &lt;Name /&gt;
        &lt;/OrderBy&gt;
      &lt;/PutNestedClasses&gt;
    &lt;/CreateRegion&gt;
  &lt;/ForEach&gt;
  &lt;Configuration&gt;
    &lt;Symbol&gt;
      &lt;HiddenDragon /&gt;
    &lt;/Symbol&gt;
    &lt;Rendering ShowCount=&quot;false&quot; /&gt;
  &lt;/Configuration&gt;
&lt;/CodeLayout&gt;
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnhmarks.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnhmarks.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnhmarks.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnhmarks.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnhmarks.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnhmarks.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnhmarks.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnhmarks.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnhmarks.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnhmarks.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnhmarks.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnhmarks.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnhmarks.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnhmarks.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=39&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnhmarks.wordpress.com/2009/09/15/regionerate-rocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/91dd3a69d9075a4dad05674398a0cb82?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnhmarks</media:title>
		</media:content>
	</item>
		<item>
		<title>Hot-swappable Themes in Silverlight</title>
		<link>http://johnhmarks.wordpress.com/2009/09/14/hot-swappable-themes-in-silverlight/</link>
		<comments>http://johnhmarks.wordpress.com/2009/09/14/hot-swappable-themes-in-silverlight/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 16:04:36 +0000</pubDate>
		<dc:creator>johnhmarks</dc:creator>
				<category><![CDATA[Prism]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Theming]]></category>

		<guid isPermaLink="false">http://johnhmarks.wordpress.com/?p=33</guid>
		<description><![CDATA[I&#8217;ve been playing around with hot-swapping themes in Silverlight recently. This turns out to be trickier than you might imagine due to a couple of facts: Silverlight doesn&#8217;t support DynamicResources Silverlight doesn&#8217;t support implicit styles And no, I don&#8217;t count the ImplicitStyleManager in the SilverlightToolkit as it&#8217;s buggy and performs like a dog. At any [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=33&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with hot-swapping themes in Silverlight recently. This turns out to be trickier than you might imagine due to a couple of facts:</p>
<ul>
<li>Silverlight doesn&#8217;t support DynamicResources</li>
<li>Silverlight doesn&#8217;t support implicit styles</li>
</ul>
<p>And no, I don&#8217;t count the ImplicitStyleManager in the SilverlightToolkit as it&#8217;s buggy and performs like a dog. At any rate, implicit styles soon become completely unmanageable in an application of any considerable size.<br />
The solution I came up with was to have a ThemingService that automatically applies Styles to FrameworkElements. The FrameworkElements register themselves with the ThemingService by setting an attached StyleKey dependency property. The ThemingService then maintains a WeakReference to the FrameworkElement and simply walks down the list of registered elements whenever a new theme is applied.</p>
<p><pre class="brush: csharp;">

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Threading;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Logging;
using Microsoft.Practices.Composite.Presentation.Events;
using ThemingPlay.Core.Configuration;

namespace ThemingPlay.Core.Theming
{
    public class ThemingService : IThemingService
    {
        #region Private Fields
        private readonly IConfigurationService _configurationService;
        private readonly ConfigurationLoadedEvent _configurationLoadedEvent;
        private readonly ThemesLoadedEvent _themesLoadedEvent;
        private readonly ThemeChangedEvent _themeChangedEvent;
        private readonly ILoggerFacade _logger;
        private readonly Dispatcher _dispatcher;

        private readonly IList&lt;WeakReference&gt; _elementReferences;
        private readonly IList&lt;Theme&gt; _themes;
        private Theme _currentTheme;
        #endregion

        #region Ctor
        public ThemingService(IConfigurationService configurationService,
                              IEventAggregator eventAggregator, Dispatcher dispatcher, ILoggerFacade logger)
        {
            _configurationService = configurationService;
            _configurationLoadedEvent = eventAggregator.GetEvent&lt;ConfigurationLoadedEvent&gt;();
            _configurationLoadedEvent.Subscribe(OnConfigurationLoaded, ThreadOption.UIThread);
            _themesLoadedEvent = eventAggregator.GetEvent&lt;ThemesLoadedEvent&gt;();
            _themeChangedEvent = eventAggregator.GetEvent&lt;ThemeChangedEvent&gt;();
            _dispatcher = dispatcher;
            _logger = logger;
            
            _elementReferences = new List&lt;WeakReference&gt;();
            _themes = new List&lt;Theme&gt;();
        }
        #endregion

        #region Dependency Properties
        public static readonly DependencyProperty StyleKeyProperty = DependencyProperty.RegisterAttached(
            &quot;StyleKey&quot;, typeof (string), typeof (ThemingService),
            new PropertyMetadata(OnStyleKeyChanged));

        public static void SetStyleKey(FrameworkElement element, string styleKey)
        {
            element.SetValue(StyleKeyProperty, styleKey);
        }

        public static string GetStyleKey(FrameworkElement element)
        {
            return element.GetValue(StyleKeyProperty) as string;
        }

        private static void OnStyleKeyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var styledElement = (FrameworkElement) d;
            var themingService = SingletonContainer.Instance.Resolve&lt;IThemingService&gt;();
            themingService.RegisterThemedElement(styledElement);
        }
        #endregion

        #region Implementation of IThemingService
        public IList&lt;Theme&gt; Themes
        {
            get { return _themes; }
        }

        public Theme CurrentTheme
        {
            get { return _currentTheme; }
            set
            {
                _currentTheme = value;
                SwitchToTheme(_currentTheme);
                _themeChangedEvent.Publish(_currentTheme);
            }
        }

        public void RegisterThemedElement(FrameworkElement element)
        {
            _elementReferences.Add(new WeakReference(element));
            if (_currentTheme != null &amp;&amp; _currentTheme.ResourceDictionary != null)
            {
                ApplyStyleToElement(_currentTheme.ResourceDictionary, element);
            }
        }
        #endregion

        #region Composite Event Handlers
        public void OnConfigurationLoaded(object nothing)
        {
            LoadThemesFromConfiguration();
        }
        #endregion

        #region Private Methods
        private void LoadThemesFromConfiguration()
        {
            var themesConfig = _configurationService[THEMES_CONFIGURATION_SECTION] as ThemesConfigurationSection;
            if (themesConfig != null)
            {
                foreach (var themeConfig in themesConfig.Themes)
                {
                    var theme = CreateTheme(themeConfig);
                    _themes.Add(theme);
                }
                var defaultTheme = (from t in _themes where t.Name == themesConfig.DefaultTheme select t).SingleOrDefault();
                if (defaultTheme != null)
                {
                    this.CurrentTheme = defaultTheme;
                }
                _themesLoadedEvent.Publish(_themes);
            }
        }

        private static Theme CreateTheme(ThemeConfigurationElement themeConfig)
        {
            var theme = new Theme
                        {
                            Name = themeConfig.Name,
                            Description = themeConfig.Description,
                            DictionaryUri = new Uri(themeConfig.DictionaryUri, UriKind.Relative),
                            PackageUri = UriHelper.AbsoluteUriFromRelativePath(themeConfig.PackageUri)
                        };
            return theme;
        }

        private void LoadCurrentThemeAsync(Theme theme)
        {
            var request = WebRequest.Create(theme.PackageUri);
            request.BeginGetResponse(result =&gt; _dispatcher.BeginInvoke(()=&gt;
               {
                   try
                   {
                       var response = request.EndGetResponse(result);
                       using (var stream = response.GetResponseStream())
                       {
                           var assemblyParts = XapHelper.GetAssemblyParts(stream);
                           if (assemblyParts.Count == 1)
                           {
                               var assemblyPart = assemblyParts[0];
                               if (XapHelper.LoadAssemblyFromStream(stream, assemblyPart) != null)
                               {
                                   var sri = Application.GetResourceStream(theme.DictionaryUri);
                                   using (var xamlStream = sri.Stream)
                                   {
                                       using (var reader = new StreamReader(xamlStream))
                                       {
                                           var xaml = reader.ReadToEnd();
                                           var resourceDictionary = XamlReader.Load(xaml) as ResourceDictionary;
                                           if (resourceDictionary != null)
                                           {
                                               theme.ResourceDictionary = resourceDictionary;
                                               ApplyTheme(theme);
                                           }
                                       }
                                   }
                               }
                           }
                       }
                   }
                   catch (Exception ex)
                   {
                       _logger.Log(ex.Message, Category.Exception, Priority.High);
                   }
               }), null);
        }

        private void SwitchToTheme(Theme theme)
        {
            if (theme.ResourceDictionary != null)
            {
                ApplyTheme(theme);
            }
            else
            {
                LoadCurrentThemeAsync(theme);
            }
        }

        private void ApplyTheme(Theme theme)
        {
            ICollection&lt;WeakReference&gt; deadElements = null;
            foreach (var elementReference in _elementReferences)
            {
                if (elementReference.IsAlive)
                {
                    var styledElement = elementReference.Target as FrameworkElement;
                    if (styledElement != null)
                    {
                        ApplyStyleToElement(theme.ResourceDictionary, styledElement);
                    }
                }
                else
                {
                    if (deadElements == null)
                    {
                        deadElements = new List&lt;WeakReference&gt;();
                    }
                    deadElements.Add(elementReference);
                }
            }
            if (deadElements != null)
            {
                foreach (var deadElement in deadElements)
                {
                    _elementReferences.Remove(deadElement);
                }
            }
        }

        private void ApplyStyleToElement(ResourceDictionary resourceDictionary, FrameworkElement element)
        {
            var styleKey = GetStyleKey(element);
            if (!string.IsNullOrEmpty(styleKey))
            {
                if (resourceDictionary.Contains(styleKey))
                {
                    var style = resourceDictionary[styleKey] as Style;
                    if (style != null)
                    {
                        try
                        {
                            element.Style = style;
                        }
                        catch (Exception ex)
                        {
                            _logger.Log(ex.Message, Category.Exception, Priority.High);
                        }
                    }
                }
            }
        }
        #endregion

        #region Constants
        private static readonly string THEMES_CONFIGURATION_SECTION = &quot;themes&quot;;
        #endregion
    }
}
</pre></p>
<p>There&#8217;s loads of other code in here to do with Prism and downloading the Themes dynamically, but you get the point&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnhmarks.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnhmarks.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnhmarks.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnhmarks.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnhmarks.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnhmarks.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnhmarks.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnhmarks.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnhmarks.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnhmarks.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnhmarks.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnhmarks.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnhmarks.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnhmarks.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=33&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnhmarks.wordpress.com/2009/09/14/hot-swappable-themes-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/91dd3a69d9075a4dad05674398a0cb82?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnhmarks</media:title>
		</media:content>
	</item>
		<item>
		<title>Deep linking in Silverlight application</title>
		<link>http://johnhmarks.wordpress.com/2009/09/03/deep-linking-in-silverlight-application/</link>
		<comments>http://johnhmarks.wordpress.com/2009/09/03/deep-linking-in-silverlight-application/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 11:15:35 +0000</pubDate>
		<dc:creator>johnhmarks</dc:creator>
				<category><![CDATA[Navigation Framework]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://johnhmarks.wordpress.com/?p=31</guid>
		<description><![CDATA[Often you want to do deep linking in Silverlight without going the whole hog and using the new Navigation Framework. Not that the Navigation Framework is bad, but it does impose a architecture on your application that you may not want to follow. Instead you can use the HtmlPage.Window.CurrentBookmark to store an arbitrary string. This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=31&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Often you want to do deep linking in Silverlight without going the whole hog and using the new <a href="http://www.silverlightshow.net/items/The-Silverlight-3-Navigation-Framework.aspx">Navigation Framework</a>.  Not that the Navigation Framework is bad, but it does impose a architecture on your application that you may not want to follow.</p>
<p>Instead you can use the HtmlPage.Window.CurrentBookmark to store an arbitrary string.  This will change the address in the browser by appending the string as a hash code or anchor.  This is great as you can now bookmark the URL by hitting Ctrl+D.  Only problem is if a user selects a bookmark while you application is still running then there&#8217;s no obvious way to detect the change.</p>
<p>I found a couple of blog entries suggesing ways to do this.  One suggested polling on a timer to check for the change.  Another used a bunch of JavaScript and didn&#8217;t work.  As you can imagine, neither of these is a great option.  Finally after hours of googling I found that you can do:</p>
<p>HtmlPage.Window.AttachEvent(&#8220;onhashchange&#8221;, new EventHandler(OnHashChange));</p>
<p>Works like a charm!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnhmarks.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnhmarks.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnhmarks.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnhmarks.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnhmarks.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnhmarks.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnhmarks.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnhmarks.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnhmarks.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnhmarks.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnhmarks.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnhmarks.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnhmarks.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnhmarks.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=31&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnhmarks.wordpress.com/2009/09/03/deep-linking-in-silverlight-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/91dd3a69d9075a4dad05674398a0cb82?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnhmarks</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight Web Request on Application Exit</title>
		<link>http://johnhmarks.wordpress.com/2009/08/17/silverlight-web-request-on-application-exit/</link>
		<comments>http://johnhmarks.wordpress.com/2009/08/17/silverlight-web-request-on-application-exit/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 14:58:00 +0000</pubDate>
		<dc:creator>johnhmarks</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://johnhmarks.wordpress.com/?p=28</guid>
		<description><![CDATA[I was just looking into persisting the state of a Silverlight application on exit. The scenario is that the application has a complex layout that we normally persist to a database via a RESTful service call. The problem is what if the user forgets to explicitly save the layout before shutting the browser down. So [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=28&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was just looking into persisting the state of a Silverlight application on exit.  The scenario is that the application has a complex layout that we normally persist to a database via a RESTful service call.  The problem is what if the user forgets to explicitly save the layout before shutting the browser down.  So I looked into calling the service in the Application_Exit method in the App class.  Sadly this does not work &#8211; it appears that the request is queued on the Dispatcher thread after the shutdown process and so never executes.  Guess I&#8217;ll have to save the state to isolated storage and put some hacky code in to determine if there is a saved state in ISO before loading the layout from the DB.  Bit of a bummer if the user uses more than one machine though&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnhmarks.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnhmarks.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnhmarks.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnhmarks.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnhmarks.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnhmarks.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnhmarks.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnhmarks.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnhmarks.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnhmarks.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnhmarks.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnhmarks.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnhmarks.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnhmarks.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=28&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnhmarks.wordpress.com/2009/08/17/silverlight-web-request-on-application-exit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/91dd3a69d9075a4dad05674398a0cb82?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnhmarks</media:title>
		</media:content>
	</item>
		<item>
		<title>Playing Around with System.Reactive Again</title>
		<link>http://johnhmarks.wordpress.com/2009/08/17/playing-around-with-system-reactive-again/</link>
		<comments>http://johnhmarks.wordpress.com/2009/08/17/playing-around-with-system-reactive-again/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 09:00:47 +0000</pubDate>
		<dc:creator>johnhmarks</dc:creator>
				<category><![CDATA[Lambda Expressions]]></category>
		<category><![CDATA[Reactive Framework]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://johnhmarks.wordpress.com/?p=26</guid>
		<description><![CDATA[Further to my previous post, Erik Meijer commented that an overload to the FromEvent method is available to convert from generic event handlers to the specific ones used by much of the BCL. So the code from the previous post would look something like this now: This solves one of my major gripes. Exciting times!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=26&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Further to my previous <a href="http://johnhmarks.wordpress.com/2009/08/04/playing-around-with-system-reactive-in-silverlight/" target="_blank">post</a>, Erik Meijer commented that an overload to the FromEvent method is available to convert from generic event handlers to the specific ones used by much of the BCL.  So the code from the previous post would look something like this now:</p>
<p><pre class="brush: csharp;">
        #region Ctor
        public MainPage()
        {
            InitializeComponent();

            var mouseEventSource = Observable.FromEvent&lt;MouseEventHandler, MouseEventArgs&gt;(
                eh =&gt; new MouseEventHandler(eh),    // Conversion
                eh =&gt; this.MouseMove += eh,         // Subscribe
                eh =&gt; this.MouseMove -= eh);        // Unsubscribe

            _mouseMoveSubscription = mouseEventSource.Subscribe(OnMouseMove);
        }
        #endregion

        private void OnMouseMove(Event&lt;MouseEventArgs&gt; e)
        {
            var position = e.EventArgs.GetPosition(this);

            Debug.WriteLine(&quot;Mouse moved.  Position: {0}.&quot;, position);
        }
</pre></p>
<p>This solves one of my major gripes.  Exciting times!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnhmarks.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnhmarks.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnhmarks.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnhmarks.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnhmarks.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnhmarks.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnhmarks.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnhmarks.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnhmarks.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnhmarks.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnhmarks.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnhmarks.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnhmarks.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnhmarks.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=26&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnhmarks.wordpress.com/2009/08/17/playing-around-with-system-reactive-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/91dd3a69d9075a4dad05674398a0cb82?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnhmarks</media:title>
		</media:content>
	</item>
		<item>
		<title>A base class for Domain Models</title>
		<link>http://johnhmarks.wordpress.com/2009/08/14/a-base-class-for-domain-models/</link>
		<comments>http://johnhmarks.wordpress.com/2009/08/14/a-base-class-for-domain-models/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 16:49:16 +0000</pubDate>
		<dc:creator>johnhmarks</dc:creator>
				<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[Lambda Expressions]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://johnhmarks.wordpress.com/?p=22</guid>
		<description><![CDATA[I just wrote a base class that I&#8217;m going to derive all of my notifying Domain Models from. It solves the horror of passing around the property name of a changing property in the INotifyPropertyChanged implementation. This has the enormous benefit of being able to check your Property Names at compile-time and also allows you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=22&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just wrote a base class that I&#8217;m going to derive all of my notifying Domain Models from.  It solves the horror of passing around the property name of a changing property in the INotifyPropertyChanged implementation.  This has the enormous benefit of being able to check your Property Names at compile-time and also allows you to keep everything in sync when using tools like Resharper (if you don&#8217;t use Resharper &#8211; then you really should!) to rename things.  It uses lambda expressions to specify the Property that&#8217;s changing.</p>
<p><pre class="brush: csharp;">
    public abstract class ModelBase&lt;T&gt; : INotifyPropertyChanged where T : ModelBase&lt;T&gt;
    {
        #region Events
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        #region Public Methods
        public static string GetPropertyName&lt;R&gt;(Expression&lt;Func&lt;T, R&gt;&gt; expression)
        {
            var memberExpression = expression.Body as MemberExpression;
            if (memberExpression == null)
            {
                throw new ArgumentException(&quot;'expression' should be a member expression&quot;);
            }
            var propertyName = memberExpression.Member.Name;
            return propertyName;
        }
        #endregion

        #region Protected Methods
        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        
        protected void RaisePropertyChanged&lt;R&gt;(Expression&lt;Func&lt;T, R&gt;&gt; expression)
        {
            var propertyName = GetPropertyName(expression);
            this.OnPropertyChanged(propertyName);
        }
        #endregion
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnhmarks.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnhmarks.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnhmarks.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnhmarks.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnhmarks.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnhmarks.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnhmarks.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnhmarks.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnhmarks.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnhmarks.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnhmarks.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnhmarks.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnhmarks.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnhmarks.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=22&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnhmarks.wordpress.com/2009/08/14/a-base-class-for-domain-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/91dd3a69d9075a4dad05674398a0cb82?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnhmarks</media:title>
		</media:content>
	</item>
		<item>
		<title>Weak INotifyPropertyChanged and INotifyCollectionChanged Listeners</title>
		<link>http://johnhmarks.wordpress.com/2009/08/14/weak-inotifypropertychanged-and-inotifycollectionchanged-listeners/</link>
		<comments>http://johnhmarks.wordpress.com/2009/08/14/weak-inotifypropertychanged-and-inotifycollectionchanged-listeners/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 15:23:39 +0000</pubDate>
		<dc:creator>johnhmarks</dc:creator>
				<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://johnhmarks.wordpress.com/?p=12</guid>
		<description><![CDATA[Following on from my woes about ObservableCollection&#60;T&#62;, and my annoyance at having to maintain a parallel collection to ensure all INotifyPropertyChanged and INotifyCollectionChanged subscriptions are removed, I decided to look down the avenue of Weak event subscriptions.  To that end I can up with the classes WeakPropertyChangedListner and WeakCollectionChangedListener.  The code for these is as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=12&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Following on from my <a href="http://johnhmarks.wordpress.com/2009/08/12/annoyances-with-observablecollection/" target="_blank">woes about ObservableCollection&lt;T&gt;</a>, and my annoyance at having to maintain a parallel collection to ensure all INotifyPropertyChanged and INotifyCollectionChanged subscriptions are removed, I decided to look down the avenue of Weak event subscriptions.  To that end I can up with the classes WeakPropertyChangedListner and WeakCollectionChangedListener.  The code for these is as follows:</p>
<p> <br />
<pre class="brush: csharp;">
    public class WeakPropertyChangedListener
    {
        #region Private Fields
        private INotifyPropertyChanged _source;
        private WeakReference _listener;
        #endregion

        #region Ctor
        public WeakPropertyChangedListener(INotifyPropertyChanged source, PropertyChangedEventHandler listener)
        {
            this._source = source;
            this._source.PropertyChanged += this.OnPropertyChanged;
            this._listener = new WeakReference(listener);
        }
        #endregion

        #region Public Methods
        public static WeakPropertyChangedListener Create(INotifyPropertyChanged source, PropertyChangedEventHandler listener)
        {
            return new WeakPropertyChangedListener(source, listener);
        }

        public void Disconnect()
        {
            if (_source != null)
            {
                _source.PropertyChanged -= this.OnPropertyChanged;
                _source = null;
                _listener = null;
            }
        }
        #endregion

        #region Private Methods
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (_listener != null)
            {
                var handler = _listener.Target as PropertyChangedEventHandler;
                if (handler != null)
                {
                    handler(sender, e);
                }
                else
                {
                    this.Disconnect();
                }
            }
        }
        #endregion
    }
</pre></p>
<p>and:</p>
<p><pre class="brush: csharp;">
    public class WeakCollectionChangedListener
    {
        #region Private Fields
        private INotifyCollectionChanged _source;
        private WeakReference _handler;
        #endregion

        #region Ctor
        public WeakCollectionChangedListener(INotifyCollectionChanged source, NotifyCollectionChangedEventHandler handler)
        {
            this._source = source;
            this._source.CollectionChanged += this.OnCollectionChanged;
            this._handler = new WeakReference(handler);
        }
        #endregion

        #region Public Methods
        public static WeakCollectionChangedListener Create(INotifyCollectionChanged source, NotifyCollectionChangedEventHandler handler)
        {
            return new WeakCollectionChangedListener(source, handler);
        }

        public void Disconnect()
        {
            if (_source != null)
            {
                _source.CollectionChanged -= this.OnCollectionChanged;
                _source = null;
                _handler = null;
            }
        }
        #endregion

        #region Private Methods
        private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (_handler != null)
            {
                var handler = _handler.Target as NotifyCollectionChangedEventHandler;
                if (handler != null)
                {
                    handler(sender, e);
                }
                else
                {
                    this.Disconnect();
                }
            }
        }
        #endregion
    }
</pre></p>
<p> Then you simple subscribe like this:</p>
<p><pre class="brush: csharp;">
WeakPropertyChangedListener.Create(person, OnPersonPropertyChanged);

WeakCollectionChangedListener.Create(person.Children, OnPersonCollectionChanged);
</pre></p>
<p>Safe in the knowledge that your observing the notifications will not cause your domain objects to hang around.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnhmarks.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnhmarks.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnhmarks.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnhmarks.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/johnhmarks.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/johnhmarks.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/johnhmarks.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/johnhmarks.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnhmarks.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnhmarks.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnhmarks.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnhmarks.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnhmarks.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnhmarks.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=johnhmarks.wordpress.com&amp;blog=8864154&amp;post=12&amp;subd=johnhmarks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://johnhmarks.wordpress.com/2009/08/14/weak-inotifypropertychanged-and-inotifycollectionchanged-listeners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/91dd3a69d9075a4dad05674398a0cb82?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">johnhmarks</media:title>
		</media:content>
	</item>
	</channel>
</rss>
