title: How to get the child declaring type from an expression?
body: <p>I have a Parent / Child class hierarchy where the Parent abstractly declares a string property  and the Child class implements it:</p>
  
  <pre><code>abstract class Parent
  {
     public abstract string Value { get; }
  }
  
  class Child : Parent
  {
     public override string Value { get { return null; } }
  }
  </code></pre>
  
  <p>When I use an expression that explicitly (or implicitly) uses the Child class, I expect the Expressions's MemberInfo's DeclaringType to be 'Child', but instead it is Parent:</p>
  
  <pre><code>Child child = new Child();
  Expression&lt;Func&lt;string&gt;&gt; expression = (() =&gt; child.Value);
  MemberInfo memberInfo = expression.GetMemberInfo();
  Assert.AreEqual(typeof(Child), memberInfo.DeclaringType); // FAILS!
  </code></pre>
  
  <p>The assertion fails because the DeclaringType is Parent.</p>
  
  <p>Is there something I can do in declaring my expression or consuming it to reveal the actual use of the Child type?</p>
  
  <p>NOTE: GetMemberInfo() above as an extension method (I even forgot we had written this!):</p>
  
  <pre><code>public static class TypeExtensions
  {
      /// &lt;summary&gt;
      /// Gets the member info represented by an expression.
      /// &lt;/summary&gt;
      /// &lt;param name="expression"&gt;The member expression.&lt;/param&gt;
      /// &lt;returns&gt;The member info represeted by the expression.&lt;/returns&gt;
      public static MemberInfo GetMemberInfo(this Expression expression)
      {
          var lambda = (LambdaExpression)expression;
  
          MemberExpression memberExpression;
          if (lambda.Body is UnaryExpression)
          {
              var unaryExpression = (UnaryExpression)lambda.Body;
              memberExpression = (MemberExpression)unaryExpression.Operand;
          }
          else memberExpression = (MemberExpression)lambda.Body;
  
          return memberExpression.Member;
      }
  }
  </code></pre>