Improving the INotifiedPropertyChanged implementation

As you may have noticed from previous projects, our standard property implementation for handling property changes looks like the following:

private string _descriptionMessage = "Take a Picture";  
 
public string DescriptionMessage 
        { 
            get 
            { 
                return _descriptionMessage; 
            } 
 
            set 
            { 
                if (value.Equals(_descriptionMessage)) 
                { 
                    return; 
                } 
 
                _descriptionMessage = value; 
                OnPropertyChanged("DescriptionMessage"); 
            } 
        } 

The repeated code in every public property makes our view-model code look much bigger than it actually is. In all your code sheets, a good coding practice to think about is how you can reduce the amount of lines of code and, especially repeated code. The following function SetProperty is an example of ...

Get Xamarin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.