I have a class which implements INotifyPropertyChanged. I have a property setter which triggers notification. But the C# compiler does not know/complain anything if I just use the field, and directly assign values. But if I do that property changed notification is completely useless. I am seeing this mistake being made quite often. SO my questions are
- How to verify if this mistake (setting filed value instead of using setter) is made in a large solution,
- How to force some kind of warning or errors when this happens
Since no question is complete without a code sample, here is the illustration of proplem
class Person : INotifyPropertyChanged
{
private string personName;
public string PersonName
{
get { return personName; }
set { if(personName!=value)
{
personName = value;
this.OnPropertyChanged ("PersonName");
}
}
}
public bool dummy()
{
personName = "not notified"; //need to detect/avoid this
}
}