<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Refactor Safe Implementation Of INotifyPropertyChanged</title>
	<atom:link href="http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/feed/" rel="self" type="application/rss+xml" />
	<link>http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/</link>
	<description>Trying to walk that thin line between intelligence and ignorance</description>
	<lastBuildDate>Fri, 12 Mar 2010 18:56:09 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: sean kearon</title>
		<link>http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/comment-page-1/#comment-22445</link>
		<dc:creator>sean kearon</dc:creator>
		<pubDate>Thu, 03 Sep 2009 15:12:45 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1483#comment-22445</guid>
		<description>Hi Davy

Great article and a great approach to avoiding strings.  The approach I take is to use AOP and let &lt;a href=&quot;www.postsharp.org&quot; rel=&quot;nofollow&quot;&gt;PostSharp&lt;/a&gt; do the work at compile time.  Design time you have code that looks something like:

&lt;code&gt;
[NotifyChanges]
public string Name { get; set }
&lt;/code&gt;

Alternatively, you can take a convention approach and put an attribute on the assembly (using a property attribute to exclude properties that should not publish notifications).  I have a couple of posts linked below that illustrate the approach and there is more on the &lt;a href=&quot;www.postsharp.org&quot; rel=&quot;nofollow&quot;&gt;PostSharp&lt;/a&gt; website.

Cheers

Sean

