title: c# marking class property as dirty
body: <p>The following is a simple example of an enum which defines the state of an object and a class which shows the implementation of this enum.</p>
  
  <pre><code>public enum StatusEnum
  {
      Clean = 0,
      Dirty = 1,
      New = 2,
      Deleted = 3,
      Purged = 4
  }
  
  
  public class Example_Class
  {
      private StatusEnum _Status = StatusEnum.New;
  
      private long _ID;
      private string _Name;
  
      public StatusEnum Status
      {
          get { return _Status; }
          set { _Status = value; }
      }
  
      public long ID
      {
          get { return _ID; }
          set { _ID = value; }
      }
  
      public string Name
      {
          get { return _Name; }
          set { _Name = value; }
      }
  }
  </code></pre>
  
  <p>when populating the class object with data from the database, we set the enum value to "clean". with the goal of keeping most of the logic out of the presentation layer, how can we set the enum value to "dirty" when a property is changed.</p>
  
  <p>i was thinking something along the lines of;</p>
  
  <pre><code>public string Name
  {
      get { return _Name; }
      set 
      {
          if (value != _Name)
          {
                 _Name = value; 
             _Status = StatusEnum.Dirty;
          }
      }   
  }
  </code></pre>
  
  <p>in the setter of each property of the class.</p>
  
  <p>does this sound like a good idea, does anyone have any better ideas on how the dirty flag can be assigned without doing so in the presentation layer.</p>