Answered by:
What does "MarkAsDirty" mean

Question
-
What does "MarkAsDirty" mean? I never seen that before. below is the code I first seen this:
public bool Successful { get { return this.successful; } set { if (this.successful != value) { this.successful = value; MarkAsDirty("Successful"); } } }
Wednesday, March 14, 2012 7:11 PM
Answers
-
Hi bthumber,
From your code I think this MarkAsDirty looks like a custom method that fires the INotifyPropertyChanged.PropertyChanged, like the OnNotityPropertyChanged method in the following code.
public class Figure : INotifyPropertyChanged { protected void OnNotifyPropertyChanged(string p) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(p)); } } public event PropertyChangedEventHandler PropertyChanged; int _Num; public int Num { get { return _Num; } set { if (_Num != value) { _Num = value; OnNotifyPropertyChanged("Num"); } } } }
Best regards,Min Zhu [MSFT]
MSDN Community Support | Feedback to us
- Marked as answer by Min Zhu Thursday, March 22, 2012 6:24 AM
Thursday, March 15, 2012 1:45 AM -
On 3/14/2012 3:11 PM, bthumber wrote:> What does "MarkAsDirty" mean? I never seen that before. below is the> code I first seen this:>> public bool Successful> {> get { return this.successful; }> set> {> if (this.successful != value)> {> this.successful = value;> MarkAsDirty("Successful");> }> }> }>>From an object oriented programming standpoint and working with acustom object that has state and using a public property, it means thatthe object's state has been set to a dirty state indicating the data haschanged within the object. The MarkAsDirty() in this case is setting theobject's state to a dirty state.An object's state can be the following based on the following Booleanflags within the object.1) IsNew2) IsDirty3) IsDeleteIn the persistence of the object to a database, the state of the objectwill tell a Data Access Layer how to persist the object to the databasebased on the following:1) IsNew && IsDirty -- insert the new object into the database2) !IsNew && IsDirty -- update the existing object in the database3) IsDelete -- object is to be deleted from the databaseWhen the object is first instantiated, the IsDirty and IsDelete stateflags are set to false, and the IsNew is set to true.When you populate the object from existing data for the first time, themethods MakkOld() -- sets IsNew to false and MarkClean() -- sets theIsDirty to false. This sets the object's state to it's old or anexisting object and it is not dirty. You do the MarkClean(), because thesetter for the object will firer and mark the object as dirty when youpopulate the object with existing data from the database. So you markthe object as old, and you mark the object as not dirty in this situation.Now something changes data with an object's public property, setter onthe public property firers and the MarkDirty() firers setting theobject's state to dirty.The only way something is going to be done to persist the object forinsert or update is the object's state must be set to dirty based on theobject's property data has changed, and its dirty state has changed toreflect that the object dirty and is saveable.
- Proposed as answer by Pete LakerMVP Thursday, March 15, 2012 12:39 PM
- Marked as answer by Min Zhu Thursday, March 22, 2012 6:24 AM
Thursday, March 15, 2012 9:51 AM -
All of which makes sense.
Not to pick a fight or anything...
But that's all guesswork.
The only way to know what that method does is to look at the code.
It could alternatively be a strangely named implementation of notifypropertychanged, as Min suggested.
Or it might be a mix of both, calling notifypropertychanged.
Or anything.
- Marked as answer by Min Zhu Thursday, March 22, 2012 6:24 AM
Thursday, March 15, 2012 12:05 PM
All replies
-
It means he has a method called markasdirty.Wednesday, March 14, 2012 8:36 PM
-
It certanly has nothing to do with WPF... Ask over at the C# forum
Kenneth
Thursday, March 15, 2012 12:43 AM -
Hi bthumber,
From your code I think this MarkAsDirty looks like a custom method that fires the INotifyPropertyChanged.PropertyChanged, like the OnNotityPropertyChanged method in the following code.
public class Figure : INotifyPropertyChanged { protected void OnNotifyPropertyChanged(string p) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(p)); } } public event PropertyChangedEventHandler PropertyChanged; int _Num; public int Num { get { return _Num; } set { if (_Num != value) { _Num = value; OnNotifyPropertyChanged("Num"); } } } }
Best regards,Min Zhu [MSFT]
MSDN Community Support | Feedback to us
- Marked as answer by Min Zhu Thursday, March 22, 2012 6:24 AM
Thursday, March 15, 2012 1:45 AM -
On 3/14/2012 3:11 PM, bthumber wrote:> What does "MarkAsDirty" mean? I never seen that before. below is the> code I first seen this:>> public bool Successful> {> get { return this.successful; }> set> {> if (this.successful != value)> {> this.successful = value;> MarkAsDirty("Successful");> }> }> }>>From an object oriented programming standpoint and working with acustom object that has state and using a public property, it means thatthe object's state has been set to a dirty state indicating the data haschanged within the object. The MarkAsDirty() in this case is setting theobject's state to a dirty state.An object's state can be the following based on the following Booleanflags within the object.1) IsNew2) IsDirty3) IsDeleteIn the persistence of the object to a database, the state of the objectwill tell a Data Access Layer how to persist the object to the databasebased on the following:1) IsNew && IsDirty -- insert the new object into the database2) !IsNew && IsDirty -- update the existing object in the database3) IsDelete -- object is to be deleted from the databaseWhen the object is first instantiated, the IsDirty and IsDelete stateflags are set to false, and the IsNew is set to true.When you populate the object from existing data for the first time, themethods MakkOld() -- sets IsNew to false and MarkClean() -- sets theIsDirty to false. This sets the object's state to it's old or anexisting object and it is not dirty. You do the MarkClean(), because thesetter for the object will firer and mark the object as dirty when youpopulate the object with existing data from the database. So you markthe object as old, and you mark the object as not dirty in this situation.Now something changes data with an object's public property, setter onthe public property firers and the MarkDirty() firers setting theobject's state to dirty.The only way something is going to be done to persist the object forinsert or update is the object's state must be set to dirty based on theobject's property data has changed, and its dirty state has changed toreflect that the object dirty and is saveable.
- Proposed as answer by Pete LakerMVP Thursday, March 15, 2012 12:39 PM
- Marked as answer by Min Zhu Thursday, March 22, 2012 6:24 AM
Thursday, March 15, 2012 9:51 AM -
All of which makes sense.
Not to pick a fight or anything...
But that's all guesswork.
The only way to know what that method does is to look at the code.
It could alternatively be a strangely named implementation of notifypropertychanged, as Min suggested.
Or it might be a mix of both, calling notifypropertychanged.
Or anything.
- Marked as answer by Min Zhu Thursday, March 22, 2012 6:24 AM
Thursday, March 15, 2012 12:05 PM -
Hi bthember,
Just checking in to see if the information was helpful. Please let us know if you would like further assistance.
Have a great day!
Min Zhu [MSFT]
MSDN Community Support | Feedback to us
Monday, March 19, 2012 2:05 AM