title: How can I get the base object of an object (not just the BaseType)
body: <p>I was wondering how you can get the actual base object of an object? I have a base class named <strong><em>MessageBase</em></strong>, and a lot of classes that inherit this base class, which themselves get inherited by other classes in different depths. An example:</p>
  
  <p>Some classes inherit like this:</p>
  
  <pre><code>MessageBase --&gt; ValueMessage --&gt; DoubleValueMessage
  </code></pre>
  
  <p>others like that:</p>
  
  <pre><code>MessageBase --&gt; ValueMessage --&gt; [some class] --&gt; [some other class] --&gt; TestMessage
  </code></pre>
  
  <p>What I need is this: I have an object of one of these inherited classes, let's say an instance of DoubleValueMessage. I don't know in advance the type of this object, all I know is that somehwere down the nested inheritance, there is a base object (MessageBase) whose properties I need to set.</p>
  
  <p>Now I tried to get a reference to that base object. So tried to get the ValueMessage the DoubleValueMessage is based upon, but I don't understand <em>how</em>.</p>
  
  <p>I tried it like that:</p>
  
  <pre><code>public bool SetPropertyValue(object obj, string prop, object value)
  {
      var item = obj.GetType().GetProperty(prop);
      //MessageBox.Show(obj.ToString());
      if (item != null)
      {
          item.SetValue(obj, value);
          return true;
      }
      else
      {
          if (obj.base != null)
          {
              SetPropertyValue(obj.base, prop, mb);
          }
      }
  
      return false;
  }
  </code></pre>
  
  <p>The idea is this: I pass in an object (e.g. of type <strong><em>DoubleValueMessage</em></strong>), the property I want to set (is a base object even a property in the first place?) and an object that needs to replace the given property, in my case the <strong><em>MessageBase</em></strong>. So I thought it would be a good idea to recursively iterate down the inheritance hierarchy until the property that I need to set is found.</p>
  
  <p>THe problem is: the <code>.base</code> keyword does not seem to be the right way to get the base object.</p>
  
  <p>How can I get it? Thanks in advance for your help!</p>