title: C#: Getting Names of properties in a chain from lambda expression
body: <p>I'm developing a API that uses lambda expressions to specify properties. I'm using this famous piece of code similar to this one (this is simplified and incomplete, just to make clear what I'm talking about):</p>
  
  <pre><code>public void Foo&lt;T, P&gt;(Expression&lt;Func&lt;T, P&gt;&gt; action)
  {
      var expression = (MemberExpression)action.Body;
      string propertyName = expression.Member.Name;
      // ...
  }
  </code></pre>
  
  <p>To be called like this: </p>
  
  <pre><code>Foo((String x) =&gt; x.Length);
  </code></pre>
  
  <p>Now I would like to specify a property path by chaining property names, like this:</p>
  
  <pre><code>Foo((MyClass x) =&gt; x.Name.Length);
  </code></pre>
  
  <p>Foo should be able to split the path into its property names (<code>"Name"</code> and <code>"Length"</code>). Is there a way to do this with reasonable effort?</p>
  
  <hr>
  
  <p>There is a <a href="https://stackoverflow.com/questions/995142/combining-lambda-expressions-to-property-paths">somehow similar looking question</a>, but I think they are trying to combine lambda expressions there.</p>
  
  <p><a href="https://stackoverflow.com/questions/536932/how-to-create-expression-tree-lambda-for-a-deep-property-from-a-string">Another question</a> also is dealing with nested property names, but I don't really understand what they are talking about.</p>