http://kearon.blogspot.com/2008/10/using-c-automatic-properties-with-xpo_27.html
http://kearon.blogspot.com/2008/10/using-c-automatic-properties-with-xpo.html</description>
		<content:encoded><![CDATA[<p>Hi Davy</p>
<p>Great article and a great approach to avoiding strings.  The approach I take is to use AOP and let <a href="www.postsharp.org" rel="nofollow">PostSharp</a> do the work at compile time.  Design time you have code that looks something like:</p>
<p><code><br />
[NotifyChanges]<br />
public string Name { get; set }<br />
</code></p>
<p>Alternatively, you can take a convention approach and put an attribute on the assembly (using a property attribute to exclude properties that should not publish notifications).  I have a couple of posts linked below that illustrate the approach and there is more on the <a href="www.postsharp.org" rel="nofollow">PostSharp</a> website.</p>
<p>Cheers</p>
<p>Sean</p>
<p><a href="http://kearon.blogspot.com/2008/10/using-c-automatic-properties-with-xpo_27.html" rel="nofollow">http://kearon.blogspot.com/2008/10/using-c-automatic-properties-with-xpo_27.html</a><br />
<a href="http://kearon.blogspot.com/2008/10/using-c-automatic-properties-with-xpo.html" rel="nofollow">http://kearon.blogspot.com/2008/10/using-c-automatic-properties-with-xpo.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nima</title>
		<link>http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/comment-page-1/#comment-22367</link>
		<dc:creator>Nima</dc:creator>
		<pubDate>Sat, 29 Aug 2009 05:47:42 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1483#comment-22367</guid>
		<description>OK I get it. It seems that if an UnaryExpression is given we should use its Operand to get its MemberExpression.
&lt;code&gt;
var memberExpression =(expression.Body is UnaryExpression? expression.Body.Operand :expression.Body) as MemberExpression;
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>OK I get it. It seems that if an UnaryExpression is given we should use its Operand to get its MemberExpression.<br />
<code><br />
var memberExpression =(expression.Body is UnaryExpression? expression.Body.Operand :expression.Body) as MemberExpression;<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nima</title>
		<link>http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/comment-page-1/#comment-22366</link>
		<dc:creator>Nima</dc:creator>
		<pubDate>Sat, 29 Aug 2009 05:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1483#comment-22366</guid>
		<description>Thanks for your post!
I think that I&#039;m doing something wrong.As long as I pass a non struct property ( a string property for example) everything is fine but when I try to pass a struct property (an integer or a boolean) It won&#039;t get a MemberExpression but some other type of expression (UnaryExpression for example)</description>
		<content:encoded><![CDATA[<p>Thanks for your post!<br />
I think that I&#8217;m doing something wrong.As long as I pass a non struct property ( a string property for example) everything is fine but when I try to pass a struct property (an integer or a boolean) It won&#8217;t get a MemberExpression but some other type of expression (UnaryExpression for example)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/comment-page-1/#comment-22282</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Tue, 18 Aug 2009 18:43:42 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1483#comment-22282</guid>
		<description>there was only a performance penalty noticeable after triggering the event a couple of thousands times.  obviously, if you&#039;re doing that you&#039;ve probably got bigger problems to worry about than the performance overhead of using an expression instead of a string ;)</description>
		<content:encoded><![CDATA[<p>there was only a performance penalty noticeable after triggering the event a couple of thousands times.  obviously, if you&#8217;re doing that you&#8217;ve probably got bigger problems to worry about than the performance overhead of using an expression instead of a string <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/comment-page-1/#comment-22281</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Tue, 18 Aug 2009 18:38:38 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1483#comment-22281</guid>
		<description>Interesting idea, I&#039;m still trying to digest it.

What kind of overhead does this create? Performance or dependencies?


Right now, I&#039;m just unit testing to verify the PropertyChanged event is thrown with the correct property name.  (Very similiar to your AssertThatPropertyChangedIsCorrect)</description>
		<content:encoded><![CDATA[<p>Interesting idea, I&#8217;m still trying to digest it.</p>
<p>What kind of overhead does this create? Performance or dependencies?</p>
<p>Right now, I&#8217;m just unit testing to verify the PropertyChanged event is thrown with the correct property name.  (Very similiar to your AssertThatPropertyChangedIsCorrect)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/comment-page-1/#comment-22254</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Fri, 07 Aug 2009 04:46:04 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1483#comment-22254</guid>
		<description>passing the propertyname as a string was exactly what we were trying to get away from :)
it&#039;s actually less typing now because of the intellisense support.</description>
		<content:encoded><![CDATA[<p>passing the propertyname as a string was exactly what we were trying to get away from <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
it&#8217;s actually less typing now because of the intellisense support.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frederik</title>
		<link>http://davybrion.com/blog/2009/08/refactor-safe-implementation-of-inotifypropertychanged/comment-page-1/#comment-22252</link>
		<dc:creator>Frederik</dc:creator>
		<pubDate>Thu, 06 Aug 2009 23:27:06 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1483#comment-22252</guid>
		<description>Although I fully understand the advantage of this (I also hate hardcoded strings in my code, and I&#039;ve annoyed myself over this INotifyPropertyChanged implementation as well), I still think that this is some kind of cumbersome solution.  
I think that the code becomes less readable.

For the moment, I do it like this:
In my base class which implements INotifyPropertyChanged, I also have a method called &#039;PropertyChanged&#039;, which looks like a bit like this (from the top of my head):

&lt;code&gt;
protected void PropertyChanged( string propertyName )
{
    if( String.IsNullOrEmpty (propertyName) )
    {
         throw new ArgumentNullException (propertyName);
    }

    #if DEBUG

    if( !PropertyExists (propertyName) )
    {
         throw new ArgumentException (&quot;No such property&quot;, propertyName);
    }

    #endif

    PropertyChanged (this, new PropertyChangedEventArgs(propertyName));
}
&lt;/code&gt;

The PropertyExists method uses reflection in order to check whether the class has a property with the given name.  (But I&#039;m sure you&#039;ve guessed this already ;) ).</description>
		<content:encoded><![CDATA[<p>Although I fully understand the advantage of this (I also hate hardcoded strings in my code, and I&#8217;ve annoyed myself over this INotifyPropertyChanged implementation as well), I still think that this is some kind of cumbersome solution.<br />
I think that the code becomes less readable.</p>
<p>For the moment, I do it like this:<br />
In my base class which implements INotifyPropertyChanged, I also have a method called &#8216;PropertyChanged&#8217;, which looks like a bit like this (from the top of my head):</p>
<p><code><br />
protected void PropertyChanged( string propertyName )<br />
{<br />
    if( String.IsNullOrEmpty (propertyName) )<br />
    {<br />
         throw new ArgumentNullException (propertyName);<br />
    }</p>
<p>    #if DEBUG</p>
<p>    if( !PropertyExists (propertyName) )<br />
    {<br />
         throw new ArgumentException ("No such property", propertyName);<br />
    }</p>
<p>    #endif</p>
<p>    PropertyChanged (this, new PropertyChangedEventArgs(propertyName));<br />
}<br />
</code></p>
<p>The PropertyExists method uses reflection in order to check whether the class has a property with the given name.  (But I&#8217;m sure you&#8217;ve guessed this already <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
