This project has moved and is read-only. For the latest updates, please go here.

Refactoring friendly INotifyPropertyChanged

Oct 21, 2009 at 10:25 AM

Could something like be considered to make the handling of INotifyPropertyChanged a bit more refactor friendly compared to const strings.

Oct 27, 2009 at 9:17 PM


Thanks a lot for your comment. I considered many possibilities to avoid working with "magic strings" but my personal opinion is that using other alternatives (such as the one proposed in the link you mention) are rather complex and "frightening" for unexperienced programmers, who are a large target for the MVVM Light Toolkit. I will however add the following in V3:

This solution developed by Josh Smith (who is already a contributor to the MVVM Light Toolkit through the RelayCommand that he very nicely agreed to let me use) checks in DEBUG mode that a given property name actually exists on the calling object. This is, I think, a satisfying compromise. On one hand we keep the simplicity of using strings instead of harder-to-understand expressions, and on the other hand we get an error if a property name gets changed and some spots are missed where it is used.

Note that if you use the constant consistently throughout the code, you should be fine when you change a property name. The name itself is defined as a string only once, and all other references are checked at compilation.

Let me know if you think this is not good enough.



Apr 18, 2010 at 7:51 PM


As you are a previous user of the discussion tab on the MVVM Light Codeplex site, I would like to inform you that I decided to promote the usage of StackOverflow for questions regarding the MVVM Light toolkit. Please tag your questions with the mvvm-light tag.

StackOverflow is an awesome site where tons of developers help others with their technical question.

I will monitor this tag on the StackOverflow website and do my best to answer questions. The advantage of StackOverflow over the Codeplex discussion is the sheer number of qualified developers able to help you with your questions, the visibility of the question itself, and the whole StackOverflow infrastructure (reputation, up- or down-vote, comments, etc)



May 14, 2010 at 11:50 AM

Hi, I too also think this would be a good idea. If you feel its frightening for inexperienced programmers then why not a simple overload, best of both worlds?

In the meantime I am using this:


    public class ViewModelBaseExt : ViewModelBase
        public void RaisePropertyChanged<TProperty>(Expression<Func<TProperty>> propertyExpression)

        private static string GetMemberInfoName(Expression expression)
            var lambda = (LambdaExpression)expression;

            MemberExpression memberExpression;
            if (lambda.Body is UnaryExpression)
                var unaryExpression = (UnaryExpression)lambda.Body;
                memberExpression = (MemberExpression)unaryExpression.Operand;
            else memberExpression = (MemberExpression)lambda.Body;

            return memberExpression.Member.Name;