title: How to find the source property based on the name of a flattened property with AutoMapper
body: <p>I'm using AutoMapper and I'd like it to trace back a source property based on the name of the mapped (flattened) destination property.</p>
  
  <p>This is because my MVC controller has the name of a mapped property that it needs to provide to a service call that for sorting purposes. The service needs to know the name of the property that the mapping originated from (and the controller is not supposed to know it) in order to perform a proper call to the repository that actually sorts the data.</p>
  
  <p>For example:</p>
  
  <blockquote>
    <p>[Source.Address.ZipCode] maps to [Destination.AddressZipCode]</p>
  </blockquote>
  
  <p>Then</p>
  
  <blockquote>
    <p>Trace "AddressZipCode" back to [Source.Address.ZipCode]</p>
  </blockquote>
  
  <p>Is this something that AutoMapper can do for me or do I need to resort to digging into AutoMapper's mapping data?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Jimmy Bogard told me that this should be possible but not in an obvious manner. It requires loading the type map and going through it. I've looked into it briefly but it seems that I need access to internal types to get to the property mapping information that is required to do reverse mapping.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I've decided to provide some more details.</p>
  
  <p>When I load up the type map, I find that there are two source value resolvers in it for the implicit ZipCode mapping:</p>
  
  <ul>
  <li>a <code>AutoMapper.Internal.PropertyGetter</code> that gets the Address.</li>
  <li>a <code>AutoMapper.Internal.PropertyGetter</code> that gets the ZipCode.</li>
  </ul>
  
  <p>When I have an explicit mapping (that has a lambda expression specified), I find no source value resolver but a custom resolver:</p>
  
  <ul>
  <li>a <code>AutoMapper.DelegateBasedResolver&lt;Company,string&gt;</code> that I think holds my explicit mapping lambda expression.</li>
  </ul>
  
  <p>Unfortunately these resolvers are internal so I can only access them through reflection (which I really don't want to do) or by changing the AutoMapper source code.</p>
  
  <p>If I could access them, I could solve the problem by either walking through the value resolvers or by inspecting the custom resolver although I doubt it that would lead me back to the mapping lambda expression which I need to build the unflattened property name (actually a series of property names separated by dots).</p>