title: Method To Set Nested Property Value
body: <p>I'm writing a plugin for a piece of software that requires all code to be in a single class (or nested classes)...</p>
  
  <p>What I'm wanting to do is create a method that can handle changes to the nested properties of my <code>_data</code> object and give me a central place to do things like setting a dirty flag so I know to save it later. </p>
  
  <p>Below is some code illustrating my file's structure and at the bottom are two pseudo-methods that hopefully can give you an idea of what I'm trying to accomplish.</p>
  
  <pre><code>public class SomePlugin
  {
      private DataObject _data;
      private bool _dataIsDirty = false;
  
      private class DataObject
      {
          public GeneralSettings Settings { get; set; }
      }
  
      private class GeneralSettings
      {
          public string SettingOne { get; set; }
          public string SettingTwo { get; set; }
      }
  
      protected override void Init()
      {
          _data = new DataObject
          {
              Settings = new GeneralSettings
              {
                  SettingOne = "Example value one.",
                  SettingTwo = "Example value two."
              }
          }
      }
  
      // These are pseudo-methods illustrating what I'm trying to do.
      private void SetData&lt;t&gt;(T ref instanceProperty, T newValue)
      {
          if (newValue == null) throw new ArgumentNullException("newValue");
          if (instanceProperty == newValue) return;
  
          instanceProperty = newValue;
          _dataIsDirty = true;
      }
  
      private void SomeOtherMethod()
      {
          SetData(_data.Settings.SettingOne, "Updated value one.");
      }
  
  }
  </code></pre>