INotifyPropertyChanged Revisited with .Net Framework 4.5

Prior to this post, I have already discussed a few methods of handling the INotifyPropertyChanged interface. Now you might be thinking what's next?
Well, today I'll talk about the much better and a cleaner way of handling this interface, which is type-safe as well as less error prone. Till now, as a common practice, we were passing a property name as a parameter of our RaisedPropertyChanged method, which unfortunately has some demerits.
Let's say, what if the user changed the name of the property and forgot to change the parameter passed in the RaisedPropertyChanged method. Now, here, you may say that we can get rid of this by using the Reflection. Even I agree with this, but again, it comes with an additional associated cost. So, what's the solution now???
Enough of these worries; this issue has already been addressed in .Net 4.5, in which the developer can get rid of this parameter passing approach. Impressed?
An attribute titled the CallerMemberName relieves us from all the worries because this attribute retrieves the method and the property name for us. Let's have a look at the code now:

You will notice that the attribute has been applied with the parameters supplied for the RaisedPropertyChanged method. So, now the implementation of our property will be a lot simpler as:
Now, the user is not forced to pass the parameter to this RaisedPropertyChanged method. Hope you enjoyed learning this new feature.  

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now