CodeRush Template for INotifyPropertyChanged

Updated 6/6/14: @MarkMiller found my tweet the referred to this blog post and kindly pointed out that I had reinvented the wheel. If your class implements INotifyPropertyChanged, you could use the standard “p(type)” expansion and it’ll put in the property change code for you. You can customize the setter to use your framework by editing the System / Declaration Bodies / #PropertySetter# template. Big kudos to Mark for noticing my tweet and helping me with this!

See this to see what it looks like in action.

Raising a PropertyChanged event for every property in a class is a lot of typing, and if you have CodeRush for Visual Studio the following template should help you out.

(You’ll have to edit the “this.NotifyPropertyChanged” line to fit the way you raise this event in your framework.)

Seems like I need this once every year or so, and have to reinvent it every time. Hopefully this will be a good spot for me to pull this from.

This entry was posted in CodeRush, Programming. Bookmark the permalink.
  • grmbl

    Hi Jason, bit late for a reply on this post. But check out C#5.0 Caller Info Attributes and especially the [CallerMemberName] one. 😉 I’m not familiar with CodeRush, how does it compare to ReSharper?

    • pettys

      Really excited for c# 5 to become mainstream so some of this repetitive gunk can be cleaned up!

      CodeRush and ReSharper are direct competitors with pros and cons for each one. I chose CodeRush years ago for reasons that are no longer relevant, but after investing so much in that tool I’m reluctant to switch.