IsDirty using INotifyPropertyChanged

First, let me say that I just come across this code from a pluralsight author and it doesn't make sense to me.

So the code in question is ObjectBase class that implements INotifyPropertyChanged.

We have IsDirty property in ObjectBase…

public class ObjectBase : INotifyPropertyChanged { #region INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; protected virtual void RaisePropertyChanged([CallerMemberName] string propertyName = "") { RaisePropertyChanged(true, propertyName); } protected virtual void RaisePropertyChanged(bool makeDirty, [CallerMemberName] string propertyName = "") { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); if (makeDirty) { isDirty = true; } } #endregion private bool isDirty; public bool IsDirty { get { return isDirty; } } } 

Now, this seems wrong to me because as soon as you set any property it becomes dirty, but how would you get a clean object with data inside it and consider it clean?

by Karmadilla via /r/csharp

Leave a Reply