<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog &#124; Limilabs &#187; AOP</title>
	<atom:link href="http://www.limilabs.com/blog/category/aop/feed" rel="self" type="application/rss+xml" />
	<link>http://www.limilabs.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 21 May 2012 09:49:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Introducing PostSharp to your team</title>
		<link>http://www.limilabs.com/blog/introducing-postsharp-to-your-team?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=introducing-postsharp-to-your-team</link>
		<comments>http://www.limilabs.com/blog/introducing-postsharp-to-your-team#comments</comments>
		<pubDate>Wed, 16 Sep 2009 12:17:30 +0000</pubDate>
		<dc:creator>Limilabs support</dc:creator>
				<category><![CDATA[AOP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[PostSharp]]></category>

		<guid isPermaLink="false">http://www.limilabs.com/blog/?p=30</guid>
		<description><![CDATA[PostSharp is AOP (Aspect-Oriented-Programming) framework (www.sharpcrafters.com). It transparently inserts itself in the build process and post-processes the compiled assembly. To enable PostSharp in your project you need to download and run the PostSharp installer, and add appropriate references in your project. However if your project is in SVN, and you are not the only one [...]]]></description>
			<content:encoded><![CDATA[<p>      PostSharp is <strong>AOP</strong> (Aspect-Oriented-Programming) framework (<a href="http://www.sharpcrafters.com" rel="nofollow">www.sharpcrafters.com</a>).<br />
It transparently inserts itself in the build process and post-processes the compiled assembly.</p>
<p>To enable PostSharp in your project you need to download and run the PostSharp installer, and add appropriate references in your project.</p>
<p>However if your project is in SVN, and you are not the only one compiling it (other developers, CI machine) most likely you don&#8217;t want to run PostSharp installer on all the machines.</p>
<p>There is a way to introduce PostSharp <strong>transparently </strong> to your project.</p>
<ul>
<li>Put all the PostSharp files in the LibPostSharp folder of your project <strong>and add this folder to SVN</strong>.</li>
<li><strong>Modify the .csproj file</strong>: After the last ItemGroup following xml must be inserted: </li>
</ul>
<pre class="brush: xml;">
  &lt;propertyGroup&gt;
    &lt;dontImportPostSharp&gt;True&lt;/dontImportPostSharp&gt;
    &lt;!-- Add the next line if you are using Visual Studio 2010 --&gt;
    &lt;!-- &lt;postSharpUseCommandLine&gt;True&lt;/postSharpUseCommandLine&gt;--&gt;
  &lt;/propertyGroup&gt;
</pre>
<ul>
<li><strong>Modify the .csproj file</strong>: After the </li>
</ul>
<pre class="brush: xml;">
&lt;import Project=&quot;$(MSBuildToolsPath)Microsoft.CSharp.targets&quot; /&gt;
</pre>
<p>following xml must be inserted: </p>
<pre class="brush: xml;">
&lt;import Project=&quot;..LibPostSharpPostSharp.targets&quot; /&gt;
</pre>
<p>The whole change should be similar to this sample: </p>
<pre class="brush: xml;">
&lt;/itemGroup&gt;
  &lt;propertyGroup&gt;
    &lt;dontImportPostSharp&gt;True&lt;/dontImportPostSharp&gt;
  &lt;/propertyGroup&gt;
  &lt;import Project=&quot;$(MSBuildToolsPath)Microsoft.CSharp.targets&quot; /&gt;
  &lt;import Project=&quot;..LibPostSharpPostSharp-1.5.targets&quot; /&gt;
&lt;/project&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/introducing-postsharp-to-your-team/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>INotifyPropertyChanged with PostSharp 1.5</title>
		<link>http://www.limilabs.com/blog/inotifypropertychanged-with-postsharp?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=inotifypropertychanged-with-postsharp</link>
		<comments>http://www.limilabs.com/blog/inotifypropertychanged-with-postsharp#comments</comments>
		<pubDate>Tue, 15 Sep 2009 12:03:01 +0000</pubDate>
		<dc:creator>Limilabs support</dc:creator>
				<category><![CDATA[AOP]]></category>
		<category><![CDATA[Presentation]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[PostSharp]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.limilabs.com/blog/?p=14</guid>
		<description><![CDATA[If you are doing WPF development, most likely you are tired of writing property implementations that raise PropertyChanged event manually: public class MainWindowViewModel : ViewModel { private string _message; public string Message { get { return _message; } set { _message = value; OnPropertyChanged(&#34;Message&#34;); } } // ... } PostSharp is a great tool to [...]]]></description>
			<content:encoded><![CDATA[<p>If you are doing WPF development, most likely you are tired of writing property implementations that raise <em>PropertyChanged</em> event manually:</p>
<pre class="brush: csharp;">
public class MainWindowViewModel : ViewModel
{
    private string _message;

    public string Message
    {
        get
        {
            return _message;
        }
        set
        {
            _message = value;
            OnPropertyChanged(&quot;Message&quot;);
        }
    }

    // ...
}
</pre>
<p><a href="http://www.postsharp.org">PostSharp</a> is a great tool to make such things simplier.</p>
<p>Let&#8217;s look at the specific ViewModel class that has a <em>Message</em> property that is <strong>bound to some UI element</strong> using XAML:</p>
<pre class="brush: csharp;">
public class MainWindowViewModel : ViewModel
{
    [RaisePropertyChanged]
    public string Message { get; set; }

    // ...
}
</pre>
<p> Notice the <em>RaisePropertyChanged</em> attribute, which we&#8217;ll implement later.</p>
<p>Here&#8217;s our <strong>base ViewModel</strong> class that provides <strong>actual implementation</strong> of the <em>INotifyPropertyChanged</em> interface:</p>
<pre class="brush: csharp;">
public class ViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged
        = delegate { };

    public void OnPropertyChanged(string propertyName)
    {
        PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
    }
};
</pre>
<p>Finally the PostSharp attribute:</p>
<pre class="brush: csharp;">
[Serializable]  // required by PostSharp
public class RaisePropertyChangedAttribute : OnMethodBoundaryAspect
{
    private string _propertyName;

    /// &lt;summary&gt;
    /// Executed at runtime, after the method.
    /// &lt;/summary&gt;
    public override void OnExit(MethodExecutionEventArgs eventArgs)
    {
        ViewModel viewModel = (ViewModel)eventArgs.Instance;
        viewModel.OnPropertyChanged(_propertyName);
    }

    public override bool CompileTimeValidate(MethodBase method)
    {
        if (IsPropertySetter(method))
        {
            _propertyName = GetPropertyName(method);
            return true;
        }
        return false;
    }

    private static string GetPropertyName(MethodBase method)
    {
        return method.Name.Replace&quot;set_&quot;, &quot;&quot;);
    }

    private static bool IsPropertySetter(MethodBase method)
    {
        return method.Name.StartsWith(&quot;set_&quot;);
    }
};
</pre>
<p>Note that we are validating if the method is in fact a property only during <strong>compilation time</strong> using <em>CompileTimeValidate</em> method.</p>
<p>During compile time appropriate invocations of <em>OnPropertyChanged</em> method will be <strong>injected after every set operation</strong> applied to the <em>Message</em> property.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/inotifypropertychanged-with-postsharp/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

