PropertyChangedEvent using Static Reflection (Expression)

Feel free to correct me if this is a bad way of going about using static reflection… but I had a change to remove a ‘magic string’ and figured I’d use static reflection as a way around it.

I was working on a Silverlight sample of Two-way binding and re-reading some of John Papa’s Data-Driven Services with Silverlight 2 book where he is showing that in order to use two-way binding, you must implement the INotifyPropertyChanged interface.

In his book he shows a way to wrap up the duplicating code into a base class, ie:

image

To use this, the following must be done to the entity:

image

The problem I had with this is the ‘PropertyChangedHandler’ taking in a string that is to be the property name.

I’m sure there is a better way to handle this, but I decided to use some static reflection to hand it the property name:

image

Now, I can use this to replace the above “magic string”:

image

Advertisements

One thought on “PropertyChangedEvent using Static Reflection (Expression)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s