locked
What does "MarkAsDirty" mean RRS feed

  • 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 a
    custom object that has state and using a public property, it means that
    the object's state has been set to a dirty state indicating the data has
    changed within the object. The MarkAsDirty() in this case is setting the
    object's state to a dirty state.
     
    An object's state can be the following based on the following Boolean
    flags within the object.
     1) IsNew
    2) IsDirty
    3) IsDelete
     
    In the persistence of the object to a database, the state of the object
    will tell a Data Access Layer how to persist the object to the database
    based on the following:
     
    1) IsNew && IsDirty -- insert the new object into the database
    2) !IsNew && IsDirty -- update the existing object in the database
    3) IsDelete -- object is to be deleted from the database
     
    When the object is first instantiated, the IsDirty and IsDelete state
    flags are set to false, and the IsNew is set to true.
     
    When you populate the object from existing data for the first time, the
    methods MakkOld() -- sets IsNew to false and MarkClean() -- sets the
    IsDirty to false. This sets the object's state to it's old or an
    existing object and it is not dirty. You do the MarkClean(), because the
    setter for the object will firer and mark the object as dirty when you
    populate the object with existing data from the database. So you mark
    the 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 on
    the public property firers and the MarkDirty() firers setting the
    object's state to dirty.
     
    The only way something is going to be done to persist the object for
    insert or update is the object's state must be set to dirty based on the
    object's property data has changed,  and  its dirty state has changed to
    reflect 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 a
    custom object that has state and using a public property, it means that
    the object's state has been set to a dirty state indicating the data has
    changed within the object. The MarkAsDirty() in this case is setting the
    object's state to a dirty state.
     
    An object's state can be the following based on the following Boolean
    flags within the object.
     1) IsNew
    2) IsDirty
    3) IsDelete
     
    In the persistence of the object to a database, the state of the object
    will tell a Data Access Layer how to persist the object to the database
    based on the following:
     
    1) IsNew && IsDirty -- insert the new object into the database
    2) !IsNew && IsDirty -- update the existing object in the database
    3) IsDelete -- object is to be deleted from the database
     
    When the object is first instantiated, the IsDirty and IsDelete state
    flags are set to false, and the IsNew is set to true.
     
    When you populate the object from existing data for the first time, the
    methods MakkOld() -- sets IsNew to false and MarkClean() -- sets the
    IsDirty to false. This sets the object's state to it's old or an
    existing object and it is not dirty. You do the MarkClean(), because the
    setter for the object will firer and mark the object as dirty when you
    populate the object with existing data from the database. So you mark
    the 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 on
    the public property firers and the MarkDirty() firers setting the
    object's state to dirty.
     
    The only way something is going to be done to persist the object for
    insert or update is the object's state must be set to dirty based on the
    object's property data has changed,  and  its dirty state has changed to
    reflect 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