Actually, it's only 3-4 lines per property; the other lines are amortized over all "notifying" properties:
class Person : INotifyPropertyChanged
{
#region INotifyPropertyChanged: Shared bit
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
PropertyChanged(this, e);
}
#endregion
private string _firstName;
public string FirstName
{
get { return _firstName; }
set
{
if (_firstName == value)
return;
_firstName = value;
OnPropertyChanged(new PropertyChangedEventArgs("FirstName"));
}
}
// Ditto for other properties
}
You could try something like the following, which shares some more of the load:
private string _firstName;
public string FirstName
{
get { return _firstName; }
set { SetNotifyingProperty("FirstName", ref _firstName, value); }
}
private void SetNotifyingProperty<T>(string propertyName,
ref T field, T value)
{
if (value.Equals(field))
return;
field = value;
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}