<?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>Denis Vuyka</title>
	<atom:link href="http://denisvuyka.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://denisvuyka.wordpress.com</link>
	<description>WPF and Silverlight</description>
	<lastBuildDate>Tue, 01 Nov 2011 20:17:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='denisvuyka.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Denis Vuyka</title>
		<link>http://denisvuyka.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://denisvuyka.wordpress.com/osd.xml" title="Denis Vuyka" />
	<atom:link rel='hub' href='http://denisvuyka.wordpress.com/?pushpress=hub'/>
		<item>
		<title>IL.View October 2011 Features.</title>
		<link>http://denisvuyka.wordpress.com/2011/11/01/il-view-october-2011-features/</link>
		<comments>http://denisvuyka.wordpress.com/2011/11/01/il-view-october-2011-features/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 20:17:05 +0000</pubDate>
		<dc:creator>Denis Vuyka</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://denisvuyka.wordpress.com/?p=324</guid>
		<description><![CDATA[October 2011 was a very busy month for IL.View in terms of new features  introduced. The major features that are worth mentioning in this recap is as following: Automatic updates for OOB (out-of-browser) scenario Rich browsing for Silverlight packages (.xap files) Platform identifiers for assemblies Version numbers for assembly references Content preview for some file [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=324&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>October 2011 was a very busy month for IL.View in terms of new features  introduced.</p>
<p>The major features that are worth mentioning in this recap is as following:</p>
<ul>
<li>Automatic updates for OOB (out-of-browser) scenario</li>
<li>Rich browsing for Silverlight packages (.xap files)</li>
<li>Platform identifiers for assemblies</li>
<li>Version numbers for assembly references</li>
<li>Content preview for some file types (xml/xaml/ClientConfig/jpg/png)</li>
<li>Displaying and expanding embedded resource assemblies (for Silverlight assemblies only) by pressing Space bar</li>
<li>Preview of embedded resources (xml/xaml/ClientConfig/jpg/png) by pressing Space bar</li>
<li>User-defined reference paths for automatic assembly resolution (similar to Visual Studio &#8220;reference paths&#8221; feature)</li>
<li>Lot of stabilization and improvements for underlying infrastructures</li>
<li>New assembly versioning schema based on &#8220;YYYY.MM.DD.{Build}&#8221; format</li>
</ul>
<h2><strong>Automatic Updates</strong></h2>
<p>Live preview builds that are continuously  pushed to the <a title="IL.View Project Page" href="denisvuyka.github.com/IL.View" target="_blank">project page</a> got support for automatic updates. Users that are using the full-trust OOB (out-of-browser) scenario will get the application up-to-date automatically upon every launch.</p>
<h2>Browsing Silverlight Packages</h2>
<div>IL.View now provides rich capabilities for browsing Silverlight packages (&#8220;.xap&#8221; files). Users are now able to drag and drop &#8220;.xap&#8221; package directly onto the application surface and view package contents. Package browsing includes full support for content and assembly navigation in the same way it is done for a regular assembly.</div>
<div><a href="http://denisvuyka.files.wordpress.com/2011/11/image01_xapbrowsing.png"><img class="alignnone size-full wp-image-326" title="Image01_XapBrowsing" src="http://denisvuyka.files.wordpress.com/2011/11/image01_xapbrowsing.png?w=328&#038;h=216" alt="Silverlight Package Browsing" width="328" height="216" /></a></div>
<div></div>
<h2>Platform identifiers for assemblies</h2>
<p>As application is moving forward having a single list of assemblies within the browser the platform identifiers were added to assembly names. Silverlight assemblies will be marked as &#8220;(SL)&#8221; while .NET assemblies will be marked as &#8220;.NET&#8221;. Later on identifiers will be extended to display the actual version of the corresponding framework.</p>
<p><a href="http://denisvuyka.files.wordpress.com/2011/11/image02_platformidentifiers.png"><img class="alignnone size-full wp-image-327" title="Image02_PlatformIdentifiers" src="http://denisvuyka.files.wordpress.com/2011/11/image02_platformidentifiers.png?w=326&#038;h=167" alt="Platform Identifiers" width="326" height="167" /></a></p>
<h2>Version numbers for assembly references</h2>
<p>To improve dependency analysis process the application provides version numbers for assembly references within the reference title. That allows to avoid unnecessary decompilation or assembly resolution calls when it is only the version of reference the user is interested in.</p>
<p><a href="http://denisvuyka.files.wordpress.com/2011/11/image03_referenceversionnumbers.png"><img class="alignnone size-full wp-image-328" title="Image03_ReferenceVersionNumbers" src="http://denisvuyka.files.wordpress.com/2011/11/image03_referenceversionnumbers.png?w=466&#038;h=437" alt="Version numbers for assembly references" width="466" height="437" /></a></p>
<h2>Content Preview</h2>
<p>It is now possible to view the content of the files that are frequently added to the &#8220;.xap&#8221; files. IL.View provides support to show xml-based files (xml, xaml, ClientConfig) with syntax colouring:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2011/11/image04_contentpreview_xaml.png"><img class="alignnone size-full wp-image-329" title="Image04_ContentPreview_xaml" src="http://denisvuyka.files.wordpress.com/2011/11/image04_contentpreview_xaml.png?w=600&#038;h=402" alt="Content Preview of xml-based files" width="600" height="402" /></a></p>
<div> It is also possible to preview the content of image files in the formats supported by Silverlight (.png and .jpg). Images are displayed in real sizes.</div>
<div><a href="http://denisvuyka.files.wordpress.com/2011/11/image05_contentpreview_png.png"><img class="alignnone size-full wp-image-330" title="Image05_ContentPreview_png" src="http://denisvuyka.files.wordpress.com/2011/11/image05_contentpreview_png.png?w=600&#038;h=401" alt="Content preview for image files" width="600" height="401" /></a></div>
<div></div>
<h2>Browsing embedded resource assemblies</h2>
<p>October version of IL.View brings out support for embedded resource assemblies navigation. This feature is however limited to only Silverlight assemblies. A new node called &#8220;Resources&#8221; will appear next to every main module of the assembly. Resource assemblies can be expanded like regular assemblies and their xml/image-based content can be previewed by pressing a Space bar on the selected item.</p>
<p><a href="http://denisvuyka.files.wordpress.com/2011/11/image06_embeddedresources.png"><img class="size-full wp-image-331 alignnone" title="Image06_EmbeddedResources" src="http://denisvuyka.files.wordpress.com/2011/11/image06_embeddedresources.png?w=600&#038;h=343" alt="Browsing embedded resources" width="600" height="343" /></a></p>
<h2> Reference Paths</h2>
<p>Application now provides a way to define common reference paths that should be used for assembly lookup during decompilation and reference resolution. There will be a new options panel called &#8220;Reference Paths&#8221; within the &#8220;Settings&#8221; page. The user is able to add or remove a path to any directory containing .NET or Silverlight assemblies that needs to be checked during decompilation process. Every single reference path can be configured to use recursive search, meaning that the entire folder tree (including all sub-folders) is going to be inspected. However recursive search is a time consuming event and users discouraged to use it against deep nested folders.</p>
<p>Every time an external assembly is found the path to the file is cached. This gives much better performance during next sessions.</p>
<p><a href="http://denisvuyka.files.wordpress.com/2011/11/image07_referencepaths.png"><img class="alignnone size-full wp-image-336" title="Image07_ReferencePaths" src="http://denisvuyka.files.wordpress.com/2011/11/image07_referencepaths.png?w=600&#038;h=330" alt="Reference Paths" width="600" height="330" /></a></p>
<p>This feature is however limited to full-trust mode running on Windows machines. &#8220;Reference Paths&#8221; section won&#8217;t be displayed when running IL.View on non-Windows computers (i.e. MacOs).</p>
<h2>New Versioning Schema</h2>
<p>New assembly versioning schema was applied based on &#8220;YYYY.MM.DD.{Build}&#8221; format. The version number can now be checked at the &#8220;About&#8221; page:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2011/11/image08_versioningschema.png"><img class="alignnone size-full wp-image-337" title="Image08_VersioningSchema" src="http://denisvuyka.files.wordpress.com/2011/11/image08_versioningschema.png?w=476&#038;h=245" alt="Versioning Schema" width="476" height="245" /></a></p>
<p>Besides new features there was a lot of stabilization work performed.</p>
<p>More and more features are being registered within the <a href="https://github.com/DenisVuyka/IL.View/issues?sort=created&amp;direction=desc&amp;state=open" target="_blank">issue tracking system</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/denisvuyka.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/denisvuyka.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/denisvuyka.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/denisvuyka.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/denisvuyka.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/denisvuyka.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/denisvuyka.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/denisvuyka.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/denisvuyka.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/denisvuyka.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/denisvuyka.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/denisvuyka.wordpress.com/324/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/denisvuyka.wordpress.com/324/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/denisvuyka.wordpress.com/324/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=324&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://denisvuyka.wordpress.com/2011/11/01/il-view-october-2011-features/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/032cdef00bc6c528b24517b137c97660?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Denis</media:title>
		</media:content>

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

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

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

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

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

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

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

		<media:content url="http://denisvuyka.files.wordpress.com/2011/11/image08_versioningschema.png" medium="image">
			<media:title type="html">Image08_VersioningSchema</media:title>
		</media:content>
	</item>
		<item>
		<title>IL.View beta builds are now available online</title>
		<link>http://denisvuyka.wordpress.com/2011/10/27/il-view-beta-builds-are-now-available-online/</link>
		<comments>http://denisvuyka.wordpress.com/2011/10/27/il-view-beta-builds-are-now-available-online/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 16:36:54 +0000</pubDate>
		<dc:creator>Denis Vuyka</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Cecil]]></category>
		<category><![CDATA[Reflector]]></category>

		<guid isPermaLink="false">http://denisvuyka.wordpress.com/?p=319</guid>
		<description><![CDATA[Today I&#8217;m glad to announce that thanks to Github &#8220;project pages&#8221; feature I am able to host beta builds of &#8220;IL.View&#8221; that can be consumed both in browswer and out of browser. You can browse and/or install IL.View by navigating this link: http://denisvuyka.github.com/IL.View &#160; What&#8217;s new in the deployed build: I have added an experimental support [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=319&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m glad to announce that thanks to Github &#8220;project pages&#8221; feature I am able to host beta builds of &#8220;IL.View&#8221; that can be consumed both in browswer and out of browser.</p>
<p>You can browse and/or install IL.View by navigating this link: <a href="http://denisvuyka.github.com/IL.View" target="_blank">http://denisvuyka.github.com/IL.View</a></p>
<p>&nbsp;</p>
<p><strong>What&#8217;s new in the deployed build:</strong></p>
<p>I have added an experimental support for Silverlight &#8220;.xap&#8221; packages. It will be possible to drop a &#8220;.xap&#8221; file onto IL.View surface and navigate it&#8217;s content within assembly browser like shown below:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2011/10/ilviewxapsupport.png"><img class="alignnone size-full wp-image-320" title="ILViewXapSupport" src="http://denisvuyka.files.wordpress.com/2011/10/ilviewxapsupport.png?w=600&#038;h=469" alt="" width="600" height="469" /></a></p>
<p>Just have to note that the implementation of &#8220;.xap&#8221; browsing is in its early stage and is not feature complete.</p>
<p><strong>What&#8217;s on the way:</strong></p>
<p>Many features related to MEF framework. I&#8217;m a greatest fan of MEF and use it every day in the production. There&#8217;s some tooling that I would like to integrate into IL.View like displaying all the MEF imports/exports for the particular assembly, etc. More content viewers are pending (xaml/xml, images, etc.)</p>
<p><strong>Suggestions, issues and feedbacks?</strong></p>
<p>I would really appreciate to get them registered here: <a href="https://github.com/DenisVuyka/IL.View/issues?sort=created&amp;direction=desc&amp;state=open" target="_blank">IL.View Issues</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/denisvuyka.wordpress.com/319/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/denisvuyka.wordpress.com/319/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/denisvuyka.wordpress.com/319/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/denisvuyka.wordpress.com/319/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/denisvuyka.wordpress.com/319/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/denisvuyka.wordpress.com/319/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/denisvuyka.wordpress.com/319/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/denisvuyka.wordpress.com/319/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/denisvuyka.wordpress.com/319/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/denisvuyka.wordpress.com/319/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/denisvuyka.wordpress.com/319/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/denisvuyka.wordpress.com/319/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/denisvuyka.wordpress.com/319/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/denisvuyka.wordpress.com/319/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=319&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://denisvuyka.wordpress.com/2011/10/27/il-view-beta-builds-are-now-available-online/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/032cdef00bc6c528b24517b137c97660?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Denis</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2011/10/ilviewxapsupport.png" medium="image">
			<media:title type="html">ILViewXapSupport</media:title>
		</media:content>
	</item>
		<item>
		<title>IL.View: .NET Reflector OSS Alternative. In Silverlight!</title>
		<link>http://denisvuyka.wordpress.com/2011/04/27/il-view-net-reflector-oss-alternative-in-silverlight/</link>
		<comments>http://denisvuyka.wordpress.com/2011/04/27/il-view-net-reflector-oss-alternative-in-silverlight/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 09:59:00 +0000</pubDate>
		<dc:creator>Denis Vuyka</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Cecil]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[Reflector]]></category>

		<guid isPermaLink="false">https://denisvuyka.wordpress.com/2011/04/27/il-view-net-reflector-oss-alternative-in-silverlight/</guid>
		<description><![CDATA[Today I would like to announce a new project I’ve been working on to contribute to the .NET community. The project is called “IL.View” and it is a .NET Reflector alternative made in Silverlight 4 as an Out-of-Browser Silverlight Application. “IL.View” sources will be published under the MIT (X11) license to the following GitHub repository [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=310&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I would like to announce a new project I’ve been working on to contribute to the .NET community.</p>
<p>The project is called “<strong>IL.View</strong>” and it is a .NET Reflector alternative made in <strong>Silverlight 4</strong> as an Out-of-Browser Silverlight Application. “IL.View” sources will be published under the MIT (X11) license to the following <strong><a href="https://github.com/DenisVuyka/IL.View" target="_blank">GitHub</a></strong> repository in the next couple of hours. As soon as Google fixes <a href="http://code.google.com/p/googleappengine/issues/detail?id=4838" target="_blank">“If-Modified-Since” bug</a> the online version of “IL.View” will hopefully become immediately available with “Google App Engine”.</p>
<p><a href="http://denisvuyka.files.wordpress.com/2011/04/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-color:initial;border-style:initial;border-width:0;" title="image" src="http://denisvuyka.files.wordpress.com/2011/04/image_thumb.png?w=649&#038;h=447" alt="image" width="649" height="447" border="0" /></a></p>
<h3></h3>
<h3>Background</h3>
<p>I’ve started planning this project approximately 2 weeks before infamous Red Gate <a href="http://www.red-gate.com/products/dotnet-development/reflector/announcement" target="_blank">announcement</a> that “.NET Reflector” goes commercial way and so approximately 2 weeks before an awesome OSS alternative appeared: <a href="http://wiki.sharpdevelop.net/ilspy.ashx" target="_blank"><strong>ILSpy</strong></a><strong>. </strong>So “IL.View” background is not an emotional move and is not going to be abandoned with the ILSpy arrival (like <a href="https://github.com/jcdickinson/Monoflector" target="_blank">Monoflector</a> for instance).</p>
<p>I am a Silverlight developer and my team does a lot of really crazy stuff related to Silverlight, Azure, REST and OData. During the “demo” and “testing” periods we have to deal with publishing a lot – different versions of Windows Servers, various IIS versions, different .NET frameworks at server sides, multiple remote desktops and issue addressing, etc.</p>
<p>One of the issues I’ve experienced in the past (and according to Google I’m not alone with that) is the process of brining .NET Reflector to server side in order to have a quick look at my assemblies. You should be able to download it from somewhere for every server (of course if you have rights to download and install anything), you need to have a proper .NET Framework installed on server side (Reflector itself requires .NET 3.5 or later to be present), etc.</p>
<p>Actually the very same problem may be valid for <strong>ILSpy</strong> as well. If it is compiled for .NET 4.0 framework you cannot use it at server having .NET 3.x only. So the idea of having a Silverlight version hosted in the company intranet (or in the cloud) was very appealing as it could save time and reduce efforts.</p>
<p>Another feature I was dreaming of is “Remote Assembly Cache” or the possibility to decompile .NET assembly without binding to local machine – even without having any .NET framework installed at all. For example having a remote web service (pure REST, OData, whatever) to resolve .NET dependencies upon being needed. This could open a brand new set of scenarios for me. Having no bindings to local machine could for example allow Mac users to disassemble .NET assemblies easily and drilling down to “mscorlib” or any other part of .NET framework without difficulties (this feature is in progress for “IL.VIew” and will be available later on).</p>
<p>Third major feature I was trying to address is extensibility. NET Reflector always deserved better extensibility support and more complex addins from both code and presentation points of view.</p>
<h3></h3>
<h3>Overview</h3>
<p>As I’ve mentioned above “IL.View” is an OOB (Out-of-browser) Silverlight 4 application (Full Trust). It supports drag and drop for .NET assemblies from the desktop or Windows Explorer and provides a local cache of assemblies that were loaded (with the possibility extending the cache manually). “Assembly Browser” control supports “lazy loading” so you get disassembling process on demand. There’s a native “IL” formatting and “C#” one (in progress).</p>
<p>There are several ways “IL.View” can be deployed and used:</p>
<ul>
<li>Online (cloud, web site)</li>
<li>On-premise (intranet)</li>
<li>Local installation</li>
</ul>
<ul>Some features that are in progress will allow “IL.View” users to get maximum benefit of both cloud and on-premise deployments.</ul>
<h4>Mono.Cecil</h4>
<p>“IL.View” is not using .NET Reflection. It is being build on the top of Silverlight port of “<strong><a href="https://github.com/jbevain/cecil" target="_blank">Mono.Cecil</a></strong>”. This is a tremendous project and I would like to thank <a href="https://github.com/jbevain" target="_blank"><strong>Jb Evain</strong></a><strong> </strong>for his work. Thanks to Cecil I got an opportunity dealing with both .NET and Silverlight assembly inspection within Silverlight runtime.</p>
<p>Despite the asynchronous nature of Silverlight the Cecil integration went well. “IL.View” provides its own dependency resolution facility that is capable of properly locking the UI and waiting for the user to perform actions:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2011/04/snaghtml103147e.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-color:initial;border-style:initial;border-width:0;margin:0;" title="SNAGHTML103147e" src="http://denisvuyka.files.wordpress.com/2011/04/snaghtml103147e_thumb.png?w=638&#038;h=463" alt="SNAGHTML103147e" width="638" height="463" border="0" /></a></p>
<p><a href="http://denisvuyka.files.wordpress.com/2011/04/snaghtml14fc8c1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-color:initial;border-style:initial;border-width:0;margin:0;" title="SNAGHTML14fc8c1" src="http://denisvuyka.files.wordpress.com/2011/04/snaghtml14fc8c1_thumb.png?w=638&#038;h=463" alt="SNAGHTML14fc8c1" width="638" height="463" border="0" /></a></p>
<h4></h4>
<h4></h4>
<h4>ICSharpCode Decompiler and NRefactory for Silverlight</h4>
<p>The biggest challenge for me was “<strong>C#</strong>” output support. Not to reinvent a wheel I’ve decided to stick to <strong>ICSharpCode.Decompiler</strong> and <strong>ICSharpCode.NRefactory</strong> projects that are the part of <strong>ILSpy</strong>.  The only problem I came across is the absence of Silverlight ports for the mentioned projects. So I’ve took the challenge to port them to Silverlight myself. You can find the sources at my <a href="https://github.com/DenisVuyka/ILSpy" target="_blank">GitHub repository</a>. First attempts were quite tricky, but thanks to the ILSpy team the original codebase becomes more and more “portable-friendly”.</p>
<p>As a result I have managed to provide C# output based on ILSpy libraries:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2011/04/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-color:initial;border-style:initial;border-width:0;margin:0;" title="image" src="http://denisvuyka.files.wordpress.com/2011/04/image_thumb1.png?w=733&#038;h=432" alt="image" width="733" height="432" border="0" /></a></p>
<h4></h4>
<h4>JetPack Theme</h4>
<p>“IL.View” UI is based on the great “<strong><a href="http://timheuer.com/blog/archive/2010/09/09/silverlight-jetpack-theme-released.aspx" target="_blank">JetPack Theme</a></strong>”. However I had to provide a set of bugfixes for templates and styles in order to make some of the components look properly and behave as expected.</p>
<h3></h3>
<h3>Notes</h3>
<p>The project is still in its early stage but is going to evolve rapidly. There’s a huge backlog of features and roadmap will be announced later on. “IL.View” does not compete with <strong>ILSpy</strong> and I would love to contribute eventually to both .NET Reflector alternatives in the nearest future.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/denisvuyka.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/denisvuyka.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/denisvuyka.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/denisvuyka.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/denisvuyka.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/denisvuyka.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/denisvuyka.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/denisvuyka.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/denisvuyka.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/denisvuyka.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/denisvuyka.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/denisvuyka.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/denisvuyka.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/denisvuyka.wordpress.com/310/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=310&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://denisvuyka.wordpress.com/2011/04/27/il-view-net-reflector-oss-alternative-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/032cdef00bc6c528b24517b137c97660?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Denis</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2011/04/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2011/04/snaghtml103147e_thumb.png" medium="image">
			<media:title type="html">SNAGHTML103147e</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2011/04/snaghtml14fc8c1_thumb.png" medium="image">
			<media:title type="html">SNAGHTML14fc8c1</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2011/04/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>VS 2010 bug related to Silverlight 4.0 compilation</title>
		<link>http://denisvuyka.wordpress.com/2010/10/08/vs-2010-bug-related-to-silverlight-4-0-compilation/</link>
		<comments>http://denisvuyka.wordpress.com/2010/10/08/vs-2010-bug-related-to-silverlight-4-0-compilation/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 07:52:00 +0000</pubDate>
		<dc:creator>Denis Vuyka</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight 4]]></category>
		<category><![CDATA[VS 2010]]></category>
		<category><![CDATA[XmlnsDefinitionAttribute]]></category>

		<guid isPermaLink="false">https://denisvuyka.wordpress.com/2010/10/08/vs-2010-bug-related-to-silverlight-4-0-compilation/</guid>
		<description><![CDATA[Some time ago I came across the problem of compiling Silverlight 4.0 with Visual Studio 2010 when using XmlnsDefinitionAttribute attribute. I have reported the problem to Microsoft but for the time of writing this post I haven’t yet received confirmation of the bug. However more and more people around me start to experience the very [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=284&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">Some time ago I came across the problem of compiling Silverlight 4.0 with Visual Studio 2010 when using <a href="http://msdn.microsoft.com/en-us/library/system.windows.markup.xmlnsdefinitionattribute%28VS.95%29.aspx" target="_blank">XmlnsDefinitionAttribute</a> attribute. I have reported the problem to Microsoft but for the time of writing this post I haven’t yet received confirmation of the bug. However more and more people around me start to experience the very same problem with VS 2010 so I’ve decided to publish some details towards the problem as well as possible workarounds that can be used until the bug is confirmed and some sort of hotfix is available.</p>
<p align="justify">The problem is that under some specific circumstances Visual Studio 2010 will fail compiling Silverlight 4 assembly if it refers to any other assembly via xmlns mapping in the root of the XAML.</p>
<p>Here you can find a sample solution that addresses this problem: <a href="http://dl.dropbox.com/u/5260674/Wordpress/VS2010/VSBuildBug.zip" target="_blank">VSBuildBug</a>.</p>
<p>Here’s the brief overview of the sample code:</p>
<p>1. Silverlight 4.0 assembly “<strong>SharedComponents</strong>” contains a User Control called “SharedControl”</p>
<p>2. The assembly “<strong>SharedComponents</strong>” maps one of its namespaces to an Uri (in my case it is “<strong>http://denisvuyka.wordpress.com/vsbugs</strong>”)</p>
<p>3. Silverlight application “<strong>VSBuildBug</strong>” references “<strong>SharedComponents</strong>” assembly</p>
<p>4. Application contains a “<strong>MainForm</strong>” that is declared my means of the namespace mapping: <strong>&lt;shared:UserControl xmlns:shared=”http://denisvuyka.wordpress.com/vsbugs”…</strong></p>
<p>When you open the solution attached with VS 2010 and try compiling it you will receive the following error:</p>
<p>“<strong><em>The type or namespace ‘SharedControl’ could not be found (are you missing a using directive or an assembly reference?</em></strong>” (see the screenshot below)</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/12/clip_image002.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="clip_image002" border="0" alt="clip_image002" src="http://denisvuyka.files.wordpress.com/2010/12/clip_image002_thumb.jpg?w=640&#038;h=62" width="640" height="62" /></a></p>
<p align="justify">However theoretically everything should compile without any problem. Some of the guys I’ve contacted towards this problem just gave up using xml namespace mappings thinking that the problem is in Silverlight itself but it’s wrong. This use case is absolutely correct and can be compiled.</p>
<p align="justify">The first workaround is calling “Build – Rebuild solution” several times in a row. At some stage you will receive “successful compilation” result and after that you will stop getting errors both for “Build” and “Rebuild”. However everything will be ok until the “Build – Clean solution” call or until you get a brand new version of the solution from the source control for example. Also different versions of Windows require different number of rebuild cycles. I didn’t bother figuring out the correct numbers, I can only confirm that on Windows 7 you may need about 3-4 “rebuild” calls while Windows XP may require 5+ “rebuild” calls.</p>
<p align="justify">After you made it compile you can reproduce the problem any time again. Just call “Build – Clean” solution and try “building” or “rebuilding” it again. The compilation problem will come back and you may need repeating the “rebuild” cycle one more time.</p>
<p align="justify">I’ve decided to go further with my investigation as I was wondering why TFS builds do not fail under the same conditions. I’ve ended up with a more reliable solution that I am using nowadays – <strong>msbuild</strong> tool.</p>
<p align="justify">If you unpack my solution once again and compile it from the VS command prompt using msbuild (just “<strong>msbuild VSBuildBug.sln</strong>”) you will never get an error. You won’t get errors calling “Build – Clean” solution and then using msbuild to build it as well.</p>
<p align="justify">So the second and most reliable solution is using msbuild tool to produce a solution. In case of avoiding full cleanups with “Build – Clean” solution developer may need calling msbuild only once getting a brand new version of codebase from TFS.</p>
<p align="justify">After finding a reliable workaround I’ve decided to go deeper into the details and see why auto-generated code is not compiling. </p>
<p align="justify">I’ve opened “<strong>MainPage.g.i.cs</strong>” with Visual Studio to get notifications when it is changed and to have an opportunity to see how it was changed. After a couple of experiments I’ve noticed that first two compilations (and code generations) does not produce the very same code behind actually.</p>
<p align="justify">Steps to reproduce:</p>
<p align="justify"><strong>Step 1. Open demo solution and call “Build – Clean solution”</strong></p>
<p align="justify"><strong>Step 2. Call “Build – Rebuild”</strong></p>
<p align="justify">You should see the same error I’ve described earlier:</p>
<p align="justify"><a href="http://denisvuyka.files.wordpress.com/2010/12/clip_image0024.jpg"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="clip_image002[4]" border="0" alt="clip_image002[4]" src="http://denisvuyka.files.wordpress.com/2010/12/clip_image0024_thumb.jpg?w=640&#038;h=23" width="640" height="23" /></a></p>
<p>If you open the auto-generated “MainPage.g.i.cs” you should notice that “MainPage” inherits “SharedControl” but no references to external component library are present (neither within “using” clause nor type declaration). See the screenshot below:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/10/clip_image0026.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="clip_image002[6]" border="0" alt="clip_image002[6]" src="http://denisvuyka.files.wordpress.com/2010/10/clip_image0026_thumb.jpg?w=307&#038;h=320" width="307" height="320" /></a></p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/10/clip_image0028.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="clip_image002[8]" border="0" alt="clip_image002[8]" src="http://denisvuyka.files.wordpress.com/2010/10/clip_image0028_thumb.jpg?w=471&#038;h=144" width="471" height="144" /></a></p>
<p>I completely agree that this code should not compile even theoretically and Visual Studio gives me the correct output stating about missing references.</p>
<p><strong>Step 3. Call “Build – Rebuild” for the second time.</strong></p>
<p>You should get the very same compilation error again:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/12/clip_image00210.jpg"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="clip_image002[10]" border="0" alt="clip_image002[10]" src="http://denisvuyka.files.wordpress.com/2010/12/clip_image00210_thumb.jpg?w=640&#038;h=23" width="640" height="23" /></a></p>
<p align="justify">However if you have “MainPage.g.i.cs” file opened in VS 2010 you will get a notification that its content was changed. Alternatively you can locate this file and open it manually.</p>
<p>After the second rebuild the type definition looks like the following:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/10/clip_image00212.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="clip_image002[12]" border="0" alt="clip_image002[12]" src="http://denisvuyka.files.wordpress.com/2010/10/clip_image00212_thumb.jpg?w=515&#038;h=184" width="515" height="184" /></a></p>
<p align="justify">As you can see now VS generated another version of code behind that correctly references the “SharedControl” type. The namespace is provided and code should theoretically compile fine. But it does not.</p>
<p><strong>Step 4. Call “Build – Rebuild” 3rd time </strong></p>
<p align="justify">You should receive notification that compilation was successful (<em>please don’t forget about my notes at the beginning that I am using Windows 7, it was noticed that Windows XP environments sometimes require more “rebuild” calls</em>). </p>
<p>Third compilation does not produce a new code behind file and its content is equal to those produced during the Step 3.</p>
<p>I’m pretty sure VS is doing something wrong between steps 2–4. Two different code generation outputs for the same action that was just called twice seems to be very suspicious. </p>
<p align="justify">The only idea I have for the moment is that “MainPage.g.i.cs” was generated AFTER the rebuild procedure has finished. And the 3rd rebuild is just using the file generated during the 2nd pass. If that is true then it makes a perfect sense why 3rd pass was successful. And if I’m right then developers may potentially encounter even more serious problems in the future because there will be always a possibility testing the code that was built without exception but does not contain changes or bug fixes that needs to be verified by developer if you see what I mean. </p>
<p align="justify">The only thing I don’t understand for the moment is why VS 2010 produces compilation errors while msbuild works fine. I expected VS 2010 is using msbuild under the hood for building Silverlight but my investigation results make me think that there are two ways of building (please correct me if I’m wrong, I didn’t try reflecting VS to find an answer for this question) and the build procedure embedded into VS is definitely having issues.</p>
<p align="justify">&#160;</p>
<p align="justify"><strong>Conslusion</strong></p>
<p align="justify">I still think that xml namespace binding is a very important feature that needs to be reused as much as possible (see more details here: “<a href="http://msdn.microsoft.com/en-us/library/dd728664%28VS.95%29.aspx" target="_blank">Prefixes and Mappings for Silverlight Libraries</a>”) at least because of the following benefits:</p>
<ul>
<li>
<div align="justify">helps a lot with xaml/code generation scenarios;</div>
</li>
<li>
<div align="justify">helps a lot with component discovery (we all love intellisense);</div>
</li>
<li>
<div align="left">reduces a variety of problems related to code refactorings and type namespace changes;</div>
</li>
</ul>
<p align="left">I’m pretty sure Microsoft will provide a hotfix as soon as this issue is confirmed but meanwhile you can use “msbuild” or “continuous rebuild” workarounds to keep using xml namespace mappings within your projects.</p>
<p align="left">Any feedback is appreciated.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/denisvuyka.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/denisvuyka.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/denisvuyka.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/denisvuyka.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/denisvuyka.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/denisvuyka.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/denisvuyka.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/denisvuyka.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/denisvuyka.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/denisvuyka.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/denisvuyka.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/denisvuyka.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/denisvuyka.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/denisvuyka.wordpress.com/284/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=284&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://denisvuyka.wordpress.com/2010/10/08/vs-2010-bug-related-to-silverlight-4-0-compilation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/032cdef00bc6c528b24517b137c97660?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Denis</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/12/clip_image002_thumb.jpg" medium="image">
			<media:title type="html">clip_image002</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/12/clip_image0024_thumb.jpg" medium="image">
			<media:title type="html">clip_image002[4]</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/10/clip_image0026_thumb.jpg" medium="image">
			<media:title type="html">clip_image002[6]</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/10/clip_image0028_thumb.jpg" medium="image">
			<media:title type="html">clip_image002[8]</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/12/clip_image00210_thumb.jpg" medium="image">
			<media:title type="html">clip_image002[10]</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/10/clip_image00212_thumb.jpg" medium="image">
			<media:title type="html">clip_image002[12]</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamic Silverlight Forms. Embedding S# Scripts into Xaml.</title>
		<link>http://denisvuyka.wordpress.com/2010/05/19/dynamic-silverlight-forms-embedding-s-scripts-into-xaml/</link>
		<comments>http://denisvuyka.wordpress.com/2010/05/19/dynamic-silverlight-forms-embedding-s-scripts-into-xaml/#comments</comments>
		<pubDate>Wed, 19 May 2010 08:05:00 +0000</pubDate>
		<dc:creator>Denis Vuyka</dc:creator>
				<category><![CDATA[S#]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">https://denisvuyka.wordpress.com/2010/05/19/dynamic-silverlight-forms-embedding-s-scripts-into-xaml/</guid>
		<description><![CDATA[I’ve been receiving a lot of questions regarding the possibility of usage S# in a declarative way directly from xaml rather than from code behind. Such approach is extremely valuable when dealing with BPM-like usages and dynamic forms that are presented by raw Xaml stored in database and instantiated via XamlReader. In this article I’m [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=244&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">I’ve been receiving a lot of questions regarding the possibility of usage S# in a declarative way directly from xaml rather than from code behind. Such approach is extremely valuable when dealing with BPM-like usages and dynamic forms that are presented by raw Xaml stored in database and instantiated via XamlReader. </p>
<p align="justify">In this article I’m going to show you how easy it can be to embed a S# script into Xaml and execute it dynamically. For this purpose I will be using some blocks of the new upcoming “<strong>S# Silverlight Toolkit</strong>” that will be available soon as a part of the S# package. The toolkit will be distributed as a free addition with source code provided.</p>
<p align="justify">For the sake of simplicity I&#8217;m going to show the very basic injection of S# scripts into Xaml markup. I will be using Silverlight 3 for this purpose. The sample code will be updated to Silverlight 4 as soon as S# 2.0 reaches RTM.</p>
<h2>1. Required Assembly References</h2>
<p align="justify">You will need adding references to the following assemblies:</p>
<ul>
<li>
<div align="justify"><strong>Orbifold.SSharp.dll</strong></div>
</li>
<li>
<div align="justify"><strong>Orbifold.SSharp.Silverlight.Toolkit.dll</strong> (you can find it in the form of source code within the sample solution attached at the end of the article)</div>
</li>
</ul>
<h2>2. Required Namespace Declaration</h2>
<p align="justify">You will need to declare 3 additional namespaces</p>
<ul>
<li>
<div align="justify">“<strong>sys</strong>” pointing to the “System” namespace in “mscorlib” to be able using basic .NET types from within Xaml;</div>
</li>
<li>
<div align="justify">“<strong>scriptingRuntime</strong>” pointing to the “<strong>Orbifold.SSharp.Runtime</strong>” namespace to be able using “ScriptContext” from within Xaml;</div>
</li>
<li>
<div align="justify">“<strong>scriptingToolkit”</strong> pointing to the “<strong>Orbifold.SSharp.Silverlight</strong>” namespace to be able using Silverlight facilities like “<strong>CodeBlock</strong>” and “<strong>ScriptManager</strong>” from within Xaml;</div>
</li>
</ul>
<p><a href="http://denisvuyka.files.wordpress.com/2010/05/image.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/05/image_thumb.png?w=826&#038;h=120" width="826" height="120" /></a> </p>
<h2>3. Introducing Script Execution Context for the Form</h2>
<p align="justify">Obviously you will want providing some context variables or custom functions for the scripts executed by the form. For this purpose I’m declaring a ScriptContext instance in the resources section of the form:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/05/image1.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/05/image_thumb1.png?w=424&#038;h=55" width="424" height="55" /></a></p>
<p>Here’s the code behind I’ve used to initialize default script context for the form:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/05/image2.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/05/image_thumb2.png?w=517&#038;h=260" width="517" height="260" /></a> </p>
<p align="justify">First of all you will need initializing Runtime Host. I’ve promoted the entire “System.Windows” assembly (via MessageBox type) to be able calling Message Boxes from within scripts.</p>
<p align="justify">Next I’ve got access to “defaultContext” declared in the markup and created a script variable “Form” pointing to the instance of this very Silverlight form. Additionally you may need assigning “ExecutionContext” attached property for the form if you want embedding scripts for the form-level events like “Loaded”.</p>
<h2>4. Attaching S# Scripts to the UI elements</h2>
<p align="justify">S# Silverlight Toolkit provides a set of facilities regarding script injection. You will need 2 of them for now: <strong>Code Block</strong> and <strong>Script Manager</strong>. <strong>CodeBlock</strong> class serves as a wrapper around plain S# script while <strong>Script Manager</strong> provides a set of attached properties (see <strong>Ramora Pattern</strong>) to wire UI elements with the S# runtime engine.</p>
<p><strong>OnLoaded Attached Property</strong></p>
<p>Allows you to associate a S# script with a FrameworkElement and execute it each time “FrameworkElement.Loaded” event is fired. Here’s a basic example:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/05/image3.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/05/image_thumb3.png?w=600&#038;h=327" width="600" height="327" /></a> </p>
<p><strong>ScriptManager.OnLoaded</strong> attached property setter accepts “CodeBlock” instance as a valid value. Every Code Block can contain a body of the S# script and can be optionally bound to the execution context. </p>
<p>The script above uses common Silverlight FrameworkElement.FindName method to find an element called “TextBox” and assigns its Text property to “<em>Dynamically populated text!!!</em>”.</p>
<p><strong>ScriptManager.OnButtonClick</strong> attached property setter accepts “CodeBlock” instance as a value and wires a S# script with a “<strong>Button.Click</strong>” event:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/05/image4.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/05/image_thumb4.png?w=618&#038;h=227" width="618" height="227" /></a> </p>
<p>Sample above shows a simple scenario of finding a TextBox element on the form and modifying its “Text” property.</p>
<p><strong>ScriptManager.OnGotFocus</strong> attached property setter accepts “CodeBlock” instance as a value and wires a S# script with “<strong>UIElement.GotFocus</strong>” event:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/05/image5.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/05/image_thumb5.png?w=591&#038;h=163" width="591" height="163" /></a> </p>
<h2>5. Running Sample</h2>
</p>
</p>
<p>After launching the sample you will see the following UI elements:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/05/image6.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/05/image_thumb6.png?w=491&#038;h=131" width="491" height="131" /></a> </p>
<p>There is a Button and a TextBox controls. The text box will contain some text assigned by the Form-level script (<em><strong>ScriptManager.OnLoaded</strong></em>)</p>
<p>When clicking (and so focusing) the TextBox the “OnGotFocus” script will be executed:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/05/image7.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/05/image_thumb7.png?w=404&#038;h=90" width="404" height="90" /></a> </p>
</p>
<p>When clicking a Button element the message box will appear and the TextBox.Text will be changed according to the “OnButtonClick” script:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/05/image8.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/05/image_thumb8.png?w=381&#038;h=310" width="381" height="310" /></a> </p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/05/image9.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/05/image_thumb9.png?w=393&#038;h=118" width="393" height="118" /></a> </p>
<h2>Conclusion</h2>
<p align="justify">The S# Silverlight Toolkit opens the door for more efficient and rich scripting for your applications. Being similar to ASP.NET development it provides facilities for dynamic invocation of your scripts during the UI life cycle, allows you storing the xaml in databases and instantiate the entire UI with corresponding scripts during runtime by means of XamlReader (note that all attached properties will be restored during form instantiation, and all event handlers will be re-assigned during XamlReader.Load process).</p>
<p align="justify">You can get the source code for this article here:</p>
<ul>
<li>
<div align="justify"><a href="http://dl.dropbox.com/u/5260674/Wordpress/Samples/SLForms.zip">Silverlight 3 sample</a></div>
</li>
<li>
<div align="justify">Silverlight 4 sample (coming soon)</div>
</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/denisvuyka.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/denisvuyka.wordpress.com/244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/denisvuyka.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/denisvuyka.wordpress.com/244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/denisvuyka.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/denisvuyka.wordpress.com/244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/denisvuyka.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/denisvuyka.wordpress.com/244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/denisvuyka.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/denisvuyka.wordpress.com/244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/denisvuyka.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/denisvuyka.wordpress.com/244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/denisvuyka.wordpress.com/244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/denisvuyka.wordpress.com/244/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=244&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://denisvuyka.wordpress.com/2010/05/19/dynamic-silverlight-forms-embedding-s-scripts-into-xaml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/032cdef00bc6c528b24517b137c97660?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Denis</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/05/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/05/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/05/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/05/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/05/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/05/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/05/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/05/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/05/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/05/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>S# 2.0 features. It&#8217;s all about performance, dynamics and integration.</title>
		<link>http://denisvuyka.wordpress.com/2010/03/21/s-2-0-features-its-all-about-performance-dynamics-and-integration/</link>
		<comments>http://denisvuyka.wordpress.com/2010/03/21/s-2-0-features-its-all-about-performance-dynamics-and-integration/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 15:35:00 +0000</pubDate>
		<dc:creator>Denis Vuyka</dc:creator>
				<category><![CDATA[S#]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[C# 4.0]]></category>
		<category><![CDATA[DLR]]></category>

		<guid isPermaLink="false">http://denisvuyka.wordpress.com/2010/03/21/s-2-0-features-its-all-about-performance-dynamics-and-integration/</guid>
		<description><![CDATA[In this article I would like to give you some details towards next version (2.0) of the S# language and scripting runtime. Version 2.x will be based on .NET 4.0 and will be supported separately of Version 1.x that is still built on the top of .NET 3.5. Both versions will have a set of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=219&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this article I would like to give you some details towards next version (2.0) of the <a href="www.orbifold.net/ssharp" target="_blank">S# language and scripting runtime</a>. </p>
<p align="justify">Version 2.x will be based on .NET 4.0 and will be supported separately of Version 1.x that is still built on the top of .NET 3.5. Both versions will have a set of common features powered by both .NET 3.5 and .NET 4.0 however version 2.x will introduce a set of brand new capabilities built on the top of .NET 4.0 only. The entire 2.x family will be backward compatible. There will be no breaking changes in the scripts and migration difficulties.</p>
<h2>Performance</h2>
<p align="justify">A lot of work is related to script execution performance. S# runtime is used in various reporting and visualization tools where execution time of large or repetitive blocks is very important. Version 2 provides tremendous improvements and optimizations in comparison to Version 1.0.</p>
<p align="justify">Here’s one of our comparison benchmarks for basic loops (execution results are given in <strong>milliseconds</strong>)</p>
<table border="0" cellspacing="0" cellpadding="2" width="596">
<tbody>
<tr>
<td valign="top" width="501"><strong>Script</strong></td>
<td valign="top" width="29"><strong>v.1</strong></td>
<td valign="top" width="34"><strong>v.2</strong></td>
<td valign="top" width="30"><strong>%</strong></td>
</tr>
<tr>
<td valign="top" width="501">for (i = 0; i &lt;= 100000; i++) { }</td>
<td valign="top" width="29">48.7</td>
<td valign="top" width="34">26.7</td>
<td valign="top" width="30">182</td>
</tr>
<tr>
<td valign="top" width="501">for (i = 0; i &lt;= 100000; i = i + 1) { }</td>
<td valign="top" width="29">63.84</td>
<td valign="top" width="34">41.38</td>
<td valign="top" width="30">154</td>
</tr>
<tr>
<td valign="top" width="501">for (i = 0; i &lt;= 100000; i++) {&#160; i.ToString(); }</td>
<td valign="top" width="29">4129.5</td>
<td valign="top" width="34">227.06</td>
<td valign="top" width="30">1517</td>
</tr>
<tr>
<td valign="top" width="501">a = [1,2,3]; x = 0; for (i = 0; i &lt; 100000; i++) { x = a[1]; }</td>
<td valign="top" width="29">1571.1</td>
<td valign="top" width="34">72.62</td>
<td valign="top" width="30">2164</td>
</tr>
<tr>
<td valign="top" width="501">a = [1,2,3]; for (i = 0; i &lt; 100000; i++) { a[0] = i; }</td>
<td valign="top" width="29">2630.9</td>
<td valign="top" width="34">87.38</td>
<td valign="top" width="30">3011</td>
</tr>
<tr>
<td valign="top" width="501">x = null; p = new Person(); for (i = 0; i &lt; 100000; i++) { x = p[&quot;testme&quot;]; }</td>
<td valign="top" width="29">1242.8</td>
<td valign="top" width="34">75.56</td>
<td valign="top" width="30">1645</td>
</tr>
<tr>
<td valign="top" width="501">x = null; p = new Person(); for (i = 0; i &lt; 100000; i++) { p[&quot;name&quot;] = &quot;test&quot;; }</td>
<td valign="top" width="29">1322.8</td>
<td valign="top" width="34">82.2</td>
<td valign="top" width="30">1609</td>
</tr>
<tr>
<td valign="top" width="501">for (i = 0; i &lt;= 100000; i++) { i.ToString(null); }</td>
<td valign="top" width="29">3257.8</td>
<td valign="top" width="34">773.06</td>
<td valign="top" width="30">421.4</td>
</tr>
</tbody>
</table>
<p>As you can see the performance improvements for loops, method calls and array manipulations range from <strong>200%</strong> for <strong>3000%</strong> and this is not the complete list.</p>
<p>Here’s the graphical charts for the first 50 calls of each script benchmark (vertical axis is given in milliseconds):</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/03/image.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/03/image_thumb.png?w=1206&#038;h=511" width="1206" height="511" /></a> </p>
</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/03/image1.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/03/image_thumb1.png?w=1206&#038;h=511" width="1206" height="511" /></a> </p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/03/image2.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/03/image_thumb2.png?w=1206&#038;h=511" width="1206" height="511" /></a> </p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/03/image3.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/03/image_thumb3.png?w=1206&#038;h=511" width="1206" height="511" /></a> </p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/03/image4.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/03/image_thumb4.png?w=1206&#038;h=511" width="1206" height="511" /></a> </p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/03/image5.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/03/image_thumb5.png?w=1206&#038;h=511" width="1206" height="511" /></a> </p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/03/image6.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/03/image_thumb6.png?w=1206&#038;h=511" width="1206" height="511" /></a> </p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/03/image7.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/03/image_thumb7.png?w=1206&#038;h=511" width="1206" height="511" /></a></p>
<p>All the tests were performed on Windows 7 Ultimate ( x64), Intel Core 2 Duo T9400, 2.5GHz, 4GB RAM </p>
<h2>Dynamics</h2>
<p>I’m glad to announce that S# 2.0 will support “dynamic” objects powered by .NET 4.0 and its DLR (Dynamic Language Runtime) part. There will be a new type alias called “dynamic” that will allow you creating objects on the fly similar to the following sample:</p>
<table border="0" cellspacing="0" cellpadding="2" width="186">
<tbody>
<tr>
<td valign="top" width="184"><strong><em>person = new dynamic();              <br />person.Name = “John Doe”;               <br />person.Age = 40;</em></strong></td>
</tr>
</tbody>
</table>
<p>This should significantly improve scripting experience an reduce efforts required to perform complex reporting or visualization scripts as types can be created dynamically during script execution instead of creating custom types and registering them within the runtime host.</p>
<p>The performance of dynamic objects is also very important for us. For the moment object property access (both getting and setting property value) is much quicker than of plain CLR type:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/03/image8.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/03/image_thumb8.png?w=1206&#038;h=511" width="1206" height="511" /></a> </p>
<p>&#160;</p>
<h2>Integration</h2>
<p>You will get more samples related to S# integration with other technologies and products. Soon there will be a set of articles regarding new features in S# for WPF and Silverlight, Microsoft Office 2007/2010 etc.</p>
<p>S# framework will provide a new libraries targeting OpenXml SDK 2.0 reuse within the scripts. It will be possible getting and setting data for Microsoft Excel 2010 document by accessing cells in scripts similar to the following way:</p>
<table border="0" cellspacing="0" cellpadding="2" width="323">
<tbody>
<tr>
<td valign="top" width="321"><strong><em>workbook = new Workbook(“Book1.xslx”);              <br />workbook.Sheet1.A1 = “Hello world”;               <br />workbook.Sheet1.A2 = 100;               <br />workbook.Sheet1.B1 = workbook.Sheet1.A2 + 200;</em></strong></td>
</tr>
</tbody>
</table>
<p>More news are on the way…</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/denisvuyka.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/denisvuyka.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/denisvuyka.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/denisvuyka.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/denisvuyka.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/denisvuyka.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/denisvuyka.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/denisvuyka.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/denisvuyka.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/denisvuyka.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/denisvuyka.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/denisvuyka.wordpress.com/219/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/denisvuyka.wordpress.com/219/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/denisvuyka.wordpress.com/219/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=219&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://denisvuyka.wordpress.com/2010/03/21/s-2-0-features-its-all-about-performance-dynamics-and-integration/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/032cdef00bc6c528b24517b137c97660?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Denis</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/03/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/03/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/03/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/03/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

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

		<media:content url="http://denisvuyka.files.wordpress.com/2010/03/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

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

		<media:content url="http://denisvuyka.files.wordpress.com/2010/03/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/03/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Dynamic event handlers for Xaml-only Silverlight content (XamlReader, &#8220;Ramora&#8221; pattern and MEF)</title>
		<link>http://denisvuyka.wordpress.com/2010/02/21/dynamic-event-handlers-for-xaml-only-silverlight-content-xamlreader-ramora-pattern-and-mef/</link>
		<comments>http://denisvuyka.wordpress.com/2010/02/21/dynamic-event-handlers-for-xaml-only-silverlight-content-xamlreader-ramora-pattern-and-mef/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 10:50:00 +0000</pubDate>
		<dc:creator>Denis Vuyka</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[MEF]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[XamlReader]]></category>

		<guid isPermaLink="false">http://denisvuyka.wordpress.com/2010/02/21/dynamic-event-handlers-for-xaml-only-silverlight-content-xamlreader-ramora-pattern-and-mef/</guid>
		<description><![CDATA[The complete source code for the article can be found here. &#160; Since developers started using XamlReader and XamlWriter in WPF the question towards events and event handlers seem to be one of the most hottest both for WPF and Silverlight. In this article I’m going to show you one of the possible ways to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=200&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em><strong>The complete source code for the article can be found </strong></em><a href="http://www.box.net/shared/hvbp5l8dnb" target="_blank"><em><strong>here</strong></em></a><em><strong>.</strong></em></p>
<p align="justify">&#160;</p>
<p align="justify">Since developers started using XamlReader and XamlWriter in WPF the question towards events and event handlers seem to be one of the most hottest both for WPF and Silverlight. In this article I’m going to show you one of the possible ways to provide event handlers for Silverlight controls that are instantiated from a Xaml dynamically by means of XamlReader. I will be using MEF Preview 9 to glue parts together in my sample.</p>
<p>Imagine the following scenario: </p>
<p>&#160;</p>
<p align="justify">Some “business form” is designed within some thick/thin client and deployed to a server-side repository (database) as a string representation of xaml. Later on a Silverlight client loads this form data, turns into live UI layout and presents to a user. There is a set of logic should be involved during the “business form” life cycle taking into account such events as “Form Load”, “Submit Button Click”, “Cancel Button Click” etc. These events should be wired by the owner form during string-to-content conversion.</p>
<p align="justify"><em><strong>Hint</strong>: When a “business” form is being converted from its string-based representation to a live Silverlight content the types for resulting object graph are taken from the active application domain. This means that you can declare any type of control if you are sure the assembly containing this control is loaded during runtime. For example if your shell references “Silverlight Toolkit”, the XamlReader will allow you creating Charts from string-based content.</em></p>
<p align="justify"><em></em></p>
<p align="justify">I’ll be using the awesome “Ramora” pattern I’ve been a greatest fun of since it was suggested by <a href="http://blogs.msdn.com/bencon/archive/2006/07/26/679321.aspx" target="_blank">Ben Constable here</a>. The reason is that XamlReader provides support for Attached Properties for parsed content. This means that every Attached Property can serve as a some sort of entry point for application specific logic by means of “Ramora” pattern.</p>
<p align="justify">&#160;</p>
<p align="justify">You may want creating a separate “Silverlight Class Library” to hold contract classes and services that will be loaded during runtime and could be accessible by XamlReader when parsing strings. In my sample this library will be called “XamlOnlyUtils” but you can call it whatever you want.</p>
<p align="justify">&#160;</p>
<p><strong>Customizing Export attribute to suit our needs</strong></p>
<p><strong></strong></p>
<p align="justify">Latest MEF previews unseal “ExportAttribute” in order to support highly customizable solutions and allow hiding MEF from the “end-developer” levels. For more details please refer to “<strong><a href="http://mef.codeplex.com/wikipage?title=Exports%20and%20Metadata&amp;referringTitle=Guide" target="_blank">Exports and Metadata</a></strong>” section in MEF documentation.</p>
<p align="justify">&#160;</p>
<p align="justify">I’ve created an application specific attribute that will allow you exporting event handlers:</p>
<p><strong><em>“XamlEventHandlerAttribute.cs”</em></strong></p>
<pre class="code"><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>System.ComponentModel.Composition;
<span style="color:blue;">using </span>System.Windows;

<span style="color:blue;">namespace </span>XamlOnlyUtils
{
  [<span style="color:#2b91af;">MetadataAttribute</span>]
  [<span style="color:#2b91af;">AttributeUsage</span>(<span style="color:#2b91af;">AttributeTargets</span>.Method, AllowMultiple = <span style="color:blue;">false</span>, Inherited = <span style="color:blue;">false</span>)]
  <span style="color:blue;">public sealed class </span><span style="color:#2b91af;">XamlEventHandlerAttribute </span>: <span style="color:#2b91af;">ExportAttribute
  </span>{
    <span style="color:blue;">public string </span>Name { <span style="color:blue;">get</span>; <span style="color:blue;">private set</span>; }

    <span style="color:blue;">public </span>XamlEventHandlerAttribute(<span style="color:blue;">string </span>name)
      : <span style="color:blue;">base</span>(<span style="color:#a31515;">&quot;XamlEventHandlers&quot;</span>, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">DependencyObject</span>&gt;))
    {
      <span style="color:blue;">this</span>.Name = name;
    }
  }
}</pre>
<p align="justify">The attribute above will hold the “Name” of event handler and will be scoped by the “XamlEventHandlers” contract addressing &quot;”Action&lt;DependencyObject&gt;” handlers. This is a minimalistic implementation and you can easily modify it to cover complex scenarios later on.</p>
<p>As a result you will be able creating a handler that looks similar to that below:</p>
<pre class="code">[<span style="color:#2b91af;">XamlEventHandler</span>(<span style="color:#a31515;">&quot;CustomOnLoad&quot;</span>)]
   <span style="color:blue;">public void </span>CustomOnLoadHandler(<span style="color:#2b91af;">DependencyObject </span>sender)
   {
     <span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">&quot;Loosely bound event handler fired!&quot;</span>);
   }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>&#160;</p>
<p><strong>Providing strongly-typed metadata</strong></p>
<p>&#160;</p>
<p>To simplify handlers discovery and invokation I’ve created a simple interface to expose “Name” property of each imported action:</p>
<pre class="code"><span style="color:blue;">namespace </span>XamlOnlyUtils
{
  <span style="color:blue;">public interface </span><span style="color:#2b91af;">IXamlEventHandlerMetadata
  </span>{
    <span style="color:blue;">string </span>Name { <span style="color:blue;">get</span>; }
  }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>If you want getting more details towards strongly-typed metadata and its usage please refer to “<strong><a href="http://mef.codeplex.com/wikipage?title=Exports%20and%20Metadata&amp;referringTitle=Guide" target="_blank">Exports and Metadata</a></strong>” section in MEF documentation.</p>
<p>&#160;</p>
<p><strong></strong></p>
<p><strong>Creating and consuming a simple event</strong></p>
<p><strong></strong></p>
<p>Now we need exposing “<strong><a href="http://blogs.msdn.com/bencon/archive/2006/07/26/679321.aspx" target="_blank">Ramora</a></strong>” pattern to instrument a simple “Loaded” event. Let’s assume we want handling the “<strong>FrameworkElement.Loaded</strong>” event in a dynamic way.</p>
<p>Create a new Dependency object in the “XamlOnlyUtils” library and call it “XamlEventServices”:</p>
<pre class="code"><span style="color:blue;">public class </span><span style="color:#2b91af;">XamlEventServices </span>: <span style="color:#2b91af;">DependencyObject</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>This class will store all attached properties required to accomplish the task. I’ve inherited it from a DependencyObject in order to have access to Dispatcher in future.</p>
<p>Now let’s define a simple “Loaded” event handler. It will be an attached property holding the name of the handler:</p>
<pre class="code"><span style="color:blue;">public static readonly </span><span style="color:#2b91af;">DependencyProperty </span>OnLoadedProperty =
     <span style="color:#2b91af;">DependencyProperty</span>.RegisterAttached(
       <span style="color:#a31515;">&quot;OnLoaded&quot;</span>,
       <span style="color:blue;">typeof</span>(<span style="color:blue;">string</span>),
       <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">XamlEventServices</span>),
       <span style="color:blue;">new </span><span style="color:#2b91af;">PropertyMetadata</span>(<span style="color:blue;">null</span>, OnLoadedPropertyChanged));</pre>
<p><a href="http://11011.net/software/vspaste"></a>Exposing getter and setter in the common way:</p>
<pre class="code"><span style="color:blue;">public static string </span>GetOnLoaded(<span style="color:#2b91af;">DependencyObject </span>target)
    {
      <span style="color:blue;">return </span>(<span style="color:blue;">string</span>)target.GetValue(OnLoadedProperty);
    }

    <span style="color:blue;">public static void </span>SetOnLoaded(<span style="color:#2b91af;">DependencyObject </span>target, <span style="color:blue;">string </span>value)
    {
      target.SetValue(OnLoadedProperty, value);
    }</pre>
<p align="justify">As you might have noticed I’m declaring a “property change” handler called “OnLoadedPropertyChanged” for attached property. This is where the “<strong><a href="http://blogs.msdn.com/bencon/archive/2006/07/26/679321.aspx" target="_blank">Ramora</a></strong>” implementation begins. The idea is to wire additional logic as soon as “OnLoaded” attached property is defined for an object. As XamlReader takes care of parsing and assigning attached properties we can be sure that event handler will be fired during parsing phase and we’ll get the expected entry point.</p>
<p>Here’s how the implementation of “OnLoadedPropertyChanged” handler looks like on my side:</p>
<pre class="code"><span style="color:blue;">private static void </span>OnLoadedPropertyChanged(
      <span style="color:#2b91af;">DependencyObject </span>sender,
      <span style="color:#2b91af;">DependencyPropertyChangedEventArgs </span>e)
    {
      <span style="color:#2b91af;">FrameworkElement </span>fe = sender <span style="color:blue;">as </span><span style="color:#2b91af;">FrameworkElement</span>;
      <span style="color:blue;">if </span>(fe == <span style="color:blue;">null</span>) <span style="color:blue;">return</span>;

      <span style="color:blue;">bool </span>wasWired = (e.OldValue != <span style="color:blue;">null</span>);
      <span style="color:blue;">bool </span>needsWiring = (e.NewValue != <span style="color:blue;">null</span>);

      <span style="color:blue;">if </span>(wasWired) fe.Loaded -= OnLoadedHandler;
      <span style="color:blue;">if </span>(needsWiring) fe.Loaded += OnLoadedHandler;
    }</pre>
<p><a href="http://11011.net/software/vspaste"></a>This method wires “FrameworkElement.Loaded” event upon every attached property value change and covers 2 scenarios at once. It can either wire a new event handler if the property has changed for the first time or unwire the previously assigned handler if we want removing it by passing null value.</p>
<p>&#160;</p>
<p>Here’s how my “FrameworkElement.Loaded” handler looks like:</p>
<pre class="code"><span style="color:blue;">static void </span>OnLoadedHandler(<span style="color:blue;">object </span>sender, <span style="color:#2b91af;">RoutedEventArgs </span>e)
   {
     <span style="color:#2b91af;">DependencyObject </span>dobj = sender <span style="color:blue;">as </span><span style="color:#2b91af;">DependencyObject</span>;
     <span style="color:blue;">if </span>(dobj == <span style="color:blue;">null</span>) <span style="color:blue;">return</span>;

     <span style="color:blue;">string </span>handlerName = GetOnLoaded(dobj);
     <span style="color:blue;">if </span>(<span style="color:blue;">string</span>.IsNullOrEmpty(handlerName)) <span style="color:blue;">return</span>;

     <span style="color:blue;">var </span>resolver = <span style="color:blue;">new </span><span style="color:#2b91af;">EventHandlersResolver</span>();
     <span style="color:#2b91af;">CompositionInitializer</span>.SatisfyImports(resolver);

     <span style="color:blue;">var </span>handlers = resolver.EventHandlers
       .Where(row =&gt; row.Metadata.Name.Equals(
         handlerName, <span style="color:#2b91af;">StringComparison</span>.InvariantCultureIgnoreCase));

     <span style="color:blue;">foreach </span>(<span style="color:blue;">var </span>handler <span style="color:blue;">in </span>handlers)
       handler.Value(dobj);
   }</pre>
<p align="justify"><a href="http://11011.net/software/vspaste"></a>Couple of details towards the code above: the first thing I’m trying to do is to get the name of the handler that was defined via the attached property. After that I create a &quot;resolver” class that will hold all the external actions marked with “XamlEventHandlerAttribute”. After satisfying all imports for this resolver (simply getting all the action exports) I enumerate the result to find the actions matching the name defined by attached property and invoke every found action. This means that you can have multiple actions being fired for a single event. </p>
<p align="justify">&#160;</p>
<p align="justify"><strong>Resolving exported actions</strong></p>
<p align="justify">&#160;</p>
<p align="justify">Attached properties is a world of statics. The property holder class (in my case it is “XamlEventServices”) is not instantiated each time a dependency property is used so it is quite difficult satisfying imports on it. I strongly recommend following MEF team suggestions not to try wiring static classes with MEF bus as It brings out additional implications in the future. Instead I’m using the “resolver” class and satisfy imports on the fly. Here’s how my simple resolver looks like:</p>
<p align="justify">&#160;</p>
<pre class="code"><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>System.ComponentModel.Composition;
<span style="color:blue;">using </span>System.Windows;

<span style="color:blue;">namespace </span>XamlOnlyUtils
{
  <span style="color:blue;">public class </span><span style="color:#2b91af;">EventHandlersResolver
  </span>{
    [<span style="color:#2b91af;">ImportMany</span>(<span style="color:#a31515;">&quot;XamlEventHandlers&quot;</span>, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">DependencyObject</span>&gt;))]
    <span style="color:blue;">public </span><span style="color:#2b91af;">Lazy</span>&lt;<span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">DependencyObject</span>&gt;, <span style="color:#2b91af;">IXamlEventHandlerMetadata</span>&gt;[] EventHandlers { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
  }
}</pre>
<p>It contains a single property collecting all “Action&lt;DependencyObject&gt;” exports scoped by “XamlEventHandlers” contract. You don’t need enabling recomposition here because imports will be collected dynamically when “FrameworkElement.Loaded” event is fired.</p>
<p>&#160;</p>
<p><strong>Testing loose handlers on “live” control</strong></p>
<p>&#160;</p>
<p align="justify">To ensure the loose event handler binding actually works you can do the following steps. Create a new Silverlight Application and reference the “contract” assembly “XamlOnlyUtils” (you can add reference to a project if you create application in the same solution).</p>
<p align="justify">&#160;</p>
<p align="justify">Go to the code behind of the “MainForm.xaml” (“MainForm.xaml.cs”) and declare the following method:</p>
<pre class="code">[<span style="color:#2b91af;">XamlEventHandler</span>(<span style="color:#a31515;">&quot;CustomOnLoad&quot;</span>)]
   <span style="color:blue;">public void </span>CustomOnLoadHandler(<span style="color:#2b91af;">DependencyObject </span>sender)
   {
     <span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">&quot;Loosely bound event handler fired!&quot;</span>);
   }</pre>
<p><a href="http://11011.net/software/vspaste"></a>You’ll be showing a dummy message box to ensure the infrastructure is working. Now return back to the xaml side and assign the “OnLoaded” attached property directly for the main form like on the screenshot below:</p>
<p>&#160;</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/02/image.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/02/image_thumb.png?w=443&#038;h=133" width="443" height="133" /></a> </p>
<p>&#160;</p>
<p align="justify">The workflow you expect to be executed is as follows: when the “OnLoaded” attached property is assigned, our “XamlEventServices” will attach a custom handler to control’s native “Loaded” event. As soon as control is loaded and a corresponding event is fired, “XamlEventServices” will resolve the imports for handler actions, find any action named as “CustomOnLoad” and execute them.</p>
<p align="justify">&#160;</p>
<p align="justify"><strong>Configuring MEF for application</strong></p>
<p align="justify">&#160;</p>
<p align="justify">In order the sample above to work as expected you will need to actually enable MEF for the application. As my “MainForm.xaml.cs” contains some actions that need to be exported, I’ve decided to export the entire form to be able satisfying all the imports easily. For this purpose I’m marking “MainForm” with “ExportAttribute”:</p>
<p align="justify">&#160;</p>
<pre class="code">[<span style="color:#2b91af;">Export</span>]
<span style="color:blue;">public partial class </span><span style="color:#2b91af;">MainPage </span>: <span style="color:#2b91af;">UserControl
</span>{</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p align="justify">&#160;</p>
<p align="justify">After that you will need opening the “App.xaml.cs” to configure composition host and satisfy imports (providing all the corresponding exports we are interested in). Here are the changes I’ve made to accomplish that:</p>
<p align="justify">&#160;</p>
<p align="justify">1. Importing form into the application class:</p>
<p align="justify">&#160;</p>
<pre class="code"><span style="color:blue;">public partial class </span><span style="color:#2b91af;">App </span>: <span style="color:#2b91af;">Application
 </span>{
   [<span style="color:#2b91af;">Import</span>]
   <span style="color:blue;">public </span><span style="color:#2b91af;">MainPage </span>MainPage { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p align="justify">&#160;</p>
<p align="justify">2. Rewiring root visual to the form being imported:</p>
<p align="justify">&#160;</p>
<pre class="code"><span style="color:blue;">private void </span>Application_Startup(<span style="color:blue;">object </span>sender, <span style="color:#2b91af;">StartupEventArgs </span>e)
   {
     <span style="color:blue;">this</span>.RootVisual = <span style="color:blue;">this</span>.MainPage;
   }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p align="justify">&#160;</p>
<p align="justify">3. Finally providing a quick configuration of MEF including both assemblies I’ve been working with:</p>
<p align="justify">&#160;</p>
<p align="justify"><a href="http://denisvuyka.files.wordpress.com/2010/02/image1.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/02/image_thumb1.png?w=418&#038;h=251" width="418" height="251" /></a> </p>
<p align="justify">&#160;</p>
<p align="justify"><em>Note: for more details towards MEF hosting please refer to “<strong><a href="http://mef.codeplex.com/wikipage?title=Hosting%20MEF%20and%20the%20Container&amp;referringTitle=Guide" target="_blank">Hosting MEF in an application</a></strong>” section of MEF documentation.</em></p>
</p>
<p>&#160;</p>
<p>I assume that both projects I’ve been demonstrating already contain references to MEF “Composition” and “Initialization” for Silverlight assemblies:</p>
<p>&#160;</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/02/image2.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/02/image_thumb2.png?w=327&#038;h=185" width="327" height="185" /></a> </p>
<p>&#160;</p>
<p>When running the application you should see the Message Box displayed by “CustomOnLoadHandler” defined in the code behind of the main form:</p>
<p>&#160;</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/02/image3.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/02/image_thumb3.png?w=259&#038;h=163" width="259" height="163" /></a> </p>
<p>&#160;</p>
<p align="justify">This means that the loose infrastructure is working as expected. The method was successfully exported, discovered and fired.</p>
<p align="justify">&#160;</p>
<p align="justify">&#160;</p>
</p>
<p><strong>Testing XamlReader and string-based xaml content</strong></p>
<p>&#160;</p>
<p>Now we need turning some string-based content into the live object graph and ensure the events can be wired during XamlReader parsing phase. I’ve changed the main form to contain a test Button that will start string-to-xaml conversion and a placeholder to put the resulting UI into:</p>
<p>&#160;</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/02/image4.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/02/image_thumb4.png?w=569&#038;h=340" width="569" height="340" /></a> </p>
<p>&#160;</p>
<p>Here’s the sample content I will be trying to process:</p>
<p>&#160;</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/02/image5.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/02/image_thumb5.png?w=464&#038;h=215" width="464" height="215" /></a> </p>
<p>&#160;</p>
<p>As I’ve mentioned at the beginning of the article, I can freely rely on the attached properties that are present within the application domain during runtime. I’ve imported a namespace from the “contract” library and configured “OnLoaded” attached property to point to the “CustomOnLoad” action that is expected to be defined somewhere in the hosting application.</p>
<p>&#160;</p>
<p>Finally I provide some logic for “btnLoadXaml” Button Click handler:</p>
<p>&#160;</p>
<pre class="code"><span style="color:blue;">private void </span>btnLoadXaml_Click(<span style="color:blue;">object </span>sender, <span style="color:#2b91af;">RoutedEventArgs </span>e)
  {
    <span style="color:#2b91af;">FrameworkElement </span>fe = <span style="color:#2b91af;">XamlReader</span>.Load(XamlContent) <span style="color:blue;">as </span><span style="color:#2b91af;">FrameworkElement</span>;
    <span style="color:blue;">if </span>(fe != <span style="color:blue;">null</span>)
      <span style="color:blue;">this</span>.xamlContainer.Content = fe;
  }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>&#160;</p>
<p>In the code above I turn “XamlContent” string into a fully-fledged object graph (with all the attached properties processed) and assign the result to the Content property of my “xamlContainer” placeholder. As soon as It is done, the UI will be loaded and a corresponding “Loaded” event will be fired so causing the “OnCustomLoad” action be discovered and executed.</p>
<p>&#160;</p>
<p>As soon as you click the “Load Xaml” button you should see the following result:</p>
<p>&#160;</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/02/image6.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/02/image_thumb6.png?w=461&#038;h=254" width="461" height="254" /></a> </p>
<p>&#160;</p>
<p>This article dwells on the very basic scenarios to demonstrate the things working indeed. Feel free extending it to support more complex scenarios.</p>
<p>&#160;</p>
<p><em><strong>The complete source code for the article can be found </strong></em><a href="http://www.box.net/shared/hvbp5l8dnb" target="_blank"><em><strong>here</strong></em></a><em><strong>.</strong></em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/denisvuyka.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/denisvuyka.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/denisvuyka.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/denisvuyka.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/denisvuyka.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/denisvuyka.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/denisvuyka.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/denisvuyka.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/denisvuyka.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/denisvuyka.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/denisvuyka.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/denisvuyka.wordpress.com/200/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/denisvuyka.wordpress.com/200/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/denisvuyka.wordpress.com/200/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=200&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://denisvuyka.wordpress.com/2010/02/21/dynamic-event-handlers-for-xaml-only-silverlight-content-xamlreader-ramora-pattern-and-mef/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/032cdef00bc6c528b24517b137c97660?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Denis</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/02/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/02/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/02/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/02/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/02/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/02/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/02/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>S# 1.3 is out with .NET Compact Framework 3.5 support</title>
		<link>http://denisvuyka.wordpress.com/2010/01/24/s-1-3-is-out-with-net-compact-framework-3-5-support/</link>
		<comments>http://denisvuyka.wordpress.com/2010/01/24/s-1-3-is-out-with-net-compact-framework-3-5-support/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 18:32:00 +0000</pubDate>
		<dc:creator>Denis Vuyka</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Compact Framework]]></category>
		<category><![CDATA[S#]]></category>

		<guid isPermaLink="false">http://denisvuyka.wordpress.com/2010/01/24/s-1-3-is-out-with-net-compact-framework-3-5-support/</guid>
		<description><![CDATA[I would like to announce that tomorrow we are releasing an updated version of S# Scripting Runtime (version 1.3) containing a set of bug fixes, performance and API enhancements and .NET CF 3.5 support. Please refer to the official product page for getting more details and latest installation package. Starting from now you will be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=185&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I would like to announce that tomorrow we are releasing an updated version of S# Scripting Runtime (version 1.3) containing a set of bug fixes, performance and API enhancements and .NET CF 3.5 support.</p>
<p>Please refer to the <a href="http://www.orbifold.net/ssharp/" target="_blank">official product page</a> for getting more details and latest installation package. </p>
<p>Starting from now you will be able enriching your mobile software with rich capabilities of S# scripting. Here’s a couple of screenshots:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/01/image.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/01/image_thumb.png?w=362&#038;h=600" width="362" height="600" /></a></p>
<p>S# allows you creating content dynamically on the fly and that should be extremely valuable in various scenarios:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/01/image1.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/01/image_thumb1.png?w=361&#038;h=596" width="361" height="596" /></a> </p>
<p>Execution of the script above will create a new Form with a TextBox control on it:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/01/image2.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/01/image_thumb2.png?w=359&#038;h=599" width="359" height="599" /></a> </p>
<p>The sample above requires only 3 lines of code </p>
</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/01/image3.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/01/image_thumb3.png?w=525&#038;h=461" width="525" height="461" /></a> </p>
<p>Also we’ve updated the setup package to simplify your development efforts. The corresponding assembly will be automatically displayed within the “Add reference” dialog in Visual Studio:</p>
<p><a href="http://denisvuyka.files.wordpress.com/2010/01/image4.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://denisvuyka.files.wordpress.com/2010/01/image_thumb4.png?w=1114&#038;h=557" width="1114" height="557" /></a></p>
</p>
<p>Please refer to the <a href="http://www.orbifold.net/ssharp/" target="_blank">official product page</a> for getting more details and latest installation package. </p>
<p>Any feedback, suggestions or ideas are much appreciated.</p>
<p>Happy coding!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/denisvuyka.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/denisvuyka.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/denisvuyka.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/denisvuyka.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/denisvuyka.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/denisvuyka.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/denisvuyka.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/denisvuyka.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/denisvuyka.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/denisvuyka.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/denisvuyka.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/denisvuyka.wordpress.com/185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/denisvuyka.wordpress.com/185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/denisvuyka.wordpress.com/185/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=185&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://denisvuyka.wordpress.com/2010/01/24/s-1-3-is-out-with-net-compact-framework-3-5-support/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/032cdef00bc6c528b24517b137c97660?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Denis</media:title>
		</media:content>

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

		<media:content url="http://denisvuyka.files.wordpress.com/2010/01/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/01/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/01/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://denisvuyka.files.wordpress.com/2010/01/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Building refactoring-friendly observable objects in C#</title>
		<link>http://denisvuyka.wordpress.com/2009/12/09/building-refactoring-friendly-observable-objects-in-c/</link>
		<comments>http://denisvuyka.wordpress.com/2009/12/09/building-refactoring-friendly-observable-objects-in-c/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 18:45:00 +0000</pubDate>
		<dc:creator>Denis Vuyka</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[INotifyPropertyChanged]]></category>
		<category><![CDATA[Linq]]></category>

		<guid isPermaLink="false">http://denisvuyka.wordpress.com/2009/12/09/building-refactoring-friendly-observable-objects-in-c/</guid>
		<description><![CDATA[INotifyPropertyChanged is one the most frequently used .NET interfaces nowadays. I use this interface every day within the models in all kinds of applications: Windows Forms, WPF, Silverlight. However there is one disadvantage in using INotifyPropertyChanged I have to deal with very often – it is not “refactoring-friendly” and requires a lot of efforts when [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=173&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify"><strong>INotifyPropertyChanged</strong> is one the most frequently used .NET interfaces nowadays. I use this interface every day within the models in all kinds of applications: Windows Forms, WPF, Silverlight. </p>
<p align="justify">However there is one disadvantage in using INotifyPropertyChanged I have to deal with very often – it is not “refactoring-friendly” and requires a lot of efforts when supporting large scalable enterprise applications/frameworks. </p>
<p align="justify">Here’s a skeleton of a common observable object exposing INotifyPropertyChanged interface we all usually deal with:</p>
<pre class="code"><span style="color:blue;">public class </span><span style="color:#2b91af;">MyCommonObject </span>: <span style="color:#2b91af;">INotifyPropertyChanged
</span>{
  <span style="color:blue;">#region </span>INotifyPropertyChanged Members

  <span style="color:blue;">public event </span><span style="color:#2b91af;">PropertyChangedEventHandler </span>PropertyChanged;

  <span style="color:blue;">protected void </span>OnPropertyChanged(<span style="color:blue;">string </span>propertyName)
  {
    <span style="color:blue;">var </span>handler = PropertyChanged;
    <span style="color:blue;">if </span>(handler != <span style="color:blue;">null</span>)
      handler(<span style="color:blue;">this</span>, <span style="color:blue;">new </span><span style="color:#2b91af;">PropertyChangedEventArgs</span>(propertyName));
  }

  <span style="color:blue;">#endregion
</span>}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>&#160;</p>
<p>Now let’s take a “Name” property that supports value change notifications:</p>
<pre class="code"><span style="color:blue;">public class </span><span style="color:#2b91af;">MyCommonObject </span>: <span style="color:#2b91af;">INotifyPropertyChanged
</span>{
  <span style="color:blue;">private string </span>_Name;

  <span style="color:blue;">public string </span>Name
  {
    <span style="color:blue;">get </span>{ <span style="color:blue;">return </span>_Name; }
    <span style="color:blue;">set
    </span>{
      <span style="color:blue;">if </span>(_Name == <span style="color:blue;">value</span>) <span style="color:blue;">return</span>;
      _Name = <span style="color:blue;">value</span>;
      OnPropertyChanged(<span style="color:#a31515;">&quot;Name&quot;</span>);
    }
  }

  <span style="color:blue;">#region </span>INotifyPropertyChanged Members
  <span style="color:blue;">#endregion
</span>}</pre>
<p>&#160;</p>
<p align="justify">When you want to rename “Name” property above to something like “FirstName” using some refactoring tool the notification will work properly only when the “OnPropertyChanged” call argument is changed as well. It is quite easy to change the code above to call <strong>OnPropertyChanged(“FirstName”)</strong> but it’s not so easy when you deal with hundreds of objects with possibly hundreds of properties spread over more than one project/solution. Sometimes it is not only the property who notifies about value changes and this makes the refactoring/support task extremely difficult and error-prone.</p>
<p align="justify">Being tired of searching broken “OnPropertyChanged” occurrences I’ve started to think over modifying this pattern in order to make it “refactoring-aware”. I wanted to pass something like a “pointer” to the property rather than it’s name so that each time the property name is changed the “pointer” does not require additional tuning. After trying out several approaches I finally found the one that perfectly suits my needs. </p>
<p align="justify"><strong>Linq Expressions to the rescue…</strong></p>
<p align="justify">I’ve decided to reuse Linq Expressions and lambda Functions in order to pass a strongly-typed reference to the object’s property for the “OnPropertyChanged” method. I ended with the following modification of basic “INotifyPropertyChanged” implementation:</p>
<pre class="code"><span style="color:blue;">public class </span><span style="color:#2b91af;">ObservableObject</span>&lt;T&gt; : <span style="color:#2b91af;">INotifyPropertyChanged
</span>{
  <span style="color:blue;">public event </span><span style="color:#2b91af;">PropertyChangedEventHandler </span>PropertyChanged;

  <span style="color:blue;">protected virtual void </span>OnPropertyChanged(<span style="color:#2b91af;">Expression</span>&lt;<span style="color:#2b91af;">Func</span>&lt;T, <span style="color:blue;">object</span>&gt;&gt; property)
  {
    <span style="color:blue;">if </span>(property == <span style="color:blue;">null </span>|| property.Body == <span style="color:blue;">null</span>) <span style="color:blue;">return</span>;

    <span style="color:blue;">var </span>memberExp = property.Body <span style="color:blue;">as </span><span style="color:#2b91af;">MemberExpression</span>;
    <span style="color:blue;">if </span>(memberExp == <span style="color:blue;">null</span>) <span style="color:blue;">return</span>;

    <span style="color:blue;">var </span>handler = PropertyChanged;
    <span style="color:blue;">if </span>(handler != <span style="color:blue;">null</span>)
      handler(<span style="color:blue;">this</span>, <span style="color:blue;">new </span><span style="color:#2b91af;">PropertyChangedEventArgs</span>(memberExp.Member.Name));
  }</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>As you can see “OnPropertyChanged” method was changed to receive <strong>Expression&lt;Func&lt;T, object&gt;&gt;</strong> instead of a string-based property name.</p>
<p>You don’t need compiling or executing this expression. The primary goal is accessing its <strong>Body</strong> that is represented by a <strong>MemberExpression</strong>. MemberExpression instance wraps a common “<strong>System.Reflection.MemberInfo</strong>” as a Member property and so it is obvious that you can get the actual name of the property based on reflection and create a proper event arguments on the fly.</p>
<p><strong><em>Note: This is a basic implementation and does not consider various possible scenarios. I simply exit method execution if things go the unexpected way. You may want providing some exceptions or error handling.</em></strong></p>
<p>As you may have noticed I’ve provided a generic class implementation that can be consumed by my objects. Here’s a basic sample of the object consuming modified pattern:</p>
<pre class="code"><span style="color:blue;">public class </span><span style="color:#2b91af;">MyObject </span>: <span style="color:#2b91af;">ObservableObject</span>&lt;<span style="color:#2b91af;">MyObject</span>&gt;
{
  <span style="color:blue;">private bool </span>_BoolProperty;
  <span style="color:blue;">public bool </span>BoolProperty
  {
    <span style="color:blue;">get </span>{ <span style="color:blue;">return </span>_BoolProperty; }
    <span style="color:blue;">set
    </span>{
      <span style="color:blue;">if </span>(_BoolProperty == <span style="color:blue;">value</span>) <span style="color:blue;">return</span>;
      _BoolProperty = <span style="color:blue;">value</span>;
      OnPropertyChanged(@this =&gt; @this.BoolProperty);
    }
  }

  <span style="color:blue;">private int </span>_IntProperty;
  <span style="color:blue;">public int </span>IntProperty
  {
    <span style="color:blue;">get </span>{ <span style="color:blue;">return </span>_IntProperty; }
    <span style="color:blue;">set
    </span>{
      <span style="color:blue;">if </span>(_IntProperty == <span style="color:blue;">value</span>) <span style="color:blue;">return</span>;
      _IntProperty = <span style="color:blue;">value</span>;
      OnPropertyChanged(@this =&gt; @this.IntProperty);
    }
  }

  <span style="color:blue;">private string </span>_StringProperty;
  <span style="color:blue;">public string </span>StringProperty
  {
    <span style="color:blue;">get </span>{ <span style="color:blue;">return </span>_StringProperty; }
    <span style="color:blue;">set
    </span>{
      <span style="color:blue;">if </span>(_StringProperty == <span style="color:blue;">value</span>) <span style="color:blue;">return</span>;
      _StringProperty = <span style="color:blue;">value</span>;
      OnPropertyChanged(@this =&gt; @this.StringProperty);
    }
  }

  <span style="color:blue;">private object </span>_ObjectProperty;
  <span style="color:blue;">public object </span>ObjectProperty
  {
    <span style="color:blue;">get </span>{ <span style="color:blue;">return </span>_ObjectProperty; }
    <span style="color:blue;">set
    </span>{
      <span style="color:blue;">if </span>(_ObjectProperty == <span style="color:blue;">value</span>) <span style="color:blue;">return</span>;
      _ObjectProperty = <span style="color:blue;">value</span>;
      OnPropertyChanged(@this =&gt; @this.ObjectProperty);
    }
  }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>&#160;</p>
<p>I guess the sample above does not need detailed comments. Instead of string-based property name you now pass the property. If you or someone else decides refactoring the name of the property all notification logic will be automatically updated. </p>
<p><strong>Proper implementation</strong></p>
<p>However when running the following test I found that the code above was not working as expected:</p>
<pre class="code"><span style="color:blue;">class </span><span style="color:#2b91af;">Program
</span>{
  <span style="color:blue;">static void </span>Main(<span style="color:blue;">string</span>[] args)
  {
    <span style="color:#2b91af;">MyObject </span>my = <span style="color:blue;">new </span><span style="color:#2b91af;">MyObject</span>();
    my.PropertyChanged += (sender, e) =&gt; <span style="color:#2b91af;">Console</span>.WriteLine(e.PropertyName);

    my.BoolProperty = <span style="color:blue;">true</span>;
    my.IntProperty = 100;
    my.StringProperty = <span style="color:#a31515;">&quot;something&quot;</span>;
    my.ObjectProperty = 100;

    <span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">&quot;Press Enter to exit...&quot;</span>);
    <span style="color:#2b91af;">Console</span>.ReadLine();
  }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a>I was receiving only notifications for “StringProperty” and “ObjectProperty” properties, but nothing for “BoolProperty” and “IntProperty”.</p>
<p align="justify">After some investigation I found out that my problem was in “object” declaration in Expression&lt;Func&lt;T,object&gt;&gt;. Linq wraps value type instances with additional “Convert” expression so my check for “MemberExpression” was receiving null value during type casting.</p>
<p align="justify">This produced another slight modification that covered all aspects of expression passing:</p>
<pre class="code"><span style="color:blue;">public class </span><span style="color:#2b91af;">ObservableObject</span>&lt;T&gt; : <span style="color:#2b91af;">INotifyPropertyChanged
</span>{
  <span style="color:blue;">public event </span><span style="color:#2b91af;">PropertyChangedEventHandler </span>PropertyChanged;

  <span style="color:blue;">protected virtual void </span>OnPropertyChanged(<span style="color:#2b91af;">Expression</span>&lt;<span style="color:#2b91af;">Func</span>&lt;T, <span style="color:blue;">object</span>&gt;&gt; property)
  {
    <span style="color:blue;">if </span>(property == <span style="color:blue;">null </span>|| property.Body == <span style="color:blue;">null</span>) <span style="color:blue;">return</span>;

    <span style="color:blue;">var </span>memberExp = property.Body <span style="color:blue;">as </span><span style="color:#2b91af;">MemberExpression</span>;
    <span style="color:blue;">if </span>(memberExp == <span style="color:blue;">null</span>)
    {
      <span style="color:#2b91af;">UnaryExpression </span>unary = property.Body <span style="color:blue;">as </span><span style="color:#2b91af;">UnaryExpression</span>;
      <span style="color:blue;">if </span>(unary != <span style="color:blue;">null</span>) memberExp = unary.Operand <span style="color:blue;">as </span><span style="color:#2b91af;">MemberExpression</span>;
      <span style="color:blue;">if </span>(memberExp == <span style="color:blue;">null</span>) <span style="color:blue;">return</span>;
    }

    <span style="color:blue;">var </span>handler = PropertyChanged;
    <span style="color:blue;">if </span>(handler != <span style="color:blue;">null</span>)
      handler(<span style="color:blue;">this</span>, <span style="color:blue;">new </span><span style="color:#2b91af;">PropertyChangedEventArgs</span>(memberExp.Member.Name));
  }
}</pre>
<p align="justify">As you can see I’ve added a fallback step to check whether an Unary Expression is actually being received. In this case I’m taking it’s Operand as the expected Member expression and this works like magic. Now my test output is correct and provides notification for all the properties.</p>
<p><strong>Notes</strong></p>
<p align="justify">The approach above consumes more CPU cycles than the common INotifyPropertyChanged use so it might slightly decrease performance. However I’m sure it may greatly reduce the cost of code support in future and save your time and money.</p>
<p>Feel free playing with the <a href="http://www.box.net/shared/cuy146884h">source code</a> for this article.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/denisvuyka.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/denisvuyka.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/denisvuyka.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/denisvuyka.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/denisvuyka.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/denisvuyka.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/denisvuyka.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/denisvuyka.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/denisvuyka.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/denisvuyka.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/denisvuyka.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/denisvuyka.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/denisvuyka.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/denisvuyka.wordpress.com/173/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=173&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://denisvuyka.wordpress.com/2009/12/09/building-refactoring-friendly-observable-objects-in-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/032cdef00bc6c528b24517b137c97660?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Denis</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows Automation: Automating Windows 7 Notepad within S# Script</title>
		<link>http://denisvuyka.wordpress.com/2009/12/08/windows-automation-automating-windows-7-notepad-within-s-script/</link>
		<comments>http://denisvuyka.wordpress.com/2009/12/08/windows-automation-automating-windows-7-notepad-within-s-script/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 15:40:29 +0000</pubDate>
		<dc:creator>Denis Vuyka</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://denisvuyka.wordpress.com/?p=168</guid>
		<description><![CDATA[Today we have updated S# with another sample covering the use of Windows Automation API from within a common S# script. Auto# (AutoSharp) This is a demo project shows how easily your S# scripts can be enhanced with a set of functions that target Windows UI Automation API and the ways of forming a QA-friendly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=168&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today we have updated S# with another sample covering the use of Windows Automation API from within a common S# script.
</p>
<p><strong>Auto# (AutoSharp)<br />
</strong></p>
<p>This is a demo project shows how easily your S# scripts can be enhanced with a set of functions that target Windows UI Automation API and the ways of forming a QA-friendly language on the top of S# runtime. Full source code for this sample is available within the latest S# runtime update <a href="http://www.orbifold.net/Downloads/SSharp/Orbifold.SSharp.Runtime.exe">here</a>.
</p>
<p><strong>Note: Sample project targets Windows 7 Notepad and may not work properly on other versions of Windows because of control ids difference.</strong>
	</p>
<p>To find Windows Automation API for your version of Windows please refer to <a href="http://support.microsoft.com/kb/971513/">this article</a>.
</p>
<p>Auto# introduces 9 functions that provide Windows Automation support S# scripts:
</p>
<ul>
<li><strong>Kill</strong> – close all running instances of some process
</li>
<li><strong>Launch</strong> – launch a new process and return its main window
</li>
<li><strong>Wait</strong> – sleep for some time, often required when waiting application response
</li>
<li><strong>FindByClassName</strong> – finds element by Class Name
</li>
<li><strong>FindById</strong> – finds element by Automation ID
</li>
<li><strong>FindByName</strong> – finds element by its Name
</li>
<li><strong>Expand</strong> – expands menu element
</li>
<li><strong>InvokeById</strong> – invokes element by Automation ID
</li>
<li><strong>FocusEditor</strong> – focuses textbox editor
</li>
</ul>
<p>The following workflow is executed in order to automate Notepad:
</p>
<ol>
<li>Kill all running Notepad instances
</li>
<li>Launch a new Notepad process
</li>
<li>Type some text
</li>
<li>Click &#8220;File&#8221; – &#8220;Save As&#8221; in the main menu
</li>
<li>Type destination file name
</li>
<li>Agree to overwrite existing file if confirmation dialog appears
</li>
<li>Click &#8220;File&#8221; – &#8220;Exit&#8221; to close Notepad
</li>
</ol>
<p>Here&#8217;s how the S# script may look like:
</p>
<div>
<table style="border-collapse:collapse;background:#eeece1;" border="0">
<col>
<tbody valign="top">
<tr>
<td style="padding-left:7px;padding-right:7px;border-top:solid .5pt;border-left:solid .5pt;border-bottom:solid .5pt;border-right:solid .5pt;">
<p><span style="color:#00b050;">// Close existing instances of Notepad<br />
</span></p>
<p><strong>Kill</strong>(&#8220;notepad&#8221;);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Launch a new Notepad instance and get main window<br />
</span></p>
<p>window = <strong>Launch</strong>(&#8220;notepad&#8221;);
</p>
<p><span style="color:#00b050;">// Wait 1 second<br />
</span></p>
<p><strong>Wait</strong>(1000);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Get main editor region<br />
</span></p>
<p>edit = <strong>FindByClassName</strong>(window, &#8220;Edit&#8221;);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// focus main editor<br />
</span></p>
<p><strong>FocusEditor</strong>(edit);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Send sample text to the editor region<br />
</span></p>
<p>SendKeys.SendWait(&#8220;Automating Notepad using Windows UI Automation and S#&#8221;);
</p>
<p><strong>Wait</strong>(3000);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Find [File] menu<br />
</span></p>
<p>mnuFile = <strong>FindById</strong>(window, &#8220;Item 1&#8243;);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Expand [File] menu<br />
</span></p>
<p><strong>Expand</strong>(mnuFile);
</p>
<p><strong>Wait</strong>(1000);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Invoke [Save As] menu item<br />
</span></p>
<p><strong>InvokeById</strong>(window, &#8220;Item 4&#8243;);
</p>
<p><strong>Wait</strong>(1000);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Get [Save As] dialog<br />
</span></p>
<p>saveAsDialog = <strong>FindByName</strong>(window, &#8220;Save As&#8221;);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Get access to [FileName] textbox<br />
</span></p>
<p>saveAsName = <strong>FindById</strong>(saveAsDialog, &#8220;1001&#8243;);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Focus filename editor           </span>
						</p>
<p><strong>FocusEditor</strong>(saveAsName);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Write down file name<br />
</span></p>
<p>SendKeys.SendWait(&#8220;D:\\MyTextFile&#8221;);
</p>
<p><span style="color:#00b050;">// Send [Enter] keypress<br />
</span></p>
<p>SendKeys.SendWait(&#8220;{ENTER}&#8221;);
</p>
<p><strong>Wait</strong>(1000);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Check whether Overwrite Dialog appeared<br />
</span></p>
<p>confirmSaveAs = <strong>FindByName</strong>(saveAsDialog, &#8220;Confirm Save As&#8221;);
</p>
<p>if (confirmSaveAs != null)
</p>
<p>{
</p>
<p>    // Click [OK] button
</p>
<p>    <strong>InvokeById</strong>(confirmSaveAs, &#8220;CommandButton_6&#8243;);
</p>
<p>    <strong>Wait</strong>(1000);
</p>
<p>}
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Expand [File] menu<br />
</span></p>
<p><strong>Expand</strong>(mnuFile);
</p>
<p><strong>Wait</strong>(1000);
</p>
<p>
 </p>
<p><span style="color:#00b050;">// Click [Exit] item<br />
</span></p>
<p><strong>InvokeById</strong>(window, &#8220;Item 7&#8243;);
</p>
<p>         </p>
</td>
</tr>
</tbody>
</table>
</div>
<p>
 </p>
<p>Demo project also includes a very simply UI providing possibility to alter the script above and execute it.
</p>
<p>Unleash your fantasy <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/denisvuyka.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/denisvuyka.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/denisvuyka.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/denisvuyka.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/denisvuyka.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/denisvuyka.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/denisvuyka.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/denisvuyka.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/denisvuyka.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/denisvuyka.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/denisvuyka.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/denisvuyka.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/denisvuyka.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/denisvuyka.wordpress.com/168/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=denisvuyka.wordpress.com&amp;blog=4724773&amp;post=168&amp;subd=denisvuyka&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://denisvuyka.wordpress.com/2009/12/08/windows-automation-automating-windows-7-notepad-within-s-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/032cdef00bc6c528b24517b137c97660?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Denis</media:title>
		</media:content>
	</item>
	</channel>
</rss>
